Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: src/gpu/GrReducedClip.cpp

Issue 48593003: Avoid re-rendering stencil clip for every draw with reducable clip stack (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrReducedClip.h" 9 #include "GrReducedClip.h"
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 if (NULL != requiresAA) { 64 if (NULL != requiresAA) {
65 *requiresAA = false; 65 *requiresAA = false;
66 } 66 }
67 } else if (isectRect.intersect(stackBounds, scalarQueryBounds)) { 67 } else if (isectRect.intersect(stackBounds, scalarQueryBounds)) {
68 if (NULL != tighterBounds) { 68 if (NULL != tighterBounds) {
69 isectRect.roundOut(tighterBounds); 69 isectRect.roundOut(tighterBounds);
70 SkRect scalarTighterBounds = SkRect::MakeFromIRect(*tighterBound s); 70 SkRect scalarTighterBounds = SkRect::MakeFromIRect(*tighterBound s);
71 if (scalarTighterBounds == isectRect) { 71 if (scalarTighterBounds == isectRect) {
72 // the round-out didn't add any area outside the clip rect. 72 // the round-out didn't add any area outside the clip rect.
73 *requiresAA = false; 73 if (NULL != requiresAA) {
74 *requiresAA = false;
75 }
74 *initialState = kAllIn_InitialState; 76 *initialState = kAllIn_InitialState;
75 return; 77 return;
76 } 78 }
77 *initialState = kAllOut_InitialState; 79 *initialState = kAllOut_InitialState;
78 // iior should only be true if aa/non-aa status matches among al l elements. 80 // iior should only be true if aa/non-aa status matches among al l elements.
79 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart) ; 81 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart) ;
80 bool doAA = iter.prev()->isAA(); 82 bool doAA = iter.prev()->isAA();
81 SkNEW_INSERT_AT_LLIST_HEAD(result, Element, (isectRect, SkRegion ::kReplace_Op, doAA)); 83 // The clip established by the element list might be cached base d on the last
84 // generation id. Without walking the stack, we do not knoow wha t was the generation
85 // id that lead to this state. Make a conservative guess.
86 SkNEW_INSERT_AT_LLIST_HEAD(result, Element, (isectRect, SkRegion ::kReplace_Op, doAA,
bsalomon 2013/10/30 14:25:59 Rather than assigning a genID to the manufactured
Kimmo Kinnunen 2013/11/01 12:12:20 Done.
87 stack.getTopmostGen ID()));
88
82 if (NULL != requiresAA) { 89 if (NULL != requiresAA) {
83 *requiresAA = doAA; 90 *requiresAA = doAA;
84 } 91 }
85 } 92 }
86 } else { 93 } else {
87 *initialState = kAllOut_InitialState; 94 *initialState = kAllOut_InitialState;
88 if (NULL != requiresAA) { 95 if (NULL != requiresAA) {
89 *requiresAA = false; 96 *requiresAA = false;
90 } 97 }
91 } 98 }
(...skipping 25 matching lines...) Expand all
117 *tighterBounds = queryBounds; 124 *tighterBounds = queryBounds;
118 } 125 }
119 } 126 }
120 } 127 }
121 128
122 SkRect scalarBounds = SkRect::MakeFromIRect(*bounds); 129 SkRect scalarBounds = SkRect::MakeFromIRect(*bounds);
123 130
124 // Now that we have determined the bounds to use and filtered out the trivia l cases, call the 131 // Now that we have determined the bounds to use and filtered out the trivia l cases, call the
125 // helper that actually walks the stack. 132 // helper that actually walks the stack.
126 reduced_stack_walker(stack, scalarBounds, result, initialState, requiresAA); 133 reduced_stack_walker(stack, scalarBounds, result, initialState, requiresAA);
134
135 // The list that was computed in this function may be cached based on the ge n id of the last
136 // element.
137 SkASSERT(0 == result->count() || SkClipStack::kInvalidGenID != result->tail ()->getGenID());
127 } 138 }
128 139
129 void reduced_stack_walker(const SkClipStack& stack, 140 void reduced_stack_walker(const SkClipStack& stack,
130 const SkRect& queryBounds, 141 const SkRect& queryBounds,
131 ElementList* result, 142 ElementList* result,
132 InitialState* initialState, 143 InitialState* initialState,
133 bool* requiresAA) { 144 bool* requiresAA) {
134 145
135 // walk backwards until we get to: 146 // walk backwards until we get to:
136 // a) the beginning 147 // a) the beginning
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 SkDEBUGFAIL("Unexpected op."); 322 SkDEBUGFAIL("Unexpected op.");
312 break; 323 break;
313 } 324 }
314 if (!skippable) { 325 if (!skippable) {
315 // if it is a flip, change it to a bounds-filling rect 326 // if it is a flip, change it to a bounds-filling rect
316 if (isFlip) { 327 if (isFlip) {
317 SkASSERT(SkRegion::kXOR_Op == element->getOp() || 328 SkASSERT(SkRegion::kXOR_Op == element->getOp() ||
318 SkRegion::kReverseDifference_Op == element->getOp()); 329 SkRegion::kReverseDifference_Op == element->getOp());
319 SkNEW_INSERT_AT_LLIST_HEAD(result, 330 SkNEW_INSERT_AT_LLIST_HEAD(result,
320 Element, 331 Element,
321 (queryBounds, SkRegion::kReverseDiffe rence_Op, false)); 332 (queryBounds, SkRegion::kReverseDiffe rence_Op, false, element->getGenID()));
322 } else { 333 } else {
323 Element* newElement = result->addToHead(*element); 334 Element* newElement = result->addToHead(*element);
324 if (newElement->isAA()) { 335 if (newElement->isAA()) {
325 ++numAAElements; 336 ++numAAElements;
326 } 337 }
327 // Intersecting an inverse shape is the same as differencing the non-inverse shape. 338 // Intersecting an inverse shape is the same as differencing the non-inverse shape.
328 // Replacing with an inverse shape is the same as setting initia lState=kAllIn and 339 // Replacing with an inverse shape is the same as setting initia lState=kAllIn and
329 // differencing the non-inverse shape. 340 // differencing the non-inverse shape.
330 bool isReplace = SkRegion::kReplace_Op == newElement->getOp(); 341 bool isReplace = SkRegion::kReplace_Op == newElement->getOp();
331 if (newElement->isInverseFilled() && 342 if (newElement->isInverseFilled() &&
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 result->popHead(); 423 result->popHead();
413 element = result->headIter().get(); 424 element = result->headIter().get();
414 } 425 }
415 } 426 }
416 } 427 }
417 if (NULL != requiresAA) { 428 if (NULL != requiresAA) {
418 *requiresAA = numAAElements > 0; 429 *requiresAA = numAAElements > 0;
419 } 430 }
420 } 431 }
421 } // namespace GrReducedClip 432 } // namespace GrReducedClip
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698