OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 } | 222 } |
223 | 223 |
224 // Important: Several of these properties are also stored in GraphicsContext's | 224 // Important: Several of these properties are also stored in GraphicsContext's |
225 // StrokeData. The default values that StrokeData uses may not the same values | 225 // StrokeData. The default values that StrokeData uses may not the same values |
226 // that the canvas 2d spec specifies. Make sure to sync the initial state of the | 226 // that the canvas 2d spec specifies. Make sure to sync the initial state of the |
227 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! | 227 // GraphicsContext in HTMLCanvasElement::createImageBuffer()! |
228 CanvasRenderingContext2D::State::State() | 228 CanvasRenderingContext2D::State::State() |
229 : m_unrealizedSaveCount(0) | 229 : m_unrealizedSaveCount(0) |
230 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) | 230 , m_strokeStyle(CanvasStyle::createFromRGBA(Color::black)) |
231 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) | 231 , m_fillStyle(CanvasStyle::createFromRGBA(Color::black)) |
232 , m_lineWidth(1) | 232 , m_lineWidth(1) |
Justin Novosad
2014/04/07 18:03:14
You responded "Done", but m_lineWidth is still her
| |
233 , m_lineCap(ButtCap) | 233 , m_lineCap(ButtCap) |
234 , m_lineJoin(MiterJoin) | 234 , m_lineJoin(MiterJoin) |
235 , m_miterLimit(10) | 235 , m_miterLimit(10) |
236 , m_shadowBlur(0) | 236 , m_shadowBlur(0) |
237 , m_shadowColor(Color::transparent) | 237 , m_shadowColor(Color::transparent) |
238 , m_globalAlpha(1) | 238 , m_globalAlpha(1) |
239 , m_globalComposite(CompositeSourceOver) | 239 , m_globalComposite(CompositeSourceOver) |
240 , m_globalBlend(blink::WebBlendModeNormal) | 240 , m_globalBlend(blink::WebBlendModeNormal) |
241 , m_invertibleCTM(true) | 241 , m_invertibleCTM(true) |
242 , m_lineDashOffset(0) | 242 , m_lineDashOffset(0) |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 } | 1007 } |
1008 | 1008 |
1009 WindRule windRule = c->fillRule(); | 1009 WindRule windRule = c->fillRule(); |
1010 WindRule newWindRule = RULE_NONZERO; | 1010 WindRule newWindRule = RULE_NONZERO; |
1011 if (!parseWinding(windingRuleString, newWindRule)) { | 1011 if (!parseWinding(windingRuleString, newWindRule)) { |
1012 return; | 1012 return; |
1013 } | 1013 } |
1014 c->setFillRule(newWindRule); | 1014 c->setFillRule(newWindRule); |
1015 | 1015 |
1016 if (isFullCanvasCompositeMode(state().m_globalComposite)) { | 1016 if (isFullCanvasCompositeMode(state().m_globalComposite)) { |
1017 fullCanvasCompositedFill(path); | 1017 fullCanvasComposite(path, &GraphicsContext::fillPath); |
1018 didDraw(clipBounds); | 1018 didDraw(clipBounds); |
1019 } else if (state().m_globalComposite == CompositeCopy) { | 1019 } else if (state().m_globalComposite == CompositeCopy) { |
1020 clearCanvas(); | 1020 clearCanvas(); |
1021 c->fillPath(path); | 1021 c->fillPath(path); |
1022 didDraw(clipBounds); | 1022 didDraw(clipBounds); |
1023 } else { | 1023 } else { |
1024 FloatRect dirtyRect; | 1024 FloatRect dirtyRect; |
1025 if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) { | 1025 if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) { |
1026 c->fillPath(path); | 1026 c->fillPath(path); |
1027 didDraw(dirtyRect); | 1027 didDraw(dirtyRect); |
(...skipping 28 matching lines...) Expand all Loading... | |
1056 if (path.isEmpty()) { | 1056 if (path.isEmpty()) { |
1057 return; | 1057 return; |
1058 } | 1058 } |
1059 GraphicsContext* c = drawingContext(); | 1059 GraphicsContext* c = drawingContext(); |
1060 if (!c) { | 1060 if (!c) { |
1061 return; | 1061 return; |
1062 } | 1062 } |
1063 if (!state().m_invertibleCTM) { | 1063 if (!state().m_invertibleCTM) { |
1064 return; | 1064 return; |
1065 } | 1065 } |
1066 FloatRect clipBounds; | |
1067 if (!c->getTransformedClipBounds(&clipBounds)) | |
1068 return; | |
1066 | 1069 |
1067 // If gradient size is zero, then paint nothing. | 1070 // If gradient size is zero, then paint nothing. |
1068 Gradient* gradient = c->strokeGradient(); | 1071 Gradient* gradient = c->strokeGradient(); |
1069 if (gradient && gradient->isZeroSize()) { | 1072 if (gradient && gradient->isZeroSize()) { |
1070 return; | 1073 return; |
1071 } | 1074 } |
1072 | 1075 |
1073 FloatRect bounds = path.boundingRect(); | 1076 if (isFullCanvasCompositeMode(state().m_globalComposite)) { |
1074 inflateStrokeRect(bounds); | 1077 fullCanvasComposite(path, &GraphicsContext::strokePath); |
1075 FloatRect dirtyRect; | 1078 didDraw(clipBounds); |
1076 if (computeDirtyRect(bounds, &dirtyRect)) { | 1079 } else if (state().m_globalComposite == CompositeCopy) { |
1080 clearCanvas(); | |
1077 c->strokePath(path); | 1081 c->strokePath(path); |
1078 didDraw(dirtyRect); | 1082 didDraw(clipBounds); |
1083 } else { | |
1084 FloatRect bounds = path.boundingRect(); | |
1085 inflateStrokeRect(bounds); | |
1086 FloatRect dirtyRect; | |
1087 if (computeDirtyRect(path.boundingRect(), &dirtyRect)) { | |
1088 c->strokePath(path); | |
1089 didDraw(dirtyRect); | |
1090 } | |
1079 } | 1091 } |
1080 } | 1092 } |
1081 | 1093 |
1082 void CanvasRenderingContext2D::stroke() | 1094 void CanvasRenderingContext2D::stroke() |
1083 { | 1095 { |
1084 strokeInternal(m_path); | 1096 strokeInternal(m_path); |
1085 } | 1097 } |
1086 | 1098 |
1087 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State) | 1099 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State) |
1088 { | 1100 { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing | 1329 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing |
1318 Gradient* gradient = c->fillGradient(); | 1330 Gradient* gradient = c->fillGradient(); |
1319 if (gradient && gradient->isZeroSize()) | 1331 if (gradient && gradient->isZeroSize()) |
1320 return; | 1332 return; |
1321 | 1333 |
1322 FloatRect rect(x, y, width, height); | 1334 FloatRect rect(x, y, width, height); |
1323 if (rectContainsTransformedRect(rect, clipBounds)) { | 1335 if (rectContainsTransformedRect(rect, clipBounds)) { |
1324 c->fillRect(rect); | 1336 c->fillRect(rect); |
1325 didDraw(clipBounds); | 1337 didDraw(clipBounds); |
1326 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { | 1338 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { |
1327 fullCanvasCompositedFill(rect); | 1339 fullCanvasComposite(rect, &GraphicsContext::fillRect); |
1328 didDraw(clipBounds); | 1340 didDraw(clipBounds); |
1329 } else if (state().m_globalComposite == CompositeCopy) { | 1341 } else if (state().m_globalComposite == CompositeCopy) { |
1330 clearCanvas(); | 1342 clearCanvas(); |
1331 c->fillRect(rect); | 1343 c->fillRect(rect); |
1332 didDraw(clipBounds); | 1344 didDraw(clipBounds); |
1333 } else { | 1345 } else { |
1334 FloatRect dirtyRect; | 1346 FloatRect dirtyRect; |
1335 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) { | 1347 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) { |
1336 c->fillRect(rect); | 1348 c->fillRect(rect); |
1337 didDraw(dirtyRect); | 1349 didDraw(dirtyRect); |
1338 } | 1350 } |
1339 } | 1351 } |
1340 } | 1352 } |
1341 | 1353 |
1342 void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float h eight) | 1354 void CanvasRenderingContext2D::strokeRect(float x, float y, float width, float h eight) |
1343 { | 1355 { |
1344 if (!validateRectForCanvas(x, y, width, height)) | 1356 if (!validateRectForCanvas(x, y, width, height)) |
1345 return; | 1357 return; |
1346 | 1358 |
1347 if (!(state().m_lineWidth >= 0)) | 1359 if (!(state().m_lineWidth >= 0)) |
1348 return; | 1360 return; |
1349 | 1361 |
1350 GraphicsContext* c = drawingContext(); | 1362 GraphicsContext* c = drawingContext(); |
1351 if (!c) | 1363 if (!c) |
1352 return; | 1364 return; |
1353 if (!state().m_invertibleCTM) | 1365 if (!state().m_invertibleCTM) |
1354 return; | 1366 return; |
1367 FloatRect clipBounds; | |
1368 if (!c->getTransformedClipBounds(&clipBounds)) | |
1369 return; | |
1355 | 1370 |
1356 // If gradient size is zero, then paint nothing. | 1371 // If gradient size is zero, then paint nothing. |
1357 Gradient* gradient = c->strokeGradient(); | 1372 Gradient* gradient = c->strokeGradient(); |
1358 if (gradient && gradient->isZeroSize()) | 1373 if (gradient && gradient->isZeroSize()) |
1359 return; | 1374 return; |
1360 | 1375 |
1361 FloatRect rect(x, y, width, height); | 1376 FloatRect rect(x, y, width, height); |
1362 | 1377 |
1363 FloatRect boundingRect = rect; | 1378 if (isFullCanvasCompositeMode(state().m_globalComposite)) { |
1364 boundingRect.inflate(state().m_lineWidth / 2); | 1379 fullCanvasComposite(rect, &GraphicsContext::strokeRect); |
1365 FloatRect dirtyRect; | 1380 didDraw(clipBounds); |
1366 if (computeDirtyRect(boundingRect, &dirtyRect)) { | 1381 } else if (state().m_globalComposite == CompositeCopy) { |
1367 c->strokeRect(rect, state().m_lineWidth); | 1382 clearCanvas(); |
1368 didDraw(dirtyRect); | 1383 c->strokeRect(rect); |
1384 didDraw(clipBounds); | |
1385 } else { | |
1386 FloatRect boundingRect = rect; | |
1387 FloatRect dirtyRect; | |
1388 if (computeDirtyRect(boundingRect, &dirtyRect)) { | |
1389 c->strokeRect(rect); | |
1390 didDraw(dirtyRect); | |
1391 } | |
1369 } | 1392 } |
1370 } | 1393 } |
1371 | 1394 |
1372 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) | 1395 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) |
1373 { | 1396 { |
1374 setShadow(FloatSize(width, height), blur, Color::transparent); | 1397 setShadow(FloatSize(width, height), blur, Color::transparent); |
1375 } | 1398 } |
1376 | 1399 |
1377 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) | 1400 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) |
1378 { | 1401 { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 | 1670 |
1648 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) | 1671 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
1649 { | 1672 { |
1650 ASSERT(isFullCanvasCompositeMode(op)); | 1673 ASSERT(isFullCanvasCompositeMode(op)); |
1651 | 1674 |
1652 drawingContext()->beginLayer(1, op); | 1675 drawingContext()->beginLayer(1, op); |
1653 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver); | 1676 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver); |
1654 drawingContext()->endLayer(); | 1677 drawingContext()->endLayer(); |
1655 } | 1678 } |
1656 | 1679 |
1657 static void fillPrimitive(const FloatRect& rect, GraphicsContext* context) | 1680 template<class T> void CanvasRenderingContext2D::fullCanvasComposite(const T& ar ea, void (GraphicsContext::*drawOperation)(const T&)) |
Justin Novosad
2014/04/07 18:03:14
drawOperation is an unnecessary indirection. A si
| |
1658 { | |
1659 context->fillRect(rect); | |
1660 } | |
1661 | |
1662 static void fillPrimitive(const Path& path, GraphicsContext* context) | |
1663 { | |
1664 context->fillPath(path); | |
1665 } | |
1666 | |
1667 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedFill(const T& area) | |
1668 { | 1681 { |
1669 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); | 1682 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); |
1670 | 1683 |
1671 GraphicsContext* c = drawingContext(); | 1684 GraphicsContext* c = drawingContext(); |
1672 ASSERT(c); | 1685 ASSERT(c); |
1673 c->beginLayer(1, state().m_globalComposite); | 1686 c->beginLayer(1, state().m_globalComposite); |
1674 CompositeOperator previousOperator = c->compositeOperation(); | 1687 CompositeOperator previousOperator = c->compositeOperation(); |
1675 c->setCompositeOperation(CompositeSourceOver); | 1688 c->setCompositeOperation(CompositeSourceOver); |
1676 fillPrimitive(area, c); | 1689 (c->*drawOperation)(area); |
1677 c->setCompositeOperation(previousOperator); | 1690 c->setCompositeOperation(previousOperator); |
1678 c->endLayer(); | 1691 c->endLayer(); |
1679 } | 1692 } |
1680 | 1693 |
1681 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) | 1694 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) |
1682 { | 1695 { |
1683 if (!std::isfinite(x0)) | 1696 if (!std::isfinite(x0)) |
1684 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); | 1697 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); |
1685 else if (!std::isfinite(y0)) | 1698 else if (!std::isfinite(y0)) |
1686 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0")); | 1699 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0")); |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2441 c->setAlphaAsFloat(1.0); | 2454 c->setAlphaAsFloat(1.0); |
2442 c->clearShadow(); | 2455 c->clearShadow(); |
2443 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2456 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
2444 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2457 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
2445 c->restore(); | 2458 c->restore(); |
2446 | 2459 |
2447 didDraw(dirtyRect); | 2460 didDraw(dirtyRect); |
2448 } | 2461 } |
2449 | 2462 |
2450 } // namespace WebCore | 2463 } // namespace WebCore |
OLD | NEW |