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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index 2cd9089ad9828e9810c7662a74b118c34507b769..45c9f4dd579f97d4a79c4c7ceb83d3be101b10bc 100644
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -870,86 +870,129 @@ static bool parseWinding(const String& windingRuleString, WindRule& windRule)
return true;
}
-void CanvasRenderingContext2D::fill(const String& windingRuleString)
+void CanvasRenderingContext2D::fillInternal(const Path& path, const String& windingRuleString)
{
+ if (path.isEmpty()) {
+ return;
+ }
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
FloatRect clipBounds;
- if (!drawingContext()->getTransformedClipBounds(&clipBounds))
+ if (!drawingContext()->getTransformedClipBounds(&clipBounds)) {
return;
+ }
// If gradient size is zero, then paint nothing.
Gradient* gradient = c->fillGradient();
- if (gradient && gradient->isZeroSize())
+ if (gradient && gradient->isZeroSize()) {
return;
+ }
- if (!m_path.isEmpty()) {
- WindRule windRule = c->fillRule();
- WindRule newWindRule = RULE_NONZERO;
- if (!parseWinding(windingRuleString, newWindRule))
- return;
- c->setFillRule(newWindRule);
-
- if (isFullCanvasCompositeMode(state().m_globalComposite)) {
- fullCanvasCompositedFill(m_path);
- didDraw(clipBounds);
- } else if (state().m_globalComposite == CompositeCopy) {
- clearCanvas();
- c->fillPath(m_path);
- didDraw(clipBounds);
- } else {
- FloatRect dirtyRect;
- if (computeDirtyRect(m_path.boundingRect(), clipBounds, &dirtyRect)) {
- c->fillPath(m_path);
- didDraw(dirtyRect);
- }
- }
+ WindRule windRule = c->fillRule();
+ WindRule newWindRule = RULE_NONZERO;
+ if (!parseWinding(windingRuleString, newWindRule)) {
+ return;
+ }
+ c->setFillRule(newWindRule);
- c->setFillRule(windRule);
+ if (isFullCanvasCompositeMode(state().m_globalComposite)) {
+ fullCanvasCompositedFill(path);
+ didDraw(clipBounds);
+ } else if (state().m_globalComposite == CompositeCopy) {
+ clearCanvas();
+ c->fillPath(path);
+ didDraw(clipBounds);
+ } else {
+ FloatRect dirtyRect;
+ if (computeDirtyRect(path.boundingRect(), clipBounds, &dirtyRect)) {
+ c->fillPath(path);
+ didDraw(dirtyRect);
+ }
}
+
+ c->setFillRule(windRule);
}
-void CanvasRenderingContext2D::stroke()
+void CanvasRenderingContext2D::fill(const String& windingRuleString)
+{
+ fillInternal(m_path, windingRuleString);
+}
+
+void CanvasRenderingContext2D::fill(DOMPath* domPath, const String& windingRuleString)
+{
+ fillInternal(domPath->path(), windingRuleString);
+}
+
+void CanvasRenderingContext2D::strokeInternal(const Path& path)
{
+ if (path.isEmpty()) {
+ return;
+ }
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
// If gradient size is zero, then paint nothing.
Gradient* gradient = c->strokeGradient();
- if (gradient && gradient->isZeroSize())
+ if (gradient && gradient->isZeroSize()) {
return;
+ }
- if (!m_path.isEmpty()) {
- FloatRect bounds = m_path.boundingRect();
- inflateStrokeRect(bounds);
- FloatRect dirtyRect;
- if (computeDirtyRect(bounds, &dirtyRect)) {
- c->strokePath(m_path);
- didDraw(dirtyRect);
- }
+ FloatRect bounds = path.boundingRect();
+ inflateStrokeRect(bounds);
+ FloatRect dirtyRect;
+ if (computeDirtyRect(bounds, &dirtyRect)) {
+ c->strokePath(path);
+ didDraw(dirtyRect);
}
}
-void CanvasRenderingContext2D::clip(const String& windingRuleString)
+void CanvasRenderingContext2D::stroke()
+{
+ strokeInternal(m_path);
+}
+
+void CanvasRenderingContext2D::stroke(DOMPath* domPath)
+{
+ strokeInternal(domPath->path());
+}
+
+void CanvasRenderingContext2D::clipInternal(const Path& path, const String& windingRuleString)
{
GraphicsContext* c = drawingContext();
- if (!c)
+ if (!c) {
return;
- if (!state().m_invertibleCTM)
+ }
+ if (!state().m_invertibleCTM) {
return;
+ }
WindRule newWindRule = RULE_NONZERO;
- if (!parseWinding(windingRuleString, newWindRule))
+ if (!parseWinding(windingRuleString, newWindRule)) {
return;
+ }
realizeSaves();
- c->canvasClip(m_path, newWindRule);
+ c->canvasClip(path, newWindRule);
+}
+
+void CanvasRenderingContext2D::clip(const String& windingRuleString)
+{
+ clipInternal(m_path, windingRuleString);
+}
+
+void CanvasRenderingContext2D::clip(DOMPath* domPath, const String& windingRuleString)
+{
+ clipInternal(domPath->path(), windingRuleString);
}
bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
« 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