Chromium Code Reviews| 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 996 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 fullCanvasComposited(path, FillPathFunctor()); |
| 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 fullCanvasComposited(path, StrokePathFunctor()); |
| 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 fullCanvasComposited(rect, FillRectFunctor()); |
| 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 fullCanvasComposited(rect, StrokeRectFunctor()); |
|
Justin Novosad
2014/04/07 15:50:30
I think that with this line of code removed State:
| |
| 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 boundingRect.inflate(state().m_lineWidth / 2); | |
| 1388 FloatRect dirtyRect; | |
| 1389 if (computeDirtyRect(boundingRect, &dirtyRect)) { | |
| 1390 c->strokeRect(rect, state().m_lineWidth); | |
| 1391 didDraw(dirtyRect); | |
| 1392 } | |
| 1369 } | 1393 } |
| 1370 } | 1394 } |
| 1371 | 1395 |
| 1372 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) | 1396 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) |
| 1373 { | 1397 { |
| 1374 setShadow(FloatSize(width, height), blur, Color::transparent); | 1398 setShadow(FloatSize(width, height), blur, Color::transparent); |
| 1375 } | 1399 } |
| 1376 | 1400 |
| 1377 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) | 1401 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) |
| 1378 { | 1402 { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1647 | 1671 |
| 1648 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) | 1672 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) |
| 1649 { | 1673 { |
| 1650 ASSERT(isFullCanvasCompositeMode(op)); | 1674 ASSERT(isFullCanvasCompositeMode(op)); |
| 1651 | 1675 |
| 1652 drawingContext()->beginLayer(1, op); | 1676 drawingContext()->beginLayer(1, op); |
| 1653 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver); | 1677 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver); |
| 1654 drawingContext()->endLayer(); | 1678 drawingContext()->endLayer(); |
| 1655 } | 1679 } |
| 1656 | 1680 |
| 1657 static void fillPrimitive(const FloatRect& rect, GraphicsContext* context) | 1681 template<class T, class Functor> void CanvasRenderingContext2D::fullCanvasCompos ited(const T& area, Functor functor) |
| 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 { | 1682 { |
| 1669 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); | 1683 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); |
| 1670 | 1684 |
| 1671 GraphicsContext* c = drawingContext(); | 1685 GraphicsContext* c = drawingContext(); |
| 1672 ASSERT(c); | 1686 ASSERT(c); |
| 1673 c->beginLayer(1, state().m_globalComposite); | 1687 c->beginLayer(1, state().m_globalComposite); |
| 1674 CompositeOperator previousOperator = c->compositeOperation(); | 1688 CompositeOperator previousOperator = c->compositeOperation(); |
| 1675 c->setCompositeOperation(CompositeSourceOver); | 1689 c->setCompositeOperation(CompositeSourceOver); |
| 1676 fillPrimitive(area, c); | 1690 functor(area, c); |
| 1677 c->setCompositeOperation(previousOperator); | 1691 c->setCompositeOperation(previousOperator); |
| 1678 c->endLayer(); | 1692 c->endLayer(); |
| 1679 } | 1693 } |
| 1680 | 1694 |
| 1681 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) | 1695 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) |
| 1682 { | 1696 { |
| 1683 if (!std::isfinite(x0)) | 1697 if (!std::isfinite(x0)) |
| 1684 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); | 1698 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); |
| 1685 else if (!std::isfinite(y0)) | 1699 else if (!std::isfinite(y0)) |
| 1686 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0")); | 1700 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); | 2455 c->setAlphaAsFloat(1.0); |
| 2442 c->clearShadow(); | 2456 c->clearShadow(); |
| 2443 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); | 2457 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); |
| 2444 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); | 2458 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); |
| 2445 c->restore(); | 2459 c->restore(); |
| 2446 | 2460 |
| 2447 didDraw(dirtyRect); | 2461 didDraw(dirtyRect); |
| 2448 } | 2462 } |
| 2449 | 2463 |
| 2450 } // namespace WebCore | 2464 } // namespace WebCore |
| OLD | NEW |