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

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

Issue 137353004: Add versions of stroke, fill, and clip that take a Path parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reorder IDL, so that the stricter check for Path comes before the less strict check for an enum. Created 6 years, 10 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 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 if (windingRuleString == "nonzero") 863 if (windingRuleString == "nonzero")
864 windRule = RULE_NONZERO; 864 windRule = RULE_NONZERO;
865 else if (windingRuleString == "evenodd") 865 else if (windingRuleString == "evenodd")
866 windRule = RULE_EVENODD; 866 windRule = RULE_EVENODD;
867 else 867 else
868 return false; 868 return false;
869 869
870 return true; 870 return true;
871 } 871 }
872 872
873 void CanvasRenderingContext2D::fillInternal(const Path& path, const String& wind ingRuleString)
874 {
875 if (path.isEmpty()) {
876 return;
877 }
878 GraphicsContext* c = drawingContext();
879 if (!c) {
880 return;
881 }
882 if (!state().m_invertibleCTM) {
883 return;
884 }
885 FloatRect clipBounds;
886 if (!drawingContext()->getTransformedClipBounds(&clipBounds)) {
887 return;
888 }
889
890 // If gradient size is zero, then paint nothing.
891 Gradient* gradient = c->fillGradient();
892 if (gradient && gradient->isZeroSize()) {
893 return;
894 }
895
896 WindRule windRule = c->fillRule();
897 WindRule newWindRule = RULE_NONZERO;
898 if (!parseWinding(windingRuleString, newWindRule)) {
899 return;
900 }
901 c->setFillRule(newWindRule);
902
903 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
904 fullCanvasCompositedFill(path);
905 didDraw(clipBounds);
906 } else if (state().m_globalComposite == CompositeCopy) {
907 clearCanvas();
908 c->fillPath(path);
909 didDraw(clipBounds);
910 } else {
911 FloatRect dirtyRect;
912 if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) {
913 c->fillPath(path);
914 didDraw(dirtyRect);
915 }
916 }
917
918 c->setFillRule(windRule);
919 }
920
873 void CanvasRenderingContext2D::fill(const String& windingRuleString) 921 void CanvasRenderingContext2D::fill(const String& windingRuleString)
874 { 922 {
923 fillInternal(m_path, windingRuleString);
924 }
925
926 void CanvasRenderingContext2D::fill(DOMPath* domPath, const String& windingRuleS tring)
927 {
928 fillInternal(domPath->path(), windingRuleString);
929 }
930
931 void CanvasRenderingContext2D::strokeInternal(const Path& path)
932 {
933 if (path.isEmpty()) {
934 return;
935 }
875 GraphicsContext* c = drawingContext(); 936 GraphicsContext* c = drawingContext();
876 if (!c) 937 if (!c) {
877 return; 938 return;
878 if (!state().m_invertibleCTM) 939 }
940 if (!state().m_invertibleCTM) {
879 return; 941 return;
880 FloatRect clipBounds; 942 }
881 if (!drawingContext()->getTransformedClipBounds(&clipBounds))
882 return;
883 943
884 // If gradient size is zero, then paint nothing. 944 // If gradient size is zero, then paint nothing.
885 Gradient* gradient = c->fillGradient(); 945 Gradient* gradient = c->strokeGradient();
886 if (gradient && gradient->isZeroSize()) 946 if (gradient && gradient->isZeroSize()) {
887 return; 947 return;
948 }
888 949
889 if (!m_path.isEmpty()) { 950 FloatRect bounds = path.boundingRect();
890 WindRule windRule = c->fillRule(); 951 inflateStrokeRect(bounds);
891 WindRule newWindRule = RULE_NONZERO; 952 FloatRect dirtyRect;
892 if (!parseWinding(windingRuleString, newWindRule)) 953 if (computeDirtyRect(bounds, &dirtyRect)) {
893 return; 954 c->strokePath(path);
894 c->setFillRule(newWindRule); 955 didDraw(dirtyRect);
895
896 if (isFullCanvasCompositeMode(state().m_globalComposite)) {
897 fullCanvasCompositedFill(m_path);
898 didDraw(clipBounds);
899 } else if (state().m_globalComposite == CompositeCopy) {
900 clearCanvas();
901 c->fillPath(m_path);
902 didDraw(clipBounds);
903 } else {
904 FloatRect dirtyRect;
905 if (computeDirtyRect(m_path.boundingRect(), clipBounds, &dirtyRect)) {
906 c->fillPath(m_path);
907 didDraw(dirtyRect);
908 }
909 }
910
911 c->setFillRule(windRule);
912 } 956 }
913 } 957 }
914 958
915 void CanvasRenderingContext2D::stroke() 959 void CanvasRenderingContext2D::stroke()
916 { 960 {
961 strokeInternal(m_path);
962 }
963
964 void CanvasRenderingContext2D::stroke(DOMPath* domPath)
965 {
966 strokeInternal(domPath->path());
967 }
968
969 void CanvasRenderingContext2D::clipInternal(const Path& path, const String& wind ingRuleString)
970 {
917 GraphicsContext* c = drawingContext(); 971 GraphicsContext* c = drawingContext();
918 if (!c) 972 if (!c) {
919 return; 973 return;
920 if (!state().m_invertibleCTM) 974 }
975 if (!state().m_invertibleCTM) {
921 return; 976 return;
977 }
922 978
923 // If gradient size is zero, then paint nothing. 979 WindRule newWindRule = RULE_NONZERO;
924 Gradient* gradient = c->strokeGradient(); 980 if (!parseWinding(windingRuleString, newWindRule)) {
925 if (gradient && gradient->isZeroSize())
926 return; 981 return;
982 }
927 983
928 if (!m_path.isEmpty()) { 984 realizeSaves();
929 FloatRect bounds = m_path.boundingRect(); 985 c->canvasClip(path, newWindRule);
930 inflateStrokeRect(bounds);
931 FloatRect dirtyRect;
932 if (computeDirtyRect(bounds, &dirtyRect)) {
933 c->strokePath(m_path);
934 didDraw(dirtyRect);
935 }
936 }
937 } 986 }
938 987
939 void CanvasRenderingContext2D::clip(const String& windingRuleString) 988 void CanvasRenderingContext2D::clip(const String& windingRuleString)
940 { 989 {
941 GraphicsContext* c = drawingContext(); 990 clipInternal(m_path, windingRuleString);
942 if (!c) 991 }
943 return;
944 if (!state().m_invertibleCTM)
945 return;
946 992
947 WindRule newWindRule = RULE_NONZERO; 993 void CanvasRenderingContext2D::clip(DOMPath* domPath, const String& windingRuleS tring)
948 if (!parseWinding(windingRuleString, newWindRule)) 994 {
949 return; 995 clipInternal(domPath->path(), windingRuleString);
950
951 realizeSaves();
952 c->canvasClip(m_path, newWindRule);
953 } 996 }
954 997
955 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString) 998 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
956 { 999 {
957 GraphicsContext* c = drawingContext(); 1000 GraphicsContext* c = drawingContext();
958 if (!c) 1001 if (!c)
959 return false; 1002 return false;
960 if (!state().m_invertibleCTM) 1003 if (!state().m_invertibleCTM)
961 return false; 1004 return false;
962 1005
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 const int focusRingWidth = 5; 2435 const int focusRingWidth = 5;
2393 const int focusRingOutline = 0; 2436 const int focusRingOutline = 0;
2394 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2437 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2395 2438
2396 c->restore(); 2439 c->restore();
2397 2440
2398 didDraw(dirtyRect); 2441 didDraw(dirtyRect);
2399 } 2442 }
2400 2443
2401 } // namespace WebCore 2444 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | Source/core/html/canvas/CanvasRenderingContext2D.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698