diff options
author | brianosman <brianosman@google.com> | 2016-09-07 08:09:10 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-07 08:09:10 -0700 |
commit | 77320dbabcddf05c0a1489eaf1f496729dc8de0e (patch) | |
tree | 6dce3ee85d2206685279217db47e66dd47839e43 /src/gpu/effects/GrSimpleTextureEffect.cpp | |
parent | d2e39dbc6a68a6cc2a480d0c8082eb204f6b6e77 (diff) |
Add color gamut xform helpers to GrGLSLShaderBuilder
New helper functions inject the necessary shader
function. Texture lookup functions can now insert
the gamut xform at the appropriate place, too.
As written, could be used to transform non-texture
colors (e.g. vertex colors) as well.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2180803005
Review-Url: https://codereview.chromium.org/2180803005
Diffstat (limited to 'src/gpu/effects/GrSimpleTextureEffect.cpp')
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index a452d3e6fd..8e452814b9 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -8,23 +8,46 @@ #include "GrSimpleTextureEffect.h" #include "GrInvariantOutput.h" #include "GrTexture.h" +#include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor { public: void emitCode(EmitArgs& args) override { + const GrSimpleTextureEffect& textureEffect = args.fFp.cast<GrSimpleTextureEffect>(); + GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler, + textureEffect.colorSpaceXform(), + &fColorSpaceXformUni); + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; fragBuilder->codeAppendf("%s = ", args.fOutputColor); fragBuilder->appendTextureLookupAndModulate(args.fInputColor, - args.fTexSamplers[0], - args.fCoords[0].c_str(), - args.fCoords[0].getType()); + args.fTexSamplers[0], + args.fCoords[0].c_str(), + args.fCoords[0].getType(), + &colorSpaceHelper); fragBuilder->codeAppend(";"); } + static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, + GrProcessorKeyBuilder* b) { + const GrSimpleTextureEffect& textureEffect = effect.cast<GrSimpleTextureEffect>(); + b->add32(GrColorSpaceXform::XformKey(textureEffect.colorSpaceXform())); + } + +protected: + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& processor) override { + const GrSimpleTextureEffect& textureEffect = processor.cast<GrSimpleTextureEffect>(); + if (SkToBool(textureEffect.colorSpaceXform())) { + pdman.setMatrix4f(fColorSpaceXformUni, textureEffect.colorSpaceXform()->srcToDst()); + } + } + private: typedef GrGLSLFragmentProcessor INHERITED; + + UniformHandle fColorSpaceXformUni; }; /////////////////////////////////////////////////////////////////////////////// |