OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 at this time (and may not be able to afford since during record our | 69 at this time (and may not be able to afford since during record our |
70 clip starts out the size of the picture, which is often much larger | 70 clip starts out the size of the picture, which is often much larger |
71 than the size of the actual device we'll use during playback). | 71 than the size of the actual device we'll use during playback). |
72 */ | 72 */ |
73 return kNoLayer_SaveLayerStrategy; | 73 return kNoLayer_SaveLayerStrategy; |
74 } | 74 } |
75 | 75 |
76 void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { | 76 void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { |
77 fContentInfo.onSaveLayer(); | 77 fContentInfo.onSaveLayer(); |
78 | 78 |
79 // op + flatflags | 79 // op + bool for 'bounds' |
80 size_t size = 2 * kUInt32Size; | 80 size_t size = 2 * kUInt32Size; |
81 uint32_t flatFlags = 0; | 81 if (rec.fBounds) { |
| 82 size += sizeof(*rec.fBounds); // + rect |
| 83 } |
| 84 // + paint index + flags |
| 85 size += 2 * kUInt32Size; |
82 | 86 |
83 if (rec.fBounds) { | 87 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); |
84 flatFlags |= SAVELAYERREC_HAS_BOUNDS; | 88 this->addRectPtr(rec.fBounds); |
85 size += sizeof(*rec.fBounds); | 89 this->addPaintPtr(rec.fPaint); |
86 } | 90 this->addInt(rec.fSaveLayerFlags); |
87 if (rec.fPaint) { | |
88 flatFlags |= SAVELAYERREC_HAS_PAINT; | |
89 size += sizeof(uint32_t); // index | |
90 } | |
91 if (rec.fBackdrop) { | |
92 flatFlags |= SAVELAYERREC_HAS_BACKDROP; | |
93 size += sizeof(uint32_t); // (paint) index | |
94 } | |
95 if (rec.fSaveLayerFlags) { | |
96 flatFlags |= SAVELAYERREC_HAS_FLAGS; | |
97 size += sizeof(uint32_t); | |
98 } | |
99 | 91 |
100 const size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERREC, &size); | |
101 this->addInt(flatFlags); | |
102 if (flatFlags & SAVELAYERREC_HAS_BOUNDS) { | |
103 this->addRect(*rec.fBounds); | |
104 } | |
105 if (flatFlags & SAVELAYERREC_HAS_PAINT) { | |
106 this->addPaintPtr(rec.fPaint); | |
107 } | |
108 if (flatFlags & SAVELAYERREC_HAS_BACKDROP) { | |
109 // overkill, but we didn't already track single flattenables, so using a
paint for that | |
110 SkPaint paint; | |
111 paint.setImageFilter(const_cast<SkImageFilter*>(rec.fBackdrop)); | |
112 this->addPaint(paint); | |
113 } | |
114 if (flatFlags & SAVELAYERREC_HAS_FLAGS) { | |
115 this->addInt(rec.fSaveLayerFlags); | |
116 } | |
117 this->validate(initialOffset, size); | 92 this->validate(initialOffset, size); |
118 } | 93 } |
119 | 94 |
120 #ifdef SK_DEBUG | 95 #ifdef SK_DEBUG |
121 /* | 96 /* |
122 * Read the op code from 'offset' in 'writer' and extract the size too. | 97 * Read the op code from 'offset' in 'writer' and extract the size too. |
123 */ | 98 */ |
124 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { | 99 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { |
125 uint32_t peek = writer->readTAt<uint32_t>(offset); | 100 uint32_t peek = writer->readTAt<uint32_t>(offset); |
126 | 101 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 offset = peek; | 217 offset = peek; |
243 } | 218 } |
244 | 219 |
245 #ifdef SK_DEBUG | 220 #ifdef SK_DEBUG |
246 // offset of 0 has been disabled, so we skip it | 221 // offset of 0 has been disabled, so we skip it |
247 if (offset > 0) { | 222 if (offset > 0) { |
248 // assert that the final offset value points to a save verb | 223 // assert that the final offset value points to a save verb |
249 uint32_t opSize; | 224 uint32_t opSize; |
250 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); | 225 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
251 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); | 226 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); |
252 SkASSERT(SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016 != drawOp); | 227 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERFLAGS == drawOp); |
253 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERREC == drawOp); | |
254 } | 228 } |
255 #endif | 229 #endif |
256 } | 230 } |
257 | 231 |
258 void SkPictureRecord::beginRecording() { | 232 void SkPictureRecord::beginRecording() { |
259 // we have to call this *after* our constructor, to ensure that it gets | 233 // we have to call this *after* our constructor, to ensure that it gets |
260 // recorded. This is balanced by restoreToCount() call from endRecording, | 234 // recorded. This is balanced by restoreToCount() call from endRecording, |
261 // which in-turn calls our overridden restore(), so those get recorded too. | 235 // which in-turn calls our overridden restore(), so those get recorded too. |
262 fInitialSaveCount = this->save(); | 236 fInitialSaveCount = this->save(); |
263 } | 237 } |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 931 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
958 int index = fTextBlobRefs.count(); | 932 int index = fTextBlobRefs.count(); |
959 *fTextBlobRefs.append() = blob; | 933 *fTextBlobRefs.append() = blob; |
960 blob->ref(); | 934 blob->ref(); |
961 // follow the convention of recording a 1-based index | 935 // follow the convention of recording a 1-based index |
962 this->addInt(index + 1); | 936 this->addInt(index + 1); |
963 } | 937 } |
964 | 938 |
965 /////////////////////////////////////////////////////////////////////////////// | 939 /////////////////////////////////////////////////////////////////////////////// |
966 | 940 |
OLD | NEW |