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

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

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