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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 return SkColorMatrixFilter::Create(concat); 380 return SkColorMatrixFilter::Create(concat);
381 } 381 }
382 return nullptr; 382 return nullptr;
383 } 383 }
384 384
385 #if SK_SUPPORT_GPU 385 #if SK_SUPPORT_GPU
386 #include "GrFragmentProcessor.h" 386 #include "GrFragmentProcessor.h"
387 #include "GrInvariantOutput.h" 387 #include "GrInvariantOutput.h"
388 #include "glsl/GrGLSLFragmentProcessor.h" 388 #include "glsl/GrGLSLFragmentProcessor.h"
389 #include "glsl/GrGLSLFragmentShaderBuilder.h" 389 #include "glsl/GrGLSLFragmentShaderBuilder.h"
390 #include "glsl/GrGLSLProgramBuilder.h"
391 #include "glsl/GrGLSLProgramDataManager.h" 390 #include "glsl/GrGLSLProgramDataManager.h"
391 #include "glsl/GrGLSLUniformHandler.h"
392 392
393 class ColorMatrixEffect : public GrFragmentProcessor { 393 class ColorMatrixEffect : public GrFragmentProcessor {
394 public: 394 public:
395 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) { 395 static const GrFragmentProcessor* Create(const SkColorMatrix& matrix) {
396 return new ColorMatrixEffect(matrix); 396 return new ColorMatrixEffect(matrix);
397 } 397 }
398 398
399 const char* name() const override { return "Color Matrix"; } 399 const char* name() const override { return "Color Matrix"; }
400 400
401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
402 402
403 class GLSLProcessor : public GrGLSLFragmentProcessor { 403 class GLSLProcessor : public GrGLSLFragmentProcessor {
404 public: 404 public:
405 // this class always generates the same code. 405 // this class always generates the same code.
406 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder* b) {} 406 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder* b) {}
407 407
408 GLSLProcessor(const GrProcessor&) {} 408 GLSLProcessor(const GrProcessor&) {}
409 409
410 virtual void emitCode(EmitArgs& args) override { 410 virtual void emitCode(EmitArgs& args) override {
411 fMatrixHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra gment_Visibility, 411 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
412 kMat44f_GrSLType, kDefault_GrSLP recision, 412 fMatrixHandle = uniformHandler->addUniform(GrGLSLUniformHandler::kFr agment_Visibility,
413 "ColorMatrix"); 413 kMat44f_GrSLType, kDefaul t_GrSLPrecision,
414 fVectorHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFra gment_Visibility, 414 "ColorMatrix");
415 kVec4f_GrSLType, kDefault_GrSLPr ecision, 415 fVectorHandle = uniformHandler->addUniform(GrGLSLUniformHandler::kFr agment_Visibility,
416 "ColorMatrixVector"); 416 kVec4f_GrSLType, kDefault _GrSLPrecision,
417 "ColorMatrixVector");
417 418
418 if (nullptr == args.fInputColor) { 419 if (nullptr == args.fInputColor) {
419 // could optimize this case, but we aren't for now. 420 // could optimize this case, but we aren't for now.
420 args.fInputColor = "vec4(1)"; 421 args.fInputColor = "vec4(1)";
421 } 422 }
422 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 423 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
423 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is 424 // The max() is to guard against 0 / 0 during unpremul when the inco ming color is
424 // transparent black. 425 // transparent black.
425 fragBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001); \n", 426 fragBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001); \n",
426 args.fInputColor); 427 args.fInputColor);
427 fragBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, no nZeroAlpha) + %s;\n", 428 fragBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, no nZeroAlpha) + %s;\n",
428 args.fOutputColor, 429 args.fOutputColor,
429 args.fBuilder->getUniformCStr(fMatrixHandle ), 430 uniformHandler->getUniformCStr(fMatrixHandl e),
430 args.fInputColor, 431 args.fInputColor,
431 args.fBuilder->getUniformCStr(fVectorHandle )); 432 uniformHandler->getUniformCStr(fVectorHandl e));
432 fragBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n", 433 fragBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n",
433 args.fOutputColor, args.fOutputColor); 434 args.fOutputColor, args.fOutputColor);
434 fragBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, a rgs.fOutputColor); 435 fragBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, a rgs.fOutputColor);
435 } 436 }
436 437
437 protected: 438 protected:
438 virtual void onSetData(const GrGLSLProgramDataManager& uniManager, 439 virtual void onSetData(const GrGLSLProgramDataManager& uniManager,
439 const GrProcessor& proc) override { 440 const GrProcessor& proc) override {
440 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>(); 441 const ColorMatrixEffect& cme = proc.cast<ColorMatrixEffect>();
441 const float* m = cme.fMatrix.fMat; 442 const float* m = cme.fMatrix.fMat;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 str->append("matrix: ("); 554 str->append("matrix: (");
554 for (int i = 0; i < 20; ++i) { 555 for (int i = 0; i < 20; ++i) {
555 str->appendScalar(fMatrix.fMat[i]); 556 str->appendScalar(fMatrix.fMat[i]);
556 if (i < 19) { 557 if (i < 19) {
557 str->append(", "); 558 str->append(", ");
558 } 559 }
559 } 560 }
560 str->append(")"); 561 str->append(")");
561 } 562 }
562 #endif 563 #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