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

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

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.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 "GrTBackendEffectFactory.h" 10 #include "GrTBackendEffectFactory.h"
11 #include "GrSimpleTextureEffect.h" 11 #include "GrSimpleTextureEffect.h"
12 #include "gl/GrGLEffect.h" 12 #include "gl/GrGLEffect.h"
13 #include "gl/GrGLEffectMatrix.h"
14 #include "SkMatrix.h" 13 #include "SkMatrix.h"
15 14
16 class GrGLConfigConversionEffect : public GrGLEffect { 15 class GrGLConfigConversionEffect : public GrGLEffect {
17 public: 16 public:
18 GrGLConfigConversionEffect(const GrBackendEffectFactory& factory, 17 GrGLConfigConversionEffect(const GrBackendEffectFactory& factory,
19 const GrDrawEffect& drawEffect) 18 const GrDrawEffect& drawEffect)
20 : INHERITED (factory) 19 : INHERITED (factory) {
21 , fEffectMatrix(drawEffect.castEffect<GrConfigConversionEffect>().coordsType ()) {
22 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC onversionEffect>(); 20 const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigC onversionEffect>();
23 fSwapRedAndBlue = effect.swapsRedAndBlue(); 21 fSwapRedAndBlue = effect.swapsRedAndBlue();
24 fPMConversion = effect.pmConversion(); 22 fPMConversion = effect.pmConversion();
25 } 23 }
26 24
27 virtual void emitCode(GrGLShaderBuilder* builder, 25 virtual void emitCode(GrGLShaderBuilder* builder,
28 const GrDrawEffect&, 26 const GrDrawEffect&,
29 EffectKey key, 27 EffectKey key,
30 const char* outputColor, 28 const char* outputColor,
31 const char* inputColor, 29 const char* inputColor,
30 const TransformedCoordsArray& coords,
32 const TextureSamplerArray& samplers) SK_OVERRIDE { 31 const TextureSamplerArray& samplers) SK_OVERRIDE {
33 SkString coords;
34 GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
35 builder->fsCodeAppendf("\t\t%s = ", outputColor); 32 builder->fsCodeAppendf("\t\t%s = ", outputColor);
36 builder->fsAppendTextureLookup(samplers[0], coords.c_str(), coordsType); 33 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0] .type());
37 builder->fsCodeAppend(";\n"); 34 builder->fsCodeAppend(";\n");
38 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { 35 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
39 SkASSERT(fSwapRedAndBlue); 36 SkASSERT(fSwapRedAndBlue);
40 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor ); 37 builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor );
41 } else { 38 } else {
42 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb"; 39 const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb";
43 switch (fPMConversion) { 40 switch (fPMConversion) {
44 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion: 41 case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
45 builder->fsCodeAppendf( 42 builder->fsCodeAppendf(
46 "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a) ;\n", 43 "\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a) ;\n",
(...skipping 19 matching lines...) Expand all
66 default: 63 default:
67 GrCrash("Unknown conversion op."); 64 GrCrash("Unknown conversion op.");
68 break; 65 break;
69 } 66 }
70 } 67 }
71 SkString modulate; 68 SkString modulate;
72 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); 69 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
73 builder->fsCodeAppend(modulate.c_str()); 70 builder->fsCodeAppend(modulate.c_str());
74 } 71 }
75 72
76 void setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
77 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon versionEffect>();
78 fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0 ));
79 }
80
81 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) { 73 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
82 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon versionEffect>(); 74 const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigCon versionEffect>();
83 EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.p mConversion() << 1); 75 return static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.pmConversi on() << 1);
84 key <<= GrGLEffectMatrix::kKeyBits;
85 EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
86 drawEffect,
87 conv.coordsType(),
88 conv.texture(0));
89 SkASSERT(!(matrixKey & key));
90 return matrixKey | key;
91 } 76 }
92 77
93 private: 78 private:
94 bool fSwapRedAndBlue; 79 bool fSwapRedAndBlue;
95 GrConfigConversionEffect::PMConversion fPMConversion; 80 GrConfigConversionEffect::PMConversion fPMConversion;
96 GrGLEffectMatrix fEffectMatrix;
97 81
98 typedef GrGLEffect INHERITED; 82 typedef GrGLEffect INHERITED;
99 83
100 }; 84 };
101 85
102 /////////////////////////////////////////////////////////////////////////////// 86 ///////////////////////////////////////////////////////////////////////////////
103 87
104 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture, 88 GrConfigConversionEffect::GrConfigConversionEffect(GrTexture* texture,
105 bool swapRedAndBlue, 89 bool swapRedAndBlue,
106 PMConversion pmConversion, 90 PMConversion pmConversion,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // The PM conversions assume colors are 0..255 268 // The PM conversions assume colors are 0..255
285 return NULL; 269 return NULL;
286 } 270 }
287 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture, 271 AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture,
288 swapRedAndB lue, 272 swapRedAndB lue,
289 pmConversio n, 273 pmConversio n,
290 matrix))); 274 matrix)));
291 return CreateEffectRef(effect); 275 return CreateEffectRef(effect);
292 } 276 }
293 } 277 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.cpp ('k') | src/gpu/effects/GrConvolutionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698