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

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 a change in behavior Created 7 years, 5 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
« no previous file with comments | « samplecode/SamplePictFile.cpp ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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* pInfo) {
268 this->initFromStream(stream, NULL, NULL); 268 if (NULL == stream) {
269 return false;
270 }
271
272 SkPictInfo info;
273 if (!stream->read(&info, sizeof(SkPictInfo))) {
274 return false;
275 }
276 if (PICTURE_VERSION != info.fVersion) {
277 return false;
278 }
279
280 if (pInfo != NULL) {
281 *pInfo = info;
282 }
283 return true;
269 } 284 }
270 285
271 SkPicture::SkPicture(SkStream* stream, bool* success, InstallPixelRefProc proc) { 286 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
272 this->initFromStream(stream, success, proc); 287 : fPlayback(playback)
273 } 288 , fRecord(NULL)
289 , fWidth(width)
290 , fHeight(height) {}
274 291
275 void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefP roc proc) { 292 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; 293 SkPictInfo info;
284 294
285 if (!stream->read(&info, sizeof(info))) { 295 if (!StreamIsSKP(stream, &info)) {
286 return; 296 return NULL;
287 }
288 if (PICTURE_VERSION != info.fVersion) {
289 return;
290 } 297 }
291 298
299 SkPicturePlayback* playback;
300 // Check to see if there is a playback to recreate.
292 if (stream->readBool()) { 301 if (stream->readBool()) {
293 fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc)); 302 playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc));
303 } else {
304 playback = NULL;
294 } 305 }
295 306
296 // do this at the end, so that they will be zero if we hit an error. 307 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 } 308 }
303 309
304 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 310 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
305 SkPicturePlayback* playback = fPlayback; 311 SkPicturePlayback* playback = fPlayback;
306 312
307 if (NULL == playback && fRecord) { 313 if (NULL == playback && fRecord) {
308 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 314 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
309 } 315 }
310 316
311 SkPictInfo info; 317 SkPictInfo info;
(...skipping 23 matching lines...) Expand all
335 } 341 }
336 342
337 #ifdef SK_BUILD_FOR_ANDROID 343 #ifdef SK_BUILD_FOR_ANDROID
338 void SkPicture::abortPlayback() { 344 void SkPicture::abortPlayback() {
339 if (NULL == fPlayback) { 345 if (NULL == fPlayback) {
340 return; 346 return;
341 } 347 }
342 fPlayback->abort(); 348 fPlayback->abort();
343 } 349 }
344 #endif 350 #endif
OLDNEW
« no previous file with comments | « samplecode/SamplePictFile.cpp ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698