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" |
11 #include "GrAARectRenderer.h" | 11 #include "GrAARectRenderer.h" |
12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
13 #include "GrPaint.h" | 13 #include "GrPaint.h" |
14 #include "GrPathRenderer.h" | 14 #include "GrPathRenderer.h" |
15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
17 #include "GrStencilAttachment.h" | 17 #include "GrStencilAttachment.h" |
18 #include "GrSWMaskHelper.h" | 18 #include "GrSWMaskHelper.h" |
19 #include "SkRasterClip.h" | 19 #include "SkRasterClip.h" |
20 #include "SkStrokeRec.h" | |
21 #include "SkTLazy.h" | 20 #include "SkTLazy.h" |
22 #include "effects/GrConvexPolyEffect.h" | 21 #include "effects/GrConvexPolyEffect.h" |
23 #include "effects/GrPorterDuffXferProcessor.h" | 22 #include "effects/GrPorterDuffXferProcessor.h" |
24 #include "effects/GrRRectEffect.h" | 23 #include "effects/GrRRectEffect.h" |
25 #include "effects/GrTextureDomain.h" | 24 #include "effects/GrTextureDomain.h" |
26 | 25 |
27 typedef SkClipStack::Element Element; | 26 typedef SkClipStack::Element Element; |
28 | 27 |
29 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
30 namespace { | 29 namespace { |
(...skipping 22 matching lines...) Expand all Loading... |
53 GrTextureDomain::kDecal_Mode, | 52 GrTextureDomain::kDecal_Mode, |
54 GrTextureParams::kNone_FilterMode, | 53 GrTextureParams::kNone_FilterMode, |
55 kDevice_GrCoordSet))->unref(); | 54 kDevice_GrCoordSet))->unref(); |
56 } | 55 } |
57 | 56 |
58 bool path_needs_SW_renderer(GrContext* context, | 57 bool path_needs_SW_renderer(GrContext* context, |
59 const GrDrawTarget* gpu, | 58 const GrDrawTarget* gpu, |
60 const GrPipelineBuilder* pipelineBuilder, | 59 const GrPipelineBuilder* pipelineBuilder, |
61 const SkMatrix& viewMatrix, | 60 const SkMatrix& viewMatrix, |
62 const SkPath& origPath, | 61 const SkPath& origPath, |
63 const SkStrokeRec& stroke, | 62 const GrStrokeInfo& stroke, |
64 bool doAA) { | 63 bool doAA) { |
65 // the gpu alpha mask will draw the inverse paths as non-inverse to a temp b
uffer | 64 // the gpu alpha mask will draw the inverse paths as non-inverse to a temp b
uffer |
66 SkTCopyOnFirstWrite<SkPath> path(origPath); | 65 SkTCopyOnFirstWrite<SkPath> path(origPath); |
67 if (path->isInverseFillType()) { | 66 if (path->isInverseFillType()) { |
68 path.writable()->toggleInverseFillType(); | 67 path.writable()->toggleInverseFillType(); |
69 } | 68 } |
70 // last (false) parameter disallows use of the SW path renderer | 69 // last (false) parameter disallows use of the SW path renderer |
71 GrPathRendererChain::DrawType type = doAA ? | 70 GrPathRendererChain::DrawType type = doAA ? |
72 GrPathRendererChain::kColorAntiAlias_Dr
awType : | 71 GrPathRendererChain::kColorAntiAlias_Dr
awType : |
73 GrPathRendererChain::kColor_DrawType; | 72 GrPathRendererChain::kColor_DrawType; |
74 | 73 |
75 return NULL == context->getPathRenderer(gpu, pipelineBuilder, viewMatrix, *p
ath, stroke, | 74 return NULL == context->getPathRenderer(gpu, pipelineBuilder, viewMatrix, *p
ath, stroke, |
76 false, type); | 75 false, type); |
77 } | 76 } |
78 } | 77 } |
79 | 78 |
80 /* | 79 /* |
81 * This method traverses the clip stack to see if the GrSoftwarePathRenderer | 80 * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
82 * will be used on any element. If so, it returns true to indicate that the | 81 * will be used on any element. If so, it returns true to indicate that the |
83 * entire clip should be rendered in SW and then uploaded en masse to the gpu. | 82 * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
84 */ | 83 */ |
85 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder* pipelineBuilder, | 84 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder* pipelineBuilder, |
86 const SkVector& clipToMaskOffset, | 85 const SkVector& clipToMaskOffset, |
87 const GrReducedClip::ElementList& elements
) { | 86 const GrReducedClip::ElementList& elements
) { |
88 // TODO: generalize this function so that when | 87 // TODO: generalize this function so that when |
89 // a clip gets complex enough it can just be done in SW regardless | 88 // a clip gets complex enough it can just be done in SW regardless |
90 // of whether it would invoke the GrSoftwarePathRenderer. | 89 // of whether it would invoke the GrSoftwarePathRenderer. |
91 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); | 90 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
92 | 91 |
93 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip | 92 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip |
94 // space. | 93 // space. |
95 SkMatrix translate; | 94 SkMatrix translate; |
96 translate.setTranslate(clipToMaskOffset); | 95 translate.setTranslate(clipToMaskOffset); |
97 | 96 |
98 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get();
iter.next()) { | 97 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get();
iter.next()) { |
99 const Element* element = iter.get(); | 98 const Element* element = iter.get(); |
100 // rects can always be drawn directly w/o using the software path | 99 // rects can always be drawn directly w/o using the software path |
101 // Skip rrects once we're drawing them directly. | 100 // Skip rrects once we're drawing them directly. |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 fClipTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix,
element->getRect()); | 405 fClipTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix,
element->getRect()); |
407 } | 406 } |
408 return true; | 407 return true; |
409 default: { | 408 default: { |
410 SkPath path; | 409 SkPath path; |
411 element->asPath(&path); | 410 element->asPath(&path); |
412 path.setIsVolatile(true); | 411 path.setIsVolatile(true); |
413 if (path.isInverseFillType()) { | 412 if (path.isInverseFillType()) { |
414 path.toggleInverseFillType(); | 413 path.toggleInverseFillType(); |
415 } | 414 } |
416 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); | 415 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
417 if (NULL == pr) { | 416 if (NULL == pr) { |
418 GrPathRendererChain::DrawType type; | 417 GrPathRendererChain::DrawType type; |
419 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr
awType : | 418 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr
awType : |
420 GrPathRendererChain::kColor_DrawType; | 419 GrPathRendererChain::kColor_DrawType; |
421 pr = this->getContext()->getPathRenderer(fClipTarget, pipelineBu
ilder, viewMatrix, | 420 pr = this->getContext()->getPathRenderer(fClipTarget, pipelineBu
ilder, viewMatrix, |
422 path, stroke, false, ty
pe); | 421 path, stroke, false, ty
pe); |
423 } | 422 } |
424 if (NULL == pr) { | 423 if (NULL == pr) { |
425 return false; | 424 return false; |
426 } | 425 } |
(...skipping 15 matching lines...) Expand all Loading... |
442 if (Element::kRect_Type == element->getType()) { | 441 if (Element::kRect_Type == element->getType()) { |
443 return true; | 442 return true; |
444 } else { | 443 } else { |
445 // We shouldn't get here with an empty clip element. | 444 // We shouldn't get here with an empty clip element. |
446 SkASSERT(Element::kEmpty_Type != element->getType()); | 445 SkASSERT(Element::kEmpty_Type != element->getType()); |
447 SkPath path; | 446 SkPath path; |
448 element->asPath(&path); | 447 element->asPath(&path); |
449 if (path.isInverseFillType()) { | 448 if (path.isInverseFillType()) { |
450 path.toggleInverseFillType(); | 449 path.toggleInverseFillType(); |
451 } | 450 } |
452 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); | 451 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
453 GrPathRendererChain::DrawType type = element->isAA() ? | 452 GrPathRendererChain::DrawType type = element->isAA() ? |
454 GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : | 453 GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : |
455 GrPathRendererChain::kStencilAndColor_DrawType; | 454 GrPathRendererChain::kStencilAndColor_DrawType; |
456 *pr = this->getContext()->getPathRenderer(fClipTarget, pipelineBuilder,
SkMatrix::I(), path, | 455 *pr = this->getContext()->getPathRenderer(fClipTarget, pipelineBuilder,
SkMatrix::I(), path, |
457 stroke, false, type); | 456 stroke, false, type); |
458 return SkToBool(*pr); | 457 return SkToBool(*pr); |
459 } | 458 } |
460 } | 459 } |
461 | 460 |
462 void GrClipMaskManager::mergeMask(GrPipelineBuilder* pipelineBuilder, | 461 void GrClipMaskManager::mergeMask(GrPipelineBuilder* pipelineBuilder, |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 750 } |
752 | 751 |
753 bool fillInverted = false; | 752 bool fillInverted = false; |
754 // enabled at bottom of loop | 753 // enabled at bottom of loop |
755 fClipMode = kIgnoreClip_StencilClipMode; | 754 fClipMode = kIgnoreClip_StencilClipMode; |
756 | 755 |
757 // This will be used to determine whether the clip shape can be rend
ered into the | 756 // This will be used to determine whether the clip shape can be rend
ered into the |
758 // stencil with arbitrary stencil settings. | 757 // stencil with arbitrary stencil settings. |
759 GrPathRenderer::StencilSupport stencilSupport; | 758 GrPathRenderer::StencilSupport stencilSupport; |
760 | 759 |
761 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); | 760 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
762 SkRegion::Op op = element->getOp(); | 761 SkRegion::Op op = element->getOp(); |
763 | 762 |
764 GrPathRenderer* pr = NULL; | 763 GrPathRenderer* pr = NULL; |
765 SkPath clipPath; | 764 SkPath clipPath; |
766 if (Element::kRect_Type == element->getType()) { | 765 if (Element::kRect_Type == element->getType()) { |
767 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; | 766 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
768 fillInverted = false; | 767 fillInverted = false; |
769 } else { | 768 } else { |
770 element->asPath(&clipPath); | 769 element->asPath(&clipPath); |
771 fillInverted = clipPath.isInverseFillType(); | 770 fillInverted = clipPath.isInverseFillType(); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 fAACache.setContext(clipTarget->getContext()); | 1126 fAACache.setContext(clipTarget->getContext()); |
1128 } | 1127 } |
1129 | 1128 |
1130 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, | 1129 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, |
1131 GrStencilSettings* settings) { | 1130 GrStencilSettings* settings) { |
1132 if (stencilAttachment) { | 1131 if (stencilAttachment) { |
1133 int stencilBits = stencilAttachment->bits(); | 1132 int stencilBits = stencilAttachment->bits(); |
1134 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1133 this->adjustStencilParams(settings, fClipMode, stencilBits); |
1135 } | 1134 } |
1136 } | 1135 } |
OLD | NEW |