| 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 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 DashArray convertedLineDash(lineDash.size()); | 117 DashArray convertedLineDash(lineDash.size()); |
| 118 for (size_t i = 0; i < lineDash.size(); ++i) | 118 for (size_t i = 0; i < lineDash.size(); ++i) |
| 119 convertedLineDash[i] = static_cast<DashArrayElement>(lineDash[i]); | 119 convertedLineDash[i] = static_cast<DashArrayElement>(lineDash[i]); |
| 120 c->setLineDash(convertedLineDash, m_canvasContext->lineDashOffset()); | 120 c->setLineDash(convertedLineDash, m_canvasContext->lineDashOffset()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 CanvasRenderingContext2D* m_canvasContext; | 124 CanvasRenderingContext2D* m_canvasContext; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo
ol usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode) | 127 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, bo
ol usesCSSCompatibilityParseMode) |
| 128 : CanvasRenderingContext(canvas) | 128 : CanvasRenderingContext(canvas) |
| 129 , m_stateStack(1) | 129 , m_stateStack(1) |
| 130 , m_unrealizedSaveCount(0) | 130 , m_unrealizedSaveCount(0) |
| 131 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) | 131 , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) |
| 132 #if ENABLE(DASHBOARD_SUPPORT) | |
| 133 , m_usesDashboardCompatibilityMode(usesDashboardCompatibilityMode) | |
| 134 #endif | |
| 135 { | 132 { |
| 136 #if !ENABLE(DASHBOARD_SUPPORT) | |
| 137 ASSERT_UNUSED(usesDashboardCompatibilityMode, !usesDashboardCompatibilityMod
e); | |
| 138 #endif | |
| 139 } | 133 } |
| 140 | 134 |
| 141 void CanvasRenderingContext2D::unwindStateStack() | 135 void CanvasRenderingContext2D::unwindStateStack() |
| 142 { | 136 { |
| 143 // Ensure that the state stack in the ImageBuffer's context | 137 // Ensure that the state stack in the ImageBuffer's context |
| 144 // is cleared before destruction, to avoid assertions in the | 138 // is cleared before destruction, to avoid assertions in the |
| 145 // GraphicsContext dtor. | 139 // GraphicsContext dtor. |
| 146 if (size_t stackSize = m_stateStack.size()) { | 140 if (size_t stackSize = m_stateStack.size()) { |
| 147 if (GraphicsContext* context = canvas()->existingDrawingContext()) { | 141 if (GraphicsContext* context = canvas()->existingDrawingContext()) { |
| 148 while (--stackSize) | 142 while (--stackSize) |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 } | 882 } |
| 889 | 883 |
| 890 if (height < 0) { | 884 if (height < 0) { |
| 891 height = -height; | 885 height = -height; |
| 892 y -= height; | 886 y -= height; |
| 893 } | 887 } |
| 894 | 888 |
| 895 return true; | 889 return true; |
| 896 } | 890 } |
| 897 | 891 |
| 898 #if ENABLE(DASHBOARD_SUPPORT) | |
| 899 void CanvasRenderingContext2D::clearPathForDashboardBackwardCompatibilityMode() | |
| 900 { | |
| 901 if (m_usesDashboardCompatibilityMode) | |
| 902 m_path.clear(); | |
| 903 } | |
| 904 #endif | |
| 905 | |
| 906 static bool isFullCanvasCompositeMode(CompositeOperator op) | 892 static bool isFullCanvasCompositeMode(CompositeOperator op) |
| 907 { | 893 { |
| 908 // See 4.8.11.1.3 Compositing | 894 // See 4.8.11.1.3 Compositing |
| 909 // CompositeSourceAtop and CompositeDestinationOut are not listed here as th
e platforms already | 895 // CompositeSourceAtop and CompositeDestinationOut are not listed here as th
e platforms already |
| 910 // implement the specification's behavior. | 896 // implement the specification's behavior. |
| 911 return op == CompositeSourceIn || op == CompositeSourceOut || op == Composit
eDestinationIn || op == CompositeDestinationAtop; | 897 return op == CompositeSourceIn || op == CompositeSourceOut || op == Composit
eDestinationIn || op == CompositeDestinationAtop; |
| 912 } | 898 } |
| 913 | 899 |
| 914 static bool parseWinding(const String& windingRuleString, WindRule& windRule) | 900 static bool parseWinding(const String& windingRuleString, WindRule& windRule) |
| 915 { | 901 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 clearCanvas(); | 936 clearCanvas(); |
| 951 c->fillPath(m_path); | 937 c->fillPath(m_path); |
| 952 didDrawEntireCanvas(); | 938 didDrawEntireCanvas(); |
| 953 } else { | 939 } else { |
| 954 c->fillPath(m_path); | 940 c->fillPath(m_path); |
| 955 didDraw(m_path.fastBoundingRect()); | 941 didDraw(m_path.fastBoundingRect()); |
| 956 } | 942 } |
| 957 | 943 |
| 958 c->setFillRule(windRule); | 944 c->setFillRule(windRule); |
| 959 } | 945 } |
| 960 | |
| 961 #if ENABLE(DASHBOARD_SUPPORT) | |
| 962 clearPathForDashboardBackwardCompatibilityMode(); | |
| 963 #endif | |
| 964 } | 946 } |
| 965 | 947 |
| 966 void CanvasRenderingContext2D::stroke() | 948 void CanvasRenderingContext2D::stroke() |
| 967 { | 949 { |
| 968 GraphicsContext* c = drawingContext(); | 950 GraphicsContext* c = drawingContext(); |
| 969 if (!c) | 951 if (!c) |
| 970 return; | 952 return; |
| 971 if (!state().m_invertibleCTM) | 953 if (!state().m_invertibleCTM) |
| 972 return; | 954 return; |
| 973 | 955 |
| 974 // If gradient size is zero, then paint nothing. | 956 // If gradient size is zero, then paint nothing. |
| 975 Gradient* gradient = c->strokeGradient(); | 957 Gradient* gradient = c->strokeGradient(); |
| 976 if (gradient && gradient->isZeroSize()) | 958 if (gradient && gradient->isZeroSize()) |
| 977 return; | 959 return; |
| 978 | 960 |
| 979 if (!m_path.isEmpty()) { | 961 if (!m_path.isEmpty()) { |
| 980 FloatRect dirtyRect = m_path.fastBoundingRect(); | 962 FloatRect dirtyRect = m_path.fastBoundingRect(); |
| 981 inflateStrokeRect(dirtyRect); | 963 inflateStrokeRect(dirtyRect); |
| 982 | 964 |
| 983 c->strokePath(m_path); | 965 c->strokePath(m_path); |
| 984 didDraw(dirtyRect); | 966 didDraw(dirtyRect); |
| 985 } | 967 } |
| 986 | |
| 987 #if ENABLE(DASHBOARD_SUPPORT) | |
| 988 clearPathForDashboardBackwardCompatibilityMode(); | |
| 989 #endif | |
| 990 } | 968 } |
| 991 | 969 |
| 992 void CanvasRenderingContext2D::clip(const String& windingRuleString) | 970 void CanvasRenderingContext2D::clip(const String& windingRuleString) |
| 993 { | 971 { |
| 994 GraphicsContext* c = drawingContext(); | 972 GraphicsContext* c = drawingContext(); |
| 995 if (!c) | 973 if (!c) |
| 996 return; | 974 return; |
| 997 if (!state().m_invertibleCTM) | 975 if (!state().m_invertibleCTM) |
| 998 return; | 976 return; |
| 999 | 977 |
| 1000 WindRule newWindRule = RULE_NONZERO; | 978 WindRule newWindRule = RULE_NONZERO; |
| 1001 if (!parseWinding(windingRuleString, newWindRule)) | 979 if (!parseWinding(windingRuleString, newWindRule)) |
| 1002 return; | 980 return; |
| 1003 | 981 |
| 1004 realizeSaves(); | 982 realizeSaves(); |
| 1005 c->canvasClip(m_path, newWindRule); | 983 c->canvasClip(m_path, newWindRule); |
| 1006 | |
| 1007 #if ENABLE(DASHBOARD_SUPPORT) | |
| 1008 clearPathForDashboardBackwardCompatibilityMode(); | |
| 1009 #endif | |
| 1010 } | 984 } |
| 1011 | 985 |
| 1012 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const
String& windingRuleString) | 986 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const
String& windingRuleString) |
| 1013 { | 987 { |
| 1014 GraphicsContext* c = drawingContext(); | 988 GraphicsContext* c = drawingContext(); |
| 1015 if (!c) | 989 if (!c) |
| 1016 return false; | 990 return false; |
| 1017 if (!state().m_invertibleCTM) | 991 if (!state().m_invertibleCTM) |
| 1018 return false; | 992 return false; |
| 1019 | 993 |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 Path path = transformAreaToDevice(area); | 1635 Path path = transformAreaToDevice(area); |
| 1662 path.translate(FloatSize(-bufferRect.x(), -bufferRect.y())); | 1636 path.translate(FloatSize(-bufferRect.x(), -bufferRect.y())); |
| 1663 | 1637 |
| 1664 buffer->context()->setCompositeOperation(CompositeSourceOver); | 1638 buffer->context()->setCompositeOperation(CompositeSourceOver); |
| 1665 state().m_fillStyle->applyFillColor(buffer->context()); | 1639 state().m_fillStyle->applyFillColor(buffer->context()); |
| 1666 buffer->context()->fillPath(path); | 1640 buffer->context()->fillPath(path); |
| 1667 | 1641 |
| 1668 compositeBuffer(buffer.get(), bufferRect, state().m_globalComposite); | 1642 compositeBuffer(buffer.get(), bufferRect, state().m_globalComposite); |
| 1669 } | 1643 } |
| 1670 | 1644 |
| 1671 void CanvasRenderingContext2D::prepareGradientForDashboard(CanvasGradient* gradi
ent) const | |
| 1672 { | |
| 1673 #if ENABLE(DASHBOARD_SUPPORT) | |
| 1674 if (m_usesDashboardCompatibilityMode) | |
| 1675 gradient->setDashboardCompatibilityMode(); | |
| 1676 #else | |
| 1677 UNUSED_PARAM(gradient); | |
| 1678 #endif | |
| 1679 } | |
| 1680 | |
| 1681 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float
x0, float y0, float x1, float y1, ExceptionCode& ec) | 1645 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float
x0, float y0, float x1, float y1, ExceptionCode& ec) |
| 1682 { | 1646 { |
| 1683 if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(x1) || !std::
isfinite(y1)) { | 1647 if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(x1) || !std::
isfinite(y1)) { |
| 1684 ec = NOT_SUPPORTED_ERR; | 1648 ec = NOT_SUPPORTED_ERR; |
| 1685 return 0; | 1649 return 0; |
| 1686 } | 1650 } |
| 1687 | 1651 |
| 1688 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0),
FloatPoint(x1, y1)); | 1652 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0),
FloatPoint(x1, y1)); |
| 1689 prepareGradientForDashboard(gradient.get()); | |
| 1690 return gradient.release(); | 1653 return gradient.release(); |
| 1691 } | 1654 } |
| 1692 | 1655 |
| 1693 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float
x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode& ec) | 1656 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float
x0, float y0, float r0, float x1, float y1, float r1, ExceptionCode& ec) |
| 1694 { | 1657 { |
| 1695 if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(r0) || !std::
isfinite(x1) || !std::isfinite(y1) || !std::isfinite(r1)) { | 1658 if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(r0) || !std::
isfinite(x1) || !std::isfinite(y1) || !std::isfinite(r1)) { |
| 1696 ec = NOT_SUPPORTED_ERR; | 1659 ec = NOT_SUPPORTED_ERR; |
| 1697 return 0; | 1660 return 0; |
| 1698 } | 1661 } |
| 1699 | 1662 |
| 1700 if (r0 < 0 || r1 < 0) { | 1663 if (r0 < 0 || r1 < 0) { |
| 1701 ec = INDEX_SIZE_ERR; | 1664 ec = INDEX_SIZE_ERR; |
| 1702 return 0; | 1665 return 0; |
| 1703 } | 1666 } |
| 1704 | 1667 |
| 1705 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0),
r0, FloatPoint(x1, y1), r1); | 1668 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0),
r0, FloatPoint(x1, y1), r1); |
| 1706 prepareGradientForDashboard(gradient.get()); | |
| 1707 return gradient.release(); | 1669 return gradient.release(); |
| 1708 } | 1670 } |
| 1709 | 1671 |
| 1710 PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
nt* image, | 1672 PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(HTMLImageEleme
nt* image, |
| 1711 const String& repetitionType, ExceptionCode& ec) | 1673 const String& repetitionType, ExceptionCode& ec) |
| 1712 { | 1674 { |
| 1713 if (!image) { | 1675 if (!image) { |
| 1714 ec = TYPE_MISMATCH_ERR; | 1676 ec = TYPE_MISMATCH_ERR; |
| 1715 return 0; | 1677 return 0; |
| 1716 } | 1678 } |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2353 return; | 2315 return; |
| 2354 | 2316 |
| 2355 realizeSaves(); | 2317 realizeSaves(); |
| 2356 modifiableState().m_imageSmoothingEnabled = enabled; | 2318 modifiableState().m_imageSmoothingEnabled = enabled; |
| 2357 GraphicsContext* c = drawingContext(); | 2319 GraphicsContext* c = drawingContext(); |
| 2358 if (c) | 2320 if (c) |
| 2359 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality :
InterpolationNone); | 2321 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality :
InterpolationNone); |
| 2360 } | 2322 } |
| 2361 | 2323 |
| 2362 } // namespace WebCore | 2324 } // namespace WebCore |
| OLD | NEW |