Chromium Code Reviews| Index: tests/PictureTest.cpp |
| diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp |
| index 618ccfc4c0ffc3b931a0e170099c2af76f8280fd..62119016113b4ee6c9c80866f99ca660d2fcbfa1 100644 |
| --- a/tests/PictureTest.cpp |
| +++ b/tests/PictureTest.cpp |
| @@ -986,6 +986,40 @@ public: |
| } |
| }; |
| +static void create_imbalance(SkCanvas* canvas) { |
| + SkRect clipRect = SkRect::MakeWH(2, 2); |
| + SkRect drawRect = SkRect::MakeWH(10, 10); |
| + canvas->save(); |
| + canvas->clipRect(clipRect, SkRegion::kReplace_Op); |
| + canvas->translate(1.0f, 1.0f); |
| + SkPaint p; |
| + p.setColor(SK_ColorGREEN); |
| + canvas->drawRect(drawRect, p); |
| + // no restore |
| +} |
| + |
| +static void check_balance(skiatest::Reporter* reporter, SkPicture* picture) { |
|
scroggo
2014/06/10 13:31:25
Some comments here would be nice. e.g.
// Test th
robertphillips
2014/06/10 17:26:28
Done.
|
| + SkBitmap bm; |
| + bm.allocN32Pixels(4, 3); |
| + SkCanvas canvas(bm); |
| + |
| + int beforeSaveCount = canvas.getSaveCount(); |
| + |
| + SkMatrix beforeMatrix = canvas.getTotalMatrix(); |
| + |
| + canvas.drawPicture(picture); |
| + |
| + REPORTER_ASSERT(reporter, beforeSaveCount == canvas.getSaveCount()); |
| + REPORTER_ASSERT(reporter, beforeMatrix == canvas.getTotalMatrix()); |
| + |
| + SkRect afterClip; |
| + |
| + canvas.getClipBounds(&afterClip); |
| + |
| + REPORTER_ASSERT(reporter, afterClip.width() == 4); |
| + REPORTER_ASSERT(reporter, afterClip.height() == 4); |
|
scroggo
2014/06/10 13:31:25
How did the height end up 4?
robertphillips
2014/06/10 17:27:24
Switch to storing a beforeClip so things are clear
|
| +} |
| + |
| // Test out SkPictureRecorder::partialReplay |
| DEF_TEST(PictureRecorder_replay, reporter) { |
| // check save/saveLayer state |
| @@ -1040,6 +1074,23 @@ DEF_TEST(PictureRecorder_replay, reporter) { |
| // The snapshot shouldn't pick up any operations added after it was made |
| REPORTER_ASSERT(reporter, !copy->willPlayBackBitmaps()); |
| } |
| + |
| + // Recreate the Android partialReplay test case |
| + { |
| + SkPictureRecorder recorder; |
| + |
| + SkCanvas* canvas = recorder.beginRecording(4, 3, NULL, 0); |
| + create_imbalance(canvas); |
| + |
| + int expectedSaveCount = canvas->getSaveCount(); |
| + |
| + SkAutoTUnref<SkPicture> copy(SkPictureRecorderReplayTester::Copy(&recorder)); |
| + check_balance(reporter, copy); |
| + |
| + REPORTER_ASSERT(reporter, expectedSaveCount = canvas->getSaveCount()); |
| + |
| + SkAutoTUnref<SkPicture> final(recorder.endRecording()); |
|
scroggo
2014/06/10 13:31:25
What does this test?
robertphillips
2014/06/10 17:26:28
Done - added comment.
|
| + } |
| } |
| static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { |