OLD | NEW |
---|---|
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 Loading... | |
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 if (!stream->readBool()) { | |
reed1
2013/06/25 15:40:10
// What is the bool we are checking?
scroggo
2013/06/25 16:54:35
In SkPicture::serialize, we record true if there w
| |
280 return false; | |
281 } | |
282 | |
283 if (pInfo != NULL) { | |
284 *pInfo = info; | |
285 } | |
286 return true; | |
269 } | 287 } |
270 | 288 |
271 SkPicture::SkPicture(SkStream* stream, bool* success, InstallPixelRefProc proc) { | 289 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
272 this->initFromStream(stream, success, proc); | 290 : fPlayback(playback) |
273 } | 291 , fRecord(NULL) |
292 , fWidth(width) | |
293 , fHeight(height) {} | |
274 | 294 |
275 void SkPicture::initFromStream(SkStream* stream, bool* success, InstallPixelRefP roc proc) { | 295 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; | 296 SkPictInfo info; |
284 | 297 |
285 if (!stream->read(&info, sizeof(info))) { | 298 if (!StreamIsSKP(stream, &info)) { |
286 return; | 299 return NULL; |
287 } | |
288 if (PICTURE_VERSION != info.fVersion) { | |
289 return; | |
290 } | 300 } |
291 | 301 |
292 if (stream->readBool()) { | 302 SkPicturePlayback* playback = SkNEW_ARGS(SkPicturePlayback, (stream, info, p roc)); |
293 fPlayback = SkNEW_ARGS(SkPicturePlayback, (stream, info, proc)); | |
294 } | |
295 | 303 |
296 // do this at the end, so that they will be zero if we hit an error. | 304 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 } | 305 } |
303 | 306 |
304 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 307 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
305 SkPicturePlayback* playback = fPlayback; | 308 SkPicturePlayback* playback = fPlayback; |
306 | 309 |
307 if (NULL == playback && fRecord) { | 310 if (NULL == playback && fRecord) { |
308 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | 311 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); |
309 } | 312 } |
310 | 313 |
311 SkPictInfo info; | 314 SkPictInfo info; |
(...skipping 23 matching lines...) Expand all Loading... | |
335 } | 338 } |
336 | 339 |
337 #ifdef SK_BUILD_FOR_ANDROID | 340 #ifdef SK_BUILD_FOR_ANDROID |
338 void SkPicture::abortPlayback() { | 341 void SkPicture::abortPlayback() { |
339 if (NULL == fPlayback) { | 342 if (NULL == fPlayback) { |
340 return; | 343 return; |
341 } | 344 } |
342 fPlayback->abort(); | 345 fPlayback->abort(); |
343 } | 346 } |
344 #endif | 347 #endif |
OLD | NEW |