| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 1, // DRAW_RECT - right after op code | 76 1, // DRAW_RECT - right after op code |
| 77 1, // DRAW_RRECT - right after op code | 77 1, // DRAW_RRECT - right after op code |
| 78 1, // DRAW_SPRITE - right after op code | 78 1, // DRAW_SPRITE - right after op code |
| 79 1, // DRAW_TEXT - right after op code | 79 1, // DRAW_TEXT - right after op code |
| 80 1, // DRAW_TEXT_ON_PATH - right after op code | 80 1, // DRAW_TEXT_ON_PATH - right after op code |
| 81 1, // DRAW_TEXT_TOP_BOTTOM - right after op code | 81 1, // DRAW_TEXT_TOP_BOTTOM - right after op code |
| 82 1, // DRAW_VERTICES - right after op code | 82 1, // DRAW_VERTICES - right after op code |
| 83 0, // RESTORE - no paint | 83 0, // RESTORE - no paint |
| 84 0, // ROTATE - no paint | 84 0, // ROTATE - no paint |
| 85 0, // SAVE - no paint | 85 0, // SAVE - no paint |
| 86 0, // SAVE_LAYER - see below - this paint's location varies | 86 0, // SAVE_LAYER_SAVEFLAGS - see below - this paint's location varies |
| 87 0, // SCALE - no paint | 87 0, // SCALE - no paint |
| 88 0, // SET_MATRIX - no paint | 88 0, // SET_MATRIX - no paint |
| 89 0, // SKEW - no paint | 89 0, // SKEW - no paint |
| 90 0, // TRANSLATE - no paint | 90 0, // TRANSLATE - no paint |
| 91 0, // NOOP - no paint | 91 0, // NOOP - no paint |
| 92 0, // BEGIN_GROUP - no paint | 92 0, // BEGIN_GROUP - no paint |
| 93 0, // COMMENT - no paint | 93 0, // COMMENT - no paint |
| 94 0, // END_GROUP - no paint | 94 0, // END_GROUP - no paint |
| 95 1, // DRAWDRRECT - right after op code | 95 1, // DRAWDRRECT - right after op code |
| 96 0, // PUSH_CULL - no paint | 96 0, // PUSH_CULL - no paint |
| (...skipping 11 matching lines...) Expand all Loading... |
| 108 static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_i
n_sync"); | 108 static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_i
n_sync"); |
| 109 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 109 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
| 110 | 110 |
| 111 int overflow = 0; | 111 int overflow = 0; |
| 112 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 112 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
| 113 // This op's size overflows so an extra uint32_t will be written | 113 // This op's size overflows so an extra uint32_t will be written |
| 114 // after the op code | 114 // after the op code |
| 115 overflow = sizeof(uint32_t); | 115 overflow = sizeof(uint32_t); |
| 116 } | 116 } |
| 117 | 117 |
| 118 if (SAVE_LAYER == op) { | 118 if (SAVE_LAYER_SAVEFLAGS_DEPRECATED == op) { |
| 119 static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; | 119 static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; |
| 120 static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size
+ sizeof(SkRect); | 120 static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size
+ sizeof(SkRect); |
| 121 | 121 |
| 122 if (kSaveLayerNoBoundsSize == opSize) { | 122 if (kSaveLayerNoBoundsSize == opSize) { |
| 123 return kSaveLayerNoBoundsPaintOffset + overflow; | 123 return kSaveLayerNoBoundsPaintOffset + overflow; |
| 124 } else { | 124 } else { |
| 125 SkASSERT(kSaveLayerWithBoundsSize == opSize); | 125 SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 126 return kSaveLayerWithBoundsPaintOffset + overflow; | 126 return kSaveLayerWithBoundsPaintOffset + overflow; |
| 127 } | 127 } |
| 128 } | 128 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 void SkPictureRecord::recordSave() { | 144 void SkPictureRecord::recordSave() { |
| 145 fContentInfo.onSave(); | 145 fContentInfo.onSave(); |
| 146 | 146 |
| 147 // op only | 147 // op only |
| 148 size_t size = kSaveSize; | 148 size_t size = kSaveSize; |
| 149 size_t initialOffset = this->addDraw(SAVE, &size); | 149 size_t initialOffset = this->addDraw(SAVE, &size); |
| 150 | 150 |
| 151 this->validate(initialOffset, size); | 151 this->validate(initialOffset, size); |
| 152 } | 152 } |
| 153 | 153 |
| 154 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, | 154 SkCanvas::SaveLayerStrategy SkPictureRecord::getSaveLayerStrategy(const SaveLaye
rRec& rec) { |
| 155 const SkPaint* paint,
SaveFlags flags) { | |
| 156 // record the offset to us, making it non-positive to distinguish a save | 155 // record the offset to us, making it non-positive to distinguish a save |
| 157 // from a clip entry. | 156 // from a clip entry. |
| 158 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 157 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 159 this->recordSaveLayer(bounds, paint, flags); | 158 this->recordSaveLayer(rec); |
| 160 | 159 |
| 161 this->INHERITED::willSaveLayer(bounds, paint, flags); | 160 (void)this->INHERITED::getSaveLayerStrategy(rec); |
| 162 /* No need for a (potentially very big) layer which we don't actually need | 161 /* No need for a (potentially very big) layer which we don't actually need |
| 163 at this time (and may not be able to afford since during record our | 162 at this time (and may not be able to afford since during record our |
| 164 clip starts out the size of the picture, which is often much larger | 163 clip starts out the size of the picture, which is often much larger |
| 165 than the size of the actual device we'll use during playback). | 164 than the size of the actual device we'll use during playback). |
| 166 */ | 165 */ |
| 167 return kNoLayer_SaveLayerStrategy; | 166 return kNoLayer_SaveLayerStrategy; |
| 168 } | 167 } |
| 169 | 168 |
| 170 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, | 169 void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { |
| 171 SaveFlags flags) { | |
| 172 fContentInfo.onSaveLayer(); | 170 fContentInfo.onSaveLayer(); |
| 173 | 171 |
| 174 // op + bool for 'bounds' | 172 // op + bool for 'bounds' |
| 175 size_t size = 2 * kUInt32Size; | 173 size_t size = 2 * kUInt32Size; |
| 176 if (bounds) { | 174 if (rec.fBounds) { |
| 177 size += sizeof(*bounds); // + rect | 175 size += sizeof(*rec.fBounds); // + rect |
| 178 } | 176 } |
| 179 // + paint index + flags | 177 // + paint index + flags |
| 180 size += 2 * kUInt32Size; | 178 size += 2 * kUInt32Size; |
| 181 | 179 |
| 182 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; | 180 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; |
| 183 | 181 |
| 184 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); | 182 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); |
| 185 this->addRectPtr(bounds); | 183 this->addRectPtr(rec.fBounds); |
| 186 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWr
itten()); | 184 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER_SAVELAYERFLAGS, size) ==
fWriter.bytesWritten()); |
| 187 this->addPaintPtr(paint); | 185 this->addPaintPtr(rec.fPaint); |
| 188 this->addInt(flags); | 186 this->addInt(rec.fSaveLayerFlags); |
| 189 | 187 |
| 190 this->validate(initialOffset, size); | 188 this->validate(initialOffset, size); |
| 191 } | 189 } |
| 192 | 190 |
| 193 #ifdef SK_DEBUG | 191 #ifdef SK_DEBUG |
| 194 /* | 192 /* |
| 195 * Read the op code from 'offset' in 'writer' and extract the size too. | 193 * Read the op code from 'offset' in 'writer' and extract the size too. |
| 196 */ | 194 */ |
| 197 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { | 195 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { |
| 198 uint32_t peek = writer->readTAt<uint32_t>(offset); | 196 uint32_t peek = writer->readTAt<uint32_t>(offset); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 fWriter.overwriteTAt(offset, restoreOffset); | 312 fWriter.overwriteTAt(offset, restoreOffset); |
| 315 offset = peek; | 313 offset = peek; |
| 316 } | 314 } |
| 317 | 315 |
| 318 #ifdef SK_DEBUG | 316 #ifdef SK_DEBUG |
| 319 // offset of 0 has been disabled, so we skip it | 317 // offset of 0 has been disabled, so we skip it |
| 320 if (offset > 0) { | 318 if (offset > 0) { |
| 321 // assert that the final offset value points to a save verb | 319 // assert that the final offset value points to a save verb |
| 322 uint32_t opSize; | 320 uint32_t opSize; |
| 323 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); | 321 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
| 324 SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp); | 322 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); |
| 323 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERFLAGS == drawOp); |
| 325 } | 324 } |
| 326 #endif | 325 #endif |
| 327 } | 326 } |
| 328 | 327 |
| 329 void SkPictureRecord::beginRecording() { | 328 void SkPictureRecord::beginRecording() { |
| 330 // we have to call this *after* our constructor, to ensure that it gets | 329 // we have to call this *after* our constructor, to ensure that it gets |
| 331 // recorded. This is balanced by restoreToCount() call from endRecording, | 330 // recorded. This is balanced by restoreToCount() call from endRecording, |
| 332 // which in-turn calls our overridden restore(), so those get recorded too. | 331 // which in-turn calls our overridden restore(), so those get recorded too. |
| 333 fInitialSaveCount = this->save(); | 332 fInitialSaveCount = this->save(); |
| 334 } | 333 } |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1050 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 1052 int index = fTextBlobRefs.count(); | 1051 int index = fTextBlobRefs.count(); |
| 1053 *fTextBlobRefs.append() = blob; | 1052 *fTextBlobRefs.append() = blob; |
| 1054 blob->ref(); | 1053 blob->ref(); |
| 1055 // follow the convention of recording a 1-based index | 1054 // follow the convention of recording a 1-based index |
| 1056 this->addInt(index + 1); | 1055 this->addInt(index + 1); |
| 1057 } | 1056 } |
| 1058 | 1057 |
| 1059 /////////////////////////////////////////////////////////////////////////////// | 1058 /////////////////////////////////////////////////////////////////////////////// |
| 1060 | 1059 |
| OLD | NEW |