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

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

Issue 1837913003: Add support for serializing/deserializing of SkDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ability to specify custom flattenable factories on SkReadBuffer Created 4 years, 8 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
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
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size()); 309 write_tag_size(buffer, SK_PICT_READER_TAG, fOpData->size());
300 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); 310 buffer.writeByteArray(fOpData->bytes(), fOpData->size());
301 311
302 if (fPictureCount > 0) { 312 if (fPictureCount > 0) {
303 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount); 313 write_tag_size(buffer, SK_PICT_PICTURE_TAG, fPictureCount);
304 for (int i = 0; i < fPictureCount; i++) { 314 for (int i = 0; i < fPictureCount; i++) {
305 fPictureRefs[i]->flatten(buffer); 315 fPictureRefs[i]->flatten(buffer);
306 } 316 }
307 } 317 }
308 318
319 if (fDrawableCount > 0) {
320 write_tag_size(buffer, SK_PICT_DRAWABLE_TAG, fDrawableCount);
321 for (int i = 0; i < fDrawableCount; i++) {
322 buffer.writeFlattenable(fDrawableRefs[i]);
323 }
324 }
325
309 // Write this picture playback's data into a writebuffer 326 // Write this picture playback's data into a writebuffer
310 this->flattenToBuffer(buffer); 327 this->flattenToBuffer(buffer);
311 buffer.write32(SK_PICT_EOF_TAG); 328 buffer.write32(SK_PICT_EOF_TAG);
312 } 329 }
313 330
314 /////////////////////////////////////////////////////////////////////////////// 331 ///////////////////////////////////////////////////////////////////////////////
315 332
316 /** 333 /**
317 * Return the corresponding SkReadBuffer flags, given a set of 334 * Return the corresponding SkReadBuffer flags, given a set of
318 * SkPictInfo flags. 335 * SkPictInfo flags.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) { 460 static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
444 return buffer.readImage(); 461 return buffer.readImage();
445 } 462 }
446 463
447 // Need a shallow wrapper to return const SkPicture* to match the other factorie s, 464 // Need a shallow wrapper to return const SkPicture* to match the other factorie s,
448 // as SkPicture::CreateFromBuffer() returns SkPicture* 465 // as SkPicture::CreateFromBuffer() returns SkPicture*
449 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) { 466 static const SkPicture* create_picture_from_buffer(SkReadBuffer& buffer) {
450 return SkPicture::MakeFromBuffer(buffer).release(); 467 return SkPicture::MakeFromBuffer(buffer).release();
451 } 468 }
452 469
470 static const SkDrawable* create_drawable_from_buffer(SkReadBuffer& buffer) {
471 return (SkDrawable*) buffer.readFlattenable(SkFlattenable::kSkDrawable_Type) ;
472 }
473
453 template <typename T> 474 template <typename T>
454 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount, 475 bool new_array_from_buffer(SkReadBuffer& buffer, uint32_t inCount,
455 const T*** array, int* outCount, const T* (*factory)( SkReadBuffer&)) { 476 const T*** array, int* outCount, const T* (*factory)( SkReadBuffer&)) {
456 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) { 477 if (!buffer.validate((0 == *outCount) && (nullptr == *array))) {
457 return false; 478 return false;
458 } 479 }
459 if (0 == inCount) { 480 if (0 == inCount) {
460 return true; 481 return true;
461 } 482 }
462 *outCount = inCount; 483 *outCount = inCount;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 554 }
534 SkASSERT(nullptr == fOpData); 555 SkASSERT(nullptr == fOpData);
535 fOpData = std::move(data); 556 fOpData = std::move(data);
536 } break; 557 } break;
537 case SK_PICT_PICTURE_TAG: 558 case SK_PICT_PICTURE_TAG:
538 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou nt, 559 if (!new_array_from_buffer(buffer, size, &fPictureRefs, &fPictureCou nt,
539 create_picture_from_buffer)) { 560 create_picture_from_buffer)) {
540 return false; 561 return false;
541 } 562 }
542 break; 563 break;
564 case SK_PICT_DRAWABLE_TAG:
565 if (!new_array_from_buffer(buffer, size, (const SkDrawable***)&fDraw ableRefs,
566 &fDrawableCount, create_drawable_from_buf fer)) {
567 return false;
568 }
569 break;
543 default: 570 default:
544 // The tag was invalid. 571 // The tag was invalid.
545 return false; 572 return false;
546 } 573 }
547 return true; // success 574 return true; // success
548 } 575 }
549 576
550 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, 577 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream,
551 const SkPictInfo& info, 578 const SkPictInfo& info,
552 SkPicture::InstallPixelRefProc pr oc, 579 SkPicture::InstallPixelRefProc pr oc,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } else { 650 } else {
624 return this->suitableForGpuRasterization(nullptr, reason); 651 return this->suitableForGpuRasterization(nullptr, reason);
625 } 652 }
626 } 653 }
627 654
628 bool SkPictureData::suitableForLayerOptimization() const { 655 bool SkPictureData::suitableForLayerOptimization() const {
629 return fContentInfo.numLayers() > 0; 656 return fContentInfo.numLayers() > 0;
630 } 657 }
631 #endif 658 #endif
632 /////////////////////////////////////////////////////////////////////////////// 659 ///////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698