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

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: moar build fix 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 virtual ~PictureBBHTestBase() { }
27
28 virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) = 0 ;
29
30 void run(skiatest::Reporter* reporter) {
31 // No BBH
32 this->run(NULL, reporter);
33
34 // With a Tile Grid
35 SkTileGridFactory::TileGridInfo gridInfo;
36 gridInfo.fMargin.setEmpty();
37 gridInfo.fOffset.setZero();
38 gridInfo.fTileInterval.set(1, 1);
39 SkTileGridFactory gridFactory(gridInfo);
40 this->run(&gridFactory, reporter);
41
42 // With an R-Tree
43 SkRTreeFactory RTreeFactory;
44 this->run(&RTreeFactory, reporter);
45 }
46
47 private:
48 void run(SkBBHFactory* factory, skiatest::Reporter* reporter) {
49 SkCanvas playbackCanvas(fResultBitmap);
50 playbackCanvas.clear(SK_ColorGREEN);
51 SkPictureRecorder recorder;
52 SkCanvas* recordCanvas = recorder.beginRecording(SkIntToScalar(fPictureW idth), SkIntToScalar(fPictureHeight), factory);
53 this->doTest(playbackCanvas, *recordCanvas);
54 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
55 playbackCanvas.drawPicture(picture);
56 REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0)) ;
57 }
58
59 SkBitmap fResultBitmap;
60 int fPictureWidth, fPictureHeight;
61 };
62
63 // Test to verify the playback of an empty picture
64 //
65 class DrawEmptyPictureBBHTest : public PictureBBHTestBase {
66 public:
67 DrawEmptyPictureBBHTest()
68 : PictureBBHTestBase(2, 2, 1, 1) { }
69 virtual ~DrawEmptyPictureBBHTest() { }
70
71 virtual void doTest(SkCanvas&, SkCanvas&) SK_OVERRIDE { }
72 };
73
74 // Test to verify the playback of a picture into a canvas that has
75 // an empty clip.
76 //
77 class EmptyClipPictureBBHTest : public PictureBBHTestBase {
78 public:
79 EmptyClipPictureBBHTest()
80 : PictureBBHTestBase(2, 2, 3, 3) { }
81
82 virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) SK_ OVERRIDE {
83 // intersect with out of bounds rect -> empty clip.
84 playbackCanvas.clipRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScala r(10),
85 SkIntToScalar(1), SkIntToScalar(1)), SkRegion::kIntersect_Op);
86 SkPaint paint;
87 recordingCanvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScala r(0),
88 SkIntToScalar(3), SkIntToScalar(3)), paint);
89 }
90
91 virtual ~EmptyClipPictureBBHTest() { }
92 };
93
94 DEF_TEST(PictureBBH, reporter) {
95
96 DrawEmptyPictureBBHTest emptyPictureTest;
97 emptyPictureTest.run(reporter);
98
99 EmptyClipPictureBBHTest emptyClipPictureTest;
100 emptyClipPictureTest.run(reporter);
101 }
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