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

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

Issue 658603002: 2D canvas: fix shadow rendering with compositing modes that require temp layers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: comment fix Created 6 years, 2 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 | Annotate | Revision Log
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 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 bool wasDrawingShadows = shouldDrawShadows(); 1403 bool wasDrawingShadows = shouldDrawShadows();
1404 realizeSaves(0); 1404 realizeSaves(0);
1405 modifiableState().m_shadowOffset = offset; 1405 modifiableState().m_shadowOffset = offset;
1406 modifiableState().m_shadowBlur = blur; 1406 modifiableState().m_shadowBlur = blur;
1407 modifiableState().m_shadowColor = color; 1407 modifiableState().m_shadowColor = color;
1408 if (!wasDrawingShadows && !shouldDrawShadows()) 1408 if (!wasDrawingShadows && !shouldDrawShadows())
1409 return; 1409 return;
1410 applyShadow(); 1410 applyShadow();
1411 } 1411 }
1412 1412
1413 void CanvasRenderingContext2D::applyShadow() 1413 void CanvasRenderingContext2D::applyShadow(ShadowMode shadowMode)
1414 { 1414 {
1415 GraphicsContext* c = drawingContext(); 1415 GraphicsContext* c = drawingContext();
1416 if (!c) 1416 if (!c)
1417 return; 1417 return;
1418 1418
1419 if (shouldDrawShadows()) { 1419 if (shouldDrawShadows()) {
1420 c->setShadow(state().m_shadowOffset, state().m_shadowBlur, state().m_sha dowColor, 1420 c->setShadow(state().m_shadowOffset, state().m_shadowBlur, state().m_sha dowColor,
1421 DrawLooperBuilder::ShadowIgnoresTransforms); 1421 DrawLooperBuilder::ShadowIgnoresTransforms, DrawLooperBuilder::Shado wRespectsAlpha, shadowMode);
1422 } else { 1422 } else {
1423 c->clearShadow(); 1423 c->clearShadow();
1424 } 1424 }
1425 } 1425 }
1426 1426
1427 bool CanvasRenderingContext2D::shouldDrawShadows() const 1427 bool CanvasRenderingContext2D::shouldDrawShadows() const
1428 { 1428 {
1429 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat e().m_shadowOffset.isZero()); 1429 return alphaChannel(state().m_shadowColor) && (state().m_shadowBlur || !stat e().m_shadowOffset.isZero());
1430 } 1430 }
1431 1431
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 { 1641 {
1642 context->strokePath(path); 1642 context->strokePath(path);
1643 } 1643 }
1644 1644
1645 template<CanvasRenderingContext2D::DrawingType drawingType, class T> void Canvas RenderingContext2D::fullCanvasCompositedDraw(const T& area) 1645 template<CanvasRenderingContext2D::DrawingType drawingType, class T> void Canvas RenderingContext2D::fullCanvasCompositedDraw(const T& area)
1646 { 1646 {
1647 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite)); 1647 ASSERT(isFullCanvasCompositeMode(state().m_globalComposite));
1648 1648
1649 GraphicsContext* c = drawingContext(); 1649 GraphicsContext* c = drawingContext();
1650 ASSERT(c); 1650 ASSERT(c);
1651
1652 CompositeOperator previousOperator = c->compositeOperation();
1653 if (shouldDrawShadows()) {
1654 // unroll into two independently composited passes if drawing shadows
1655 c->beginLayer(1, state().m_globalComposite);
1656 c->setCompositeOperation(CompositeSourceOver);
1657 applyShadow(DrawShadowOnly);
1658 if (drawingType == Fill) {
1659 fillPrimitive(area, c);
1660 } else {
1661 strokePrimitive(area, c);
1662 }
1663 c->setCompositeOperation(previousOperator);
1664 c->endLayer();
1665 }
1666
1651 c->beginLayer(1, state().m_globalComposite); 1667 c->beginLayer(1, state().m_globalComposite);
1652 CompositeOperator previousOperator = c->compositeOperation(); 1668 c->clearShadow();
1653 c->setCompositeOperation(CompositeSourceOver); 1669 c->setCompositeOperation(CompositeSourceOver);
1654 if (drawingType == Fill) { 1670 if (drawingType == Fill) {
1655 fillPrimitive(area, c); 1671 fillPrimitive(area, c);
1656 } else { 1672 } else {
1657 strokePrimitive(area, c); 1673 strokePrimitive(area, c);
1658 } 1674 }
1659 c->setCompositeOperation(previousOperator); 1675 c->setCompositeOperation(previousOperator);
1660 c->endLayer(); 1676 c->endLayer();
1677 applyShadow(DrawShadowAndForeground); // go back to normal shadows mode
1661 } 1678 }
1662 1679
1663 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGra dient(float x0, float y0, float x1, float y1) 1680 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGra dient(float x0, float y0, float x1, float y1)
1664 { 1681 {
1665 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), FloatPoint(x1, y1)); 1682 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), FloatPoint(x1, y1));
1666 return gradient.release(); 1683 return gradient.release();
1667 } 1684 }
1668 1685
1669 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra dient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionState & exceptionState) 1686 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra dient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionState & exceptionState)
1670 { 1687 {
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 2462
2446 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2463 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2447 { 2464 {
2448 if (m_hitRegionManager) 2465 if (m_hitRegionManager)
2449 return m_hitRegionManager->getHitRegionsCount(); 2466 return m_hitRegionManager->getHitRegionsCount();
2450 2467
2451 return 0; 2468 return 0;
2452 } 2469 }
2453 2470
2454 } // namespace blink 2471 } // namespace blink
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