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

Side by Side Diff: src/effects/SkBlendImageFilter.cpp

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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/effects/SkBicubicImageFilter.cpp ('k') | src/effects/SkColorMatrixFilter.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 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkBlendImageFilter.h" 8 #include "SkBlendImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 paint.setXfermodeMode(modeToXfermode(fMode)); 87 paint.setXfermodeMode(modeToXfermode(fMode));
88 canvas.drawBitmap(foreground, 0, 0, &paint); 88 canvas.drawBitmap(foreground, 0, 0, &paint);
89 return true; 89 return true;
90 } 90 }
91 91
92 /////////////////////////////////////////////////////////////////////////////// 92 ///////////////////////////////////////////////////////////////////////////////
93 93
94 #if SK_SUPPORT_GPU 94 #if SK_SUPPORT_GPU
95 class GrGLBlendEffect : public GrGLEffect { 95 class GrGLBlendEffect : public GrGLEffect {
96 public: 96 public:
97 GrGLBlendEffect(const GrBackendEffectFactory& factory, 97 GrGLBlendEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
98 const GrEffectRef& effect);
99 virtual ~GrGLBlendEffect(); 98 virtual ~GrGLBlendEffect();
100 99
101 virtual void emitCode(GrGLShaderBuilder*, 100 virtual void emitCode(GrGLShaderBuilder*,
102 const GrEffectStage&, 101 const GrDrawEffect&,
103 EffectKey, 102 EffectKey,
104 const char* vertexCoords,
105 const char* outputColor, 103 const char* outputColor,
106 const char* inputColor, 104 const char* inputColor,
107 const TextureSamplerArray&) SK_OVERRIDE; 105 const TextureSamplerArray&) SK_OVERRIDE;
108 106
109 static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&); 107 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
110 108
111 virtual void setData(const GrGLUniformManager&, const GrEffectStage&); 109 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
112 110
113 private: 111 private:
112 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
113
114 SkBlendImageFilter::Mode fMode; 114 SkBlendImageFilter::Mode fMode;
115 GrGLEffectMatrix fForegroundEffectMatrix; 115 GrGLEffectMatrix fForegroundEffectMatrix;
116 GrGLEffectMatrix fBackgroundEffectMatrix; 116 GrGLEffectMatrix fBackgroundEffectMatrix;
117 117
118 typedef GrGLEffect INHERITED; 118 typedef GrGLEffect INHERITED;
119 }; 119 };
120 120
121 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
122 122
123 class GrBlendEffect : public GrEffect { 123 class GrBlendEffect : public GrEffect {
124 public: 124 public:
125 static GrEffectRef* Create(SkBlendImageFilter::Mode mode, 125 static GrEffectRef* Create(SkBlendImageFilter::Mode mode,
126 GrTexture* foreground, 126 GrTexture* foreground,
127 GrTexture* background) { 127 GrTexture* background) {
128 AutoEffectUnref effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, back ground))); 128 AutoEffectUnref effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, back ground)));
129 return CreateEffectRef(effect); 129 return CreateEffectRef(effect);
130 } 130 }
131 131
132 virtual ~GrBlendEffect(); 132 virtual ~GrBlendEffect();
133 133
134 const GrBackendEffectFactory& getFactory() const; 134 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
135 SkBlendImageFilter::Mode mode() const { return fMode; } 135 SkBlendImageFilter::Mode mode() const { return fMode; }
136 136
137 typedef GrGLBlendEffect GLEffect; 137 typedef GrGLBlendEffect GLEffect;
138 static const char* Name() { return "Blend"; } 138 static const char* Name() { return "Blend"; }
139 139
140 void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; 140 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE;
141 141
142 private: 142 private:
143 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; 143 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
144 144
145 GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTextur e* background); 145 GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTextur e* background);
146 GrTextureAccess fForegroundAccess; 146 GrTextureAccess fForegroundAccess;
147 GrTextureAccess fBackgroundAccess; 147 GrTextureAccess fBackgroundAccess;
148 SkBlendImageFilter::Mode fMode; 148 SkBlendImageFilter::Mode fMode;
149 149
150 typedef GrEffect INHERITED; 150 typedef GrEffect INHERITED;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) { 217 GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) {
218 *validFlags = kA_ValidComponentFlag; 218 *validFlags = kA_ValidComponentFlag;
219 *color = GrColorPackRGBA(0, 0, 0, 0xff); 219 *color = GrColorPackRGBA(0, 0, 0, 0xff);
220 } else { 220 } else {
221 *validFlags = 0; 221 *validFlags = 0;
222 } 222 }
223 } 223 }
224 224
225 /////////////////////////////////////////////////////////////////////////////// 225 ///////////////////////////////////////////////////////////////////////////////
226 226
227 GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, const Gr EffectRef& effect) 227 GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory,
228 : INHERITED(factory), 228 const GrDrawEffect& drawEffect)
229 fMode(CastEffect<GrBlendEffect>(effect).mode()) { 229 : INHERITED(factory)
230 , fMode(drawEffect.castEffect<GrBlendEffect>().mode())
231 , fForegroundEffectMatrix(kCoordsType)
232 , fBackgroundEffectMatrix(kCoordsType) {
230 } 233 }
231 234
232 GrGLBlendEffect::~GrGLBlendEffect() { 235 GrGLBlendEffect::~GrGLBlendEffect() {
233 } 236 }
234 237
235 void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder, 238 void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
236 const GrEffectStage&, 239 const GrDrawEffect&,
237 EffectKey key, 240 EffectKey key,
238 const char* vertexCoords,
239 const char* outputColor, 241 const char* outputColor,
240 const char* inputColor, 242 const char* inputColor,
241 const TextureSamplerArray& samplers) { 243 const TextureSamplerArray& samplers) {
244 const GrGLShaderVar& localCoords = builder->localCoordsAttribute();
242 const char* fgCoords; 245 const char* fgCoords;
243 const char* bgCoords; 246 const char* bgCoords;
244 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode( 247 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(builder, key, &fgCo ords, NULL, "FG");
245 builder, key, vertexCoords, &fgCoords, NULL, "FG"); 248 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCo ords, NULL, "BG");
246 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(
247 builder, key, vertexCoords, &bgCoords, NULL, "BG");
248 249
249 const char* bgColor = "bgColor"; 250 const char* bgColor = "bgColor";
250 const char* fgColor = "fgColor"; 251 const char* fgColor = "fgColor";
251 252
252 builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor); 253 builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor);
253 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, 254 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
254 samplers[0], 255 samplers[0],
255 fgCoords, 256 fgCoords,
256 fgCoordsType); 257 fgCoordsType);
257 builder->fsCodeAppend(";\n"); 258 builder->fsCodeAppend(";\n");
(...skipping 18 matching lines...) Expand all
276 break; 277 break;
277 case SkBlendImageFilter::kDarken_Mode: 278 case SkBlendImageFilter::kDarken_Mode:
278 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); 279 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor);
279 break; 280 break;
280 case SkBlendImageFilter::kLighten_Mode: 281 case SkBlendImageFilter::kLighten_Mode:
281 builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); 282 builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor);
282 break; 283 break;
283 } 284 }
284 } 285 }
285 286
286 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStag e& stage) { 287 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect & drawEffect) {
287 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage); 288 const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
288 GrTexture* fgTex = blend.texture(0); 289 GrTexture* fgTex = blend.texture(0);
289 GrTexture* bgTex = blend.texture(1); 290 GrTexture* bgTex = blend.texture(1);
290 fForegroundEffectMatrix.setData(uman, 291 fForegroundEffectMatrix.setData(uman,
291 GrEffect::MakeDivByTextureWHMatrix(fgTex), 292 GrEffect::MakeDivByTextureWHMatrix(fgTex),
292 stage.getCoordChangeMatrix(), 293 drawEffect,
293 fgTex); 294 fgTex);
294 fBackgroundEffectMatrix.setData(uman, 295 fBackgroundEffectMatrix.setData(uman,
295 GrEffect::MakeDivByTextureWHMatrix(bgTex), 296 GrEffect::MakeDivByTextureWHMatrix(bgTex),
296 stage.getCoordChangeMatrix(), 297 drawEffect,
297 bgTex); 298 bgTex);
298 299
299 } 300 }
300 301
301 GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) { 302 GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrDrawEffect& drawEffect, co nst GrGLCaps&) {
302 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage); 303 const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
303 304
304 GrTexture* fgTex = blend.texture(0); 305 GrTexture* fgTex = blend.texture(0);
305 GrTexture* bgTex = blend.texture(1); 306 GrTexture* bgTex = blend.texture(1);
306 307
307 EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(fgTex), 308 EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(fgTex),
308 stage.getCoordChangeMatrix(), 309 drawEffect,
310 kCoordsType,
309 fgTex); 311 fgTex);
310 312
311 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex), 313 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex),
312 stage.getCoordChangeMatrix(), 314 drawEffect,
315 kCoordsType,
313 bgTex); 316 bgTex);
314 bgKey <<= GrGLEffectMatrix::kKeyBits; 317 bgKey <<= GrGLEffectMatrix::kKeyBits;
315 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits); 318 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits);
316 319
317 return modeKey | bgKey | fgKey; 320 return modeKey | bgKey | fgKey;
318 } 321 }
319 #endif 322 #endif
OLDNEW
« no previous file with comments | « src/effects/SkBicubicImageFilter.cpp ('k') | src/effects/SkColorMatrixFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698