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

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: fixed 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 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 if (path.isEmpty()) { 1049 if (path.isEmpty()) {
1050 return; 1050 return;
1051 } 1051 }
1052 GraphicsContext* c = drawingContext(); 1052 GraphicsContext* c = drawingContext();
1053 if (!c) { 1053 if (!c) {
1054 return; 1054 return;
1055 } 1055 }
1056 if (!state().m_invertibleCTM) { 1056 if (!state().m_invertibleCTM) {
1057 return; 1057 return;
1058 } 1058 }
1059 FloatRect clipBounds;
1060 if (!c->getTransformedClipBounds(&clipBounds))
1061 return;
1059 1062
1060 // If gradient size is zero, then paint nothing. 1063 // If gradient size is zero, then paint nothing.
1061 Gradient* gradient = c->strokeGradient(); 1064 Gradient* gradient = c->strokeGradient();
1062 if (gradient && gradient->isZeroSize()) { 1065 if (gradient && gradient->isZeroSize()) {
1063 return; 1066 return;
1064 } 1067 }
1065 1068
1066 FloatRect bounds = path.boundingRect(); 1069 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1067 inflateStrokeRect(bounds); 1070 fullCanvasCompositedStroke(path);
1068 FloatRect dirtyRect; 1071 didDraw(clipBounds);
1069 if (computeDirtyRect(bounds, &dirtyRect)) { 1072 } else if (state().m_globalComposite == CompositeCopy) {
1073 clearCanvas();
1070 c->strokePath(path); 1074 c->strokePath(path);
1071 didDraw(dirtyRect); 1075 didDraw(clipBounds);
1076 } else {
1077 FloatRect bounds = path.boundingRect();
1078 inflateStrokeRect(bounds);
1079 FloatRect dirtyRect;
1080 if (computeDirtyRect(bounds, &dirtyRect)) {
1081 c->strokePath(path);
1082 didDraw(dirtyRect);
1083 }
1072 } 1084 }
1073 } 1085 }
1074 1086
1075 void CanvasRenderingContext2D::stroke() 1087 void CanvasRenderingContext2D::stroke()
1076 { 1088 {
1077 strokeInternal(m_path); 1089 strokeInternal(m_path);
1078 } 1090 }
1079 1091
1080 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State) 1092 void CanvasRenderingContext2D::stroke(Path2D* domPath, ExceptionState& exception State)
1081 { 1093 {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 return; 1350 return;
1339 1351
1340 if (!(state().m_lineWidth >= 0)) 1352 if (!(state().m_lineWidth >= 0))
1341 return; 1353 return;
1342 1354
1343 GraphicsContext* c = drawingContext(); 1355 GraphicsContext* c = drawingContext();
1344 if (!c) 1356 if (!c)
1345 return; 1357 return;
1346 if (!state().m_invertibleCTM) 1358 if (!state().m_invertibleCTM)
1347 return; 1359 return;
1360 FloatRect clipBounds;
1361 if (!c->getTransformedClipBounds(&clipBounds))
1362 return;
1348 1363
1349 // If gradient size is zero, then paint nothing. 1364 // If gradient size is zero, then paint nothing.
1350 Gradient* gradient = c->strokeGradient(); 1365 Gradient* gradient = c->strokeGradient();
1351 if (gradient && gradient->isZeroSize()) 1366 if (gradient && gradient->isZeroSize())
1352 return; 1367 return;
1353 1368
1354 FloatRect rect(x, y, width, height); 1369 FloatRect rect(x, y, width, height);
1355 1370
1356 FloatRect boundingRect = rect; 1371 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
1357 boundingRect.inflate(state().m_lineWidth / 2); 1372 fullCanvasCompositedStroke(rect);
1358 FloatRect dirtyRect; 1373 didDraw(clipBounds);
1359 if (computeDirtyRect(boundingRect, &dirtyRect)) { 1374 } else if (state().m_globalComposite == CompositeCopy) {
1360 c->strokeRect(rect, state().m_lineWidth); 1375 clearCanvas();
1361 didDraw(dirtyRect); 1376 c->strokeRect(rect);
1377 didDraw(clipBounds);
1378 } else {
1379 FloatRect boundingRect = rect;
1380 boundingRect.inflate(state().m_lineWidth / 2);
1381 FloatRect dirtyRect;
1382 if (computeDirtyRect(boundingRect, &dirtyRect)) {
1383 c->strokeRect(rect);
1384 didDraw(dirtyRect);
1385 }
1362 } 1386 }
1363 } 1387 }
1364 1388
1365 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) 1389 void CanvasRenderingContext2D::setShadow(float width, float height, float blur)
1366 { 1390 {
1367 setShadow(FloatSize(width, height), blur, Color::transparent); 1391 setShadow(FloatSize(width, height), blur, Color::transparent);
1368 } 1392 }
1369 1393
1370 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) 1394 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color)
1371 { 1395 {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 GraphicsContext* c = drawingContext(); 1688 GraphicsContext* c = drawingContext();
1665 ASSERT(c); 1689 ASSERT(c);
1666 c->beginLayer(1, state().m_globalComposite); 1690 c->beginLayer(1, state().m_globalComposite);
1667 CompositeOperator previousOperator = c->compositeOperation(); 1691 CompositeOperator previousOperator = c->compositeOperation();
1668 c->setCompositeOperation(CompositeSourceOver); 1692 c->setCompositeOperation(CompositeSourceOver);
1669 fillPrimitive(area, c); 1693 fillPrimitive(area, c);
1670 c->setCompositeOperation(previousOperator); 1694 c->setCompositeOperation(previousOperator);
1671 c->endLayer(); 1695 c->endLayer();
1672 } 1696 }
1673 1697
1698 static void strokePrimitive(const FloatRect& rect, GraphicsContext* context)
1699 {
1700 context->strokeRect(rect);
1701 }
1702
1703 static void strokePrimitive(const Path& path, GraphicsContext* context)
1704 {
1705 context->strokePath(path);
1706 }
1707
1708 template<class T> void CanvasRenderingContext2D::fullCanvasCompositedStroke(cons t T& area)
1709 {
1710 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
1711
1712 GraphicsContext* c = drawingContext();
1713 ASSERT(c);
1714 c->beginLayer(1, state().m_globalComposite);
1715 CompositeOperator previousOperator = c->compositeOperation();
1716 c->setCompositeOperation(CompositeSourceOver);
1717 strokePrimitive(area, c);
1718 c->setCompositeOperation(previousOperator);
1719 c->endLayer();
1720 }
1721
1674 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState) 1722 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1, ExceptionState& exceptionState)
1675 { 1723 {
1676 if (!std::isfinite(x0)) 1724 if (!std::isfinite(x0))
1677 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0")); 1725 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x0, "x0"));
1678 else if (!std::isfinite(y0)) 1726 else if (!std::isfinite(y0))
1679 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0")); 1727 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y0, "y0"));
1680 else if (!std::isfinite(x1)) 1728 else if (!std::isfinite(x1))
1681 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x1, "x1")); 1729 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(x1, "x1"));
1682 else if (!std::isfinite(y1)) 1730 else if (!std::isfinite(y1))
1683 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y1, "y1")); 1731 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::n otAFiniteNumber(y1, "y1"));
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 c->setAlphaAsFloat(1.0); 2482 c->setAlphaAsFloat(1.0);
2435 c->clearShadow(); 2483 c->clearShadow();
2436 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2484 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal);
2437 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2485 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2438 c->restore(); 2486 c->restore();
2439 2487
2440 didDraw(dirtyRect); 2488 didDraw(dirtyRect);
2441 } 2489 }
2442 2490
2443 } // namespace WebCore 2491 } // 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