| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 #include <new> | 8 #include <new> |
| 9 #include "SkBBoxHierarchy.h" | 9 #include "SkBBoxHierarchy.h" |
| 10 #include "SkOffsetTable.h" | 10 #include "SkOffsetTable.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 fPaints = NULL; | 263 fPaints = NULL; |
| 264 fPictureRefs = NULL; | 264 fPictureRefs = NULL; |
| 265 fPictureCount = 0; | 265 fPictureCount = 0; |
| 266 fOpData = NULL; | 266 fOpData = NULL; |
| 267 fFactoryPlayback = NULL; | 267 fFactoryPlayback = NULL; |
| 268 fBoundingHierarchy = NULL; | 268 fBoundingHierarchy = NULL; |
| 269 fStateTree = NULL; | 269 fStateTree = NULL; |
| 270 } | 270 } |
| 271 | 271 |
| 272 SkPicturePlayback::~SkPicturePlayback() { | 272 SkPicturePlayback::~SkPicturePlayback() { |
| 273 fOpData->unref(); | 273 SkSafeUnref(fOpData); |
| 274 | 274 |
| 275 SkSafeUnref(fBitmaps); | 275 SkSafeUnref(fBitmaps); |
| 276 SkSafeUnref(fPaints); | 276 SkSafeUnref(fPaints); |
| 277 SkSafeUnref(fBoundingHierarchy); | 277 SkSafeUnref(fBoundingHierarchy); |
| 278 SkSafeUnref(fStateTree); | 278 SkSafeUnref(fStateTree); |
| 279 | 279 |
| 280 for (int i = 0; i < fPictureCount; i++) { | 280 for (int i = 0; i < fPictureCount; i++) { |
| 281 fPictureRefs[i]->unref(); | 281 fPictureRefs[i]->unref(); |
| 282 } | 282 } |
| 283 SkDELETE_ARRAY(fPictureRefs); | 283 SkDELETE_ARRAY(fPictureRefs); |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 fPaints = SkTRefArray<SkPaint>::Create(size); | 605 fPaints = SkTRefArray<SkPaint>::Create(size); |
| 606 for (size_t i = 0; i < size; ++i) { | 606 for (size_t i = 0; i < size; ++i) { |
| 607 buffer.readPaint(&fPaints->writableAt(i)); | 607 buffer.readPaint(&fPaints->writableAt(i)); |
| 608 } | 608 } |
| 609 } break; | 609 } break; |
| 610 case SK_PICT_PATH_BUFFER_TAG: | 610 case SK_PICT_PATH_BUFFER_TAG: |
| 611 if (size > 0) { | 611 if (size > 0) { |
| 612 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); | 612 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); |
| 613 } | 613 } |
| 614 break; | 614 break; |
| 615 case SK_PICT_READER_TAG: { |
| 616 SkAutoMalloc storage(size); |
| 617 if (!buffer.readByteArray(storage.get(), size) || |
| 618 !buffer.validate(NULL == fOpData)) { |
| 619 return false; |
| 620 } |
| 621 SkASSERT(NULL == fOpData); |
| 622 fOpData = SkData::NewFromMalloc(storage.detach(), size); |
| 623 } break; |
| 624 case SK_PICT_PICTURE_TAG: { |
| 625 if (!buffer.validate((0 == fPictureCount) && (NULL == fPictureRefs))
) { |
| 626 return false; |
| 627 } |
| 628 fPictureCount = size; |
| 629 fPictureRefs = SkNEW_ARRAY(SkPicture*, fPictureCount); |
| 630 bool success = true; |
| 631 int i = 0; |
| 632 for ( ; i < fPictureCount; i++) { |
| 633 fPictureRefs[i] = SkPicture::CreateFromBuffer(buffer); |
| 634 if (NULL == fPictureRefs[i]) { |
| 635 success = false; |
| 636 break; |
| 637 } |
| 638 } |
| 639 if (!success) { |
| 640 // Delete all of the pictures that were already created (up to b
ut excluding i): |
| 641 for (int j = 0; j < i; j++) { |
| 642 fPictureRefs[j]->unref(); |
| 643 } |
| 644 // Delete the array |
| 645 SkDELETE_ARRAY(fPictureRefs); |
| 646 fPictureCount = 0; |
| 647 return false; |
| 648 } |
| 649 } break; |
| 615 default: | 650 default: |
| 616 // The tag was invalid. | 651 // The tag was invalid. |
| 617 return false; | 652 return false; |
| 618 } | 653 } |
| 619 return true; // success | 654 return true; // success |
| 620 } | 655 } |
| 621 | 656 |
| 622 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, | 657 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, |
| 623 const SkPictInfo& info, | 658 const SkPictInfo& info, |
| 624 SkPicture::InstallPixelRe
fProc proc) { | 659 SkPicture::InstallPixelRe
fProc proc) { |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 for (index = 0; index < fPictureCount; index++) | 1765 for (index = 0; index < fPictureCount; index++) |
| 1731 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1766 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
| 1732 "picture%p, ", fPictureRefs[index]); | 1767 "picture%p, ", fPictureRefs[index]); |
| 1733 if (fPictureCount > 0) | 1768 if (fPictureCount > 0) |
| 1734 SkDebugf("%s0};\n", pBuffer); | 1769 SkDebugf("%s0};\n", pBuffer); |
| 1735 | 1770 |
| 1736 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1771 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
| 1737 } | 1772 } |
| 1738 | 1773 |
| 1739 #endif | 1774 #endif |
| OLD | NEW |