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