aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar schenney <schenney@chromium.org>2015-07-07 14:27:10 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-07 14:27:10 -0700
commiteeff8bb8ffdd6e77823a23bad3d23e4f15057681 (patch)
treeabc031970b47be982d6570749ce8107fe2c6426a
parent0dacc6708d5db4fbe755d7b1d0716b51fe703058 (diff)
Allow reset of the SkPictureRecorder cull rect and other parameters during endRecording.
For some users of SkPictureRecorder, the cull rect is more efficiently determined while drawing is in progress, rather than when recording starts. The existing API requires the cull rect at start time, even though the information is not used for any culling purpose until the end of recording. This patch provides a means to reset the cull rect when recording ends, allowing users to update the rect based on information learned during drawing and for the new rect to be used as the culling bound. A valid bound is still required on the beginRecording call because it sizes the underlying canvas and sets the aspect ratio for any bounding box hierarchy. The bounding box factory can also be specified and parameters that control SkPicture creation. R=mtklein, reed1 BUG=skia:3919 Review URL: https://codereview.chromium.org/1178673007
-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) {