aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-09 16:03:55 +0000
committerGravatar junov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-09 16:03:55 +0000
commite3dbedb44cad6c7b7e5c9aae5224d0b0abec9bf4 (patch)
tree1d5769eb89cb752a3a76e41cd1c2fe9e3c98c196
parent2eb479555b351bc9c77feb3d0873856f7d365b74 (diff)
Refactoring code in SkPictureRecord that touches fRestoreOffsetStack
-rw-r--r--src/core/SkPictureRecord.cpp43
-rw-r--r--src/core/SkPictureRecord.h7
2 files changed, 26 insertions, 24 deletions
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index a499ee1904..a55c9afe9a 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -83,14 +83,8 @@ void SkPictureRecord::restore() {
return;
}
- // patch up the clip offsets
- uint32_t restoreOffset = (uint32_t)fWriter.size();
- uint32_t offset = fRestoreOffsetStack.top();
- while (offset) {
- uint32_t* peek = fWriter.peek32(offset);
- offset = *peek;
- *peek = restoreOffset;
- }
+ fillRestoreOffsetPlaceholdersForCurrentStackLevel(
+ (uint32_t)fWriter.size());
if (fRestoreOffsetStack.count() == fFirstSavedLayerIndex) {
fFirstSavedLayerIndex = kNoSavedLayerIndex;
@@ -166,21 +160,31 @@ static bool regionOpExpands(SkRegion::Op op) {
}
}
-void SkPictureRecord::recordOffsetForRestore(SkRegion::Op op) {
+void SkPictureRecord::fillRestoreOffsetPlaceholdersForCurrentStackLevel(
+ uint32_t restoreOffset) {
+ uint32_t offset = fRestoreOffsetStack.top();
+ while (offset) {
+ uint32_t* peek = fWriter.peek32(offset);
+ offset = *peek;
+ *peek = restoreOffset;
+ }
+}
+
+void SkPictureRecord::recordRestoreOffsetPlaceholder(SkRegion::Op op) {
if (regionOpExpands(op)) {
// Run back through any previous clip ops, and mark their offset to
// be 0, disabling their ability to trigger a jump-to-restore, otherwise
// they could hide this clips ability to expand the clip (i.e. go from
// empty to non-empty).
- uint32_t offset = fRestoreOffsetStack.top();
- while (offset) {
- uint32_t* peek = fWriter.peek32(offset);
- offset = *peek;
- *peek = 0;
- }
+ fillRestoreOffsetPlaceholdersForCurrentStackLevel(0);
}
size_t offset = fWriter.size();
+ // The RestoreOffset field is initially filled with a placeholder
+ // value that points to the offset of the previous RestoreOffset
+ // in the current stack level, thus forming a linked list so that
+ // the restore offsets can be filled in when the corresponding
+ // restore command is recorded.
addInt(fRestoreOffsetStack.top());
fRestoreOffsetStack.top() = offset;
}
@@ -189,8 +193,7 @@ bool SkPictureRecord::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
addDraw(CLIP_RECT);
addRect(rect);
addInt(ClipParams_pack(op, doAA));
-
- this->recordOffsetForRestore(op);
+ recordRestoreOffsetPlaceholder(op);
validate();
return this->INHERITED::clipRect(rect, op, doAA);
@@ -200,8 +203,7 @@ bool SkPictureRecord::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
addDraw(CLIP_PATH);
addPath(path);
addInt(ClipParams_pack(op, doAA));
-
- this->recordOffsetForRestore(op);
+ recordRestoreOffsetPlaceholder(op);
validate();
@@ -216,8 +218,7 @@ bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) {
addDraw(CLIP_REGION);
addRegion(region);
addInt(ClipParams_pack(op, false));
-
- this->recordOffsetForRestore(op);
+ recordRestoreOffsetPlaceholder(op);
validate();
return this->INHERITED::clipRegion(region, op);
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 4d0e96296f..7e5f086c7b 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -107,6 +107,10 @@ private:
}
};
+ void recordRestoreOffsetPlaceholder(SkRegion::Op);
+ void fillRestoreOffsetPlaceholdersForCurrentStackLevel(
+ uint32_t restoreOffset);
+
SkTDArray<uint32_t> fRestoreOffsetStack;
int fFirstSavedLayerIndex;
enum {
@@ -198,9 +202,6 @@ private:
uint32_t fRecordFlags;
- // helper function to handle save/restore culling offsets
- void recordOffsetForRestore(SkRegion::Op op);
-
friend class SkPicturePlayback;
friend class SkPictureTester; // for unit testing