aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-01-19 11:36:41 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-19 18:31:28 +0000
commit3726a4ac68821deea7ef4d5472a42f7d35ec4b4e (patch)
tree1caa4c84140921e0a90157a65bca6cf5ebb20942 /tests
parentfbff3297876a7c9c77a48be9a6fe62274a58bd8c (diff)
new hacky api to get cliprgn for android
BUG=skia: Change-Id: I42711a474906084adb3c888a599ae02505726484 Reviewed-on: https://skia-review.googlesource.com/7220 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/CanvasStateTest.cpp38
-rw-r--r--tests/ClipStackTest.cpp29
2 files changed, 44 insertions, 23 deletions
diff --git a/tests/CanvasStateTest.cpp b/tests/CanvasStateTest.cpp
index 9533474c56..38fb3fe8bc 100644
--- a/tests/CanvasStateTest.cpp
+++ b/tests/CanvasStateTest.cpp
@@ -306,9 +306,11 @@ DEF_TEST(CanvasState_test_soft_clips, reporter) {
REPORTER_ASSERT(reporter, !state);
}
-#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
-#include "SkClipStack.h"
DEF_TEST(CanvasState_test_saveLayer_clip, reporter) {
+ const uint32_t dontSaveFlag = 1 << 31; // secret flag for don't save
+#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
+ static_assert(SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag == dontSaveFlag, "");
+#endif
const int WIDTH = 100;
const int HEIGHT = 100;
const int LAYER_WIDTH = 50;
@@ -321,31 +323,21 @@ DEF_TEST(CanvasState_test_saveLayer_clip, reporter) {
SkRect bounds = SkRect::MakeWH(SkIntToScalar(LAYER_WIDTH), SkIntToScalar(LAYER_HEIGHT));
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(WIDTH), SkIntToScalar(HEIGHT)));
- // Check that saveLayer without the kClipToLayer_SaveFlag leaves the
- // clip stack unchanged.
- canvas.saveLayer(SkCanvas::SaveLayerRec(&bounds,
- nullptr,
- SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag));
- SkRect clipStackBounds;
- SkClipStack::BoundsType boundsType;
- canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType);
- // 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);
- }
+ SkIRect devClip;
+ // Check that saveLayer without the kClipToLayer_SaveFlag leaves the clip unchanged.
+ canvas.saveLayer(SkCanvas::SaveLayerRec(&bounds, nullptr, dontSaveFlag));
+ canvas.getClipDeviceBounds(&devClip);
+ REPORTER_ASSERT(reporter, canvas.isClipRect());
+ REPORTER_ASSERT(reporter, devClip.width() == WIDTH);
+ REPORTER_ASSERT(reporter, devClip.height() == HEIGHT);
canvas.restore();
// Check that saveLayer with the kClipToLayer_SaveFlag sets the clip
// stack to the layer bounds.
canvas.saveLayer(&bounds, nullptr);
- canvas.getClipStack()->getBounds(&clipStackBounds, &boundsType);
- REPORTER_ASSERT(reporter, clipStackBounds.width() == LAYER_WIDTH);
- REPORTER_ASSERT(reporter, clipStackBounds.height() == LAYER_HEIGHT);
-
+ canvas.getClipDeviceBounds(&devClip);
+ REPORTER_ASSERT(reporter, canvas.isClipRect());
+ REPORTER_ASSERT(reporter, devClip.width() == LAYER_WIDTH);
+ REPORTER_ASSERT(reporter, devClip.height() == LAYER_HEIGHT);
canvas.restore();
}
-#endif
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index a85f0168b2..8448f4cbe5 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -1456,4 +1456,33 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(ClipMaskCache, reporter, ctxInfo) {
#endif
}
+#include "SkSurface.h"
+DEF_GPUTEST_FOR_ALL_CONTEXTS(canvas_private_clipRgn, reporter, ctxInfo) {
+ GrContext* context = ctxInfo.grContext();
+
+ const int w = 10;
+ const int h = 10;
+ SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+ sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
+ SkCanvas* canvas = surf->getCanvas();
+ SkRegion rgn;
+
+ canvas->temporary_internal_getRgnClip(&rgn);
+ REPORTER_ASSERT(reporter, rgn.isRect());
+ REPORTER_ASSERT(reporter, rgn.getBounds() == SkIRect::MakeWH(w, h));
+
+ canvas->save();
+ canvas->clipRect(SkRect::MakeWH(5, 5), kDifference_SkClipOp);
+ canvas->temporary_internal_getRgnClip(&rgn);
+ REPORTER_ASSERT(reporter, rgn.isComplex());
+ REPORTER_ASSERT(reporter, rgn.getBounds() == SkIRect::MakeWH(w, h));
+ canvas->restore();
+
+ canvas->save();
+ canvas->clipRRect(SkRRect::MakeOval(SkRect::MakeLTRB(3, 3, 7, 7)));
+ canvas->temporary_internal_getRgnClip(&rgn);
+ REPORTER_ASSERT(reporter, rgn.isComplex());
+ REPORTER_ASSERT(reporter, rgn.getBounds() == SkIRect::MakeLTRB(3, 3, 7, 7));
+ canvas->restore();
+}
#endif