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

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

Issue 1584473002: Swizzle shader output and blend when using GL_RED to implement kAlpha_8_GrPixelConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@hideformats
Patch Set: Address comments Created 4 years, 11 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/glsl/GrGLSLCaps.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 "GrSwizzle.h"
13 #include "GrTexture.h" 14 #include "GrTexture.h"
14 #include "SkRTConf.h" 15 #include "SkRTConf.h"
15 #include "SkTraceEvent.h" 16 #include "SkTraceEvent.h"
16 #include "gl/GrGLGpu.h" 17 #include "gl/GrGLGpu.h"
17 #include "gl/GrGLProgram.h" 18 #include "gl/GrGLProgram.h"
18 #include "gl/GrGLSLPrettyPrint.h" 19 #include "gl/GrGLSLPrettyPrint.h"
19 #include "gl/builders/GrGLShaderStringBuilder.h" 20 #include "gl/builders/GrGLShaderStringBuilder.h"
20 #include "glsl/GrGLSLCaps.h" 21 #include "glsl/GrGLSLCaps.h"
21 #include "glsl/GrGLSLFragmentProcessor.h" 22 #include "glsl/GrGLSLFragmentProcessor.h"
22 #include "glsl/GrGLSLGeometryProcessor.h" 23 #include "glsl/GrGLSLGeometryProcessor.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 this->emitAndInstallProc(primProc, inputColor, inputCoverage); 90 this->emitAndInstallProc(primProc, inputColor, inputCoverage);
90 91
91 fFragmentProcessors.reset(new GrGLInstalledFragProcs); 92 fFragmentProcessors.reset(new GrGLInstalledFragProcs);
92 int numProcs = this->pipeline().numFragmentProcessors(); 93 int numProcs = this->pipeline().numFragmentProcessors();
93 this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentProcessors (), inputColor); 94 this->emitAndInstallFragProcs(0, this->pipeline().numColorFragmentProcessors (), inputColor);
94 this->emitAndInstallFragProcs(this->pipeline().numColorFragmentProcessors(), numProcs, 95 this->emitAndInstallFragProcs(this->pipeline().numColorFragmentProcessors(), numProcs,
95 inputCoverage); 96 inputCoverage);
96 this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *inputColo r, *inputCoverage, 97 this->emitAndInstallXferProc(this->pipeline().getXferProcessor(), *inputColo r, *inputCoverage,
97 this->pipeline().ignoresCoverage()); 98 this->pipeline().ignoresCoverage());
99 this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOu tput());
98 return true; 100 return true;
99 } 101 }
100 102
101 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset, 103 void GrGLProgramBuilder::emitAndInstallFragProcs(int procOffset,
102 int numProcs, 104 int numProcs,
103 GrGLSLExpr4* inOut) { 105 GrGLSLExpr4* inOut) {
104 for (int i = procOffset; i < numProcs; ++i) { 106 for (int i = procOffset; i < numProcs; ++i) {
105 GrGLSLExpr4 output; 107 GrGLSLExpr4 output;
106 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i) ; 108 const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i) ;
107 this->emitAndInstallProc(fp, i, *inOut, &output); 109 this->emitAndInstallProc(fp, i, *inOut, &output);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 fFS.getSecondaryColorOutputName(), 257 fFS.getSecondaryColorOutputName(),
256 samplers); 258 samplers);
257 fXferProcessor->fGLProc->emitCode(args); 259 fXferProcessor->fGLProc->emitCode(args);
258 260
259 // We have to check that effects and the code they emit are consistent, ie i f an effect 261 // We have to check that effects and the code they emit are consistent, ie i f an effect
260 // asks for dst color, then the emit code needs to follow suit 262 // asks for dst color, then the emit code needs to follow suit
261 verify(xp); 263 verify(xp);
262 fFS.codeAppend("}"); 264 fFS.codeAppend("}");
263 } 265 }
264 266
267 void GrGLProgramBuilder::emitFSOutputSwizzle(bool hasSecondaryOutput) {
268 // Swizzle the fragment shader outputs if necessary.
269 GrSwizzle swizzle;
270 swizzle.setFromKey(this->desc().header().fOutputSwizzle);
271 if (swizzle != GrSwizzle::RGBA()) {
272 fFS.codeAppendf("%s = %s.%s;", fFS.getPrimaryColorOutputName(),
273 fFS.getPrimaryColorOutputName(),
274 swizzle.c_str());
275 if (hasSecondaryOutput) {
276 fFS.codeAppendf("%s = %s.%s;", fFS.getSecondaryColorOutputName(),
277 fFS.getSecondaryColorOutputName(),
278 swizzle.c_str());
279 }
280 }
281 }
282
265 void GrGLProgramBuilder::verify(const GrPrimitiveProcessor& gp) { 283 void GrGLProgramBuilder::verify(const GrPrimitiveProcessor& gp) {
266 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition()); 284 SkASSERT(fFS.hasReadFragmentPosition() == gp.willReadFragmentPosition());
267 } 285 }
268 286
269 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) { 287 void GrGLProgramBuilder::verify(const GrXferProcessor& xp) {
270 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor()); 288 SkASSERT(fFS.hasReadDstColor() == xp.willReadDstColor());
271 } 289 }
272 290
273 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { 291 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) {
274 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); 292 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 496 }
479 497
480 //////////////////////////////////////////////////////////////////////////////// /////////////////// 498 //////////////////////////////////////////////////////////////////////////////// ///////////////////
481 499
482 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { 500 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() {
483 int numProcs = fProcs.count(); 501 int numProcs = fProcs.count();
484 for (int i = 0; i < numProcs; ++i) { 502 for (int i = 0; i < numProcs; ++i) {
485 delete fProcs[i]; 503 delete fProcs[i];
486 } 504 }
487 } 505 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/glsl/GrGLSLCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698