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

Side by Side Diff: src/gpu/gl/builders/GrGLProgramBuilder.cpp

Issue 637003003: Opt state takes a GP instead of a GeometryStage (Closed) Base URL: https://skia.googlesource.com/skia.git@builder_cleanup
Patch Set: memory leaks fixed Created 6 years, 2 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/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.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 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 "GrGLProgramBuilder.h" 8 #include "GrGLProgramBuilder.h"
9 #include "gl/GrGLGeometryProcessor.h"
10 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
11 #include "gl/GrGLSLPrettyPrint.h" 10 #include "gl/GrGLSLPrettyPrint.h"
12 #include "gl/GrGLUniformHandle.h" 11 #include "gl/GrGLUniformHandle.h"
13 #include "../GrGpuGL.h" 12 #include "../GrGpuGL.h"
14 #include "GrCoordTransform.h" 13 #include "GrCoordTransform.h"
15 #include "GrGLLegacyNvprProgramBuilder.h" 14 #include "GrGLLegacyNvprProgramBuilder.h"
16 #include "GrGLNvprProgramBuilder.h" 15 #include "GrGLNvprProgramBuilder.h"
17 #include "GrGLProgramBuilder.h" 16 #include "GrGLProgramBuilder.h"
18 #include "GrTexture.h" 17 #include "GrTexture.h"
19 #include "SkRTConf.h" 18 #include "SkRTConf.h"
20 #include "SkTraceEvent.h" 19 #include "SkTraceEvent.h"
21 20
22 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) 21 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
23 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) 22 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
24 23
25 // ES2 FS only guarantees mediump and lowp support 24 // ES2 FS only guarantees mediump and lowp support
26 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar: :kMedium_Precision; 25 static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar: :kMedium_Precision;
27 26
28 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
29 28
30 const int GrGLProgramBuilder::kVarsPerBlock = 8; 29 const int GrGLProgramBuilder::kVarsPerBlock = 8;
31 30
32 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, 31 GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState,
33 const GrGLProgramDesc& desc, 32 const GrGLProgramDesc& desc,
34 GrGpu::DrawType drawType, 33 GrGpu::DrawType drawType,
35 const GrGeometryStage* geometryPr ocessor,
36 const GrFragmentStage* colorStage s[],
37 const GrFragmentStage* coverageSt ages[],
38 GrGpuGL* gpu) { 34 GrGpuGL* gpu) {
39 // create a builder. This will be handed off to effects so they can use it to add 35 // create a builder. This will be handed off to effects so they can use it to add
40 // uniforms, varyings, textures, etc 36 // uniforms, varyings, textures, etc
41 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(desc, 37 SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(desc,
42 optState, 38 optState,
43 drawType, 39 drawType,
44 SkToBool(geom etryProcessor), 40 optState.hasG eometryProcessor(),
45 gpu)); 41 gpu));
46 42
47 GrGLProgramBuilder* pb = builder.get(); 43 GrGLProgramBuilder* pb = builder.get();
48 const GrGLProgramDesc::KeyHeader& header = pb->header(); 44 const GrGLProgramDesc::KeyHeader& header = pb->header();
49 45
50 // emit code to read the dst copy texture, if necessary 46 // emit code to read the dst copy texture, if necessary
51 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey 47 if (GrGLFragmentShaderBuilder::kNoDstRead_DstReadKey != header.fDstReadKey
52 && !gpu->glCaps().fbFetchSupport()) { 48 && !gpu->glCaps().fbFetchSupport()) {
53 pb->fFS.emitCodeToReadDstTexture(); 49 pb->fFS.emitCodeToReadDstTexture();
54 } 50 }
(...skipping 12 matching lines...) Expand all
67 pb->fVS.codeAppend("gl_PointSize = 1.0;"); 63 pb->fVS.codeAppend("gl_PointSize = 1.0;");
68 } 64 }
69 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { 65 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) {
70 pb->fVS.setupBuiltinVertexAttribute("Color", &inputColor); 66 pb->fVS.setupBuiltinVertexAttribute("Color", &inputColor);
71 } 67 }
72 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { 68 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) {
73 pb->fVS.setupBuiltinVertexAttribute("Coverage", &inputCoverage); 69 pb->fVS.setupBuiltinVertexAttribute("Coverage", &inputCoverage);
74 } 70 }
75 } 71 }
76 72
77 pb->createAndEmitProcessors(geometryProcessor, colorStages, coverageStages, &inputColor, 73 pb->emitAndInstallProcs(optState, &inputColor, &inputCoverage);
78 &inputCoverage);
79 74
80 if (hasVertexShader) { 75 if (hasVertexShader) {
81 pb->fVS.transformSkiaToGLCoords(); 76 pb->fVS.transformSkiaToGLCoords();
82 } 77 }
83 78
84 // write the secondary color output if necessary 79 // write the secondary color output if necessary
85 if (GrOptDrawState::kNone_SecondaryOutputType != header.fSecondaryOutputType ) { 80 if (GrOptDrawState::kNone_SecondaryOutputType != header.fSecondaryOutputType ) {
86 pb->fFS.enableSecondaryOutput(inputColor, inputCoverage); 81 pb->fFS.enableSecondaryOutput(inputColor, inputCoverage);
87 } 82 }
88 83
(...skipping 20 matching lines...) Expand all
109 GrGLPathRendering::SeparableShaders_TexturingMode); 104 GrGLPathRendering::SeparableShaders_TexturingMode);
110 SkASSERT(!hasGeometryProcessor); 105 SkASSERT(!hasGeometryProcessor);
111 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState, desc)); 106 return SkNEW_ARGS(GrGLNvprProgramBuilder, (gpu, optState, desc));
112 } else { 107 } else {
113 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState, desc)); 108 return SkNEW_ARGS(GrGLProgramBuilder, (gpu, optState, desc));
114 } 109 }
115 } 110 }
116 111
117 ///////////////////////////////////////////////////////////////////////////// 112 /////////////////////////////////////////////////////////////////////////////
118 113
119 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu, const GrOptDrawState& optSt ate, 114 GrGLProgramBuilder::GrGLProgramBuilder(GrGpuGL* gpu,
115 const GrOptDrawState& optState,
120 const GrGLProgramDesc& desc) 116 const GrGLProgramDesc& desc)
121 : fVS(this) 117 : fVS(this)
122 , fGS(this) 118 , fGS(this)
123 , fFS(this, desc) 119 , fFS(this, desc)
124 , fOutOfStage(true) 120 , fOutOfStage(true)
125 , fStageIndex(-1) 121 , fStageIndex(-1)
122 , fGeometryProcessor(NULL)
126 , fOptState(optState) 123 , fOptState(optState)
127 , fDesc(desc) 124 , fDesc(desc)
128 , fGpu(gpu) 125 , fGpu(gpu)
129 , fUniforms(kVarsPerBlock) { 126 , fUniforms(kVarsPerBlock) {
130 } 127 }
131 128
132 void GrGLProgramBuilder::addVarying(GrSLType type, 129 void GrGLProgramBuilder::addVarying(GrSLType type,
133 const char* name, 130 const char* name,
134 const char** vsOutName, 131 const char** vsOutName,
135 const char** fsInName, 132 const char** fsInName,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 this->addUniform(GrGLProgramBuilder::kFragment_Visibility, 215 this->addUniform(GrGLProgramBuilder::kFragment_Visibility,
219 kVec4f_GrSLType, 216 kVec4f_GrSLType,
220 "Coverage", 217 "Coverage",
221 &name); 218 &name);
222 *inputCoverage = GrGLSLExpr4(name); 219 *inputCoverage = GrGLSLExpr4(name);
223 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) { 220 } else if (GrGLProgramDesc::kAllOnes_ColorInput == header.fCoverageInput) {
224 *inputCoverage = GrGLSLExpr4(1); 221 *inputCoverage = GrGLSLExpr4(1);
225 } 222 }
226 } 223 }
227 224
228 void GrGLProgramBuilder::createAndEmitProcessors(const GrGeometryStage* geometry Processor, 225 void GrGLProgramBuilder::emitAndInstallProcs(const GrOptDrawState& optState,
229 const GrFragmentStage* colorSta ges[], 226 GrGLSLExpr4* inputColor,
230 const GrFragmentStage* coverage Stages[], 227 GrGLSLExpr4* inputCoverage) {
231 GrGLSLExpr4* inputColor, 228 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
232 GrGLSLExpr4* inputCoverage) { 229 int numProcs = optState.numFragmentStages();
233 bool useLocalCoords = fVS.hasExplicitLocalCoords(); 230 this->emitAndInstallFragProcs(0, optState.numColorStages(), inputColor);
234 231 if (optState.hasGeometryProcessor()) {
235 EffectKeyProvider colorKeyProvider(&fDesc, EffectKeyProvider::kColor_EffectT ype); 232 const GrGeometryProcessor& gp = *optState.getGeometryProcessor();
236 int numColorEffects = fDesc.numColorEffects(); 233 fVS.emitAttributes(gp);
237 GrGLInstalledProcessors* ip = SkNEW_ARGS(GrGLInstalledProcessors, (numColorE ffects, 234 ProcKeyProvider keyProvider(&fDesc, ProcKeyProvider::kGeometry_Processor Type);
238 useLocalC oords)); 235 GrGLSLExpr4 output;
239 this->createAndEmitProcessors<GrFragmentStage>(colorStages, numColorEffects, colorKeyProvider, 236 this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *input Coverage, &output);
240 inputColor, ip); 237 *inputCoverage = output;
241 fColorEffects.reset(ip);
242
243 if (geometryProcessor) {
244 fVS.emitAttributes(*geometryProcessor->getProcessor());
245 EffectKeyProvider gpKeyProvider(&fDesc, EffectKeyProvider::kGeometryProc essor_EffectType);
246 ip = SkNEW_ARGS(GrGLInstalledProcessors, (1, useLocalCoords));
247 this->createAndEmitProcessors<GrGeometryStage>(&geometryProcessor, 1, gp KeyProvider,
248 inputCoverage, ip);
249 fGeometryProcessor.reset(ip);
250 } 238 }
251 239 this->emitAndInstallFragProcs(optState.numColorStages(), numProcs, inputCov erage);
252 EffectKeyProvider coverageKeyProvider(&fDesc, EffectKeyProvider::kCoverage_E ffectType);
253 int numCoverageEffects = fDesc.numCoverageEffects();
254 ip = SkNEW_ARGS(GrGLInstalledProcessors, (numCoverageEffects, useLocalCoords ));
255 this->createAndEmitProcessors<GrFragmentStage>(coverageStages, numCoverageEf fects,
256 coverageKeyProvider, inputCov erage, ip);
257 fCoverageEffects.reset(ip);
258 } 240 }
259 241
260 template <class ProcessorStage> 242 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G rGLSLExpr4* inOut) {
261 void GrGLProgramBuilder::createAndEmitProcessors(const ProcessorStage* processSt ages[], 243 ProcKeyProvider keyProvider(&fDesc, ProcKeyProvider::kFragment_ProcessorType );
262 int effectCnt, 244 for (int e = procOffset; e < numProcs; ++e) {
263 const EffectKeyProvider& keyPro vider, 245 GrGLSLExpr4 output;
264 GrGLSLExpr4* fsInOutColor, 246 const GrFragmentStage& stage = fOptState.getFragmentStage(e);
265 GrGLInstalledProcessors* instal ledProcessors) { 247 this->emitAndInstallProc<GrFragmentStage>(stage, e, keyProvider, *inOut, &output);
266 bool effectEmitted = false; 248 *inOut = output;
267
268 GrGLSLExpr4 inColor = *fsInOutColor;
269 GrGLSLExpr4 outColor;
270
271 for (int e = 0; e < effectCnt; ++e) {
272 // Program builders have a bit of state we need to clear with each effec t
273 AutoStageAdvance adv(this);
274 const ProcessorStage& stage = *processStages[e];
275 SkASSERT(stage.getProcessor());
276
277 if (inColor.isZeros()) {
278 SkString inColorName;
279
280 // Effects have no way to communicate zeros, they treat an empty str ing as ones.
281 this->nameVariable(&inColorName, '\0', "input");
282 fFS.codeAppendf("vec4 %s = %s;", inColorName.c_str(), inColor.c_str( ));
283 inColor = inColorName;
284 }
285
286 // create var to hold stage result
287 SkString outColorName;
288 this->nameVariable(&outColorName, '\0', "output");
289 fFS.codeAppendf("vec4 %s;", outColorName.c_str());
290 outColor = outColorName;
291
292 SkASSERT(installedProcessors);
293 const typename ProcessorStage::Processor& processor = *stage.getProcesso r();
294 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(processor.numTrans forms());
295 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(processor.numTextur es());
296
297 this->emitTransforms(stage, &coords, installedProcessors);
298 this->emitSamplers(processor, &samplers, installedProcessors);
299
300 typename ProcessorStage::GLProcessor* glEffect =
301 processor.getFactory().createGLInstance(processor);
302 installedProcessors->addEffect(glEffect);
303
304 // Enclose custom code in a block to avoid namespace conflicts
305 SkString openBrace;
306 openBrace.printf("{ // Stage %d: %s\n", fStageIndex, glEffect->name());
307 fFS.codeAppend(openBrace.c_str());
308 fVS.codeAppend(openBrace.c_str());
309
310 glEffect->emitCode(this, processor, keyProvider.get(e), outColor.c_str() ,
311 inColor.isOnes() ? NULL : inColor.c_str(), coords, sa mplers);
312
313 // We have to check that effects and the code they emit are consistent, ie if an effect
314 // asks for dst color, then the emit code needs to follow suit
315 verify(processor);
316 fFS.codeAppend("}");
317 fVS.codeAppend("}");
318
319 inColor = outColor;
320 effectEmitted = true;
321 }
322
323 if (effectEmitted) {
324 *fsInOutColor = outColor;
325 } 249 }
326 } 250 }
327 251
252 // TODO Processors cannot output zeros because an empty string is all 1s
253 // the fix is to allow effects to take the GrGLSLExpr4 directly
254 template <class Proc>
255 void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc,
256 int index,
257 const ProcKeyProvider keyProvider,
258 const GrGLSLExpr4& input,
259 GrGLSLExpr4* output) {
260 // Program builders have a bit of state we need to clear with each effect
261 AutoStageAdvance adv(this);
262
263 // create var to hold stage result
264 SkString outColorName;
265 this->nameVariable(&outColorName, '\0', "output");
266 fFS.codeAppendf("vec4 %s;", outColorName.c_str());
267 *output = outColorName;
268
269 // Enclose custom code in a block to avoid namespace conflicts
270 SkString openBrace;
271 openBrace.printf("{ // Stage %d\n", fStageIndex);
272 fFS.codeAppend(openBrace.c_str());
273
274 this->emitAndInstallProc(proc, keyProvider.get(index), output->c_str(),
275 input.isOnes() ? NULL : input.c_str());
276
277 fFS.codeAppend("}");
278 }
279
280 void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentStage& fs,
281 const GrProcessorKey& key,
282 const char* outColor,
283 const char* inColor) {
284 GrGLInstalledFragProc* ifp = SkNEW_ARGS(GrGLInstalledFragProc, (fVS.hasLocal Coords()));
285
286 const GrFragmentProcessor& fp = *fs.getProcessor();
287 ifp->fGLProc.reset(fp.getFactory().createGLInstance(fp));
288
289 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures());
290 this->emitSamplers(fp, &samplers, ifp);
291
292 // Fragment processors can have coord transforms
293 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(fp.numTransforms());
294 this->emitTransforms(fs, &coords, ifp);
295
296 ifp->fGLProc->emitCode(this, fp, key, outColor, inColor, coords, samplers);
297
298 // We have to check that effects and the code they emit are consistent, ie i f an effect
299 // asks for dst color, then the emit code needs to follow suit
300 verify(fp);
301 fFragmentProcessors->fProcs.push_back(ifp);
302 }
303
304 void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp,
305 const GrProcessorKey& key,
306 const char* outColor,
307 const char* inColor) {
308 SkASSERT(!fGeometryProcessor);
309 fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
310
311 fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp));
312
313 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
314 this->emitSamplers(gp, &samplers, fGeometryProcessor);
315
316 SkSTArray<2, GrGLProcessor::TransformedCoords> coords;
317
318 // TODO remove coords from emit code signature, probably best to use a struc t here so these
319 // updates are less painful
320 fGeometryProcessor->fGLProc->emitCode(this, gp, key, outColor, inColor, coor ds, samplers);
321
322 // We have to check that effects and the code they emit are consistent, ie i f an effect
323 // asks for dst color, then the emit code needs to follow suit
324 verify(gp);
325 }
326
328 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { 327 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) {
329 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); 328 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition());
330 } 329 }
331 330
332 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { 331 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) {
333 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); 332 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition());
334 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); 333 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor());
335 } 334 }
336 335
337 void GrGLProgramBuilder::emitTransforms(const GrProcessorStage& effectStage, 336 void GrGLProgramBuilder::emitTransforms(const GrFragmentStage& effectStage,
338 GrGLProcessor::TransformedCoordsArray* o utCoords, 337 GrGLProcessor::TransformedCoordsArray* o utCoords,
339 GrGLInstalledProcessors* installedProces sors) { 338 GrGLInstalledFragProc* ifp) {
340 SkTArray<GrGLInstalledProcessors::Transform, true>& transforms = 339 const GrFragmentProcessor* effect = effectStage.getProcessor();
341 installedProcessors->addTransforms();
342 const GrProcessor* effect = effectStage.getProcessor();
343 int numTransforms = effect->numTransforms(); 340 int numTransforms = effect->numTransforms();
344 transforms.push_back_n(numTransforms); 341 ifp->fTransforms.push_back_n(numTransforms);
345 342
346 for (int t = 0; t < numTransforms; t++) { 343 for (int t = 0; t < numTransforms; t++) {
347 const char* uniName = "StageMatrix"; 344 const char* uniName = "StageMatrix";
348 GrSLType varyingType = 345 GrSLType varyingType =
349 effectStage.isPerspectiveCoordTransform(t, fVS.hasExplicitLocalC oords()) ? 346 effectStage.isPerspectiveCoordTransform(t, fVS.hasLocalCoords()) ?
350 kVec3f_GrSLType : 347 kVec3f_GrSLType :
351 kVec2f_GrSLType; 348 kVec2f_GrSLType;
352 349
353 SkString suffixedUniName; 350 SkString suffixedUniName;
354 if (0 != t) { 351 if (0 != t) {
355 suffixedUniName.append(uniName); 352 suffixedUniName.append(uniName);
356 suffixedUniName.appendf("_%i", t); 353 suffixedUniName.appendf("_%i", t);
357 uniName = suffixedUniName.c_str(); 354 uniName = suffixedUniName.c_str();
358 } 355 }
359 transforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVertex_Vis ibility, 356 ifp->fTransforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVert ex_Visibility,
360 kMat33f_GrSLType, 357 kMat33f_GrSLType,
361 uniName, 358 uniName,
362 &uniName).toShaderBuilderIndex( ); 359 &uniName).toShaderBuilder Index();
363 360
364 const char* varyingName = "MatrixCoord"; 361 const char* varyingName = "MatrixCoord";
365 SkString suffixedVaryingName; 362 SkString suffixedVaryingName;
366 if (0 != t) { 363 if (0 != t) {
367 suffixedVaryingName.append(varyingName); 364 suffixedVaryingName.append(varyingName);
368 suffixedVaryingName.appendf("_%i", t); 365 suffixedVaryingName.appendf("_%i", t);
369 varyingName = suffixedVaryingName.c_str(); 366 varyingName = suffixedVaryingName.c_str();
370 } 367 }
371 const char* vsVaryingName; 368 const char* vsVaryingName;
372 const char* fsVaryingName; 369 const char* fsVaryingName;
(...skipping 13 matching lines...) Expand all
386 fVS.codeAppendf("%s = %s * vec3(%s, 1);", 383 fVS.codeAppendf("%s = %s * vec3(%s, 1);",
387 vsVaryingName, uniName, coords.c_str()); 384 vsVaryingName, uniName, coords.c_str());
388 } 385 }
389 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, 386 SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords,
390 (SkString(fsVaryingName), varyingType)); 387 (SkString(fsVaryingName), varyingType));
391 } 388 }
392 } 389 }
393 390
394 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, 391 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor,
395 GrGLProcessor::TextureSamplerArray* outSam plers, 392 GrGLProcessor::TextureSamplerArray* outSam plers,
396 GrGLInstalledProcessors* installedProcesso rs) { 393 GrGLInstalledProc* ip) {
397 SkTArray<GrGLInstalledProcessors::Sampler, true>& samplers = installedProces sors->addSamplers();
398 int numTextures = processor.numTextures(); 394 int numTextures = processor.numTextures();
399 samplers.push_back_n(numTextures); 395 ip->fSamplers.push_back_n(numTextures);
400 SkString name; 396 SkString name;
401 for (int t = 0; t < numTextures; ++t) { 397 for (int t = 0; t < numTextures; ++t) {
402 name.printf("Sampler%d", t); 398 name.printf("Sampler%d", t);
403 samplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragment_Vi sibility, 399 ip->fSamplers[t].fUniform = this->addUniform(GrGLProgramBuilder::kFragme nt_Visibility,
404 kSampler2D_GrSLType, 400 kSampler2D_GrSLType,
405 name.c_str()); 401 name.c_str());
406 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler, 402 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler,
407 (samplers[t].fUniform, processor.textureAccess(t) )); 403 (ip->fSamplers[t].fUniform, processor.textureAcce ss(t)));
408 } 404 }
409 } 405 }
410 406
411 GrGLProgram* GrGLProgramBuilder::finalize() { 407 GrGLProgram* GrGLProgramBuilder::finalize() {
412 // verify we can get a program id 408 // verify we can get a program id
413 GrGLuint programID; 409 GrGLuint programID;
414 GL_CALL_RET(programID, CreateProgram()); 410 GL_CALL_RET(programID, CreateProgram());
415 if (0 == programID) { 411 if (0 == programID) {
416 return NULL; 412 return NULL;
417 } 413 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 cleanupShaders(shaderIDs); 495 cleanupShaders(shaderIDs);
500 } 496 }
501 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { 497 void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
502 for (int i = 0; i < shaderIDs.count(); ++i) { 498 for (int i = 0; i < shaderIDs.count(); ++i) {
503 GL_CALL(DeleteShader(shaderIDs[i])); 499 GL_CALL(DeleteShader(shaderIDs[i]));
504 } 500 }
505 } 501 }
506 502
507 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { 503 GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
508 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn iforms, 504 return SkNEW_ARGS(GrGLProgram, (fGpu, fDesc, fUniformHandles, programID, fUn iforms,
509 fGeometryProcessor, fColorEffects, fCoverage Effects)); 505 fGeometryProcessor, fFragmentProcessors.get( )));
510 } 506 }
511 507
512 //////////////////////////////////////////////////////////////////////////////// 508 //////////////////////////////////////////////////////////////////////////////// ///////////////////
513 509
514 GrGLInstalledProcessors::~GrGLInstalledProcessors() { 510 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
515 int numEffects = fGLProcessors.count(); 511 int numProcs = fProcs.count();
516 for (int e = 0; e < numEffects; ++e) { 512 for (int e = 0; e < numProcs; ++e) {
517 SkDELETE(fGLProcessors[e]); 513 SkDELETE(fProcs[e]);
518 } 514 }
519 } 515 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLVertexShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698