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

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

Issue 365853002: Rename GrGLUniformManager to GrGLProgramResourceManager (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: rebase Created 6 years, 4 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
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDataManager.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"
11 #include "GrEffect.h" 11 #include "GrEffect.h"
12 #include "GrCoordTransform.h" 12 #include "GrCoordTransform.h"
13 #include "GrDrawEffect.h" 13 #include "GrDrawEffect.h"
14 #include "GrGLEffect.h" 14 #include "GrGLEffect.h"
15 #include "GrGpuGL.h" 15 #include "GrGpuGL.h"
16 #include "GrGLShaderVar.h" 16 #include "GrGLShaderVar.h"
17 #include "GrGLSL.h" 17 #include "GrGLSL.h"
18 #include "SkXfermode.h" 18 #include "SkXfermode.h"
19 19
20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) 20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) 21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
22 22
23 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, 23 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu,
24 const GrGLProgramDesc& desc, 24 const GrGLProgramDesc& desc,
25 const GrEffectStage* colorStages[], 25 const GrEffectStage* colorStages[],
26 const GrEffectStage* coverageStages[]) { 26 const GrEffectStage* coverageStages[]) {
27 GrGLShaderBuilder::GenProgramOutput output; 27 GrGLShaderBuilder::GenProgramOutput output;
28 SkAutoTUnref<GrGLUniformManager> uman(SkNEW_ARGS(GrGLUniformManager, (gpu))) ; 28 SkAutoTUnref<GrGLProgramDataManager> pdman(SkNEW_ARGS(GrGLProgramDataManager , (gpu)));
29 if (GrGLShaderBuilder::GenProgram(gpu, uman, desc, colorStages, coverageStag es, 29 if (GrGLShaderBuilder::GenProgram(gpu, pdman, desc, colorStages, coverageSta ges,
30 &output)) { 30 &output)) {
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, pdman, 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 GrGLProgramDataManager* pdman,
40 const GrGLShaderBuilder::GenProgramOutput& builderOutpu t) 40 const GrGLShaderBuilder::GenProgramOutput& builderOutpu t)
41 : fColor(GrColor_ILLEGAL) 41 : fColor(GrColor_ILLEGAL)
42 , fCoverage(GrColor_ILLEGAL) 42 , fCoverage(GrColor_ILLEGAL)
43 , fDstCopyTexUnit(-1) 43 , fDstCopyTexUnit(-1)
44 , fBuilderOutput(builderOutput) 44 , fBuilderOutput(builderOutput)
45 , fDesc(desc) 45 , fDesc(desc)
46 , fGpu(gpu) 46 , fGpu(gpu)
47 , fUniformManager(SkRef(uman)) { 47 , fProgramDataManager(SkRef(pdman)) {
48 this->initSamplerUniforms(); 48 this->initSamplerUniforms();
49 } 49 }
50 50
51 GrGLProgram::~GrGLProgram() { 51 GrGLProgram::~GrGLProgram() {
52 if (fBuilderOutput.fProgramID) { 52 if (fBuilderOutput.fProgramID) {
53 GL_CALL(DeleteProgram(fBuilderOutput.fProgramID)); 53 GL_CALL(DeleteProgram(fBuilderOutput.fProgramID));
54 } 54 }
55 } 55 }
56 56
57 void GrGLProgram::abandon() { 57 void GrGLProgram::abandon() {
(...skipping 19 matching lines...) Expand all
77 default: 77 default:
78 SkFAIL("Unexpected coverage output"); 78 SkFAIL("Unexpected coverage output");
79 break; 79 break;
80 } 80 }
81 } 81 }
82 82
83 void GrGLProgram::initSamplerUniforms() { 83 void GrGLProgram::initSamplerUniforms() {
84 GL_CALL(UseProgram(fBuilderOutput.fProgramID)); 84 GL_CALL(UseProgram(fBuilderOutput.fProgramID));
85 GrGLint texUnitIdx = 0; 85 GrGLint texUnitIdx = 0;
86 if (fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { 86 if (fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()) {
87 fUniformManager->setSampler(fBuilderOutput.fUniformHandles.fDstCopySampl erUni, texUnitIdx); 87 fProgramDataManager->setSampler(fBuilderOutput.fUniformHandles.fDstCopyS amplerUni, texUnitIdx);
88 fDstCopyTexUnit = texUnitIdx++; 88 fDstCopyTexUnit = texUnitIdx++;
89 } 89 }
90 fBuilderOutput.fColorEffects->initSamplers(*fUniformManager, &texUnitIdx); 90 fBuilderOutput.fColorEffects->initSamplers(*fProgramDataManager, &texUnitIdx );
91 fBuilderOutput.fCoverageEffects->initSamplers(*fUniformManager, &texUnitIdx) ; 91 fBuilderOutput.fCoverageEffects->initSamplers(*fProgramDataManager, &texUnit Idx);
92 } 92 }
93 93
94 /////////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////////
95 95
96 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, 96 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts,
97 const GrEffectStage* colorStages[], 97 const GrEffectStage* colorStages[],
98 const GrEffectStage* coverageStages[], 98 const GrEffectStage* coverageStages[],
99 const GrDeviceCoordTexture* dstCopy, 99 const GrDeviceCoordTexture* dstCopy,
100 SharedGLState* sharedState) { 100 SharedGLState* sharedState) {
101 const GrDrawState& drawState = fGpu->getDrawState(); 101 const GrDrawState& drawState = fGpu->getDrawState();
(...skipping 10 matching lines...) Expand all
112 color = drawState.getColor(); 112 color = drawState.getColor();
113 coverage = drawState.getCoverageColor(); 113 coverage = drawState.getCoverageColor();
114 } 114 }
115 115
116 this->setColor(drawState, color, sharedState); 116 this->setColor(drawState, color, sharedState);
117 this->setCoverage(drawState, coverage, sharedState); 117 this->setCoverage(drawState, coverage, sharedState);
118 this->setMatrixAndRenderTargetHeight(drawState); 118 this->setMatrixAndRenderTargetHeight(drawState);
119 119
120 if (NULL != dstCopy) { 120 if (NULL != dstCopy) {
121 if (fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()) { 121 if (fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()) {
122 fUniformManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyTopLef tUni, 122 fProgramDataManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyTo pLeftUni,
123 static_cast<GrGLfloat>(dstCopy->offset().fX), 123 static_cast<GrGLfloat>(dstCopy->offset(). fX),
124 static_cast<GrGLfloat>(dstCopy->offset().fY)) ; 124 static_cast<GrGLfloat>(dstCopy->offset(). fY));
125 fUniformManager->set2f(fBuilderOutput.fUniformHandles.fDstCopyScaleU ni, 125 fProgramDataManager->set2f(fBuilderOutput.fUniformHandles.fDstCopySc aleUni,
126 1.f / dstCopy->texture()->width(), 126 1.f / dstCopy->texture()->width(),
127 1.f / dstCopy->texture()->height()); 127 1.f / dstCopy->texture()->height());
128 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; 128 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ;
129 static GrTextureParams kParams; // the default is clamp, nearest fil tering. 129 static GrTextureParams kParams; // the default is clamp, nearest fil tering.
130 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); 130 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
131 } else { 131 } else {
132 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()) ; 132 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()) ;
133 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid( )); 133 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid( ));
134 } 134 }
135 } else { 135 } else {
136 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid()); 136 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyTopLeftUni.isValid());
137 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid()); 137 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopyScaleUni.isValid());
138 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid()); 138 SkASSERT(!fBuilderOutput.fUniformHandles.fDstCopySamplerUni.isValid());
139 } 139 }
140 140
141 fBuilderOutput.fColorEffects->setData(fGpu, *fUniformManager, colorStages); 141 fBuilderOutput.fColorEffects->setData(fGpu, *fProgramDataManager, colorStage s);
142 fBuilderOutput.fCoverageEffects->setData(fGpu, *fUniformManager, coverageSta ges); 142 fBuilderOutput.fCoverageEffects->setData(fGpu, *fProgramDataManager, coverag eStages);
143 143
144 144
145 // PathTexGen state applies to the the fixed function vertex shader. For 145 // PathTexGen state applies to the the fixed function vertex shader. For
146 // 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
147 // settings in that case. 147 // settings in that case.
148 if (!fBuilderOutput.fHasVertexShader) { 148 if (!fBuilderOutput.fHasVertexShader) {
149 fGpu->flushPathTexGenSettings(fBuilderOutput.fTexCoordSetCnt); 149 fGpu->flushPathTexGenSettings(fBuilderOutput.fTexCoordSetCnt);
150 } 150 }
151 } 151 }
152 152
(...skipping 13 matching lines...) Expand all
166 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); 166 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c));
167 sharedState->fConstAttribColor = color; 167 sharedState->fConstAttribColor = color;
168 sharedState->fConstAttribColorIndex = header.fColorAttribute Index; 168 sharedState->fConstAttribColorIndex = header.fColorAttribute Index;
169 } 169 }
170 break; 170 break;
171 case GrGLProgramDesc::kUniform_ColorInput: 171 case GrGLProgramDesc::kUniform_ColorInput:
172 if (fColor != color && fBuilderOutput.fUniformHandles.fColorUni. isValid()) { 172 if (fColor != color && fBuilderOutput.fUniformHandles.fColorUni. isValid()) {
173 // OpenGL ES doesn't support unsigned byte varieties of glUn iform 173 // OpenGL ES doesn't support unsigned byte varieties of glUn iform
174 GrGLfloat c[4]; 174 GrGLfloat c[4];
175 GrColorToRGBAFloat(color, c); 175 GrColorToRGBAFloat(color, c);
176 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fColo rUni, 1, c); 176 fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.f ColorUni, 1, c);
177 fColor = color; 177 fColor = color;
178 } 178 }
179 sharedState->fConstAttribColorIndex = -1; 179 sharedState->fConstAttribColorIndex = -1;
180 break; 180 break;
181 default: 181 default:
182 SkFAIL("Unexpected color type."); 182 SkFAIL("Unexpected color type.");
183 } 183 }
184 } else { 184 } else {
185 sharedState->fConstAttribColorIndex = -1; 185 sharedState->fConstAttribColorIndex = -1;
186 } 186 }
(...skipping 14 matching lines...) Expand all
201 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); 201 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c));
202 sharedState->fConstAttribCoverage = coverage; 202 sharedState->fConstAttribCoverage = coverage;
203 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex; 203 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex;
204 } 204 }
205 break; 205 break;
206 case GrGLProgramDesc::kUniform_ColorInput: 206 case GrGLProgramDesc::kUniform_ColorInput:
207 if (fCoverage != coverage) { 207 if (fCoverage != coverage) {
208 // OpenGL ES doesn't support unsigned byte varieties of glUn iform 208 // OpenGL ES doesn't support unsigned byte varieties of glUn iform
209 GrGLfloat c[4]; 209 GrGLfloat c[4];
210 GrColorToRGBAFloat(coverage, c); 210 GrColorToRGBAFloat(coverage, c);
211 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fCove rageUni, 1, c); 211 fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.f CoverageUni, 1, c);
212 fCoverage = coverage; 212 fCoverage = coverage;
213 } 213 }
214 sharedState->fConstAttribCoverageIndex = -1; 214 sharedState->fConstAttribCoverageIndex = -1;
215 break; 215 break;
216 case GrGLProgramDesc::kSolidWhite_ColorInput: 216 case GrGLProgramDesc::kSolidWhite_ColorInput:
217 sharedState->fConstAttribCoverageIndex = -1; 217 sharedState->fConstAttribCoverageIndex = -1;
218 break; 218 break;
219 default: 219 default:
220 SkFAIL("Unexpected coverage type."); 220 SkFAIL("Unexpected coverage type.");
221 } 221 }
222 } else { 222 } else {
223 sharedState->fConstAttribCoverageIndex = -1; 223 sharedState->fConstAttribCoverageIndex = -1;
224 } 224 }
225 } 225 }
226 226
227 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { 227 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) {
228 const GrRenderTarget* rt = drawState.getRenderTarget(); 228 const GrRenderTarget* rt = drawState.getRenderTarget();
229 SkISize size; 229 SkISize size;
230 size.set(rt->width(), rt->height()); 230 size.set(rt->width(), rt->height());
231 231
232 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 232 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
233 if (fBuilderOutput.fUniformHandles.fRTHeightUni.isValid() && 233 if (fBuilderOutput.fUniformHandles.fRTHeightUni.isValid() &&
234 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { 234 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) {
235 fUniformManager->set1f(fBuilderOutput.fUniformHandles.fRTHeightUni, 235 fProgramDataManager->set1f(fBuilderOutput.fUniformHandles.fRTHeightUni,
236 SkIntToScalar(size.fHeight)); 236 SkIntToScalar(size.fHeight));
237 } 237 }
238 238
239 if (!fBuilderOutput.fHasVertexShader) { 239 if (!fBuilderOutput.fHasVertexShader) {
240 SkASSERT(!fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid()); 240 SkASSERT(!fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid());
241 SkASSERT(!fBuilderOutput.fUniformHandles.fRTAdjustmentUni.isValid()); 241 SkASSERT(!fBuilderOutput.fUniformHandles.fRTAdjustmentUni.isValid());
242 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ; 242 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ;
243 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || 243 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
244 fMatrixState.fRenderTargetSize != size || 244 fMatrixState.fRenderTargetSize != size ||
245 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) { 245 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) {
246 SkASSERT(fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid()); 246 SkASSERT(fBuilderOutput.fUniformHandles.fViewMatrixUni.isValid());
247 247
248 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 248 fMatrixState.fViewMatrix = drawState.getViewMatrix();
249 fMatrixState.fRenderTargetSize = size; 249 fMatrixState.fRenderTargetSize = size;
250 fMatrixState.fRenderTargetOrigin = rt->origin(); 250 fMatrixState.fRenderTargetOrigin = rt->origin();
251 251
252 GrGLfloat viewMatrix[3 * 3]; 252 GrGLfloat viewMatrix[3 * 3];
253 fMatrixState.getGLMatrix<3>(viewMatrix); 253 fMatrixState.getGLMatrix<3>(viewMatrix);
254 fUniformManager->setMatrix3f(fBuilderOutput.fUniformHandles.fViewMatrixU ni, viewMatrix); 254 fProgramDataManager->setMatrix3f(fBuilderOutput.fUniformHandles.fViewMat rixUni, viewMatrix);
255 255
256 GrGLfloat rtAdjustmentVec[4]; 256 GrGLfloat rtAdjustmentVec[4];
257 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); 257 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
258 fUniformManager->set4fv(fBuilderOutput.fUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); 258 fProgramDataManager->set4fv(fBuilderOutput.fUniformHandles.fRTAdjustment Uni, 1, rtAdjustmentVec);
259 } 259 }
260 } 260 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDataManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698