OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 |
10 #include "SkPictureFlat.h" | 9 #include "SkPictureFlat.h" |
11 #include "SkPictureData.h" | 10 #include "SkPictureData.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // This for compatibility with serialization code only. This is not cheap. | 446 // This for compatibility with serialization code only. This is not cheap. |
448 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info, | 447 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info, |
449 SkPicture const* const drawablePicts[], int d
rawableCount) { | 448 SkPicture const* const drawablePicts[], int d
rawableCount) { |
450 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei
ght()), 0/*flags*/); | 449 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei
ght()), 0/*flags*/); |
451 rec.beginRecording(); | 450 rec.beginRecording(); |
452 SkRecordDraw(src, &rec, drawablePicts, NULL, drawableCount, NULL/*bbh*/,
NULL/*callback*/); | 451 SkRecordDraw(src, &rec, drawablePicts, NULL, drawableCount, NULL/*bbh*/,
NULL/*callback*/); |
453 rec.endRecording(); | 452 rec.endRecording(); |
454 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); | 453 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); |
455 } | 454 } |
456 | 455 |
457 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 456 #ifdef SK_LEGACY_ENCODE_BITMAP |
| 457 // Helper to support the EncodeBitmap version of serialize. |
| 458 // Mimics the old behavior of always accepting the encoded data, and encoding |
| 459 // using EncodeBitmap if there was no encoded data. |
| 460 class EncodeBitmapSerializer : public SkPixelSerializer { |
| 461 public: |
| 462 explicit EncodeBitmapSerializer(SkPicture::EncodeBitmap encoder) |
| 463 : fEncoder(encoder) |
| 464 { |
| 465 SkASSERT(fEncoder); |
| 466 } |
| 467 |
| 468 virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true
; } |
| 469 |
| 470 virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels, |
| 471 size_t rowBytes) SK_OVERRIDE { |
| 472 // Required by signature of EncodeBitmap. |
| 473 size_t unused; |
| 474 SkBitmap bm; |
| 475 bm.installPixels(info, pixels, rowBytes); |
| 476 return fEncoder(&unused, bm); |
| 477 } |
| 478 |
| 479 private: |
| 480 SkPicture::EncodeBitmap fEncoder; |
| 481 }; |
| 482 |
| 483 void SkPicture::serialize(SkWStream* wStream, SkPicture::EncodeBitmap encoder) c
onst { |
| 484 EncodeBitmapSerializer serializer(encoder); |
| 485 this->serialize(wStream, &serializer); |
| 486 } |
| 487 |
| 488 #endif |
| 489 |
| 490 void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer)
const { |
458 SkPictInfo info; | 491 SkPictInfo info; |
459 this->createHeader(&info); | 492 this->createHeader(&info); |
460 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), | 493 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), |
461 this->drawableCount())); | 494 this->drawableCount())); |
462 | 495 |
463 stream->write(&info, sizeof(info)); | 496 stream->write(&info, sizeof(info)); |
464 if (data) { | 497 if (data) { |
465 stream->writeBool(true); | 498 stream->writeBool(true); |
466 data->serialize(stream, encoder); | 499 data->serialize(stream, pixelSerializer); |
467 } else { | 500 } else { |
468 stream->writeBool(false); | 501 stream->writeBool(false); |
469 } | 502 } |
470 } | 503 } |
471 | 504 |
472 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 505 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
473 SkPictInfo info; | 506 SkPictInfo info; |
474 this->createHeader(&info); | 507 this->createHeader(&info); |
475 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), | 508 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), |
476 this->drawableCount())); | 509 this->drawableCount())); |
(...skipping 22 matching lines...) Expand all Loading... |
499 | 532 |
500 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* dr
awablePicts, | 533 SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* dr
awablePicts, |
501 SkBBoxHierarchy* bbh) | 534 SkBBoxHierarchy* bbh) |
502 : fUniqueID(next_picture_generation_id()) | 535 : fUniqueID(next_picture_generation_id()) |
503 , fCullRect(cullRect) | 536 , fCullRect(cullRect) |
504 , fRecord(SkRef(record)) | 537 , fRecord(SkRef(record)) |
505 , fBBH(SkSafeRef(bbh)) | 538 , fBBH(SkSafeRef(bbh)) |
506 , fDrawablePicts(drawablePicts) // take ownership | 539 , fDrawablePicts(drawablePicts) // take ownership |
507 , fAnalysis(*fRecord) | 540 , fAnalysis(*fRecord) |
508 {} | 541 {} |
OLD | NEW |