OLD | NEW |
---|---|
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 m_inDrawingRecorder(false) | 67 m_inDrawingRecorder(false) |
68 #endif | 68 #endif |
69 , | 69 , |
70 m_disabledState(disableContextOrPainting), | 70 m_disabledState(disableContextOrPainting), |
71 m_deviceScaleFactor(1.0f), | 71 m_deviceScaleFactor(1.0f), |
72 m_printing(false), | 72 m_printing(false), |
73 m_hasMetaData(!!metaData) { | 73 m_hasMetaData(!!metaData) { |
74 if (metaData) | 74 if (metaData) |
75 m_metaData = *metaData; | 75 m_metaData = *metaData; |
76 | 76 |
77 // FIXME: Do some tests to determine how many states are typically used, and a llocate | 77 // FIXME: Do some tests to determine how many states are typically used, and |
78 // several here. | 78 // allocate several here. |
79 m_paintStateStack.append(GraphicsContextState::create()); | 79 m_paintStateStack.append(GraphicsContextState::create()); |
80 m_paintState = m_paintStateStack.last().get(); | 80 m_paintState = m_paintStateStack.last().get(); |
81 | 81 |
82 if (contextDisabled()) { | 82 if (contextDisabled()) { |
83 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkCreateNullCanvas())); | 83 DEFINE_STATIC_LOCAL(SkCanvas*, nullCanvas, (SkCreateNullCanvas())); |
84 m_canvas = nullCanvas; | 84 m_canvas = nullCanvas; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 GraphicsContext::~GraphicsContext() { | 88 GraphicsContext::~GraphicsContext() { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 drawLooperBuilder ? drawLooperBuilder->detachDrawLooper() : nullptr); | 205 drawLooperBuilder ? drawLooperBuilder->detachDrawLooper() : nullptr); |
206 } | 206 } |
207 | 207 |
208 SkColorFilter* GraphicsContext::getColorFilter() const { | 208 SkColorFilter* GraphicsContext::getColorFilter() const { |
209 return immutableState()->getColorFilter(); | 209 return immutableState()->getColorFilter(); |
210 } | 210 } |
211 | 211 |
212 void GraphicsContext::setColorFilter(ColorFilter colorFilter) { | 212 void GraphicsContext::setColorFilter(ColorFilter colorFilter) { |
213 GraphicsContextState* stateToSet = mutableState(); | 213 GraphicsContextState* stateToSet = mutableState(); |
214 | 214 |
215 // We only support one active color filter at the moment. If (when) this becom es a problem, | 215 // We only support one active color filter at the moment. If (when) this |
216 // we should switch to using color filter chains (Skia work in progress). | 216 // becomes a problem, we should switch to using color filter chains (Skia work |
217 // in progress). | |
217 DCHECK(!stateToSet->getColorFilter()); | 218 DCHECK(!stateToSet->getColorFilter()); |
218 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)); | 219 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)); |
219 } | 220 } |
220 | 221 |
221 void GraphicsContext::concat(const SkMatrix& matrix) { | 222 void GraphicsContext::concat(const SkMatrix& matrix) { |
222 if (contextDisabled()) | 223 if (contextDisabled()) |
223 return; | 224 return; |
224 | 225 |
225 ASSERT(m_canvas); | 226 ASSERT(m_canvas); |
226 | 227 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 | 478 |
478 // We know these are vertical or horizontal lines, so the length will just | 479 // We know these are vertical or horizontal lines, so the length will just |
479 // be the sum of the displacement component vectors give or take 1 - | 480 // be the sum of the displacement component vectors give or take 1 - |
480 // probably worth the speed up of no square root, which also won't be exact. | 481 // probably worth the speed up of no square root, which also won't be exact. |
481 FloatSize disp = p2 - p1; | 482 FloatSize disp = p2 - p1; |
482 int length = SkScalarRoundToInt(disp.width() + disp.height()); | 483 int length = SkScalarRoundToInt(disp.width() + disp.height()); |
483 SkPaint paint(immutableState()->strokePaint(length)); | 484 SkPaint paint(immutableState()->strokePaint(length)); |
484 | 485 |
485 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) { | 486 if (getStrokeStyle() == DottedStroke || getStrokeStyle() == DashedStroke) { |
486 // Do a rect fill of our endpoints. This ensures we always have the | 487 // Do a rect fill of our endpoints. This ensures we always have the |
487 // appearance of being a border. We then draw the actual dotted/dashed line . | 488 // appearance of being a border. We then draw the actual dotted/dashed |
489 // line. | |
488 SkRect r1, r2; | 490 SkRect r1, r2; |
489 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); | 491 r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); |
490 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); | 492 r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); |
491 | 493 |
492 if (isVerticalLine) { | 494 if (isVerticalLine) { |
493 r1.offset(-width / 2, 0); | 495 r1.offset(-width / 2, 0); |
494 r2.offset(-width / 2, -width); | 496 r2.offset(-width / 2, -width); |
495 } else { | 497 } else { |
496 r1.offset(0, -width / 2); | 498 r1.offset(0, -width / 2); |
497 r2.offset(-width, -width / 2); | 499 r2.offset(-width, -width / 2); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 !WebCoreFloatNearlyEqual( | 1036 !WebCoreFloatNearlyEqual( |
1035 oRadii.bottomRight().height() - strokeSize.height(), | 1037 oRadii.bottomRight().height() - strokeSize.height(), |
1036 iRadii.bottomRight().height()) || | 1038 iRadii.bottomRight().height()) || |
1037 !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.width(), | 1039 !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.width(), |
1038 iRadii.bottomLeft().width()) || | 1040 iRadii.bottomLeft().width()) || |
1039 !WebCoreFloatNearlyEqual( | 1041 !WebCoreFloatNearlyEqual( |
1040 oRadii.bottomLeft().height() - strokeSize.height(), | 1042 oRadii.bottomLeft().height() - strokeSize.height(), |
1041 iRadii.bottomLeft().height())) | 1043 iRadii.bottomLeft().height())) |
1042 return false; | 1044 return false; |
1043 | 1045 |
1044 // We also ignore DRRects with a very thick relative stroke (shapes which are mostly filled by | 1046 // We also ignore DRRects with a very thick relative stroke (shapes which are |
1045 // the stroke): Skia's stroke outline can diverge significantly from the outer /inner contours | 1047 // mostly filled by the stroke): Skia's stroke outline can diverge |
1046 // in some edge cases, so we fall back to drawDRRect instead. | 1048 // significantly from the outer/inner contours in some edge cases, so we fall |
1049 // back to drawDRRect instead. | |
Stephen White
2016/10/05 14:45:37
Nit: drawDRRect() (not new to this patch)
Peter Kasting
2016/10/05 18:46:01
Done.
| |
1047 const float kMaxStrokeToSizeRatio = 0.75f; | 1050 const float kMaxStrokeToSizeRatio = 0.75f; |
1048 if (2 * strokeSize.width() / outer.rect().width() > kMaxStrokeToSizeRatio || | 1051 if (2 * strokeSize.width() / outer.rect().width() > kMaxStrokeToSizeRatio || |
1049 2 * strokeSize.height() / outer.rect().height() > kMaxStrokeToSizeRatio) | 1052 2 * strokeSize.height() / outer.rect().height() > kMaxStrokeToSizeRatio) |
1050 return false; | 1053 return false; |
1051 | 1054 |
1052 return true; | 1055 return true; |
1053 } | 1056 } |
1054 | 1057 |
1055 } // anonymous namespace | 1058 } // anonymous namespace |
1056 | 1059 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1145 return; | 1148 return; |
1146 } | 1149 } |
1147 | 1150 |
1148 clipRRect(rrect, shouldAntialias, regionOp); | 1151 clipRRect(rrect, shouldAntialias, regionOp); |
1149 } | 1152 } |
1150 | 1153 |
1151 void GraphicsContext::clipOut(const Path& pathToClip) { | 1154 void GraphicsContext::clipOut(const Path& pathToClip) { |
1152 if (contextDisabled()) | 1155 if (contextDisabled()) |
1153 return; | 1156 return; |
1154 | 1157 |
1155 // Use const_cast and temporarily toggle the inverse fill type instead of copy ing the path. | 1158 // Use const_cast and temporarily toggle the inverse fill type instead of |
1159 // copying the path. | |
1156 SkPath& path = const_cast<SkPath&>(pathToClip.getSkPath()); | 1160 SkPath& path = const_cast<SkPath&>(pathToClip.getSkPath()); |
1157 path.toggleInverseFillType(); | 1161 path.toggleInverseFillType(); |
1158 clipPath(path, AntiAliased); | 1162 clipPath(path, AntiAliased); |
1159 path.toggleInverseFillType(); | 1163 path.toggleInverseFillType(); |
1160 } | 1164 } |
1161 | 1165 |
1162 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) { | 1166 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) { |
1163 if (contextDisabled()) | 1167 if (contextDisabled()) |
1164 return; | 1168 return; |
1165 | 1169 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1267 | 1271 |
1268 SkPaint paint(immutableState()->fillPaint()); | 1272 SkPaint paint(immutableState()->fillPaint()); |
1269 paint.setColor(color.rgb()); | 1273 paint.setColor(color.rgb()); |
1270 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint); | 1274 m_canvas->drawDRRect(SkRRect::MakeRect(rect), roundedHoleRect, paint); |
1271 } | 1275 } |
1272 | 1276 |
1273 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, | 1277 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, |
1274 FloatPoint& p2, | 1278 FloatPoint& p2, |
1275 float strokeWidth, | 1279 float strokeWidth, |
1276 StrokeStyle penStyle) { | 1280 StrokeStyle penStyle) { |
1277 // For odd widths, we add in 0.5 to the appropriate x/y so that the float arit hmetic | 1281 // For odd widths, we add in 0.5 to the appropriate x/y so that the float |
1278 // works out. For example, with a border width of 3, WebKit will pass us (y1+ y2)/2, e.g., | 1282 // arithmetic works out. For example, with a border width of 3, WebKit will |
1279 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even w idth gave | 1283 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is |
1280 // us a perfect position, but an odd width gave us a position that is off by e xactly 0.5. | 1284 // always true that an even width gave us a perfect position, but an odd width |
1285 // gave us a position that is off by exactly 0.5. | |
1281 if (penStyle == DottedStroke || penStyle == DashedStroke) { | 1286 if (penStyle == DottedStroke || penStyle == DashedStroke) { |
1282 if (p1.x() == p2.x()) { | 1287 if (p1.x() == p2.x()) { |
1283 p1.setY(p1.y() + strokeWidth); | 1288 p1.setY(p1.y() + strokeWidth); |
1284 p2.setY(p2.y() - strokeWidth); | 1289 p2.setY(p2.y() - strokeWidth); |
1285 } else { | 1290 } else { |
1286 p1.setX(p1.x() + strokeWidth); | 1291 p1.setX(p1.x() + strokeWidth); |
1287 p2.setX(p2.x() - strokeWidth); | 1292 p2.setX(p2.x() - strokeWidth); |
1288 } | 1293 } |
1289 } | 1294 } |
1290 | 1295 |
1291 if (static_cast<int>(strokeWidth) % 2) { //odd | 1296 if (static_cast<int>(strokeWidth) % 2) { // odd |
1292 if (p1.x() == p2.x()) { | 1297 if (p1.x() == p2.x()) { |
1293 // We're a vertical line. Adjust our x. | 1298 // We're a vertical line. Adjust our x. |
1294 p1.setX(p1.x() + 0.5f); | 1299 p1.setX(p1.x() + 0.5f); |
1295 p2.setX(p2.x() + 0.5f); | 1300 p2.setX(p2.x() + 0.5f); |
1296 } else { | 1301 } else { |
1297 // We're a horizontal line. Adjust our y. | 1302 // We're a horizontal line. Adjust our y. |
1298 p1.setY(p1.y() + 0.5f); | 1303 p1.setY(p1.y() + 0.5f); |
1299 p2.setY(p2.y() + 0.5f); | 1304 p2.setY(p2.y() + 0.5f); |
1300 } | 1305 } |
1301 } | 1306 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 static const SkPMColor colors[] = { | 1412 static const SkPMColor colors[] = { |
1408 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1413 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1409 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1414 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1410 }; | 1415 }; |
1411 | 1416 |
1412 return colors[index]; | 1417 return colors[index]; |
1413 } | 1418 } |
1414 #endif | 1419 #endif |
1415 | 1420 |
1416 } // namespace blink | 1421 } // namespace blink |
OLD | NEW |