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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 if (PICTURE_VERSION != info.fVersion) { | 286 if (PICTURE_VERSION != info.fVersion) { |
287 return false; | 287 return false; |
288 } | 288 } |
289 | 289 |
290 if (pInfo != NULL) { | 290 if (pInfo != NULL) { |
291 *pInfo = info; | 291 *pInfo = info; |
292 } | 292 } |
293 return true; | 293 return true; |
294 } | 294 } |
295 | 295 |
296 bool SkPicture::BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo) { | |
297 // Check magic bytes. | |
298 char magic[sizeof(kMagic)]; | |
299 | |
300 if (!buffer.readByteArray(magic, sizeof(kMagic)) || | |
301 (0 != memcmp(magic, kMagic, sizeof(kMagic)))) { | |
302 return false; | |
303 } | |
304 | |
305 SkPictInfo info; | |
306 if (!buffer.readByteArray(&info, sizeof(SkPictInfo))) { | |
307 return false; | |
308 } | |
309 | |
310 if (PICTURE_VERSION != info.fVersion) { | |
311 return false; | |
312 } | |
313 | |
314 if (pInfo != NULL) { | |
315 *pInfo = info; | |
316 } | |
317 return true; | |
318 } | |
319 | |
296 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 320 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
297 : fPlayback(playback) | 321 : fPlayback(playback) |
298 , fRecord(NULL) | 322 , fRecord(NULL) |
299 , fWidth(width) | 323 , fWidth(width) |
300 , fHeight(height) {} | 324 , fHeight(height) {} |
301 | 325 |
302 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { | 326 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { |
303 SkPictInfo info; | 327 SkPictInfo info; |
304 | 328 |
305 if (!StreamIsSKP(stream, &info)) { | 329 if (!StreamIsSKP(stream, &info)) { |
306 return NULL; | 330 return NULL; |
307 } | 331 } |
308 | 332 |
309 SkPicturePlayback* playback; | 333 SkPicturePlayback* playback; |
310 // Check to see if there is a playback to recreate. | 334 // Check to see if there is a playback to recreate. |
311 if (stream->readBool()) { | 335 if (stream->readBool()) { |
312 playback = SkPicturePlayback::CreateFromStream(stream, info, proc); | 336 playback = SkPicturePlayback::CreateFromStream(stream, info, proc); |
313 if (NULL == playback) { | 337 if (NULL == playback) { |
314 return NULL; | 338 return NULL; |
315 } | 339 } |
316 } else { | 340 } else { |
317 playback = NULL; | 341 playback = NULL; |
318 } | 342 } |
319 | 343 |
320 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | 344 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); |
321 } | 345 } |
322 | 346 |
347 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { | |
348 SkPictInfo info; | |
349 | |
350 if (!BufferIsSKP(buffer, &info)) { | |
351 return NULL; | |
352 } | |
353 | |
354 SkPicturePlayback* playback; | |
355 // Check to see if there is a playback to recreate. | |
356 if (buffer.readBool()) { | |
357 playback = SkPicturePlayback::CreateFromBuffer(buffer); | |
358 if (NULL == playback) { | |
359 return NULL; | |
360 } | |
361 } else { | |
362 playback = NULL; | |
363 } | |
364 | |
365 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | |
366 } | |
367 | |
323 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 368 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
324 SkPicturePlayback* playback = fPlayback; | 369 SkPicturePlayback* playback = fPlayback; |
325 | 370 |
326 if (NULL == playback && fRecord) { | 371 if (NULL == playback && fRecord) { |
327 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | 372 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); |
328 } | 373 } |
329 | 374 |
330 SkPictInfo info; | 375 SkPictInfo info; |
331 | 376 |
332 info.fVersion = PICTURE_VERSION; | 377 info.fVersion = PICTURE_VERSION; |
(...skipping 16 matching lines...) Expand all Loading... | |
349 stream->writeBool(true); | 394 stream->writeBool(true); |
350 playback->serialize(stream, encoder); | 395 playback->serialize(stream, encoder); |
351 // delete playback if it is a local version (i.e. cons'd up just now) | 396 // delete playback if it is a local version (i.e. cons'd up just now) |
352 if (playback != fPlayback) { | 397 if (playback != fPlayback) { |
353 SkDELETE(playback); | 398 SkDELETE(playback); |
354 } | 399 } |
355 } else { | 400 } else { |
356 stream->writeBool(false); | 401 stream->writeBool(false); |
357 } | 402 } |
358 } | 403 } |
359 | 404 |
robertphillips
2014/02/05 18:02:33
Is there some way to share more of this code (e.g.
sugoi1
2014/02/05 21:33:06
Done.
| |
405 void SkPicture::flatten(SkWriteBuffer& buffer) const { | |
406 SkPicturePlayback* playback = fPlayback; | |
407 | |
408 if (NULL == playback && fRecord) { | |
409 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); | |
410 } | |
411 | |
412 SkPictInfo info; | |
413 | |
414 info.fVersion = PICTURE_VERSION; | |
415 info.fWidth = fWidth; | |
416 info.fHeight = fHeight; | |
417 info.fFlags = SkPictInfo::kCrossProcess_Flag; | |
418 // TODO: remove this flag, since we're always float (now) | |
419 info.fFlags |= SkPictInfo::kScalarIsFloat_Flag; | |
420 | |
421 if (8 == sizeof(void*)) { | |
422 info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | |
423 } | |
424 | |
425 // Write 8 magic bytes to ID this file format. | |
426 SkASSERT(sizeof(kMagic) == 8); | |
427 buffer.writeByteArray(kMagic, sizeof(kMagic)); | |
428 | |
429 buffer.writeByteArray(&info, sizeof(info)); | |
430 if (playback) { | |
431 buffer.writeBool(true); | |
432 playback->flatten(buffer); | |
433 // delete playback if it is a local version (i.e. cons'd up just now) | |
434 if (playback != fPlayback) { | |
435 SkDELETE(playback); | |
436 } | |
437 } else { | |
438 buffer.writeBool(false); | |
439 } | |
440 } | |
441 | |
360 bool SkPicture::willPlayBackBitmaps() const { | 442 bool SkPicture::willPlayBackBitmaps() const { |
361 if (!fPlayback) return false; | 443 if (!fPlayback) return false; |
362 return fPlayback->containsBitmaps(); | 444 return fPlayback->containsBitmaps(); |
363 } | 445 } |
364 | 446 |
365 #ifdef SK_BUILD_FOR_ANDROID | 447 #ifdef SK_BUILD_FOR_ANDROID |
366 void SkPicture::abortPlayback() { | 448 void SkPicture::abortPlayback() { |
367 if (NULL == fPlayback) { | 449 if (NULL == fPlayback) { |
368 return; | 450 return; |
369 } | 451 } |
370 fPlayback->abort(); | 452 fPlayback->abort(); |
371 } | 453 } |
372 #endif | 454 #endif |
OLD | NEW |