| 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 "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 static int const kUInt32Size = 4; | 24 static int const kUInt32Size = 4; |
| 25 | 25 |
| 26 static const uint32_t kSaveSize = kUInt32Size; | 26 static const uint32_t kSaveSize = kUInt32Size; |
| 27 #ifdef SK_DEBUG | 27 #ifdef SK_DEBUG |
| 28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; | 28 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
| 29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); | 29 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); |
| 30 #endif//SK_DEBUG | 30 #endif//SK_DEBUG |
| 31 | 31 |
| 32 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) | 32 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
| 33 : INHERITED(dimensions.width(), dimensions.height()) | 33 : INHERITED(dimensions.width(), dimensions.height()) |
| 34 , fFirstSavedLayerIndex(kNoSavedLayerIndex) | |
| 35 , fRecordFlags(flags) | 34 , fRecordFlags(flags) |
| 36 , fInitialSaveCount(kNoInitialSave) { | 35 , fInitialSaveCount(kNoInitialSave) { |
| 37 } | 36 } |
| 38 | 37 |
| 39 SkPictureRecord::~SkPictureRecord() { | 38 SkPictureRecord::~SkPictureRecord() { |
| 40 fPictureRefs.unrefAll(); | 39 fPictureRefs.unrefAll(); |
| 41 fTextBlobRefs.unrefAll(); | 40 fTextBlobRefs.unrefAll(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 143 |
| 145 this->validate(initialOffset, size); | 144 this->validate(initialOffset, size); |
| 146 } | 145 } |
| 147 | 146 |
| 148 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, | 147 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, |
| 149 const SkPaint* paint,
SaveFlags flags) { | 148 const SkPaint* paint,
SaveFlags flags) { |
| 150 // record the offset to us, making it non-positive to distinguish a save | 149 // record the offset to us, making it non-positive to distinguish a save |
| 151 // from a clip entry. | 150 // from a clip entry. |
| 152 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 151 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 153 this->recordSaveLayer(bounds, paint, flags); | 152 this->recordSaveLayer(bounds, paint, flags); |
| 154 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { | |
| 155 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); | |
| 156 } | |
| 157 | 153 |
| 158 this->INHERITED::willSaveLayer(bounds, paint, flags); | 154 this->INHERITED::willSaveLayer(bounds, paint, flags); |
| 159 /* No need for a (potentially very big) layer which we don't actually need | 155 /* No need for a (potentially very big) layer which we don't actually need |
| 160 at this time (and may not be able to afford since during record our | 156 at this time (and may not be able to afford since during record our |
| 161 clip starts out the size of the picture, which is often much larger | 157 clip starts out the size of the picture, which is often much larger |
| 162 than the size of the actual device we'll use during playback). | 158 than the size of the actual device we'll use during playback). |
| 163 */ | 159 */ |
| 164 return kNoLayer_SaveLayerStrategy; | 160 return kNoLayer_SaveLayerStrategy; |
| 165 } | 161 } |
| 166 | 162 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 180 | 176 |
| 181 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); | 177 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); |
| 182 this->addRectPtr(bounds); | 178 this->addRectPtr(bounds); |
| 183 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWr
itten()); | 179 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWr
itten()); |
| 184 this->addPaintPtr(paint); | 180 this->addPaintPtr(paint); |
| 185 this->addInt(flags); | 181 this->addInt(flags); |
| 186 | 182 |
| 187 this->validate(initialOffset, size); | 183 this->validate(initialOffset, size); |
| 188 } | 184 } |
| 189 | 185 |
| 190 bool SkPictureRecord::isDrawingToLayer() const { | |
| 191 return fFirstSavedLayerIndex != kNoSavedLayerIndex; | |
| 192 } | |
| 193 | |
| 194 #ifdef SK_DEBUG | 186 #ifdef SK_DEBUG |
| 195 /* | 187 /* |
| 196 * Read the op code from 'offset' in 'writer' and extract the size too. | 188 * Read the op code from 'offset' in 'writer' and extract the size too. |
| 197 */ | 189 */ |
| 198 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { | 190 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { |
| 199 uint32_t peek = writer->readTAt<uint32_t>(offset); | 191 uint32_t peek = writer->readTAt<uint32_t>(offset); |
| 200 | 192 |
| 201 uint32_t op; | 193 uint32_t op; |
| 202 UNPACK_8_24(peek, op, *size); | 194 UNPACK_8_24(peek, op, *size); |
| 203 if (MASK_24 == *size) { | 195 if (MASK_24 == *size) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 214 // turned on permanently. | 206 // turned on permanently. |
| 215 #if 0 | 207 #if 0 |
| 216 SkASSERT(fRestoreOffsetStack.count() > 1); | 208 SkASSERT(fRestoreOffsetStack.count() > 1); |
| 217 #endif | 209 #endif |
| 218 | 210 |
| 219 // check for underflow | 211 // check for underflow |
| 220 if (fRestoreOffsetStack.count() == 0) { | 212 if (fRestoreOffsetStack.count() == 0) { |
| 221 return; | 213 return; |
| 222 } | 214 } |
| 223 | 215 |
| 224 if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) { | |
| 225 fFirstSavedLayerIndex = kNoSavedLayerIndex; | |
| 226 } | |
| 227 | |
| 228 this->recordRestore(); | 216 this->recordRestore(); |
| 229 | 217 |
| 230 fRestoreOffsetStack.pop(); | 218 fRestoreOffsetStack.pop(); |
| 231 | 219 |
| 232 this->INHERITED::willRestore(); | 220 this->INHERITED::willRestore(); |
| 233 } | 221 } |
| 234 | 222 |
| 235 void SkPictureRecord::recordRestore(bool fillInSkips) { | 223 void SkPictureRecord::recordRestore(bool fillInSkips) { |
| 236 fContentInfo.onRestore(); | 224 fContentInfo.onRestore(); |
| 237 | 225 |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1001 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 1014 int index = fTextBlobRefs.count(); | 1002 int index = fTextBlobRefs.count(); |
| 1015 *fTextBlobRefs.append() = blob; | 1003 *fTextBlobRefs.append() = blob; |
| 1016 blob->ref(); | 1004 blob->ref(); |
| 1017 // follow the convention of recording a 1-based index | 1005 // follow the convention of recording a 1-based index |
| 1018 this->addInt(index + 1); | 1006 this->addInt(index + 1); |
| 1019 } | 1007 } |
| 1020 | 1008 |
| 1021 /////////////////////////////////////////////////////////////////////////////// | 1009 /////////////////////////////////////////////////////////////////////////////// |
| 1022 | 1010 |
| OLD | NEW |