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 "SkPictureData.h" | 8 #include "SkPictureData.h" |
9 #include "SkPictureRecord.h" | 9 #include "SkPictureRecord.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 fBitmaps = record.fBitmaps; | 46 fBitmaps = record.fBitmaps; |
47 fPaints = record.fPaints; | 47 fPaints = record.fPaints; |
48 fPaths = record.fPaths; | 48 fPaths = record.fPaths; |
49 | 49 |
50 this->initForPlayback(); | 50 this->initForPlayback(); |
51 | 51 |
52 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); | 52 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); |
53 fPictureCount = pictures.count(); | 53 fPictureCount = pictures.count(); |
54 if (fPictureCount > 0) { | 54 if (fPictureCount > 0) { |
55 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); | 55 fPictureRefs = new const SkPicture* [fPictureCount]; |
56 for (int i = 0; i < fPictureCount; i++) { | 56 for (int i = 0; i < fPictureCount; i++) { |
57 fPictureRefs[i] = pictures[i]; | 57 fPictureRefs[i] = pictures[i]; |
58 fPictureRefs[i]->ref(); | 58 fPictureRefs[i]->ref(); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 // templatize to consolidate with similar picture logic? | 62 // templatize to consolidate with similar picture logic? |
63 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); | 63 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); |
64 fTextBlobCount = blobs.count(); | 64 fTextBlobCount = blobs.count(); |
65 if (fTextBlobCount > 0) { | 65 if (fTextBlobCount > 0) { |
66 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); | 66 fTextBlobRefs = new const SkTextBlob* [fTextBlobCount]; |
67 for (int i = 0; i < fTextBlobCount; ++i) { | 67 for (int i = 0; i < fTextBlobCount; ++i) { |
68 fTextBlobRefs[i] = SkRef(blobs[i]); | 68 fTextBlobRefs[i] = SkRef(blobs[i]); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 const SkTDArray<const SkImage*>& imgs = record.getImageRefs(); | 72 const SkTDArray<const SkImage*>& imgs = record.getImageRefs(); |
73 fImageCount = imgs.count(); | 73 fImageCount = imgs.count(); |
74 if (fImageCount > 0) { | 74 if (fImageCount > 0) { |
75 fImageRefs = SkNEW_ARRAY(const SkImage*, fImageCount); | 75 fImageRefs = new const SkImage* [fImageCount]; |
76 for (int i = 0; i < fImageCount; ++i) { | 76 for (int i = 0; i < fImageCount; ++i) { |
77 fImageRefs[i] = SkRef(imgs[i]); | 77 fImageRefs[i] = SkRef(imgs[i]); |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void SkPictureData::init() { | 82 void SkPictureData::init() { |
83 fPictureRefs = NULL; | 83 fPictureRefs = NULL; |
84 fPictureCount = 0; | 84 fPictureCount = 0; |
85 fTextBlobRefs = NULL; | 85 fTextBlobRefs = NULL; |
86 fTextBlobCount = 0; | 86 fTextBlobCount = 0; |
87 fImageRefs = NULL; | 87 fImageRefs = NULL; |
88 fImageCount = 0; | 88 fImageCount = 0; |
89 fOpData = NULL; | 89 fOpData = NULL; |
90 fFactoryPlayback = NULL; | 90 fFactoryPlayback = NULL; |
91 } | 91 } |
92 | 92 |
93 SkPictureData::~SkPictureData() { | 93 SkPictureData::~SkPictureData() { |
94 SkSafeUnref(fOpData); | 94 SkSafeUnref(fOpData); |
95 | 95 |
96 for (int i = 0; i < fPictureCount; i++) { | 96 for (int i = 0; i < fPictureCount; i++) { |
97 fPictureRefs[i]->unref(); | 97 fPictureRefs[i]->unref(); |
98 } | 98 } |
99 SkDELETE_ARRAY(fPictureRefs); | 99 delete[] fPictureRefs; |
100 | 100 |
101 for (int i = 0; i < fTextBlobCount; i++) { | 101 for (int i = 0; i < fTextBlobCount; i++) { |
102 fTextBlobRefs[i]->unref(); | 102 fTextBlobRefs[i]->unref(); |
103 } | 103 } |
104 SkDELETE_ARRAY(fTextBlobRefs); | 104 delete[] fTextBlobRefs; |
105 | 105 |
106 for (int i = 0; i < fImageCount; i++) { | 106 for (int i = 0; i < fImageCount; i++) { |
107 fImageRefs[i]->unref(); | 107 fImageRefs[i]->unref(); |
108 } | 108 } |
109 SkDELETE_ARRAY(fImageRefs); | 109 delete[] fImageRefs; |
110 | 110 |
111 SkDELETE(fFactoryPlayback); | 111 delete fFactoryPlayback; |
112 } | 112 } |
113 | 113 |
114 bool SkPictureData::containsBitmaps() const { | 114 bool SkPictureData::containsBitmaps() const { |
115 if (fBitmaps.count() > 0 || fImageCount > 0) { | 115 if (fBitmaps.count() > 0 || fImageCount > 0) { |
116 return true; | 116 return true; |
117 } | 117 } |
118 for (int i = 0; i < fPictureCount; ++i) { | 118 for (int i = 0; i < fPictureCount; ++i) { |
119 if (fPictureRefs[i]->willPlayBackBitmaps()) { | 119 if (fPictureRefs[i]->willPlayBackBitmaps()) { |
120 return true; | 120 return true; |
121 } | 121 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 case SK_PICT_READER_TAG: | 357 case SK_PICT_READER_TAG: |
358 SkASSERT(NULL == fOpData); | 358 SkASSERT(NULL == fOpData); |
359 fOpData = SkData::NewFromStream(stream, size); | 359 fOpData = SkData::NewFromStream(stream, size); |
360 if (!fOpData) { | 360 if (!fOpData) { |
361 return false; | 361 return false; |
362 } | 362 } |
363 break; | 363 break; |
364 case SK_PICT_FACTORY_TAG: { | 364 case SK_PICT_FACTORY_TAG: { |
365 SkASSERT(!haveBuffer); | 365 SkASSERT(!haveBuffer); |
366 size = stream->readU32(); | 366 size = stream->readU32(); |
367 fFactoryPlayback = SkNEW_ARGS(SkFactoryPlayback, (size)); | 367 fFactoryPlayback = new SkFactoryPlayback(size); |
368 for (size_t i = 0; i < size; i++) { | 368 for (size_t i = 0; i < size; i++) { |
369 SkString str; | 369 SkString str; |
370 const size_t len = stream->readPackedUInt(); | 370 const size_t len = stream->readPackedUInt(); |
371 str.resize(len); | 371 str.resize(len); |
372 if (stream->read(str.writable_str(), len) != len) { | 372 if (stream->read(str.writable_str(), len) != len) { |
373 return false; | 373 return false; |
374 } | 374 } |
375 fFactoryPlayback->base()[i] = SkFlattenable::NameToFactory(str.c
_str()); | 375 fFactoryPlayback->base()[i] = SkFlattenable::NameToFactory(str.c
_str()); |
376 } | 376 } |
377 } break; | 377 } break; |
378 case SK_PICT_TYPEFACE_TAG: { | 378 case SK_PICT_TYPEFACE_TAG: { |
379 SkASSERT(!haveBuffer); | 379 SkASSERT(!haveBuffer); |
380 const int count = SkToInt(size); | 380 const int count = SkToInt(size); |
381 fTFPlayback.setCount(count); | 381 fTFPlayback.setCount(count); |
382 for (int i = 0; i < count; i++) { | 382 for (int i = 0; i < count; i++) { |
383 SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream)); | 383 SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream)); |
384 if (!tf.get()) { // failed to deserialize | 384 if (!tf.get()) { // failed to deserialize |
385 // fTFPlayback asserts it never has a null, so we plop in | 385 // fTFPlayback asserts it never has a null, so we plop in |
386 // the default here. | 386 // the default here. |
387 tf.reset(SkTypeface::RefDefault()); | 387 tf.reset(SkTypeface::RefDefault()); |
388 } | 388 } |
389 fTFPlayback.set(i, tf); | 389 fTFPlayback.set(i, tf); |
390 } | 390 } |
391 } break; | 391 } break; |
392 case SK_PICT_PICTURE_TAG: { | 392 case SK_PICT_PICTURE_TAG: { |
393 fPictureCount = 0; | 393 fPictureCount = 0; |
394 fPictureRefs = SkNEW_ARRAY(const SkPicture*, size); | 394 fPictureRefs = new const SkPicture* [size]; |
395 for (uint32_t i = 0; i < size; i++) { | 395 for (uint32_t i = 0; i < size; i++) { |
396 fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc, topL
evelTFPlayback); | 396 fPictureRefs[i] = SkPicture::CreateFromStream(stream, proc, topL
evelTFPlayback); |
397 if (!fPictureRefs[i]) { | 397 if (!fPictureRefs[i]) { |
398 return false; | 398 return false; |
399 } | 399 } |
400 fPictureCount++; | 400 fPictureCount++; |
401 } | 401 } |
402 } break; | 402 } break; |
403 case SK_PICT_BUFFER_SIZE_TAG: { | 403 case SK_PICT_BUFFER_SIZE_TAG: { |
404 SkAutoMalloc storage(size); | 404 SkAutoMalloc storage(size); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 template <typename T> | 467 template <typename T> |
468 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, | 468 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, |
469 const T*** array, int* outCount, const T* (*factory)(
SkReadBuffer&)) { | 469 const T*** array, int* outCount, const T* (*factory)(
SkReadBuffer&)) { |
470 if (!buffer.validate((0 == *outCount) && (NULL == *array))) { | 470 if (!buffer.validate((0 == *outCount) && (NULL == *array))) { |
471 return false; | 471 return false; |
472 } | 472 } |
473 if (0 == inCount) { | 473 if (0 == inCount) { |
474 return true; | 474 return true; |
475 } | 475 } |
476 *outCount = inCount; | 476 *outCount = inCount; |
477 *array = SkNEW_ARRAY(const T*, *outCount); | 477 *array = new const T* [*outCount]; |
478 bool success = true; | 478 bool success = true; |
479 int i = 0; | 479 int i = 0; |
480 for (; i < *outCount; i++) { | 480 for (; i < *outCount; i++) { |
481 (*array)[i] = factory(buffer); | 481 (*array)[i] = factory(buffer); |
482 if (NULL == (*array)[i]) { | 482 if (NULL == (*array)[i]) { |
483 success = false; | 483 success = false; |
484 break; | 484 break; |
485 } | 485 } |
486 } | 486 } |
487 if (!success) { | 487 if (!success) { |
488 // Delete all of the blobs that were already created (up to but excludin
g i): | 488 // Delete all of the blobs that were already created (up to but excludin
g i): |
489 for (int j = 0; j < i; j++) { | 489 for (int j = 0; j < i; j++) { |
490 (*array)[j]->unref(); | 490 (*array)[j]->unref(); |
491 } | 491 } |
492 // Delete the array | 492 // Delete the array |
493 SkDELETE_ARRAY(*array); | 493 delete[] * array; |
494 *array = NULL; | 494 *array = NULL; |
495 *outCount = 0; | 495 *outCount = 0; |
496 return false; | 496 return false; |
497 } | 497 } |
498 return true; | 498 return true; |
499 } | 499 } |
500 | 500 |
501 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t
size) { | 501 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, uint32_t tag, uint32_t
size) { |
502 switch (tag) { | 502 switch (tag) { |
503 case SK_PICT_BITMAP_BUFFER_TAG: { | 503 case SK_PICT_BITMAP_BUFFER_TAG: { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 // The tag was invalid. | 558 // The tag was invalid. |
559 return false; | 559 return false; |
560 } | 560 } |
561 return true; // success | 561 return true; // success |
562 } | 562 } |
563 | 563 |
564 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, | 564 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, |
565 const SkPictInfo& info, | 565 const SkPictInfo& info, |
566 SkPicture::InstallPixelRefProc pr
oc, | 566 SkPicture::InstallPixelRefProc pr
oc, |
567 SkTypefacePlayback* topLevelTFPla
yback) { | 567 SkTypefacePlayback* topLevelTFPla
yback) { |
568 SkAutoTDelete<SkPictureData> data(SkNEW_ARGS(SkPictureData, (info))); | 568 SkAutoTDelete<SkPictureData> data(new SkPictureData(info)); |
569 if (!topLevelTFPlayback) { | 569 if (!topLevelTFPlayback) { |
570 topLevelTFPlayback = &data->fTFPlayback; | 570 topLevelTFPlayback = &data->fTFPlayback; |
571 } | 571 } |
572 | 572 |
573 if (!data->parseStream(stream, proc, topLevelTFPlayback)) { | 573 if (!data->parseStream(stream, proc, topLevelTFPlayback)) { |
574 return NULL; | 574 return NULL; |
575 } | 575 } |
576 return data.detach(); | 576 return data.detach(); |
577 } | 577 } |
578 | 578 |
579 SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer, | 579 SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer, |
580 const SkPictInfo& info) { | 580 const SkPictInfo& info) { |
581 SkAutoTDelete<SkPictureData> data(SkNEW_ARGS(SkPictureData, (info))); | 581 SkAutoTDelete<SkPictureData> data(new SkPictureData(info)); |
582 buffer.setVersion(info.fVersion); | 582 buffer.setVersion(info.fVersion); |
583 | 583 |
584 if (!data->parseBuffer(buffer)) { | 584 if (!data->parseBuffer(buffer)) { |
585 return NULL; | 585 return NULL; |
586 } | 586 } |
587 return data.detach(); | 587 return data.detach(); |
588 } | 588 } |
589 | 589 |
590 bool SkPictureData::parseStream(SkStream* stream, | 590 bool SkPictureData::parseStream(SkStream* stream, |
591 SkPicture::InstallPixelRefProc proc, | 591 SkPicture::InstallPixelRefProc proc, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 bool SkPictureData::suitableForLayerOptimization() const { | 642 bool SkPictureData::suitableForLayerOptimization() const { |
643 return fContentInfo.numLayers() > 0; | 643 return fContentInfo.numLayers() > 0; |
644 } | 644 } |
645 #endif | 645 #endif |
646 /////////////////////////////////////////////////////////////////////////////// | 646 /////////////////////////////////////////////////////////////////////////////// |
647 | 647 |
648 | 648 |
OLD | NEW |