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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkDrawPictureCallback.h" | 9 #include "SkDrawPictureCallback.h" |
10 #include "SkPictureData.h" | 10 #include "SkPictureData.h" |
11 #include "SkPictureRecord.h" | 11 #include "SkPictureRecord.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkTextBlob.h" |
13 #include "SkTypeface.h" | 14 #include "SkTypeface.h" |
14 #include "SkTSort.h" | 15 #include "SkTSort.h" |
15 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
16 | 17 |
17 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
18 #include "GrContext.h" | 19 #include "GrContext.h" |
19 #endif | 20 #endif |
20 | 21 |
21 template <typename T> int SafeCount(const T* obj) { | 22 template <typename T> int SafeCount(const T* obj) { |
22 return obj ? obj->count() : 0; | 23 return obj ? obj->count() : 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 70 |
70 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); | 71 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); |
71 fPictureCount = pictures.count(); | 72 fPictureCount = pictures.count(); |
72 if (fPictureCount > 0) { | 73 if (fPictureCount > 0) { |
73 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); | 74 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); |
74 for (int i = 0; i < fPictureCount; i++) { | 75 for (int i = 0; i < fPictureCount; i++) { |
75 fPictureRefs[i] = pictures[i]; | 76 fPictureRefs[i] = pictures[i]; |
76 fPictureRefs[i]->ref(); | 77 fPictureRefs[i]->ref(); |
77 } | 78 } |
78 } | 79 } |
| 80 |
| 81 // templetize to consolidate with similar picture logic? |
| 82 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); |
| 83 fTextBlobCount = blobs.count(); |
| 84 if (fTextBlobCount > 0) { |
| 85 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); |
| 86 for (int i = 0; i < fTextBlobCount; ++i) { |
| 87 fTextBlobRefs[i] = blobs[i]; |
| 88 fTextBlobRefs[i]->ref(); |
| 89 } |
| 90 } |
79 } | 91 } |
80 | 92 |
81 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE | 93 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE |
82 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI
nfo) | 94 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI
nfo) |
83 : fInfo(src.fInfo) { | 95 : fInfo(src.fInfo) { |
84 this->init(); | 96 this->init(); |
85 | 97 |
86 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); | 98 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); |
87 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); | 99 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); |
88 | 100 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 144 } |
133 } | 145 } |
134 } | 146 } |
135 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE | 147 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE |
136 | 148 |
137 void SkPictureData::init() { | 149 void SkPictureData::init() { |
138 fBitmaps = NULL; | 150 fBitmaps = NULL; |
139 fPaints = NULL; | 151 fPaints = NULL; |
140 fPictureRefs = NULL; | 152 fPictureRefs = NULL; |
141 fPictureCount = 0; | 153 fPictureCount = 0; |
| 154 fTextBlobRefs = NULL; |
| 155 fTextBlobCount = 0; |
142 fOpData = NULL; | 156 fOpData = NULL; |
143 fFactoryPlayback = NULL; | 157 fFactoryPlayback = NULL; |
144 fBoundingHierarchy = NULL; | 158 fBoundingHierarchy = NULL; |
145 fStateTree = NULL; | 159 fStateTree = NULL; |
146 } | 160 } |
147 | 161 |
148 SkPictureData::~SkPictureData() { | 162 SkPictureData::~SkPictureData() { |
149 SkSafeUnref(fOpData); | 163 SkSafeUnref(fOpData); |
150 | 164 |
151 SkSafeUnref(fBitmaps); | 165 SkSafeUnref(fBitmaps); |
152 SkSafeUnref(fPaints); | 166 SkSafeUnref(fPaints); |
153 SkSafeUnref(fBoundingHierarchy); | 167 SkSafeUnref(fBoundingHierarchy); |
154 SkSafeUnref(fStateTree); | 168 SkSafeUnref(fStateTree); |
155 | 169 |
156 for (int i = 0; i < fPictureCount; i++) { | 170 for (int i = 0; i < fPictureCount; i++) { |
157 fPictureRefs[i]->unref(); | 171 fPictureRefs[i]->unref(); |
158 } | 172 } |
159 SkDELETE_ARRAY(fPictureRefs); | 173 SkDELETE_ARRAY(fPictureRefs); |
160 | 174 |
| 175 for (int i = 0; i < fTextBlobCount; i++) { |
| 176 fTextBlobRefs[i]->unref(); |
| 177 } |
| 178 SkDELETE_ARRAY(fTextBlobRefs); |
| 179 |
161 SkDELETE(fFactoryPlayback); | 180 SkDELETE(fFactoryPlayback); |
162 } | 181 } |
163 | 182 |
164 bool SkPictureData::containsBitmaps() const { | 183 bool SkPictureData::containsBitmaps() const { |
165 if (fBitmaps && fBitmaps->count() > 0) { | 184 if (fBitmaps && fBitmaps->count() > 0) { |
166 return true; | 185 return true; |
167 } | 186 } |
168 for (int i = 0; i < fPictureCount; ++i) { | 187 for (int i = 0; i < fPictureCount; ++i) { |
169 if (fPictureRefs[i]->willPlayBackBitmaps()) { | 188 if (fPictureRefs[i]->willPlayBackBitmaps()) { |
170 return true; | 189 return true; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); | 280 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); |
262 for (i = 0; i < n; i++) { | 281 for (i = 0; i < n; i++) { |
263 buffer.writePaint((*fPaints)[i]); | 282 buffer.writePaint((*fPaints)[i]); |
264 } | 283 } |
265 } | 284 } |
266 | 285 |
267 if ((n = SafeCount(fPathHeap.get())) > 0) { | 286 if ((n = SafeCount(fPathHeap.get())) > 0) { |
268 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); | 287 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); |
269 fPathHeap->flatten(buffer); | 288 fPathHeap->flatten(buffer); |
270 } | 289 } |
| 290 |
| 291 if (fTextBlobCount > 0) { |
| 292 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount); |
| 293 for (i = 0; i < fTextBlobCount; ++i) { |
| 294 fTextBlobRefs[i]->flatten(buffer); |
| 295 } |
| 296 } |
271 } | 297 } |
272 | 298 |
273 void SkPictureData::serialize(SkWStream* stream, | 299 void SkPictureData::serialize(SkWStream* stream, |
274 SkPicture::EncodeBitmap encoder) const { | 300 SkPicture::EncodeBitmap encoder) const { |
275 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); | 301 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); |
276 stream->write(fOpData->bytes(), fOpData->size()); | 302 stream->write(fOpData->bytes(), fOpData->size()); |
277 | 303 |
278 if (fPictureCount > 0) { | 304 if (fPictureCount > 0) { |
279 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); | 305 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); |
280 for (int i = 0; i < fPictureCount; i++) { | 306 for (int i = 0; i < fPictureCount; i++) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 fPaints = SkTRefArray<SkPaint>::Create(size); | 504 fPaints = SkTRefArray<SkPaint>::Create(size); |
479 for (int i = 0; i < count; ++i) { | 505 for (int i = 0; i < count; ++i) { |
480 buffer.readPaint(&fPaints->writableAt(i)); | 506 buffer.readPaint(&fPaints->writableAt(i)); |
481 } | 507 } |
482 } break; | 508 } break; |
483 case SK_PICT_PATH_BUFFER_TAG: | 509 case SK_PICT_PATH_BUFFER_TAG: |
484 if (size > 0) { | 510 if (size > 0) { |
485 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); | 511 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); |
486 } | 512 } |
487 break; | 513 break; |
| 514 case SK_PICT_TEXTBLOB_BUFFER_TAG: { |
| 515 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs
))) { |
| 516 return false; |
| 517 } |
| 518 fTextBlobCount = size; |
| 519 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); |
| 520 bool success = true; |
| 521 int i = 0; |
| 522 for ( ; i < fTextBlobCount; i++) { |
| 523 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer); |
| 524 if (NULL == fTextBlobRefs[i]) { |
| 525 success = false; |
| 526 break; |
| 527 } |
| 528 } |
| 529 if (!success) { |
| 530 // Delete all of the blobs that were already created (up to but
excluding i): |
| 531 for (int j = 0; j < i; j++) { |
| 532 fTextBlobRefs[j]->unref(); |
| 533 } |
| 534 // Delete the array |
| 535 SkDELETE_ARRAY(fTextBlobRefs); |
| 536 fTextBlobCount = 0; |
| 537 return false; |
| 538 } |
| 539 } break; |
488 case SK_PICT_READER_TAG: { | 540 case SK_PICT_READER_TAG: { |
489 SkAutoMalloc storage(size); | 541 SkAutoMalloc storage(size); |
490 if (!buffer.readByteArray(storage.get(), size) || | 542 if (!buffer.readByteArray(storage.get(), size) || |
491 !buffer.validate(NULL == fOpData)) { | 543 !buffer.validate(NULL == fOpData)) { |
492 return false; | 544 return false; |
493 } | 545 } |
494 SkASSERT(NULL == fOpData); | 546 SkASSERT(NULL == fOpData); |
495 fOpData = SkData::NewFromMalloc(storage.detach(), size); | 547 fOpData = SkData::NewFromMalloc(storage.detach(), size); |
496 } break; | 548 } break; |
497 case SK_PICT_PICTURE_TAG: { | 549 case SK_PICT_PICTURE_TAG: { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 } | 662 } |
611 } | 663 } |
612 | 664 |
613 bool SkPictureData::suitableForLayerOptimization() const { | 665 bool SkPictureData::suitableForLayerOptimization() const { |
614 return fContentInfo.numLayers() > 0; | 666 return fContentInfo.numLayers() > 0; |
615 } | 667 } |
616 #endif | 668 #endif |
617 /////////////////////////////////////////////////////////////////////////////// | 669 /////////////////////////////////////////////////////////////////////////////// |
618 | 670 |
619 | 671 |
OLD | NEW |