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

Side by Side 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: respond to comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2007 The Android Open Source Project 3 * Copyright 2007 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkPictureFlat.h" 10 #include "SkPictureFlat.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 this->endRecording(); 257 this->endRecording();
258 if (fPlayback) { 258 if (fPlayback) {
259 fPlayback->draw(*surface, callback); 259 fPlayback->draw(*surface, callback);
260 } 260 }
261 } 261 }
262 262
263 /////////////////////////////////////////////////////////////////////////////// 263 ///////////////////////////////////////////////////////////////////////////////
264 264
265 #include "SkStream.h" 265 #include "SkStream.h"
266 266
267 SkPicture::SkPicture(SkStream* stream) { 267 bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* info) {
268 this->initFromStream(stream, NULL, NULL); 268 if (NULL == stream || NULL == info) {
reed1 2013/06/24 22:24:14 Why do we return false on info==null? 1. crashing
scroggo 2013/06/25 15:36:50 Done.
269 return false;
270 }
271 if (!stream->read(info, sizeof(SkPictInfo))) {
272 return false;
273 }
274 if (PICTURE_VERSION != info->fVersion) {
275 return false;
276 }
277 return stream->readBool();
269 } 278 }
270 279
271 SkPicture::SkPicture(SkStream* stream, bool* success, InstallPixelRefProc proc) { 280 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
272 this->initFromStream(stream, success, proc); 281 : fPlayback(playback)
273 } 282 , fRecord(NULL)
283 , fWidth(width)
284 , fHeight(height) {}
274 285
275 void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefP roc proc) { 286 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
276 if (success) {
277 *success = false;
278 }
279 fRecord = NULL;
280 fPlayback = NULL;
281 fWidth = fHeight = 0;
282
283 SkPictInfo info; 287 SkPictInfo info;
284 288
285 if (!stream->read(&info, sizeof(info))) { 289 if (!StreamIsSKP(stream, &info)) {
286 return; 290 return NULL;
287 }
288 if (PICTURE_VERSION != info.fVersion) {
289 return;
290 } 291 }
291 292
292 if (stream->readBool()) { 293 SkPicturePlayback* playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, p roc));
293 fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
294 }
295 294
296 // do this at the end, so that they will be zero if we hit an error. 295 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
297 fWidth = info.fWidth;
298 fHeight = info.fHeight;
299 if (success) {
300 *success = true;
301 }
302 } 296 }
303 297
304 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 298 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
305 SkPicturePlayback* playback = fPlayback; 299 SkPicturePlayback* playback = fPlayback;
306 300
307 if (NULL == playback && fRecord) { 301 if (NULL == playback && fRecord) {
308 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 302 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
309 } 303 }
310 304
311 SkPictInfo info; 305 SkPictInfo info;
(...skipping 23 matching lines...) Expand all
335 } 329 }
336 330
337 #ifdef SK_BUILD_FOR_ANDROID 331 #ifdef SK_BUILD_FOR_ANDROID
338 void SkPicture::abortPlayback() { 332 void SkPicture::abortPlayback() {
339 if (NULL == fPlayback) { 333 if (NULL == fPlayback) {
340 return; 334 return;
341 } 335 }
342 fPlayback->abort(); 336 fPlayback->abort();
343 } 337 }
344 #endif 338 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698