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

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: size check 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();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 199 }
204 } 200 }
205 201
206 if ((n = SafeCount(fPaints)) > 0) { 202 if ((n = SafeCount(fPaints)) > 0) {
207 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); 203 write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n);
208 for (i = 0; i < n; i++) { 204 for (i = 0; i < n; i++) {
209 buffer.writePaint((*fPaints)[i]); 205 buffer.writePaint((*fPaints)[i]);
210 } 206 }
211 } 207 }
212 208
213 if ((n = SafeCount(fPathHeap.get())) > 0) { 209 if ((n = SafeCount(fPaths)) > 0) {
214 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); 210 write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n);
215 fPathHeap->flatten(buffer); 211 buffer.writeInt(n);
212 for (int i = 0; i < n; i++) {
213 buffer.writePath((*fPaths)[i]);
214 }
216 } 215 }
217 216
218 if (fTextBlobCount > 0) { 217 if (fTextBlobCount > 0) {
219 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount); 218 write_tag_size(buffer, SK_PICT_TEXTBLOB_BUFFER_TAG, fTextBlobCount);
220 for (i = 0; i < fTextBlobCount; ++i) { 219 for (i = 0; i < fTextBlobCount; ++i) {
221 fTextBlobRefs[i]->flatten(buffer); 220 fTextBlobRefs[i]->flatten(buffer);
222 } 221 }
223 } 222 }
224 } 223 }
225 224
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 return false; 430 return false;
432 } 431 }
433 } 432 }
434 } break; 433 } break;
435 case SK_PICT_PAINT_BUFFER_TAG: { 434 case SK_PICT_PAINT_BUFFER_TAG: {
436 const int count = SkToInt(size); 435 const int count = SkToInt(size);
437 fPaints = SkTRefArray<SkPaint>::Create(size); 436 fPaints = SkTRefArray<SkPaint>::Create(size);
438 for (int i = 0; i < count; ++i) { 437 for (int i = 0; i < count; ++i) {
439 buffer.readPaint(&fPaints->writableAt(i)); 438 buffer.readPaint(&fPaints->writableAt(i));
440 } 439 }
441 } break; 440 } break;
robertphillips 2014/11/12 18:12:55 newline before the if here ?
mtklein 2014/11/12 18:15:18 Done.
442 case SK_PICT_PATH_BUFFER_TAG: 441 case SK_PICT_PATH_BUFFER_TAG: if (size > 0) {
443 if (size > 0) { 442 const int count = buffer.readInt();
444 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); 443 fPaths = SkTRefArray<SkPath>::Create(count);
444 for (int i = 0; i < count; i++) {
445 buffer.readPath(&fPaths->writableAt(i));
445 } 446 }
446 break; 447 } break;
447 case SK_PICT_TEXTBLOB_BUFFER_TAG: { 448 case SK_PICT_TEXTBLOB_BUFFER_TAG: {
448 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) { 449 if (!buffer.validate((0 == fTextBlobCount) && (NULL == fTextBlobRefs ))) {
449 return false; 450 return false;
450 } 451 }
451 fTextBlobCount = size; 452 fTextBlobCount = size;
452 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount); 453 fTextBlobRefs = SkNEW_ARRAY(const SkTextBlob*, fTextBlobCount);
453 bool success = true; 454 bool success = true;
454 int i = 0; 455 int i = 0;
455 for ( ; i < fTextBlobCount; i++) { 456 for ( ; i < fTextBlobCount; i++) {
456 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer); 457 fTextBlobRefs[i] = SkTextBlob::CreateFromBuffer(buffer);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 587 }
587 } 588 }
588 589
589 bool SkPictureData::suitableForLayerOptimization() const { 590 bool SkPictureData::suitableForLayerOptimization() const {
590 return fContentInfo.numLayers() > 0; 591 return fContentInfo.numLayers() > 0;
591 } 592 }
592 #endif 593 #endif
593 /////////////////////////////////////////////////////////////////////////////// 594 ///////////////////////////////////////////////////////////////////////////////
594 595
595 596
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