| 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 "GrCaps.h" | 9 #include "GrCaps.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 type = element->isAA() | 80 type = element->isAA() |
| 81 ? GrPathRendererChain::kStencilAndColorAntiAlias_Dra
wType | 81 ? GrPathRendererChain::kStencilAndColorAntiAlias_Dra
wType |
| 82 : GrPathRendererChain::kStencilAndColor_DrawType; | 82 : GrPathRendererChain::kStencilAndColor_DrawType; |
| 83 } else { | 83 } else { |
| 84 type = element->isAA() | 84 type = element->isAA() |
| 85 ? GrPathRendererChain::kColorAntiAlias_DrawType | 85 ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 86 : GrPathRendererChain::kColor_DrawType; | 86 : GrPathRendererChain::kColor_DrawType; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // the 'false' parameter disallows use of the SW path renderer | 89 // the 'false' parameter disallows use of the SW path renderer |
| 90 GrPathRenderer* pr = context->getPathRenderer(&pipelineBuilder, viewMatr
ix, path, | 90 GrPathRenderer* pr = context->getPathRenderer(pipelineBuilder, viewMatri
x, path, |
| 91 stroke, false, type); | 91 stroke, false, type); |
| 92 if (tryStencilFirst && !pr) { | 92 if (tryStencilFirst && !pr) { |
| 93 // If the path can't be stenciled, createAlphaClipMask falls back to
color rendering | 93 // If the path can't be stenciled, createAlphaClipMask falls back to
color rendering |
| 94 // it into a temporary buffer. If that fails then SW is truly requir
ed. | 94 // it into a temporary buffer. If that fails then SW is truly requir
ed. |
| 95 type = element->isAA() | 95 type = element->isAA() |
| 96 ? GrPathRendererChain::kColorAntiAlias_DrawType | 96 ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 97 : GrPathRendererChain::kColor_DrawType; | 97 : GrPathRendererChain::kColor_DrawType; |
| 98 | 98 |
| 99 pr = context->getPathRenderer(&pipelineBuilder, viewMatrix, path, st
roke, false, type); | 99 pr = context->getPathRenderer(pipelineBuilder, viewMatrix, path, str
oke, false, type); |
| 100 } | 100 } |
| 101 | 101 |
| 102 if (prOut) { | 102 if (prOut) { |
| 103 *prOut = pr; | 103 *prOut = pr; |
| 104 } | 104 } |
| 105 return SkToBool(!pr); | 105 return SkToBool(!pr); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget) | 109 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 120 */ | 120 */ |
| 121 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder& pipelineBuilder, | 121 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder& pipelineBuilder, |
| 122 const SkVector& clipToMaskOffset, | 122 const SkVector& clipToMaskOffset, |
| 123 const GrReducedClip::ElementList& elements
) { | 123 const GrReducedClip::ElementList& elements
) { |
| 124 // TODO: generalize this function so that when | 124 // TODO: generalize this function so that when |
| 125 // a clip gets complex enough it can just be done in SW regardless | 125 // a clip gets complex enough it can just be done in SW regardless |
| 126 // of whether it would invoke the GrSoftwarePathRenderer. | 126 // of whether it would invoke the GrSoftwarePathRenderer. |
| 127 | 127 |
| 128 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip | 128 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip |
| 129 // space. | 129 // space. |
| 130 SkMatrix translate; | 130 const SkMatrix translate = SkMatrix::MakeTrans(clipToMaskOffset.fX, clipToMa
skOffset.fY); |
| 131 translate.setTranslate(clipToMaskOffset); | |
| 132 | 131 |
| 133 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get();
iter.next()) { | 132 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get();
iter.next()) { |
| 134 const Element* element = iter.get(); | 133 const Element* element = iter.get(); |
| 135 | 134 |
| 136 SkRegion::Op op = element->getOp(); | 135 SkRegion::Op op = element->getOp(); |
| 137 bool invert = element->isInverseFilled(); | 136 bool invert = element->isInverseFilled(); |
| 138 bool tryStencilFirst = invert || | 137 bool tryStencilFirst = invert || |
| 139 SkRegion::kIntersect_Op == op || | 138 SkRegion::kIntersect_Op == op || |
| 140 SkRegion::kReverseDifference_Op == op; | 139 SkRegion::kReverseDifference_Op == op; |
| 141 | 140 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 SkPath path; | 445 SkPath path; |
| 447 element->asPath(&path); | 446 element->asPath(&path); |
| 448 if (path.isInverseFillType()) { | 447 if (path.isInverseFillType()) { |
| 449 path.toggleInverseFillType(); | 448 path.toggleInverseFillType(); |
| 450 } | 449 } |
| 451 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); | 450 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
| 452 if (nullptr == pr) { | 451 if (nullptr == pr) { |
| 453 GrPathRendererChain::DrawType type; | 452 GrPathRendererChain::DrawType type; |
| 454 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr
awType : | 453 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr
awType : |
| 455 GrPathRendererChain::kColor_DrawType; | 454 GrPathRendererChain::kColor_DrawType; |
| 456 pr = this->getContext()->getPathRenderer(pipelineBuilder, viewMa
trix, | 455 pr = this->getContext()->getPathRenderer(*pipelineBuilder, viewM
atrix, |
| 457 path, stroke, false, ty
pe); | 456 path, stroke, false, ty
pe); |
| 458 } | 457 } |
| 459 if (nullptr == pr) { | 458 if (nullptr == pr) { |
| 460 return false; | 459 return false; |
| 461 } | 460 } |
| 462 GrPathRenderer::DrawPathArgs args; | 461 GrPathRenderer::DrawPathArgs args; |
| 463 args.fTarget = fDrawTarget; | 462 args.fTarget = fDrawTarget; |
| 464 args.fResourceProvider = this->getContext()->resourceProvider(); | 463 args.fResourceProvider = this->getContext()->resourceProvider(); |
| 465 args.fPipelineBuilder = pipelineBuilder; | 464 args.fPipelineBuilder = pipelineBuilder; |
| 466 args.fColor = color; | 465 args.fColor = color; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 488 SkASSERT(Element::kEmpty_Type != element->getType()); | 487 SkASSERT(Element::kEmpty_Type != element->getType()); |
| 489 SkPath path; | 488 SkPath path; |
| 490 element->asPath(&path); | 489 element->asPath(&path); |
| 491 if (path.isInverseFillType()) { | 490 if (path.isInverseFillType()) { |
| 492 path.toggleInverseFillType(); | 491 path.toggleInverseFillType(); |
| 493 } | 492 } |
| 494 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); | 493 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
| 495 GrPathRendererChain::DrawType type = element->isAA() ? | 494 GrPathRendererChain::DrawType type = element->isAA() ? |
| 496 GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : | 495 GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : |
| 497 GrPathRendererChain::kStencilAndColor_DrawType; | 496 GrPathRendererChain::kStencilAndColor_DrawType; |
| 498 *pr = this->getContext()->getPathRenderer(pipelineBuilder, SkMatrix::I()
, path, | 497 *pr = this->getContext()->getPathRenderer(*pipelineBuilder, SkMatrix::I(
), path, |
| 499 stroke, false, type); | 498 stroke, false, type); |
| 500 return SkToBool(*pr); | 499 return SkToBool(*pr); |
| 501 } | 500 } |
| 502 } | 501 } |
| 503 | 502 |
| 504 void GrClipMaskManager::mergeMask(GrPipelineBuilder* pipelineBuilder, | 503 void GrClipMaskManager::mergeMask(GrPipelineBuilder* pipelineBuilder, |
| 505 GrTexture* dstMask, | 504 GrTexture* dstMask, |
| 506 GrTexture* srcMask, | 505 GrTexture* srcMask, |
| 507 SkRegion::Op op, | 506 SkRegion::Op op, |
| 508 const SkIRect& dstBound, | 507 const SkIRect& dstBound, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 SkAutoTUnref<GrTexture> texture(this->createCachedMask( | 588 SkAutoTUnref<GrTexture> texture(this->createCachedMask( |
| 590 clipSpaceIBounds.width(), clipSpaceIBounds.height(), key, true)); | 589 clipSpaceIBounds.width(), clipSpaceIBounds.height(), key, true)); |
| 591 | 590 |
| 592 // There's no texture in the cache. Let's try to allocate it then. | 591 // There's no texture in the cache. Let's try to allocate it then. |
| 593 if (!texture) { | 592 if (!texture) { |
| 594 return nullptr; | 593 return nullptr; |
| 595 } | 594 } |
| 596 | 595 |
| 597 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip | 596 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip |
| 598 // space. | 597 // space. |
| 599 SkMatrix translate; | 598 const SkMatrix translate = SkMatrix::MakeTrans(clipToMaskOffset.fX, clipToMa
skOffset.fY); |
| 600 translate.setTranslate(clipToMaskOffset); | |
| 601 | 599 |
| 602 // The texture may be larger than necessary, this rect represents the part o
f the texture | 600 // The texture may be larger than necessary, this rect represents the part o
f the texture |
| 603 // we populate with a rasterization of the clip. | 601 // we populate with a rasterization of the clip. |
| 604 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); | 602 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); |
| 605 | 603 |
| 606 // The scratch texture that we are drawing into can be substantially larger
than the mask. Only | 604 // The scratch texture that we are drawing into can be substantially larger
than the mask. Only |
| 607 // clear the part that we care about. | 605 // clear the part that we care about. |
| 608 fDrawTarget->clear(&maskSpaceIBounds, | 606 fDrawTarget->clear(&maskSpaceIBounds, |
| 609 GrReducedClip::kAllIn_InitialState == initialState ? 0xff
ffffff : 0x00000000, | 607 GrReducedClip::kAllIn_InitialState == initialState ? 0xff
ffffff : 0x00000000, |
| 610 true, | 608 true, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 SkPath clipPath; | 791 SkPath clipPath; |
| 794 if (Element::kRect_Type == element->getType()) { | 792 if (Element::kRect_Type == element->getType()) { |
| 795 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; | 793 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 796 fillInverted = false; | 794 fillInverted = false; |
| 797 } else { | 795 } else { |
| 798 element->asPath(&clipPath); | 796 element->asPath(&clipPath); |
| 799 fillInverted = clipPath.isInverseFillType(); | 797 fillInverted = clipPath.isInverseFillType(); |
| 800 if (fillInverted) { | 798 if (fillInverted) { |
| 801 clipPath.toggleInverseFillType(); | 799 clipPath.toggleInverseFillType(); |
| 802 } | 800 } |
| 803 pr = this->getContext()->getPathRenderer(&pipelineBuilder, | 801 pr = this->getContext()->getPathRenderer(pipelineBuilder, |
| 804 viewMatrix, | 802 viewMatrix, |
| 805 clipPath, | 803 clipPath, |
| 806 stroke, | 804 stroke, |
| 807 false, | 805 false, |
| 808 GrPathRendererChain::kS
tencilOnly_DrawType, | 806 GrPathRendererChain::kS
tencilOnly_DrawType, |
| 809 &stencilSupport); | 807 &stencilSupport); |
| 810 if (nullptr == pr) { | 808 if (nullptr == pr) { |
| 811 return false; | 809 return false; |
| 812 } | 810 } |
| 813 } | 811 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 | 1154 |
| 1157 //////////////////////////////////////////////////////////////////////////////// | 1155 //////////////////////////////////////////////////////////////////////////////// |
| 1158 | 1156 |
| 1159 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, | 1157 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, |
| 1160 GrStencilSettings* settings) { | 1158 GrStencilSettings* settings) { |
| 1161 if (stencilAttachment) { | 1159 if (stencilAttachment) { |
| 1162 int stencilBits = stencilAttachment->bits(); | 1160 int stencilBits = stencilAttachment->bits(); |
| 1163 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1161 this->adjustStencilParams(settings, fClipMode, stencilBits); |
| 1164 } | 1162 } |
| 1165 } | 1163 } |
| OLD | NEW |