Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/core/SkPicture.cpp

Issue 17113004: Replace SkPicture(SkStream) constructors with a factory. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove dead function declaration. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index ab2faea6b6b4eb38b6e0a9a9ac4ae5338cb46c8b..dbe879c3190949d8813b6305432e80a9730fa93a 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -264,41 +264,33 @@ void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) {
#include "SkStream.h"
-SkPicture::SkPicture(SkStream* stream) {
- this->initFromStream(stream, NULL, NULL);
-}
-
-SkPicture::SkPicture(SkStream* stream, bool* success, InstallPixelRefProc proc) {
- this->initFromStream(stream, success, proc);
-}
-
-void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefProc proc) {
- if (success) {
- *success = false;
+bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* info) {
+ if (NULL == stream || NULL == info) {
+ return false;
}
- fRecord = NULL;
- fPlayback = NULL;
- fWidth = fHeight = 0;
+ if (!stream->read(info, sizeof(SkPictInfo))) {
+ return false;
+ }
+ if (PICTURE_VERSION != info->fVersion) {
+ return false;
+ }
+ return stream->readBool();
+}
+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;
}
- if (stream->readBool()) {
- fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
- }
+ SkPicturePlayback* playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
robertphillips 2013/06/24 17:22:09 Again, could we use SkNEW_ARGS here?
scroggo 2013/06/24 18:22:19 Done.
- // 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;
- }
+ SkPicture* picture = SkNEW(SkPicture);
+ picture->fWidth = info.fWidth;
+ picture->fHeight = info.fHeight;
+ picture->fPlayback = playback;
+ return picture;
}
void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {

Powered by Google App Engine
This is Rietveld 408576698