aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrReducedClip.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-01 15:24:20 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-01 15:24:20 +0000
commit679eb674fc064993d534df4d48a4ddaff4e33e06 (patch)
treed687e47c032e2b8f17693bdef8350035744586dd /src/gpu/GrReducedClip.cpp
parent5c8ee2539b9316b22416a991a1f560ef5cec7957 (diff)
Avoid re-rendering stencil clip for every draw with reducable clip stack
Fixes the cases where clip stack reduction would cause clip to be re-rendered to stencil for each draw call. This causes unneeded slowdown. Stencil cache would not be used because the clip stack generation id communicated by the clip stack element list would be invalid. This happended due to a) clip stack reduction creating new elements in the element list. b) purging logic removing the generation id, but reduction logic selecting already purged element, and thus the generation id, as the representative state of the clip. Cases of a) where reduction would flatten the stack to a single new element were fixed by assigning the generation id of the top-most element of the clip stack as the generation id of the new element. This is not strictly minimal, but enables more caching than using invalid id. Cases of a) where reduction would substitute a stack element with a new element the generation id of the substituted element is used. The b) part was fixed by removing the purging logic. It was not exactly correct, as the previously purged states were actually used. The purging was not used for anything. Changes SkClipStack API to highlight that invalid generation id is never returned by SkClipStack. Empty stacks are wide open. Changes the clients to reflect this. Fixes a crash when not passing anti-alias out parameter to GrReducedClip::ReduceClipStack. The crash is not exercised in the current code. R=bsalomon@google.com, robertphillips@google.com Author: kkinnunen@nvidia.com Review URL: https://codereview.chromium.org/48593003 git-svn-id: http://skia.googlecode.com/svn/trunk@12084 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrReducedClip.cpp')
-rw-r--r--src/gpu/GrReducedClip.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/gpu/GrReducedClip.cpp b/src/gpu/GrReducedClip.cpp
index a5f4519ea7..8480e041b8 100644
--- a/src/gpu/GrReducedClip.cpp
+++ b/src/gpu/GrReducedClip.cpp
@@ -17,6 +17,7 @@ namespace GrReducedClip {
void reduced_stack_walker(const SkClipStack& stack,
const SkRect& queryBounds,
ElementList* result,
+ int32_t* resultGenID,
InitialState* initialState,
bool* requiresAA);
@@ -30,11 +31,17 @@ take a rect in case the caller knows a bound on what is to be drawn through this
void ReduceClipStack(const SkClipStack& stack,
const SkIRect& queryBounds,
ElementList* result,
+ int32_t* resultGenID,
InitialState* initialState,
SkIRect* tighterBounds,
bool* requiresAA) {
result->reset();
+ // The clip established by the element list might be cached based on the last
+ // generation id. When we make early returns, we do not know what was the generation
+ // id that lead to the state. Make a conservative guess.
+ *resultGenID = stack.getTopmostGenID();
+
if (stack.isWideOpen()) {
*initialState = kAllIn_InitialState;
return;
@@ -70,7 +77,9 @@ void ReduceClipStack(const SkClipStack& stack,
SkRect scalarTighterBounds = SkRect::Make(*tighterBounds);
if (scalarTighterBounds == isectRect) {
// the round-out didn't add any area outside the clip rect.
- *requiresAA = false;
+ if (NULL != requiresAA) {
+ *requiresAA = false;
+ }
*initialState = kAllIn_InitialState;
return;
}
@@ -123,12 +132,17 @@ void ReduceClipStack(const SkClipStack& stack,
// Now that we have determined the bounds to use and filtered out the trivial cases, call the
// helper that actually walks the stack.
- reduced_stack_walker(stack, scalarBounds, result, initialState, requiresAA);
+ reduced_stack_walker(stack, scalarBounds, result, resultGenID, initialState, requiresAA);
+
+ // The list that was computed in this function may be cached based on the gen id of the last
+ // element.
+ SkASSERT(SkClipStack::kInvalidGenID != *resultGenID);
}
void reduced_stack_walker(const SkClipStack& stack,
const SkRect& queryBounds,
ElementList* result,
+ int32_t* resultGenID,
InitialState* initialState,
bool* requiresAA) {
@@ -312,6 +326,11 @@ void reduced_stack_walker(const SkClipStack& stack,
break;
}
if (!skippable) {
+ if (0 == result->count()) {
+ // This will be the last element. Record the stricter genID.
+ *resultGenID = element->getGenID();
+ }
+
// if it is a flip, change it to a bounds-filling rect
if (isFlip) {
SkASSERT(SkRegion::kXOR_Op == element->getOp() ||
@@ -417,5 +436,13 @@ void reduced_stack_walker(const SkClipStack& stack,
if (NULL != requiresAA) {
*requiresAA = numAAElements > 0;
}
+
+ if (0 == result->count()) {
+ if (*initialState == kAllIn_InitialState) {
+ *resultGenID = SkClipStack::kWideOpenGenID;
+ } else {
+ *resultGenID = SkClipStack::kEmptyGenID;
+ }
+ }
}
} // namespace GrReducedClip