Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: src/core/SkPictureData.cpp

Issue 499413002: SkTextBlob plumbing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: review comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // templatize 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] = SkRef(blobs[i]);
88 }
89 }
79 } 90 }
80 91
81 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE 92 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
82 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI nfo) 93 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI nfo)
83 : fInfo(src.fInfo) { 94 : fInfo(src.fInfo) {
84 this->init(); 95 this->init();
85 96
86 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); 97 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get()));
87 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); 98 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
88 99
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 143 }
133 } 144 }
134 } 145 }
135 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE 146 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE
136 147
137 void SkPictureData::init() { 148 void SkPictureData::init() {
138 fBitmaps = NULL; 149 fBitmaps = NULL;
139 fPaints = NULL; 150 fPaints = NULL;
140 fPictureRefs = NULL; 151 fPictureRefs = NULL;
141 fPictureCount = 0; 152 fPictureCount = 0;
153 fTextBlobRefs = NULL;
154 fTextBlobCount = 0;
142 fOpData = NULL; 155 fOpData = NULL;
143 fFactoryPlayback = NULL; 156 fFactoryPlayback = NULL;
144 fBoundingHierarchy = NULL; 157 fBoundingHierarchy = NULL;
145 fStateTree = NULL; 158 fStateTree = NULL;
146 } 159 }
147 160
148 SkPictureData::~SkPictureData() { 161 SkPictureData::~SkPictureData() {
149 SkSafeUnref(fOpData); 162 SkSafeUnref(fOpData);
150 163
151 SkSafeUnref(fBitmaps); 164 SkSafeUnref(fBitmaps);
152 SkSafeUnref(fPaints); 165 SkSafeUnref(fPaints);
153 SkSafeUnref(fBoundingHierarchy); 166 SkSafeUnref(fBoundingHierarchy);
154 SkSafeUnref(fStateTree); 167 SkSafeUnref(fStateTree);
155 168
156 for (int i = 0; i < fPictureCount; i++) { 169 for (int i = 0; i < fPictureCount; i++) {
157 fPictureRefs[i]->unref(); 170 fPictureRefs[i]->unref();
158 } 171 }
159 SkDELETE_ARRAY(fPictureRefs); 172 SkDELETE_ARRAY(fPictureRefs);
160 173
174 for (int i = 0; i < fTextBlobCount; i++) {
175 fTextBlobRefs[i]->unref();
176 }
177 SkDELETE_ARRAY(fTextBlobRefs);
178
161 SkDELETE(fFactoryPlayback); 179 SkDELETE(fFactoryPlayback);
162 } 180 }
163 181
164 bool SkPictureData::containsBitmaps() const { 182 bool SkPictureData::containsBitmaps() const {
165 if (fBitmaps && fBitmaps->count() > 0) { 183 if (fBitmaps && fBitmaps->count() > 0) {
166 return true; 184 return true;
167 } 185 }
168 for (int i = 0; i < fPictureCount; ++i) { 186 for (int i = 0; i < fPictureCount; ++i) {
169 if (fPictureRefs[i]->willPlayBackBitmaps()) { 187 if (fPictureRefs[i]->willPlayBackBitmaps()) {
170 return true; 188 return true;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 279 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
262 for (i = 0; i < n; i++) { 280 for (i = 0; i < n; i++) {
263 buffer.writePaint((*fPaints)[i]); 281 buffer.writePaint((*fPaints)[i]);
264 } 282 }
265 } 283 }
266 284
267 if ((n = SafeCount(fPathHeap.get())) > 0) { 285 if ((n = SafeCount(fPathHeap.get())) > 0) {
268 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); 286 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
269 fPathHeap->flatten(buffer); 287 fPathHeap->flatten(buffer);
270 } 288 }
289
290 if (fTextBlobCount > 0) {
291 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount);
292 for (i = 0; i < fTextBlobCount; ++i) {
293 fTextBlobRefs[i]->flatten(buffer);
294 }
295 }
271 } 296 }
272 297
273 void SkPictureData::serialize(SkWStream* stream, 298 void SkPictureData::serialize(SkWStream* stream,
274 SkPicture::EncodeBitmap encoder) const { 299 SkPicture::EncodeBitmap encoder) const {
275 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size()); 300 write_tag_size(stream, SK_PICT_READER_TAG, fOpData->size());
276 stream->write(fOpData->bytes(), fOpData->size()); 301 stream->write(fOpData->bytes(), fOpData->size());
277 302
278 if (fPictureCount > 0) { 303 if (fPictureCount > 0) {
279 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount); 304 write_tag_size(stream, SK_PICT_PICTURE_TAG, fPictureCount);
280 for (int i = 0; i < fPictureCount; i++) { 305 for (int i = 0; i < fPictureCount; i++) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 fPaints = SkTRefArray<SkPaint>::Create(size); 503 fPaints = SkTRefArray<SkPaint>::Create(size);
479 for (int i = 0; i < count; ++i) { 504 for (int i = 0; i < count; ++i) {
480 buffer.readPaint(&fPaints->writableAt(i)); 505 buffer.readPaint(&fPaints->writableAt(i));
481 } 506 }
482 } break; 507 } break;
483 case SK_PICT_PATH_BUFFER_TAG: 508 case SK_PICT_PATH_BUFFER_TAG:
484 if (size > 0) { 509 if (size > 0) {
485 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); 510 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer)));
486 } 511 }
487 break; 512 break;
513 case SK_PICT_TEXTBLOB_BUFFER_TAG: {
514 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) {
515 return false;
516 }
517 fTextBlobCount = size;
518 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
519 bool success = true;
520 int i = 0;
521 for ( ; i < fTextBlobCount; i++) {
522 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer);
523 if (NULL == fTextBlobRefs[i]) {
524 success = false;
525 break;
526 }
527 }
528 if (!success) {
529 // Delete all of the blobs that were already created (up to but excluding i):
530 for (int j = 0; j < i; j++) {
531 fTextBlobRefs[j]->unref();
532 }
533 // Delete the array
534 SkDELETE_ARRAY(fTextBlobRefs);
535 fTextBlobRefs = NULL;
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
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
OLDNEW
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698