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

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

Issue 742853002: Don't use NULL GrOptDrawState to indicate that draw should be skipped. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "GrOptDrawState.h" 8 #include "GrOptDrawState.h"
9 9
10 #include "GrDefaultGeoProcFactory.h" 10 #include "GrDefaultGeoProcFactory.h"
11 #include "GrDrawState.h" 11 #include "GrDrawState.h"
12 #include "GrDrawTargetCaps.h" 12 #include "GrDrawTargetCaps.h"
13 #include "GrGpu.h" 13 #include "GrGpu.h"
14 #include "GrProcOptInfo.h" 14 #include "GrProcOptInfo.h"
15 15
16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, 16 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
17 GrDrawState::BlendOpt blendOpt,
18 GrBlendCoeff optSrcCoeff,
19 GrBlendCoeff optDstCoeff,
20 GrGpu* gpu, 17 GrGpu* gpu,
21 const ScissorState& scissorState, 18 const ScissorState& scissorState,
22 const GrDeviceCoordTexture* dstCopy, 19 const GrDeviceCoordTexture* dstCopy,
23 GrGpu::DrawType drawType) 20 GrGpu::DrawType drawType) {
24 : fRenderTarget(drawState.fRenderTarget.get()) { 21
22 GrBlendCoeff optSrcCoeff;
23 GrBlendCoeff optDstCoeff;
24 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff);
25
26 // When path rendering the stencil settings are not always set on the draw s tate
27 // so we must check the draw type. In cases where we will skip drawing we si mply return a
28 // null GrOptDrawState.
29 if (GrDrawState::kSkipDraw_BlendOpt == blendOpt && GrGpu::kStencilPath_DrawT ype != drawType) {
30 // Set the fields that don't default init and return. The lack of a rend er target will
31 // indicate that this can be skipped.
32 fFlags = 0;
33 fVAPtr = NULL;
34 fVACount = 0;
35 fVAStride = 0;
36 fDrawFace = GrDrawState::kInvalid_DrawFace;
37 fSrcBlend = kZero_GrBlendCoeff;
38 fDstBlend = kZero_GrBlendCoeff;
39 fBlendConstant = 0x0;
40 fViewMatrix.reset();
41 return;
42 }
43
44 fRenderTarget.reset(drawState.fRenderTarget.get());
egdaniel 2014/11/19 21:07:11 is worth having SkASSERT(ds.fRT.get())? Mostly thi
bsalomon 2014/11/20 15:00:30 Done.
25 fScissorState = scissorState; 45 fScissorState = scissorState;
26 fViewMatrix = drawState.getViewMatrix(); 46 fViewMatrix = drawState.getViewMatrix();
27 fBlendConstant = drawState.getBlendConstant(); 47 fBlendConstant = drawState.getBlendConstant();
28 fVAPtr = drawState.getVertexAttribs(); 48 fVAPtr = drawState.getVertexAttribs();
29 fVACount = drawState.getVertexAttribCount(); 49 fVACount = drawState.getVertexAttribCount();
30 fVAStride = drawState.getVertexStride(); 50 fVAStride = drawState.getVertexStride();
31 fStencilSettings = drawState.getStencil(); 51 fStencilSettings = drawState.getStencil();
32 fDrawFace = drawState.getDrawFace(); 52 fDrawFace = drawState.getDrawFace();
33 fSrcBlend = optSrcCoeff; 53 fSrcBlend = optSrcCoeff;
34 fDstBlend = optDstCoeff; 54 fDstBlend = optDstCoeff;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 GrPendingFragmentStage, 113 GrPendingFragmentStage,
94 (drawState.fCoverageStages[i], explicitLocalCoord s)); 114 (drawState.fCoverageStages[i], explicitLocalCoord s));
95 } 115 }
96 116
97 this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo); 117 this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo);
98 118
99 // now create a key 119 // now create a key
100 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); 120 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc);
101 }; 121 };
102 122
103 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
104 GrGpu* gpu,
105 const ScissorState& scissorState,
106 const GrDeviceCoordTexture* dstCopy,
107 GrGpu::DrawType drawType) {
108 GrBlendCoeff srcCoeff;
109 GrBlendCoeff dstCoeff;
110 GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &srcCoeff, &ds tCoeff);
111
112 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl ess we are
113 // stenciling. When path rendering the stencil settings are not always set o n the draw state
114 // so we must check the draw type. In cases where we will skip drawing we si mply return a
115 // null GrOptDrawState.
116 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
117 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d rawType) {
118 return NULL;
119 }
120
121 return SkNEW_ARGS(GrOptDrawState, (drawState, blendOpt, srcCoeff,
122 dstCoeff, gpu, scissorState, dstCopy, dra wType));
123 }
124
125 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, 123 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
126 GrDrawState::BlendOpt blendOpt, 124 GrDrawState::BlendOpt blendOpt,
127 const GrDrawTargetCaps& caps, 125 const GrDrawTargetCaps& caps,
128 GrProgramDesc::DescInfo* descInfo) { 126 GrProgramDesc::DescInfo* descInfo) {
129 // Set this default and then possibly change our mind if there is coverage. 127 // Set this default and then possibly change our mind if there is coverage.
130 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; 128 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
131 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; 129 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
132 130
133 // Determine whether we should use dual source blending or shader code to ke ep coverage 131 // Determine whether we should use dual source blending or shader code to ke ep coverage
134 // separate from color. 132 // separate from color.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 SkASSERT(this->numFragmentStages() == that.numFragmentStages()); 299 SkASSERT(this->numFragmentStages() == that.numFragmentStages());
302 for (int i = 0; i < this->numFragmentStages(); i++) { 300 for (int i = 0; i < this->numFragmentStages(); i++) {
303 301
304 if (this->getFragmentStage(i) != that.getFragmentStage(i)) { 302 if (this->getFragmentStage(i) != that.getFragmentStage(i)) {
305 return false; 303 return false;
306 } 304 }
307 } 305 }
308 return true; 306 return true;
309 } 307 }
310 308
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | tests/GLProgramsTest.cpp » ('j') | tests/GLProgramsTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698