Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: src/gpu/GrClipMaskManager.cpp

Issue 1407883004: Remove GrPipelineBuilder from getPathRenderer call (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Hide GrContext::drawingManager entry point Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrClipMaskManager.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrDrawContext.h" 11 #include "GrDrawContext.h"
11 #include "GrDrawTarget.h" 12 #include "GrDrawTarget.h"
12 #include "GrGpuResourcePriv.h" 13 #include "GrGpuResourcePriv.h"
13 #include "GrPaint.h" 14 #include "GrPaint.h"
14 #include "GrPathRenderer.h" 15 #include "GrPathRenderer.h"
15 #include "GrRenderTarget.h" 16 #include "GrRenderTarget.h"
16 #include "GrRenderTargetPriv.h" 17 #include "GrRenderTargetPriv.h"
17 #include "GrResourceProvider.h" 18 #include "GrResourceProvider.h"
18 #include "GrStencilAttachment.h" 19 #include "GrStencilAttachment.h"
19 #include "GrSWMaskHelper.h" 20 #include "GrSWMaskHelper.h"
(...skipping 22 matching lines...) Expand all
42 mat, 43 mat,
43 GrTextureDomain::MakeTexelDomain(result , domainTexels), 44 GrTextureDomain::MakeTexelDomain(result , domainTexels),
44 GrTextureDomain::kDecal_Mode, 45 GrTextureDomain::kDecal_Mode,
45 GrTextureParams::kNone_FilterMode, 46 GrTextureParams::kNone_FilterMode,
46 kDevice_GrCoordSet); 47 kDevice_GrCoordSet);
47 } 48 }
48 49
49 // Does the path in 'element' require SW rendering? If so, return true (and, 50 // Does the path in 'element' require SW rendering? If so, return true (and,
50 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set 51 // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set
51 // 'prOut' to the non-SW path renderer that will do the job). 52 // 'prOut' to the non-SW path renderer that will do the job).
52 static bool path_needs_SW_renderer(GrContext* context, 53 bool GrClipMaskManager::PathNeedsSWRenderer(GrContext* context,
53 const GrPipelineBuilder& pipelineBuilder, 54 bool isStencilDisabled,
54 const SkMatrix& viewMatrix, 55 const GrRenderTarget* rt,
55 const Element* element, 56 const SkMatrix& viewMatrix,
56 GrPathRenderer** prOut, 57 const Element* element,
57 bool needsStencil) { 58 GrPathRenderer** prOut,
59 bool needsStencil) {
58 if (Element::kRect_Type == element->getType()) { 60 if (Element::kRect_Type == element->getType()) {
59 // rects can always be drawn directly w/o using the software path 61 // rects can always be drawn directly w/o using the software path
60 // TODO: skip rrects once we're drawing them directly. 62 // TODO: skip rrects once we're drawing them directly.
61 if (prOut) { 63 if (prOut) {
62 *prOut = nullptr; 64 *prOut = nullptr;
63 } 65 }
64 return false; 66 return false;
65 } else { 67 } else {
66 // We shouldn't get here with an empty clip element. 68 // We shouldn't get here with an empty clip element.
67 SkASSERT(Element::kEmpty_Type != element->getType()); 69 SkASSERT(Element::kEmpty_Type != element->getType());
(...skipping 11 matching lines...) Expand all
79 if (needsStencil) { 81 if (needsStencil) {
80 type = element->isAA() 82 type = element->isAA()
81 ? GrPathRendererChain::kStencilAndColorAntiAlias_Dra wType 83 ? GrPathRendererChain::kStencilAndColorAntiAlias_Dra wType
82 : GrPathRendererChain::kStencilAndColor_DrawType; 84 : GrPathRendererChain::kStencilAndColor_DrawType;
83 } else { 85 } else {
84 type = element->isAA() 86 type = element->isAA()
85 ? GrPathRendererChain::kColorAntiAlias_DrawType 87 ? GrPathRendererChain::kColorAntiAlias_DrawType
86 : GrPathRendererChain::kColor_DrawType; 88 : GrPathRendererChain::kColor_DrawType;
87 } 89 }
88 90
91 GrPathRenderer::CanDrawPathArgs canDrawArgs;
92 canDrawArgs.fShaderCaps = context->caps()->shaderCaps();
93 canDrawArgs.fViewMatrix = &viewMatrix;
94 canDrawArgs.fPath = &path;
95 canDrawArgs.fStroke = &stroke;
96 canDrawArgs.fAntiAlias = element->isAA();
97 canDrawArgs.fIsStencilDisabled = isStencilDisabled;
98 canDrawArgs.fIsStencilBufferMSAA = rt->isStencilBufferMultisampled();
99
89 // the 'false' parameter disallows use of the SW path renderer 100 // the 'false' parameter disallows use of the SW path renderer
90 GrPathRenderer* pr = context->getPathRenderer(pipelineBuilder, viewMatri x, path, 101 GrPathRenderer* pr = context->drawingManager()->getPathRenderer(canDrawA rgs, false, type);
91 stroke, false, type);
92 if (prOut) { 102 if (prOut) {
93 *prOut = pr; 103 *prOut = pr;
94 } 104 }
95 return SkToBool(!pr); 105 return SkToBool(!pr);
96 } 106 }
97 } 107 }
98 108
99 // Determines whether it is possible to draw the element to both the stencil buf fer and the 109 // Determines whether it is possible to draw the element to both the stencil buf fer and the
100 // alpha mask simultaneously. If so and the element is a path a compatible path renderer is 110 // alpha mask simultaneously. If so and the element is a path a compatible path renderer is
101 // also returned. 111 // also returned.
102 static GrPathRenderer* get_path_renderer(GrContext* context, 112 GrPathRenderer* GrClipMaskManager::GetPathRenderer(GrContext* context,
103 GrPipelineBuilder* pipelineBuilder, 113 GrTexture* texture,
104 const SkMatrix& viewMatrix, 114 const SkMatrix& viewMatrix,
105 const SkClipStack::Element* element) { 115 const SkClipStack::Element* e lement) {
106 GrPathRenderer* pr; 116 GrPathRenderer* pr;
107 static const bool kNeedsStencil = true; 117 static const bool kNeedsStencil = true;
108 path_needs_SW_renderer(context, *pipelineBuilder, viewMatrix, element, &pr, kNeedsStencil); 118 static const bool kStencilIsDisabled = true;
119 PathNeedsSWRenderer(context,
120 kStencilIsDisabled,
121 texture->asRenderTarget(),
122 viewMatrix,
123 element,
124 &pr,
125 kNeedsStencil);
109 return pr; 126 return pr;
110 } 127 }
111 128
112 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget) 129 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget)
113 : fDrawTarget(drawTarget) 130 : fDrawTarget(drawTarget)
114 , fClipMode(kIgnoreClip_StencilClipMode) { 131 , fClipMode(kIgnoreClip_StencilClipMode) {
115 } 132 }
116 133
117 GrContext* GrClipMaskManager::getContext() { 134 GrContext* GrClipMaskManager::getContext() {
118 return fDrawTarget->cmmAccess().context(); 135 return fDrawTarget->cmmAccess().context();
119 } 136 }
120 137
121 const GrCaps* GrClipMaskManager::caps() const { 138 const GrCaps* GrClipMaskManager::caps() const {
122 return fDrawTarget->caps(); 139 return fDrawTarget->caps();
123 } 140 }
124 141
125 GrResourceProvider* GrClipMaskManager::resourceProvider() { 142 GrResourceProvider* GrClipMaskManager::resourceProvider() {
126 return fDrawTarget->cmmAccess().resourceProvider(); 143 return fDrawTarget->cmmAccess().resourceProvider();
127 } 144 }
128 /* 145 /*
129 * This method traverses the clip stack to see if the GrSoftwarePathRenderer 146 * This method traverses the clip stack to see if the GrSoftwarePathRenderer
130 * will be used on any element. If so, it returns true to indicate that the 147 * will be used on any element. If so, it returns true to indicate that the
131 * entire clip should be rendered in SW and then uploaded en masse to the gpu. 148 * entire clip should be rendered in SW and then uploaded en masse to the gpu.
132 */ 149 */
133 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder& pipelineBuilder, 150 bool GrClipMaskManager::useSWOnlyPath(const GrPipelineBuilder& pipelineBuilder,
151 const GrRenderTarget* rt,
134 const SkVector& clipToMaskOffset, 152 const SkVector& clipToMaskOffset,
135 const GrReducedClip::ElementList& elements ) { 153 const GrReducedClip::ElementList& elements ) {
136 // TODO: generalize this function so that when 154 // TODO: generalize this function so that when
137 // a clip gets complex enough it can just be done in SW regardless 155 // a clip gets complex enough it can just be done in SW regardless
138 // of whether it would invoke the GrSoftwarePathRenderer. 156 // of whether it would invoke the GrSoftwarePathRenderer.
139 157
140 // Set the matrix so that rendered clip elements are transformed to mask spa ce from clip 158 // Set the matrix so that rendered clip elements are transformed to mask spa ce from clip
141 // space. 159 // space.
142 const SkMatrix translate = SkMatrix::MakeTrans(clipToMaskOffset.fX, clipToMa skOffset.fY); 160 const SkMatrix translate = SkMatrix::MakeTrans(clipToMaskOffset.fX, clipToMa skOffset.fY);
143 161
144 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get(); iter.next()) { 162 for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get(); iter.next()) {
145 const Element* element = iter.get(); 163 const Element* element = iter.get();
146 164
147 SkRegion::Op op = element->getOp(); 165 SkRegion::Op op = element->getOp();
148 bool invert = element->isInverseFilled(); 166 bool invert = element->isInverseFilled();
149 bool needsStencil = invert || 167 bool needsStencil = invert ||
150 SkRegion::kIntersect_Op == op || SkRegion::kReverseD ifference_Op == op; 168 SkRegion::kIntersect_Op == op || SkRegion::kReverseD ifference_Op == op;
151 169
152 if (path_needs_SW_renderer(this->getContext(), pipelineBuilder, translat e, 170 if (PathNeedsSWRenderer(this->getContext(), pipelineBuilder.getStencil() .isDisabled(),
153 element, nullptr, needsStencil)) { 171 rt, translate, element, nullptr, needsStencil)) {
154 return true; 172 return true;
155 } 173 }
156 } 174 }
157 return false; 175 return false;
158 } 176 }
159 177
160 bool GrClipMaskManager::getAnalyticClipProcessor(const GrReducedClip::ElementLis t& elements, 178 bool GrClipMaskManager::getAnalyticClipProcessor(const GrReducedClip::ElementLis t& elements,
161 bool abortIfAA, 179 bool abortIfAA,
162 SkVector& clipToRTOffset, 180 SkVector& clipToRTOffset,
163 const SkRect* drawBounds, 181 const SkRect* drawBounds,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // If MSAA is enabled we can do everything in the stencil buffer. 371 // If MSAA is enabled we can do everything in the stencil buffer.
354 if (0 == rt->numStencilSamples() && requiresAA) { 372 if (0 == rt->numStencilSamples() && requiresAA) {
355 SkAutoTUnref<GrTexture> result; 373 SkAutoTUnref<GrTexture> result;
356 374
357 // The top-left of the mask corresponds to the top-left corner of the bo unds. 375 // The top-left of the mask corresponds to the top-left corner of the bo unds.
358 SkVector clipToMaskOffset = { 376 SkVector clipToMaskOffset = {
359 SkIntToScalar(-clipSpaceIBounds.fLeft), 377 SkIntToScalar(-clipSpaceIBounds.fLeft),
360 SkIntToScalar(-clipSpaceIBounds.fTop) 378 SkIntToScalar(-clipSpaceIBounds.fTop)
361 }; 379 };
362 380
363 if (this->useSWOnlyPath(pipelineBuilder, clipToMaskOffset, elements)) { 381 if (this->useSWOnlyPath(pipelineBuilder, rt, clipToMaskOffset, elements) ) {
364 // The clip geometry is complex enough that it will be more efficien t to create it 382 // The clip geometry is complex enough that it will be more efficien t to create it
365 // entirely in software 383 // entirely in software
366 result.reset(this->createSoftwareClipMask(genID, 384 result.reset(this->createSoftwareClipMask(genID,
367 initialState, 385 initialState,
368 elements, 386 elements,
369 clipToMaskOffset, 387 clipToMaskOffset,
370 clipSpaceIBounds)); 388 clipSpaceIBounds));
371 } else { 389 } else {
372 result.reset(this->createAlphaClipMask(genID, 390 result.reset(this->createAlphaClipMask(genID,
373 initialState, 391 initialState,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 437 }
420 } 438 }
421 439
422 //////////////////////////////////////////////////////////////////////////////// 440 ////////////////////////////////////////////////////////////////////////////////
423 bool GrClipMaskManager::drawElement(GrPipelineBuilder* pipelineBuilder, 441 bool GrClipMaskManager::drawElement(GrPipelineBuilder* pipelineBuilder,
424 const SkMatrix& viewMatrix, 442 const SkMatrix& viewMatrix,
425 GrTexture* target, 443 GrTexture* target,
426 const SkClipStack::Element* element, 444 const SkClipStack::Element* element,
427 GrPathRenderer* pr) { 445 GrPathRenderer* pr) {
428 446
429 pipelineBuilder->setRenderTarget(target->asRenderTarget()); 447 GrRenderTarget* rt = target->asRenderTarget();
448 pipelineBuilder->setRenderTarget(rt);
430 449
431 // The color we use to draw does not matter since we will always be using a GrCoverageSetOpXP 450 // The color we use to draw does not matter since we will always be using a GrCoverageSetOpXP
432 // which ignores color. 451 // which ignores color.
433 GrColor color = GrColor_WHITE; 452 GrColor color = GrColor_WHITE;
434 453
435 // TODO: Draw rrects directly here. 454 // TODO: Draw rrects directly here.
436 switch (element->getType()) { 455 switch (element->getType()) {
437 case Element::kEmpty_Type: 456 case Element::kEmpty_Type:
438 SkDEBUGFAIL("Should never get here with an empty element."); 457 SkDEBUGFAIL("Should never get here with an empty element.");
439 break; 458 break;
(...skipping 15 matching lines...) Expand all
455 SkPath path; 474 SkPath path;
456 element->asPath(&path); 475 element->asPath(&path);
457 if (path.isInverseFillType()) { 476 if (path.isInverseFillType()) {
458 path.toggleInverseFillType(); 477 path.toggleInverseFillType();
459 } 478 }
460 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle); 479 GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle);
461 if (nullptr == pr) { 480 if (nullptr == pr) {
462 GrPathRendererChain::DrawType type; 481 GrPathRendererChain::DrawType type;
463 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr awType : 482 type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_Dr awType :
464 GrPathRendererChain::kColor_DrawType; 483 GrPathRendererChain::kColor_DrawType;
465 pr = this->getContext()->getPathRenderer(*pipelineBuilder, viewM atrix, 484
466 path, stroke, false, ty pe); 485 GrPathRenderer::CanDrawPathArgs canDrawArgs;
486 canDrawArgs.fShaderCaps = this->getContext()->caps()->shaderCaps ();
487 canDrawArgs.fViewMatrix = &viewMatrix;
488 canDrawArgs.fPath = &path;
489 canDrawArgs.fStroke = &stroke;
490 canDrawArgs.fAntiAlias = element->isAA();;
491 canDrawArgs.fIsStencilDisabled = pipelineBuilder->getStencil().i sDisabled();
492 canDrawArgs.fIsStencilBufferMSAA = rt->isStencilBufferMultisampl ed();
493
494 pr = this->getContext()->drawingManager()->getPathRenderer(canDr awArgs, false, type);
467 } 495 }
468 if (nullptr == pr) { 496 if (nullptr == pr) {
469 return false; 497 return false;
470 } 498 }
471 GrPathRenderer::DrawPathArgs args; 499 GrPathRenderer::DrawPathArgs args;
472 args.fTarget = fDrawTarget; 500 args.fTarget = fDrawTarget;
473 args.fResourceProvider = this->getContext()->resourceProvider(); 501 args.fResourceProvider = this->getContext()->resourceProvider();
474 args.fPipelineBuilder = pipelineBuilder; 502 args.fPipelineBuilder = pipelineBuilder;
475 args.fColor = color; 503 args.fColor = color;
476 args.fViewMatrix = &viewMatrix; 504 args.fViewMatrix = &viewMatrix;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 for (GrReducedClip::ElementList::Iter iter = elements.headIter(); iter.get() ; iter.next()) { 587 for (GrReducedClip::ElementList::Iter iter = elements.headIter(); iter.get() ; iter.next()) {
560 const Element* element = iter.get(); 588 const Element* element = iter.get();
561 SkRegion::Op op = element->getOp(); 589 SkRegion::Op op = element->getOp();
562 bool invert = element->isInverseFilled(); 590 bool invert = element->isInverseFilled();
563 if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDiffere nce_Op == op) { 591 if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDiffere nce_Op == op) {
564 GrPipelineBuilder pipelineBuilder; 592 GrPipelineBuilder pipelineBuilder;
565 593
566 pipelineBuilder.setClip(clip); 594 pipelineBuilder.setClip(clip);
567 pipelineBuilder.setRenderTarget(texture->asRenderTarget()); 595 pipelineBuilder.setRenderTarget(texture->asRenderTarget());
568 596
569 GrPathRenderer* pr = get_path_renderer(this->getContext(), &pipeline Builder, 597 SkASSERT(pipelineBuilder.getStencil().isDisabled());
570 translate, element); 598 GrPathRenderer* pr = GetPathRenderer(this->getContext(),
599 texture, translate, element);
571 if (Element::kRect_Type != element->getType() && !pr) { 600 if (Element::kRect_Type != element->getType() && !pr) {
572 // useSWOnlyPath should now filter out all cases where gpu-side mask merging would 601 // useSWOnlyPath should now filter out all cases where gpu-side mask merging would
573 // be performed (i.e., pr would be NULL for a non-rect path). Se e skbug.com/4519 602 // be performed (i.e., pr would be NULL for a non-rect path). Se e skbug.com/4519
574 // for rationale and details. 603 // for rationale and details.
575 SkASSERT(0); 604 SkASSERT(0);
576 continue; 605 continue;
577 } 606 }
578 607
579 // draw directly into the result with the stencil set to make the pi xels affected 608 // draw directly into the result with the stencil set to make the pi xels affected
580 // by the clip shape be non-zero. 609 // by the clip shape be non-zero.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 SkPath clipPath; 723 SkPath clipPath;
695 if (Element::kRect_Type == element->getType()) { 724 if (Element::kRect_Type == element->getType()) {
696 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; 725 stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
697 fillInverted = false; 726 fillInverted = false;
698 } else { 727 } else {
699 element->asPath(&clipPath); 728 element->asPath(&clipPath);
700 fillInverted = clipPath.isInverseFillType(); 729 fillInverted = clipPath.isInverseFillType();
701 if (fillInverted) { 730 if (fillInverted) {
702 clipPath.toggleInverseFillType(); 731 clipPath.toggleInverseFillType();
703 } 732 }
704 pr = this->getContext()->getPathRenderer(pipelineBuilder, 733
705 viewMatrix, 734 SkASSERT(pipelineBuilder.getStencil().isDisabled());
706 clipPath, 735
707 stroke, 736 GrPathRenderer::CanDrawPathArgs canDrawArgs;
708 false, 737 canDrawArgs.fShaderCaps = this->getContext()->caps()->shaderCaps ();
709 GrPathRendererChain::kS tencilOnly_DrawType, 738 canDrawArgs.fViewMatrix = &viewMatrix;
710 &stencilSupport); 739 canDrawArgs.fPath = &clipPath;
740 canDrawArgs.fStroke = &stroke;
741 canDrawArgs.fAntiAlias = false;
742 canDrawArgs.fIsStencilDisabled = pipelineBuilder.getStencil().is Disabled();
743 canDrawArgs.fIsStencilBufferMSAA = rt->isStencilBufferMultisampl ed();
744
745 pr = this->getContext()->drawingManager()->getPathRenderer(canDr awArgs, false,
746 GrPat hRendererChain::kStencilOnly_DrawType,
747 &sten cilSupport);
711 if (nullptr == pr) { 748 if (nullptr == pr) {
712 return false; 749 return false;
713 } 750 }
714 } 751 }
715 752
716 int passes; 753 int passes;
717 GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClip Passes]; 754 GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClip Passes];
718 755
719 bool canRenderDirectToStencil = 756 bool canRenderDirectToStencil =
720 GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport; 757 GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 1093
1057 //////////////////////////////////////////////////////////////////////////////// 1094 ////////////////////////////////////////////////////////////////////////////////
1058 1095
1059 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc ilAttachment, 1096 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc ilAttachment,
1060 GrStencilSettings* settings) { 1097 GrStencilSettings* settings) {
1061 if (stencilAttachment) { 1098 if (stencilAttachment) {
1062 int stencilBits = stencilAttachment->bits(); 1099 int stencilBits = stencilAttachment->bits();
1063 this->adjustStencilParams(settings, fClipMode, stencilBits); 1100 this->adjustStencilParams(settings, fClipMode, stencilBits);
1064 } 1101 }
1065 } 1102 }
OLDNEW
« no previous file with comments | « src/gpu/GrClipMaskManager.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698