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

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

Issue 367643004: Implement NVPR on GLES (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
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 "GrGLPathRendering.h"
16 #include "GrGLShaderVar.h" 17 #include "GrGLShaderVar.h"
17 #include "GrGLSL.h" 18 #include "GrGLSL.h"
18 #include "SkXfermode.h" 19 #include "SkXfermode.h"
19 20
20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) 21 #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) 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X)
22 23
23 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, 24 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu,
24 const GrGLProgramDesc& desc, 25 const GrGLProgramDesc& desc,
25 const GrEffectStage* colorStages[], 26 const GrEffectStage* colorStages[],
26 const GrEffectStage* coverageStages[]) { 27 const GrEffectStage* coverageStages[]) {
27 SkAutoTDelete<GrGLShaderBuilder> builder; 28 SkAutoTDelete<GrGLShaderBuilder> builder;
28 if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing( )) { 29 if (!desc.getHeader().fHasVertexCode &&
bsalomon 2014/08/07 21:02:52 I think we should probably rename this field from
30 gpu->glCaps().pathRenderingSupport() &&
31 !gpu->pathRendering()->caps().fragmentInputGenSupport) {
32 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyShaderBuilder, (gpu, desc)));
33 } else {
29 builder.reset(SkNEW_ARGS(GrGLFullShaderBuilder, (gpu, desc))); 34 builder.reset(SkNEW_ARGS(GrGLFullShaderBuilder, (gpu, desc)));
30 } else {
31 builder.reset(SkNEW_ARGS(GrGLFragmentOnlyShaderBuilder, (gpu, desc)));
32 } 35 }
33 36
34 if (builder->genProgram(colorStages, coverageStages)) { 37 if (builder->genProgram(colorStages, coverageStages)) {
35 SkASSERT(0 != builder->getProgramID()); 38 SkASSERT(0 != builder->getProgramID());
36 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder)); 39 return SkNEW_ARGS(GrGLProgram, (gpu, desc, *builder));
37 } 40 }
38 return NULL; 41 return NULL;
39 } 42 }
40 43
41 GrGLProgram::GrGLProgram(GrGpuGL* gpu, 44 GrGLProgram::GrGLProgram(GrGpuGL* gpu,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) { 97 if (fBuiltinUniformHandles.fDstCopySamplerUni.isValid()) {
95 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx); 98 fProgramDataManager.setSampler(fBuiltinUniformHandles.fDstCopySamplerUni , texUnitIdx);
96 fDstCopyTexUnit = texUnitIdx++; 99 fDstCopyTexUnit = texUnitIdx++;
97 } 100 }
98 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); 101 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx);
99 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); 102 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx);
100 } 103 }
101 104
102 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
103 106
104 void GrGLProgram::setData(GrDrawState::BlendOptFlags blendOpts, 107 void GrGLProgram::setData(GrGpu::DrawType drawType,
108 GrDrawState::BlendOptFlags blendOpts,
105 const GrEffectStage* colorStages[], 109 const GrEffectStage* colorStages[],
106 const GrEffectStage* coverageStages[], 110 const GrEffectStage* coverageStages[],
107 const GrDeviceCoordTexture* dstCopy, 111 const GrDeviceCoordTexture* dstCopy,
108 SharedGLState* sharedState) { 112 SharedGLState* sharedState) {
109 const GrDrawState& drawState = fGpu->getDrawState(); 113 const GrDrawState& drawState = fGpu->getDrawState();
110 114
111 GrColor color; 115 GrColor color;
112 GrColor coverage; 116 GrColor coverage;
113 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { 117 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) {
114 color = 0; 118 color = 0;
115 coverage = 0; 119 coverage = 0;
116 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { 120 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) {
117 color = 0xffffffff; 121 color = 0xffffffff;
118 coverage = drawState.getCoverageColor(); 122 coverage = drawState.getCoverageColor();
119 } else { 123 } else {
120 color = drawState.getColor(); 124 color = drawState.getColor();
121 coverage = drawState.getCoverageColor(); 125 coverage = drawState.getCoverageColor();
122 } 126 }
123 127
124 this->setColor(drawState, color, sharedState); 128 this->setColor(drawState, color, sharedState);
125 this->setCoverage(drawState, coverage, sharedState); 129 this->setCoverage(drawState, coverage, sharedState);
126 this->setMatrixAndRenderTargetHeight(drawState); 130 this->setMatrixAndRenderTargetHeight(drawType, drawState);
127 131
128 if (NULL != dstCopy) { 132 if (NULL != dstCopy) {
129 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { 133 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) {
130 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, 134 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni,
131 static_cast<GrGLfloat>(dstCopy->offset(). fX), 135 static_cast<GrGLfloat>(dstCopy->offset(). fX),
132 static_cast<GrGLfloat>(dstCopy->offset(). fY)); 136 static_cast<GrGLfloat>(dstCopy->offset(). fY));
133 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, 137 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni,
134 1.f / dstCopy->texture()->width(), 138 1.f / dstCopy->texture()->width(),
135 1.f / dstCopy->texture()->height()); 139 1.f / dstCopy->texture()->height());
136 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ; 140 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture()) ;
137 static GrTextureParams kParams; // the default is clamp, nearest fil tering. 141 static GrTextureParams kParams; // the default is clamp, nearest fil tering.
138 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture); 142 fGpu->bindTexture(fDstCopyTexUnit, kParams, texture);
139 } else { 143 } else {
140 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); 144 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
141 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); 145 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
142 } 146 }
143 } else { 147 } else {
144 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()); 148 SkASSERT(!fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid());
145 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid()); 149 SkASSERT(!fBuiltinUniformHandles.fDstCopyScaleUni.isValid());
146 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid()); 150 SkASSERT(!fBuiltinUniformHandles.fDstCopySamplerUni.isValid());
147 } 151 }
148 152
149 fColorEffects->setData(fGpu, fProgramDataManager, colorStages); 153 fColorEffects->setData(fGpu, drawType,fProgramDataManager, colorStages);
150 fCoverageEffects->setData(fGpu, fProgramDataManager, coverageStages); 154 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages );
151
152 155
153 // PathTexGen state applies to the the fixed function vertex shader. For 156 // PathTexGen state applies to the the fixed function vertex shader. For
154 // custom shaders, it's ignored, so we don't need to change the texgen 157 // custom shaders, it's ignored, so we don't need to change the texgen
155 // settings in that case. 158 // settings in that case.
156 if (!fHasVertexShader) { 159 if (!fHasVertexShader) {
157 fGpu->flushPathTexGenSettings(fTexCoordSetCnt); 160 fGpu->flushPathTexGenSettings(fTexCoordSetCnt);
158 } 161 }
159 } 162 }
160 163
161 void GrGLProgram::setColor(const GrDrawState& drawState, 164 void GrGLProgram::setColor(const GrDrawState& drawState,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 sharedState->fConstAttribCoverageIndex = -1; 228 sharedState->fConstAttribCoverageIndex = -1;
226 break; 229 break;
227 default: 230 default:
228 SkFAIL("Unexpected coverage type."); 231 SkFAIL("Unexpected coverage type.");
229 } 232 }
230 } else { 233 } else {
231 sharedState->fConstAttribCoverageIndex = -1; 234 sharedState->fConstAttribCoverageIndex = -1;
232 } 235 }
233 } 236 }
234 237
235 void GrGLProgram::setMatrixAndRenderTargetHeight(const GrDrawState& drawState) { 238 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
239 const GrDrawState& drawState) {
236 const GrRenderTarget* rt = drawState.getRenderTarget(); 240 const GrRenderTarget* rt = drawState.getRenderTarget();
237 SkISize size; 241 SkISize size;
238 size.set(rt->width(), rt->height()); 242 size.set(rt->width(), rt->height());
239 243
240 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. 244 // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
241 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && 245 if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
242 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { 246 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) {
243 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, 247 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni,
244 SkIntToScalar(size.fHeight)); 248 SkIntToScalar(size.fHeight));
245 } 249 }
246 250
247 if (!fHasVertexShader) { 251 if (GrGpu::IsPathRenderingDrawType(drawType)) {
248 SkASSERT(!fBuiltinUniformHandles.fViewMatrixUni.isValid());
249 SkASSERT(!fBuiltinUniformHandles.fRTAdjustmentUni.isValid());
250 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ; 252 fGpu->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin()) ;
251 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || 253 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() ||
252 fMatrixState.fRenderTargetSize != size || 254 fMatrixState.fRenderTargetSize != size ||
253 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) { 255 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix()) ) {
254 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); 256 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid());
255 257
256 fMatrixState.fViewMatrix = drawState.getViewMatrix(); 258 fMatrixState.fViewMatrix = drawState.getViewMatrix();
257 fMatrixState.fRenderTargetSize = size; 259 fMatrixState.fRenderTargetSize = size;
258 fMatrixState.fRenderTargetOrigin = rt->origin(); 260 fMatrixState.fRenderTargetOrigin = rt->origin();
259 261
260 GrGLfloat viewMatrix[3 * 3]; 262 GrGLfloat viewMatrix[3 * 3];
261 fMatrixState.getGLMatrix<3>(viewMatrix); 263 fMatrixState.getGLMatrix<3>(viewMatrix);
262 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix); 264 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v iewMatrix);
263 265
264 GrGLfloat rtAdjustmentVec[4]; 266 GrGLfloat rtAdjustmentVec[4];
265 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); 267 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec);
266 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec); 268 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r tAdjustmentVec);
267 } 269 }
268 } 270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698