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

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

Issue 715413002: More cleanup: streamline paths and bitmaps. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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/SkPictureRecord.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 if (fPathHeap.get()) { 33 for (int i = 0; i < fPaths->count(); i++) {
34 for (int i = 0; i < fPathHeap->count(); i++) { 34 (*fPaths)[i].updateBoundsCache();
35 (*fPathHeap.get())[i].updateBoundsCache();
36 }
37 } 35 }
38 } 36 }
39 37
40 SkPictureData::SkPictureData(const SkPictureRecord& record, 38 SkPictureData::SkPictureData(const SkPictureRecord& record,
41 const SkPictInfo& info, 39 const SkPictInfo& info,
42 bool deepCopyOps) 40 bool deepCopyOps)
43 : fInfo(info) { 41 : fInfo(info) {
44 42
45 this->init(); 43 this->init();
46 44
47 fOpData = record.opData(deepCopyOps); 45 fOpData = record.opData(deepCopyOps);
48 46
49 fContentInfo.set(record.fContentInfo); 47 fContentInfo.set(record.fContentInfo);
50 48
51 fBitmaps = record.fBitmapHeap->extractBitmaps(); 49 fBitmaps = SkTRefArray<SkBitmap>::Create(record.fBitmaps.begin(), record.fBi tmaps.count());
52 fPaints = SkTRefArray<SkPaint>::Create(record.fPaints.begin(), record.fPaint s.count()); 50 fPaints = SkTRefArray<SkPaint> ::Create(record.fPaints .begin(), record.fPa ints .count());
53 51 fPaths = SkTRefArray<SkPath> ::Create(record.fPaths .begin(), record.fPa ths .count());
54 fBitmapHeap.reset(SkSafeRef(record.fBitmapHeap));
55 fPathHeap.reset(SkSafeRef(record.pathHeap()));
56 52
57 this->initForPlayback(); 53 this->initForPlayback();
58 54
59 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); 55 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs();
60 fPictureCount = pictures.count(); 56 fPictureCount = pictures.count();
61 if (fPictureCount > 0) { 57 if (fPictureCount > 0) {
62 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); 58 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount);
63 for (int i = 0; i < fPictureCount; i++) { 59 for (int i = 0; i < fPictureCount; i++) {
64 fPictureRefs[i] = pictures[i]; 60 fPictureRefs[i] = pictures[i];
65 fPictureRefs[i]->ref(); 61 fPictureRefs[i]->ref();
66 } 62 }
67 } 63 }
68 64
69 // templatize to consolidate with similar picture logic? 65 // templatize to consolidate with similar picture logic?
70 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); 66 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs();
71 fTextBlobCount = blobs.count(); 67 fTextBlobCount = blobs.count();
72 if (fTextBlobCount > 0) { 68 if (fTextBlobCount > 0) {
73 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); 69 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
74 for (int i = 0; i < fTextBlobCount; ++i) { 70 for (int i = 0; i < fTextBlobCount; ++i) {
75 fTextBlobRefs[i] = SkRef(blobs[i]); 71 fTextBlobRefs[i] = SkRef(blobs[i]);
76 } 72 }
77 } 73 }
78 } 74 }
79 75
80 void SkPictureData::init() { 76 void SkPictureData::init() {
81 fBitmaps = NULL; 77 fBitmaps = NULL;
82 fPaints = NULL; 78 fPaints = NULL;
79 fPaths = NULL;
83 fPictureRefs = NULL; 80 fPictureRefs = NULL;
84 fPictureCount = 0; 81 fPictureCount = 0;
85 fTextBlobRefs = NULL; 82 fTextBlobRefs = NULL;
86 fTextBlobCount = 0; 83 fTextBlobCount = 0;
87 fOpData = NULL; 84 fOpData = NULL;
88 fFactoryPlayback = NULL; 85 fFactoryPlayback = NULL;
89 } 86 }
90 87
91 SkPictureData::~SkPictureData() { 88 SkPictureData::~SkPictureData() {
92 SkSafeUnref(fOpData); 89 SkSafeUnref(fOpData);
93 90
94 SkSafeUnref(fBitmaps); 91 SkSafeUnref(fBitmaps);
95 SkSafeUnref(fPaints); 92 SkSafeUnref(fPaints);
93 SkSafeUnref(fPaths);
96 94
97 for (int i = 0; i < fPictureCount; i++) { 95 for (int i = 0; i < fPictureCount; i++) {
98 fPictureRefs[i]->unref(); 96 fPictureRefs[i]->unref();
99 } 97 }
100 SkDELETE_ARRAY(fPictureRefs); 98 SkDELETE_ARRAY(fPictureRefs);
101 99
102 for (int i = 0; i < fTextBlobCount; i++) { 100 for (int i = 0; i < fTextBlobCount; i++) {
103 fTextBlobRefs[i]->unref(); 101 fTextBlobRefs[i]->unref();
104 } 102 }
105 SkDELETE_ARRAY(fTextBlobRefs); 103 SkDELETE_ARRAY(fTextBlobRefs);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 201 }
204 } 202 }
205 203
206 if ((n = SafeCount(fPaints)) > 0) { 204 if ((n = SafeCount(fPaints)) > 0) {
207 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 205 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
208 for (i = 0; i < n; i++) { 206 for (i = 0; i < n; i++) {
209 buffer.writePaint((*fPaints)[i]); 207 buffer.writePaint((*fPaints)[i]);
210 } 208 }
211 } 209 }
212 210
213 if ((n = SafeCount(fPathHeap.get())) > 0) { 211 if ((n = SafeCount(fPaths)) > 0) {
214 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); 212 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
215 fPathHeap->flatten(buffer); 213 buffer.writeInt(n);
214 for (int i = 0; i < n; i++) {
215 buffer.writePath((*fPaths)[i]);
216 }
216 } 217 }
217 218
218 if (fTextBlobCount > 0) { 219 if (fTextBlobCount > 0) {
219 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount); 220 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount);
220 for (i = 0; i < fTextBlobCount; ++i) { 221 for (i = 0; i < fTextBlobCount; ++i) {
221 fTextBlobRefs[i]->flatten(buffer); 222 fTextBlobRefs[i]->flatten(buffer);
222 } 223 }
223 } 224 }
224 } 225 }
225 226
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } break; 435 } break;
435 case SK_PICT_PAINT_BUFFER_TAG: { 436 case SK_PICT_PAINT_BUFFER_TAG: {
436 const int count = SkToInt(size); 437 const int count = SkToInt(size);
437 fPaints = SkTRefArray<SkPaint>::Create(size); 438 fPaints = SkTRefArray<SkPaint>::Create(size);
438 for (int i = 0; i < count; ++i) { 439 for (int i = 0; i < count; ++i) {
439 buffer.readPaint(&fPaints->writableAt(i)); 440 buffer.readPaint(&fPaints->writableAt(i));
440 } 441 }
441 } break; 442 } break;
442 case SK_PICT_PATH_BUFFER_TAG: 443 case SK_PICT_PATH_BUFFER_TAG:
443 if (size > 0) { 444 if (size > 0) {
444 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); 445 const int count = buffer.readInt();
445 } 446 fPaths = SkTRefArray<SkPath>::Create(count);
446 break; 447 for (int i = 0; i < count; i++) {
448 buffer.readPath(&fPaths->writableAt(i));
449 }
450 } break;
447 case SK_PICT_TEXTBLOB_BUFFER_TAG: { 451 case SK_PICT_TEXTBLOB_BUFFER_TAG: {
448 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) { 452 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) {
449 return false; 453 return false;
450 } 454 }
451 fTextBlobCount = size; 455 fTextBlobCount = size;
452 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); 456 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
453 bool success = true; 457 bool success = true;
454 int i = 0; 458 int i = 0;
455 for ( ; i < fTextBlobCount; i++) { 459 for ( ; i < fTextBlobCount; i++) {
456 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer); 460 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 590 }
587 } 591 }
588 592
589 bool SkPictureData::suitableForLayerOptimization() const { 593 bool SkPictureData::suitableForLayerOptimization() const {
590 return fContentInfo.numLayers() > 0; 594 return fContentInfo.numLayers() > 0;
591 } 595 }
592 #endif 596 #endif
593 /////////////////////////////////////////////////////////////////////////////// 597 ///////////////////////////////////////////////////////////////////////////////
594 598
595 599
OLDNEW
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698