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

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

Issue 699023003: remove separate color from coverage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGLProgramDesc.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 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"
(...skipping 26 matching lines...) Expand all
37 37
38 memcpy(descInfo.fFixedFunctionVertexAttribIndices, 38 memcpy(descInfo.fFixedFunctionVertexAttribIndices,
39 drawState.getFixedFunctionVertexAttribIndices(), 39 drawState.getFixedFunctionVertexAttribIndices(),
40 sizeof(descInfo.fFixedFunctionVertexAttribIndices)); 40 sizeof(descInfo.fFixedFunctionVertexAttribIndices));
41 41
42 descInfo.fInputColorIsUsed = true; 42 descInfo.fInputColorIsUsed = true;
43 descInfo.fInputCoverageIsUsed = true; 43 descInfo.fInputCoverageIsUsed = true;
44 44
45 int firstColorStageIdx = 0; 45 int firstColorStageIdx = 0;
46 int firstCoverageStageIdx = 0; 46 int firstCoverageStageIdx = 0;
47 bool separateCoverageFromColor;
48 47
49 uint8_t fixedFunctionVAToRemove = 0; 48 uint8_t fixedFunctionVAToRemove = 0;
50 49
51 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx, 50 this->computeEffectiveColorStages(drawState, &descInfo, &firstColorStageIdx,
52 &fixedFunctionVAToRemove); 51 &fixedFunctionVAToRemove);
53 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta geIdx); 52 this->computeEffectiveCoverageStages(drawState, &descInfo, &firstCoverageSta geIdx);
54 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC overageStageIdx, 53 this->adjustFromBlendOpts(drawState, &descInfo, &firstColorStageIdx, &firstC overageStageIdx,
55 &fixedFunctionVAToRemove); 54 &fixedFunctionVAToRemove);
56 // Should not be setting any more FFVA to be removed at this point 55 // Should not be setting any more FFVA to be removed at this point
57 if (0 != fixedFunctionVAToRemove) { 56 if (0 != fixedFunctionVAToRemove) {
58 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf o); 57 this->removeFixedFunctionVertexAttribs(fixedFunctionVAToRemove, &descInf o);
59 } 58 }
60 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d escInfo); 59 this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, &d escInfo);
61 this->setOutputStateInfo(drawState, *gpu->caps(), firstCoverageStageIdx, &de scInfo,
62 &separateCoverageFromColor);
63 60
64 // Copy GeometryProcesssor from DS or ODS 61 // Copy GeometryProcesssor from DS or ODS
65 if (drawState.hasGeometryProcessor()) { 62 if (drawState.hasGeometryProcessor()) {
66 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor); 63 fGeometryProcessor.initAndRef(drawState.fGeometryProcessor);
67 } else if (!GrGpu::IsPathRenderingDrawType(drawType)) { 64 } else if (!GrGpu::IsPathRenderingDrawType(drawType)) {
68 // Install default GP, this will be ignored if we are rendering with fra gment shader only 65 // Install default GP, this will be ignored if we are rendering with fra gment shader only
69 // TODO(joshualitt) rendering code should do this 66 // TODO(joshualitt) rendering code should do this
70 fGeometryProcessor.reset(GrDefaultGeoProcFactory::Create()); 67 fGeometryProcessor.reset(GrDefaultGeoProcFactory::Create());
71 } else { 68 } else {
72 fGeometryProcessor.reset(NULL); 69 fGeometryProcessor.reset(NULL);
73 } 70 }
74 71
75 // Copy Color Stages from DS to ODS 72 // Copy Color Stages from DS to ODS
76 if (firstColorStageIdx < drawState.numColorStages()) { 73 if (firstColorStageIdx < drawState.numColorStages()) {
77 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx), 74 fFragmentStages.reset(&drawState.getColorStage(firstColorStageIdx),
78 drawState.numColorStages() - firstColorStageIdx); 75 drawState.numColorStages() - firstColorStageIdx);
79 } else { 76 } else {
80 fFragmentStages.reset(); 77 fFragmentStages.reset();
81 } 78 }
82 79
83 fNumColorStages = fFragmentStages.count(); 80 fNumColorStages = fFragmentStages.count();
84 81
85 // Copy Coverage Stages from DS to ODS 82 // Copy Coverage Stages from DS to ODS
86 if (firstCoverageStageIdx < drawState.numCoverageStages()) { 83 if (firstCoverageStageIdx < drawState.numCoverageStages()) {
87 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx, 84 fFragmentStages.push_back_n(drawState.numCoverageStages() - firstCoverag eStageIdx,
88 &drawState.getCoverageStage(firstCoverageSta geIdx)); 85 &drawState.getCoverageStage(firstCoverageSta geIdx));
89 if (!separateCoverageFromColor) {
90 fNumColorStages = fFragmentStages.count();
91 }
92 } 86 }
93 87
88 this->setOutputStateInfo(drawState, *gpu->caps(), &descInfo);
89
94 // now create a key 90 // now create a key
95 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc); 91 gpu->buildProgramDesc(*this, descInfo, drawType, dstCopy, &fDesc);
96 }; 92 };
97 93
98 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState, 94 GrOptDrawState* GrOptDrawState::Create(const GrDrawState& drawState,
99 GrGpu* gpu, 95 GrGpu* gpu,
100 const GrDeviceCoordTexture* dstCopy, 96 const GrDeviceCoordTexture* dstCopy,
101 GrGpu::DrawType drawType) { 97 GrGpu::DrawType drawType) {
102 GrBlendCoeff srcCoeff; 98 GrBlendCoeff srcCoeff;
103 GrBlendCoeff dstCoeff; 99 GrBlendCoeff dstCoeff;
104 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false, 100 BlendOptFlags blendFlags = (BlendOptFlags) drawState.getBlendOpts(false,
105 &srcCoeff, 101 &srcCoeff,
106 &dstCoeff) ; 102 &dstCoeff) ;
107 103
108 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl ess we are 104 // If our blend coeffs are set to 0,1 we know we will not end up drawing unl ess we are
109 // stenciling. When path rendering the stencil settings are not always set o n the draw state 105 // stenciling. When path rendering the stencil settings are not always set o n the draw state
110 // so we must check the draw type. In cases where we will skip drawing we si mply return a 106 // so we must check the draw type. In cases where we will skip drawing we si mply return a
111 // null GrOptDrawState. 107 // null GrOptDrawState.
112 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff && 108 if (kZero_GrBlendCoeff == srcCoeff && kOne_GrBlendCoeff == dstCoeff &&
113 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d rawType) { 109 !drawState.getStencil().doesWrite() && GrGpu::kStencilPath_DrawType != d rawType) {
114 return NULL; 110 return NULL;
115 } 111 }
116 112
117 return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff, 113 return SkNEW_ARGS(GrOptDrawState, (drawState, blendFlags, srcCoeff,
118 dstCoeff, gpu, dstCopy, drawType)); 114 dstCoeff, gpu, dstCopy, drawType));
119 } 115 }
120 116
121 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, 117 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
122 const GrDrawTargetCaps& caps, 118 const GrDrawTargetCaps& caps,
123 int firstCoverageStageIdx, 119 GrProgramDesc::DescInfo* descInfo) {
124 GrProgramDesc::DescInfo* descInfo,
125 bool* separateCoverageFromColor) {
126 // Set this default and then possibly change our mind if there is coverage. 120 // Set this default and then possibly change our mind if there is coverage.
127 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; 121 descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
128 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; 122 descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
129 123
130 // If we do have coverage determine whether it matters. 124 // If we do have coverage determine whether it matters. Dual source blendin g is expensive so
131 *separateCoverageFromColor = this->hasGeometryProcessor(); 125 // we don't do it if we are doing coverage drawing. If we aren't then We al ways do dual source
132 if (!this->isCoverageDrawing() && 126 // blending if we have any effective coverage stages OR the geometry process or doesn't emits
133 (ds.numCoverageStages() - firstCoverageStageIdx > 0 || 127 // solid coverage.
134 ds.hasGeometryProcessor() || 128 // TODO move the gp logic into the GP base class
135 descInfo->hasCoverageVertexAttribute())) { 129 if (!this->isCoverageDrawing() && !ds.hasSolidCoverage()) {
136
137 if (caps.dualSourceBlendingSupport()) { 130 if (caps.dualSourceBlendingSupport()) {
138 if (kZero_GrBlendCoeff == fDstBlend) { 131 if (kZero_GrBlendCoeff == fDstBlend) {
139 // write the coverage value to second color 132 // write the coverage value to second color
140 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType; 133 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_Second aryOutputType;
141 *separateCoverageFromColor = true;
142 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 134 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
143 } else if (kSA_GrBlendCoeff == fDstBlend) { 135 } else if (kSA_GrBlendCoeff == fDstBlend) {
144 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 136 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
145 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType; 137 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_Sec ondaryOutputType;
146 *separateCoverageFromColor = true;
147 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 138 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
148 } else if (kSC_GrBlendCoeff == fDstBlend) { 139 } else if (kSC_GrBlendCoeff == fDstBlend) {
149 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. 140 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
150 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType; 141 descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_Sec ondaryOutputType;
151 *separateCoverageFromColor = true;
152 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 142 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
153 } 143 }
154 } else if (descInfo->fReadsDst && 144 } else if (descInfo->fReadsDst &&
155 kOne_GrBlendCoeff == fSrcBlend && 145 kOne_GrBlendCoeff == fSrcBlend &&
156 kZero_GrBlendCoeff == fDstBlend) { 146 kZero_GrBlendCoeff == fDstBlend) {
157 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType; 147 descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_Primar yOutputType;
158 *separateCoverageFromColor = true;
159 } 148 }
160 } 149 }
161 } 150 }
162 151
163 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds, 152 void GrOptDrawState::adjustFromBlendOpts(const GrDrawState& ds,
164 GrProgramDesc::DescInfo* descInfo, 153 GrProgramDesc::DescInfo* descInfo,
165 int* firstColorStageIdx, 154 int* firstColorStageIdx,
166 int* firstCoverageStageIdx, 155 int* firstCoverageStageIdx,
167 uint8_t* fixedFunctionVAToRemove) { 156 uint8_t* fixedFunctionVAToRemove) {
168 switch (fBlendOptFlags) { 157 switch (fBlendOptFlags) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex != -1; 360 bool explicitLocalCoords = this->fDesc.header().fLocalCoordAttributeIndex != -1;
372 for (int i = 0; i < this->numFragmentStages(); i++) { 361 for (int i = 0; i < this->numFragmentStages(); i++) {
373 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i), 362 if (!GrFragmentStage::AreCompatible(this->getFragmentStage(i), that.getF ragmentStage(i),
374 explicitLocalCoords)) { 363 explicitLocalCoords)) {
375 return false; 364 return false;
376 } 365 }
377 } 366 }
378 return true; 367 return true;
379 } 368 }
380 369
OLDNEW
« no previous file with comments | « src/gpu/GrOptDrawState.h ('k') | src/gpu/gl/GrGLProgramDesc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698