aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-08-18 13:39:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-18 13:39:11 -0700
commit3e8232b6ef6b04290f0c280f88b38f8cd2c3f3ec (patch)
tree7a99de71e2aad5c98582969290381823abb260f4 /tests
parent3b5c86c7a2db25f82a8415b6c79d1ac580fc64ae (diff)
Counterproposal for skirting the BBH when the query fully contains the picture.
BUG=skia: R=reed@google.com, robertphillips@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/485703002
Diffstat (limited to 'tests')
-rw-r--r--tests/PictureTest.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index b7e4bb6cca..61cc5021fc 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkBBoxHierarchy.h"
#include "SkBlurImageFilter.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
@@ -662,7 +663,7 @@ static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) {
}
#ifdef SK_DEBUG
-// Ensure that deleting an empty SkPicture does not assert. Asserts only fire
+// Ensure that deleting an empty SkPicture does not assert. Asserts only fire
// in debug mode, so only run in debug mode.
static void test_deleting_empty_picture() {
SkPictureRecorder recorder;
@@ -1716,3 +1717,49 @@ DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) {
REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080);
REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000);
}
+
+struct CountingBBH : public SkBBoxHierarchy {
+ mutable int searchCalls;
+
+ CountingBBH() : searchCalls(0) {}
+
+ virtual void search(const SkIRect& query, SkTDArray<void*>* results) const {
+ this->searchCalls++;
+ }
+
+ // All other methods unimplemented.
+ virtual void insert(void* data, const SkIRect& bounds, bool defer) {}
+ virtual void flushDeferredInserts() {}
+ virtual void clear() {}
+ virtual int getCount() const { return 0; }
+ virtual int getDepth() const { return 0; }
+ virtual void rewindInserts() {}
+};
+
+class SpoonFedBBHFactory : public SkBBHFactory {
+public:
+ explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {}
+ virtual SkBBoxHierarchy* operator()(int width, int height) const {
+ return SkRef(fBBH);
+ }
+private:
+ SkBBoxHierarchy* fBBH;
+};
+
+// When the canvas clip covers the full picture, we don't need to call the BBH.
+DEF_TEST(Picture_SkipBBH, r) {
+ CountingBBH bbh;
+ SpoonFedBBHFactory factory(&bbh);
+
+ SkPictureRecorder recorder;
+ recorder.beginRecording(320, 240, &factory);
+ SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
+
+ SkCanvas big(640, 480), small(300, 200);
+
+ picture->draw(&big);
+ REPORTER_ASSERT(r, bbh.searchCalls == 0);
+
+ picture->draw(&small);
+ REPORTER_ASSERT(r, bbh.searchCalls == 1);
+}