OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrClipMaskManager.h" | 8 #include "GrClipMaskManager.h" |
9 #include "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
10 #include "GrAAHairLinePathRenderer.h" | 10 #include "GrAAHairLinePathRenderer.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "effects/GrPorterDuffXferProcessor.h" | 23 #include "effects/GrPorterDuffXferProcessor.h" |
24 #include "effects/GrRRectEffect.h" | 24 #include "effects/GrRRectEffect.h" |
25 #include "effects/GrTextureDomain.h" | 25 #include "effects/GrTextureDomain.h" |
26 | 26 |
27 typedef SkClipStack::Element Element; | 27 typedef SkClipStack::Element Element; |
28 | 28 |
29 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
30 namespace { | 30 namespace { |
31 // set up the draw state to enable the aa clipping mask. Besides setting up the | 31 // set up the draw state to enable the aa clipping mask. Besides setting up the |
32 // stage matrix this also alters the vertex layout | 32 // stage matrix this also alters the vertex layout |
33 void setup_drawstate_aaclip(const SkIRect &devBound, | 33 void setup_drawstate_aaclip(GrPipelineBuilder* pipelineBuilder, |
34 GrPipelineBuilder* pipelineBuilder, | 34 GrTexture* result, |
35 GrTexture* result) { | 35 GrPipelineBuilder::AutoRestoreEffects* are, |
36 SkASSERT(pipelineBuilder); | 36 const SkIRect &devBound) { |
| 37 SkASSERT(pipelineBuilder && are); |
| 38 are->set(pipelineBuilder); |
37 | 39 |
38 SkMatrix mat; | 40 SkMatrix mat; |
39 // We use device coords to compute the texture coordinates. We set our matri
x to be a | 41 // We use device coords to compute the texture coordinates. We set our matri
x to be a |
40 // translation to the devBound, and then a scaling matrix to normalized coor
ds. | 42 // translation to the devBound, and then a scaling matrix to normalized coor
ds. |
41 mat.setIDiv(result->width(), result->height()); | 43 mat.setIDiv(result->width(), result->height()); |
42 mat.preTranslate(SkIntToScalar(-devBound.fLeft), | 44 mat.preTranslate(SkIntToScalar(-devBound.fLeft), |
43 SkIntToScalar(-devBound.fTop)); | 45 SkIntToScalar(-devBound.fTop)); |
44 | 46 |
45 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); | 47 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
46 // This could be a long-lived effect that is cached with the alpha-mask. | 48 // This could be a long-lived effect that is cached with the alpha-mask. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 edgeType = | 164 edgeType = |
163 invert ? kInverseFillAA_GrProcessorEdgeType : kFillAA_Gr
ProcessorEdgeType; | 165 invert ? kInverseFillAA_GrProcessorEdgeType : kFillAA_Gr
ProcessorEdgeType; |
164 } else { | 166 } else { |
165 edgeType = | 167 edgeType = |
166 invert ? kInverseFillBW_GrProcessorEdgeType : kFillBW_Gr
ProcessorEdgeType; | 168 invert ? kInverseFillBW_GrProcessorEdgeType : kFillBW_Gr
ProcessorEdgeType; |
167 } | 169 } |
168 SkAutoTUnref<GrFragmentProcessor> fp; | 170 SkAutoTUnref<GrFragmentProcessor> fp; |
169 switch (iter.get()->getType()) { | 171 switch (iter.get()->getType()) { |
170 case SkClipStack::Element::kPath_Type: | 172 case SkClipStack::Element::kPath_Type: |
171 fp.reset(GrConvexPolyEffect::Create(edgeType, iter.get()->ge
tPath(), | 173 fp.reset(GrConvexPolyEffect::Create(edgeType, iter.get()->ge
tPath(), |
172 &clipToRTOffset)); | 174 &clipToRTOffset)); |
173 break; | 175 break; |
174 case SkClipStack::Element::kRRect_Type: { | 176 case SkClipStack::Element::kRRect_Type: { |
175 SkRRect rrect = iter.get()->getRRect(); | 177 SkRRect rrect = iter.get()->getRRect(); |
176 rrect.offset(clipToRTOffset.fX, clipToRTOffset.fY); | 178 rrect.offset(clipToRTOffset.fX, clipToRTOffset.fY); |
177 fp.reset(GrRRectEffect::Create(edgeType, rrect)); | 179 fp.reset(GrRRectEffect::Create(edgeType, rrect)); |
178 break; | 180 break; |
179 } | 181 } |
180 case SkClipStack::Element::kRect_Type: { | 182 case SkClipStack::Element::kRect_Type: { |
181 SkRect rect = iter.get()->getRect(); | 183 SkRect rect = iter.get()->getRect(); |
182 rect.offset(clipToRTOffset.fX, clipToRTOffset.fY); | 184 rect.offset(clipToRTOffset.fX, clipToRTOffset.fY); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 clipSpaceIBounds); | 326 clipSpaceIBounds); |
325 } else { | 327 } else { |
326 result = this->createAlphaClipMask(genID, | 328 result = this->createAlphaClipMask(genID, |
327 initialState, | 329 initialState, |
328 elements, | 330 elements, |
329 clipToMaskOffset, | 331 clipToMaskOffset, |
330 clipSpaceIBounds); | 332 clipSpaceIBounds); |
331 } | 333 } |
332 | 334 |
333 if (result) { | 335 if (result) { |
| 336 are->set(pipelineBuilder); |
334 // The mask's top left coord should be pinned to the rounded-out top
left corner of | 337 // The mask's top left coord should be pinned to the rounded-out top
left corner of |
335 // clipSpace bounds. We determine the mask's position WRT to the ren
der target here. | 338 // clipSpace bounds. We determine the mask's position WRT to the ren
der target here. |
336 SkIRect rtSpaceMaskBounds = clipSpaceIBounds; | 339 SkIRect rtSpaceMaskBounds = clipSpaceIBounds; |
337 rtSpaceMaskBounds.offset(-clip.origin()); | 340 rtSpaceMaskBounds.offset(-clip.origin()); |
338 setup_drawstate_aaclip(rtSpaceMaskBounds, pipelineBuilder, result); | 341 setup_drawstate_aaclip(pipelineBuilder, result, are, rtSpaceMaskBoun
ds); |
339 this->setPipelineBuilderStencil(pipelineBuilder, ars); | 342 this->setPipelineBuilderStencil(pipelineBuilder, ars); |
340 return true; | 343 return true; |
341 } | 344 } |
342 // if alpha clip mask creation fails fall through to the non-AA code pat
hs | 345 // if alpha clip mask creation fails fall through to the non-AA code pat
hs |
343 } | 346 } |
344 | 347 |
345 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a
liased clip couldn't | 348 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a
liased clip couldn't |
346 // be created. In either case, free up the texture in the anti-aliased mask
cache. | 349 // be created. In either case, free up the texture in the anti-aliased mask
cache. |
347 // TODO: this may require more investigation. Ganesh performs a lot of utili
ty draws (e.g., | 350 // TODO: this may require more investigation. Ganesh performs a lot of utili
ty draws (e.g., |
348 // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. Th
ese may be | 351 // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. Th
ese may be |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 fAACache.setContext(clipTarget->getContext()); | 1123 fAACache.setContext(clipTarget->getContext()); |
1121 } | 1124 } |
1122 | 1125 |
1123 void GrClipMaskManager::adjustPathStencilParams(const GrStencilBuffer* stencilBu
ffer, | 1126 void GrClipMaskManager::adjustPathStencilParams(const GrStencilBuffer* stencilBu
ffer, |
1124 GrStencilSettings* settings) { | 1127 GrStencilSettings* settings) { |
1125 if (stencilBuffer) { | 1128 if (stencilBuffer) { |
1126 int stencilBits = stencilBuffer->bits(); | 1129 int stencilBits = stencilBuffer->bits(); |
1127 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1130 this->adjustStencilParams(settings, fClipMode, stencilBits); |
1128 } | 1131 } |
1129 } | 1132 } |
OLD | NEW |