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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | tests/PictureTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PictureBBHTest.cpp
diff --git a/tests/PictureBBHTest.cpp b/tests/PictureBBHTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3ff5625686b298fdcd99357222d1b9daa066ab9c
--- /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);
+}
« 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