aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/tests.gypi1
-rw-r--r--src/core/SkRecordDraw.cpp6
-rw-r--r--tests/PictureBBHTest.cpp101
-rw-r--r--tests/PictureTest.cpp42
4 files changed, 106 insertions, 44 deletions
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index 59604db6c5..8dfc671c47 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -156,6 +156,7 @@
'../tests/PathMeasureTest.cpp',
'../tests/PathTest.cpp',
'../tests/PathUtilsTest.cpp',
+ '../tests/PictureBBHTest.cpp',
'../tests/PictureShaderTest.cpp',
'../tests/PictureTest.cpp',
'../tests/PixelRefTest.cpp',
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 5981245c01..ad1327016b 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -20,8 +20,10 @@ void SkRecordDraw(const SkRecord& record,
// is not necessarily in that same space. getClipBounds() returns us
// this canvas' clip bounds transformed back into identity space, which
// lets us query the BBH.
- SkRect query = { 0, 0, 0, 0 };
- (void)canvas->getClipBounds(&query);
+ SkRect query;
+ if (!canvas->getClipBounds(&query)) {
+ return;
+ }
SkTDArray<unsigned> ops;
bbh->search(query, &ops);
diff --git a/tests/PictureBBHTest.cpp b/tests/PictureBBHTest.cpp
new file mode 100644
index 0000000000..3ff5625686
--- /dev/null
+++ b/tests/PictureBBHTest.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCanvas.h"
+#include "SkBBoxHierarchy.h"
+#include "SkPaint.h"
+#include "SkPicture.h"
+#include "SkPictureRecorder.h"
+
+#include "Test.h"
+
+class PictureBBHTestBase {
+public:
+ PictureBBHTestBase(int playbackWidth, int playbackHeight,
+ int recordWidth, int recordHeight) {
+
+ fResultBitmap.allocN32Pixels(playbackWidth, playbackHeight);
+ fPictureWidth = recordWidth;
+ fPictureHeight = recordHeight;
+ }
+
+ virtual ~PictureBBHTestBase() { }
+
+ virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) = 0;
+
+ void run(skiatest::Reporter* reporter) {
+ // No BBH
+ this->run(NULL, reporter);
+
+ // With a Tile Grid
+ SkTileGridFactory::TileGridInfo gridInfo;
+ gridInfo.fMargin.setEmpty();
+ gridInfo.fOffset.setZero();
+ gridInfo.fTileInterval.set(1, 1);
+ SkTileGridFactory gridFactory(gridInfo);
+ this->run(&gridFactory, reporter);
+
+ // With an R-Tree
+ SkRTreeFactory RTreeFactory;
+ this->run(&RTreeFactory, reporter);
+ }
+
+private:
+ void run(SkBBHFactory* factory, skiatest::Reporter* reporter) {
+ SkCanvas playbackCanvas(fResultBitmap);
+ playbackCanvas.clear(SK_ColorGREEN);
+ SkPictureRecorder recorder;
+ SkCanvas* recordCanvas = recorder.beginRecording(SkIntToScalar(fPictureWidth), SkIntToScalar(fPictureHeight), factory);
+ this->doTest(playbackCanvas, *recordCanvas);
+ SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+ playbackCanvas.drawPicture(picture);
+ REPORTER_ASSERT(reporter, SK_ColorGREEN == fResultBitmap.getColor(0, 0));
+ }
+
+ SkBitmap fResultBitmap;
+ int fPictureWidth, fPictureHeight;
+};
+
+// Test to verify the playback of an empty picture
+//
+class DrawEmptyPictureBBHTest : public PictureBBHTestBase {
+public:
+ DrawEmptyPictureBBHTest()
+ : PictureBBHTestBase(2, 2, 1, 1) { }
+ virtual ~DrawEmptyPictureBBHTest() { }
+
+ virtual void doTest(SkCanvas&, SkCanvas&) SK_OVERRIDE { }
+};
+
+// Test to verify the playback of a picture into a canvas that has
+// an empty clip.
+//
+class EmptyClipPictureBBHTest : public PictureBBHTestBase {
+public:
+ EmptyClipPictureBBHTest()
+ : PictureBBHTestBase(2, 2, 3, 3) { }
+
+ virtual void doTest(SkCanvas& playbackCanvas, SkCanvas& recordingCanvas) SK_OVERRIDE {
+ // intersect with out of bounds rect -> empty clip.
+ playbackCanvas.clipRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
+ SkIntToScalar(1), SkIntToScalar(1)), SkRegion::kIntersect_Op);
+ SkPaint paint;
+ recordingCanvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
+ SkIntToScalar(3), SkIntToScalar(3)), paint);
+ }
+
+ virtual ~EmptyClipPictureBBHTest() { }
+};
+
+DEF_TEST(PictureBBH, reporter) {
+
+ DrawEmptyPictureBBHTest emptyPictureTest;
+ emptyPictureTest.run(reporter);
+
+ EmptyClipPictureBBHTest emptyClipPictureTest;
+ emptyClipPictureTest.run(reporter);
+}
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index fa4dc10142..7c3a4d0fe0 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1494,47 +1494,6 @@ static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) {
SkSetErrorCallback(NULL, NULL);
}
-static void test_draw_empty(skiatest::Reporter* reporter) {
- SkBitmap result;
- make_bm(&result, 2, 2, SK_ColorBLACK, false);
-
- SkCanvas canvas(result);
-
- {
- // stock SkPicture
- SkPictureRecorder recorder;
- recorder.beginRecording(1, 1);
- SkAutoTUnref<SkPicture> picture(recorder.endRecording());
-
- canvas.drawPicture(picture);
- }
-
- {
- // tile grid
- SkTileGridFactory::TileGridInfo gridInfo;
- gridInfo.fMargin.setEmpty();
- gridInfo.fOffset.setZero();
- gridInfo.fTileInterval.set(1, 1);
-
- SkTileGridFactory factory(gridInfo);
- SkPictureRecorder recorder;
- recorder.beginRecording(1, 1, &factory);
- SkAutoTUnref<SkPicture> picture(recorder.endRecording());
-
- canvas.drawPicture(picture);
- }
-
- {
- // RTree
- SkRTreeFactory factory;
- SkPictureRecorder recorder;
- recorder.beginRecording(1, 1, &factory);
- SkAutoTUnref<SkPicture> picture(recorder.endRecording());
-
- canvas.drawPicture(picture);
- }
-}
-
static void test_clip_bound_opt(skiatest::Reporter* reporter) {
// Test for crbug.com/229011
SkRect rect1 = SkRect::MakeXYWH(SkIntToScalar(4), SkIntToScalar(4),
@@ -1765,7 +1724,6 @@ DEF_TEST(Picture, reporter) {
test_gatherpixelrefs(reporter);
test_gatherpixelrefsandrects(reporter);
test_bitmap_with_encoded_data(reporter);
- test_draw_empty(reporter);
test_clip_bound_opt(reporter);
test_clip_expansion(reporter);
test_hierarchical(reporter);