Index: tests/PictureBBHTest.cpp |
diff --git a/tests/PictureBBHTest.cpp b/tests/PictureBBHTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..66e509b015c286ab548a8f3fd456eabebf81dbe7 |
--- /dev/null |
+++ b/tests/PictureBBHTest.cpp |
@@ -0,0 +1,112 @@ |
+/* |
+ * 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; |
+ } |
+ |
+ // To clear the playback canvas at the beginning of the test |
+ virtual void resetCanvas(SkCanvas& resultCanvas) = 0; |
reed1
2014/10/29 15:56:14
I assumed we could always assert that nothing drew
|
+ // To record command into the SkPicture |
+ virtual void recordCommands(SkCanvas& recordingCanvas) = 0; |
+ // To verify the results of playing back the SkPicture |
+ virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* reporter) = 0; |
+ |
+ virtual ~PictureBBHTestBase() { } |
reed1
2014/10/29 15:56:14
nit: skia puts its destructor right after the cons
|
+ |
+ void run(skiatest::Reporter* reporter) { |
+ run(NULL, reporter); |
+ |
+ SkTileGridFactory::TileGridInfo gridInfo; |
+ gridInfo.fMargin.setEmpty(); |
+ gridInfo.fOffset.setZero(); |
+ gridInfo.fTileInterval.set(1, 1); |
+ SkTileGridFactory gridFactory(gridInfo); |
+ run(&gridFactory, reporter); |
+ |
+ SkRTreeFactory RTreeFactory; |
+ run(&RTreeFactory, reporter); |
+ } |
+ |
+private: |
+ void run(SkBBHFactory* factory, skiatest::Reporter* reporter) { |
+ SkCanvas playbackCanvas(fResultBitmap); |
+ resetCanvas(playbackCanvas); |
reed1
2014/10/29 15:56:14
nit: this->resetCanvas(...) for methods
|
+ SkPictureRecorder recorder; |
+ SkCanvas* recordCanvas = recorder.beginRecording(fPictureWidth, fPictureHeight, factory); |
+ recordCommands(*recordCanvas); |
+ SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
+ playbackCanvas.drawPicture(picture); |
+ validateResult(fResultBitmap, reporter); |
+ } |
+ |
+ 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) { } |
+ |
+ // Functions are all empty. Test passes by not crashing |
+ virtual void resetCanvas(SkCanvas& resultCanvas) { } |
reed1
2014/10/29 15:56:14
nit: SK_OVERRIDE in the subclasses
|
+ virtual void recordCommands(SkCanvas& recordingCanvas) { } |
+ virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* reporter) { } |
+ virtual ~DrawEmptyPictureBBHTest() { } |
+}; |
+ |
+// 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 resetCanvas(SkCanvas& resultCanvas) { |
+ resultCanvas.clear(SK_ColorGREEN); |
+ // intersect with out of bounds rect -> empty clip. |
+ resultCanvas.clipRect(SkRect::MakeXYWH(10, 10, 1, 1), SkRegion::kIntersect_Op); |
reed1
2014/10/29 15:56:14
seems like we can fold this clip call into the rec
|
+ } |
+ |
+ virtual void recordCommands(SkCanvas& recordingCanvas) { |
+ SkPaint paint; |
+ recordingCanvas.drawRect(SkRect::MakeXYWH(0, 0, 3, 3), paint); |
+ } |
+ |
+ virtual void validateResult(SkBitmap& playbackResult, skiatest::Reporter* reporter) { |
+ REPORTER_ASSERT(reporter, SK_ColorGREEN == playbackResult.getColor(0, 0)); |
+ } |
+ |
+ virtual ~EmptyClipPictureBBHTest() { } |
+}; |
+ |
+DEF_TEST(PictureBBH, reporter) { |
+ |
+ DrawEmptyPictureBBHTest emptyPictureTest; |
+ emptyPictureTest.run(reporter); |
+ |
+ EmptyClipPictureBBHTest emptyClipPictureTest; |
+ emptyClipPictureTest.run(reporter); |
+} |