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

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

Issue 1837913003: Add support for serializing/deserializing of SkDrawable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase 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
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/core/SkPictureRecorder.cpp » ('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 7
8 #include "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkImage_Base.h" 9 #include "SkImage_Base.h"
10 #include "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
(...skipping 15 matching lines...) Expand all
26 26
27 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) 27 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
28 : INHERITED(dimensions.width(), dimensions.height()) 28 : INHERITED(dimensions.width(), dimensions.height())
29 , fRecordFlags(flags) 29 , fRecordFlags(flags)
30 , fInitialSaveCount(kNoInitialSave) { 30 , fInitialSaveCount(kNoInitialSave) {
31 } 31 }
32 32
33 SkPictureRecord::~SkPictureRecord() { 33 SkPictureRecord::~SkPictureRecord() {
34 fImageRefs.unrefAll(); 34 fImageRefs.unrefAll();
35 fPictureRefs.unrefAll(); 35 fPictureRefs.unrefAll();
36 fDrawableRefs.unrefAll();
36 fTextBlobRefs.unrefAll(); 37 fTextBlobRefs.unrefAll();
37 } 38 }
38 39
39 /////////////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////////////
40 41
41 void SkPictureRecord::willSave() { 42 void SkPictureRecord::willSave() {
42 // record the offset to us, making it non-positive to distinguish a save 43 // record the offset to us, making it non-positive to distinguish a save
43 // from a clip entry. 44 // from a clip entry.
44 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); 45 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten());
45 this->recordSave(); 46 this->recordSave();
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); 631 const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
631 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint 632 size += m.writeToMemory(nullptr) + kUInt32Size; // matrix + paint
632 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); 633 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size);
633 this->addPaintPtr(paint); 634 this->addPaintPtr(paint);
634 this->addMatrix(m); 635 this->addMatrix(m);
635 this->addPicture(picture); 636 this->addPicture(picture);
636 } 637 }
637 this->validate(initialOffset, size); 638 this->validate(initialOffset, size);
638 } 639 }
639 640
641 void SkPictureRecord::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matri x) {
642 // op + drawable index
643 size_t size = 2 * kUInt32Size;
644 size_t initialOffset;
645
646 if (nullptr == matrix) {
647 initialOffset = this->addDraw(DRAW_DRAWABLE, &size);
648 this->addDrawable(drawable);
649 } else {
650 size += matrix->writeToMemory(nullptr); // matrix
651 initialOffset = this->addDraw(DRAW_DRAWABLE_MATRIX, &size);
652 this->addMatrix(*matrix);
653 this->addDrawable(drawable);
654 }
655 this->validate(initialOffset, size);
656 }
657
640 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount, 658 void SkPictureRecord::onDrawVertices(VertexMode vmode, int vertexCount,
641 const SkPoint vertices[], const SkPoint tex s[], 659 const SkPoint vertices[], const SkPoint tex s[],
642 const SkColor colors[], SkXfermode* xfer, 660 const SkColor colors[], SkXfermode* xfer,
643 const uint16_t indices[], int indexCount, 661 const uint16_t indices[], int indexCount,
644 const SkPaint& paint) { 662 const SkPaint& paint) {
645 uint32_t flags = 0; 663 uint32_t flags = 0;
646 if (texs) { 664 if (texs) {
647 flags |= DRAW_VERTICES_HAS_TEXS; 665 flags |= DRAW_VERTICES_HAS_TEXS;
648 } 666 }
649 if (colors) { 667 if (colors) {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 int index = fPictureRefs.find(picture); 929 int index = fPictureRefs.find(picture);
912 if (index < 0) { // not found 930 if (index < 0) { // not found
913 index = fPictureRefs.count(); 931 index = fPictureRefs.count();
914 *fPictureRefs.append() = picture; 932 *fPictureRefs.append() = picture;
915 picture->ref(); 933 picture->ref();
916 } 934 }
917 // follow the convention of recording a 1-based index 935 // follow the convention of recording a 1-based index
918 this->addInt(index + 1); 936 this->addInt(index + 1);
919 } 937 }
920 938
939 void SkPictureRecord::addDrawable(SkDrawable* drawable) {
940 int index = fDrawableRefs.find(drawable);
941 if (index < 0) { // not found
942 index = fDrawableRefs.count();
943 *fDrawableRefs.append() = drawable;
944 drawable->ref();
945 }
946 // follow the convention of recording a 1-based index
947 this->addInt(index + 1);
948 }
949
921 void SkPictureRecord::addPoint(const SkPoint& point) { 950 void SkPictureRecord::addPoint(const SkPoint& point) {
922 fWriter.writePoint(point); 951 fWriter.writePoint(point);
923 } 952 }
924 953
925 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { 954 void SkPictureRecord::addPoints(const SkPoint pts[], int count) {
926 fWriter.writeMul4(pts, count * sizeof(SkPoint)); 955 fWriter.writeMul4(pts, count * sizeof(SkPoint));
927 } 956 }
928 957
929 void SkPictureRecord::addNoOp() { 958 void SkPictureRecord::addNoOp() {
930 size_t size = kUInt32Size; // op 959 size_t size = kUInt32Size; // op
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 996
968 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 997 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
969 int index = fTextBlobRefs.count(); 998 int index = fTextBlobRefs.count();
970 *fTextBlobRefs.append() = blob; 999 *fTextBlobRefs.append() = blob;
971 blob->ref(); 1000 blob->ref();
972 // follow the convention of recording a 1-based index 1001 // follow the convention of recording a 1-based index
973 this->addInt(index + 1); 1002 this->addInt(index + 1);
974 } 1003 }
975 1004
976 /////////////////////////////////////////////////////////////////////////////// 1005 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.h ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698