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

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

Issue 1425013003: Remove GrGLProcessor and create GrGLSLTextureSampler class. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove grglprocessor from gyp Created 5 years, 1 month 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/GrGLShaderBuilder.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 9
10 #include "GrAutoLocaleSetter.h" 10 #include "GrAutoLocaleSetter.h"
11 #include "GrCoordTransform.h" 11 #include "GrCoordTransform.h"
12 #include "GrGLProgramBuilder.h" 12 #include "GrGLProgramBuilder.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "SkRTConf.h" 14 #include "SkRTConf.h"
15 #include "SkTraceEvent.h" 15 #include "SkTraceEvent.h"
16 #include "gl/GrGLGeometryProcessor.h" 16 #include "gl/GrGLGeometryProcessor.h"
17 #include "gl/GrGLGpu.h" 17 #include "gl/GrGLGpu.h"
18 #include "gl/GrGLProgram.h" 18 #include "gl/GrGLProgram.h"
19 #include "gl/GrGLSLPrettyPrint.h" 19 #include "gl/GrGLSLPrettyPrint.h"
20 #include "gl/GrGLXferProcessor.h" 20 #include "gl/GrGLXferProcessor.h"
21 #include "glsl/GrGLSLCaps.h" 21 #include "glsl/GrGLSLCaps.h"
22 #include "glsl/GrGLSLProgramDataManager.h" 22 #include "glsl/GrGLSLProgramDataManager.h"
23 #include "glsl/GrGLSLTextureSampler.h"
23 24
24 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) 25 #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
25 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) 26 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
26 27
27 const int GrGLProgramBuilder::kVarsPerBlock = 8; 28 const int GrGLProgramBuilder::kVarsPerBlock = 8;
28 29
29 GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp u) { 30 GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp u) {
30 GrAutoLocaleSetter als("C"); 31 GrAutoLocaleSetter als("C");
31 32
32 // create a builder. This will be handed off to effects so they can use it to add 33 // create a builder. This will be handed off to effects so they can use it to add
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 273 }
273 274
274 void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp, 275 void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp,
275 int index, 276 int index,
276 const char* outColor, 277 const char* outColor,
277 const char* inColor) { 278 const char* inColor) {
278 GrGLInstalledFragProc* ifp = new GrGLInstalledFragProc; 279 GrGLInstalledFragProc* ifp = new GrGLInstalledFragProc;
279 280
280 ifp->fGLProc.reset(fp.createGLInstance()); 281 ifp->fGLProc.reset(fp.createGLInstance());
281 282
282 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); 283 SkSTArray<4, GrGLSLTextureSampler> samplers(fp.numTextures());
283 this->emitSamplers(fp, &samplers, ifp); 284 this->emitSamplers(fp, &samplers, ifp);
284 285
285 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords [index], samplers); 286 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords [index], samplers);
286 ifp->fGLProc->emitCode(args); 287 ifp->fGLProc->emitCode(args);
287 288
288 // We have to check that effects and the code they emit are consistent, ie i f an effect 289 // We have to check that effects and the code they emit are consistent, ie i f an effect
289 // asks for dst color, then the emit code needs to follow suit 290 // asks for dst color, then the emit code needs to follow suit
290 verify(fp); 291 verify(fp);
291 fFragmentProcessors->fProcs.push_back(ifp); 292 fFragmentProcessors->fProcs.push_back(ifp);
292 } 293 }
293 294
294 void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp, 295 void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp,
295 const char* outColor, 296 const char* outColor,
296 const char* outCoverage) { 297 const char* outCoverage) {
297 SkASSERT(!fGeometryProcessor); 298 SkASSERT(!fGeometryProcessor);
298 fGeometryProcessor = new GrGLInstalledGeoProc; 299 fGeometryProcessor = new GrGLInstalledGeoProc;
299 300
300 fGeometryProcessor->fGLProc.reset(gp.createGLInstance(*fGpu->glCaps().glslCa ps())); 301 fGeometryProcessor->fGLProc.reset(gp.createGLInstance(*fGpu->glCaps().glslCa ps()));
301 302
302 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(gp.numTextures()); 303 SkSTArray<4, GrGLSLTextureSampler> samplers(gp.numTextures());
303 this->emitSamplers(gp, &samplers, fGeometryProcessor); 304 this->emitSamplers(gp, &samplers, fGeometryProcessor);
304 305
305 GrGLGeometryProcessor::EmitArgs args(this, gp, outColor, outCoverage, sample rs, 306 GrGLGeometryProcessor::EmitArgs args(this, gp, outColor, outCoverage, sample rs,
306 fCoordTransforms, &fOutCoords); 307 fCoordTransforms, &fOutCoords);
307 fGeometryProcessor->fGLProc->emitCode(args); 308 fGeometryProcessor->fGLProc->emitCode(args);
308 309
309 // We have to check that effects and the code they emit are consistent, ie i f an effect 310 // We have to check that effects and the code they emit are consistent, ie i f an effect
310 // asks for dst color, then the emit code needs to follow suit 311 // asks for dst color, then the emit code needs to follow suit
311 verify(gp); 312 verify(gp);
312 } 313 }
(...skipping 15 matching lines...) Expand all
328 } 329 }
329 330
330 if (this->ctxInfo().caps()->glslCaps()->mustDeclareFragmentShaderOutput()) { 331 if (this->ctxInfo().caps()->glslCaps()->mustDeclareFragmentShaderOutput()) {
331 fFS.enableCustomOutput(); 332 fFS.enableCustomOutput();
332 } 333 }
333 334
334 SkString openBrace; 335 SkString openBrace;
335 openBrace.printf("{ // Xfer Processor: %s\n", xp.name()); 336 openBrace.printf("{ // Xfer Processor: %s\n", xp.name());
336 fFS.codeAppend(openBrace.c_str()); 337 fFS.codeAppend(openBrace.c_str());
337 338
338 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(xp.numTextures()); 339 SkSTArray<4, GrGLSLTextureSampler> samplers(xp.numTextures());
339 this->emitSamplers(xp, &samplers, fXferProcessor); 340 this->emitSamplers(xp, &samplers, fXferProcessor);
340 341
341 GrGLXferProcessor::EmitArgs args(this, xp, colorIn.c_str(), coverageIn.c_str (), 342 GrGLXferProcessor::EmitArgs args(this, xp, colorIn.c_str(), coverageIn.c_str (),
342 fFS.getPrimaryColorOutputName(), 343 fFS.getPrimaryColorOutputName(),
343 fFS.getSecondaryColorOutputName(), samplers ); 344 fFS.getSecondaryColorOutputName(), samplers );
344 fXferProcessor->fGLProc->emitCode(args); 345 fXferProcessor->fGLProc->emitCode(args);
345 346
346 // We have to check that effects and the code they emit are consistent, ie i f an effect 347 // We have to check that effects and the code they emit are consistent, ie i f an effect
347 // asks for dst color, then the emit code needs to follow suit 348 // asks for dst color, then the emit code needs to follow suit
348 verify(xp); 349 verify(xp);
349 fFS.codeAppend("}"); 350 fFS.codeAppend("}");
350 } 351 }
351 352
352 void GrGLProgramBuilder::verify(const GrPrimitiveProcessor& gp) { 353 void GrGLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
353 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); 354 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition());
354 } 355 }
355 356
356 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { 357 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) {
357 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); 358 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
358 } 359 }
359 360
360 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { 361 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) {
361 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); 362 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition());
362 } 363 }
363 364
364 template <class Proc> 365 template <class Proc>
365 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor, 366 void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor,
366 GrGLProcessor::TextureSamplerArray* outSam plers, 367 GrGLSLTextureSampler::TextureSamplerArray* outSamplers,
367 GrGLInstalledProc<Proc>* ip) { 368 GrGLInstalledProc<Proc>* ip) {
368 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();) 369 SkDEBUGCODE(ip->fSamplersIdx = fSamplerUniforms.count();)
369 int numTextures = processor.numTextures(); 370 int numTextures = processor.numTextures();
370 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur es); 371 UniformHandle* localSamplerUniforms = fSamplerUniforms.push_back_n(numTextur es);
371 SkString name; 372 SkString name;
372 for (int t = 0; t < numTextures; ++t) { 373 for (int t = 0; t < numTextures; ++t) {
373 name.printf("Sampler%d", t); 374 name.printf("Sampler%d", t);
374 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment _Visibility, 375 localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment _Visibility,
375 kSampler2D_GrSLType, kDefault _GrSLPrecision, 376 kSampler2D_GrSLType, kDefault _GrSLPrecision,
376 name.c_str()); 377 name.c_str());
377 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLProcessor::TextureSampler, 378 SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler,
378 (localSamplerUniforms[t], processor.textureAccess (t))); 379 (localSamplerUniforms[t], processor.textureAccess (t)));
379 } 380 }
380 } 381 }
381 382
382 GrGLProgram* GrGLProgramBuilder::finalize() { 383 GrGLProgram* GrGLProgramBuilder::finalize() {
383 // verify we can get a program id 384 // verify we can get a program id
384 GrGLuint programID; 385 GrGLuint programID;
385 GL_CALL_RET(programID, CreateProgram()); 386 GL_CALL_RET(programID, CreateProgram());
386 if (0 == programID) { 387 if (0 == programID) {
387 return nullptr; 388 return nullptr;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 519 }
519 520
520 //////////////////////////////////////////////////////////////////////////////// /////////////////// 521 //////////////////////////////////////////////////////////////////////////////// ///////////////////
521 522
522 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 523 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
523 int numProcs = fProcs.count(); 524 int numProcs = fProcs.count();
524 for (int i = 0; i < numProcs; ++i) { 525 for (int i = 0; i < numProcs; ++i) {
525 delete fProcs[i]; 526 delete fProcs[i];
526 } 527 }
527 } 528 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698