| 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 "SkTSearch.h" | 9 #include "SkTSearch.h" |
| 10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 enum { | 27 enum { |
| 28 // just need a value that save or getSaveCount would never return | 28 // just need a value that save or getSaveCount would never return |
| 29 kNoInitialSave = -1, | 29 kNoInitialSave = -1, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et
c. | 32 // A lot of basic types get stored as a uint32_t: bools, ints, paint indices, et
c. |
| 33 static int const kUInt32Size = 4; | 33 static int const kUInt32Size = 4; |
| 34 | 34 |
| 35 static const uint32_t kSaveSize = 2 * kUInt32Size; | 35 static const uint32_t kSaveSize = kUInt32Size; |
| 36 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; | 36 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
| 37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); | 37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); |
| 38 | 38 |
| 39 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) | 39 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
| 40 : INHERITED(dimensions.width(), dimensions.height()) | 40 : INHERITED(dimensions.width(), dimensions.height()) |
| 41 , fBoundingHierarchy(NULL) | 41 , fBoundingHierarchy(NULL) |
| 42 , fStateTree(NULL) | 42 , fStateTree(NULL) |
| 43 , fFlattenableHeap(HEAP_BLOCK_SIZE) | 43 , fFlattenableHeap(HEAP_BLOCK_SIZE) |
| 44 , fPaints(&fFlattenableHeap) | 44 , fPaints(&fFlattenableHeap) |
| 45 , fRecordFlags(flags) | 45 , fRecordFlags(flags) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } else { | 144 } else { |
| 145 SkASSERT(kSaveLayerWithBoundsSize == opSize); | 145 SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 146 return kSaveLayerWithBoundsPaintOffset + overflow; | 146 return kSaveLayerWithBoundsPaintOffset + overflow; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth
od | 150 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth
od |
| 151 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; | 151 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void SkPictureRecord::willSave(SaveFlags flags) { | 154 void SkPictureRecord::willSave() { |
| 155 | 155 |
| 156 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 156 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 157 fMCMgr.save(flags); | 157 fMCMgr.save(); |
| 158 #else | 158 #else |
| 159 // record the offset to us, making it non-positive to distinguish a save | 159 // record the offset to us, making it non-positive to distinguish a save |
| 160 // from a clip entry. | 160 // from a clip entry. |
| 161 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 161 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 162 this->recordSave(flags); | 162 this->recordSave(); |
| 163 #endif | 163 #endif |
| 164 | 164 |
| 165 this->INHERITED::willSave(flags); | 165 this->INHERITED::willSave(); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void SkPictureRecord::recordSave(SaveFlags flags) { | 168 void SkPictureRecord::recordSave() { |
| 169 // op + flags | 169 // op only |
| 170 size_t size = kSaveSize; | 170 size_t size = kSaveSize; |
| 171 size_t initialOffset = this->addDraw(SAVE, &size); | 171 size_t initialOffset = this->addDraw(SAVE, &size); |
| 172 this->addInt(flags); | |
| 173 | 172 |
| 174 this->validate(initialOffset, size); | 173 this->validate(initialOffset, size); |
| 175 } | 174 } |
| 176 | 175 |
| 177 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, | 176 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, |
| 178 const SkPaint* paint,
SaveFlags flags) { | 177 const SkPaint* paint,
SaveFlags flags) { |
| 179 | 178 |
| 180 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 179 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 181 fMCMgr.saveLayer(bounds, paint, flags); | 180 fMCMgr.saveLayer(bounds, paint, flags); |
| 182 #else | 181 #else |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 offset = -offset; | 509 offset = -offset; |
| 511 uint32_t opSize; | 510 uint32_t opSize; |
| 512 DrawType op = peek_op_and_size(writer, offset, &opSize); | 511 DrawType op = peek_op_and_size(writer, offset, &opSize); |
| 513 if (SAVE_LAYER == op) { | 512 if (SAVE_LAYER == op) { |
| 514 // not ready to cull these out yet (mrr) | 513 // not ready to cull these out yet (mrr) |
| 515 return false; | 514 return false; |
| 516 } | 515 } |
| 517 SkASSERT(SAVE == op); | 516 SkASSERT(SAVE == op); |
| 518 SkASSERT(kSaveSize == opSize); | 517 SkASSERT(kSaveSize == opSize); |
| 519 | 518 |
| 520 // get the save flag (last 4-bytes of the space allocated for the opSize) | |
| 521 SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags) writer->readTAt<uint32
_t>(offset + 4); | |
| 522 if (SkCanvas::kMatrixClip_SaveFlag != saveFlags) { | |
| 523 // This function's optimization is only correct for kMatrixClip style sa
ves. | |
| 524 // TODO: set checkMatrix & checkClip booleans here and then check for th
e | |
| 525 // offending operations in the following loop. | |
| 526 return false; | |
| 527 } | |
| 528 | |
| 529 // Walk forward until we get back to either a draw-verb (abort) or we hit | 519 // Walk forward until we get back to either a draw-verb (abort) or we hit |
| 530 // our restore (success). | 520 // our restore (success). |
| 531 int32_t saveOffset = offset; | 521 int32_t saveOffset = offset; |
| 532 | 522 |
| 533 offset += opSize; | 523 offset += opSize; |
| 534 while (offset < restoreOffset) { | 524 while (offset < restoreOffset) { |
| 535 op = peek_op_and_size(writer, offset, &opSize); | 525 op = peek_op_and_size(writer, offset, &opSize); |
| 536 if (is_drawing_op(op) || (SAVE_LAYER == op)) { | 526 if (is_drawing_op(op) || (SAVE_LAYER == op)) { |
| 537 // drawing verb, abort | 527 // drawing verb, abort |
| 538 return false; | 528 return false; |
| (...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 void SkPictureRecord::validateRegions() const { | 1822 void SkPictureRecord::validateRegions() const { |
| 1833 int count = fRegions.count(); | 1823 int count = fRegions.count(); |
| 1834 SkASSERT((unsigned) count < 0x1000); | 1824 SkASSERT((unsigned) count < 0x1000); |
| 1835 for (int index = 0; index < count; index++) { | 1825 for (int index = 0; index < count; index++) { |
| 1836 const SkFlatData* region = fRegions[index]; | 1826 const SkFlatData* region = fRegions[index]; |
| 1837 SkASSERT(region); | 1827 SkASSERT(region); |
| 1838 // region->validate(); | 1828 // region->validate(); |
| 1839 } | 1829 } |
| 1840 } | 1830 } |
| 1841 #endif | 1831 #endif |
| OLD | NEW |