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

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

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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/effects/SkAlphaThresholdFilter.cpp ('k') | src/effects/SkBlurMaskFilter.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 2013 Google Inc. 2 * Copyright 2013 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 "SkArithmeticMode.h" 8 #include "SkArithmeticMode.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 #include "SkString.h" 12 #include "SkString.h"
13 #include "SkUnPreMultiply.h" 13 #include "SkUnPreMultiply.h"
14 #if SK_SUPPORT_GPU 14 #if SK_SUPPORT_GPU
15 #include "GrContext.h" 15 #include "GrContext.h"
16 #include "GrCoordTransform.h" 16 #include "GrCoordTransform.h"
17 #include "gl/GrGLEffect.h" 17 #include "gl/GrGLEffect.h"
18 #include "gl/GrGLShaderBuilder.h" 18 #include "gl/builders/GrGLProgramBuilder.h"
19 #include "GrTBackendEffectFactory.h" 19 #include "GrTBackendEffectFactory.h"
20 #endif 20 #endif
21 21
22 static const bool gUseUnpremul = false; 22 static const bool gUseUnpremul = false;
23 23
24 class SkArithmeticMode_scalar : public SkXfermode { 24 class SkArithmeticMode_scalar : public SkXfermode {
25 public: 25 public:
26 static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3 , SkScalar k4, 26 static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3 , SkScalar k4,
27 bool enforcePMColor) { 27 bool enforcePMColor) {
28 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4, enforcePMCol or)); 28 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4, enforcePMCol or));
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 ////////////////////////////////////////////////////////////////////////////// 246 //////////////////////////////////////////////////////////////////////////////
247 247
248 #if SK_SUPPORT_GPU 248 #if SK_SUPPORT_GPU
249 249
250 class GrGLArithmeticEffect : public GrGLEffect { 250 class GrGLArithmeticEffect : public GrGLEffect {
251 public: 251 public:
252 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrDrawEffect&); 252 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
253 virtual ~GrGLArithmeticEffect(); 253 virtual ~GrGLArithmeticEffect();
254 254
255 virtual void emitCode(GrGLShaderBuilder*, 255 virtual void emitCode(GrGLProgramBuilder*,
256 const GrDrawEffect&, 256 const GrDrawEffect&,
257 const GrEffectKey&, 257 const GrEffectKey&,
258 const char* outputColor, 258 const char* outputColor,
259 const char* inputColor, 259 const char* inputColor,
260 const TransformedCoordsArray&, 260 const TransformedCoordsArray&,
261 const TextureSamplerArray&) SK_OVERRIDE; 261 const TextureSamplerArray&) SK_OVERRIDE;
262 262
263 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE; 263 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE;
264 264
265 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b); 265 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui lder* b);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 352
353 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendEffectFactory& factory , 353 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendEffectFactory& factory ,
354 const GrDrawEffect& drawEffect) 354 const GrDrawEffect& drawEffect)
355 : INHERITED(factory), 355 : INHERITED(factory),
356 fEnforcePMColor(true) { 356 fEnforcePMColor(true) {
357 } 357 }
358 358
359 GrGLArithmeticEffect::~GrGLArithmeticEffect() { 359 GrGLArithmeticEffect::~GrGLArithmeticEffect() {
360 } 360 }
361 361
362 void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder, 362 void GrGLArithmeticEffect::emitCode(GrGLProgramBuilder* builder,
363 const GrDrawEffect& drawEffect, 363 const GrDrawEffect& drawEffect,
364 const GrEffectKey& key, 364 const GrEffectKey& key,
365 const char* outputColor, 365 const char* outputColor,
366 const char* inputColor, 366 const char* inputColor,
367 const TransformedCoordsArray& coords, 367 const TransformedCoordsArray& coords,
368 const TextureSamplerArray& samplers) { 368 const TextureSamplerArray& samplers) {
369 369
370 GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backg roundTexture(); 370 GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backg roundTexture();
371 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
371 const char* dstColor; 372 const char* dstColor;
372 if (backgroundTex) { 373 if (backgroundTex) {
373 builder->fsCodeAppend("\t\tvec4 bgColor = "); 374 fsBuilder->codeAppend("\t\tvec4 bgColor = ");
374 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0] .type()); 375 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0] .type());
375 builder->fsCodeAppendf(";\n"); 376 fsBuilder->codeAppendf(";\n");
376 dstColor = "bgColor"; 377 dstColor = "bgColor";
377 } else { 378 } else {
378 dstColor = builder->dstColor(); 379 dstColor = fsBuilder->dstColor();
379 } 380 }
380 381
381 SkASSERT(NULL != dstColor); 382 SkASSERT(NULL != dstColor);
382 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 383 fKUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
383 kVec4f_GrSLType, "k"); 384 kVec4f_GrSLType, "k");
384 const char* kUni = builder->getUniformCStr(fKUni); 385 const char* kUni = builder->getUniformCStr(fKUni);
385 386
386 // We don't try to optimize for this case at all 387 // We don't try to optimize for this case at all
387 if (NULL == inputColor) { 388 if (NULL == inputColor) {
388 builder->fsCodeAppendf("\t\tconst vec4 src = vec4(1);\n"); 389 fsBuilder->codeAppendf("\t\tconst vec4 src = vec4(1);\n");
389 } else { 390 } else {
390 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); 391 fsBuilder->codeAppendf("\t\tvec4 src = %s;\n", inputColor);
391 if (gUseUnpremul) { 392 if (gUseUnpremul) {
392 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1. 0);\n"); 393 fsBuilder->codeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1. 0);\n");
393 } 394 }
394 } 395 }
395 396
396 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); 397 fsBuilder->codeAppendf("\t\tvec4 dst = %s;\n", dstColor);
397 if (gUseUnpremul) { 398 if (gUseUnpremul) {
398 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\ n"); 399 fsBuilder->codeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\ n");
399 } 400 }
400 401
401 builder->fsCodeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst + %s.w;\n", outputColor, kUni, kUni, kUni, kUni); 402 fsBuilder->codeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst + %s.w;\n", outputColor, kUni, kUni, kUni, kUni);
402 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu tColor); 403 fsBuilder->codeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu tColor);
403 if (gUseUnpremul) { 404 if (gUseUnpremul) {
404 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor ); 405 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor );
405 } else if (fEnforcePMColor) { 406 } else if (fEnforcePMColor) {
406 builder->fsCodeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor, outputColor, outputColor); 407 fsBuilder->codeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor, outputColor, outputColor);
407 } 408 }
408 } 409 }
409 410
410 void GrGLArithmeticEffect::setData(const GrGLProgramDataManager& pdman, const Gr DrawEffect& drawEffect) { 411 void GrGLArithmeticEffect::setData(const GrGLProgramDataManager& pdman, const Gr DrawEffect& drawEffect) {
411 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>( ); 412 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>( );
412 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); 413 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4());
413 fEnforcePMColor = arith.enforcePMColor(); 414 fEnforcePMColor = arith.enforcePMColor();
414 } 415 }
415 416
416 void GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffect, 417 void GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffect,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 background); 449 background);
449 } 450 }
450 return true; 451 return true;
451 } 452 }
452 453
453 #endif 454 #endif
454 455
455 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) 456 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode)
456 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) 457 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar)
457 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 458 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkAlphaThresholdFilter.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698