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

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

Issue 1457543003: Add ShaderBuilders to EmitArgs and remove gettings from ProgBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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/SkColorCubeFilter.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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkColorMatrixFilter.h" 8 #include "SkColorMatrixFilter.h"
9 #include "SkColorMatrix.h" 9 #include "SkColorMatrix.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 kMat44f_GrSLType, kDefault_GrSLP recision, 412 kMat44f_GrSLType, kDefault_GrSLP recision,
413 "ColorMatrix"); 413 "ColorMatrix");
414 fVectorHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra gment_Visibility, 414 fVectorHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra gment_Visibility,
415 kVec4f_GrSLType, kDefault_GrSLPr ecision, 415 kVec4f_GrSLType, kDefault_GrSLPr ecision,
416 "ColorMatrixVector"); 416 "ColorMatrixVector");
417 417
418 if (nullptr == args.fInputColor) { 418 if (nullptr == args.fInputColor) {
419 // could optimize this case, but we aren't for now. 419 // could optimize this case, but we aren't for now.
420 args.fInputColor = "vec4(1)"; 420 args.fInputColor = "vec4(1)";
421 } 421 }
422 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB uilder(); 422 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
423 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is 423 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is
424 // transparent black. 424 // transparent black.
425 fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n ", 425 fragBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001); \n",
426 args.fInputColor); 426 args.fInputColor);
427 fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZ eroAlpha) + %s;\n", 427 fragBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, no nZeroAlpha) + %s;\n",
428 args.fOutputColor, 428 args.fOutputColor,
429 args.fBuilder->getUniformCStr(fMatrixHandle), 429 args.fBuilder->getUniformCStr(fMatrixHandle ),
430 args.fInputColor, 430 args.fInputColor,
431 args.fBuilder->getUniformCStr(fVectorHandle)) ; 431 args.fBuilder->getUniformCStr(fVectorHandle ));
432 fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", 432 fragBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n",
433 args.fOutputColor, args.fOutputColor); 433 args.fOutputColor, args.fOutputColor);
434 fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, arg s.fOutputColor); 434 fragBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, a rgs.fOutputColor);
435 } 435 }
436 436
437 protected: 437 protected:
438 virtual void onSetData(const GrGLSLProgramDataManager& uniManager, 438 virtual void onSetData(const GrGLSLProgramDataManager& uniManager,
439 const GrProcessor& proc) override { 439 const GrProcessor& proc) override {
440 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); 440 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>();
441 const float* m = cme.fMatrix.fMat; 441 const float* m = cme.fMatrix.fMat;
442 // The GL matrix is transposed from SkColorMatrix. 442 // The GL matrix is transposed from SkColorMatrix.
443 float mt[] = { 443 float mt[] = {
444 m[0], m[5], m[10], m[15], 444 m[0], m[5], m[10], m[15],
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 str->append("matrix: ("); 553 str->append("matrix: (");
554 for (int i = 0; i < 20; ++i) { 554 for (int i = 0; i < 20; ++i) {
555 str->appendScalar(fMatrix.fMat[i]); 555 str->appendScalar(fMatrix.fMat[i]);
556 if (i < 19) { 556 if (i < 19) {
557 str->append(", "); 557 str->append(", ");
558 } 558 }
559 } 559 }
560 str->append(")"); 560 str->append(")");
561 } 561 }
562 #endif 562 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorCubeFilter.cpp ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698