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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // With an R-Tree | 42 // With an R-Tree |
43 SkRTreeFactory RTreeFactory; | 43 SkRTreeFactory RTreeFactory; |
44 this->run(&RTreeFactory, reporter); | 44 this->run(&RTreeFactory, reporter); |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 void run(SkBBHFactory* factory, skiatest::Reporter* reporter) { | 48 void run(SkBBHFactory* factory, skiatest::Reporter* reporter) { |
49 SkCanvas playbackCanvas(fResultBitmap); | 49 SkCanvas playbackCanvas(fResultBitmap); |
50 playbackCanvas.clear(SK_ColorGREEN); | 50 playbackCanvas.clear(SK_ColorGREEN); |
51 SkPictureRecorder recorder; | 51 SkPictureRecorder recorder; |
52 SkCanvas* recordCanvas = recorder.beginRecording(SkIntToScalar(fPictureW
idth), SkIntToScalar(fPictureHeight), factory); | 52 SkCanvas* recordCanvas = recorder.beginRecording(SkIntToScalar(fPictureW
idth), |
| 53 SkIntToScalar(fPictureH
eight), |
| 54 factory); |
53 this->doTest(playbackCanvas, *recordCanvas); | 55 this->doTest(playbackCanvas, *recordCanvas); |
54 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 56 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
55 playbackCanvas.drawPicture(picture); | 57 playbackCanvas.drawPicture(picture); |
56 REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0))
; | 58 REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0))
; |
57 } | 59 } |
58 | 60 |
59 SkBitmap fResultBitmap; | 61 SkBitmap fResultBitmap; |
60 int fPictureWidth, fPictureHeight; | 62 int fPictureWidth, fPictureHeight; |
61 }; | 63 }; |
62 | 64 |
(...skipping 29 matching lines...) Expand all Loading... |
92 }; | 94 }; |
93 | 95 |
94 DEF_TEST(PictureBBH, reporter) { | 96 DEF_TEST(PictureBBH, reporter) { |
95 | 97 |
96 DrawEmptyPictureBBHTest emptyPictureTest; | 98 DrawEmptyPictureBBHTest emptyPictureTest; |
97 emptyPictureTest.run(reporter); | 99 emptyPictureTest.run(reporter); |
98 | 100 |
99 EmptyClipPictureBBHTest emptyClipPictureTest; | 101 EmptyClipPictureBBHTest emptyClipPictureTest; |
100 emptyClipPictureTest.run(reporter); | 102 emptyClipPictureTest.run(reporter); |
101 } | 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 SkAutoTDelete<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 SkAutoTDelete<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 REPORTER_ASSERT(r, dstPic->approximateOpCount() == 4); |
| 123 } |
| 124 |
| 125 DEF_TEST(PictureBBH_Clear, r) { |
| 126 test_clear(r, NULL); |
| 127 |
| 128 SkTileGridFactory::TileGridInfo grid = { {1,1}, {0,0}, {0,0} }; |
| 129 SkTileGridFactory tilegrid(grid); |
| 130 test_clear(r, &tilegrid); |
| 131 |
| 132 SkRTreeFactory rtree; |
| 133 test_clear(r, &rtree); |
| 134 } |
OLD | NEW |