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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 227213002: globalCompositeOperation is ignored in stroke, strokeRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 8 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) 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 if (!state().m_invertibleCTM) { 1063 if (!state().m_invertibleCTM) {
1064 return; 1064 return;
1065 } 1065 }
1066 1066
1067 // If gradient size is zero, then paint nothing. 1067 // If gradient size is zero, then paint nothing.
1068 Gradient* gradient = c->strokeGradient(); 1068 Gradient* gradient = c->strokeGradient();
1069 if (gradient && gradient->isZeroSize()) { 1069 if (gradient && gradient->isZeroSize()) {
1070 return; 1070 return;
1071 } 1071 }
1072 1072
1073 FloatRect bounds = path.boundingRect(); 1073 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1074 inflateStrokeRect(bounds); 1074 fullCanvasComposited(path, StrokePathFunctor());
1075 FloatRect dirtyRect; 1075 didDraw(path.boundingRect());
krit 2014/04/07 08:10:35 It think you should make the whole canvas for repa
1076 if (computeDirtyRect(bounds, &dirtyRect)) { 1076 } else if (state().m_globalComposite == CompositeCopy) {
1077 clearCanvas();
1077 c->strokePath(path); 1078 c->strokePath(path);
1078 didDraw(dirtyRect); 1079 didDraw(path.boundingRect());
1080 } else {
1081 FloatRect bounds = path.boundingRect();
1082 inflateStrokeRect(bounds);
1083 FloatRect dirtyRect;
1084 if (computeDirtyRect(path.boundingRect(), &dirtyRect)) {
1085 c->strokePath(path);
1086 didDraw(dirtyRect);
1087 }
1079 } 1088 }
1080 } 1089 }
1081 1090
1082 void CanvasRenderingContext2D::stroke() 1091 void CanvasRenderingContext2D::stroke()
1083 { 1092 {
1084 strokeInternal(m_path); 1093 strokeInternal(m_path);
1085 } 1094 }
1086 1095
1087 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State) 1096 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State)
1088 { 1097 {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing 1326 // If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint n othing
1318 Gradient* gradient = c->fillGradient(); 1327 Gradient* gradient = c->fillGradient();
1319 if (gradient && gradient->isZeroSize()) 1328 if (gradient && gradient->isZeroSize())
1320 return; 1329 return;
1321 1330
1322 FloatRect rect(x, y, width, height); 1331 FloatRect rect(x, y, width, height);
1323 if (rectContainsTransformedRect(rect, clipBounds)) { 1332 if (rectContainsTransformedRect(rect, clipBounds)) {
1324 c->fillRect(rect); 1333 c->fillRect(rect);
1325 didDraw(clipBounds); 1334 didDraw(clipBounds);
1326 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) { 1335 } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1327 fullCanvasCompositedFill(rect); 1336 fullCanvasComposited(rect, FillRectFunctor());
1328 didDraw(clipBounds); 1337 didDraw(clipBounds);
1329 } else if (state().m_globalComposite == CompositeCopy) { 1338 } else if (state().m_globalComposite == CompositeCopy) {
1330 clearCanvas(); 1339 clearCanvas();
1331 c->fillRect(rect); 1340 c->fillRect(rect);
1332 didDraw(clipBounds); 1341 didDraw(clipBounds);
1333 } else { 1342 } else {
1334 FloatRect dirtyRect; 1343 FloatRect dirtyRect;
1335 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) { 1344 if (computeDirtyRect(rect, clipBounds, &dirtyRect)) {
1336 c->fillRect(rect); 1345 c->fillRect(rect);
1337 didDraw(dirtyRect); 1346 didDraw(dirtyRect);
(...skipping 15 matching lines...) Expand all
1353 if (!state().m_invertibleCTM) 1362 if (!state().m_invertibleCTM)
1354 return; 1363 return;
1355 1364
1356 // If gradient size is zero, then paint nothing. 1365 // If gradient size is zero, then paint nothing.
1357 Gradient* gradient = c->strokeGradient(); 1366 Gradient* gradient = c->strokeGradient();
1358 if (gradient && gradient->isZeroSize()) 1367 if (gradient && gradient->isZeroSize())
1359 return; 1368 return;
1360 1369
1361 FloatRect rect(x, y, width, height); 1370 FloatRect rect(x, y, width, height);
1362 1371
1363 FloatRect boundingRect = rect; 1372 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1364 boundingRect.inflate(state().m_lineWidth / 2); 1373 fullCanvasComposited(rect, StrokeRectFunctor());
1365 FloatRect dirtyRect; 1374 didDraw(rect);
krit 2014/04/07 08:10:35 Ditto.
1366 if (computeDirtyRect(boundingRect, &dirtyRect)) { 1375 } else if (state().m_globalComposite == CompositeCopy) {
1367 c->strokeRect(rect, state().m_lineWidth); 1376 clearCanvas();
1368 didDraw(dirtyRect); 1377 c->strokeRect(rect);
1378 didDraw(rect);
1379 } else {
1380 FloatRect boundingRect = rect;
1381 boundingRect.inflate(state().m_lineWidth / 2);
1382 FloatRect dirtyRect;
1383 if (computeDirtyRect(boundingRect, &dirtyRect)) {
1384 c->strokeRect(rect, state().m_lineWidth);
1385 didDraw(dirtyRect);
1386 }
1369 } 1387 }
1370 } 1388 }
1371 1389
1372 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) 1390 void CanvasRenderingContext2D::setShadow(float width, float height, float blur)
1373 { 1391 {
1374 setShadow(FloatSize(width, height), blur, Color::transparent); 1392 setShadow(FloatSize(width, height), blur, Color::transparent);
1375 } 1393 }
1376 1394
1377 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) 1395 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color)
1378 { 1396 {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 1665
1648 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op) 1666 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedDrawImage( T* image, const FloatRect& dest, const FloatRect& src, CompositeOperator op)
1649 { 1667 {
1650 ASSERT(isFullCanvasCompositeMode(op)); 1668 ASSERT(isFullCanvasCompositeMode(op));
1651 1669
1652 drawingContext()->beginLayer(1, op); 1670 drawingContext()->beginLayer(1, op);
1653 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver); 1671 drawImageToContext(image, drawingContext(), dest, src, CompositeSourceOver);
1654 drawingContext()->endLayer(); 1672 drawingContext()->endLayer();
1655 } 1673 }
1656 1674
1657 static void fillPrimitive(const FloatRect& rect, GraphicsContext* context) 1675 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 { 1676 {
1669 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); 1677 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
1670 1678
1671 GraphicsContext* c = drawingContext(); 1679 GraphicsContext* c = drawingContext();
1672 ASSERT(c); 1680 ASSERT(c);
1673 c->beginLayer(1, state().m_globalComposite); 1681 c->beginLayer(1, state().m_globalComposite);
1674 CompositeOperator previousOperator = c->compositeOperation(); 1682 CompositeOperator previousOperator = c->compositeOperation();
1675 c->setCompositeOperation(CompositeSourceOver); 1683 c->setCompositeOperation(CompositeSourceOver);
1676 fillPrimitive(area, c); 1684 functor(area, c);
1677 c->setCompositeOperation(previousOperator); 1685 c->setCompositeOperation(previousOperator);
1678 c->endLayer(); 1686 c->endLayer();
1679 } 1687 }
1680 1688
1681 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) 1689 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState)
1682 { 1690 {
1683 if (!std::isfinite(x0)) 1691 if (!std::isfinite(x0))
1684 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); 1692 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0"));
1685 else if (!std::isfinite(y0)) 1693 else if (!std::isfinite(y0))
1686 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0")); 1694 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0"));
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 c->setAlphaAsFloat(1.0); 2449 c->setAlphaAsFloat(1.0);
2442 c->clearShadow(); 2450 c->clearShadow();
2443 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2451 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal);
2444 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2452 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2445 c->restore(); 2453 c->restore();
2446 2454
2447 didDraw(dirtyRect); 2455 didDraw(dirtyRect);
2448 } 2456 }
2449 2457
2450 } // namespace WebCore 2458 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | Source/platform/graphics/GraphicsContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698