| 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_DEPRECATED - see below - this paint's locati
on 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 |
| 97 0, // POP_CULL - no paint | 97 0, // POP_CULL - no paint |
| 98 1, // DRAW_PATCH - right after op code | 98 1, // DRAW_PATCH - right after op code |
| 99 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code | 99 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code |
| 100 1, // DRAW_TEXT_BLOB- right after op code | 100 1, // DRAW_TEXT_BLOB- right after op code |
| 101 1, // DRAW_IMAGE - right after op code | 101 1, // DRAW_IMAGE - right after op code |
| 102 1, // DRAW_IMAGE_RECT_STRICT - right after op code | 102 1, // DRAW_IMAGE_RECT_STRICT - right after op code |
| 103 1, // DRAW_ATLAS - right after op code | 103 1, // DRAW_ATLAS - right after op code |
| 104 1, // DRAW_IMAGE_NINE - right after op code | 104 1, // DRAW_IMAGE_NINE - right after op code |
| 105 1, // DRAW_IMAGE_RECT - right after op code | 105 1, // DRAW_IMAGE_RECT - right after op code |
| 106 0, // SAVE_LAYER_SAVELAYERFLAGS - see below - this paint's location var
ies |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_i
n_sync"); | 109 static_assert(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, "need_to_be_i
n_sync"); |
| 109 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 110 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
| 110 | 111 |
| 111 int overflow = 0; | 112 int overflow = 0; |
| 112 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 113 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
| 113 // This op's size overflows so an extra uint32_t will be written | 114 // This op's size overflows so an extra uint32_t will be written |
| 114 // after the op code | 115 // after the op code |
| 115 overflow = sizeof(uint32_t); | 116 overflow = sizeof(uint32_t); |
| 116 } | 117 } |
| 117 | 118 |
| 118 if (SAVE_LAYER == op) { | 119 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != op); |
| 120 if (SAVE_LAYER_SAVELAYERFLAGS == op) { |
| 119 static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; | 121 static const uint32_t kSaveLayerNoBoundsPaintOffset = 2 * kUInt32Size; |
| 120 static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size
+ sizeof(SkRect); | 122 static const uint32_t kSaveLayerWithBoundsPaintOffset = 2 * kUInt32Size
+ sizeof(SkRect); |
| 121 | 123 |
| 122 if (kSaveLayerNoBoundsSize == opSize) { | 124 if (kSaveLayerNoBoundsSize == opSize) { |
| 123 return kSaveLayerNoBoundsPaintOffset + overflow; | 125 return kSaveLayerNoBoundsPaintOffset + overflow; |
| 124 } else { | 126 } else { |
| 125 SkASSERT(kSaveLayerWithBoundsSize == opSize); | 127 SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 126 return kSaveLayerWithBoundsPaintOffset + overflow; | 128 return kSaveLayerWithBoundsPaintOffset + overflow; |
| 127 } | 129 } |
| 128 } | 130 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 void SkPictureRecord::recordSave() { | 146 void SkPictureRecord::recordSave() { |
| 145 fContentInfo.onSave(); | 147 fContentInfo.onSave(); |
| 146 | 148 |
| 147 // op only | 149 // op only |
| 148 size_t size = kSaveSize; | 150 size_t size = kSaveSize; |
| 149 size_t initialOffset = this->addDraw(SAVE, &size); | 151 size_t initialOffset = this->addDraw(SAVE, &size); |
| 150 | 152 |
| 151 this->validate(initialOffset, size); | 153 this->validate(initialOffset, size); |
| 152 } | 154 } |
| 153 | 155 |
| 154 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, | 156 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 | 157 // record the offset to us, making it non-positive to distinguish a save |
| 157 // from a clip entry. | 158 // from a clip entry. |
| 158 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 159 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 159 this->recordSaveLayer(bounds, paint, flags); | 160 this->recordSaveLayer(rec); |
| 160 | 161 |
| 161 this->INHERITED::willSaveLayer(bounds, paint, flags); | 162 (void)this->INHERITED::getSaveLayerStrategy(rec); |
| 162 /* No need for a (potentially very big) layer which we don't actually need | 163 /* 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 | 164 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 | 165 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). | 166 than the size of the actual device we'll use during playback). |
| 166 */ | 167 */ |
| 167 return kNoLayer_SaveLayerStrategy; | 168 return kNoLayer_SaveLayerStrategy; |
| 168 } | 169 } |
| 169 | 170 |
| 170 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, | 171 void SkPictureRecord::recordSaveLayer(const SaveLayerRec& rec) { |
| 171 SaveFlags flags) { | |
| 172 fContentInfo.onSaveLayer(); | 172 fContentInfo.onSaveLayer(); |
| 173 | 173 |
| 174 // op + bool for 'bounds' | 174 // op + bool for 'bounds' |
| 175 size_t size = 2 * kUInt32Size; | 175 size_t size = 2 * kUInt32Size; |
| 176 if (bounds) { | 176 if (rec.fBounds) { |
| 177 size += sizeof(*bounds); // + rect | 177 size += sizeof(*rec.fBounds); // + rect |
| 178 } | 178 } |
| 179 // + paint index + flags | 179 // + paint index + flags |
| 180 size += 2 * kUInt32Size; | 180 size += 2 * kUInt32Size; |
| 181 | 181 |
| 182 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; | 182 SkASSERT(kSaveLayerNoBoundsSize == size || kSaveLayerWithBoundsSize == size)
; |
| 183 | 183 |
| 184 size_t initialOffset = this->addDraw(SAVE_LAYER, &size); | 184 size_t initialOffset = this->addDraw(SAVE_LAYER_SAVELAYERFLAGS, &size); |
| 185 this->addRectPtr(bounds); | 185 this->addRectPtr(rec.fBounds); |
| 186 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWr
itten()); | 186 SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER_SAVELAYERFLAGS, size) ==
fWriter.bytesWritten()); |
| 187 this->addPaintPtr(paint); | 187 this->addPaintPtr(rec.fPaint); |
| 188 this->addInt(flags); | 188 this->addInt(rec.fSaveLayerFlags); |
| 189 | 189 |
| 190 this->validate(initialOffset, size); | 190 this->validate(initialOffset, size); |
| 191 } | 191 } |
| 192 | 192 |
| 193 #ifdef SK_DEBUG | 193 #ifdef SK_DEBUG |
| 194 /* | 194 /* |
| 195 * Read the op code from 'offset' in 'writer' and extract the size too. | 195 * Read the op code from 'offset' in 'writer' and extract the size too. |
| 196 */ | 196 */ |
| 197 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { | 197 static DrawType peek_op_and_size(SkWriter32* writer, size_t offset, uint32_t* si
ze) { |
| 198 uint32_t peek = writer->readTAt<uint32_t>(offset); | 198 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); | 314 fWriter.overwriteTAt(offset, restoreOffset); |
| 315 offset = peek; | 315 offset = peek; |
| 316 } | 316 } |
| 317 | 317 |
| 318 #ifdef SK_DEBUG | 318 #ifdef SK_DEBUG |
| 319 // offset of 0 has been disabled, so we skip it | 319 // offset of 0 has been disabled, so we skip it |
| 320 if (offset > 0) { | 320 if (offset > 0) { |
| 321 // assert that the final offset value points to a save verb | 321 // assert that the final offset value points to a save verb |
| 322 uint32_t opSize; | 322 uint32_t opSize; |
| 323 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); | 323 DrawType drawOp = peek_op_and_size(&fWriter, -offset, &opSize); |
| 324 SkASSERT(SAVE == drawOp || SAVE_LAYER == drawOp); | 324 SkASSERT(SAVE_LAYER_SAVEFLAGS_DEPRECATED != drawOp); |
| 325 SkASSERT(SAVE == drawOp || SAVE_LAYER_SAVELAYERFLAGS == drawOp); |
| 325 } | 326 } |
| 326 #endif | 327 #endif |
| 327 } | 328 } |
| 328 | 329 |
| 329 void SkPictureRecord::beginRecording() { | 330 void SkPictureRecord::beginRecording() { |
| 330 // we have to call this *after* our constructor, to ensure that it gets | 331 // we have to call this *after* our constructor, to ensure that it gets |
| 331 // recorded. This is balanced by restoreToCount() call from endRecording, | 332 // recorded. This is balanced by restoreToCount() call from endRecording, |
| 332 // which in-turn calls our overridden restore(), so those get recorded too. | 333 // which in-turn calls our overridden restore(), so those get recorded too. |
| 333 fInitialSaveCount = this->save(); | 334 fInitialSaveCount = this->save(); |
| 334 } | 335 } |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1052 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 1052 int index = fTextBlobRefs.count(); | 1053 int index = fTextBlobRefs.count(); |
| 1053 *fTextBlobRefs.append() = blob; | 1054 *fTextBlobRefs.append() = blob; |
| 1054 blob->ref(); | 1055 blob->ref(); |
| 1055 // follow the convention of recording a 1-based index | 1056 // follow the convention of recording a 1-based index |
| 1056 this->addInt(index + 1); | 1057 this->addInt(index + 1); |
| 1057 } | 1058 } |
| 1058 | 1059 |
| 1059 /////////////////////////////////////////////////////////////////////////////// | 1060 /////////////////////////////////////////////////////////////////////////////// |
| 1060 | 1061 |
| OLD | NEW |