Chromium Code Reviews| 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 "GrDrawContext.h" | 11 #include "GrDrawContext.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 "GrStencilAttachment.h" | 19 #include "GrStencilAttachment.h" |
| 20 #include "GrSWMaskHelper.h" | 20 #include "GrSWMaskHelper.h" |
| 21 #include "SkRasterClip.h" | 21 #include "SkRasterClip.h" |
| 22 #include "SkTLazy.h" | 22 #include "SkTLazy.h" |
| 23 #include "batches/GrRectBatchFactory.h" | |
| 23 #include "effects/GrConvexPolyEffect.h" | 24 #include "effects/GrConvexPolyEffect.h" |
| 24 #include "effects/GrPorterDuffXferProcessor.h" | 25 #include "effects/GrPorterDuffXferProcessor.h" |
| 25 #include "effects/GrRRectEffect.h" | 26 #include "effects/GrRRectEffect.h" |
| 26 #include "effects/GrTextureDomain.h" | 27 #include "effects/GrTextureDomain.h" |
| 27 | 28 |
| 28 typedef SkClipStack::Element Element; | 29 typedef SkClipStack::Element Element; |
| 29 | 30 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 31 // set up the draw state to enable the aa clipping mask. Besides setting up the | 32 // set up the draw state to enable the aa clipping mask. Besides setting up the |
| 32 // stage matrix this also alters the vertex layout | 33 // stage matrix this also alters the vertex layout |
| 33 static const GrFragmentProcessor* create_fp_for_mask(GrTexture* result, const Sk IRect &devBound) { | 34 static const GrFragmentProcessor* create_fp_for_mask(GrTexture* result, const Sk IRect &devBound) { |
| 34 SkMatrix mat; | 35 SkMatrix mat; |
| 35 // We use device coords to compute the texture coordinates. We set our matri x to be a | 36 // We use device coords to compute the texture coordinates. We set our matri x to be a |
| 36 // translation to the devBound, and then a scaling matrix to normalized coor ds. | 37 // translation to the devBound, and then a scaling matrix to normalized coor ds. |
| 37 mat.setIDiv(result->width(), result->height()); | 38 mat.setIDiv(result->width(), result->height()); |
| 38 mat.preTranslate(SkIntToScalar(-devBound.fLeft), | 39 mat.preTranslate(SkIntToScalar(-devBound.fLeft), |
| 39 SkIntToScalar(-devBound.fTop)); | 40 SkIntToScalar(-devBound.fTop)); |
| 40 | 41 |
| 41 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); | 42 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
| 42 return GrTextureDomainEffect::Create(result, | 43 return GrTextureDomainEffect::Create(result, |
| 43 mat, | 44 mat, |
| 44 GrTextureDomain::MakeTexelDomain(result , domainTexels), | 45 GrTextureDomain::MakeTexelDomain(result , domainTexels), |
| 45 GrTextureDomain::kDecal_Mode, | 46 GrTextureDomain::kDecal_Mode, |
| 46 GrTextureParams::kNone_FilterMode, | 47 GrTextureParams::kNone_FilterMode, |
| 47 kDevice_GrCoordSet); | 48 kDevice_GrCoordSet); |
| 48 } | 49 } |
| 49 | 50 |
|
robertphillips
2016/01/13 20:17:07
Didn't we add something just like this in the prio
| |
| 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 | |
| 50 // Does the path in 'element' require SW rendering? If so, return true (and, | 61 // Does the path in 'element' require SW rendering? If so, return true (and, |
| 51 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set | 62 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set |
| 52 // 'prOut' to the non-SW path renderer that will do the job). | 63 // 'prOut' to the non-SW path renderer that will do the job). |
| 53 bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context, | 64 bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context, |
| 54 bool isStencilDisabled, | 65 bool isStencilDisabled, |
| 55 const GrRenderTarget* rt, | 66 const GrRenderTarget* rt, |
| 56 const SkMatrix& viewMatrix, | 67 const SkMatrix& viewMatrix, |
| 57 const Element* element, | 68 const Element* element, |
| 58 GrPathRenderer** prOut, | 69 GrPathRenderer** prOut, |
| 59 bool needsStencil) { | 70 bool needsStencil) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 | 510 |
| 500 // The color we use to draw does not matter since we will always be using a GrCoverageSetOpXP | 511 // The color we use to draw does not matter since we will always be using a GrCoverageSetOpXP |
| 501 // which ignores color. | 512 // which ignores color. |
| 502 GrColor color = GrColor_WHITE; | 513 GrColor color = GrColor_WHITE; |
| 503 | 514 |
| 504 // TODO: Draw rrects directly here. | 515 // TODO: Draw rrects directly here. |
| 505 switch (element->getType()) { | 516 switch (element->getType()) { |
| 506 case Element::kEmpty_Type: | 517 case Element::kEmpty_Type: |
| 507 SkDEBUGFAIL("Should never get here with an empty element."); | 518 SkDEBUGFAIL("Should never get here with an empty element."); |
| 508 break; | 519 break; |
| 509 case Element::kRect_Type: | 520 case Element::kRect_Type: { |
| 510 // TODO: Do rects directly to the accumulator using a aa-rect GrProc essor that covers | 521 // TODO: Do rects directly to the accumulator using a aa-rect GrProc essor that covers |
| 511 // the entire mask bounds and writes 0 outside the rect. | 522 // the entire mask bounds and writes 0 outside the rect. |
| 512 if (element->isAA()) { | 523 if (element->isAA()) { |
| 513 SkRect devRect = element->getRect(); | 524 SkRect devRect = element->getRect(); |
| 514 viewMatrix.mapRect(&devRect); | 525 viewMatrix.mapRect(&devRect); |
| 515 | 526 |
| 516 fDrawTarget->drawAARect(*pipelineBuilder, color, viewMatrix, | 527 SkAutoTUnref<GrDrawBatch> batch( |
| 517 element->getRect(), devRect); | 528 GrRectBatchFactory::CreateAAFill(color, viewMatrix, elem ent->getRect(), |
| 529 devRect)); | |
| 530 | |
| 531 fDrawTarget->drawBatch(*pipelineBuilder, batch); | |
| 518 } else { | 532 } else { |
| 519 fDrawTarget->drawNonAARect(*pipelineBuilder, color, viewMatrix, | 533 draw_non_aa_rect(fDrawTarget, *pipelineBuilder, color, viewMatri x, |
| 520 element->getRect()); | 534 element->getRect()); |
| 521 } | 535 } |
| 522 return true; | 536 return true; |
| 537 } | |
| 523 default: { | 538 default: { |
| 524 SkPath path; | 539 SkPath path; |
| 525 element->asPath(&path); | 540 element->asPath(&path); |
| 526 if (path.isInverseFillType()) { | 541 if (path.isInverseFillType()) { |
| 527 path.toggleInverseFillType(); | 542 path.toggleInverseFillType(); |
| 528 } | 543 } |
| 529 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); | 544 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); |
| 530 if (nullptr == pr) { | 545 if (nullptr == pr) { |
| 531 GrPathRendererChain::DrawType type; | 546 GrPathRendererChain::DrawType type; |
| 532 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr awType : | 547 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr awType : |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 GR_STATIC_CONST_SAME_STENCIL(kDrawOutsideElement, | 699 GR_STATIC_CONST_SAME_STENCIL(kDrawOutsideElement, |
| 685 kZero_StencilOp, | 700 kZero_StencilOp, |
| 686 kZero_StencilOp, | 701 kZero_StencilOp, |
| 687 kEqual_StencilFunc, | 702 kEqual_StencilFunc, |
| 688 0xffff, | 703 0xffff, |
| 689 0x0000, | 704 0x0000, |
| 690 0xffff); | 705 0xffff); |
| 691 backgroundPipelineBuilder.setStencil(kDrawOutsideElement); | 706 backgroundPipelineBuilder.setStencil(kDrawOutsideElement); |
| 692 | 707 |
| 693 // The color passed in here does not matter since the coverageSe tOpXP won't read it. | 708 // The color passed in here does not matter since the coverageSe tOpXP won't read it. |
| 694 fDrawTarget->drawNonAARect(backgroundPipelineBuilder, GrColor_WH ITE, translate, | 709 draw_non_aa_rect(fDrawTarget, backgroundPipelineBuilder, GrColor _WHITE, translate, |
| 695 clipSpaceIBounds); | 710 SkRect::Make(clipSpaceIBounds)); |
| 696 } | 711 } |
| 697 } else { | 712 } else { |
| 698 GrPipelineBuilder pipelineBuilder; | 713 GrPipelineBuilder pipelineBuilder; |
| 699 | 714 |
| 700 // all the remaining ops can just be directly draw into the accumula tion buffer | 715 // all the remaining ops can just be directly draw into the accumula tion buffer |
| 701 set_coverage_drawing_xpf(op, false, &pipelineBuilder); | 716 set_coverage_drawing_xpf(op, false, &pipelineBuilder); |
| 702 // The color passed in here does not matter since the coverageSetOpX P won't read it. | 717 // The color passed in here does not matter since the coverageSetOpX P won't read it. |
| 703 this->drawElement(&pipelineBuilder, translate, texture, element); | 718 this->drawElement(&pipelineBuilder, translate, texture, element); |
| 704 } | 719 } |
| 705 } | 720 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, | 839 GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, |
| 825 kIncClamp_StencilOp, | 840 kIncClamp_StencilOp, |
| 826 kIncClamp_StencilOp, | 841 kIncClamp_StencilOp, |
| 827 kAlways_StencilFunc, | 842 kAlways_StencilFunc, |
| 828 0xffff, | 843 0xffff, |
| 829 0x0000, | 844 0x0000, |
| 830 0xffff); | 845 0xffff); |
| 831 if (Element::kRect_Type == element->getType()) { | 846 if (Element::kRect_Type == element->getType()) { |
| 832 *pipelineBuilder.stencil() = gDrawToStencil; | 847 *pipelineBuilder.stencil() = gDrawToStencil; |
| 833 | 848 |
| 834 // We need this AGP until everything is in GrBatch | 849 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE , viewMatrix, |
| 835 fDrawTarget->drawNonAARect(pipelineBuilder, | 850 element->getRect()); |
| 836 GrColor_WHITE, | |
| 837 viewMatrix, | |
| 838 element->getRect()); | |
| 839 } else { | 851 } else { |
| 840 if (!clipPath.isEmpty()) { | 852 if (!clipPath.isEmpty()) { |
| 841 if (canRenderDirectToStencil) { | 853 if (canRenderDirectToStencil) { |
| 842 *pipelineBuilder.stencil() = gDrawToStencil; | 854 *pipelineBuilder.stencil() = gDrawToStencil; |
| 843 | 855 |
| 844 GrPathRenderer::DrawPathArgs args; | 856 GrPathRenderer::DrawPathArgs args; |
| 845 args.fTarget = fDrawTarget; | 857 args.fTarget = fDrawTarget; |
| 846 args.fResourceProvider = this->getContext()->resourc eProvider(); | 858 args.fResourceProvider = this->getContext()->resourc eProvider(); |
| 847 args.fPipelineBuilder = &pipelineBuilder; | 859 args.fPipelineBuilder = &pipelineBuilder; |
| 848 args.fColor = GrColor_WHITE; | 860 args.fColor = GrColor_WHITE; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 866 } | 878 } |
| 867 | 879 |
| 868 // now we modify the clip bit by rendering either the clip | 880 // now we modify the clip bit by rendering either the clip |
| 869 // element directly or a bounding rect of the entire clip. | 881 // element directly or a bounding rect of the entire clip. |
| 870 fClipMode = kModifyClip_StencilClipMode; | 882 fClipMode = kModifyClip_StencilClipMode; |
| 871 for (int p = 0; p < passes; ++p) { | 883 for (int p = 0; p < passes; ++p) { |
| 872 *pipelineBuilder.stencil() = stencilSettings[p]; | 884 *pipelineBuilder.stencil() = stencilSettings[p]; |
| 873 | 885 |
| 874 if (canDrawDirectToClip) { | 886 if (canDrawDirectToClip) { |
| 875 if (Element::kRect_Type == element->getType()) { | 887 if (Element::kRect_Type == element->getType()) { |
| 876 // We need this AGP until everything is in GrBatch | 888 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_W HITE, viewMatrix, |
| 877 fDrawTarget->drawNonAARect(pipelineBuilder, | 889 element->getRect()); |
| 878 GrColor_WHITE, | |
| 879 viewMatrix, | |
| 880 element->getRect()); | |
| 881 } else { | 890 } else { |
| 882 GrPathRenderer::DrawPathArgs args; | 891 GrPathRenderer::DrawPathArgs args; |
| 883 args.fTarget = fDrawTarget; | 892 args.fTarget = fDrawTarget; |
| 884 args.fResourceProvider = this->getContext()->resourcePro vider(); | 893 args.fResourceProvider = this->getContext()->resourcePro vider(); |
| 885 args.fPipelineBuilder = &pipelineBuilder; | 894 args.fPipelineBuilder = &pipelineBuilder; |
| 886 args.fColor = GrColor_WHITE; | 895 args.fColor = GrColor_WHITE; |
| 887 args.fViewMatrix = &viewMatrix; | 896 args.fViewMatrix = &viewMatrix; |
| 888 args.fPath = &clipPath; | 897 args.fPath = &clipPath; |
| 889 args.fStroke = &stroke; | 898 args.fStroke = &stroke; |
| 890 args.fAntiAlias = false; | 899 args.fAntiAlias = false; |
| 891 pr->drawPath(args); | 900 pr->drawPath(args); |
| 892 } | 901 } |
| 893 } else { | 902 } else { |
| 894 // The view matrix is setup to do clip space -> stencil spac e translation, so | 903 // The view matrix is setup to do clip space -> stencil spac e translation, so |
| 895 // draw rect in clip space. | 904 // draw rect in clip space. |
| 896 fDrawTarget->drawNonAARect(pipelineBuilder, | 905 draw_non_aa_rect(fDrawTarget, pipelineBuilder, GrColor_WHITE , viewMatrix, |
| 897 GrColor_WHITE, | 906 SkRect::Make(clipSpaceIBounds)); |
| 898 viewMatrix, | |
| 899 SkRect::Make(clipSpaceIBounds)); | |
| 900 } | 907 } |
| 901 } | 908 } |
| 902 } | 909 } |
| 903 } | 910 } |
| 904 fClipMode = kRespectClip_StencilClipMode; | 911 fClipMode = kRespectClip_StencilClipMode; |
| 905 return true; | 912 return true; |
| 906 } | 913 } |
| 907 | 914 |
| 908 // mapping of clip-respecting stencil funcs to normal stencil funcs | 915 // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 909 // mapping depends on whether stencil-clipping is in effect. | 916 // mapping depends on whether stencil-clipping is in effect. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1146 | 1153 |
| 1147 //////////////////////////////////////////////////////////////////////////////// | 1154 //////////////////////////////////////////////////////////////////////////////// |
| 1148 | 1155 |
| 1149 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc ilAttachment, | 1156 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc ilAttachment, |
| 1150 GrStencilSettings* settings) { | 1157 GrStencilSettings* settings) { |
| 1151 if (stencilAttachment) { | 1158 if (stencilAttachment) { |
| 1152 int stencilBits = stencilAttachment->bits(); | 1159 int stencilBits = stencilAttachment->bits(); |
| 1153 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1160 this->adjustStencilParams(settings, fClipMode, stencilBits); |
| 1154 } | 1161 } |
| 1155 } | 1162 } |
| OLD | NEW |