| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 void SkPictureData::init() { | 89 void SkPictureData::init() { |
| 90 fPictureRefs = nullptr; | 90 fPictureRefs = nullptr; |
| 91 fPictureCount = 0; | 91 fPictureCount = 0; |
| 92 fTextBlobRefs = nullptr; | 92 fTextBlobRefs = nullptr; |
| 93 fTextBlobCount = 0; | 93 fTextBlobCount = 0; |
| 94 fImageRefs = nullptr; | 94 fImageRefs = nullptr; |
| 95 fImageCount = 0; | 95 fImageCount = 0; |
| 96 fOpData = nullptr; | |
| 97 fFactoryPlayback = nullptr; | 96 fFactoryPlayback = nullptr; |
| 98 } | 97 } |
| 99 | 98 |
| 100 SkPictureData::~SkPictureData() { | 99 SkPictureData::~SkPictureData() { |
| 101 SkSafeUnref(fOpData); | |
| 102 | |
| 103 for (int i = 0; i < fPictureCount; i++) { | 100 for (int i = 0; i < fPictureCount; i++) { |
| 104 fPictureRefs[i]->unref(); | 101 fPictureRefs[i]->unref(); |
| 105 } | 102 } |
| 106 delete[] fPictureRefs; | 103 delete[] fPictureRefs; |
| 107 | 104 |
| 108 for (int i = 0; i < fTextBlobCount; i++) { | 105 for (int i = 0; i < fTextBlobCount; i++) { |
| 109 fTextBlobRefs[i]->unref(); | 106 fTextBlobRefs[i]->unref(); |
| 110 } | 107 } |
| 111 delete[] fTextBlobRefs; | 108 delete[] fTextBlobRefs; |
| 112 | 109 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 * | 348 * |
| 352 * We assert that if/when we see either of these, that we have not yet seen | 349 * We assert that if/when we see either of these, that we have not yet seen |
| 353 * the buffer tag, because if we have, then its too-late to deal with the | 350 * the buffer tag, because if we have, then its too-late to deal with the |
| 354 * factories or typefaces. | 351 * factories or typefaces. |
| 355 */ | 352 */ |
| 356 SkDEBUGCODE(bool haveBuffer = false;) | 353 SkDEBUGCODE(bool haveBuffer = false;) |
| 357 | 354 |
| 358 switch (tag) { | 355 switch (tag) { |
| 359 case SK_PICT_READER_TAG: | 356 case SK_PICT_READER_TAG: |
| 360 SkASSERT(nullptr == fOpData); | 357 SkASSERT(nullptr == fOpData); |
| 361 fOpData = SkData::NewFromStream(stream, size); | 358 fOpData = SkData::MakeFromStream(stream, size); |
| 362 if (!fOpData) { | 359 if (!fOpData) { |
| 363 return false; | 360 return false; |
| 364 } | 361 } |
| 365 break; | 362 break; |
| 366 case SK_PICT_FACTORY_TAG: { | 363 case SK_PICT_FACTORY_TAG: { |
| 367 SkASSERT(!haveBuffer); | 364 SkASSERT(!haveBuffer); |
| 368 size = stream->readU32(); | 365 size = stream->readU32(); |
| 369 fFactoryPlayback = new SkFactoryPlayback(size); | 366 fFactoryPlayback = new SkFactoryPlayback(size); |
| 370 for (size_t i = 0; i < size; i++) { | 367 for (size_t i = 0; i < size; i++) { |
| 371 SkString str; | 368 SkString str; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 return false; | 519 return false; |
| 523 } | 520 } |
| 524 break; | 521 break; |
| 525 case SK_PICT_IMAGE_BUFFER_TAG: | 522 case SK_PICT_IMAGE_BUFFER_TAG: |
| 526 if (!new_array_from_buffer(buffer, size, &fImageRefs, &fImageCount, | 523 if (!new_array_from_buffer(buffer, size, &fImageRefs, &fImageCount, |
| 527 create_image_from_buffer)) { | 524 create_image_from_buffer)) { |
| 528 return false; | 525 return false; |
| 529 } | 526 } |
| 530 break; | 527 break; |
| 531 case SK_PICT_READER_TAG: { | 528 case SK_PICT_READER_TAG: { |
| 532 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 529 auto data(SkData::MakeUninitialized(size)); |
| 533 if (!buffer.readByteArray(data->writable_data(), size) || | 530 if (!buffer.readByteArray(data->writable_data(), size) || |
| 534 !buffer.validate(nullptr == fOpData)) { | 531 !buffer.validate(nullptr == fOpData)) { |
| 535 return false; | 532 return false; |
| 536 } | 533 } |
| 537 SkASSERT(nullptr == fOpData); | 534 SkASSERT(nullptr == fOpData); |
| 538 fOpData = data.detach(); | 535 fOpData = std::move(data); |
| 539 } break; | 536 } break; |
| 540 case SK_PICT_PICTURE_TAG: | 537 case SK_PICT_PICTURE_TAG: |
| 541 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou
nt, | 538 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou
nt, |
| 542 create_picture_from_buffer)) { | 539 create_picture_from_buffer)) { |
| 543 return false; | 540 return false; |
| 544 } | 541 } |
| 545 break; | 542 break; |
| 546 default: | 543 default: |
| 547 // The tag was invalid. | 544 // The tag was invalid. |
| 548 return false; | 545 return false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 625 } |
| 629 } | 626 } |
| 630 | 627 |
| 631 bool SkPictureData::suitableForLayerOptimization() const { | 628 bool SkPictureData::suitableForLayerOptimization() const { |
| 632 return fContentInfo.numLayers() > 0; | 629 return fContentInfo.numLayers() > 0; |
| 633 } | 630 } |
| 634 #endif | 631 #endif |
| 635 /////////////////////////////////////////////////////////////////////////////// | 632 /////////////////////////////////////////////////////////////////////////////// |
| 636 | 633 |
| 637 | 634 |
| OLD | NEW |