aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkCanvas.cpp46
-rw-r--r--tests/CanvasStateTest.cpp10
2 files changed, 41 insertions, 15 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 895d36fe8c..ef7b1e799b 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1508,24 +1508,44 @@ void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg
}
#endif
- AutoValidateClip avc(this);
-
- fDeviceCMDirty = true;
- fCachedLocalClipBoundsDirty = true;
if (!fAllowSoftClip) {
edgeStyle = kHard_ClipEdgeStyle;
}
- if (fMCRec->fMatrix.rectStaysRect()) {
- // for these simpler matrices, we can stay a rect even after applying
- // the matrix. This means we don't have to a) make a path, and b) tell
- // the region code to scan-convert the path, only to discover that it
- // is really just a rect.
- SkRect r;
+ const bool rectStaysRect = fMCRec->fMatrix.rectStaysRect();
+ SkRect devR;
+ if (rectStaysRect) {
+ fMCRec->fMatrix.mapRect(&devR, rect);
+ }
+
+ // Check if we can quick-accept the clip call (and do nothing)
+ //
+ // TODO: investigate if a (conservative) version of this could be done in ::clipRect,
+ // so that subclasses (like PictureRecording) didn't see unnecessary clips, which in turn
+ // might allow lazy save/restores to eliminate entire save/restore blocks.
+ //
+ if (SkRegion::kIntersect_Op == op &&
+ kHard_ClipEdgeStyle == edgeStyle
+ && rectStaysRect)
+ {
+ if (devR.round().contains(fMCRec->fRasterClip.getBounds())) {
+#if 0
+ SkDebugf("------- ignored clipRect [%g %g %g %g]\n",
+ rect.left(), rect.top(), rect.right(), rect.bottom());
+#endif
+ return;
+ }
+ }
+
+ AutoValidateClip avc(this);
+
+ fDeviceCMDirty = true;
+ fCachedLocalClipBoundsDirty = true;
- fMCRec->fMatrix.mapRect(&r, rect);
- fClipStack->clipDevRect(r, op, kSoft_ClipEdgeStyle == edgeStyle);
- fMCRec->fRasterClip.op(r, this->getBaseLayerSize(), op, kSoft_ClipEdgeStyle == edgeStyle);
+ if (rectStaysRect) {
+ const bool isAA = kSoft_ClipEdgeStyle == edgeStyle;
+ fClipStack->clipDevRect(devR, op, isAA);
+ fMCRec->fRasterClip.op(devR, this->getBaseLayerSize(), op, isAA);
} else {
// since we're rotated or some such thing, we convert the rect to a path
// and clip against that, since it can handle any matrix. However, to
diff --git a/tests/CanvasStateTest.cpp b/tests/CanvasStateTest.cpp
index b5543a1523..4f5fb463e3 100644
--- a/tests/CanvasStateTest.cpp
+++ b/tests/CanvasStateTest.cpp
@@ -322,8 +322,14 @@ DEF_TEST(CanvasState_test_saveLayer_clip, reporter) {
SkRect clipStackBounds;
SkClipStack::BoundsType boundsType;
canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType);
- REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH);
- REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT);
+ // The clip stack will return its bounds, or it may be "full" : i.e. empty + inside_out.
+ // Either result is consistent with this test, since the canvas' size is WIDTH/HEIGHT
+ if (SkClipStack::kInsideOut_BoundsType == boundsType) {
+ REPORTER_ASSERT(reporter, clipStackBounds.isEmpty());
+ } else {
+ REPORTER_ASSERT(reporter, clipStackBounds.width() == WIDTH);
+ REPORTER_ASSERT(reporter, clipStackBounds.height() == HEIGHT);
+ }
canvas.restore();
// Check that saveLayer with the kClipToLayer_SaveFlag sets the clip