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

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

Issue 1923393002: Revert of Enable flattening of SkRecordedDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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 "SkImageGenerator.h" 8 #include "SkImageGenerator.h"
9 #include "SkPictureData.h" 9 #include "SkPictureData.h"
10 #include "SkPictureRecord.h" 10 #include "SkPictureRecord.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); 59 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs();
60 fPictureCount = pictures.count(); 60 fPictureCount = pictures.count();
61 if (fPictureCount > 0) { 61 if (fPictureCount > 0) {
62 fPictureRefs = new const SkPicture* [fPictureCount]; 62 fPictureRefs = new const SkPicture* [fPictureCount];
63 for (int i = 0; i < fPictureCount; i++) { 63 for (int i = 0; i < fPictureCount; i++) {
64 fPictureRefs[i] = pictures[i]; 64 fPictureRefs[i] = pictures[i];
65 fPictureRefs[i]->ref(); 65 fPictureRefs[i]->ref();
66 } 66 }
67 } 67 }
68 68
69 const SkTDArray<SkDrawable* >& drawables = record.getDrawableRefs();
70 fDrawableCount = drawables.count();
71 if (fDrawableCount > 0) {
72 fDrawableRefs = new SkDrawable* [fDrawableCount];
73 for (int i = 0; i < fDrawableCount; i++) {
74 fDrawableRefs[i] = drawables[i];
75 fDrawableRefs[i]->ref();
76 }
77 }
78
79 // templatize to consolidate with similar picture logic? 69 // templatize to consolidate with similar picture logic?
80 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs(); 70 const SkTDArray<const SkTextBlob*>& blobs = record.getTextBlobRefs();
81 fTextBlobCount = blobs.count(); 71 fTextBlobCount = blobs.count();
82 if (fTextBlobCount > 0) { 72 if (fTextBlobCount > 0) {
83 fTextBlobRefs = new const SkTextBlob* [fTextBlobCount]; 73 fTextBlobRefs = new const SkTextBlob* [fTextBlobCount];
84 for (int i = 0; i < fTextBlobCount; ++i) { 74 for (int i = 0; i < fTextBlobCount; ++i) {
85 fTextBlobRefs[i] = SkRef(blobs[i]); 75 fTextBlobRefs[i] = SkRef(blobs[i]);
86 } 76 }
87 } 77 }
88 78
89 const SkTDArray<const SkImage*>& imgs = record.getImageRefs(); 79 const SkTDArray<const SkImage*>& imgs = record.getImageRefs();
90 fImageCount = imgs.count(); 80 fImageCount = imgs.count();
91 if (fImageCount > 0) { 81 if (fImageCount > 0) {
92 fImageRefs = new const SkImage* [fImageCount]; 82 fImageRefs = new const SkImage* [fImageCount];
93 for (int i = 0; i < fImageCount; ++i) { 83 for (int i = 0; i < fImageCount; ++i) {
94 fImageRefs[i] = SkRef(imgs[i]); 84 fImageRefs[i] = SkRef(imgs[i]);
95 } 85 }
96 } 86 }
97 } 87 }
98 88
99 void SkPictureData::init() { 89 void SkPictureData::init() {
100 fPictureRefs = nullptr; 90 fPictureRefs = nullptr;
101 fPictureCount = 0; 91 fPictureCount = 0;
102 fDrawableRefs = nullptr;
103 fDrawableCount = 0;
104 fTextBlobRefs = nullptr; 92 fTextBlobRefs = nullptr;
105 fTextBlobCount = 0; 93 fTextBlobCount = 0;
106 fImageRefs = nullptr; 94 fImageRefs = nullptr;
107 fImageCount = 0; 95 fImageCount = 0;
108 fFactoryPlayback = nullptr; 96 fFactoryPlayback = nullptr;
109 } 97 }
110 98
111 SkPictureData::~SkPictureData() { 99 SkPictureData::~SkPictureData() {
112 for (int i = 0; i < fPictureCount; i++) { 100 for (int i = 0; i < fPictureCount; i++) {
113 fPictureRefs[i]->unref(); 101 fPictureRefs[i]->unref();
114 } 102 }
115 delete[] fPictureRefs; 103 delete[] fPictureRefs;
116 104
117 for (int i = 0; i < fDrawableCount; i++) {
118 fDrawableRefs[i]->unref();
119 }
120 if (fDrawableCount > 0) {
121 SkASSERT(fDrawableRefs);
122 delete[] fDrawableRefs;
123 }
124
125 for (int i = 0; i < fTextBlobCount; i++) { 105 for (int i = 0; i < fTextBlobCount; i++) {
126 fTextBlobRefs[i]->unref(); 106 fTextBlobRefs[i]->unref();
127 } 107 }
128 delete[] fTextBlobRefs; 108 delete[] fTextBlobRefs;
129 109
130 for (int i = 0; i < fImageCount; i++) { 110 for (int i = 0; i < fImageCount; i++) {
131 fImageRefs[i]->unref(); 111 fImageRefs[i]->unref();
132 } 112 }
133 delete[] fImageRefs; 113 delete[] fImageRefs;
134 114
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); 299 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size());
320 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); 300 buffer.writeByteArray(fOpData->bytes(), fOpData->size());
321 301
322 if (fPictureCount > 0) { 302 if (fPictureCount > 0) {
323 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); 303 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
324 for (int i = 0; i < fPictureCount; i++) { 304 for (int i = 0; i < fPictureCount; i++) {
325 fPictureRefs[i]->flatten(buffer); 305 fPictureRefs[i]->flatten(buffer);
326 } 306 }
327 } 307 }
328 308
329 if (fDrawableCount > 0) {
330 write_tag_size(buffer, SK_PICT_DRAWABLE_TAG, fDrawableCount);
331 for (int i = 0; i < fDrawableCount; i++) {
332 buffer.writeFlattenable(fDrawableRefs[i]);
333 }
334 }
335
336 // Write this picture playback's data into a writebuffer 309 // Write this picture playback's data into a writebuffer
337 this->flattenToBuffer(buffer); 310 this->flattenToBuffer(buffer);
338 buffer.write32(SK_PICT_EOF_TAG); 311 buffer.write32(SK_PICT_EOF_TAG);
339 } 312 }
340 313
341 /////////////////////////////////////////////////////////////////////////////// 314 ///////////////////////////////////////////////////////////////////////////////
342 315
343 /** 316 /**
344 * Return the corresponding SkReadBuffer flags, given a set of 317 * Return the corresponding SkReadBuffer flags, given a set of
345 * SkPictInfo flags. 318 * SkPictInfo flags.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { 443 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
471 return buffer.readImage(); 444 return buffer.readImage();
472 } 445 }
473 446
474 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, 447 // Need a shallow wrapper to return const SkPicture* to match the other factorie s,
475 // as SkPicture::CreateFromBuffer() returns SkPicture* 448 // as SkPicture::CreateFromBuffer() returns SkPicture*
476 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) { 449 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) {
477 return SkPicture::MakeFromBuffer(buffer).release(); 450 return SkPicture::MakeFromBuffer(buffer).release();
478 } 451 }
479 452
480 static const SkDrawable* create_drawable_from_buffer(SkReadBuffer& buffer) {
481 return (SkDrawable*) buffer.readFlattenable(SkFlattenable::kSkDrawable_Type) ;
482 }
483
484 template <typename T> 453 template <typename T>
485 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, 454 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount,
486 const T*** array, int* outCount, const T* (*factory)( SkReadBuffer&)) { 455 const T*** array, int* outCount, const T* (*factory)( SkReadBuffer&)) {
487 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) { 456 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) {
488 return false; 457 return false;
489 } 458 }
490 if (0 == inCount) { 459 if (0 == inCount) {
491 return true; 460 return true;
492 } 461 }
493 *outCount = inCount; 462 *outCount = inCount;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 533 }
565 SkASSERT(nullptr == fOpData); 534 SkASSERT(nullptr == fOpData);
566 fOpData = std::move(data); 535 fOpData = std::move(data);
567 } break; 536 } break;
568 case SK_PICT_PICTURE_TAG: 537 case SK_PICT_PICTURE_TAG:
569 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou nt, 538 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou nt,
570 create_picture_from_buffer)) { 539 create_picture_from_buffer)) {
571 return false; 540 return false;
572 } 541 }
573 break; 542 break;
574 case SK_PICT_DRAWABLE_TAG:
575 if (!new_array_from_buffer(buffer, size, (const SkDrawable***)&fDraw ableRefs,
576 &fDrawableCount, create_drawable_from_buf fer)) {
577 return false;
578 }
579 break;
580 default: 543 default:
581 // The tag was invalid. 544 // The tag was invalid.
582 return false; 545 return false;
583 } 546 }
584 return true; // success 547 return true; // success
585 } 548 }
586 549
587 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, 550 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream,
588 const SkPictInfo& info, 551 const SkPictInfo& info,
589 SkPicture::InstallPixelRefProc pr oc, 552 SkPicture::InstallPixelRefProc pr oc,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } else { 623 } else {
661 return this->suitableForGpuRasterization(nullptr, reason); 624 return this->suitableForGpuRasterization(nullptr, reason);
662 } 625 }
663 } 626 }
664 627
665 bool SkPictureData::suitableForLayerOptimization() const { 628 bool SkPictureData::suitableForLayerOptimization() const {
666 return fContentInfo.numLayers() > 0; 629 return fContentInfo.numLayers() > 0;
667 } 630 }
668 #endif 631 #endif
669 /////////////////////////////////////////////////////////////////////////////// 632 ///////////////////////////////////////////////////////////////////////////////
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