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

Side by Side Diff: src/gpu/effects/GrConfigConversionEffect.cpp

Issue 1251173002: Added GrGLFragmentProcessor::EmitArgs struct for use with emitCode() (Closed) Base URL: https://skia.googlesource.com/skia@composeshader_gpu
Patch Set: Created 5 years, 5 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/effects/GrBicubicEffect.cpp ('k') | src/gpu/effects/GrConstColorProcessor.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 2012 Google Inc. 2 * Copyright 2012 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 "GrConfigConversionEffect.h" 8 #include "GrConfigConversionEffect.h"
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
11 #include "GrInvariantOutput.h" 11 #include "GrInvariantOutput.h"
12 #include "GrSimpleTextureEffect.h" 12 #include "GrSimpleTextureEffect.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 #include "gl/GrGLFragmentProcessor.h" 14 #include "gl/GrGLFragmentProcessor.h"
15 #include "gl/builders/GrGLProgramBuilder.h" 15 #include "gl/builders/GrGLProgramBuilder.h"
16 16
17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { 17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor {
18 public: 18 public:
19 GrGLConfigConversionEffect(const GrProcessor& processor) { 19 GrGLConfigConversionEffect(const GrProcessor& processor) {
20 const GrConfigConversionEffect& configConversionEffect = 20 const GrConfigConversionEffect& configConversionEffect =
21 processor.cast<GrConfigConversionEffect>(); 21 processor.cast<GrConfigConversionEffect>();
22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); 22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue();
23 fPMConversion = configConversionEffect.pmConversion(); 23 fPMConversion = configConversionEffect.pmConversion();
24 } 24 }
25 25
26 virtual void emitCode(GrGLFPBuilder* builder, 26 virtual void emitCode(EmitArgs& args) override {
27 const GrFragmentProcessor&,
28 const char* outputColor,
29 const char* inputColor,
30 const TransformedCoordsArray& coords,
31 const TextureSamplerArray& samplers) override {
32 // Using highp for GLES here in order to avoid some precision issues on specific GPUs. 27 // Using highp for GLES here in order to avoid some precision issues on specific GPUs.
33 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision ); 28 GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecision );
34 SkString tmpDecl; 29 SkString tmpDecl;
35 tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl); 30 tmpVar.appendDecl(args.fBuilder->ctxInfo(), &tmpDecl);
36 31
37 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 32 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder ();
38 33
39 fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); 34 fsBuilder->codeAppendf("%s;", tmpDecl.c_str());
40 35
41 fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); 36 fsBuilder->codeAppendf("%s = ", tmpVar.c_str());
42 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0] .getType()); 37 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str( ),
38 args.fCoords[0].getType());
43 fsBuilder->codeAppend(";"); 39 fsBuilder->codeAppend(";");
44 40
45 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { 41 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
46 SkASSERT(fSwapRedAndBlue); 42 SkASSERT(fSwapRedAndBlue);
47 fsBuilder->codeAppendf("%s = %s.bgra;", outputColor, tmpVar.c_str()) ; 43 fsBuilder->codeAppendf("%s = %s.bgra;", args.fOutputColor, tmpVar.c_ str());
48 } else { 44 } else {
49 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; 45 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb";
50 switch (fPMConversion) { 46 switch (fPMConversion) {
51 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: 47 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
52 fsBuilder->codeAppendf( 48 fsBuilder->codeAppendf(
53 "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);", 49 "%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);",
54 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm pVar.c_str()); 50 tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tm pVar.c_str());
55 break; 51 break;
56 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio n: 52 case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversio n:
57 // Add a compensation(0.001) here to avoid the side effect o f the floor operation. 53 // Add a compensation(0.001) here to avoid the side effect o f the floor operation.
(...skipping 11 matching lines...) Expand all
69 break; 65 break;
70 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio n: 66 case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversio n:
71 fsBuilder->codeAppendf( 67 fsBuilder->codeAppendf(
72 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / % s.a * 255.0) / 255.0, %s.a);", 68 "%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / % s.a * 255.0) / 255.0, %s.a);",
73 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm pVar.c_str(), tmpVar.c_str()); 69 tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tm pVar.c_str(), tmpVar.c_str());
74 break; 70 break;
75 default: 71 default:
76 SkFAIL("Unknown conversion op."); 72 SkFAIL("Unknown conversion op.");
77 break; 73 break;
78 } 74 }
79 fsBuilder->codeAppendf("%s = %s;", outputColor, tmpVar.c_str()); 75 fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, tmpVar.c_str() );
80 } 76 }
81 SkString modulate; 77 SkString modulate;
82 GrGLSLMulVarBy4f(&modulate, outputColor, inputColor); 78 GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
83 fsBuilder->codeAppend(modulate.c_str()); 79 fsBuilder->codeAppend(modulate.c_str());
84 } 80 }
85 81
86 static inline void GenKey(const GrProcessor& processor, const GrGLSLCaps&, 82 static inline void GenKey(const GrProcessor& processor, const GrGLSLCaps&,
87 GrProcessorKeyBuilder* b) { 83 GrProcessorKeyBuilder* b) {
88 const GrConfigConversionEffect& conv = processor.cast<GrConfigConversion Effect>(); 84 const GrConfigConversionEffect& conv = processor.cast<GrConfigConversion Effect>();
89 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() < < 1); 85 uint32_t key = (conv.swapsRedAndBlue() ? 0 : 1) | (conv.pmConversion() < < 1);
90 b->add32(key); 86 b->add32(key);
91 } 87 }
92 88
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // The PM conversions assume colors are 0..255 311 // The PM conversions assume colors are 0..255
316 return NULL; 312 return NULL;
317 } 313 }
318 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager, 314 return SkNEW_ARGS(GrConfigConversionEffect, (procDataManager,
319 texture, 315 texture,
320 swapRedAndBlue, 316 swapRedAndBlue,
321 pmConversion, 317 pmConversion,
322 matrix)); 318 matrix));
323 } 319 }
324 } 320 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.cpp ('k') | src/gpu/effects/GrConstColorProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698