diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-07-11 14:35:28 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-12 13:28:25 +0000 |
commit | 46b654df9e70bbfacf6dc45d3a2a7ceb13a61edb (patch) | |
tree | 1df670da50b5c02defe6507cb87f2a213a801750 /src/gpu/effects/GrSimpleTextureEffect.cpp | |
parent | 6ee29658202a0bd8394df5daed8db30321c01cc9 (diff) |
converted GrSimpleTextureEffect to sksl
Bug: skia:
Change-Id: If556c6baad75f22135f429759feabaaec095b900
Reviewed-on: https://skia-review.googlesource.com/21720
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/effects/GrSimpleTextureEffect.cpp')
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.cpp | 130 |
1 files changed, 50 insertions, 80 deletions
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index 938fb04ab9..ce713b7d41 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -1,111 +1,81 @@ /* - * Copyright 2012 Google Inc. + * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +/* + * This file was autogenerated from GrSimpleTextureEffect.fp; do not modify. + */ #include "GrSimpleTextureEffect.h" -#include "GrProxyMove.h" +#if SK_SUPPORT_GPU #include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" - -GrSimpleTextureEffect::GrSimpleTextureEffect(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, - const SkMatrix& matrix, - GrSamplerParams::FilterMode filterMode) - : INHERITED{ModulationFlags(proxy->config()), - GR_PROXY_MOVE(proxy), - std::move(colorSpaceXform), - matrix, - filterMode} { - this->initClassID<GrSimpleTextureEffect>(); -} - -GrSimpleTextureEffect::GrSimpleTextureEffect(sk_sp<GrTextureProxy> proxy, - sk_sp<GrColorSpaceXform> colorSpaceXform, - const SkMatrix& matrix, - const GrSamplerParams& params) - : INHERITED{ModulationFlags(proxy->config()), - GR_PROXY_MOVE(proxy), - std::move(colorSpaceXform), - matrix, - params} { - this->initClassID<GrSimpleTextureEffect>(); -} - -class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor { +#include "glsl/GrGLSLProgramBuilder.h" +#include "SkSLCPP.h" +#include "SkSLUtil.h" +class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor { public: + GrGLSLSimpleTextureEffect() {} void emitCode(EmitArgs& args) override { - const GrSimpleTextureEffect& textureEffect = args.fFp.cast<GrSimpleTextureEffect>(); - fColorSpaceHelper.emitCode(args.fUniformHandler, textureEffect.colorSpaceXform()); - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - fragBuilder->codeAppendf("%s = ", args.fOutputColor); - fragBuilder->appendTextureLookupAndModulate(args.fInputColor, - args.fTexSamplers[0], - args.fTransformedCoords[0].c_str(), - args.fTransformedCoords[0].getType(), - &fColorSpaceHelper); - fragBuilder->codeAppend(";"); - } - - static inline void GenKey(const GrProcessor& effect, const GrShaderCaps&, - GrProcessorKeyBuilder* b) { - const GrSimpleTextureEffect& textureEffect = effect.cast<GrSimpleTextureEffect>(); - b->add32(GrColorSpaceXform::XformKey(textureEffect.colorSpaceXform())); + const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>(); + (void) _outer; + fColorSpaceHelper.emitCode(args.fUniformHandler, _outer.colorXform().get()); + SkSL::String sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); + fragBuilder->codeAppendf("vec4 _tmp0;\n%s = %s * (_tmp0 = texture(%s, %s).%s , %s != mat4(1.0) ? vec4(clamp((%s * vec4(_tmp0.xyz, 1.0)).xyz, 0.0, _tmp0.w), _tmp0.w) : _tmp0);\n", args.fOutputColor, args.fInputColor ? args.fInputColor : "vec4(1)", fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), sk_TransformedCoords2D_0.c_str(), fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), fColorSpaceHelper.isValid() ? args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform()) : "mat4(1.0)", fColorSpaceHelper.isValid() ? args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform()) : "mat4(1.0)"); } - -protected: - void onSetData(const GrGLSLProgramDataManager& pdman, - const GrFragmentProcessor& processor) override { - const GrSimpleTextureEffect& textureEffect = processor.cast<GrSimpleTextureEffect>(); - if (SkToBool(textureEffect.colorSpaceXform())) { - fColorSpaceHelper.setData(pdman, textureEffect.colorSpaceXform()); +private: + void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override { + const GrSimpleTextureEffect& _outer = _proc.cast<GrSimpleTextureEffect>(); + { + if (fColorSpaceHelper.isValid()) { + fColorSpaceHelper.setData(pdman, _outer.colorXform().get()); + } } } - -private: - typedef GrGLSLFragmentProcessor INHERITED; - + UniformHandle fImageVar; GrGLSLColorSpaceXformHelper fColorSpaceHelper; }; - -/////////////////////////////////////////////////////////////////////////////// - -void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const { - GrGLSimpleTextureEffect::GenKey(*this, caps, b); +GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const { + return new GrGLSLSimpleTextureEffect(); } - -GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const { - return new GrGLSimpleTextureEffect; +void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { + b->add32(GrColorSpaceXform::XformKey(fColorXform.get())); +} +bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const { + const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>(); + (void) that; + if (fImage != that.fImage) return false; + if (fColorXform != that.fColorXform) return false; + if (fMatrix != that.fMatrix) return false; + return true; } - -/////////////////////////////////////////////////////////////////////////////// - GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); - #if GR_TEST_UTILS -sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) { - int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx - : GrProcessorUnitTest::kAlphaTextureIdx; +sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* testData) { + + int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx + : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, }; SkShader::TileMode tileModes[] = { - kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], - kTileModes[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], + kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], + kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], }; - GrSamplerParams params(tileModes, d->fRandom->nextBool() ? GrSamplerParams::kBilerp_FilterMode - : GrSamplerParams::kNone_FilterMode); - - const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom); - sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(d->fRandom); - return GrSimpleTextureEffect::Make(d->textureProxy(texIdx), - std::move(colorSpaceXform), matrix); + GrSamplerParams params(tileModes, testData->fRandom->nextBool() + ? GrSamplerParams::kBilerp_FilterMode + : GrSamplerParams::kNone_FilterMode); + + const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom); + sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom); + return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform), + matrix); } #endif +#endif |