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

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

Issue 12547012: Make GrGLEffects use an interface to append their code. (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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const char* outputColor, 239 const char* outputColor,
240 const char* inputColor, 240 const char* inputColor,
241 const TextureSamplerArray& samplers) { 241 const TextureSamplerArray& samplers) {
242 const char* fgCoords; 242 const char* fgCoords;
243 const char* bgCoords; 243 const char* bgCoords;
244 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode( 244 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(
245 builder, key, vertexCoords, &fgCoords, NULL, "FG"); 245 builder, key, vertexCoords, &fgCoords, NULL, "FG");
246 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode( 246 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(
247 builder, key, vertexCoords, &bgCoords, NULL, "BG"); 247 builder, key, vertexCoords, &bgCoords, NULL, "BG");
248 248
249 SkString* code = &builder->fFSCode;
250 const char* bgColor = "bgColor"; 249 const char* bgColor = "bgColor";
251 const char* fgColor = "fgColor"; 250 const char* fgColor = "fgColor";
252 251
253 code->appendf("\t\tvec4 %s = ", fgColor); 252 builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor);
254 builder->appendTextureLookup(code, samplers[0], fgCoords, fgCoordsType); 253 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
255 code->append(";\n"); 254 samplers[0],
255 fgCoords,
256 fgCoordsType);
257 builder->fsCodeAppend(";\n");
256 258
257 code->appendf("\t\tvec4 %s = ", bgColor); 259 builder->fsCodeAppendf("\t\tvec4 %s = ", bgColor);
258 builder->appendTextureLookup(code, samplers[1], bgCoords, bgCoordsType); 260 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
259 code->append(";\n"); 261 samplers[1],
262 bgCoords,
263 bgCoordsType);
264 builder->fsCodeAppendf(";\n");
260 265
261 code->appendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor , bgColor, fgColor); 266 builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", ou tputColor, bgColor, fgColor);
262 switch (fMode) { 267 switch (fMode) {
263 case SkBlendImageFilter::kNormal_Mode: 268 case SkBlendImageFilter::kNormal_Mode:
264 code->appendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + %s.rgb;\n", outputCo lor, fgColor, bgColor, fgColor); 269 builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + %s.rgb;\n", outputColor, fgColor, bgColor, fgColor);
265 break; 270 break;
266 case SkBlendImageFilter::kMultiply_Mode: 271 case SkBlendImageFilter::kMultiply_Mode:
267 code->appendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rg b + %s.rgb * %s.rgb;\n", outputColor, fgColor, bgColor, bgColor, fgColor, fgColo r, bgColor); 272 builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + (1.0 - %s.a ) * %s.rgb + %s.rgb * %s.rgb;\n", outputColor, fgColor, bgColor, bgColor, fgColo r, fgColor, bgColor);
268 break; 273 break;
269 case SkBlendImageFilter::kScreen_Mode: 274 case SkBlendImageFilter::kScreen_Mode:
270 code->appendf("\t\t%s.rgb = %s.rgb + %s.rgb - %s.rgb * %s.rgb;\n", outpu tColor, bgColor, fgColor, fgColor, bgColor); 275 builder->fsCodeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb - %s.rgb * %s.rgb;\ n", outputColor, bgColor, fgColor, fgColor, bgColor);
271 break; 276 break;
272 case SkBlendImageFilter::kDarken_Mode: 277 case SkBlendImageFilter::kDarken_Mode:
273 code->appendf("\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, bgColor, fg Color, bgColor); 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);
274 break; 279 break;
275 case SkBlendImageFilter::kLighten_Mode: 280 case SkBlendImageFilter::kLighten_Mode:
276 code->appendf("\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, bgColor, fg Color, bgColor); 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);
277 break; 282 break;
278 } 283 }
279 } 284 }
280 285
281 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStag e& stage) { 286 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStag e& stage) {
282 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage); 287 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage);
283 GrTexture* fgTex = blend.texture(0); 288 GrTexture* fgTex = blend.texture(0);
284 GrTexture* bgTex = blend.texture(1); 289 GrTexture* bgTex = blend.texture(1);
285 fForegroundEffectMatrix.setData(uman, 290 fForegroundEffectMatrix.setData(uman,
286 GrEffect::MakeDivByTextureWHMatrix(fgTex), 291 GrEffect::MakeDivByTextureWHMatrix(fgTex),
(...skipping 18 matching lines...) Expand all
305 310
306 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex), 311 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex),
307 stage.getCoordChangeMatrix(), 312 stage.getCoordChangeMatrix(),
308 bgTex); 313 bgTex);
309 bgKey <<= GrGLEffectMatrix::kKeyBits; 314 bgKey <<= GrGLEffectMatrix::kKeyBits;
310 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits); 315 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits);
311 316
312 return modeKey | bgKey | fgKey; 317 return modeKey | bgKey | fgKey;
313 } 318 }
314 #endif 319 #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