blob: ce520e7fc0d18a798c7eb6fe0ff9ad2d138255cf [file] [log] [blame]
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "GrClipMaskManager.h"
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +000010#include "effects/GrTextureDomainEffect.h"
robertphillips@google.com1e945b72012-04-16 18:03:03 +000011#include "GrGpu.h"
12#include "GrRenderTarget.h"
13#include "GrStencilBuffer.h"
14#include "GrPathRenderer.h"
robertphillips@google.coma72eef32012-05-01 17:22:59 +000015#include "GrPaint.h"
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +000016#include "SkRasterClip.h"
robertphillips@google.comfa662942012-05-17 12:20:22 +000017#include "GrAAConvexPathRenderer.h"
18#include "GrAAHairLinePathRenderer.h"
robertphillips@google.com58b20212012-06-27 20:44:52 +000019#include "GrSWMaskHelper.h"
robertphillips@google.com46a86002012-08-08 10:42:44 +000020#include "GrCacheID.h"
21
22GR_DEFINE_RESOURCE_CACHE_DOMAIN(GrClipMaskManager, GetAlphaMaskDomain)
robertphillips@google.coma72eef32012-05-01 17:22:59 +000023
robertphillips@google.comba998f22012-10-12 11:33:56 +000024#define GR_AA_CLIP 1
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +000025#define GR_SW_CLIP 1
robertphillips@google.coma72eef32012-05-01 17:22:59 +000026
robertphillips@google.comf294b772012-04-27 14:29:26 +000027////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com51a62862012-11-26 21:19:43 +000028
29namespace GrReducedClip {
30
31/*
32There are plenty of optimizations that could be added here. For example we could consider
33checking for cases where an inverse path can be changed to a regular fill with a different op.
34(e.g. [kIntersect, inverse path] -> [kDifference, path]). Maybe flips could be folded into
35earlier operations. Or would inserting flips and reversing earlier ops ever be a win? Perhaps
36for the case where the bounds are kInsideOut_BoundsType. We could restrict earlier operations
37based on later intersect operations, and perhaps remove intersect-rects. We could optionally
38take a rect in case the caller knows a bound on what is to be drawn through this clip.
39*/
40void GrReduceClipStack(const SkClipStack& stack,
41 SkTDArray<SkClipStack::Iter::Clip>* resultClips,
42 SkRect* resultBounds,
43 bool* resultsAreBounded,
44 InitialState* initialState) {
45 resultClips->reset();
46
47 if (stack.isWideOpen()) {
48 *initialState = kAllIn_InitialState;
49 *resultsAreBounded = false;
50 return;
51 }
52
53 SkClipStack::BoundsType type;
54 bool iior;
55 stack.getBounds(resultBounds, &type, &iior);
56 if (iior) {
57 *resultsAreBounded = true;
58 *initialState = kAllOut_InitialState;
59 SkClipStack::Iter::Clip* clip = resultClips->append();
60 // append doesn't call the default cons.
61 *clip = SkClipStack::Iter::Clip();
62
63 // iior should only be true if aa/non-aa status matches.
64 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
65 clip->fDoAA = iter.prev()->fDoAA;
66 clip->fOp = SkRegion::kReplace_Op;
67 clip->fRect = resultBounds;
68 return;
69 }
70
71 *resultsAreBounded = SkClipStack::kNormal_BoundsType == type && !resultBounds->isEmpty();
72
73 // walk backwards until we get to:
74 // a) the beginning
75 // b) an operation that is known to make the bounds all inside/outside
76 // c) a replace operation
77
78 static const InitialState kUnknown_InitialState = static_cast<InitialState>(-1);
79 *initialState = kUnknown_InitialState;
80
81 // During our backwards walk, track whether we've seen ops that either grow or shrink the clip.
82 // TODO: track these per saved clip so that we can consider them on the forward pass.
83 bool embiggens = false;
84 bool emsmallens = false;
85
86 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
87 while ((kUnknown_InitialState == *initialState)) {
88 const SkClipStack::Iter::Clip* clip = iter.prev();
89 if (NULL == clip) {
90 *initialState = kAllIn_InitialState;
91 break;
92 }
93 if (!embiggens && SkClipStack::kEmptyGenID == clip->fGenID) {
94 *initialState = kAllOut_InitialState;
95 break;
96 }
97 if (!emsmallens && SkClipStack::kWideOpenGenID == clip->fGenID) {
98 *initialState = kAllIn_InitialState;
99 break;
100 }
101
102 bool skippable = false;
103 bool isFlip = false; // does this op just flip the in/out state of every point in the bounds
104
105 switch (clip->fOp) {
106 case SkRegion::kDifference_Op:
107 if (*resultsAreBounded) {
108 // check if the shape subtracted either contains the entire bounds (and makes
109 // the clip empty) or is outside the bounds and therefore can be skipped.
110 if (clip->isInverseFilled()) {
111 if (clip->contains(*resultBounds)) {
112 skippable = true;
113 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
114 *initialState = kAllOut_InitialState;
115 skippable = true;
116 }
117 } else {
118 if (clip->contains(*resultBounds)) {
119 *initialState = kAllOut_InitialState;
120 skippable = true;
121 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
122 skippable = true;
123 }
124 }
125 }
126 if (!skippable) {
127 emsmallens = true;
128 }
129 break;
130 case SkRegion::kIntersect_Op:
131 if (*resultsAreBounded) {
132 // check if the shape intersected contains the entire bounds and therefore can
133 // be skipped or it is outside the entire bounds and therfore makes the clip
134 // empty.
135 if (clip->isInverseFilled()) {
136 if (clip->contains(*resultBounds)) {
137 *initialState = kAllOut_InitialState;
138 skippable = true;
139 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
140 skippable = true;
141 }
142 } else {
143 if (clip->contains(*resultBounds)) {
144 skippable = true;
145 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
146 *initialState = kAllOut_InitialState;
147 skippable = true;
148 }
149 }
150 }
151 if (!skippable) {
152 emsmallens = true;
153 }
154 break;
155 case SkRegion::kUnion_Op:
156 if (*resultsAreBounded) {
157 // If the unioned shape contains the entire bounds then after this element
158 // the bounds is entirely inside the clip. If the unioned shape is outside the
159 // bounds then this op can be skipped.
160 if (clip->isInverseFilled()) {
161 if (clip->contains(*resultBounds)) {
162 skippable = true;
163 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
164 *initialState = kAllIn_InitialState;
165 skippable = true;
166 }
167 } else {
168 if (clip->contains(*resultBounds)) {
169 *initialState = kAllIn_InitialState;
170 skippable = true;
171 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
172 skippable = true;
173 }
174 }
175 }
176 if (!skippable) {
177 embiggens = true;
178 }
179 break;
180 case SkRegion::kXOR_Op:
181 if (*resultsAreBounded) {
182 if (clip->isInverseFilled()) {
183 if (clip->contains(*resultBounds)) {
184 skippable = true;
185 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
186 isFlip = true;
187 }
188 } else {
189 if (clip->contains(*resultBounds)) {
190 isFlip = true;
191 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
192 skippable = true;
193 }
194 }
195 }
196 if (!skippable) {
197 emsmallens = embiggens = true;
198 }
199 break;
200 case SkRegion::kReverseDifference_Op:
201 if (*resultsAreBounded) {
202 if (clip->isInverseFilled()) {
203 if (clip->contains(*resultBounds)) {
204 *initialState = kAllOut_InitialState;
205 skippable = true;
206 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
207 isFlip = true;
208 }
209 } else {
210 if (clip->contains(*resultBounds)) {
211 isFlip = true;
212 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
213 *initialState = kAllOut_InitialState;
214 skippable = true;
215 }
216 }
217 }
218 if (!skippable) {
219 emsmallens = embiggens = true;
220 }
221 break;
222 case SkRegion::kReplace_Op:
223 if (*resultsAreBounded) {
224 if (clip->isInverseFilled()) {
225 if (clip->contains(*resultBounds)) {
226 *initialState = kAllOut_InitialState;
227 skippable = true;
228 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
229 *initialState = kAllIn_InitialState;
230 skippable = true;
231 }
232 } else {
233 if (clip->contains(*resultBounds)) {
234 *initialState = kAllIn_InitialState;
235 skippable = true;
236 } else if (!SkRect::Intersects(clip->getBounds(), *resultBounds)) {
237 *initialState = kAllOut_InitialState;
238 skippable = true;
239 }
240 }
241 }
242 if (!skippable) {
243 *initialState = kAllOut_InitialState;
244 embiggens = emsmallens = true;
245 }
246 break;
247 default:
248 SkDEBUGFAIL("Unexpected op.");
249 break;
250 }
251 if (!skippable) {
252 SkClipStack::Iter::Clip* newClip = resultClips->prepend();
253 // if it is a flip, change it to a bounds-filling rect
254 if (isFlip) {
255 SkASSERT(SkRegion::kXOR_Op == clip->fOp ||
256 SkRegion::kReverseDifference_Op == clip->fOp);
257 newClip->fPath = NULL;
258 newClip->fRect = resultBounds;
259 // assuming this is faster to perform on GPU with stenciling than xor.
260 newClip->fOp = SkRegion::kReverseDifference_Op;
261 newClip->fDoAA = false;
262 newClip->fGenID = SkClipStack::kInvalidGenID;
263 } else {
264 *newClip = *clip;
265 }
266 }
267 }
268
269 if ((kAllOut_InitialState == *initialState && !embiggens) ||
270 (kAllIn_InitialState == *initialState && !emsmallens)) {
271 resultClips->reset();
272 } else {
273 int clipsToSkip = 0;
274 while (1) {
275 SkClipStack::Iter::Clip* clip = &(*resultClips)[clipsToSkip];
276 bool skippable = false;
277 switch (clip->fOp) {
278 case SkRegion::kDifference_Op:
279 skippable = kAllOut_InitialState == *initialState;
280 break;
281 case SkRegion::kIntersect_Op:
282 skippable = kAllOut_InitialState == *initialState;
283 break;
284 case SkRegion::kUnion_Op:
285 if (kAllIn_InitialState == *initialState) {
286 // unioning the infinite plane with anything is a no-op.
287 skippable = true;
288 } else {
289 // unioning the empty set with a shape is the shape.
290 clip->fOp = SkRegion::kReplace_Op;
291 }
292 break;
293 case SkRegion::kXOR_Op:
294 if (kAllOut_InitialState == *initialState) {
295 // xor could be changed to diff in the kAllIn case, not sure it's a win.
296 clip->fOp = SkRegion::kReplace_Op;
297 }
298 break;
299 case SkRegion::kReverseDifference_Op:
300 if (kAllIn_InitialState == *initialState) {
301 // subtracting the whole plane will yield the empty set.
302 skippable = true;
303 *initialState = kAllOut_InitialState;
304 } else {
305 // this picks up flips inserted in the backwards pass.
306 if (*resultsAreBounded && NULL != clip->fRect) {
307 skippable = clip->isInverseFilled() ?
308 !SkRect::Intersects(clip->getBounds(), *resultBounds) :
309 clip->contains(*resultBounds);
310 }
311 if (skippable) {
312 *initialState = kAllIn_InitialState;
313 } else {
314 clip->fOp = SkRegion::kReplace_Op;
315 }
316 }
317 break;
318 case SkRegion::kReplace_Op:
319 SkASSERT(!clipsToSkip); // replace should always be the first op
320 skippable = false; // we would have skipped it in the backwards walk if we
321 // could've.
322 break;
323 default:
324 SkDEBUGFAIL("Unexpected op.");
325 break;
326 }
327 if (!skippable) {
328 break;
329 } else {
330 ++clipsToSkip;
331 if (clipsToSkip == resultClips->count()) {
332 break;
333 }
334 }
335 }
336 resultClips->remove(0, clipsToSkip);
337 }
338}
339} // namespace GrReducedClip
340
341////////////////////////////////////////////////////////////////////////////////
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000342namespace {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000343// set up the draw state to enable the aa clipping mask. Besides setting up the
bsalomon@google.com08283af2012-10-26 13:01:20 +0000344// stage matrix this also alters the vertex layout
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000345void setup_drawstate_aaclip(GrGpu* gpu,
346 GrTexture* result,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000347 const GrIRect &devBound) {
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000348 GrDrawState* drawState = gpu->drawState();
349 GrAssert(drawState);
350
bsalomon@google.comdfdb7e52012-10-16 15:19:45 +0000351 static const int kMaskStage = GrPaint::kTotalStages+1;
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000352
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000353 SkMatrix mat;
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000354 mat.setIDiv(result->width(), result->height());
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000355 mat.preTranslate(SkIntToScalar(-devBound.fLeft),
robertphillips@google.com7b112892012-07-31 15:18:21 +0000356 SkIntToScalar(-devBound.fTop));
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000357 mat.preConcat(drawState->getViewMatrix());
358
bsalomon@google.com08283af2012-10-26 13:01:20 +0000359 drawState->stage(kMaskStage)->reset();
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000360
361 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
362 drawState->stage(kMaskStage)->setEffect(
363 GrTextureDomainEffect::Create(result,
364 mat,
365 GrTextureDomainEffect::MakeTexelDomain(result, domainTexels),
366 GrTextureDomainEffect::kDecal_WrapMode))->unref();
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000367}
368
robertphillips@google.com8a4fc402012-05-24 12:42:24 +0000369bool path_needs_SW_renderer(GrContext* context,
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000370 GrGpu* gpu,
371 const SkPath& path,
372 GrPathFill fill,
373 bool doAA) {
robertphillips@google.com8a4fc402012-05-24 12:42:24 +0000374 // last (false) parameter disallows use of the SW path renderer
375 return NULL == context->getPathRenderer(path, fill, gpu, doAA, false);
376}
377
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000378GrPathFill get_path_fill(const SkPath& path) {
379 switch (path.getFillType()) {
380 case SkPath::kWinding_FillType:
381 return kWinding_GrPathFill;
382 case SkPath::kEvenOdd_FillType:
383 return kEvenOdd_GrPathFill;
384 case SkPath::kInverseWinding_FillType:
385 return kInverseWinding_GrPathFill;
386 case SkPath::kInverseEvenOdd_FillType:
387 return kInverseEvenOdd_GrPathFill;
388 default:
389 GrCrash("Unsupported path fill in clip.");
390 return kWinding_GrPathFill; // suppress warning
391 }
392}
393
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000394/**
395 * Does any individual clip in 'clipIn' use anti-aliasing?
396 */
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000397bool requires_AA(const SkClipStack& clipIn) {
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000398
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000399 SkClipStack::Iter iter;
400 iter.reset(clipIn, SkClipStack::Iter::kBottom_IterStart);
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000401
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000402 const SkClipStack::Iter::Clip* clip = NULL;
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000403 for (clip = iter.skipToTopmost(SkRegion::kReplace_Op);
404 NULL != clip;
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000405 clip = iter.nextCombined()) {
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000406
407 if (clip->fDoAA) {
408 return true;
409 }
410 }
411
412 return false;
413}
414
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000415}
416
robertphillips@google.comfa662942012-05-17 12:20:22 +0000417/*
418 * This method traverses the clip stack to see if the GrSoftwarePathRenderer
419 * will be used on any element. If so, it returns true to indicate that the
420 * entire clip should be rendered in SW and then uploaded en masse to the gpu.
421 */
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000422bool GrClipMaskManager::useSWOnlyPath(const SkClipStack& clipIn) {
robertphillips@google.coma3e5c632012-05-22 18:09:26 +0000423
robertphillips@google.com8a4fc402012-05-24 12:42:24 +0000424 // TODO: generalize this function so that when
robertphillips@google.comfa662942012-05-17 12:20:22 +0000425 // a clip gets complex enough it can just be done in SW regardless
426 // of whether it would invoke the GrSoftwarePathRenderer.
427 bool useSW = false;
428
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000429 SkClipStack::Iter iter(clipIn, SkClipStack::Iter::kBottom_IterStart);
430 const SkClipStack::Iter::Clip* clip = NULL;
robertphillips@google.comfa662942012-05-17 12:20:22 +0000431
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000432 for (clip = iter.skipToTopmost(SkRegion::kReplace_Op);
433 NULL != clip;
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000434 clip = iter.nextCombined()) {
robertphillips@google.comfa662942012-05-17 12:20:22 +0000435
robertphillips@google.comf69a11b2012-06-15 13:58:07 +0000436 // rects can always be drawn directly w/o using the software path
437 // so only paths need to be checked
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000438 if (NULL != clip->fPath &&
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000439 path_needs_SW_renderer(this->getContext(), fGpu,
440 *clip->fPath,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000441 get_path_fill(*clip->fPath),
442 clip->fDoAA)) {
robertphillips@google.comf69a11b2012-06-15 13:58:07 +0000443 useSW = true;
robertphillips@google.comfa662942012-05-17 12:20:22 +0000444 }
robertphillips@google.comfa662942012-05-17 12:20:22 +0000445 }
446
447 return useSW;
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000448}
449
robertphillips@google.comf294b772012-04-27 14:29:26 +0000450////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000451// sort out what kind of clip mask needs to be created: alpha, stencil,
452// scissor, or entirely software
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000453bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn) {
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000454 fCurrClipMaskType = kNone_ClipMaskType;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000455
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000456 GrDrawState* drawState = fGpu->drawState();
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000457 if (!drawState->isClipState() || clipDataIn->fClipStack->isWideOpen()) {
bsalomon@google.coma3201942012-06-21 19:58:20 +0000458 fGpu->disableScissor();
459 this->setGpuStencil();
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000460 return true;
461 }
462
463 GrRenderTarget* rt = drawState->getRenderTarget();
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000464 // GrDrawTarget should have filtered this for us
465 GrAssert(NULL != rt);
466
robertphillips@google.com7b112892012-07-31 15:18:21 +0000467 GrIRect devClipBounds;
robertphillips@google.come4d69c02012-07-26 21:37:40 +0000468 bool isIntersectionOfRects = false;
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +0000469
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000470 clipDataIn->getConservativeBounds(rt, &devClipBounds, &isIntersectionOfRects);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000471 if (devClipBounds.isEmpty()) {
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +0000472 return false;
bsalomon@google.coma3201942012-06-21 19:58:20 +0000473 }
474
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000475#if GR_SW_CLIP
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000476 bool requiresAA = requires_AA(*clipDataIn->fClipStack);
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000477
robertphillips@google.coma3e5c632012-05-22 18:09:26 +0000478 // If MSAA is enabled we can do everything in the stencil buffer.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000479 // Otherwise check if we should just create the entire clip mask
robertphillips@google.coma3e5c632012-05-22 18:09:26 +0000480 // in software (this will only happen if the clip mask is anti-aliased
481 // and too complex for the gpu to handle in its entirety)
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000482 if (0 == rt->numSamples() &&
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000483 requiresAA &&
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000484 this->useSWOnlyPath(*clipDataIn->fClipStack)) {
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000485 // The clip geometry is complex enough that it will be more
486 // efficient to create it entirely in software
487 GrTexture* result = NULL;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000488 GrIRect devBound;
489 if (this->createSoftwareClipMask(*clipDataIn, &result, &devBound)) {
490 setup_drawstate_aaclip(fGpu, result, devBound);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000491 fGpu->disableScissor();
492 this->setGpuStencil();
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000493 return true;
494 }
robertphillips@google.coma3e5c632012-05-22 18:09:26 +0000495
496 // if SW clip mask creation fails fall through to the other
497 // two possible methods (bottoming out at stencil clipping)
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000498 }
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000499#endif // GR_SW_CLIP
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000500
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000501#if GR_AA_CLIP
robertphillips@google.comf294b772012-04-27 14:29:26 +0000502 // If MSAA is enabled use the (faster) stencil path for AA clipping
503 // otherwise the alpha clip mask is our only option
robertphillips@google.comb99225c2012-07-24 18:20:10 +0000504 if (0 == rt->numSamples() && requiresAA) {
robertphillips@google.comf294b772012-04-27 14:29:26 +0000505 // Since we are going to create a destination texture of the correct
506 // size for the mask (rather than being bound by the size of the
507 // render target) we aren't going to use scissoring like the stencil
508 // path does (see scissorSettings below)
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000509 GrTexture* result = NULL;
robertphillips@google.com7b112892012-07-31 15:18:21 +0000510 GrIRect devBound;
511 if (this->createAlphaClipMask(*clipDataIn, &result, &devBound)) {
512 setup_drawstate_aaclip(fGpu, result, devBound);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000513 fGpu->disableScissor();
514 this->setGpuStencil();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000515 return true;
516 }
517
518 // if alpha clip mask creation fails fall through to the stencil
519 // buffer method
520 }
521#endif // GR_AA_CLIP
522
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000523 // Either a hard (stencil buffer) clip was explicitly requested or
robertphillips@google.com5acc0e32012-05-17 12:01:02 +0000524 // an antialiased clip couldn't be created. In either case, free up
525 // the texture in the antialiased mask cache.
526 // TODO: this may require more investigation. Ganesh performs a lot of
robertphillips@google.coma3e5c632012-05-22 18:09:26 +0000527 // utility draws (e.g., clears, InOrderDrawBuffer playbacks) that hit
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000528 // the stencil buffer path. These may be "incorrectly" clearing the
robertphillips@google.com5acc0e32012-05-17 12:01:02 +0000529 // AA cache.
530 fAACache.reset();
531
bsalomon@google.coma3201942012-06-21 19:58:20 +0000532 // If the clip is a rectangle then just set the scissor. Otherwise, create
533 // a stencil mask.
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000534 if (isIntersectionOfRects) {
robertphillips@google.com7b112892012-07-31 15:18:21 +0000535 fGpu->enableScissor(devClipBounds);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000536 this->setGpuStencil();
537 return true;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000538 }
539
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000540 // use the stencil clip if we can't represent the clip as a rectangle.
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000541 bool useStencil = !clipDataIn->fClipStack->isWideOpen() &&
robertphillips@google.com7b112892012-07-31 15:18:21 +0000542 !devClipBounds.isEmpty();
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000543
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000544 if (useStencil) {
robertphillips@google.com7b112892012-07-31 15:18:21 +0000545 this->createStencilClipMask(*clipDataIn, devClipBounds);
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000546 }
bsalomon@google.coma3201942012-06-21 19:58:20 +0000547 // This must occur after createStencilClipMask. That function may change
548 // the scissor. Also, it only guarantees that the stencil mask is correct
549 // within the bounds it was passed, so we must use both stencil and scissor
550 // test to the bounds for the final draw.
robertphillips@google.com7b112892012-07-31 15:18:21 +0000551 fGpu->enableScissor(devClipBounds);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000552 this->setGpuStencil();
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000553 return true;
554}
555
556#define VISUALIZE_COMPLEX_CLIP 0
557
558#if VISUALIZE_COMPLEX_CLIP
tfarina@chromium.org223137f2012-11-21 22:38:36 +0000559 #include "SkRandom.h"
560 SkRandom gRandom;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000561 #define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU());
562#else
563 #define SET_RANDOM_COLOR
564#endif
565
566namespace {
robertphillips@google.com6623fcd2012-05-15 16:47:23 +0000567/**
robertphillips@google.com7b112892012-07-31 15:18:21 +0000568 * Does "canvContainer" contain "devContainee"? If either is empty then
569 * no containment is possible. "canvContainer" is in canvas coordinates while
570 * "devContainee" is in device coordiates. "origin" provides the mapping between
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000571 * the two.
robertphillips@google.com6623fcd2012-05-15 16:47:23 +0000572 */
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000573bool contains(const SkRect& canvContainer,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000574 const SkIRect& devContainee,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000575 const SkIPoint& origin) {
robertphillips@google.com7b112892012-07-31 15:18:21 +0000576 return !devContainee.isEmpty() && !canvContainer.isEmpty() &&
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000577 canvContainer.fLeft <= SkIntToScalar(devContainee.fLeft+origin.fX) &&
robertphillips@google.com7b112892012-07-31 15:18:21 +0000578 canvContainer.fTop <= SkIntToScalar(devContainee.fTop+origin.fY) &&
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000579 canvContainer.fRight >= SkIntToScalar(devContainee.fRight+origin.fX) &&
robertphillips@google.com7b112892012-07-31 15:18:21 +0000580 canvContainer.fBottom >= SkIntToScalar(devContainee.fBottom+origin.fY);
robertphillips@google.com6623fcd2012-05-15 16:47:23 +0000581}
582
robertphillips@google.comf294b772012-04-27 14:29:26 +0000583////////////////////////////////////////////////////////////////////////////////
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000584// determines how many elements at the head of the clip can be skipped and
585// whether the initial clear should be to the inside- or outside-the-clip value,
586// and what op should be used to draw the first element that isn't skipped.
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000587const SkClipStack::Iter::Clip* process_initial_clip_elements(
588 SkClipStack::Iter* iter,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000589 const GrIRect& devBounds,
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000590 bool* clearToInside,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000591 SkRegion::Op* firstOp,
592 const GrClipData& clipData) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000593
594 GrAssert(NULL != iter && NULL != clearToInside && NULL != firstOp);
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000595
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000596 // logically before the first element of the clip stack is
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000597 // processed the clip is entirely open. However, depending on the
598 // first set op we may prefer to clear to 0 for performance. We may
599 // also be able to skip the initial clip paths/rects. We loop until
600 // we cannot skip an element.
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000601 bool done = false;
602 *clearToInside = true;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000603
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000604 const SkClipStack::Iter::Clip* clip = NULL;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000605
606 for (clip = iter->skipToTopmost(SkRegion::kReplace_Op);
607 NULL != clip && !done;
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000608 clip = iter->nextCombined()) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000609 switch (clip->fOp) {
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000610 case SkRegion::kReplace_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000611 // replace ignores everything previous
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000612 *firstOp = SkRegion::kReplace_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000613 *clearToInside = false;
614 done = true;
615 break;
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000616 case SkRegion::kIntersect_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000617 // if this element contains the entire bounds then we
618 // can skip it.
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000619 if (NULL != clip->fRect &&
robertphillips@google.com7b112892012-07-31 15:18:21 +0000620 contains(*clip->fRect, devBounds, clipData.fOrigin)) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000621 break;
622 }
623 // if everything is initially clearToInside then intersect is
624 // same as clear to 0 and treat as a replace. Otherwise,
625 // set stays empty.
626 if (*clearToInside) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000627 *firstOp = SkRegion::kReplace_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000628 *clearToInside = false;
629 done = true;
630 }
631 break;
632 // we can skip a leading union.
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000633 case SkRegion::kUnion_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000634 // if everything is initially outside then union is
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000635 // same as replace. Otherwise, every pixel is still
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000636 // clearToInside
637 if (!*clearToInside) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000638 *firstOp = SkRegion::kReplace_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000639 done = true;
640 }
641 break;
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000642 case SkRegion::kXOR_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000643 // xor is same as difference or replace both of which
644 // can be 1-pass instead of 2 for xor.
645 if (*clearToInside) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000646 *firstOp = SkRegion::kDifference_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000647 } else {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000648 *firstOp = SkRegion::kReplace_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000649 }
650 done = true;
651 break;
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000652 case SkRegion::kDifference_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000653 // if all pixels are clearToInside then we have to process the
654 // difference, otherwise it has no effect and all pixels
655 // remain outside.
656 if (*clearToInside) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000657 *firstOp = SkRegion::kDifference_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000658 done = true;
659 }
660 break;
robertphillips@google.com0f191f32012-04-25 15:23:36 +0000661 case SkRegion::kReverseDifference_Op:
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000662 // if all pixels are clearToInside then reverse difference
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000663 // produces empty set. Otherise it is same as replace
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000664 if (*clearToInside) {
665 *clearToInside = false;
666 } else {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000667 *firstOp = SkRegion::kReplace_Op;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000668 done = true;
669 }
670 break;
671 default:
672 GrCrash("Unknown set op.");
673 }
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000674
675 if (done) {
676 // we need to break out here (rather than letting the test in
677 // the loop do it) since backing up the iterator is very expensive
678 break;
679 }
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000680 }
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000681 return clip;
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000682}
robertphillips@google.comf294b772012-04-27 14:29:26 +0000683
robertphillips@google.com1e945b72012-04-16 18:03:03 +0000684}
685
robertphillips@google.comf294b772012-04-27 14:29:26 +0000686namespace {
687
688////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000689// set up the OpenGL blend function to perform the specified
690// boolean operation for alpha clip mask creation
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000691void setup_boolean_blendcoeffs(GrDrawState* drawState, SkRegion::Op op) {
robertphillips@google.comf294b772012-04-27 14:29:26 +0000692
693 switch (op) {
694 case SkRegion::kReplace_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000695 drawState->setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000696 break;
697 case SkRegion::kIntersect_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000698 drawState->setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000699 break;
700 case SkRegion::kUnion_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000701 drawState->setBlendFunc(kOne_GrBlendCoeff, kISC_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000702 break;
703 case SkRegion::kXOR_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000704 drawState->setBlendFunc(kIDC_GrBlendCoeff, kISC_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000705 break;
706 case SkRegion::kDifference_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000707 drawState->setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000708 break;
709 case SkRegion::kReverseDifference_Op:
bsalomon@google.com47059542012-06-06 20:51:20 +0000710 drawState->setBlendFunc(kIDC_GrBlendCoeff, kZero_GrBlendCoeff);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000711 break;
712 default:
713 GrAssert(false);
714 break;
715 }
716}
717
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000718////////////////////////////////////////////////////////////////////////////////
719bool draw_path_in_software(GrContext* context,
720 GrGpu* gpu,
721 const SkPath& path,
722 GrPathFill fill,
723 bool doAA,
724 const GrIRect& resultBounds) {
725
726 SkAutoTUnref<GrTexture> texture(
727 GrSWMaskHelper::DrawPathMaskToTexture(context, path,
728 resultBounds, fill,
729 doAA, NULL));
730 if (NULL == texture) {
731 return false;
732 }
733
734 // The ClipMaskManager accumulates the clip mask in the UL corner
735 GrIRect rect = GrIRect::MakeWH(resultBounds.width(), resultBounds.height());
736
737 GrSWMaskHelper::DrawToTargetWithPathMask(texture, gpu, rect);
738
739 GrAssert(!GrIsFillInverted(fill));
740 return true;
741}
742
robertphillips@google.com366f1c62012-06-29 21:38:47 +0000743
744////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000745bool draw_path(GrContext* context,
746 GrGpu* gpu,
747 const SkPath& path,
748 GrPathFill fill,
749 bool doAA,
750 const GrIRect& resultBounds) {
751
752 GrPathRenderer* pr = context->getPathRenderer(path, fill, gpu, doAA, false);
753 if (NULL == pr) {
754 return draw_path_in_software(context, gpu, path, fill, doAA, resultBounds);
755 }
756
757 pr->drawPath(path, fill, gpu, doAA);
758 return true;
759}
robertphillips@google.com72176b22012-05-23 13:19:12 +0000760
robertphillips@google.com7b112892012-07-31 15:18:21 +0000761// 'rect' enters in device coordinates and leaves in canvas coordinates
762void device_to_canvas(SkRect* rect, const SkIPoint& origin) {
763 GrAssert(NULL != rect);
764
765 rect->fLeft += SkIntToScalar(origin.fX);
766 rect->fTop += SkIntToScalar(origin.fY);
767 rect->fRight += SkIntToScalar(origin.fX);
768 rect->fBottom += SkIntToScalar(origin.fY);
769}
770
robertphillips@google.com72176b22012-05-23 13:19:12 +0000771}
robertphillips@google.comf294b772012-04-27 14:29:26 +0000772
773////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000774bool GrClipMaskManager::drawClipShape(GrTexture* target,
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000775 const SkClipStack::Iter::Clip* clip,
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000776 const GrIRect& resultBounds) {
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000777 GrDrawState* drawState = fGpu->drawState();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000778 GrAssert(NULL != drawState);
779
780 drawState->setRenderTarget(target->asRenderTarget());
781
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000782 if (NULL != clip->fRect) {
783 if (clip->fDoAA) {
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000784 getContext()->getAARectRenderer()->fillAARect(fGpu, fGpu,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000785 *clip->fRect,
robertphillips@google.comf69a11b2012-06-15 13:58:07 +0000786 true);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000787 } else {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000788 fGpu->drawSimpleRect(*clip->fRect, NULL);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000789 }
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000790 } else if (NULL != clip->fPath) {
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000791 return draw_path(this->getContext(), fGpu,
792 *clip->fPath,
793 get_path_fill(*clip->fPath),
794 clip->fDoAA,
795 resultBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000796 }
797 return true;
798}
799
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000800void GrClipMaskManager::mergeMask(GrTexture* dstMask,
801 GrTexture* srcMask,
802 SkRegion::Op op,
803 const GrIRect& dstBound,
804 const GrIRect& srcBound) {
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000805 GrDrawState* drawState = fGpu->drawState();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000806 GrAssert(NULL != drawState);
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000807 SkMatrix oldMatrix = drawState->getViewMatrix();
808 drawState->viewMatrix()->reset();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000809
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000810 drawState->setRenderTarget(dstMask->asRenderTarget());
robertphillips@google.comf294b772012-04-27 14:29:26 +0000811
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000812 setup_boolean_blendcoeffs(drawState, op);
skia.committer@gmail.com72b2e6f2012-11-08 02:03:56 +0000813
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000814 SkMatrix sampleM;
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000815 sampleM.setIDiv(srcMask->width(), srcMask->height());
816 drawState->stage(0)->setEffect(
817 GrTextureDomainEffect::Create(srcMask,
818 sampleM,
819 GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
820 GrTextureDomainEffect::kDecal_WrapMode))->unref();
821 fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000822
tomhudson@google.com676e6602012-07-10 17:21:48 +0000823 drawState->disableStage(0);
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000824 drawState->setViewMatrix(oldMatrix);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000825}
826
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000827// get a texture to act as a temporary buffer for AA clip boolean operations
828// TODO: given the expense of createTexture we may want to just cache this too
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000829void GrClipMaskManager::getTemp(const GrIRect& bounds,
robertphillips@google.comf105b102012-05-14 12:18:26 +0000830 GrAutoScratchTexture* temp) {
831 if (NULL != temp->texture()) {
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000832 // we've already allocated the temp texture
833 return;
834 }
835
robertphillips@google.com75b3c962012-06-07 12:08:45 +0000836 GrTextureDesc desc;
837 desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit;
838 desc.fWidth = bounds.width();
839 desc.fHeight = bounds.height();
840 desc.fConfig = kAlpha_8_GrPixelConfig;
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000841
robertphillips@google.com2c756812012-05-22 20:28:23 +0000842 temp->set(this->getContext(), desc);
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000843}
844
robertphillips@google.comf105b102012-05-14 12:18:26 +0000845
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000846void GrClipMaskManager::setupCache(const SkClipStack& clipIn,
robertphillips@google.com6623fcd2012-05-15 16:47:23 +0000847 const GrIRect& bounds) {
robertphillips@google.comf105b102012-05-14 12:18:26 +0000848 // Since we are setting up the cache we know the last lookup was a miss
849 // Free up the currently cached mask so it can be reused
850 fAACache.reset();
851
robertphillips@google.com75b3c962012-06-07 12:08:45 +0000852 GrTextureDesc desc;
853 desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit;
854 desc.fWidth = bounds.width();
855 desc.fHeight = bounds.height();
856 desc.fConfig = kAlpha_8_GrPixelConfig;
robertphillips@google.comf105b102012-05-14 12:18:26 +0000857
858 fAACache.acquireMask(clipIn, desc, bounds);
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000859}
860
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000861////////////////////////////////////////////////////////////////////////////////
862// Shared preamble between gpu and SW-only AA clip mask creation paths.
863// Handles caching, determination of clip mask bound & allocation (if needed)
864// of the result texture
865// Returns true if there is no more work to be done (i.e., we got a cache hit)
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000866bool GrClipMaskManager::clipMaskPreamble(const GrClipData& clipDataIn,
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000867 GrTexture** result,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000868 GrIRect* devResultBounds) {
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000869 GrDrawState* origDrawState = fGpu->drawState();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000870 GrAssert(origDrawState->isClipState());
871
872 GrRenderTarget* rt = origDrawState->getRenderTarget();
873 GrAssert(NULL != rt);
874
robertphillips@google.comf294b772012-04-27 14:29:26 +0000875 // unlike the stencil path the alpha path is not bound to the size of the
876 // render target - determine the minimum size required for the mask
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000877 // Note: intBounds is in device (as opposed to canvas) coordinates
robertphillips@google.com9cb5adf2012-08-30 11:05:08 +0000878 clipDataIn.getConservativeBounds(rt, devResultBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000879
880 // need to outset a pixel since the standard bounding box computation
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000881 // path doesn't leave any room for antialiasing (esp. w.r.t. rects)
robertphillips@google.com9cb5adf2012-08-30 11:05:08 +0000882 devResultBounds->outset(1, 1);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000883
robertphillips@google.coma72eef32012-05-01 17:22:59 +0000884 // TODO: make sure we don't outset if bounds are still 0,0 @ min
885
robertphillips@google.comba998f22012-10-12 11:33:56 +0000886 if (fAACache.canReuse(*clipDataIn.fClipStack, *devResultBounds)) {
robertphillips@google.com8fff3562012-05-11 12:53:50 +0000887 *result = fAACache.getLastMask();
robertphillips@google.com7b112892012-07-31 15:18:21 +0000888 fAACache.getLastBound(devResultBounds);
robertphillips@google.com8fff3562012-05-11 12:53:50 +0000889 return true;
890 }
891
robertphillips@google.com9cb5adf2012-08-30 11:05:08 +0000892 this->setupCache(*clipDataIn.fClipStack, *devResultBounds);
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000893 return false;
894}
robertphillips@google.comf294b772012-04-27 14:29:26 +0000895
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000896////////////////////////////////////////////////////////////////////////////////
897// Create a 8-bit clip mask in alpha
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000898bool GrClipMaskManager::createAlphaClipMask(const GrClipData& clipDataIn,
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000899 GrTexture** result,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000900 GrIRect *devResultBounds) {
901 GrAssert(NULL != devResultBounds);
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000902 GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
903
robertphillips@google.com7b112892012-07-31 15:18:21 +0000904 if (this->clipMaskPreamble(clipDataIn, result, devResultBounds)) {
bsalomon@google.comc8f7f472012-06-18 13:44:51 +0000905 fCurrClipMaskType = kAlpha_ClipMaskType;
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000906 return true;
907 }
908
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000909 // Note: 'resultBounds' is in device (as opposed to canvas) coordinates
910
robertphillips@google.comf105b102012-05-14 12:18:26 +0000911 GrTexture* accum = fAACache.getLastMask();
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000912 if (NULL == accum) {
robertphillips@google.comf105b102012-05-14 12:18:26 +0000913 fAACache.reset();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000914 return false;
915 }
916
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000917 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
918 GrDrawState* drawState = fGpu->drawState();
robertphillips@google.comf294b772012-04-27 14:29:26 +0000919
bsalomon@google.com13b85aa2012-06-15 21:09:40 +0000920 GrDrawTarget::AutoGeometryPush agp(fGpu);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000921
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000922 // The mask we generate is translated so that its upper-left corner is at devResultBounds
923 // upper-left corner in device space.
924 GrIRect maskResultBounds = GrIRect::MakeWH(devResultBounds->width(), devResultBounds->height());
925
926 // Set the matrix so that rendered clip elements are transformed from the space of the clip
927 // stack to the alpha-mask. This accounts for both translation due to the clip-origin and the
928 // placement of the mask within the device.
929 SkVector clipToMaskOffset = {
930 SkIntToScalar(-devResultBounds->fLeft - clipDataIn.fOrigin.fX),
931 SkIntToScalar(-devResultBounds->fTop - clipDataIn.fOrigin.fY)
932 };
933 drawState->viewMatrix()->setTranslate(clipToMaskOffset);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000934
935 bool clearToInside;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000936 SkRegion::Op firstOp = SkRegion::kReplace_Op; // suppress warning
937
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000938 SkClipStack::Iter iter(*clipDataIn.fClipStack,
939 SkClipStack::Iter::kBottom_IterStart);
robertphillips@google.com641f8b12012-07-31 19:15:58 +0000940 const SkClipStack::Iter::Clip* clip = process_initial_clip_elements(&iter,
robertphillips@google.com7b112892012-07-31 15:18:21 +0000941 *devResultBounds,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000942 &clearToInside,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000943 &firstOp,
944 clipDataIn);
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000945 // The scratch texture that we are drawing into can be substantially larger than the mask. Only
946 // clear the part that we care about.
947 fGpu->clear(&maskResultBounds,
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000948 clearToInside ? 0xffffffff : 0x00000000,
robertphillips@google.comc82a8b72012-06-21 20:15:48 +0000949 accum->asRenderTarget());
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000950 bool accumClearedToZero = !clearToInside;
skia.committer@gmail.comd9f75032012-11-09 02:01:24 +0000951
robertphillips@google.comf105b102012-05-14 12:18:26 +0000952 GrAutoScratchTexture temp;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000953 bool first = true;
robertphillips@google.comf294b772012-04-27 14:29:26 +0000954 // walk through each clip element and perform its set op
bsalomon@google.come8ca6c62012-11-07 21:19:10 +0000955 for ( ; NULL != clip; clip = iter.nextCombined()) {
robertphillips@google.comf294b772012-04-27 14:29:26 +0000956
robertphillips@google.coma6f11c42012-07-23 17:39:44 +0000957 SkRegion::Op op = clip->fOp;
958 if (first) {
959 first = false;
960 op = firstOp;
961 }
robertphillips@google.comf294b772012-04-27 14:29:26 +0000962
bsalomon@google.com6794a252012-11-08 15:30:53 +0000963 if (SkRegion::kReplace_Op == op) {
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000964 // clear the accumulator and draw the new object directly into it
965 if (!accumClearedToZero) {
966 fGpu->clear(&maskResultBounds, 0x00000000, accum->asRenderTarget());
967 }
968
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000969 setup_boolean_blendcoeffs(drawState, op);
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000970 this->drawClipShape(accum, clip, *devResultBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +0000971
972 } else if (SkRegion::kReverseDifference_Op == op ||
973 SkRegion::kIntersect_Op == op) {
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000974 // there is no point in intersecting a screen filling rectangle.
robertphillips@google.comf8d904a2012-07-31 12:18:16 +0000975 if (SkRegion::kIntersect_Op == op && NULL != clip->fRect &&
robertphillips@google.com7b112892012-07-31 15:18:21 +0000976 contains(*clip->fRect, *devResultBounds, clipDataIn.fOrigin)) {
robertphillips@google.comf294b772012-04-27 14:29:26 +0000977 continue;
978 }
979
robertphillips@google.com7b112892012-07-31 15:18:21 +0000980 getTemp(*devResultBounds, &temp);
robertphillips@google.comf105b102012-05-14 12:18:26 +0000981 if (NULL == temp.texture()) {
robertphillips@google.comf105b102012-05-14 12:18:26 +0000982 fAACache.reset();
robertphillips@google.com6d62df42012-05-07 18:07:36 +0000983 return false;
984 }
985
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000986 // this is the bounds of the clip element in the space of the alpha-mask. The temporary
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000987 // mask buffer can be substantially larger than the actually clip stack element. We
988 // touch the minimum number of pixels necessary and use decal mode to combine it with
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000989 // the accumulator
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000990 GrRect elementMaskBounds = clip->getBounds();
991 elementMaskBounds.offset(clipToMaskOffset);
992 GrIRect elementMaskIBounds;
993 elementMaskBounds.roundOut(&elementMaskIBounds);
994
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000995 // clear the temp target & draw into it
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +0000996 fGpu->clear(&elementMaskIBounds, 0x00000000, temp.texture()->asRenderTarget());
robertphillips@google.comf294b772012-04-27 14:29:26 +0000997
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +0000998 setup_boolean_blendcoeffs(drawState, SkRegion::kReplace_Op);
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +0000999 this->drawClipShape(temp.texture(), clip, elementMaskIBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +00001000
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +00001001 // Now draw into the accumulator using the real operation
1002 // and the temp buffer as a texture
bsalomon@google.com7b7cdd12012-11-07 16:17:24 +00001003 this->mergeMask(accum, temp.texture(), op, maskResultBounds, elementMaskIBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +00001004 } else {
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001005 // all the remaining ops can just be directly draw into
robertphillips@google.comf294b772012-04-27 14:29:26 +00001006 // the accumulation buffer
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001007 setup_boolean_blendcoeffs(drawState, op);
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +00001008 this->drawClipShape(accum, clip, *devResultBounds);
robertphillips@google.comf294b772012-04-27 14:29:26 +00001009 }
bsalomon@google.com2e0c79f2012-11-12 13:38:57 +00001010 accumClearedToZero = false;
robertphillips@google.comf294b772012-04-27 14:29:26 +00001011 }
1012
robertphillips@google.coma72eef32012-05-01 17:22:59 +00001013 *result = accum;
bsalomon@google.comc8f7f472012-06-18 13:44:51 +00001014 fCurrClipMaskType = kAlpha_ClipMaskType;
robertphillips@google.comf294b772012-04-27 14:29:26 +00001015 return true;
1016}
1017
1018////////////////////////////////////////////////////////////////////////////////
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001019// Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001020// (as opposed to canvas) coordinates
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001021bool GrClipMaskManager::createStencilClipMask(const GrClipData& clipDataIn,
robertphillips@google.com7b112892012-07-31 15:18:21 +00001022 const GrIRect& devClipBounds) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001023
bsalomon@google.comc8f7f472012-06-18 13:44:51 +00001024 GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001025
bsalomon@google.com13b85aa2012-06-15 21:09:40 +00001026 GrDrawState* drawState = fGpu->drawState();
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001027 GrAssert(drawState->isClipState());
1028
1029 GrRenderTarget* rt = drawState->getRenderTarget();
1030 GrAssert(NULL != rt);
1031
1032 // TODO: dynamically attach a SB when needed.
1033 GrStencilBuffer* stencilBuffer = rt->getStencilBuffer();
1034 if (NULL == stencilBuffer) {
1035 return false;
1036 }
1037
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001038 if (stencilBuffer->mustRenderClip(clipDataIn, rt->width(), rt->height())) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001039
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001040 stencilBuffer->setLastClip(clipDataIn, rt->width(), rt->height());
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001041
1042 // we set the current clip to the bounds so that our recursive
1043 // draws are scissored to them. We use the copy of the complex clip
1044 // we just stashed on the SB to render from. We set it back after
1045 // we finish drawing it into the stencil.
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001046 const GrClipData* oldClipData = fGpu->getClip();
1047
robertphillips@google.com7b112892012-07-31 15:18:21 +00001048 // The origin of 'newClipData' is (0, 0) so it is okay to place
1049 // a device-coordinate bound in 'newClipStack'
robertphillips@google.com641f8b12012-07-31 19:15:58 +00001050 SkClipStack newClipStack(devClipBounds);
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001051 GrClipData newClipData;
1052 newClipData.fClipStack = &newClipStack;
1053
1054 fGpu->setClip(&newClipData);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001055
bsalomon@google.com13b85aa2012-06-15 21:09:40 +00001056 GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
1057 drawState = fGpu->drawState();
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001058 drawState->setRenderTarget(rt);
bsalomon@google.com13b85aa2012-06-15 21:09:40 +00001059 GrDrawTarget::AutoGeometryPush agp(fGpu);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001060
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001061 if (0 != clipDataIn.fOrigin.fX || 0 != clipDataIn.fOrigin.fY) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001062 // Add the saveLayer's offset to the view matrix rather than
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001063 // offset each individual draw
robertphillips@google.com7b112892012-07-31 15:18:21 +00001064 drawState->viewMatrix()->setTranslate(
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001065 SkIntToScalar(-clipDataIn.fOrigin.fX),
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001066 SkIntToScalar(-clipDataIn.fOrigin.fY));
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001067 }
1068
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001069#if !VISUALIZE_COMPLEX_CLIP
1070 drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
1071#endif
1072
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001073 int clipBit = stencilBuffer->bits();
1074 SkASSERT((clipBit <= 16) &&
1075 "Ganesh only handles 16b or smaller stencil buffers");
1076 clipBit = (1 << (clipBit-1));
1077
robertphillips@google.com7b112892012-07-31 15:18:21 +00001078 GrIRect devRTRect = GrIRect::MakeWH(rt->width(), rt->height());
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001079
1080 bool clearToInside;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001081 SkRegion::Op firstOp = SkRegion::kReplace_Op; // suppress warning
1082
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001083 SkClipStack::Iter iter(*oldClipData->fClipStack,
robertphillips@google.com641f8b12012-07-31 19:15:58 +00001084 SkClipStack::Iter::kBottom_IterStart);
1085 const SkClipStack::Iter::Clip* clip = process_initial_clip_elements(&iter,
robertphillips@google.com7b112892012-07-31 15:18:21 +00001086 devRTRect,
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001087 &clearToInside,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001088 &firstOp,
1089 clipDataIn);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001090
robertphillips@google.com7b112892012-07-31 15:18:21 +00001091 fGpu->clearStencilClip(devClipBounds, clearToInside);
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001092 bool first = true;
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001093
1094 // walk through each clip element and perform its set op
1095 // with the existing clip.
bsalomon@google.come8ca6c62012-11-07 21:19:10 +00001096 for ( ; NULL != clip; clip = iter.nextCombined()) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001097 GrPathFill fill;
tomhudson@google.com8afae612012-08-14 15:03:35 +00001098 bool fillInverted = false;
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001099 // enabled at bottom of loop
1100 drawState->disableState(GrGpu::kModifyStencilClip_StateBit);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001101 // if the target is MSAA then we want MSAA enabled when the clip is soft
1102 if (rt->isMultisampled()) {
bsalomon@google.comd5d69ff2012-10-04 19:42:00 +00001103 drawState->setState(GrDrawState::kHWAntialias_StateBit, clip->fDoAA);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +00001104 }
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001105
tomhudson@google.com8afae612012-08-14 15:03:35 +00001106 // Can the clip element be drawn directly to the stencil buffer
1107 // with a non-inverted fill rule without extra passes to
1108 // resolve in/out status?
1109 bool canRenderDirectToStencil = false;
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001110
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001111 SkRegion::Op op = clip->fOp;
1112 if (first) {
1113 first = false;
1114 op = firstOp;
1115 }
robertphillips@google.comf294b772012-04-27 14:29:26 +00001116
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001117 GrPathRenderer* pr = NULL;
bsalomon@google.com8d033a12012-04-27 15:52:53 +00001118 const SkPath* clipPath = NULL;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001119 if (NULL != clip->fRect) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001120 canRenderDirectToStencil = true;
bsalomon@google.com47059542012-06-06 20:51:20 +00001121 fill = kEvenOdd_GrPathFill;
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001122 fillInverted = false;
1123 // there is no point in intersecting a screen filling
1124 // rectangle.
robertphillips@google.comf294b772012-04-27 14:29:26 +00001125 if (SkRegion::kIntersect_Op == op &&
robertphillips@google.com7b112892012-07-31 15:18:21 +00001126 contains(*clip->fRect, devRTRect, oldClipData->fOrigin)) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001127 continue;
1128 }
tomhudson@google.com8afae612012-08-14 15:03:35 +00001129 } else {
1130 GrAssert(NULL != clip->fPath);
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001131 fill = get_path_fill(*clip->fPath);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001132 fillInverted = GrIsFillInverted(fill);
1133 fill = GrNonInvertedFill(fill);
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001134 clipPath = clip->fPath;
tomhudson@google.com8afae612012-08-14 15:03:35 +00001135 pr = this->getContext()->getPathRenderer(*clipPath, fill, fGpu, false, true);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001136 if (NULL == pr) {
tomhudson@google.com8afae612012-08-14 15:03:35 +00001137 fGpu->setClip(oldClipData);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001138 return false;
1139 }
1140 canRenderDirectToStencil =
bsalomon@google.com13b85aa2012-06-15 21:09:40 +00001141 !pr->requiresStencilPass(*clipPath, fill, fGpu);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001142 }
1143
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001144 int passes;
1145 GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses];
1146
1147 bool canDrawDirectToClip; // Given the renderer, the element,
1148 // fill rule, and set operation can
1149 // we render the element directly to
1150 // stencil bit used for clipping.
1151 canDrawDirectToClip =
1152 GrStencilSettings::GetClipPasses(op,
tomhudson@google.com8afae612012-08-14 15:03:35 +00001153 canRenderDirectToStencil,
1154 clipBit,
1155 fillInverted,
1156 &passes,
1157 stencilSettings);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001158
1159 // draw the element to the client stencil bits if necessary
1160 if (!canDrawDirectToClip) {
1161 GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil,
1162 kIncClamp_StencilOp,
1163 kIncClamp_StencilOp,
1164 kAlways_StencilFunc,
1165 0xffff,
1166 0x0000,
1167 0xffff);
1168 SET_RANDOM_COLOR
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001169 if (NULL != clip->fRect) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001170 *drawState->stencil() = gDrawToStencil;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001171 fGpu->drawSimpleRect(*clip->fRect, NULL);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001172 } else {
1173 if (canRenderDirectToStencil) {
1174 *drawState->stencil() = gDrawToStencil;
bsalomon@google.com0f11e1a2012-10-08 14:48:36 +00001175 pr->drawPath(*clipPath, fill, fGpu, false);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001176 } else {
bsalomon@google.com13b85aa2012-06-15 21:09:40 +00001177 pr->drawPathToStencil(*clipPath, fill, fGpu);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001178 }
1179 }
1180 }
1181
1182 // now we modify the clip bit by rendering either the clip
1183 // element directly or a bounding rect of the entire clip.
1184 drawState->enableState(GrGpu::kModifyStencilClip_StateBit);
1185 for (int p = 0; p < passes; ++p) {
1186 *drawState->stencil() = stencilSettings[p];
1187 if (canDrawDirectToClip) {
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001188 if (NULL != clip->fRect) {
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001189 SET_RANDOM_COLOR
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001190 fGpu->drawSimpleRect(*clip->fRect, NULL);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001191 } else {
1192 SET_RANDOM_COLOR
bsalomon@google.com0f11e1a2012-10-08 14:48:36 +00001193 pr->drawPath(*clipPath, fill, fGpu, false);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001194 }
1195 } else {
1196 SET_RANDOM_COLOR
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001197 // 'devClipBounds' is already in device coordinates so the
1198 // translation in the view matrix is inappropriate.
robertphillips@google.com7b112892012-07-31 15:18:21 +00001199 // Convert it to canvas space so the drawn rect will
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001200 // be in the correct location
robertphillips@google.com7b112892012-07-31 15:18:21 +00001201 GrRect canvClipBounds;
1202 canvClipBounds.set(devClipBounds);
1203 device_to_canvas(&canvClipBounds, clipDataIn.fOrigin);
1204 fGpu->drawSimpleRect(canvClipBounds, NULL);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001205 }
1206 }
1207 }
1208 // restore clip
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001209 fGpu->setClip(oldClipData);
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001210 }
bsalomon@google.comc8f7f472012-06-18 13:44:51 +00001211 // set this last because recursive draws may overwrite it back to kNone.
1212 GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
1213 fCurrClipMaskType = kStencil_ClipMaskType;
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001214 return true;
1215}
1216
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001217
bsalomon@google.com411dad02012-06-05 20:24:20 +00001218// mapping of clip-respecting stencil funcs to normal stencil funcs
1219// mapping depends on whether stencil-clipping is in effect.
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001220static const GrStencilFunc
bsalomon@google.com411dad02012-06-05 20:24:20 +00001221 gSpecialToBasicStencilFunc[2][kClipStencilFuncCount] = {
1222 {// Stencil-Clipping is DISABLED, we are effectively always inside the clip
1223 // In the Clip Funcs
1224 kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc
1225 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
1226 kLess_StencilFunc, // kLessIfInClip_StencilFunc
1227 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
1228 // Special in the clip func that forces user's ref to be 0.
1229 kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc
1230 // make ref 0 and do normal nequal.
1231 },
1232 {// Stencil-Clipping is ENABLED
1233 // In the Clip Funcs
1234 kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc
1235 // eq stencil clip bit, mask
1236 // out user bits.
1237
1238 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
1239 // add stencil bit to mask and ref
1240
1241 kLess_StencilFunc, // kLessIfInClip_StencilFunc
1242 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
1243 // for both of these we can add
1244 // the clip bit to the mask and
1245 // ref and compare as normal
1246 // Special in the clip func that forces user's ref to be 0.
1247 kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc
1248 // make ref have only the clip bit set
1249 // and make comparison be less
1250 // 10..0 < 1..user_bits..
1251 }
1252};
1253
bsalomon@google.coma3201942012-06-21 19:58:20 +00001254namespace {
1255// Sets the settings to clip against the stencil buffer clip while ignoring the
1256// client bits.
1257const GrStencilSettings& basic_apply_stencil_clip_settings() {
1258 // stencil settings to use when clip is in stencil
1259 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
1260 kKeep_StencilOp,
1261 kKeep_StencilOp,
1262 kAlwaysIfInClip_StencilFunc,
1263 0x0000,
1264 0x0000,
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001265 0x0000);
bsalomon@google.coma3201942012-06-21 19:58:20 +00001266 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
1267}
1268}
1269
1270void GrClipMaskManager::setGpuStencil() {
1271 // We make two copies of the StencilSettings here (except in the early
1272 // exit scenario. One copy from draw state to the stack var. Then another
1273 // from the stack var to the gpu. We could make this class hold a ptr to
1274 // GrGpu's fStencilSettings and eliminate the stack copy here.
1275
1276 const GrDrawState& drawState = fGpu->getDrawState();
1277
1278 // use stencil for clipping if clipping is enabled and the clip
1279 // has been written into the stencil.
1280 GrClipMaskManager::StencilClipMode clipMode;
1281 if (this->isClipInStencil() && drawState.isClipState()) {
1282 clipMode = GrClipMaskManager::kRespectClip_StencilClipMode;
1283 // We can't be modifying the clip and respecting it at the same time.
1284 GrAssert(!drawState.isStateFlagEnabled(
1285 GrGpu::kModifyStencilClip_StateBit));
1286 } else if (drawState.isStateFlagEnabled(
1287 GrGpu::kModifyStencilClip_StateBit)) {
1288 clipMode = GrClipMaskManager::kModifyClip_StencilClipMode;
1289 } else {
1290 clipMode = GrClipMaskManager::kIgnoreClip_StencilClipMode;
1291 }
1292
1293 GrStencilSettings settings;
1294 // The GrGpu client may not be using the stencil buffer but we may need to
1295 // enable it in order to respect a stencil clip.
1296 if (drawState.getStencil().isDisabled()) {
1297 if (GrClipMaskManager::kRespectClip_StencilClipMode == clipMode) {
1298 settings = basic_apply_stencil_clip_settings();
1299 } else {
1300 fGpu->disableStencil();
1301 return;
1302 }
1303 } else {
1304 settings = drawState.getStencil();
1305 }
1306
1307 // TODO: dynamically attach a stencil buffer
1308 int stencilBits = 0;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001309 GrStencilBuffer* stencilBuffer =
bsalomon@google.coma3201942012-06-21 19:58:20 +00001310 drawState.getRenderTarget()->getStencilBuffer();
1311 if (NULL != stencilBuffer) {
1312 stencilBits = stencilBuffer->bits();
1313 }
1314
bsalomon@google.comf6601872012-08-28 21:11:35 +00001315 GrAssert(fGpu->getCaps().stencilWrapOpsSupport() ||
bsalomon@google.com9e553c62012-06-22 12:23:29 +00001316 !settings.usesWrapOp());
bsalomon@google.comf6601872012-08-28 21:11:35 +00001317 GrAssert(fGpu->getCaps().twoSidedStencilSupport() || !settings.isTwoSided());
bsalomon@google.coma3201942012-06-21 19:58:20 +00001318 this->adjustStencilParams(&settings, clipMode, stencilBits);
1319 fGpu->setStencilSettings(settings);
1320}
1321
1322void GrClipMaskManager::adjustStencilParams(GrStencilSettings* settings,
1323 StencilClipMode mode,
1324 int stencilBitCnt) {
bsalomon@google.com411dad02012-06-05 20:24:20 +00001325 GrAssert(stencilBitCnt > 0);
bsalomon@google.com411dad02012-06-05 20:24:20 +00001326
1327 if (kModifyClip_StencilClipMode == mode) {
bsalomon@google.coma3201942012-06-21 19:58:20 +00001328 // We assume that this clip manager itself is drawing to the GrGpu and
1329 // has already setup the correct values.
1330 return;
bsalomon@google.com411dad02012-06-05 20:24:20 +00001331 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00001332
bsalomon@google.com411dad02012-06-05 20:24:20 +00001333 unsigned int clipBit = (1 << (stencilBitCnt - 1));
1334 unsigned int userBits = clipBit - 1;
1335
bsalomon@google.coma3201942012-06-21 19:58:20 +00001336 GrStencilSettings::Face face = GrStencilSettings::kFront_Face;
bsalomon@google.comf6601872012-08-28 21:11:35 +00001337 bool twoSided = fGpu->getCaps().twoSidedStencilSupport();
bsalomon@google.com411dad02012-06-05 20:24:20 +00001338
bsalomon@google.coma3201942012-06-21 19:58:20 +00001339 bool finished = false;
1340 while (!finished) {
1341 GrStencilFunc func = settings->func(face);
1342 uint16_t writeMask = settings->writeMask(face);
1343 uint16_t funcMask = settings->funcMask(face);
1344 uint16_t funcRef = settings->funcRef(face);
1345
1346 GrAssert((unsigned) func < kStencilFuncCount);
1347
1348 writeMask &= userBits;
1349
1350 if (func >= kBasicStencilFuncCount) {
1351 int respectClip = kRespectClip_StencilClipMode == mode;
1352 if (respectClip) {
1353 // The GrGpu class should have checked this
1354 GrAssert(this->isClipInStencil());
1355 switch (func) {
1356 case kAlwaysIfInClip_StencilFunc:
1357 funcMask = clipBit;
1358 funcRef = clipBit;
1359 break;
1360 case kEqualIfInClip_StencilFunc:
1361 case kLessIfInClip_StencilFunc:
1362 case kLEqualIfInClip_StencilFunc:
1363 funcMask = (funcMask & userBits) | clipBit;
1364 funcRef = (funcRef & userBits) | clipBit;
1365 break;
1366 case kNonZeroIfInClip_StencilFunc:
1367 funcMask = (funcMask & userBits) | clipBit;
1368 funcRef = clipBit;
1369 break;
1370 default:
1371 GrCrash("Unknown stencil func");
1372 }
1373 } else {
1374 funcMask &= userBits;
1375 funcRef &= userBits;
bsalomon@google.com411dad02012-06-05 20:24:20 +00001376 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001377 const GrStencilFunc* table =
bsalomon@google.coma3201942012-06-21 19:58:20 +00001378 gSpecialToBasicStencilFunc[respectClip];
1379 func = table[func - kBasicStencilFuncCount];
1380 GrAssert(func >= 0 && func < kBasicStencilFuncCount);
bsalomon@google.com411dad02012-06-05 20:24:20 +00001381 } else {
bsalomon@google.coma3201942012-06-21 19:58:20 +00001382 funcMask &= userBits;
1383 funcRef &= userBits;
bsalomon@google.com411dad02012-06-05 20:24:20 +00001384 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00001385
1386 settings->setFunc(face, func);
1387 settings->setWriteMask(face, writeMask);
1388 settings->setFuncMask(face, funcMask);
1389 settings->setFuncRef(face, funcRef);
1390
1391 if (GrStencilSettings::kFront_Face == face) {
1392 face = GrStencilSettings::kBack_Face;
1393 finished = !twoSided;
1394 } else {
1395 finished = true;
1396 }
bsalomon@google.com411dad02012-06-05 20:24:20 +00001397 }
bsalomon@google.coma3201942012-06-21 19:58:20 +00001398 if (!twoSided) {
1399 settings->copyFrontSettingsToBack();
1400 }
bsalomon@google.com411dad02012-06-05 20:24:20 +00001401}
1402
1403////////////////////////////////////////////////////////////////////////////////
1404
robertphillips@google.comfa662942012-05-17 12:20:22 +00001405namespace {
1406
1407GrPathFill invert_fill(GrPathFill fill) {
1408 static const GrPathFill gInvertedFillTable[] = {
bsalomon@google.com47059542012-06-06 20:51:20 +00001409 kInverseWinding_GrPathFill, // kWinding_GrPathFill
1410 kInverseEvenOdd_GrPathFill, // kEvenOdd_GrPathFill
1411 kWinding_GrPathFill, // kInverseWinding_GrPathFill
1412 kEvenOdd_GrPathFill, // kInverseEvenOdd_GrPathFill
1413 kHairLine_GrPathFill, // kHairLine_GrPathFill
robertphillips@google.comfa662942012-05-17 12:20:22 +00001414 };
bsalomon@google.com47059542012-06-06 20:51:20 +00001415 GR_STATIC_ASSERT(0 == kWinding_GrPathFill);
1416 GR_STATIC_ASSERT(1 == kEvenOdd_GrPathFill);
1417 GR_STATIC_ASSERT(2 == kInverseWinding_GrPathFill);
1418 GR_STATIC_ASSERT(3 == kInverseEvenOdd_GrPathFill);
1419 GR_STATIC_ASSERT(4 == kHairLine_GrPathFill);
1420 GR_STATIC_ASSERT(5 == kGrPathFillCount);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001421 return gInvertedFillTable[fill];
1422}
1423
1424}
1425
robertphillips@google.combeb1af72012-07-26 18:52:16 +00001426bool GrClipMaskManager::createSoftwareClipMask(const GrClipData& clipDataIn,
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001427 GrTexture** result,
robertphillips@google.com7b112892012-07-31 15:18:21 +00001428 GrIRect* devResultBounds) {
bsalomon@google.comc8f7f472012-06-18 13:44:51 +00001429 GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001430
robertphillips@google.com7b112892012-07-31 15:18:21 +00001431 if (this->clipMaskPreamble(clipDataIn, result, devResultBounds)) {
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001432 return true;
1433 }
1434
robertphillips@google.comf105b102012-05-14 12:18:26 +00001435 GrTexture* accum = fAACache.getLastMask();
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001436 if (NULL == accum) {
robertphillips@google.comf105b102012-05-14 12:18:26 +00001437 fAACache.reset();
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001438 return false;
1439 }
1440
robertphillips@google.com2c756812012-05-22 20:28:23 +00001441 GrSWMaskHelper helper(this->getContext());
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001442
bsalomon@google.comb9086a02012-11-01 18:02:54 +00001443 SkMatrix matrix;
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001444 matrix.setTranslate(SkIntToScalar(-clipDataIn.fOrigin.fX),
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001445 SkIntToScalar(-clipDataIn.fOrigin.fY));
robertphillips@google.com7b112892012-07-31 15:18:21 +00001446 helper.init(*devResultBounds, &matrix);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001447
robertphillips@google.comfa662942012-05-17 12:20:22 +00001448 bool clearToInside;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001449 SkRegion::Op firstOp = SkRegion::kReplace_Op; // suppress warning
1450
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001451 SkClipStack::Iter iter(*clipDataIn.fClipStack,
robertphillips@google.com641f8b12012-07-31 19:15:58 +00001452 SkClipStack::Iter::kBottom_IterStart);
1453 const SkClipStack::Iter::Clip* clip = process_initial_clip_elements(&iter,
robertphillips@google.com7b112892012-07-31 15:18:21 +00001454 *devResultBounds,
robertphillips@google.comfa662942012-05-17 12:20:22 +00001455 &clearToInside,
robertphillips@google.comf8d904a2012-07-31 12:18:16 +00001456 &firstOp,
1457 clipDataIn);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001458
robertphillips@google.com366f1c62012-06-29 21:38:47 +00001459 helper.clear(clearToInside ? 0xFF : 0x00);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001460
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001461 bool first = true;
bsalomon@google.come8ca6c62012-11-07 21:19:10 +00001462 for ( ; NULL != clip; clip = iter.nextCombined()) {
robertphillips@google.comfa662942012-05-17 12:20:22 +00001463
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001464 SkRegion::Op op = clip->fOp;
1465 if (first) {
1466 first = false;
1467 op = firstOp;
1468 }
robertphillips@google.comfa662942012-05-17 12:20:22 +00001469
1470 if (SkRegion::kIntersect_Op == op ||
1471 SkRegion::kReverseDifference_Op == op) {
1472 // Intersect and reverse difference require modifying pixels
1473 // outside of the geometry that is being "drawn". In both cases
1474 // we erase all the pixels outside of the geometry but
1475 // leave the pixels inside the geometry alone. For reverse
1476 // difference we invert all the pixels before clearing the ones
1477 // outside the geometry.
1478 if (SkRegion::kReverseDifference_Op == op) {
robertphillips@google.com7b112892012-07-31 15:18:21 +00001479 SkRect temp;
1480 temp.set(*devResultBounds);
robertphillips@google.comba998f22012-10-12 11:33:56 +00001481 temp.offset(SkIntToScalar(clipDataIn.fOrigin.fX),
1482 SkIntToScalar(clipDataIn.fOrigin.fX));
robertphillips@google.comfa662942012-05-17 12:20:22 +00001483
1484 // invert the entire scene
robertphillips@google.com366f1c62012-06-29 21:38:47 +00001485 helper.draw(temp, SkRegion::kXOR_Op, false, 0xFF);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001486 }
1487
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001488 if (NULL != clip->fRect) {
robertphillips@google.comfa662942012-05-17 12:20:22 +00001489
1490 // convert the rect to a path so we can invert the fill
1491 SkPath temp;
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001492 temp.addRect(*clip->fRect);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001493
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001494 helper.draw(temp, SkRegion::kReplace_Op,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001495 kInverseEvenOdd_GrPathFill, clip->fDoAA,
robertphillips@google.com366f1c62012-06-29 21:38:47 +00001496 0x00);
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001497 } else if (NULL != clip->fPath) {
1498 helper.draw(*clip->fPath,
robertphillips@google.comfa662942012-05-17 12:20:22 +00001499 SkRegion::kReplace_Op,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001500 invert_fill(get_path_fill(*clip->fPath)),
1501 clip->fDoAA,
robertphillips@google.com366f1c62012-06-29 21:38:47 +00001502 0x00);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001503 }
1504
1505 continue;
1506 }
1507
1508 // The other ops (union, xor, diff) only affect pixels inside
1509 // the geometry so they can just be drawn normally
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001510 if (NULL != clip->fRect) {
robertphillips@google.comfa662942012-05-17 12:20:22 +00001511
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001512 helper.draw(*clip->fRect,
robertphillips@google.comfa662942012-05-17 12:20:22 +00001513 op,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001514 clip->fDoAA, 0xFF);
robertphillips@google.comfa662942012-05-17 12:20:22 +00001515
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001516 } else if (NULL != clip->fPath) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +00001517 helper.draw(*clip->fPath,
robertphillips@google.comfa662942012-05-17 12:20:22 +00001518 op,
robertphillips@google.coma6f11c42012-07-23 17:39:44 +00001519 get_path_fill(*clip->fPath),
1520 clip->fDoAA, 0xFF);
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001521 }
1522 }
1523
robertphillips@google.comfa662942012-05-17 12:20:22 +00001524 // Because we are using the scratch texture cache, "accum" may be
1525 // larger than expected and have some cruft in the areas we aren't using.
1526 // Clear it out.
robertphillips@google.comc82a8b72012-06-21 20:15:48 +00001527 fGpu->clear(NULL, 0x00000000, accum->asRenderTarget());
robertphillips@google.comfa662942012-05-17 12:20:22 +00001528
robertphillips@google.com366f1c62012-06-29 21:38:47 +00001529 helper.toTexture(accum, clearToInside ? 0xFF : 0x00);
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001530
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001531 *result = accum;
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001532
bsalomon@google.comc8f7f472012-06-18 13:44:51 +00001533 fCurrClipMaskType = kAlpha_ClipMaskType;
robertphillips@google.com6b70a7b2012-05-11 15:32:48 +00001534 return true;
1535}
1536
robertphillips@google.comf294b772012-04-27 14:29:26 +00001537////////////////////////////////////////////////////////////////////////////////
robertphillips@google.comf105b102012-05-14 12:18:26 +00001538void GrClipMaskManager::releaseResources() {
robertphillips@google.comf105b102012-05-14 12:18:26 +00001539 fAACache.releaseResources();
robertphillips@google.com1e945b72012-04-16 18:03:03 +00001540}