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

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

Issue 719113004: Followup: remove unnecessary SkTRefArray (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: count Created 6 years, 1 month 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"
(...skipping 12 matching lines...) Expand all
23 return obj ? obj->count() : 0; 23 return obj ? obj->count() : 0;
24 } 24 }
25 25
26 SkPictureData::SkPictureData(const SkPictInfo& info) 26 SkPictureData::SkPictureData(const SkPictInfo& info)
27 : fInfo(info) { 27 : fInfo(info) {
28 this->init(); 28 this->init();
29 } 29 }
30 30
31 void SkPictureData::initForPlayback() const { 31 void SkPictureData::initForPlayback() const {
32 // ensure that the paths bounds are pre-computed 32 // ensure that the paths bounds are pre-computed
33 for (int i = 0; i < fPaths->count(); i++) { 33 for (int i = 0; i < fPaths.count(); i++) {
34 (*fPaths)[i].updateBoundsCache(); 34 fPaths[i].updateBoundsCache();
35 } 35 }
36 } 36 }
37 37
38 SkPictureData::SkPictureData(const SkPictureRecord& record, 38 SkPictureData::SkPictureData(const SkPictureRecord& record,
39 const SkPictInfo& info, 39 const SkPictInfo& info,
40 bool deepCopyOps) 40 bool deepCopyOps)
41 : fInfo(info) { 41 : fInfo(info) {
42 42
43 this->init(); 43 this->init();
44 44
45 fOpData = record.opData(deepCopyOps); 45 fOpData = record.opData(deepCopyOps);
46 46
47 fContentInfo.set(record.fContentInfo); 47 fContentInfo.set(record.fContentInfo);
48 48
49 fBitmaps = SkTRefArray<SkBitmap>::Create(record.fBitmaps.begin(), record.fBi tmaps.count()); 49 fBitmaps = record.fBitmaps;
50 fPaints = SkTRefArray<SkPaint> ::Create(record.fPaints .begin(), record.fPa ints .count()); 50 fPaints = record.fPaints;
51 fPaths = SkTRefArray<SkPath> ::Create(record.fPaths .begin(), record.fPa ths .count()); 51 fPaths = record.fPaths;
52 52
53 this->initForPlayback(); 53 this->initForPlayback();
54 54
55 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); 55 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs();
56 fPictureCount = pictures.count(); 56 fPictureCount = pictures.count();
57 if (fPictureCount > 0) { 57 if (fPictureCount > 0) {
58 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); 58 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount);
59 for (int i = 0; i < fPictureCount; i++) { 59 for (int i = 0; i < fPictureCount; i++) {
60 fPictureRefs[i] = pictures[i]; 60 fPictureRefs[i] = pictures[i];
61 fPictureRefs[i]->ref(); 61 fPictureRefs[i]->ref();
62 } 62 }
63 } 63 }
64 64
65 // templatize to consolidate with similar picture logic? 65 // templatize to consolidate with similar picture logic?
66 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); 66 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs();
67 fTextBlobCount = blobs.count(); 67 fTextBlobCount = blobs.count();
68 if (fTextBlobCount > 0) { 68 if (fTextBlobCount > 0) {
69 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); 69 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
70 for (int i = 0; i < fTextBlobCount; ++i) { 70 for (int i = 0; i < fTextBlobCount; ++i) {
71 fTextBlobRefs[i] = SkRef(blobs[i]); 71 fTextBlobRefs[i] = SkRef(blobs[i]);
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 void SkPictureData::init() { 76 void SkPictureData::init() {
77 fBitmaps = NULL;
78 fPaints = NULL;
79 fPaths = NULL;
80 fPictureRefs = NULL; 77 fPictureRefs = NULL;
81 fPictureCount = 0; 78 fPictureCount = 0;
82 fTextBlobRefs = NULL; 79 fTextBlobRefs = NULL;
83 fTextBlobCount = 0; 80 fTextBlobCount = 0;
84 fOpData = NULL; 81 fOpData = NULL;
85 fFactoryPlayback = NULL; 82 fFactoryPlayback = NULL;
86 } 83 }
87 84
88 SkPictureData::~SkPictureData() { 85 SkPictureData::~SkPictureData() {
89 SkSafeUnref(fOpData); 86 SkSafeUnref(fOpData);
90 87
91 SkSafeUnref(fBitmaps);
92 SkSafeUnref(fPaints);
93 SkSafeUnref(fPaths);
94
95 for (int i = 0; i < fPictureCount; i++) { 88 for (int i = 0; i < fPictureCount; i++) {
96 fPictureRefs[i]->unref(); 89 fPictureRefs[i]->unref();
97 } 90 }
98 SkDELETE_ARRAY(fPictureRefs); 91 SkDELETE_ARRAY(fPictureRefs);
99 92
100 for (int i = 0; i < fTextBlobCount; i++) { 93 for (int i = 0; i < fTextBlobCount; i++) {
101 fTextBlobRefs[i]->unref(); 94 fTextBlobRefs[i]->unref();
102 } 95 }
103 SkDELETE_ARRAY(fTextBlobRefs); 96 SkDELETE_ARRAY(fTextBlobRefs);
104 97
105 SkDELETE(fFactoryPlayback); 98 SkDELETE(fFactoryPlayback);
106 } 99 }
107 100
108 bool SkPictureData::containsBitmaps() const { 101 bool SkPictureData::containsBitmaps() const {
109 if (fBitmaps && fBitmaps->count() > 0) { 102 if (fBitmaps.count() > 0) {
110 return true; 103 return true;
111 } 104 }
112 for (int i = 0; i < fPictureCount; ++i) { 105 for (int i = 0; i < fPictureCount; ++i) {
113 if (fPictureRefs[i]->willPlayBackBitmaps()) { 106 if (fPictureRefs[i]->willPlayBackBitmaps()) {
114 return true; 107 return true;
115 } 108 }
116 } 109 }
117 return false; 110 return false;
118 } 111 }
119 112
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 rec.copyToArray((SkRefCnt**)array); 180 rec.copyToArray((SkRefCnt**)array);
188 181
189 for (int i = 0; i < count; i++) { 182 for (int i = 0; i < count; i++) {
190 array[i]->serialize(stream); 183 array[i]->serialize(stream);
191 } 184 }
192 } 185 }
193 186
194 void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { 187 void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const {
195 int i, n; 188 int i, n;
196 189
197 if ((n = SafeCount(fBitmaps)) > 0) { 190 if ((n = fBitmaps.count()) > 0) {
198 write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); 191 write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n);
199 for (i = 0; i < n; i++) { 192 for (i = 0; i < n; i++) {
200 buffer.writeBitmap((*fBitmaps)[i]); 193 buffer.writeBitmap(fBitmaps[i]);
201 } 194 }
202 } 195 }
203 196
204 if ((n = SafeCount(fPaints)) > 0) { 197 if ((n = fPaints.count()) > 0) {
205 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 198 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
206 for (i = 0; i < n; i++) { 199 for (i = 0; i < n; i++) {
207 buffer.writePaint((*fPaints)[i]); 200 buffer.writePaint(fPaints[i]);
208 } 201 }
209 } 202 }
210 203
211 if ((n = SafeCount(fPaths)) > 0) { 204 if ((n = fPaths.count()) > 0) {
212 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); 205 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
213 buffer.writeInt(n); 206 buffer.writeInt(n);
214 for (int i = 0; i < n; i++) { 207 for (int i = 0; i < n; i++) {
215 buffer.writePath((*fPaths)[i]); 208 buffer.writePath(fPaths[i]);
216 } 209 }
217 } 210 }
218 211
219 if (fTextBlobCount > 0) { 212 if (fTextBlobCount > 0) {
220 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount); 213 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount);
221 for (i = 0; i < fTextBlobCount; ++i) { 214 for (i = 0; i < fTextBlobCount; ++i) {
222 fTextBlobRefs[i]->flatten(buffer); 215 fTextBlobRefs[i]->flatten(buffer);
223 } 216 }
224 } 217 }
225 } 218 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } break; 409 } break;
417 } 410 }
418 return true; // success 411 return true; // success
419 } 412 }
420 413
421 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, 414 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer,
422 uint32_t tag, uint32_t size) { 415 uint32_t tag, uint32_t size) {
423 switch (tag) { 416 switch (tag) {
424 case SK_PICT_BITMAP_BUFFER_TAG: { 417 case SK_PICT_BITMAP_BUFFER_TAG: {
425 const int count = SkToInt(size); 418 const int count = SkToInt(size);
426 fBitmaps = SkTRefArray<SkBitmap>::Create(size); 419 fBitmaps.reset(count);
427 for (int i = 0; i < count; ++i) { 420 for (int i = 0; i < count; ++i) {
428 SkBitmap* bm = &fBitmaps->writableAt(i); 421 SkBitmap* bm = &fBitmaps[i];
429 if (buffer.readBitmap(bm)) { 422 if (buffer.readBitmap(bm)) {
430 bm->setImmutable(); 423 bm->setImmutable();
431 } else { 424 } else {
432 return false; 425 return false;
433 } 426 }
434 } 427 }
435 } break; 428 } break;
436 case SK_PICT_PAINT_BUFFER_TAG: { 429 case SK_PICT_PAINT_BUFFER_TAG: {
437 const int count = SkToInt(size); 430 const int count = SkToInt(size);
438 fPaints = SkTRefArray<SkPaint>::Create(size); 431 fPaints.reset(count);
439 for (int i = 0; i < count; ++i) { 432 for (int i = 0; i < count; ++i) {
440 buffer.readPaint(&fPaints->writableAt(i)); 433 buffer.readPaint(&fPaints[i]);
441 } 434 }
442 } break; 435 } break;
443 case SK_PICT_PATH_BUFFER_TAG: 436 case SK_PICT_PATH_BUFFER_TAG:
444 if (size > 0) { 437 if (size > 0) {
445 const int count = buffer.readInt(); 438 const int count = buffer.readInt();
446 fPaths = SkTRefArray<SkPath>::Create(count); 439 fPaths.reset(count);
447 for (int i = 0; i < count; i++) { 440 for (int i = 0; i < count; i++) {
448 buffer.readPath(&fPaths->writableAt(i)); 441 buffer.readPath(&fPaths[i]);
449 } 442 }
450 } break; 443 } break;
451 case SK_PICT_TEXTBLOB_BUFFER_TAG: { 444 case SK_PICT_TEXTBLOB_BUFFER_TAG: {
452 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) { 445 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) {
453 return false; 446 return false;
454 } 447 }
455 fTextBlobCount = size; 448 fTextBlobCount = size;
456 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); 449 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
457 bool success = true; 450 bool success = true;
458 int i = 0; 451 int i = 0;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 583 }
591 } 584 }
592 585
593 bool SkPictureData::suitableForLayerOptimization() const { 586 bool SkPictureData::suitableForLayerOptimization() const {
594 return fContentInfo.numLayers() > 0; 587 return fContentInfo.numLayers() > 0;
595 } 588 }
596 #endif 589 #endif
597 /////////////////////////////////////////////////////////////////////////////// 590 ///////////////////////////////////////////////////////////////////////////////
598 591
599 592
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