Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 2398453002: Rewrap comments to 80 columns in Source/platform/graphics/. (Closed)
Patch Set: Review feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 m_disableDestructionChecks(false), 65 m_disableDestructionChecks(false),
66 m_inDrawingRecorder(false), 66 m_inDrawingRecorder(false),
67 #endif 67 #endif
68 m_disabledState(disableContextOrPainting), 68 m_disabledState(disableContextOrPainting),
69 m_deviceScaleFactor(1.0f), 69 m_deviceScaleFactor(1.0f),
70 m_printing(false), 70 m_printing(false),
71 m_hasMetaData(!!metaData) { 71 m_hasMetaData(!!metaData) {
72 if (metaData) 72 if (metaData)
73 m_metaData = *metaData; 73 m_metaData = *metaData;
74 74
75 // FIXME: Do some tests to determine how many states are typically used, and a llocate 75 // FIXME: Do some tests to determine how many states are typically used, and
76 // several here. 76 // allocate several here.
77 m_paintStateStack.append(GraphicsContextState::create()); 77 m_paintStateStack.append(GraphicsContextState::create());
78 m_paintState = m_paintStateStack.last().get(); 78 m_paintState = m_paintStateStack.last().get();
79 79
80 if (contextDisabled()) { 80 if (contextDisabled()) {
81 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkCreateNullCanvas())); 81 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkCreateNullCanvas()));
82 m_canvas = nullCanvas; 82 m_canvas = nullCanvas;
83 } 83 }
84 } 84 }
85 85
86 GraphicsContext::~GraphicsContext() { 86 GraphicsContext::~GraphicsContext() {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 drawLooperBuilder ? drawLooperBuilder->detachDrawLooper() : nullptr); 203 drawLooperBuilder ? drawLooperBuilder->detachDrawLooper() : nullptr);
204 } 204 }
205 205
206 SkColorFilter* GraphicsContext::getColorFilter() const { 206 SkColorFilter* GraphicsContext::getColorFilter() const {
207 return immutableState()->getColorFilter(); 207 return immutableState()->getColorFilter();
208 } 208 }
209 209
210 void GraphicsContext::setColorFilter(ColorFilter colorFilter) { 210 void GraphicsContext::setColorFilter(ColorFilter colorFilter) {
211 GraphicsContextState* stateToSet = mutableState(); 211 GraphicsContextState* stateToSet = mutableState();
212 212
213 // We only support one active color filter at the moment. If (when) this becom es a problem, 213 // We only support one active color filter at the moment. If (when) this
214 // we should switch to using color filter chains (Skia work in progress). 214 // becomes a problem, we should switch to using color filter chains (Skia work
215 // in progress).
215 DCHECK(!stateToSet->getColorFilter()); 216 DCHECK(!stateToSet->getColorFilter());
216 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)); 217 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter));
217 } 218 }
218 219
219 void GraphicsContext::concat(const SkMatrix& matrix) { 220 void GraphicsContext::concat(const SkMatrix& matrix) {
220 if (contextDisabled()) 221 if (contextDisabled())
221 return; 222 return;
222 223
223 ASSERT(m_canvas); 224 ASSERT(m_canvas);
224 225
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 476
476 // We know these are vertical or horizontal lines, so the length will just 477 // We know these are vertical or horizontal lines, so the length will just
477 // be the sum of the displacement component vectors give or take 1 - 478 // be the sum of the displacement component vectors give or take 1 -
478 // probably worth the speed up of no square root, which also won't be exact. 479 // probably worth the speed up of no square root, which also won't be exact.
479 FloatSize disp = p2 - p1; 480 FloatSize disp = p2 - p1;
480 int length = SkScalarRoundToInt(disp.width() + disp.height()); 481 int length = SkScalarRoundToInt(disp.width() + disp.height());
481 SkPaint paint(immutableState()->strokePaint(length)); 482 SkPaint paint(immutableState()->strokePaint(length));
482 483
483 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) { 484 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) {
484 // Do a rect fill of our endpoints. This ensures we always have the 485 // Do a rect fill of our endpoints. This ensures we always have the
485 // appearance of being a border. We then draw the actual dotted/dashed line . 486 // appearance of being a border. We then draw the actual dotted/dashed
487 // line.
486 SkRect r1, r2; 488 SkRect r1, r2;
487 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); 489 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width);
488 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); 490 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width);
489 491
490 if (isVerticalLine) { 492 if (isVerticalLine) {
491 r1.offset(-width / 2, 0); 493 r1.offset(-width / 2, 0);
492 r2.offset(-width / 2, -width); 494 r2.offset(-width / 2, -width);
493 } else { 495 } else {
494 r1.offset(0, -width / 2); 496 r1.offset(0, -width / 2);
495 r2.offset(-width, -width / 2); 497 r2.offset(-width, -width / 2);
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 !WebCoreFloatNearlyEqual( 1034 !WebCoreFloatNearlyEqual(
1033 oRadii.bottomRight().height() - strokeSize.height(), 1035 oRadii.bottomRight().height() - strokeSize.height(),
1034 iRadii.bottomRight().height()) || 1036 iRadii.bottomRight().height()) ||
1035 !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.width(), 1037 !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.width(),
1036 iRadii.bottomLeft().width()) || 1038 iRadii.bottomLeft().width()) ||
1037 !WebCoreFloatNearlyEqual( 1039 !WebCoreFloatNearlyEqual(
1038 oRadii.bottomLeft().height() - strokeSize.height(), 1040 oRadii.bottomLeft().height() - strokeSize.height(),
1039 iRadii.bottomLeft().height())) 1041 iRadii.bottomLeft().height()))
1040 return false; 1042 return false;
1041 1043
1042 // We also ignore DRRects with a very thick relative stroke (shapes which are mostly filled by 1044 // We also ignore DRRects with a very thick relative stroke (shapes which are
1043 // the stroke): Skia's stroke outline can diverge significantly from the outer /inner contours 1045 // mostly filled by the stroke): Skia's stroke outline can diverge
1044 // in some edge cases, so we fall back to drawDRRect instead. 1046 // significantly from the outer/inner contours in some edge cases, so we fall
1047 // back to drawDRRect() instead.
1045 const float kMaxStrokeToSizeRatio = 0.75f; 1048 const float kMaxStrokeToSizeRatio = 0.75f;
1046 if (2 * strokeSize.width() / outer.rect().width() > kMaxStrokeToSizeRatio || 1049 if (2 * strokeSize.width() / outer.rect().width() > kMaxStrokeToSizeRatio ||
1047 2 * strokeSize.height() / outer.rect().height() > kMaxStrokeToSizeRatio) 1050 2 * strokeSize.height() / outer.rect().height() > kMaxStrokeToSizeRatio)
1048 return false; 1051 return false;
1049 1052
1050 return true; 1053 return true;
1051 } 1054 }
1052 1055
1053 } // anonymous namespace 1056 } // anonymous namespace
1054 1057
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 return; 1146 return;
1144 } 1147 }
1145 1148
1146 clipRRect(rrect, shouldAntialias, regionOp); 1149 clipRRect(rrect, shouldAntialias, regionOp);
1147 } 1150 }
1148 1151
1149 void GraphicsContext::clipOut(const Path& pathToClip) { 1152 void GraphicsContext::clipOut(const Path& pathToClip) {
1150 if (contextDisabled()) 1153 if (contextDisabled())
1151 return; 1154 return;
1152 1155
1153 // Use const_cast and temporarily toggle the inverse fill type instead of copy ing the path. 1156 // Use const_cast and temporarily toggle the inverse fill type instead of
1157 // copying the path.
1154 SkPath& path = const_cast<SkPath&>(pathToClip.getSkPath()); 1158 SkPath& path = const_cast<SkPath&>(pathToClip.getSkPath());
1155 path.toggleInverseFillType(); 1159 path.toggleInverseFillType();
1156 clipPath(path, AntiAliased); 1160 clipPath(path, AntiAliased);
1157 path.toggleInverseFillType(); 1161 path.toggleInverseFillType();
1158 } 1162 }
1159 1163
1160 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) { 1164 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) {
1161 if (contextDisabled()) 1165 if (contextDisabled())
1162 return; 1166 return;
1163 1167
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1269
1266 SkPaint paint(immutableState()->fillPaint()); 1270 SkPaint paint(immutableState()->fillPaint());
1267 paint.setColor(color.rgb()); 1271 paint.setColor(color.rgb());
1268 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint); 1272 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint);
1269 } 1273 }
1270 1274
1271 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, 1275 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1,
1272 FloatPoint& p2, 1276 FloatPoint& p2,
1273 float strokeWidth, 1277 float strokeWidth,
1274 StrokeStyle penStyle) { 1278 StrokeStyle penStyle) {
1275 // For odd widths, we add in 0.5 to the appropriate x/y so that the float arit hmetic 1279 // For odd widths, we add in 0.5 to the appropriate x/y so that the float
1276 // works out. For example, with a border width of 3, WebKit will pass us (y1+ y2)/2, e.g., 1280 // arithmetic works out. For example, with a border width of 3, WebKit will
1277 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even w idth gave 1281 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is
1278 // us a perfect position, but an odd width gave us a position that is off by e xactly 0.5. 1282 // always true that an even width gave us a perfect position, but an odd width
1283 // gave us a position that is off by exactly 0.5.
1279 if (penStyle == DottedStroke || penStyle == DashedStroke) { 1284 if (penStyle == DottedStroke || penStyle == DashedStroke) {
1280 if (p1.x() == p2.x()) { 1285 if (p1.x() == p2.x()) {
1281 p1.setY(p1.y() + strokeWidth); 1286 p1.setY(p1.y() + strokeWidth);
1282 p2.setY(p2.y() - strokeWidth); 1287 p2.setY(p2.y() - strokeWidth);
1283 } else { 1288 } else {
1284 p1.setX(p1.x() + strokeWidth); 1289 p1.setX(p1.x() + strokeWidth);
1285 p2.setX(p2.x() - strokeWidth); 1290 p2.setX(p2.x() - strokeWidth);
1286 } 1291 }
1287 } 1292 }
1288 1293
1289 if (static_cast<int>(strokeWidth) % 2) { //odd 1294 if (static_cast<int>(strokeWidth) % 2) { // odd
1290 if (p1.x() == p2.x()) { 1295 if (p1.x() == p2.x()) {
1291 // We're a vertical line. Adjust our x. 1296 // We're a vertical line. Adjust our x.
1292 p1.setX(p1.x() + 0.5f); 1297 p1.setX(p1.x() + 0.5f);
1293 p2.setX(p2.x() + 0.5f); 1298 p2.setX(p2.x() + 0.5f);
1294 } else { 1299 } else {
1295 // We're a horizontal line. Adjust our y. 1300 // We're a horizontal line. Adjust our y.
1296 p1.setY(p1.y() + 0.5f); 1301 p1.setY(p1.y() + 0.5f);
1297 p2.setY(p2.y() + 0.5f); 1302 p2.setY(p2.y() + 0.5f);
1298 } 1303 }
1299 } 1304 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 static const SkPMColor colors[] = { 1410 static const SkPMColor colors[] = {
1406 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1411 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1407 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1412 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1408 }; 1413 };
1409 1414
1410 return colors[index]; 1415 return colors[index];
1411 } 1416 }
1412 #endif 1417 #endif
1413 1418
1414 } // namespace blink 1419 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698