| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } else { | 139 } else { |
| 140 SkASSERT(kSaveLayerWithBoundsSize == opSize); | 140 SkASSERT(kSaveLayerWithBoundsSize == opSize); |
| 141 return kSaveLayerWithBoundsPaintOffset + overflow; | 141 return kSaveLayerWithBoundsPaintOffset + overflow; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth
od | 145 SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this meth
od |
| 146 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; | 146 return gPaintOffsets[op] * sizeof(uint32_t) + overflow; |
| 147 } | 147 } |
| 148 | 148 |
| 149 int SkPictureRecord::save(SaveFlags flags) { | 149 void SkPictureRecord::willSave(SaveFlags flags) { |
| 150 | 150 |
| 151 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 151 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 152 fMCMgr.save(flags); | 152 fMCMgr.save(flags); |
| 153 #else | 153 #else |
| 154 // record the offset to us, making it non-positive to distinguish a save | 154 // record the offset to us, making it non-positive to distinguish a save |
| 155 // from a clip entry. | 155 // from a clip entry. |
| 156 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 156 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 157 this->recordSave(flags); | 157 this->recordSave(flags); |
| 158 #endif | 158 #endif |
| 159 return this->INHERITED::save(flags); | 159 |
| 160 this->INHERITED::willSave(flags); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void SkPictureRecord::recordSave(SaveFlags flags) { | 163 void SkPictureRecord::recordSave(SaveFlags flags) { |
| 163 // op + flags | 164 // op + flags |
| 164 uint32_t size = kSaveSize; | 165 uint32_t size = kSaveSize; |
| 165 size_t initialOffset = this->addDraw(SAVE, &size); | 166 size_t initialOffset = this->addDraw(SAVE, &size); |
| 166 this->addInt(flags); | 167 this->addInt(flags); |
| 167 | 168 |
| 168 this->validate(initialOffset, size); | 169 this->validate(initialOffset, size); |
| 169 } | 170 } |
| 170 | 171 |
| 171 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, | 172 SkCanvas::SaveLayerStrategy SkPictureRecord::willSaveLayer(const SkRect* bounds, |
| 172 SaveFlags flags) { | 173 const SkPaint* paint,
SaveFlags flags) { |
| 173 | 174 |
| 174 int count; | |
| 175 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 175 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 176 count = fMCMgr.saveLayer(bounds, paint, flags); | 176 fMCMgr.saveLayer(bounds, paint, flags); |
| 177 #else | 177 #else |
| 178 // record the offset to us, making it non-positive to distinguish a save | 178 // record the offset to us, making it non-positive to distinguish a save |
| 179 // from a clip entry. | 179 // from a clip entry. |
| 180 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); | 180 fRestoreOffsetStack.push(-(int32_t)fWriter.bytesWritten()); |
| 181 this->recordSaveLayer(bounds, paint, flags); | 181 this->recordSaveLayer(bounds, paint, flags); |
| 182 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { | 182 if (kNoSavedLayerIndex == fFirstSavedLayerIndex) { |
| 183 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); | 183 fFirstSavedLayerIndex = fRestoreOffsetStack.count(); |
| 184 } | 184 } |
| 185 #endif | 185 #endif |
| 186 | 186 |
| 187 /* Don't actually call INHERITED::saveLayer, because that will try to alloc
ate | 187 this->INHERITED::willSaveLayer(bounds, paint, flags); |
| 188 an offscreen device (potentially very big) which we don't actually need | 188 /* No need for a (potentially very big) layer which we don't actually need |
| 189 at this time (and may not be able to afford since during record our | 189 at this time (and may not be able to afford since during record our |
| 190 clip starts out the size of the picture, which is often much larger | 190 clip starts out the size of the picture, which is often much larger |
| 191 than the size of the actual device we'll use during playback). | 191 than the size of the actual device we'll use during playback). |
| 192 */ | 192 */ |
| 193 count = this->INHERITED::save(flags); | 193 return kNoLayer_SaveLayerStrategy; |
| 194 this->clipRectBounds(bounds, flags, NULL); | |
| 195 return count; | |
| 196 } | 194 } |
| 197 | 195 |
| 198 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, | 196 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, |
| 199 SaveFlags flags) { | 197 SaveFlags flags) { |
| 200 // op + bool for 'bounds' | 198 // op + bool for 'bounds' |
| 201 uint32_t size = 2 * kUInt32Size; | 199 uint32_t size = 2 * kUInt32Size; |
| 202 if (NULL != bounds) { | 200 if (NULL != bounds) { |
| 203 size += sizeof(*bounds); // + rect | 201 size += sizeof(*bounds); // + rect |
| 204 } | 202 } |
| 205 // + paint index + flags | 203 // + paint index + flags |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 596 } |
| 599 // Note: No need to touch the state tree for this to work correctly. | 597 // Note: No need to touch the state tree for this to work correctly. |
| 600 // Unused branches do not burden the playback, and pruning the tree | 598 // Unused branches do not burden the playback, and pruning the tree |
| 601 // would be O(N^2), so it is best to leave it alone. | 599 // would be O(N^2), so it is best to leave it alone. |
| 602 break; | 600 break; |
| 603 default: | 601 default: |
| 604 SkASSERT(0); | 602 SkASSERT(0); |
| 605 } | 603 } |
| 606 } | 604 } |
| 607 | 605 |
| 608 void SkPictureRecord::restore() { | 606 void SkPictureRecord::willRestore() { |
| 609 // FIXME: SkDeferredCanvas needs to be refactored to respect | 607 // FIXME: SkDeferredCanvas needs to be refactored to respect |
| 610 // save/restore balancing so that the following test can be | 608 // save/restore balancing so that the following test can be |
| 611 // turned on permanently. | 609 // turned on permanently. |
| 612 #if 0 | 610 #if 0 |
| 613 SkASSERT(fRestoreOffsetStack.count() > 1); | 611 SkASSERT(fRestoreOffsetStack.count() > 1); |
| 614 #endif | 612 #endif |
| 615 | 613 |
| 616 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 614 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 617 if (fMCMgr.getSaveCount() == 1) { | 615 if (fMCMgr.getSaveCount() == 1) { |
| 618 return; | 616 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 646 } | 644 } |
| 647 | 645 |
| 648 if (!fOptsEnabled || SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { | 646 if (!fOptsEnabled || SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { |
| 649 // No optimization fired so add the RESTORE | 647 // No optimization fired so add the RESTORE |
| 650 this->recordRestore(); | 648 this->recordRestore(); |
| 651 } | 649 } |
| 652 | 650 |
| 653 fRestoreOffsetStack.pop(); | 651 fRestoreOffsetStack.pop(); |
| 654 #endif | 652 #endif |
| 655 | 653 |
| 656 return this->INHERITED::restore(); | 654 this->INHERITED::willRestore(); |
| 657 } | 655 } |
| 658 | 656 |
| 659 void SkPictureRecord::recordRestore(bool fillInSkips) { | 657 void SkPictureRecord::recordRestore(bool fillInSkips) { |
| 660 uint32_t initialOffset, size; | 658 uint32_t initialOffset, size; |
| 661 if (fillInSkips) { | 659 if (fillInSkips) { |
| 662 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite
r.bytesWritten()); | 660 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite
r.bytesWritten()); |
| 663 } | 661 } |
| 664 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code | 662 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 665 initialOffset = this->addDraw(RESTORE, &size); | 663 initialOffset = this->addDraw(RESTORE, &size); |
| 666 this->validate(initialOffset, size); | 664 this->validate(initialOffset, size); |
| (...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 void SkPictureRecord::validateRegions() const { | 1884 void SkPictureRecord::validateRegions() const { |
| 1887 int count = fRegions.count(); | 1885 int count = fRegions.count(); |
| 1888 SkASSERT((unsigned) count < 0x1000); | 1886 SkASSERT((unsigned) count < 0x1000); |
| 1889 for (int index = 0; index < count; index++) { | 1887 for (int index = 0; index < count; index++) { |
| 1890 const SkFlatData* region = fRegions[index]; | 1888 const SkFlatData* region = fRegions[index]; |
| 1891 SkASSERT(region); | 1889 SkASSERT(region); |
| 1892 // region->validate(); | 1890 // region->validate(); |
| 1893 } | 1891 } |
| 1894 } | 1892 } |
| 1895 #endif | 1893 #endif |
| OLD | NEW |