Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: tests/PictureBBHTest.cpp

Issue 678303004: Make RTree handle the case where the playback canvas has empty clip bounds (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: refactored test Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCanvas.h"
9 #include "SkBBoxHierarchy.h"
10 #include "SkPaint.h"
11 #include "SkPicture.h"
12 #include "SkPictureRecorder.h"
13
14 #include "Test.h"
15
16 class PictureBBHTestBase {
17 public:
18 PictureBBHTestBase(int playbackWidth, int playbackHeight,
19 int recordWidth, int recordHeight) {
20
21 fResultBitmap.allocN32Pixels(playbackWidth, playbackHeight);
22 fPictureWidth = recordWidth;
23 fPictureHeight = recordHeight;
24 }
25
26 // To clear the playback canvas at the beginning of the test
27 virtual void resetCanvas(SkCanvas& resultCanvas) = 0;
reed1 2014/10/29 15:56:14 I assumed we could always assert that nothing drew
28 // To record command into the SkPicture
29 virtual void recordCommands(SkCanvas& recordingCanvas) = 0;
30 // To verify the results of playing back the SkPicture
31 virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* re porter) = 0;
32
33 virtual ~PictureBBHTestBase() { }
reed1 2014/10/29 15:56:14 nit: skia puts its destructor right after the cons
34
35 void run(skiatest::Reporter* reporter) {
36 run(NULL, reporter);
37
38 SkTileGridFactory::TileGridInfo gridInfo;
39 gridInfo.fMargin.setEmpty();
40 gridInfo.fOffset.setZero();
41 gridInfo.fTileInterval.set(1, 1);
42 SkTileGridFactory gridFactory(gridInfo);
43 run(&gridFactory, reporter);
44
45 SkRTreeFactory RTreeFactory;
46 run(&RTreeFactory, reporter);
47 }
48
49 private:
50 void run(SkBBHFactory* factory, skiatest::Reporter* reporter) {
51 SkCanvas playbackCanvas(fResultBitmap);
52 resetCanvas(playbackCanvas);
reed1 2014/10/29 15:56:14 nit: this->resetCanvas(...) for methods
53 SkPictureRecorder recorder;
54 SkCanvas* recordCanvas = recorder.beginRecording(fPictureWidth, fPicture Height, factory);
55 recordCommands(*recordCanvas);
56 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
57 playbackCanvas.drawPicture(picture);
58 validateResult(fResultBitmap, reporter);
59 }
60
61 SkBitmap fResultBitmap;
62 int fPictureWidth, fPictureHeight;
63 };
64
65 // Test to verify the playback of an empty picture
66 //
67 class DrawEmptyPictureBBHTest : public PictureBBHTestBase {
68 public:
69 DrawEmptyPictureBBHTest()
70 : PictureBBHTestBase(2, 2, 1, 1) { }
71
72 // Functions are all empty. Test passes by not crashing
73 virtual void resetCanvas(SkCanvas& resultCanvas) { }
reed1 2014/10/29 15:56:14 nit: SK_OVERRIDE in the subclasses
74 virtual void recordCommands(SkCanvas& recordingCanvas) { }
75 virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* re porter) { }
76 virtual ~DrawEmptyPictureBBHTest() { }
77 };
78
79 // Test to verify the playback of a picture into a canvas that has
80 // an empty clip.
81 //
82 class EmptyClipPictureBBHTest : public PictureBBHTestBase {
83 public:
84 EmptyClipPictureBBHTest()
85 : PictureBBHTestBase(2, 2, 3, 3) { }
86
87 virtual void resetCanvas(SkCanvas& resultCanvas) {
88 resultCanvas.clear(SK_ColorGREEN);
89 // intersect with out of bounds rect -> empty clip.
90 resultCanvas.clipRect(SkRect::MakeXYWH(10, 10, 1, 1), SkRegion::kInterse ct_Op);
reed1 2014/10/29 15:56:14 seems like we can fold this clip call into the rec
91 }
92
93 virtual void recordCommands(SkCanvas& recordingCanvas) {
94 SkPaint paint;
95 recordingCanvas.drawRect(SkRect::MakeXYWH(0, 0, 3, 3), paint);
96 }
97
98 virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* re porter) {
99 REPORTER_ASSERT(reporter, SK_ColorGREEN == playbackResult.getColor(0, 0) );
100 }
101
102 virtual ~EmptyClipPictureBBHTest() { }
103 };
104
105 DEF_TEST(PictureBBH, reporter) {
106
107 DrawEmptyPictureBBHTest emptyPictureTest;
108 emptyPictureTest.run(reporter);
109
110 EmptyClipPictureBBHTest emptyClipPictureTest;
111 emptyClipPictureTest.run(reporter);
112 }
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698