| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * 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 |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include <new> | 7 #include <new> |
| 8 #include "SkImageGenerator.h" | 8 #include "SkImageGenerator.h" |
| 9 #include "SkPictureData.h" | 9 #include "SkPictureData.h" |
| 10 #include "SkPictureRecord.h" | 10 #include "SkPictureRecord.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); | 59 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); |
| 60 fPictureCount = pictures.count(); | 60 fPictureCount = pictures.count(); |
| 61 if (fPictureCount > 0) { | 61 if (fPictureCount > 0) { |
| 62 fPictureRefs = new const SkPicture* [fPictureCount]; | 62 fPictureRefs = new const SkPicture* [fPictureCount]; |
| 63 for (int i = 0; i < fPictureCount; i++) { | 63 for (int i = 0; i < fPictureCount; i++) { |
| 64 fPictureRefs[i] = pictures[i]; | 64 fPictureRefs[i] = pictures[i]; |
| 65 fPictureRefs[i]->ref(); | 65 fPictureRefs[i]->ref(); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 const SkTDArray<SkDrawable* >& drawables = record.getDrawableRefs(); |
| 70 fDrawableCount = drawables.count(); |
| 71 if (fDrawableCount > 0) { |
| 72 fDrawableRefs = new SkDrawable* [fDrawableCount]; |
| 73 for (int i = 0; i < fDrawableCount; i++) { |
| 74 fDrawableRefs[i] = drawables[i]; |
| 75 fDrawableRefs[i]->ref(); |
| 76 } |
| 77 } |
| 78 |
| 69 // templatize to consolidate with similar picture logic? | 79 // templatize to consolidate with similar picture logic? |
| 70 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); | 80 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); |
| 71 fTextBlobCount = blobs.count(); | 81 fTextBlobCount = blobs.count(); |
| 72 if (fTextBlobCount > 0) { | 82 if (fTextBlobCount > 0) { |
| 73 fTextBlobRefs = new const SkTextBlob* [fTextBlobCount]; | 83 fTextBlobRefs = new const SkTextBlob* [fTextBlobCount]; |
| 74 for (int i = 0; i < fTextBlobCount; ++i) { | 84 for (int i = 0; i < fTextBlobCount; ++i) { |
| 75 fTextBlobRefs[i] = SkRef(blobs[i]); | 85 fTextBlobRefs[i] = SkRef(blobs[i]); |
| 76 } | 86 } |
| 77 } | 87 } |
| 78 | 88 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 fImageCount = 0; | 105 fImageCount = 0; |
| 96 fFactoryPlayback = nullptr; | 106 fFactoryPlayback = nullptr; |
| 97 } | 107 } |
| 98 | 108 |
| 99 SkPictureData::~SkPictureData() { | 109 SkPictureData::~SkPictureData() { |
| 100 for (int i = 0; i < fPictureCount; i++) { | 110 for (int i = 0; i < fPictureCount; i++) { |
| 101 fPictureRefs[i]->unref(); | 111 fPictureRefs[i]->unref(); |
| 102 } | 112 } |
| 103 delete[] fPictureRefs; | 113 delete[] fPictureRefs; |
| 104 | 114 |
| 115 for (int i = 0; i < fDrawableCount; i++) { |
| 116 fDrawableRefs[i]->unref(); |
| 117 } |
| 118 delete[] fDrawableRefs; |
| 119 |
| 105 for (int i = 0; i < fTextBlobCount; i++) { | 120 for (int i = 0; i < fTextBlobCount; i++) { |
| 106 fTextBlobRefs[i]->unref(); | 121 fTextBlobRefs[i]->unref(); |
| 107 } | 122 } |
| 108 delete[] fTextBlobRefs; | 123 delete[] fTextBlobRefs; |
| 109 | 124 |
| 110 for (int i = 0; i < fImageCount; i++) { | 125 for (int i = 0; i < fImageCount; i++) { |
| 111 fImageRefs[i]->unref(); | 126 fImageRefs[i]->unref(); |
| 112 } | 127 } |
| 113 delete[] fImageRefs; | 128 delete[] fImageRefs; |
| 114 | 129 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); | 314 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); |
| 300 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); | 315 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); |
| 301 | 316 |
| 302 if (fPictureCount > 0) { | 317 if (fPictureCount > 0) { |
| 303 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); | 318 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); |
| 304 for (int i = 0; i < fPictureCount; i++) { | 319 for (int i = 0; i < fPictureCount; i++) { |
| 305 fPictureRefs[i]->flatten(buffer); | 320 fPictureRefs[i]->flatten(buffer); |
| 306 } | 321 } |
| 307 } | 322 } |
| 308 | 323 |
| 324 if (fDrawableCount > 0) { |
| 325 write_tag_size(buffer, SK_PICT_DRAWABLE_TAG, fDrawableCount); |
| 326 for (int i = 0; i < fDrawableCount; i++) { |
| 327 buffer.writeFlattenable(fDrawableRefs[i]); |
| 328 } |
| 329 } |
| 330 |
| 309 // Write this picture playback's data into a writebuffer | 331 // Write this picture playback's data into a writebuffer |
| 310 this->flattenToBuffer(buffer); | 332 this->flattenToBuffer(buffer); |
| 311 buffer.write32(SK_PICT_EOF_TAG); | 333 buffer.write32(SK_PICT_EOF_TAG); |
| 312 } | 334 } |
| 313 | 335 |
| 314 /////////////////////////////////////////////////////////////////////////////// | 336 /////////////////////////////////////////////////////////////////////////////// |
| 315 | 337 |
| 316 /** | 338 /** |
| 317 * Return the corresponding SkReadBuffer flags, given a set of | 339 * Return the corresponding SkReadBuffer flags, given a set of |
| 318 * SkPictInfo flags. | 340 * SkPictInfo flags. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { | 465 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { |
| 444 return buffer.readImage(); | 466 return buffer.readImage(); |
| 445 } | 467 } |
| 446 | 468 |
| 447 // Need a shallow wrapper to return const SkPicture* to match the other factorie
s, | 469 // Need a shallow wrapper to return const SkPicture* to match the other factorie
s, |
| 448 // as SkPicture::CreateFromBuffer() returns SkPicture* | 470 // as SkPicture::CreateFromBuffer() returns SkPicture* |
| 449 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) { | 471 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) { |
| 450 return SkPicture::MakeFromBuffer(buffer).release(); | 472 return SkPicture::MakeFromBuffer(buffer).release(); |
| 451 } | 473 } |
| 452 | 474 |
| 475 static const SkDrawable* create_drawable_from_buffer(SkReadBuffer& buffer) { |
| 476 return (SkDrawable*) buffer.readFlattenable(SkFlattenable::kSkDrawable_Type)
; |
| 477 } |
| 478 |
| 453 template <typename T> | 479 template <typename T> |
| 454 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, | 480 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, |
| 455 const T*** array, int* outCount, const T* (*factory)(
SkReadBuffer&)) { | 481 const T*** array, int* outCount, const T* (*factory)(
SkReadBuffer&)) { |
| 456 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) { | 482 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) { |
| 457 return false; | 483 return false; |
| 458 } | 484 } |
| 459 if (0 == inCount) { | 485 if (0 == inCount) { |
| 460 return true; | 486 return true; |
| 461 } | 487 } |
| 462 *outCount = inCount; | 488 *outCount = inCount; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 559 } |
| 534 SkASSERT(nullptr == fOpData); | 560 SkASSERT(nullptr == fOpData); |
| 535 fOpData = std::move(data); | 561 fOpData = std::move(data); |
| 536 } break; | 562 } break; |
| 537 case SK_PICT_PICTURE_TAG: | 563 case SK_PICT_PICTURE_TAG: |
| 538 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou
nt, | 564 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou
nt, |
| 539 create_picture_from_buffer)) { | 565 create_picture_from_buffer)) { |
| 540 return false; | 566 return false; |
| 541 } | 567 } |
| 542 break; | 568 break; |
| 569 case SK_PICT_DRAWABLE_TAG: |
| 570 if (!new_array_from_buffer(buffer, size, (const SkDrawable***)&fDraw
ableRefs, |
| 571 &fDrawableCount, create_drawable_from_buf
fer)) { |
| 572 return false; |
| 573 } |
| 574 break; |
| 543 default: | 575 default: |
| 544 // The tag was invalid. | 576 // The tag was invalid. |
| 545 return false; | 577 return false; |
| 546 } | 578 } |
| 547 return true; // success | 579 return true; // success |
| 548 } | 580 } |
| 549 | 581 |
| 550 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, | 582 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, |
| 551 const SkPictInfo& info, | 583 const SkPictInfo& info, |
| 552 SkPicture::InstallPixelRefProc pr
oc, | 584 SkPicture::InstallPixelRefProc pr
oc, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } else { | 655 } else { |
| 624 return this->suitableForGpuRasterization(nullptr, reason); | 656 return this->suitableForGpuRasterization(nullptr, reason); |
| 625 } | 657 } |
| 626 } | 658 } |
| 627 | 659 |
| 628 bool SkPictureData::suitableForLayerOptimization() const { | 660 bool SkPictureData::suitableForLayerOptimization() const { |
| 629 return fContentInfo.numLayers() > 0; | 661 return fContentInfo.numLayers() > 0; |
| 630 } | 662 } |
| 631 #endif | 663 #endif |
| 632 /////////////////////////////////////////////////////////////////////////////// | 664 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |