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

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: 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 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) {
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::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
272 this->initFromStream(stream, success, proc);
273 }
274
275 void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefP roc proc) {
276 if (success) {
277 *success = false;
278 }
279 fRecord = NULL;
280 fPlayback = NULL;
281 fWidth = fHeight = 0;
282
283 SkPictInfo info; 281 SkPictInfo info;
284 282
285 if (!stream->read(&info, sizeof(info))) { 283 if (!StreamIsSKP(stream, &info)) {
286 return; 284 return NULL;
287 }
288 if (PICTURE_VERSION != info.fVersion) {
289 return;
290 } 285 }
291 286
292 if (stream->readBool()) { 287 SkPicturePlayback* playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, p roc));
293 fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
294 }
295 288
robertphillips 2013/06/24 17:22:09 Again, could we use SkNEW_ARGS here?
scroggo 2013/06/24 18:22:19 Done.
296 // do this at the end, so that they will be zero if we hit an error. 289 SkPicture* picture = SkNEW(SkPicture);
297 fWidth = info.fWidth; 290 picture->fWidth = info.fWidth;
298 fHeight = info.fHeight; 291 picture->fHeight = info.fHeight;
299 if (success) { 292 picture->fPlayback = playback;
300 *success = true; 293 return picture;
301 }
302 } 294 }
303 295
304 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 296 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
305 SkPicturePlayback* playback = fPlayback; 297 SkPicturePlayback* playback = fPlayback;
306 298
307 if (NULL == playback && fRecord) { 299 if (NULL == playback && fRecord) {
308 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 300 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
309 } 301 }
310 302
311 SkPictInfo info; 303 SkPictInfo info;
(...skipping 23 matching lines...) Expand all
335 } 327 }
336 328
337 #ifdef SK_BUILD_FOR_ANDROID 329 #ifdef SK_BUILD_FOR_ANDROID
338 void SkPicture::abortPlayback() { 330 void SkPicture::abortPlayback() {
339 if (NULL == fPlayback) { 331 if (NULL == fPlayback) {
340 return; 332 return;
341 } 333 }
342 fPlayback->abort(); 334 fPlayback->abort();
343 } 335 }
344 #endif 336 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698