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

Side by Side Diff: src/effects/SkColorMatrixFilter.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/SkColorFilters.cpp ('k') | src/effects/SkDisplacementMapEffect.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkColorMatrixFilter.h" 8 #include "SkColorMatrixFilter.h"
9 #include "SkColorMatrix.h" 9 #include "SkColorMatrix.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (matrix) { 328 if (matrix) {
329 memcpy(matrix, fMatrix.fMat, 20 * sizeof(SkScalar)); 329 memcpy(matrix, fMatrix.fMat, 20 * sizeof(SkScalar));
330 } 330 }
331 return true; 331 return true;
332 } 332 }
333 333
334 #if SK_SUPPORT_GPU 334 #if SK_SUPPORT_GPU
335 #include "GrEffect.h" 335 #include "GrEffect.h"
336 #include "GrTBackendEffectFactory.h" 336 #include "GrTBackendEffectFactory.h"
337 #include "gl/GrGLEffect.h" 337 #include "gl/GrGLEffect.h"
338 #include "gl/GrGLShaderBuilder.h" 338 #include "gl/builders/GrGLProgramBuilder.h"
339 339
340 class ColorMatrixEffect : public GrEffect { 340 class ColorMatrixEffect : public GrEffect {
341 public: 341 public:
342 static GrEffect* Create(const SkColorMatrix& matrix) { 342 static GrEffect* Create(const SkColorMatrix& matrix) {
343 return SkNEW_ARGS(ColorMatrixEffect, (matrix)); 343 return SkNEW_ARGS(ColorMatrixEffect, (matrix));
344 } 344 }
345 345
346 static const char* Name() { return "Color Matrix"; } 346 static const char* Name() { return "Color Matrix"; }
347 347
348 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 348 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 class GLEffect : public GrGLEffect { 399 class GLEffect : public GrGLEffect {
400 public: 400 public:
401 // this class always generates the same code. 401 // this class always generates the same code.
402 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil der* b) {} 402 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil der* b) {}
403 403
404 GLEffect(const GrBackendEffectFactory& factory, 404 GLEffect(const GrBackendEffectFactory& factory,
405 const GrDrawEffect&) 405 const GrDrawEffect&)
406 : INHERITED(factory) { 406 : INHERITED(factory) {
407 } 407 }
408 408
409 virtual void emitCode(GrGLShaderBuilder* builder, 409 virtual void emitCode(GrGLProgramBuilder* builder,
410 const GrDrawEffect&, 410 const GrDrawEffect&,
411 const GrEffectKey&, 411 const GrEffectKey&,
412 const char* outputColor, 412 const char* outputColor,
413 const char* inputColor, 413 const char* inputColor,
414 const TransformedCoordsArray&, 414 const TransformedCoordsArray&,
415 const TextureSamplerArray&) SK_OVERRIDE { 415 const TextureSamplerArray&) SK_OVERRIDE {
416 fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis ibility, 416 fMatrixHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi sibility,
417 kMat44f_GrSLType, 417 kMat44f_GrSLType,
418 "ColorMatrix"); 418 "ColorMatrix");
419 fVectorHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Vis ibility, 419 fVectorHandle = builder->addUniform(GrGLProgramBuilder::kFragment_Vi sibility,
420 kVec4f_GrSLType, 420 kVec4f_GrSLType,
421 "ColorMatrixVector"); 421 "ColorMatrixVector");
422 422
423 if (NULL == inputColor) { 423 if (NULL == inputColor) {
424 // could optimize this case, but we aren't for now. 424 // could optimize this case, but we aren't for now.
425 inputColor = "vec4(1)"; 425 inputColor = "vec4(1)";
426 } 426 }
427 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui lder();
427 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is 428 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is
428 // transparent black. 429 // transparent black.
429 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n ", inputColor); 430 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n ", inputColor);
430 builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ eroAlpha) + %s;\n", 431 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ eroAlpha) + %s;\n",
431 outputColor, 432 outputColor,
432 builder->getUniformCStr(fMatrixHandle), 433 builder->getUniformCStr(fMatrixHandle),
433 inputColor, 434 inputColor,
434 builder->getUniformCStr(fVectorHandle)); 435 builder->getUniformCStr(fVectorHandle));
435 builder->fsCodeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputColor); 436 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputColor);
436 builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol or); 437 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputCol or);
437 } 438 }
438 439
439 virtual void setData(const GrGLProgramDataManager& uniManager, 440 virtual void setData(const GrGLProgramDataManager& uniManager,
440 const GrDrawEffect& drawEffect) SK_OVERRIDE { 441 const GrDrawEffect& drawEffect) SK_OVERRIDE {
441 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe ct>(); 442 const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffe ct>();
442 const float* m = cme.fMatrix.fMat; 443 const float* m = cme.fMatrix.fMat;
443 // The GL matrix is transposed from SkColorMatrix. 444 // The GL matrix is transposed from SkColorMatrix.
444 GrGLfloat mt[] = { 445 GrGLfloat mt[] = {
445 m[0], m[5], m[10], m[15], 446 m[0], m[5], m[10], m[15],
446 m[1], m[6], m[11], m[16], 447 m[1], m[6], m[11], m[16],
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 str->append("matrix: ("); 502 str->append("matrix: (");
502 for (int i = 0; i < 20; ++i) { 503 for (int i = 0; i < 20; ++i) {
503 str->appendScalar(fMatrix.fMat[i]); 504 str->appendScalar(fMatrix.fMat[i]);
504 if (i < 19) { 505 if (i < 19) {
505 str->append(", "); 506 str->append(", ");
506 } 507 }
507 } 508 }
508 str->append(")"); 509 str->append(")");
509 } 510 }
510 #endif 511 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorFilters.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698