aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkPictureRecorder.h11
-rw-r--r--src/core/SkPictureRecorder.cpp6
-rw-r--r--tests/PictureTest.cpp28
3 files changed, 45 insertions, 0 deletions
diff --git a/include/core/SkPictureRecorder.h b/include/core/SkPictureRecorder.h
index 811d02a36e..b24975acde 100644
--- a/include/core/SkPictureRecorder.h
+++ b/include/core/SkPictureRecorder.h
@@ -75,6 +75,17 @@ public:
SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture();
/**
+ * Signal that the caller is done recording, and update the cull rect to use for bounding
+ * box hierarchy (BBH) generation. The behavior is the same as calling
+ * endRecordingAsPicture(), except that this method updates the cull rect initially passed
+ * into beginRecording.
+ * @param cullRect the new culling rectangle to use as the overall bound for BBH generation
+ * and subsequent culling operations.
+ * @return the picture containing the recorded content.
+ */
+ SkPicture* SK_WARN_UNUSED_RESULT endRecordingAsPicture(const SkRect& cullRect);
+
+ /**
* Signal that the caller is done recording. This invalidates the canvas returned by
* beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
* must call unref() when they are done using it.
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
index 877314ccaf..0c50dd9bb7 100644
--- a/src/core/SkPictureRecorder.cpp
+++ b/src/core/SkPictureRecorder.cpp
@@ -95,6 +95,12 @@ SkPicture* SkPictureRecorder::endRecordingAsPicture() {
subPictureBytes));
}
+SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) {
+ fCullRect = cullRect;
+ return this->endRecordingAsPicture();
+}
+
+
void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
if (NULL == canvas) {
return;
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 0ccef3f0a9..b235a0cc23 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -984,6 +984,33 @@ static void test_clip_bound_opt(skiatest::Reporter* reporter) {
}
}
+static void test_cull_rect_reset(skiatest::Reporter* reporter) {
+ SkPictureRecorder recorder;
+ SkRect bounds = SkRect::MakeWH(10, 10);
+ SkRTreeFactory factory;
+ SkCanvas* canvas = recorder.beginRecording(bounds, &factory);
+ bounds = SkRect::MakeWH(100, 100);
+ SkPaint paint;
+ canvas->drawRect(bounds, paint);
+ canvas->drawRect(bounds, paint);
+ const SkBigPicture* picture = recorder.endRecordingAsPicture(bounds)->asSkBigPicture();
+ REPORTER_ASSERT(reporter, picture);
+
+ SkRect finalCullRect = picture->cullRect();
+ REPORTER_ASSERT(reporter, 0 == finalCullRect.fLeft);
+ REPORTER_ASSERT(reporter, 0 == finalCullRect.fTop);
+ REPORTER_ASSERT(reporter, 100 == finalCullRect.fBottom);
+ REPORTER_ASSERT(reporter, 100 == finalCullRect.fRight);
+
+ const SkBBoxHierarchy* pictureBBH = picture->bbh();
+ SkRect bbhCullRect = pictureBBH->getRootBound();
+ REPORTER_ASSERT(reporter, 0 == bbhCullRect.fLeft);
+ REPORTER_ASSERT(reporter, 0 == bbhCullRect.fTop);
+ REPORTER_ASSERT(reporter, 100 == bbhCullRect.fBottom);
+ REPORTER_ASSERT(reporter, 100 == bbhCullRect.fRight);
+}
+
+
/**
* A canvas that records the number of clip commands.
*/
@@ -1129,6 +1156,7 @@ DEF_TEST(Picture, reporter) {
test_hierarchical(reporter);
test_gen_id(reporter);
test_savelayer_extraction(reporter);
+ test_cull_rect_reset(reporter);
}
static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {