| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkBBoxHierarchy.h" | 9 #include "SkBBoxHierarchy.h" |
| 10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 56 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 57 playbackCanvas.drawPicture(picture); | 57 playbackCanvas.drawPicture(picture); |
| 58 REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0))
; | 58 REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0))
; |
| 59 } | 59 } |
| 60 | 60 |
| 61 SkBitmap fResultBitmap; | 61 SkBitmap fResultBitmap; |
| 62 int fPictureWidth, fPictureHeight; | 62 int fPictureWidth, fPictureHeight; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Test to verify the playback of an empty picture | 65 // Test to verify the playback of an empty picture |
| 66 // | 66 // |
| 67 class DrawEmptyPictureBBHTest : public PictureBBHTestBase { | 67 class DrawEmptyPictureBBHTest : public PictureBBHTestBase { |
| 68 public: | 68 public: |
| 69 DrawEmptyPictureBBHTest() | 69 DrawEmptyPictureBBHTest() |
| 70 : PictureBBHTestBase(2, 2, 1, 1) { } | 70 : PictureBBHTestBase(2, 2, 1, 1) { } |
| 71 virtual ~DrawEmptyPictureBBHTest() { } | 71 virtual ~DrawEmptyPictureBBHTest() { } |
| 72 | 72 |
| 73 virtual void doTest(SkCanvas&, SkCanvas&) SK_OVERRIDE { } | 73 virtual void doTest(SkCanvas&, SkCanvas&) SK_OVERRIDE { } |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Test to verify the playback of a picture into a canvas that has | 76 // Test to verify the playback of a picture into a canvas that has |
| 77 // an empty clip. | 77 // an empty clip. |
| 78 // | 78 // |
| 79 class EmptyClipPictureBBHTest : public PictureBBHTestBase { | 79 class EmptyClipPictureBBHTest : public PictureBBHTestBase { |
| 80 public: | 80 public: |
| 81 EmptyClipPictureBBHTest() | 81 EmptyClipPictureBBHTest() |
| 82 : PictureBBHTestBase(2, 2, 3, 3) { } | 82 : PictureBBHTestBase(2, 2, 3, 3) { } |
| 83 | 83 |
| 84 virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) SK_
OVERRIDE { | 84 virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) SK_
OVERRIDE { |
| 85 // intersect with out of bounds rect -> empty clip. | 85 // intersect with out of bounds rect -> empty clip. |
| 86 playbackCanvas.clipRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScala
r(10), | 86 playbackCanvas.clipRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScala
r(10), |
| 87 SkIntToScalar(1), SkIntToScalar(1)), SkRegion::kIntersect_Op); | 87 SkIntToScalar(1), SkIntToScalar(1)), SkRegion::kIntersect_Op); |
| 88 SkPaint paint; | 88 SkPaint paint; |
| 89 recordingCanvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScala
r(0), | 89 recordingCanvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScala
r(0), |
| 90 SkIntToScalar(3), SkIntToScalar(3)), paint); | 90 SkIntToScalar(3), SkIntToScalar(3)), paint); |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual ~EmptyClipPictureBBHTest() { } | 93 virtual ~EmptyClipPictureBBHTest() { } |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 DEF_TEST(PictureBBH, reporter) { | 96 DEF_TEST(PictureBBH, reporter) { |
| 97 | 97 |
| 98 DrawEmptyPictureBBHTest emptyPictureTest; | 98 DrawEmptyPictureBBHTest emptyPictureTest; |
| 99 emptyPictureTest.run(reporter); | 99 emptyPictureTest.run(reporter); |
| 100 | 100 |
| 101 EmptyClipPictureBBHTest emptyClipPictureTest; | 101 EmptyClipPictureBBHTest emptyClipPictureTest; |
| 102 emptyClipPictureTest.run(reporter); | 102 emptyClipPictureTest.run(reporter); |
| 103 } | 103 } |
| 104 | |
| 105 static void test_clear(skiatest::Reporter* r, SkBBHFactory* factory) { | |
| 106 // SkPicture should always call clear()s on the target canvas, even if its c
lip is empty. | |
| 107 SkPictureRecorder src, dst; | |
| 108 | |
| 109 // A picture that's just clear(). | |
| 110 src.beginRecording(1,1, factory) | |
| 111 ->clear(SK_ColorGREEN); | |
| 112 SkAutoTUnref<SkPicture> srcPic(src.endRecording()); | |
| 113 | |
| 114 // A target canvas with an empty clip. | |
| 115 SkCanvas* c = dst.beginRecording(1,1, NULL); | |
| 116 c->clipRect(SkRect::MakeEmpty()); | |
| 117 srcPic->playback(c); | |
| 118 SkAutoTUnref<SkPicture> dstPic(dst.endRecording()); | |
| 119 | |
| 120 // Should be Clip - Save - Clear - Restore. | |
| 121 // Buggy implementations might return 1 (just Clip) or 3 (Clip - Save - Rest
ore). | |
| 122 // TODO: can we just search that it contains "clear"? <reed> | |
| 123 REPORTER_ASSERT(r, dstPic->approximateOpCount() == 4 || dstPic->approximateO
pCount() == 2); | |
| 124 } | |
| 125 | |
| 126 DEF_TEST(PictureBBH_Clear, r) { | |
| 127 test_clear(r, NULL); | |
| 128 | |
| 129 SkTileGridFactory::TileGridInfo grid = { {1,1}, {0,0}, {0,0} }; | |
| 130 SkTileGridFactory tilegrid(grid); | |
| 131 test_clear(r, &tilegrid); | |
| 132 | |
| 133 SkRTreeFactory rtree; | |
| 134 test_clear(r, &rtree); | |
| 135 } | |
| OLD | NEW |