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 "GrDrawingManager.h" | 10 #include "GrDrawingManager.h" |
11 #include "GrDrawContextPriv.h" | 11 #include "GrDrawContextPriv.h" |
12 #include "GrDrawTarget.h" | 12 #include "GrDrawTarget.h" |
13 #include "GrGpuResourcePriv.h" | 13 #include "GrGpuResourcePriv.h" |
14 #include "GrPaint.h" | 14 #include "GrPaint.h" |
15 #include "GrPathRenderer.h" | 15 #include "GrPathRenderer.h" |
16 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
17 #include "GrRenderTargetPriv.h" | 17 #include "GrRenderTargetPriv.h" |
18 #include "GrResourceProvider.h" | 18 #include "GrResourceProvider.h" |
| 19 #include "GrInstancedRendering.h" |
19 #include "GrStencilAttachment.h" | 20 #include "GrStencilAttachment.h" |
20 #include "GrSWMaskHelper.h" | 21 #include "GrSWMaskHelper.h" |
21 #include "SkRasterClip.h" | 22 #include "SkRasterClip.h" |
22 #include "SkTLazy.h" | 23 #include "SkTLazy.h" |
23 #include "batches/GrRectBatchFactory.h" | 24 #include "batches/GrRectBatchFactory.h" |
24 #include "effects/GrConvexPolyEffect.h" | 25 #include "effects/GrConvexPolyEffect.h" |
25 #include "effects/GrPorterDuffXferProcessor.h" | 26 #include "effects/GrPorterDuffXferProcessor.h" |
26 #include "effects/GrRRectEffect.h" | 27 #include "effects/GrRRectEffect.h" |
27 #include "effects/GrTextureDomain.h" | 28 #include "effects/GrTextureDomain.h" |
28 | 29 |
(...skipping 12 matching lines...) Expand all Loading... |
41 | 42 |
42 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); | 43 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
43 return GrTextureDomainEffect::Create(result, | 44 return GrTextureDomainEffect::Create(result, |
44 mat, | 45 mat, |
45 GrTextureDomain::MakeTexelDomain(result
, domainTexels), | 46 GrTextureDomain::MakeTexelDomain(result
, domainTexels), |
46 GrTextureDomain::kDecal_Mode, | 47 GrTextureDomain::kDecal_Mode, |
47 GrTextureParams::kNone_FilterMode, | 48 GrTextureParams::kNone_FilterMode, |
48 kDevice_GrCoordSet); | 49 kDevice_GrCoordSet); |
49 } | 50 } |
50 | 51 |
51 static void draw_non_aa_rect(GrDrawTarget* drawTarget, | |
52 const GrPipelineBuilder& pipelineBuilder, | |
53 GrColor color, | |
54 const SkMatrix& viewMatrix, | |
55 const SkRect& rect) { | |
56 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, v
iewMatrix, rect, | |
57 nullptr,
nullptr)); | |
58 drawTarget->drawBatch(pipelineBuilder, batch); | |
59 } | |
60 | |
61 // Does the path in 'element' require SW rendering? If so, return true (and, | 52 // Does the path in 'element' require SW rendering? If so, return true (and, |
62 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set | 53 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set |
63 // 'prOut' to the non-SW path renderer that will do the job). | 54 // 'prOut' to the non-SW path renderer that will do the job). |
64 bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context, | 55 bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context, |
65 bool isStencilDisabled, | 56 bool isStencilDisabled, |
66 const GrRenderTarget* rt, | 57 const GrRenderTarget* rt, |
67 const SkMatrix& viewMatrix, | 58 const SkMatrix& viewMatrix, |
68 const Element* element, | 59 const Element* element, |
69 GrPathRenderer** prOut, | 60 GrPathRenderer** prOut, |
70 bool needsStencil) { | 61 bool needsStencil) { |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 stencilSpaceIBounds.offset(clipSpaceToStencilOffset); | 738 stencilSpaceIBounds.offset(clipSpaceToStencilOffset); |
748 GrClip clip(stencilSpaceIBounds); | 739 GrClip clip(stencilSpaceIBounds); |
749 | 740 |
750 int clipBit = stencilAttachment->bits(); | 741 int clipBit = stencilAttachment->bits(); |
751 SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil
buffers"); | 742 SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil
buffers"); |
752 clipBit = (1 << (clipBit-1)); | 743 clipBit = (1 << (clipBit-1)); |
753 | 744 |
754 fDrawTarget->cmmAccess().clearStencilClip(stencilSpaceIBounds, | 745 fDrawTarget->cmmAccess().clearStencilClip(stencilSpaceIBounds, |
755 GrReducedClip::kAllIn_InitialState == initialState, rt); | 746 GrReducedClip::kAllIn_InitialState == initialState, rt); |
756 | 747 |
| 748 GrInstancedRendering* instRendering = fDrawTarget->instancedRendering(); |
| 749 uint32_t instRenderingFlags; |
| 750 if (instRendering) { |
| 751 instRenderingFlags = GrInstancedRendering::kStencilWrite_Flag | |
| 752 GrInstancedRendering::kCanDiscardFragments_Flag
; |
| 753 if (rt->isStencilBufferMultisampled()) { |
| 754 instRenderingFlags |= GrInstancedRendering::kStencilBufferMSAA_F
lag; |
| 755 } |
| 756 } |
| 757 |
757 // walk through each clip element and perform its set op | 758 // walk through each clip element and perform its set op |
758 // with the existing clip. | 759 // with the existing clip. |
759 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.ge
t(); iter.next()) { | 760 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.ge
t(); iter.next()) { |
760 const Element* element = iter.get(); | 761 const Element* element = iter.get(); |
761 | 762 |
762 GrPipelineBuilder pipelineBuilder; | 763 GrPipelineBuilder pipelineBuilder; |
763 pipelineBuilder.setClip(clip); | 764 pipelineBuilder.setClip(clip); |
764 pipelineBuilder.setRenderTarget(rt); | 765 pipelineBuilder.setRenderTarget(rt); |
765 | 766 |
766 pipelineBuilder.setDisableColorXPFactory(); | 767 pipelineBuilder.setDisableColorXPFactory(); |
767 | 768 |
768 // if the target is MSAA then we want MSAA enabled when the clip is
soft | 769 // if the target is MSAA then we want MSAA enabled when the clip is
soft |
769 if (rt->isStencilBufferMultisampled()) { | 770 if (rt->isStencilBufferMultisampled()) { |
770 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, e
lement->isAA()); | 771 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, e
lement->isAA()); |
771 } | 772 } |
772 | 773 |
773 bool fillInverted = false; | 774 bool fillInverted = false; |
774 // enabled at bottom of loop | 775 // enabled at bottom of loop |
775 fClipMode = kIgnoreClip_StencilClipMode; | 776 fClipMode = kIgnoreClip_StencilClipMode; |
776 | 777 |
777 // This will be used to determine whether the clip shape can be rend
ered into the | 778 // This will be used to determine whether the clip shape can be rend
ered into the |
778 // stencil with arbitrary stencil settings. | 779 // stencil with arbitrary stencil settings. |
779 GrPathRenderer::StencilSupport stencilSupport; | 780 GrPathRenderer::StencilSupport stencilSupport; |
780 | 781 |
781 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); | 782 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
782 SkRegion::Op op = element->getOp(); | 783 SkRegion::Op op = element->getOp(); |
783 | 784 |
| 785 SkAutoTUnref<GrDrawBatch> fastBatch; |
| 786 if (Element::kPath_Type != element->getType()) { |
| 787 if (instRendering) { |
| 788 fastBatch.reset(instRendering->recordRRect(element->asRRect(
), viewMatrix, |
| 789 GrColor_WHITE, |
| 790 pipelineBuilder.i
sHWAntialias(), |
| 791 instRenderingFlag
s)); |
| 792 } |
| 793 if (!fastBatch && Element::kRect_Type == element->getType()) { |
| 794 fastBatch.reset(GrRectBatchFactory::CreateNonAAFill(GrColor_
WHITE, viewMatrix, |
| 795 element-
>getRect(), nullptr, |
| 796 nullptr)
); |
| 797 } |
| 798 } |
| 799 |
784 GrPathRenderer* pr = nullptr; | 800 GrPathRenderer* pr = nullptr; |
785 SkPath clipPath; | 801 SkPath clipPath; |
786 if (Element::kRect_Type == element->getType()) { | 802 if (fastBatch) { |
787 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; | 803 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
788 fillInverted = false; | 804 fillInverted = false; |
789 } else { | 805 } else { |
790 element->asPath(&clipPath); | 806 element->asPath(&clipPath); |
791 fillInverted = clipPath.isInverseFillType(); | 807 fillInverted = clipPath.isInverseFillType(); |
792 if (fillInverted) { | 808 if (fillInverted) { |
793 clipPath.toggleInverseFillType(); | 809 clipPath.toggleInverseFillType(); |
794 } | 810 } |
795 | 811 |
796 SkASSERT(pipelineBuilder.getStencil().isDisabled()); | 812 SkASSERT(pipelineBuilder.getStencil().isDisabled()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 | 846 |
831 // draw the element to the client stencil bits if necessary | 847 // draw the element to the client stencil bits if necessary |
832 if (!canDrawDirectToClip) { | 848 if (!canDrawDirectToClip) { |
833 GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, | 849 GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, |
834 kIncClamp_StencilOp, | 850 kIncClamp_StencilOp, |
835 kIncClamp_StencilOp, | 851 kIncClamp_StencilOp, |
836 kAlways_StencilFunc, | 852 kAlways_StencilFunc, |
837 0xffff, | 853 0xffff, |
838 0x0000, | 854 0x0000, |
839 0xffff); | 855 0xffff); |
840 if (Element::kRect_Type == element->getType()) { | 856 if (fastBatch) { |
841 *pipelineBuilder.stencil() = gDrawToStencil; | 857 *pipelineBuilder.stencil() = gDrawToStencil; |
842 | 858 fDrawTarget->drawBatch(pipelineBuilder, fastBatch); |
843 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE
, viewMatrix, | |
844 element->getRect()); | |
845 } else { | 859 } else { |
846 if (!clipPath.isEmpty()) { | 860 if (!clipPath.isEmpty()) { |
847 if (canRenderDirectToStencil) { | 861 if (canRenderDirectToStencil) { |
848 *pipelineBuilder.stencil() = gDrawToStencil; | 862 *pipelineBuilder.stencil() = gDrawToStencil; |
849 | 863 |
850 GrPathRenderer::DrawPathArgs args; | 864 GrPathRenderer::DrawPathArgs args; |
851 args.fTarget = fDrawTarget; | 865 args.fTarget = fDrawTarget; |
852 args.fResourceProvider = this->getContext()->resourc
eProvider(); | 866 args.fResourceProvider = this->getContext()->resourc
eProvider(); |
853 args.fPipelineBuilder = &pipelineBuilder; | 867 args.fPipelineBuilder = &pipelineBuilder; |
854 args.fColor = GrColor_WHITE; | 868 args.fColor = GrColor_WHITE; |
(...skipping 17 matching lines...) Expand all Loading... |
872 } | 886 } |
873 } | 887 } |
874 | 888 |
875 // now we modify the clip bit by rendering either the clip | 889 // now we modify the clip bit by rendering either the clip |
876 // element directly or a bounding rect of the entire clip. | 890 // element directly or a bounding rect of the entire clip. |
877 fClipMode = kModifyClip_StencilClipMode; | 891 fClipMode = kModifyClip_StencilClipMode; |
878 for (int p = 0; p < passes; ++p) { | 892 for (int p = 0; p < passes; ++p) { |
879 *pipelineBuilder.stencil() = stencilSettings[p]; | 893 *pipelineBuilder.stencil() = stencilSettings[p]; |
880 | 894 |
881 if (canDrawDirectToClip) { | 895 if (canDrawDirectToClip) { |
882 if (Element::kRect_Type == element->getType()) { | 896 if (fastBatch) { |
883 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_W
HITE, viewMatrix, | 897 fDrawTarget->drawBatch(pipelineBuilder, fastBatch); |
884 element->getRect()); | |
885 } else { | 898 } else { |
886 GrPathRenderer::DrawPathArgs args; | 899 GrPathRenderer::DrawPathArgs args; |
887 args.fTarget = fDrawTarget; | 900 args.fTarget = fDrawTarget; |
888 args.fResourceProvider = this->getContext()->resourcePro
vider(); | 901 args.fResourceProvider = this->getContext()->resourcePro
vider(); |
889 args.fPipelineBuilder = &pipelineBuilder; | 902 args.fPipelineBuilder = &pipelineBuilder; |
890 args.fColor = GrColor_WHITE; | 903 args.fColor = GrColor_WHITE; |
891 args.fViewMatrix = &viewMatrix; | 904 args.fViewMatrix = &viewMatrix; |
892 args.fPath = &clipPath; | 905 args.fPath = &clipPath; |
893 args.fStroke = &stroke; | 906 args.fStroke = &stroke; |
894 args.fAntiAlias = false; | 907 args.fAntiAlias = false; |
895 args.fGammaCorrect = false; | 908 args.fGammaCorrect = false; |
896 pr->drawPath(args); | 909 pr->drawPath(args); |
897 } | 910 } |
898 } else { | 911 } else { |
899 // The view matrix is setup to do clip space -> stencil spac
e translation, so | 912 // The view matrix is setup to do clip space -> stencil spac
e translation, so |
900 // draw rect in clip space. | 913 // draw rect in clip space. |
901 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE
, viewMatrix, | 914 const SkRect& clipSpaceRect = SkRect::Make(clipSpaceIBounds)
; |
902 SkRect::Make(clipSpaceIBounds)); | 915 SkAutoTUnref<GrDrawBatch> coverBatch; |
| 916 if (instRendering) { |
| 917 coverBatch.reset(instRendering->recordRect(clipSpaceRect
, viewMatrix, |
| 918 GrColor_WHITE
, |
| 919 pipelineBuild
er.isHWAntialias(), |
| 920 instRendering
Flags)); |
| 921 } |
| 922 if (!coverBatch) { |
| 923 coverBatch.reset(GrRectBatchFactory::CreateNonAAFill(GrC
olor_WHITE, |
| 924 vie
wMatrix, |
| 925 cli
pSpaceRect, |
| 926 nul
lptr, nullptr)); |
| 927 } |
| 928 fDrawTarget->drawBatch(pipelineBuilder, coverBatch); |
903 } | 929 } |
904 } | 930 } |
905 } | 931 } |
906 } | 932 } |
907 fClipMode = kRespectClip_StencilClipMode; | 933 fClipMode = kRespectClip_StencilClipMode; |
908 return true; | 934 return true; |
909 } | 935 } |
910 | 936 |
911 // mapping of clip-respecting stencil funcs to normal stencil funcs | 937 // mapping of clip-respecting stencil funcs to normal stencil funcs |
912 // mapping depends on whether stencil-clipping is in effect. | 938 // mapping depends on whether stencil-clipping is in effect. |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 | 1182 |
1157 //////////////////////////////////////////////////////////////////////////////// | 1183 //////////////////////////////////////////////////////////////////////////////// |
1158 | 1184 |
1159 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, | 1185 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, |
1160 GrStencilSettings* settings) { | 1186 GrStencilSettings* settings) { |
1161 if (stencilAttachment) { | 1187 if (stencilAttachment) { |
1162 int stencilBits = stencilAttachment->bits(); | 1188 int stencilBits = stencilAttachment->bits(); |
1163 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1189 this->adjustStencilParams(settings, fClipMode, stencilBits); |
1164 } | 1190 } |
1165 } | 1191 } |
OLD | NEW |