aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPicture.cpp54
-rw-r--r--src/core/SkPicturePlayback.cpp7
2 files changed, 33 insertions, 28 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index ab2faea6b6..2b488dec02 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -264,41 +264,47 @@ void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
#include "SkStream.h"
-SkPicture::SkPicture(SkStream* stream) {
- this->initFromStream(stream, NULL, NULL);
-}
+bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
+ if (NULL == stream) {
+ return false;
+ }
-SkPicture::SkPicture(SkStream* stream, bool* success, InstallPixelRefProc proc) {
- this->initFromStream(stream, success, proc);
-}
+ SkPictInfo info;
+ if (!stream->read(&info, sizeof(SkPictInfo))) {
+ return false;
+ }
+ if (PICTURE_VERSION != info.fVersion) {
+ return false;
+ }
-void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefProc proc) {
- if (success) {
- *success = false;
+ if (pInfo != NULL) {
+ *pInfo = info;
}
- fRecord = NULL;
- fPlayback = NULL;
- fWidth = fHeight = 0;
+ return true;
+}
+
+SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
+ : fPlayback(playback)
+ , fRecord(NULL)
+ , fWidth(width)
+ , fHeight(height) {}
+SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc proc) {
SkPictInfo info;
- if (!stream->read(&info, sizeof(info))) {
- return;
- }
- if (PICTURE_VERSION != info.fVersion) {
- return;
+ if (!StreamIsSKP(stream, &info)) {
+ return NULL;
}
+ SkPicturePlayback* playback;
+ // Check to see if there is a playback to recreate.
if (stream->readBool()) {
- fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
+ playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
+ } else {
+ playback = NULL;
}
- // do this at the end, so that they will be zero if we hit an error.
- fWidth = info.fWidth;
- fHeight = info.fHeight;
- if (success) {
- *success = true;
- }
+ return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
}
void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 898d379578..fe1a037cfc 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -520,15 +520,14 @@ void SkPicturePlayback::parseStreamTag(SkStream* stream, const SkPictInfo& info,
case PICT_PICTURE_TAG: {
fPictureCount = size;
fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount);
- bool success;
for (int i = 0; i < fPictureCount; i++) {
- fPictureRefs[i] = SkNEW_ARGS(SkPicture, (stream, &success, proc));
- // Success can only be false if PICTURE_VERSION does not match
+ fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc);
+ // CreateFromStream can only fail if PICTURE_VERSION does not match
// (which should never happen from here, since a sub picture will
// have the same PICTURE_VERSION as its parent) or if stream->read
// returns 0. In the latter case, we have a bug when writing the
// picture to begin with, which will be alerted to here.
- SkASSERT(success);
+ SkASSERT(fPictureRefs[i] != NULL);
}
} break;
case PICT_BUFFER_SIZE_TAG: {