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

Side by Side Diff: src/gpu/gl/GrGLProgram.cpp

Issue 305203002: Use GrGLShaderBuilder::GenProgramOutput in GrGLProgram. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: restore autotunref Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramEffects.h » ('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 2011 Google Inc. 2 * Copyright 2011 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 "GrGLProgram.h" 8 #include "GrGLProgram.h"
9 9
10 #include "GrAllocator.h" 10 #include "GrAllocator.h"
(...skipping 20 matching lines...) Expand all
31 SkASSERT(0 != output.fProgramID); 31 SkASSERT(0 != output.fProgramID);
32 return SkNEW_ARGS(GrGLProgram, (gpu, desc, uman, output)); 32 return SkNEW_ARGS(GrGLProgram, (gpu, desc, uman, output));
33 } 33 }
34 return NULL; 34 return NULL;
35 } 35 }
36 36
37 GrGLProgram::GrGLProgram(GrGpuGL* gpu, 37 GrGLProgram::GrGLProgram(GrGpuGL* gpu,
38 const GrGLProgramDesc& desc, 38 const GrGLProgramDesc& desc,
39 GrGLUniformManager* uman, 39 GrGLUniformManager* uman,
40 const GrGLShaderBuilder::GenProgramOutput& builderOutpu t) 40 const GrGLShaderBuilder::GenProgramOutput& builderOutpu t)
41 : fProgramID(builderOutput.fProgramID) 41 : fColor(GrColor_ILLEGAL)
42 , fColor(GrColor_ILLEGAL)
43 , fCoverage(GrColor_ILLEGAL) 42 , fCoverage(GrColor_ILLEGAL)
44 , fDstCopyTexUnit(-1) 43 , fDstCopyTexUnit(-1)
45 , fColorEffects(builderOutput.fColorEffects) 44 , fBuilderOutput(builderOutput)
46 , fCoverageEffects(builderOutput.fCoverageEffects)
47 , fDesc(desc) 45 , fDesc(desc)
48 , fGpu(gpu) 46 , fGpu(gpu)
49 , fUniformManager(SkRef(uman)) 47 , fUniformManager(SkRef(uman)) {
50 , fUniformHandles(builderOutput.fUniformHandles)
51 , fHasVertexShader(builderOutput.fHasVertexShader)
52 , fTexCoordSetCnt(builderOutput.fTexCoordSetCnt) {
53 this->initSamplerUniforms(); 48 this->initSamplerUniforms();
54 } 49 }
55 50
56 GrGLProgram::~GrGLProgram() { 51 GrGLProgram::~GrGLProgram() {
57 if (fProgramID) { 52 if (fBuilderOutput.fProgramID) {
58 GL_CALL(DeleteProgram(fProgramID)); 53 GL_CALL(DeleteProgram(fBuilderOutput.fProgramID));
59 } 54 }
60 } 55 }
61 56
62 void GrGLProgram::abandon() { 57 void GrGLProgram::abandon() {
63 fProgramID = 0; 58 fBuilderOutput.fProgramID = 0;
64 } 59 }
65 60
66 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff, 61 void GrGLProgram::overrideBlend(GrBlendCoeff* srcCoeff,
67 GrBlendCoeff* dstCoeff) const { 62 GrBlendCoeff* dstCoeff) const {
68 switch (fDesc.getHeader().fCoverageOutput) { 63 switch (fDesc.getHeader().fCoverageOutput) {
69 case GrGLProgramDesc::kModulate_CoverageOutput: 64 case GrGLProgramDesc::kModulate_CoverageOutput:
70 break; 65 break;
71 // The prog will write a coverage value to the secondary 66 // The prog will write a coverage value to the secondary
72 // output and the dst is blended by one minus that value. 67 // output and the dst is blended by one minus that value.
73 case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput: 68 case GrGLProgramDesc::kSecondaryCoverage_CoverageOutput:
74 case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput: 69 case GrGLProgramDesc::kSecondaryCoverageISA_CoverageOutput:
75 case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput: 70 case GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput:
76 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; 71 *dstCoeff = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
77 break; 72 break;
78 case GrGLProgramDesc::kCombineWithDst_CoverageOutput: 73 case GrGLProgramDesc::kCombineWithDst_CoverageOutput:
79 // We should only have set this if the blend was specified as (1, 0) 74 // We should only have set this if the blend was specified as (1, 0)
80 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff); 75 SkASSERT(kOne_GrBlendCoeff == *srcCoeff && kZero_GrBlendCoeff == *ds tCoeff);
81 break; 76 break;
82 default: 77 default:
83 SkFAIL("Unexpected coverage output"); 78 SkFAIL("Unexpected coverage output");
84 break; 79 break;
85 } 80 }
86 } 81 }
87 82
88 void GrGLProgram::initSamplerUniforms() { 83 void GrGLProgram::initSamplerUniforms() {
89 GL_CALL(UseProgram(fProgramID)); 84 GL_CALL(UseProgram(fBuilderOutput.fProgramID));
90 GrGLint texUnitIdx = 0; 85 GrGLint texUnitIdx = 0;
91 if (fUniformHandles.fDstCopySamplerUni.isValid()) { 86 if (fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()) {
92 fUniformManager->setSampler(fUniformHandles.fDstCopySamplerUni, texUnitI dx); 87 fUniformManager->setSampler(fBuilderOutput.fUniformHandles.fDstCopySampl erUni, texUnitIdx);
93 fDstCopyTexUnit = texUnitIdx++; 88 fDstCopyTexUnit = texUnitIdx++;
94 } 89 }
95 fColorEffects->initSamplers(*fUniformManager, &texUnitIdx); 90 fBuilderOutput.fColorEffects->initSamplers(*fUniformManager, &texUnitIdx);
96 fCoverageEffects->initSamplers(*fUniformManager, &texUnitIdx); 91 fBuilderOutput.fCoverageEffects->initSamplers(*fUniformManager, &texUnitIdx) ;
97 } 92 }
98 93
99 /////////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////////
100 95
101 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, 96 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts,
102 const GrEffectStage* colorStages[], 97 const GrEffectStage* colorStages[],
103 const GrEffectStage* coverageStages[], 98 const GrEffectStage* coverageStages[],
104 const GrDeviceCoordTexture* dstCopy, 99 const GrDeviceCoordTexture* dstCopy,
105 SharedGLState* sharedState) { 100 SharedGLState* sharedState) {
106 const GrDrawState& drawState = fGpu->getDrawState(); 101 const GrDrawState& drawState = fGpu->getDrawState();
107 102
108 GrColor color; 103 GrColor color;
109 GrColor coverage; 104 GrColor coverage;
110 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { 105 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) {
111 color = 0; 106 color = 0;
112 coverage = 0; 107 coverage = 0;
113 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { 108 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) {
114 color = 0xffffffff; 109 color = 0xffffffff;
115 coverage = drawState.getCoverageColor(); 110 coverage = drawState.getCoverageColor();
116 } else { 111 } else {
117 color = drawState.getColor(); 112 color = drawState.getColor();
118 coverage = drawState.getCoverageColor(); 113 coverage = drawState.getCoverageColor();
119 } 114 }
120 115
121 this->setColor(drawState, color, sharedState); 116 this->setColor(drawState, color, sharedState);
122 this->setCoverage(drawState, coverage, sharedState); 117 this->setCoverage(drawState, coverage, sharedState);
123 this->setMatrixAndRenderTargetHeight(drawState); 118 this->setMatrixAndRenderTargetHeight(drawState);
124 119
125 if (NULL != dstCopy) { 120 if (NULL != dstCopy) {
126 if (fUniformHandles.fDstCopyTopLeftUni.isValid()) { 121 if (fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()) {
127 fUniformManager->set2f(fUniformHandles.fDstCopyTopLeftUni, 122 fUniformManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyTopLef tUni,
128 static_cast<GrGLfloat>(dstCopy->offset().fX), 123 static_cast<GrGLfloat>(dstCopy->offset().fX),
129 static_cast<GrGLfloat>(dstCopy->offset().fY)) ; 124 static_cast<GrGLfloat>(dstCopy->offset().fY)) ;
130 fUniformManager->set2f(fUniformHandles.fDstCopyScaleUni, 125 fUniformManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyScaleU ni,
131 1.f / dstCopy->texture()->width(), 126 1.f / dstCopy->texture()->width(),
132 1.f / dstCopy->texture()->height()); 127 1.f / dstCopy->texture()->height());
133 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; 128 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ;
134 static GrTextureParams kParams; // the default is clamp, nearest fil tering. 129 static GrTextureParams kParams; // the default is clamp, nearest fil tering.
135 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); 130 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
136 } else { 131 } else {
137 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); 132 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()) ;
138 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); 133 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid( ));
139 } 134 }
140 } else { 135 } else {
141 SkASSERT(!fUniformHandles.fDstCopyTopLeftUni.isValid()); 136 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid());
142 SkASSERT(!fUniformHandles.fDstCopyScaleUni.isValid()); 137 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid());
143 SkASSERT(!fUniformHandles.fDstCopySamplerUni.isValid()); 138 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid());
144 } 139 }
145 140
146 fColorEffects->setData(fGpu, *fUniformManager, colorStages); 141 fBuilderOutput.fColorEffects->setData(fGpu, *fUniformManager, colorStages);
147 fCoverageEffects->setData(fGpu, *fUniformManager, coverageStages); 142 fBuilderOutput.fCoverageEffects->setData(fGpu, *fUniformManager, coverageSta ges);
148 143
149 144
150 // PathTexGen state applies to the the fixed function vertex shader. For 145 // PathTexGen state applies to the the fixed function vertex shader. For
151 // custom shaders, it's ignored, so we don't need to change the texgen 146 // custom shaders, it's ignored, so we don't need to change the texgen
152 // settings in that case. 147 // settings in that case.
153 if (!fHasVertexShader) { 148 if (!fBuilderOutput.fHasVertexShader) {
154 fGpu->flushPathTexGenSettings(fTexCoordSetCnt); 149 fGpu->flushPathTexGenSettings(fBuilderOutput.fTexCoordSetCnt);
155 } 150 }
156 } 151 }
157 152
158 void GrGLProgram::setColor(const GrDrawState& drawState, 153 void GrGLProgram::setColor(const GrDrawState& drawState,
159 GrColor color, 154 GrColor color,
160 SharedGLState* sharedState) { 155 SharedGLState* sharedState) {
161 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); 156 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
162 if (!drawState.hasColorVertexAttribute()) { 157 if (!drawState.hasColorVertexAttribute()) {
163 switch (header.fColorInput) { 158 switch (header.fColorInput) {
164 case GrGLProgramDesc::kAttribute_ColorInput: 159 case GrGLProgramDesc::kAttribute_ColorInput:
165 SkASSERT(-1 != header.fColorAttributeIndex); 160 SkASSERT(-1 != header.fColorAttributeIndex);
166 if (sharedState->fConstAttribColor != color || 161 if (sharedState->fConstAttribColor != color ||
167 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { 162 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) {
168 // OpenGL ES only supports the float varieties of glVertexAt trib 163 // OpenGL ES only supports the float varieties of glVertexAt trib
169 GrGLfloat c[4]; 164 GrGLfloat c[4];
170 GrColorToRGBAFloat(color, c); 165 GrColorToRGBAFloat(color, c);
171 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); 166 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c));
172 sharedState->fConstAttribColor = color; 167 sharedState->fConstAttribColor = color;
173 sharedState->fConstAttribColorIndex = header.fColorAttribute Index; 168 sharedState->fConstAttribColorIndex = header.fColorAttribute Index;
174 } 169 }
175 break; 170 break;
176 case GrGLProgramDesc::kUniform_ColorInput: 171 case GrGLProgramDesc::kUniform_ColorInput:
177 if (fColor != color && fUniformHandles.fColorUni.isValid()) { 172 if (fColor != color && fBuilderOutput.fUniformHandles.fColorUni. isValid()) {
178 // OpenGL ES doesn't support unsigned byte varieties of glUn iform 173 // OpenGL ES doesn't support unsigned byte varieties of glUn iform
179 GrGLfloat c[4]; 174 GrGLfloat c[4];
180 GrColorToRGBAFloat(color, c); 175 GrColorToRGBAFloat(color, c);
181 fUniformManager->set4fv(fUniformHandles.fColorUni, 1, c); 176 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fColo rUni, 1, c);
182 fColor = color; 177 fColor = color;
183 } 178 }
184 sharedState->fConstAttribColorIndex = -1; 179 sharedState->fConstAttribColorIndex = -1;
185 break; 180 break;
186 case GrGLProgramDesc::kSolidWhite_ColorInput: 181 case GrGLProgramDesc::kSolidWhite_ColorInput:
187 case GrGLProgramDesc::kTransBlack_ColorInput: 182 case GrGLProgramDesc::kTransBlack_ColorInput:
188 sharedState->fConstAttribColorIndex = -1; 183 sharedState->fConstAttribColorIndex = -1;
189 break; 184 break;
190 default: 185 default:
191 SkFAIL("Unknown color type."); 186 SkFAIL("Unknown color type.");
(...skipping 18 matching lines...) Expand all
210 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); 205 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c));
211 sharedState->fConstAttribCoverage = coverage; 206 sharedState->fConstAttribCoverage = coverage;
212 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex; 207 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex;
213 } 208 }
214 break; 209 break;
215 case GrGLProgramDesc::kUniform_ColorInput: 210 case GrGLProgramDesc::kUniform_ColorInput:
216 if (fCoverage != coverage) { 211 if (fCoverage != coverage) {
217 // OpenGL ES doesn't support unsigned byte varieties of glUn iform 212 // OpenGL ES doesn't support unsigned byte varieties of glUn iform
218 GrGLfloat c[4]; 213 GrGLfloat c[4];
219 GrColorToRGBAFloat(coverage, c); 214 GrColorToRGBAFloat(coverage, c);
220 fUniformManager->set4fv(fUniformHandles.fCoverageUni, 1, c); 215 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fCove rageUni, 1, c);
221 fCoverage = coverage; 216 fCoverage = coverage;
222 } 217 }
223 sharedState->fConstAttribCoverageIndex = -1; 218 sharedState->fConstAttribCoverageIndex = -1;
224 break; 219 break;
225 case GrGLProgramDesc::kSolidWhite_ColorInput: 220 case GrGLProgramDesc::kSolidWhite_ColorInput:
226 case GrGLProgramDesc::kTransBlack_ColorInput: 221 case GrGLProgramDesc::kTransBlack_ColorInput:
227 sharedState->fConstAttribCoverageIndex = -1; 222 sharedState->fConstAttribCoverageIndex = -1;
228 break; 223 break;
229 default: 224 default:
230 SkFAIL("Unknown coverage type."); 225 SkFAIL("Unknown coverage type.");
231 } 226 }
232 } else { 227 } else {
233 sharedState->fConstAttribCoverageIndex = -1; 228 sharedState->fConstAttribCoverageIndex = -1;
234 } 229 }
235 } 230 }
236 231
237 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { 232 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) {
238 const GrRenderTarget* rt = drawState.getRenderTarget(); 233 const GrRenderTarget* rt = drawState.getRenderTarget();
239 SkISize size; 234 SkISize size;
240 size.set(rt->width(), rt->height()); 235 size.set(rt->width(), rt->height());
241 236
242 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 237 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
243 if (fUniformHandles.fRTHeightUni.isValid() && 238 if (fBuilderOutput.fUniformHandles.fRTHeightUni.isValid() &&
244 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { 239 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) {
245 fUniformManager->set1f(fUniformHandles.fRTHeightUni, SkIntToScalar(size. fHeight)); 240 fUniformManager->set1f(fBuilderOutput.fUniformHandles.fRTHeightUni,
241 SkIntToScalar(size.fHeight));
246 } 242 }
247 243
248 if (!fHasVertexShader) { 244 if (!fBuilderOutput.fHasVertexShader) {
249 SkASSERT(!fUniformHandles.fViewMatrixUni.isValid()); 245 SkASSERT(!fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid());
250 SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); 246 SkASSERT(!fBuilderOutput.fUniformHandles.fRTAdjustmentUni.isValid());
251 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ; 247 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ;
252 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || 248 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
253 fMatrixState.fRenderTargetSize != size || 249 fMatrixState.fRenderTargetSize != size ||
254 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) { 250 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) {
255 SkASSERT(fUniformHandles.fViewMatrixUni.isValid()); 251 SkASSERT(fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid());
256 252
257 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 253 fMatrixState.fViewMatrix = drawState.getViewMatrix();
258 fMatrixState.fRenderTargetSize = size; 254 fMatrixState.fRenderTargetSize = size;
259 fMatrixState.fRenderTargetOrigin = rt->origin(); 255 fMatrixState.fRenderTargetOrigin = rt->origin();
260 256
261 GrGLfloat viewMatrix[3 * 3]; 257 GrGLfloat viewMatrix[3 * 3];
262 fMatrixState.getGLMatrix<3>(viewMatrix); 258 fMatrixState.getGLMatrix<3>(viewMatrix);
263 fUniformManager->setMatrix3f(fUniformHandles.fViewMatrixUni, viewMatrix) ; 259 fUniformManager->setMatrix3f(fBuilderOutput.fUniformHandles.fViewMatrixU ni, viewMatrix);
264 260
265 GrGLfloat rtAdjustmentVec[4]; 261 GrGLfloat rtAdjustmentVec[4];
266 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); 262 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
267 fUniformManager->set4fv(fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmen tVec); 263 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec);
268 } 264 }
269 } 265 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramEffects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698