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

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

Issue 755363002: remove proc key (Closed) Base URL: https://skia.googlesource.com/skia.git@fixkey
Patch Set: address nit Created 6 years 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') | tests/GLProgramsTest.cpp » ('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/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLSLPrettyPrint.h" 10 #include "gl/GrGLSLPrettyPrint.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, 245 void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
246 GrGLSLExpr4* inputCoverage) { 246 GrGLSLExpr4* inputCoverage) {
247 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); 247 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs));
248 int numProcs = fOptState.numFragmentStages(); 248 int numProcs = fOptState.numFragmentStages();
249 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor); 249 this->emitAndInstallFragProcs(0, fOptState.numColorStages(), inputColor);
250 if (fOptState.hasGeometryProcessor()) { 250 if (fOptState.hasGeometryProcessor()) {
251 const GrGeometryProcessor& gp = *fOptState.getGeometryProcessor(); 251 const GrGeometryProcessor& gp = *fOptState.getGeometryProcessor();
252 fVS.emitAttributes(gp); 252 fVS.emitAttributes(gp);
253 ProcKeyProvider keyProvider(&fDesc,
254 ProcKeyProvider::kGeometry_ProcessorType,
255 GrGLProgramDescBuilder::kProcessorKeyOffsets AndLengthOffset);
256 GrGLSLExpr4 output; 253 GrGLSLExpr4 output;
257 this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, keyProvider, *input Coverage, &output); 254 this->emitAndInstallProc<GrGeometryProcessor>(gp, 0, *inputCoverage, &ou tput);
258 *inputCoverage = output; 255 *inputCoverage = output;
259 } 256 }
260 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo verage); 257 this->emitAndInstallFragProcs(fOptState.numColorStages(), numProcs, inputCo verage);
261 } 258 }
262 259
263 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G rGLSLExpr4* inOut) { 260 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, int numProcs, G rGLSLExpr4* inOut) {
264 ProcKeyProvider keyProvider(&fDesc,
265 ProcKeyProvider::kFragment_ProcessorType,
266 GrGLProgramDescBuilder::kProcessorKeyOffsetsAndL engthOffset);
267 for (int e = procOffset; e < numProcs; ++e) { 261 for (int e = procOffset; e < numProcs; ++e) {
268 GrGLSLExpr4 output; 262 GrGLSLExpr4 output;
269 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e); 263 const GrPendingFragmentStage& stage = fOptState.getFragmentStage(e);
270 this->emitAndInstallProc<GrPendingFragmentStage>(stage, e, keyProvider, *inOut, &output); 264 this->emitAndInstallProc<GrPendingFragmentStage>(stage, e, *inOut, &outp ut);
271 *inOut = output; 265 *inOut = output;
272 } 266 }
273 } 267 }
274 268
275 // TODO Processors cannot output zeros because an empty string is all 1s 269 // TODO Processors cannot output zeros because an empty string is all 1s
276 // the fix is to allow effects to take the GrGLSLExpr4 directly 270 // the fix is to allow effects to take the GrGLSLExpr4 directly
277 template <class Proc> 271 template <class Proc>
278 void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc, 272 void GrGLProgramBuilder::emitAndInstallProc(const Proc& proc,
279 int index, 273 int index,
280 const ProcKeyProvider& keyProvider,
281 const GrGLSLExpr4& input, 274 const GrGLSLExpr4& input,
282 GrGLSLExpr4* output) { 275 GrGLSLExpr4* output) {
283 // Program builders have a bit of state we need to clear with each effect 276 // Program builders have a bit of state we need to clear with each effect
284 AutoStageAdvance adv(this); 277 AutoStageAdvance adv(this);
285 278
286 // create var to hold stage result. If we already have a valid output name, just use that 279 // create var to hold stage result. If we already have a valid output name, just use that
287 // otherwise create a new mangled one. 280 // otherwise create a new mangled one.
288 SkString outColorName; 281 SkString outColorName;
289 if (output->isValid()) { 282 if (output->isValid()) {
290 outColorName = output->c_str(); 283 outColorName = output->c_str();
291 } else { 284 } else {
292 this->nameVariable(&outColorName, '\0', "output"); 285 this->nameVariable(&outColorName, '\0', "output");
293 } 286 }
294 fFS.codeAppendf("vec4 %s;", outColorName.c_str()); 287 fFS.codeAppendf("vec4 %s;", outColorName.c_str());
295 *output = outColorName; 288 *output = outColorName;
296 289
297 // Enclose custom code in a block to avoid namespace conflicts 290 // Enclose custom code in a block to avoid namespace conflicts
298 SkString openBrace; 291 SkString openBrace;
299 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); 292 openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name());
300 fFS.codeAppend(openBrace.c_str()); 293 fFS.codeAppend(openBrace.c_str());
301 294
302 this->emitAndInstallProc(proc, keyProvider.get(index), output->c_str(), 295 this->emitAndInstallProc(proc, output->c_str(), input.isOnes() ? NULL : inpu t.c_str());
303 input.isOnes() ? NULL : input.c_str());
304 296
305 fFS.codeAppend("}"); 297 fFS.codeAppend("}");
306 } 298 }
307 299
308 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, 300 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs,
309 const GrProcessorKey& key,
310 const char* outColor, 301 const char* outColor,
311 const char* inColor) { 302 const char* inColor) {
312 GrGLInstalledFragProc* ifp = SkNEW_ARGS(GrGLInstalledFragProc, (fVS.hasLocal Coords())); 303 GrGLInstalledFragProc* ifp = SkNEW_ARGS(GrGLInstalledFragProc, (fVS.hasLocal Coords()));
313 304
314 const GrFragmentProcessor& fp = *fs.getProcessor(); 305 const GrFragmentProcessor& fp = *fs.getProcessor();
315 ifp->fGLProc.reset(fp.getFactory().createGLInstance(fp)); 306 ifp->fGLProc.reset(fp.getFactory().createGLInstance(fp));
316 307
317 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); 308 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures());
318 this->emitSamplers(fp, &samplers, ifp); 309 this->emitSamplers(fp, &samplers, ifp);
319 310
320 // Fragment processors can have coord transforms 311 // Fragment processors can have coord transforms
321 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(fp.numTransforms()); 312 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(fp.numTransforms());
322 this->emitTransforms(fs, &coords, ifp); 313 this->emitTransforms(fs, &coords, ifp);
323 314
324 ifp->fGLProc->emitCode(this, fp, key, outColor, inColor, coords, samplers); 315 ifp->fGLProc->emitCode(this, fp, outColor, inColor, coords, samplers);
325 316
326 // We have to check that effects and the code they emit are consistent, ie i f an effect 317 // We have to check that effects and the code they emit are consistent, ie i f an effect
327 // asks for dst color, then the emit code needs to follow suit 318 // asks for dst color, then the emit code needs to follow suit
328 verify(fp); 319 verify(fp);
329 fFragmentProcessors->fProcs.push_back(ifp); 320 fFragmentProcessors->fProcs.push_back(ifp);
330 } 321 }
331 322
332 void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp, 323 void GrGLProgramBuilder::emitAndInstallProc(const GrGeometryProcessor& gp,
333 const GrProcessorKey& key,
334 const char* outCoverage, 324 const char* outCoverage,
335 const char* inCoverage) { 325 const char* inCoverage) {
336 SkASSERT(!fGeometryProcessor); 326 SkASSERT(!fGeometryProcessor);
337 fGeometryProcessor = SkNEW(GrGLInstalledGeoProc); 327 fGeometryProcessor = SkNEW(GrGLInstalledGeoProc);
338 328
339 fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp)); 329 fGeometryProcessor->fGLProc.reset(gp.getFactory().createGLInstance(gp));
340 330
341 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures()); 331 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures());
342 this->emitSamplers(gp, &samplers, fGeometryProcessor); 332 this->emitSamplers(gp, &samplers, fGeometryProcessor);
343 333
344 GrGLGeometryProcessor::EmitArgs args(this, gp, key, outCoverage, inCoverage, samplers); 334 GrGLGeometryProcessor::EmitArgs args(this, gp, outCoverage, inCoverage, samp lers);
345 fGeometryProcessor->fGLProc->emitCode(args); 335 fGeometryProcessor->fGLProc->emitCode(args);
346 336
347 // We have to check that effects and the code they emit are consistent, ie i f an effect 337 // We have to check that effects and the code they emit are consistent, ie i f an effect
348 // asks for dst color, then the emit code needs to follow suit 338 // asks for dst color, then the emit code needs to follow suit
349 verify(gp); 339 verify(gp);
350 } 340 }
351 341
352 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) { 342 void GrGLProgramBuilder::verify(const GrGeometryProcessor& gp) {
353 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); 343 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition());
354 } 344 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 509 }
520 510
521 //////////////////////////////////////////////////////////////////////////////// /////////////////// 511 //////////////////////////////////////////////////////////////////////////////// ///////////////////
522 512
523 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 513 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
524 int numProcs = fProcs.count(); 514 int numProcs = fProcs.count();
525 for (int e = 0; e < numProcs; ++e) { 515 for (int e = 0; e < numProcs; ++e) {
526 SkDELETE(fProcs[e]); 516 SkDELETE(fProcs[e]);
527 } 517 }
528 } 518 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | tests/GLProgramsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698