diff options
author | Mike Reed <reed@google.com> | 2017-03-22 10:01:53 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-22 14:59:56 +0000 |
commit | 2a65cc0ff16bd597e2d4a190b757573b482f43be (patch) | |
tree | c1f67861aafd95d677b9d2e68e02d47234133c36 /tests/CanvasTest.cpp | |
parent | 20c322ef0cd04cf8e2592879d05d9f4e6cb19596 (diff) |
test (and fix) clip_restriction in canvas
BUG=skia:
Change-Id: I86d25d0fd82be35d01471fba59f77b360be5373c
Reviewed-on: https://skia-review.googlesource.com/9995
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Diffstat (limited to 'tests/CanvasTest.cpp')
-rw-r--r-- | tests/CanvasTest.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index cfdce628ca..d18324a04c 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -44,6 +44,7 @@ * works the same way as SIMPLE_TEST_STEP, and additionally verifies * that the invoked method returns a non-zero value. */ + #include "SkBitmap.h" #include "SkCanvas.h" #include "SkClipStack.h" @@ -103,6 +104,59 @@ DEF_TEST(canvas_clipbounds, reporter) { } } +const SkIRect gBaseRestrictedR = { 0, 0, 10, 10 }; + +static void test_restriction(skiatest::Reporter* reporter, SkCanvas* canvas) { + REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == gBaseRestrictedR); + + const SkIRect restrictionR = { 2, 2, 8, 8 }; + canvas->androidFramework_setDeviceClipRestriction(restrictionR); + REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == restrictionR); + + const SkIRect clipR = { 4, 4, 6, 6 }; + canvas->clipRect(SkRect::Make(clipR), SkClipOp::kIntersect); + REPORTER_ASSERT(reporter, canvas->getDeviceClipBounds() == clipR); + + // now test that expanding clipops can't exceed the restriction + const SkClipOp expanders[] = { + SkClipOp::kUnion_deprecated, + SkClipOp::kXOR_deprecated, + SkClipOp::kReverseDifference_deprecated, + SkClipOp::kReplace_deprecated, + }; + + const SkRect expandR = { 0, 0, 5, 9 }; + SkASSERT(!SkRect::Make(restrictionR).contains(expandR)); + + for (SkClipOp op : expanders) { + canvas->save(); + canvas->clipRect(expandR, op); + REPORTER_ASSERT(reporter, gBaseRestrictedR.contains(canvas->getDeviceClipBounds())); + canvas->restore(); + } +} + +/** + * Clip restriction logic exists in the canvas itself, and in various kinds of devices. + * + * This test explicitly tries to exercise that variety: + * - picture : empty device but exercises canvas itself + * - pdf : uses SkClipStack in its device (as does SVG and GPU) + * - raster : uses SkRasterClip in its device + */ +DEF_TEST(canvas_clip_restriction, reporter) { + test_restriction(reporter, SkPictureRecorder().beginRecording(SkRect::Make(gBaseRestrictedR))); + + SkNullWStream stream; + auto doc = SkDocument::MakePDF(&stream); + test_restriction(reporter, doc->beginPage(SkIntToScalar(gBaseRestrictedR.width()), + SkIntToScalar(gBaseRestrictedR.height()))); + + auto surf = SkSurface::MakeRasterN32Premul(gBaseRestrictedR.width(), + gBaseRestrictedR.height(), nullptr); + test_restriction(reporter, surf->getCanvas()); +} + static const int kWidth = 2, kHeight = 2; static void createBitmap(SkBitmap* bm, SkColor color) { |