| 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 + bool for 'bounds' | 79 // op + flatflags |
| 80 size_t size = 2 * kUInt32Size; | 80 size_t size = 2 * kUInt32Size; |
| 81 uint32_t flatFlags = 0; |
| 82 |
| 81 if (rec.fBounds) { | 83 if (rec.fBounds) { |
| 82 size += sizeof(*rec.fBounds); // + rect | 84 flatFlags |= SAVELAYERREC_HAS_BOUNDS; |
| 85 size += sizeof(*rec.fBounds); |
| 83 } | 86 } |
| 84 // + paint index + flags | 87 if (rec.fPaint) { |
| 85 size += 2 * kUInt32Size; | 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 } |
| 86 | 99 |
| 87 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); | 100 const size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERREC, &size); |
| 88 this->addRectPtr(rec.fBounds); | 101 this->addInt(flatFlags); |
| 89 this->addPaintPtr(rec.fPaint); | 102 if (flatFlags & SAVELAYERREC_HAS_BOUNDS) { |
| 90 this->addInt(rec.fSaveLayerFlags); | 103 this->addRect(*rec.fBounds); |
| 91 | 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 } |
| 92 this->validate(initialOffset, size); | 117 this->validate(initialOffset, size); |
| 93 } | 118 } |
| 94 | 119 |
| 95 #ifdef SK_DEBUG | 120 #ifdef SK_DEBUG |
| 96 /* | 121 /* |
| 97 * Read the op code from 'offset' in 'writer' and extract the size too. | 122 * Read the op code from 'offset' in 'writer' and extract the size too. |
| 98 */ | 123 */ |
| 99 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { | 124 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { |
| 100 uint32_t peek = writer->readTAt<uint32_t>(offset); | 125 uint32_t peek = writer->readTAt<uint32_t>(offset); |
| 101 | 126 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 offset = peek; | 242 offset = peek; |
| 218 } | 243 } |
| 219 | 244 |
| 220 #ifdef SK_DEBUG | 245 #ifdef SK_DEBUG |
| 221 // offset of 0 has been disabled, so we skip it | 246 // offset of 0 has been disabled, so we skip it |
| 222 if (offset > 0) { | 247 if (offset > 0) { |
| 223 // assert that the final offset value points to a save verb | 248 // assert that the final offset value points to a save verb |
| 224 uint32_t opSize; | 249 uint32_t opSize; |
| 225 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); | 250 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
| 226 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); | 251 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); |
| 227 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERFLAGS == drawOp); | 252 SkASSERT(SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016 != drawOp); |
| 253 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERREC == drawOp); |
| 228 } | 254 } |
| 229 #endif | 255 #endif |
| 230 } | 256 } |
| 231 | 257 |
| 232 void SkPictureRecord::beginRecording() { | 258 void SkPictureRecord::beginRecording() { |
| 233 // we have to call this *after* our constructor, to ensure that it gets | 259 // we have to call this *after* our constructor, to ensure that it gets |
| 234 // recorded. This is balanced by restoreToCount() call from endRecording, | 260 // recorded. This is balanced by restoreToCount() call from endRecording, |
| 235 // which in-turn calls our overridden restore(), so those get recorded too. | 261 // which in-turn calls our overridden restore(), so those get recorded too. |
| 236 fInitialSaveCount = this->save(); | 262 fInitialSaveCount = this->save(); |
| 237 } | 263 } |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 957 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 932 int index = fTextBlobRefs.count(); | 958 int index = fTextBlobRefs.count(); |
| 933 *fTextBlobRefs.append() = blob; | 959 *fTextBlobRefs.append() = blob; |
| 934 blob->ref(); | 960 blob->ref(); |
| 935 // follow the convention of recording a 1-based index | 961 // follow the convention of recording a 1-based index |
| 936 this->addInt(index + 1); | 962 this->addInt(index + 1); |
| 937 } | 963 } |
| 938 | 964 |
| 939 /////////////////////////////////////////////////////////////////////////////// | 965 /////////////////////////////////////////////////////////////////////////////// |
| 940 | 966 |
| OLD | NEW |