| 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 void SkPictureRecord::onSave(SaveFlags flags) { | 149 int SkPictureRecord::save(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 | 159 return this->INHERITED::save(flags); |
| 160 this->INHERITED::onSave(flags); | |
| 161 } | 160 } |
| 162 | 161 |
| 163 void SkPictureRecord::recordSave(SaveFlags flags) { | 162 void SkPictureRecord::recordSave(SaveFlags flags) { |
| 164 // op + flags | 163 // op + flags |
| 165 uint32_t size = kSaveSize; | 164 uint32_t size = kSaveSize; |
| 166 size_t initialOffset = this->addDraw(SAVE, &size); | 165 size_t initialOffset = this->addDraw(SAVE, &size); |
| 167 this->addInt(flags); | 166 this->addInt(flags); |
| 168 | 167 |
| 169 this->validate(initialOffset, size); | 168 this->validate(initialOffset, size); |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool SkPictureRecord::onSaveLayer(const SkRect* bounds, const SkPaint* paint, | 171 int SkPictureRecord::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 173 SaveFlags flags) { | 172 SaveFlags flags) { |
| 174 | 173 |
| 174 int count; |
| 175 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 175 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 176 fMCMgr.saveLayer(bounds, paint, flags); | 176 count = 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 this->INHERITED::onSaveLayer(bounds, paint, flags); | 187 /* Don't actually call INHERITED::saveLayer, because that will try to alloc
ate |
| 188 /* No need for a (potentially very big) layer which we don't actually need | 188 an offscreen device (potentially very big) 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 return false; | 193 count = this->INHERITED::save(flags); |
| 194 this->clipRectBounds(bounds, flags, NULL); |
| 195 return count; |
| 194 } | 196 } |
| 195 | 197 |
| 196 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, | 198 void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
, |
| 197 SaveFlags flags) { | 199 SaveFlags flags) { |
| 198 // op + bool for 'bounds' | 200 // op + bool for 'bounds' |
| 199 uint32_t size = 2 * kUInt32Size; | 201 uint32_t size = 2 * kUInt32Size; |
| 200 if (NULL != bounds) { | 202 if (NULL != bounds) { |
| 201 size += sizeof(*bounds); // + rect | 203 size += sizeof(*bounds); // + rect |
| 202 } | 204 } |
| 203 // + paint index + flags | 205 // + paint index + flags |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 } | 598 } |
| 597 // Note: No need to touch the state tree for this to work correctly. | 599 // Note: No need to touch the state tree for this to work correctly. |
| 598 // Unused branches do not burden the playback, and pruning the tree | 600 // Unused branches do not burden the playback, and pruning the tree |
| 599 // would be O(N^2), so it is best to leave it alone. | 601 // would be O(N^2), so it is best to leave it alone. |
| 600 break; | 602 break; |
| 601 default: | 603 default: |
| 602 SkASSERT(0); | 604 SkASSERT(0); |
| 603 } | 605 } |
| 604 } | 606 } |
| 605 | 607 |
| 606 void SkPictureRecord::onRestore() { | 608 void SkPictureRecord::restore() { |
| 607 // FIXME: SkDeferredCanvas needs to be refactored to respect | 609 // FIXME: SkDeferredCanvas needs to be refactored to respect |
| 608 // save/restore balancing so that the following test can be | 610 // save/restore balancing so that the following test can be |
| 609 // turned on permanently. | 611 // turned on permanently. |
| 610 #if 0 | 612 #if 0 |
| 611 SkASSERT(fRestoreOffsetStack.count() > 1); | 613 SkASSERT(fRestoreOffsetStack.count() > 1); |
| 612 #endif | 614 #endif |
| 613 | 615 |
| 614 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 616 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 615 if (fMCMgr.getSaveCount() == 1) { | 617 if (fMCMgr.getSaveCount() == 1) { |
| 616 return; | 618 return; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 644 } | 646 } |
| 645 | 647 |
| 646 if (!fOptsEnabled || SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { | 648 if (!fOptsEnabled || SK_ARRAY_COUNT(gPictureRecordOpts) == opt) { |
| 647 // No optimization fired so add the RESTORE | 649 // No optimization fired so add the RESTORE |
| 648 this->recordRestore(); | 650 this->recordRestore(); |
| 649 } | 651 } |
| 650 | 652 |
| 651 fRestoreOffsetStack.pop(); | 653 fRestoreOffsetStack.pop(); |
| 652 #endif | 654 #endif |
| 653 | 655 |
| 654 this->INHERITED::onRestore(); | 656 return this->INHERITED::restore(); |
| 655 } | 657 } |
| 656 | 658 |
| 657 void SkPictureRecord::recordRestore(bool fillInSkips) { | 659 void SkPictureRecord::recordRestore(bool fillInSkips) { |
| 658 uint32_t initialOffset, size; | 660 uint32_t initialOffset, size; |
| 659 if (fillInSkips) { | 661 if (fillInSkips) { |
| 660 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite
r.bytesWritten()); | 662 this->fillRestoreOffsetPlaceholdersForCurrentStackLevel((uint32_t)fWrite
r.bytesWritten()); |
| 661 } | 663 } |
| 662 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code | 664 size = 1 * kUInt32Size; // RESTORE consists solely of 1 op code |
| 663 initialOffset = this->addDraw(RESTORE, &size); | 665 initialOffset = this->addDraw(RESTORE, &size); |
| 664 this->validate(initialOffset, size); | 666 this->validate(initialOffset, size); |
| (...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 void SkPictureRecord::validateRegions() const { | 1886 void SkPictureRecord::validateRegions() const { |
| 1885 int count = fRegions.count(); | 1887 int count = fRegions.count(); |
| 1886 SkASSERT((unsigned) count < 0x1000); | 1888 SkASSERT((unsigned) count < 0x1000); |
| 1887 for (int index = 0; index < count; index++) { | 1889 for (int index = 0; index < count; index++) { |
| 1888 const SkFlatData* region = fRegions[index]; | 1890 const SkFlatData* region = fRegions[index]; |
| 1889 SkASSERT(region); | 1891 SkASSERT(region); |
| 1890 // region->validate(); | 1892 // region->validate(); |
| 1891 } | 1893 } |
| 1892 } | 1894 } |
| 1893 #endif | 1895 #endif |
| OLD | NEW |