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

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

Issue 560443004: Revert of Attach GrOptDrawState into shader building pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@opt2
Patch Set: Created 6 years, 3 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/GrGLProgramDesc.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 #include "GrGLProgram.h" 8 #include "GrGLProgram.h"
8 9
9 #include "GrAllocator.h" 10 #include "GrAllocator.h"
10 #include "GrEffect.h" 11 #include "GrEffect.h"
11 #include "GrCoordTransform.h" 12 #include "GrCoordTransform.h"
12 #include "GrDrawEffect.h" 13 #include "GrDrawEffect.h"
13 #include "GrGLEffect.h" 14 #include "GrGLEffect.h"
14 #include "GrGpuGL.h" 15 #include "GrGpuGL.h"
15 #include "GrGLPathRendering.h" 16 #include "GrGLPathRendering.h"
16 #include "GrGLShaderVar.h" 17 #include "GrGLShaderVar.h"
17 #include "GrGLSL.h" 18 #include "GrGLSL.h"
18 #include "GrOptDrawState.h"
19 #include "SkXfermode.h" 19 #include "SkXfermode.h"
20 20
21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) 21 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X)
22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
23 23
24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, 24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu,
25 const GrGLProgramDesc& desc, 25 const GrGLProgramDesc& desc,
26 const GrEffectStage* geometryProcessor, 26 const GrEffectStage* geometryProcessor,
27 const GrEffectStage* colorStages[], 27 const GrEffectStage* colorStages[],
28 const GrEffectStage* coverageStages[]) { 28 const GrEffectStage* coverageStages[]) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 if (fGeometryProcessor.get()) { 103 if (fGeometryProcessor.get()) {
104 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); 104 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx);
105 } 105 }
106 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); 106 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx);
107 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); 107 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx);
108 } 108 }
109 109
110 /////////////////////////////////////////////////////////////////////////////// 110 ///////////////////////////////////////////////////////////////////////////////
111 111
112 void GrGLProgram::setData(const GrOptDrawState& optState, 112 void GrGLProgram::setData(GrGpu::DrawType drawType,
113 GrGpu::DrawType drawType, 113 GrDrawState::BlendOptFlags blendOpts,
114 const GrEffectStage* geometryProcessor, 114 const GrEffectStage* geometryProcessor,
115 const GrEffectStage* colorStages[], 115 const GrEffectStage* colorStages[],
116 const GrEffectStage* coverageStages[], 116 const GrEffectStage* coverageStages[],
117 const GrDeviceCoordTexture* dstCopy, 117 const GrDeviceCoordTexture* dstCopy,
118 SharedGLState* sharedState) { 118 SharedGLState* sharedState) {
119 GrColor color = optState.getColor(); 119 const GrDrawState& drawState = fGpu->getDrawState();
120 GrColor coverage = optState.getCoverageColor();
121 120
122 this->setColor(optState, color, sharedState); 121 GrColor color;
123 this->setCoverage(optState, coverage, sharedState); 122 GrColor coverage;
124 this->setMatrixAndRenderTargetHeight(drawType, optState); 123 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) {
124 color = 0;
125 coverage = 0;
126 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) {
127 color = 0xffffffff;
128 coverage = drawState.getCoverageColor();
129 } else {
130 color = drawState.getColor();
131 coverage = drawState.getCoverageColor();
132 }
133
134 this->setColor(drawState, color, sharedState);
135 this->setCoverage(drawState, coverage, sharedState);
136 this->setMatrixAndRenderTargetHeight(drawType, drawState);
125 137
126 if (dstCopy) { 138 if (dstCopy) {
127 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { 139 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
128 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, 140 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
129 static_cast<GrGLfloat>(dstCopy->offset(). fX), 141 static_cast<GrGLfloat>(dstCopy->offset(). fX),
130 static_cast<GrGLfloat>(dstCopy->offset(). fY)); 142 static_cast<GrGLfloat>(dstCopy->offset(). fY));
131 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, 143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
132 1.f / dstCopy->texture()->width(), 144 1.f / dstCopy->texture()->width(),
133 1.f / dstCopy->texture()->height()); 145 1.f / dstCopy->texture()->height());
134 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; 146 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ;
(...skipping 17 matching lines...) Expand all
152 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages ); 164 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages );
153 165
154 // PathTexGen state applies to the the fixed function vertex shader. For 166 // PathTexGen state applies to the the fixed function vertex shader. For
155 // custom shaders, it's ignored, so we don't need to change the texgen 167 // custom shaders, it's ignored, so we don't need to change the texgen
156 // settings in that case. 168 // settings in that case.
157 if (!fHasVertexShader) { 169 if (!fHasVertexShader) {
158 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); 170 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt);
159 } 171 }
160 } 172 }
161 173
162 void GrGLProgram::setColor(const GrOptDrawState& optState, 174 void GrGLProgram::setColor(const GrDrawState& drawState,
163 GrColor color, 175 GrColor color,
164 SharedGLState* sharedState) { 176 SharedGLState* sharedState) {
165 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); 177 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
166 if (!optState.hasColorVertexAttribute()) { 178 if (!drawState.hasColorVertexAttribute() || drawState.canIgnoreColorAttribut e()) {
167 switch (header.fColorInput) { 179 switch (header.fColorInput) {
168 case GrGLProgramDesc::kAttribute_ColorInput: 180 case GrGLProgramDesc::kAttribute_ColorInput:
169 SkASSERT(-1 != header.fColorAttributeIndex); 181 SkASSERT(-1 != header.fColorAttributeIndex);
170 if (sharedState->fConstAttribColor != color || 182 if (sharedState->fConstAttribColor != color ||
171 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) { 183 sharedState->fConstAttribColorIndex != header.fColorAttribut eIndex) {
172 // OpenGL ES only supports the float varieties of glVertexAt trib 184 // OpenGL ES only supports the float varieties of glVertexAt trib
173 GrGLfloat c[4]; 185 GrGLfloat c[4];
174 GrColorToRGBAFloat(color, c); 186 GrColorToRGBAFloat(color, c);
175 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); 187 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c));
176 sharedState->fConstAttribColor = color; 188 sharedState->fConstAttribColor = color;
(...skipping 14 matching lines...) Expand all
191 sharedState->fConstAttribColorIndex = -1; 203 sharedState->fConstAttribColorIndex = -1;
192 break; 204 break;
193 default: 205 default:
194 SkFAIL("Unexpected color type."); 206 SkFAIL("Unexpected color type.");
195 } 207 }
196 } else { 208 } else {
197 sharedState->fConstAttribColorIndex = -1; 209 sharedState->fConstAttribColorIndex = -1;
198 } 210 }
199 } 211 }
200 212
201 void GrGLProgram::setCoverage(const GrOptDrawState& optState, 213 void GrGLProgram::setCoverage(const GrDrawState& drawState,
202 GrColor coverage, 214 GrColor coverage,
203 SharedGLState* sharedState) { 215 SharedGLState* sharedState) {
204 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); 216 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
205 if (!optState.hasCoverageVertexAttribute()) { 217 if (!drawState.hasCoverageVertexAttribute()) {
206 switch (header.fCoverageInput) { 218 switch (header.fCoverageInput) {
207 case GrGLProgramDesc::kAttribute_ColorInput: 219 case GrGLProgramDesc::kAttribute_ColorInput:
208 if (sharedState->fConstAttribCoverage != coverage || 220 if (sharedState->fConstAttribCoverage != coverage ||
209 sharedState->fConstAttribCoverageIndex != header.fCoverageAt tributeIndex) { 221 sharedState->fConstAttribCoverageIndex != header.fCoverageAt tributeIndex) {
210 // OpenGL ES only supports the float varieties of glVertexA ttrib 222 // OpenGL ES only supports the float varieties of glVertexA ttrib
211 GrGLfloat c[4]; 223 GrGLfloat c[4];
212 GrColorToRGBAFloat(coverage, c); 224 GrColorToRGBAFloat(coverage, c);
213 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); 225 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c));
214 sharedState->fConstAttribCoverage = coverage; 226 sharedState->fConstAttribCoverage = coverage;
215 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex; 227 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt ributeIndex;
(...skipping 14 matching lines...) Expand all
230 break; 242 break;
231 default: 243 default:
232 SkFAIL("Unexpected coverage type."); 244 SkFAIL("Unexpected coverage type.");
233 } 245 }
234 } else { 246 } else {
235 sharedState->fConstAttribCoverageIndex = -1; 247 sharedState->fConstAttribCoverageIndex = -1;
236 } 248 }
237 } 249 }
238 250
239 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, 251 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
240 const GrOptDrawState& optState) { 252 const GrDrawState& drawState) {
241 const GrRenderTarget* rt = optState.getRenderTarget(); 253 const GrRenderTarget* rt = drawState.getRenderTarget();
242 SkISize size; 254 SkISize size;
243 size.set(rt->width(), rt->height()); 255 size.set(rt->width(), rt->height());
244 256
245 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 257 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
246 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && 258 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
247 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { 259 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) {
248 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, 260 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
249 SkIntToScalar(size.fHeight)); 261 SkIntToScalar(size.fHeight));
250 } 262 }
251 263
252 if (GrGpu::IsPathRenderingDrawType(drawType)) { 264 if (GrGpu::IsPathRenderingDrawType(drawType)) {
253 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s ize, rt->origin()); 265 fGpu->glPathRendering()->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin());
254 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || 266 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
255 fMatrixState.fRenderTargetSize != size || 267 fMatrixState.fRenderTargetSize != size ||
256 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix())) { 268 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) {
257 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); 269 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
258 270
259 fMatrixState.fViewMatrix = optState.getViewMatrix(); 271 fMatrixState.fViewMatrix = drawState.getViewMatrix();
260 fMatrixState.fRenderTargetSize = size; 272 fMatrixState.fRenderTargetSize = size;
261 fMatrixState.fRenderTargetOrigin = rt->origin(); 273 fMatrixState.fRenderTargetOrigin = rt->origin();
262 274
263 GrGLfloat viewMatrix[3 * 3]; 275 GrGLfloat viewMatrix[3 * 3];
264 fMatrixState.getGLMatrix<3>(viewMatrix); 276 fMatrixState.getGLMatrix<3>(viewMatrix);
265 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix); 277 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix);
266 278
267 GrGLfloat rtAdjustmentVec[4]; 279 GrGLfloat rtAdjustmentVec[4];
268 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); 280 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
269 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec); 281 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec);
270 } 282 }
271 } 283 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgram.h ('k') | src/gpu/gl/GrGLProgramDesc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698