aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkPicture.h7
-rw-r--r--src/core/SkPicture.cpp5
-rw-r--r--src/core/SkPicturePlayback.cpp12
-rw-r--r--src/core/SkPicturePlayback.h2
-rw-r--r--tests/PictureTest.cpp45
5 files changed, 71 insertions, 0 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 9866505141..fa1cc4954d 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -186,6 +186,13 @@ public:
*/
void serialize(SkWStream*, EncodeBitmap encoder = NULL) const;
+ /**
+ * Returns true if any bitmaps may be produced when this SkPicture
+ * is replayed.
+ * Returns false if called while still recording.
+ */
+ bool willPlayBackBitmaps() const;
+
#ifdef SK_BUILD_FOR_ANDROID
/** Signals that the caller is prematurely done replaying the drawing
commands. This can be called from a canvas virtual while the picture
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 1df56a52d7..4acc549377 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -354,6 +354,11 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
}
}
+bool SkPicture::willPlayBackBitmaps() const {
+ if (!fPlayback) return false;
+ return fPlayback->containsBitmaps();
+}
+
#ifdef SK_BUILD_FOR_ANDROID
void SkPicture::abortPlayback() {
if (NULL == fPlayback) {
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index f95c44343d..4ce29c8dbb 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -300,6 +300,18 @@ void SkPicturePlayback::dumpSize() const {
SafeCount(fRegions));
}
+bool SkPicturePlayback::containsBitmaps() const {
+ if (fBitmaps && fBitmaps->count() > 0) {
+ return true;
+ }
+ for (int i = 0; i < fPictureCount; ++i) {
+ if (fPictureRefs[i]->willPlayBackBitmaps()) {
+ return true;
+ }
+ }
+ return false;
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h
index 86c976c37a..6eb9ac3425 100644
--- a/src/core/SkPicturePlayback.h
+++ b/src/core/SkPicturePlayback.h
@@ -73,6 +73,8 @@ public:
void dumpSize() const;
+ bool containsBitmaps() const;
+
#ifdef SK_BUILD_FOR_ANDROID
// Can be called in the middle of playback (the draw() call). WIll abort the
// drawing and return from draw() after the "current" op code is done
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index c7ddcbc9ef..9ef4bb06bd 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -182,6 +182,7 @@ static void test_gatherpixelrefs(skiatest::Reporter* reporter) {
for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) {
SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k]));
+ REPORTER_ASSERT(reporter, pic->willPlayBackBitmaps() || N == 0);
// quick check for a small piece of each quadrant, which should just
// contain 1 bitmap.
for (size_t i = 0; i < SK_ARRAY_COUNT(pos); ++i) {
@@ -607,6 +608,49 @@ static void test_clip_expansion(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2);
}
+static void test_hierarchical(skiatest::Reporter* reporter) {
+ SkBitmap bm;
+ make_bm(&bm, 10, 10, SK_ColorRED, true);
+
+ SkCanvas* canvas;
+
+ SkPicture childPlain;
+ childPlain.beginRecording(10, 10);
+ childPlain.endRecording();
+ REPORTER_ASSERT(reporter, !childPlain.willPlayBackBitmaps()); // 0
+
+ SkPicture childWithBitmap;
+ childWithBitmap.beginRecording(10, 10)->drawBitmap(bm, 0, 0);
+ childWithBitmap.endRecording();
+ REPORTER_ASSERT(reporter, childWithBitmap.willPlayBackBitmaps()); // 1
+
+ SkPicture parentPP;
+ canvas = parentPP.beginRecording(10, 10);
+ canvas->drawPicture(childPlain);
+ parentPP.endRecording();
+ REPORTER_ASSERT(reporter, !parentPP.willPlayBackBitmaps()); // 0
+
+ SkPicture parentPWB;
+ canvas = parentPWB.beginRecording(10, 10);
+ canvas->drawPicture(childWithBitmap);
+ parentPWB.endRecording();
+ REPORTER_ASSERT(reporter, parentPWB.willPlayBackBitmaps()); // 1
+
+ SkPicture parentWBP;
+ canvas = parentWBP.beginRecording(10, 10);
+ canvas->drawBitmap(bm, 0, 0);
+ canvas->drawPicture(childPlain);
+ parentWBP.endRecording();
+ REPORTER_ASSERT(reporter, parentWBP.willPlayBackBitmaps()); // 1
+
+ SkPicture parentWBWB;
+ canvas = parentWBWB.beginRecording(10, 10);
+ canvas->drawBitmap(bm, 0, 0);
+ canvas->drawPicture(childWithBitmap);
+ parentWBWB.endRecording();
+ REPORTER_ASSERT(reporter, parentWBWB.willPlayBackBitmaps()); // 2
+}
+
static void TestPicture(skiatest::Reporter* reporter) {
#ifdef SK_DEBUG
test_deleting_empty_playback();
@@ -620,6 +664,7 @@ static void TestPicture(skiatest::Reporter* reporter) {
test_clone_empty(reporter);
test_clip_bound_opt(reporter);
test_clip_expansion(reporter);
+ test_hierarchical(reporter);
}
#include "TestClassDef.h"