add new onClip* methods to SkCanvas
https://codereview.chromium.org/183453002/
git-svn-id: http://skia.googlecode.com/svn/trunk@13627 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkCanvasStack.cpp b/src/utils/SkCanvasStack.cpp
index 8951149..d85f34b 100644
--- a/src/utils/SkCanvasStack.cpp
+++ b/src/utils/SkCanvasStack.cpp
@@ -77,25 +77,22 @@
this->SkCanvas::setMatrix(matrix);
}
-bool SkCanvasStack::clipRect(const SkRect& r, SkRegion::Op op, bool aa) {
- bool result = this->INHERITED::clipRect(r, op, aa);
+void SkCanvasStack::onClipRect(const SkRect& r, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->INHERITED::onClipRect(r, op, edgeStyle);
this->clipToZOrderedBounds();
- return result;
}
-bool SkCanvasStack::clipRRect(const SkRRect& rr, SkRegion::Op op, bool aa) {
- bool result = this->INHERITED::clipRRect(rr, op, aa);
+void SkCanvasStack::onClipRRect(const SkRRect& rr, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->INHERITED::onClipRRect(rr, op, edgeStyle);
this->clipToZOrderedBounds();
- return result;
}
-bool SkCanvasStack::clipPath(const SkPath& p, SkRegion::Op op, bool aa) {
- bool result = this->INHERITED::clipPath(p, op, aa);
+void SkCanvasStack::onClipPath(const SkPath& p, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->INHERITED::onClipPath(p, op, edgeStyle);
this->clipToZOrderedBounds();
- return result;
}
-bool SkCanvasStack::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
+void SkCanvasStack::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
SkASSERT(fList.count() == fCanvasData.count());
for (int i = 0; i < fList.count(); ++i) {
SkRegion tempRegion;
@@ -104,5 +101,5 @@
tempRegion.op(fCanvasData[i].requiredClip, SkRegion::kIntersect_Op);
fList[i]->clipRegion(tempRegion, op);
}
- return this->SkCanvas::clipRegion(deviceRgn, op);
+ this->SkCanvas::onClipRegion(deviceRgn, op);
}
diff --git a/src/utils/SkCanvasStack.h b/src/utils/SkCanvasStack.h
index 5311118..ba2fed4 100644
--- a/src/utils/SkCanvasStack.h
+++ b/src/utils/SkCanvasStack.h
@@ -30,11 +30,12 @@
virtual void removeCanvas(SkCanvas*) SK_OVERRIDE { SkDEBUGFAIL("Invalid Op"); }
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
- virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipRegion(const SkRegion& deviceRgn,
- SkRegion::Op) SK_OVERRIDE;
+
+protected:
+ virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
private:
void clipToZOrderedBounds();
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 3911fd0..09494c9 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -789,39 +789,34 @@
this->recordedDrawCommand();
}
-bool SkDeferredCanvas::clipRect(const SkRect& rect,
- SkRegion::Op op,
- bool doAntiAlias) {
- this->drawingCanvas()->clipRect(rect, op, doAntiAlias);
- bool val = this->INHERITED::clipRect(rect, op, doAntiAlias);
+void SkDeferredCanvas::onClipRect(const SkRect& rect,
+ SkRegion::Op op,
+ ClipEdgeStyle edgeStyle) {
+ this->drawingCanvas()->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
+ this->INHERITED::onClipRect(rect, op, edgeStyle);
this->recordedDrawCommand();
- return val;
}
-bool SkDeferredCanvas::clipRRect(const SkRRect& rrect,
- SkRegion::Op op,
- bool doAntiAlias) {
- this->drawingCanvas()->clipRRect(rrect, op, doAntiAlias);
- bool val = this->INHERITED::clipRRect(rrect, op, doAntiAlias);
+void SkDeferredCanvas::onClipRRect(const SkRRect& rrect,
+ SkRegion::Op op,
+ ClipEdgeStyle edgeStyle) {
+ this->drawingCanvas()->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
+ this->INHERITED::onClipRRect(rrect, op, edgeStyle);
this->recordedDrawCommand();
- return val;
}
-bool SkDeferredCanvas::clipPath(const SkPath& path,
- SkRegion::Op op,
- bool doAntiAlias) {
- this->drawingCanvas()->clipPath(path, op, doAntiAlias);
- bool val = this->INHERITED::clipPath(path, op, doAntiAlias);
+void SkDeferredCanvas::onClipPath(const SkPath& path,
+ SkRegion::Op op,
+ ClipEdgeStyle edgeStyle) {
+ this->drawingCanvas()->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
+ this->INHERITED::onClipPath(path, op, edgeStyle);
this->recordedDrawCommand();
- return val;
}
-bool SkDeferredCanvas::clipRegion(const SkRegion& deviceRgn,
- SkRegion::Op op) {
+void SkDeferredCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
this->drawingCanvas()->clipRegion(deviceRgn, op);
- bool val = this->INHERITED::clipRegion(deviceRgn, op);
+ this->INHERITED::onClipRegion(deviceRgn, op);
this->recordedDrawCommand();
- return val;
}
void SkDeferredCanvas::clear(SkColor color) {
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index d768137..4805d62 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -261,40 +261,40 @@
///////////////////////////////////////////////////////////////////////////////
-static const char* bool_to_aastring(bool doAA) {
- return doAA ? "AA" : "BW";
+const char* SkDumpCanvas::EdgeStyleToAAString(ClipEdgeStyle edgeStyle) {
+ return kSoft_ClipEdgeStyle == edgeStyle ? "AA" : "BW";
}
-bool SkDumpCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
+void SkDumpCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
SkString str;
toString(rect, &str);
this->dump(kClip_Verb, NULL, "clipRect(%s %s %s)", str.c_str(), toString(op),
- bool_to_aastring(doAA));
- return this->INHERITED::clipRect(rect, op, doAA);
+ EdgeStyleToAAString(edgeStyle));
+ this->INHERITED::onClipRect(rect, op, edgeStyle);
}
-bool SkDumpCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
+void SkDumpCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
SkString str;
toString(rrect, &str);
this->dump(kClip_Verb, NULL, "clipRRect(%s %s %s)", str.c_str(), toString(op),
- bool_to_aastring(doAA));
- return this->INHERITED::clipRRect(rrect, op, doAA);
+ EdgeStyleToAAString(edgeStyle));
+ this->INHERITED::onClipRRect(rrect, op, edgeStyle);
}
-bool SkDumpCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
+void SkDumpCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
SkString str;
toString(path, &str);
this->dump(kClip_Verb, NULL, "clipPath(%s %s %s)", str.c_str(), toString(op),
- bool_to_aastring(doAA));
- return this->INHERITED::clipPath(path, op, doAA);
+ EdgeStyleToAAString(edgeStyle));
+ this->INHERITED::onClipPath(path, op, edgeStyle);
}
-bool SkDumpCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
+void SkDumpCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
SkString str;
toString(deviceRgn, &str);
this->dump(kClip_Verb, NULL, "clipRegion(%s %s)", str.c_str(),
toString(op));
- return this->INHERITED::clipRegion(deviceRgn, op);
+ this->INHERITED::onClipRegion(deviceRgn, op);
}
void SkDumpCanvas::onPushCull(const SkRect& cullRect) {
diff --git a/src/utils/SkLuaCanvas.cpp b/src/utils/SkLuaCanvas.cpp
index 8c25dc0..0f13073 100644
--- a/src/utils/SkLuaCanvas.cpp
+++ b/src/utils/SkLuaCanvas.cpp
@@ -139,30 +139,30 @@
this->INHERITED::setMatrix(matrix);
}
-bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) {
+void SkLuaCanvas::onClipRect(const SkRect& r, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
AUTO_LUA("clipRect");
lua.pushRect(r, "rect");
- lua.pushBool(doAA, "aa");
- return this->INHERITED::clipRect(r, op, doAA);
+ lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa");
+ this->INHERITED::onClipRect(r, op, edgeStyle);
}
-bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
+void SkLuaCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
AUTO_LUA("clipRRect");
lua.pushRRect(rrect, "rrect");
- lua.pushBool(doAA, "aa");
- return this->INHERITED::clipRRect(rrect, op, doAA);
+ lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa");
+ this->INHERITED::onClipRRect(rrect, op, edgeStyle);
}
-bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
+void SkLuaCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
AUTO_LUA("clipPath");
lua.pushPath(path, "path");
- lua.pushBool(doAA, "aa");
- return this->INHERITED::clipPath(path, op, doAA);
+ lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa");
+ this->INHERITED::onClipPath(path, op, edgeStyle);
}
-bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
+void SkLuaCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
AUTO_LUA("clipRegion");
- return this->INHERITED::clipRegion(deviceRgn, op);
+ this->INHERITED::onClipRegion(deviceRgn, op);
}
void SkLuaCanvas::drawPaint(const SkPaint& paint) {
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index 27adc6d..a9543f9 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -130,36 +130,36 @@
this->INHERITED::setMatrix(matrix);
}
-bool SkNWayCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
+void SkNWayCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
Iter iter(fList);
while (iter.next()) {
- iter->clipRect(rect, op, doAA);
+ iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
}
- return this->INHERITED::clipRect(rect, op, doAA);
+ this->INHERITED::onClipRect(rect, op, edgeStyle);
}
-bool SkNWayCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
+void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
Iter iter(fList);
while (iter.next()) {
- iter->clipRRect(rrect, op, doAA);
+ iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
}
- return this->INHERITED::clipRRect(rrect, op, doAA);
+ this->INHERITED::onClipRRect(rrect, op, edgeStyle);
}
-bool SkNWayCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
+void SkNWayCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
Iter iter(fList);
while (iter.next()) {
- iter->clipPath(path, op, doAA);
+ iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
}
- return this->INHERITED::clipPath(path, op, doAA);
+ this->INHERITED::onClipPath(path, op, edgeStyle);
}
-bool SkNWayCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
+void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
Iter iter(fList);
while (iter.next()) {
iter->clipRegion(deviceRgn, op);
}
- return this->INHERITED::clipRegion(deviceRgn, op);
+ this->INHERITED::onClipRegion(deviceRgn, op);
}
void SkNWayCanvas::clear(SkColor color) {
diff --git a/src/utils/SkNoSaveLayerCanvas.h b/src/utils/SkNoSaveLayerCanvas.h
index 58d28b4..60fad87 100644
--- a/src/utils/SkNoSaveLayerCanvas.h
+++ b/src/utils/SkNoSaveLayerCanvas.h
@@ -32,25 +32,20 @@
return count;
}
+protected:
// disable aa for speed
- virtual bool clipRect(const SkRect& rect,
- SkRegion::Op op,
- bool doAA) SK_OVERRIDE {
- return this->INHERITED::clipRect(rect, op, false);
+ virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
+ this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle);
}
// for speed, just respect the bounds, and disable AA. May give us a few
// false positives and negatives.
- virtual bool clipPath(const SkPath& path,
- SkRegion::Op op,
- bool doAA) SK_OVERRIDE {
- return this->updateClipConservativelyUsingBounds(path.getBounds(), op,
- path.isInverseFillType());
+ virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
+ this->updateClipConservativelyUsingBounds(path.getBounds(), op,
+ path.isInverseFillType());
}
- virtual bool clipRRect(const SkRRect& rrect,
- SkRegion::Op op,
- bool doAA) SK_OVERRIDE {
- return this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
+ virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle) SK_OVERRIDE {
+ this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false);
}
private:
diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp
index 245e0a6..0a9d7a8 100644
--- a/src/utils/SkProxyCanvas.cpp
+++ b/src/utils/SkProxyCanvas.cpp
@@ -58,20 +58,20 @@
fProxy->setMatrix(matrix);
}
-bool SkProxyCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
- return fProxy->clipRect(rect, op, doAA);
+void SkProxyCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ fProxy->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
}
-bool SkProxyCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
- return fProxy->clipRRect(rrect, op, doAA);
+void SkProxyCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ fProxy->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
}
-bool SkProxyCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
- return fProxy->clipPath(path, op, doAA);
+void SkProxyCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ fProxy->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
}
-bool SkProxyCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
- return fProxy->clipRegion(deviceRgn, op);
+void SkProxyCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
+ fProxy->clipRegion(deviceRgn, op);
}
void SkProxyCanvas::drawPaint(const SkPaint& paint) {
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 15165c2..fedef69 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -43,7 +43,8 @@
large.roundOut(&largeIRect);
SkASSERT(!largeIRect.isEmpty());
#endif
- INHERITED::clipRect(large, SkRegion::kReplace_Op, false);
+ // call the base class' version to avoid adding a draw command
+ this->INHERITED::onClipRect(large, SkRegion::kReplace_Op, kHard_ClipEdgeStyle);
}
SkDebugCanvas::~SkDebugCanvas() {
@@ -297,24 +298,20 @@
addDrawCommand(new SkClearCommand(color));
}
-bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
- addDrawCommand(new SkClipPathCommand(path, op, doAA));
- return true;
+void SkDebugCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
}
-bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
- addDrawCommand(new SkClipRectCommand(rect, op, doAA));
- return true;
+void SkDebugCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
}
-bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
- addDrawCommand(new SkClipRRectCommand(rrect, op, doAA));
- return true;
+void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
+ this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
}
-bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) {
- addDrawCommand(new SkClipRegionCommand(region, op));
- return true;
+void SkDebugCanvas::onClipRegion(const SkRegion& region, SkRegion::Op op) {
+ this->addDrawCommand(new SkClipRegionCommand(region, op));
}
bool SkDebugCanvas::concat(const SkMatrix& matrix) {
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index 7d49627..ebce6c9 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -143,16 +143,6 @@
virtual void clear(SkColor) SK_OVERRIDE;
- virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
-
- virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
-
- virtual bool clipRRect(const SkRRect& rrect,
- SkRegion::Op op = SkRegion::kIntersect_Op,
- bool doAntiAlias = false) SK_OVERRIDE;
-
- virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
-
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
@@ -233,11 +223,35 @@
static const int kVizImageHeight = 256;
static const int kVizImageWidth = 256;
+ virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
+ virtual ClipType getClipType() const SK_OVERRIDE {
+ return kRect_ClipType;
+ }
+ virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
+ if (NULL != bounds) {
+ bounds->setXYWH(0, 0,
+ SkIntToScalar(this->imageInfo().fWidth),
+ SkIntToScalar(this->imageInfo().fHeight));
+ }
+ return true;
+ }
+ virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
+ if (NULL != bounds) {
+ bounds->setLargest();
+ }
+ return true;
+ }
+
protected:
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
virtual void onPopCull() SK_OVERRIDE;
+ virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRegion(const SkRegion& region, SkRegion::Op) SK_OVERRIDE;
+
private:
SkTDArray<SkDrawCommand*> fCommandVector;
int fWidth;