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

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

Powered by Google App Engine
This is Rietveld 408576698