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 | |
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')
-rw-r--r-- | src/gpu/effects/GrDitherEffect.h | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.cpp | 130 | ||||
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.fp | 82 | ||||
-rw-r--r-- | src/gpu/effects/GrSimpleTextureEffect.h | 97 |
4 files changed, 184 insertions, 126 deletions
diff --git a/src/gpu/effects/GrDitherEffect.h b/src/gpu/effects/GrDitherEffect.h index d0bf9a9f9c..a996ad94c2 100644 --- a/src/gpu/effects/GrDitherEffect.h +++ b/src/gpu/effects/GrDitherEffect.h @@ -14,6 +14,7 @@ #if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" #include "GrCoordTransform.h" +#include "GrColorSpaceXform.h" #include "effects/GrProxyMove.h" class GrDitherEffect : public GrFragmentProcessor { public: 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 diff --git a/src/gpu/effects/GrSimpleTextureEffect.fp b/src/gpu/effects/GrSimpleTextureEffect.fp new file mode 100644 index 0000000000..20944447ce --- /dev/null +++ b/src/gpu/effects/GrSimpleTextureEffect.fp @@ -0,0 +1,82 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +in uniform sampler2D image; +in uniform colorSpaceXform colorXform; +in mat4 matrix; + +@constructorParams { + GrSamplerParams samplerParams +} + +@coordTransform(image) { + matrix +} + +@samplerParams(image) { + samplerParams +} + +@make { + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkMatrix& matrix) { + return sk_sp<GrFragmentProcessor>( + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, + GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode))); + } + + /* clamp mode */ + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkMatrix& matrix, + GrSamplerParams::FilterMode filterMode) { + return sk_sp<GrFragmentProcessor>( + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, + GrSamplerParams(SkShader::kClamp_TileMode, filterMode))); + } + + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkMatrix& matrix, + const GrSamplerParams& p) { + return sk_sp<GrFragmentProcessor>( + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, p)); + } +} + +@optimizationFlags { + kCompatibleWithCoverageAsAlpha_OptimizationFlag | + (GrPixelConfigIsOpaque(image->config()) ? kPreservesOpaqueInput_OptimizationFlag : + kNone_OptimizationFlags) +} + +void main() { + sk_OutColor = sk_InColor * texture(image, sk_TransformedCoords2D[0], colorXform); +} + +@test(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[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], + kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))], + }; + 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); +} diff --git a/src/gpu/effects/GrSimpleTextureEffect.h b/src/gpu/effects/GrSimpleTextureEffect.h index 5013e3dce8..aed91d7c10 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.h +++ b/src/gpu/effects/GrSimpleTextureEffect.h @@ -1,77 +1,82 @@ /* - * Copyright 2013 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. + */ #ifndef GrSimpleTextureEffect_DEFINED #define GrSimpleTextureEffect_DEFINED - -#include "GrSingleTextureEffect.h" -#include "GrTextureProxy.h" - -class GrInvariantOutput; - -/** - * The output color of this effect is a modulation of the input color and a sample from a texture. - * It allows explicit specification of the filtering and wrap modes (GrSamplerParams) and accepts - * a matrix that is used to compute texture coordinates from local coordinates. - */ -class GrSimpleTextureEffect : public GrSingleTextureEffect { +#include "SkTypes.h" +#if SK_SUPPORT_GPU +#include "GrFragmentProcessor.h" +#include "GrCoordTransform.h" +#include "GrColorSpaceXform.h" +#include "effects/GrProxyMove.h" +class GrSimpleTextureEffect : public GrFragmentProcessor { public: - /* unfiltered, clamp mode */ + sk_sp<GrColorSpaceXform> colorXform() const { return fColorXform; } + SkMatrix44 matrix() const { return fMatrix; } + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix) { return sk_sp<GrFragmentProcessor>( - new GrSimpleTextureEffect(std::move(proxy), - std::move(colorSpaceXform), matrix, - GrSamplerParams::kNone_FilterMode)); + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, + GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode))); } - /* clamp mode */ + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, GrSamplerParams::FilterMode filterMode) { return sk_sp<GrFragmentProcessor>( - new GrSimpleTextureEffect(std::move(proxy), - std::move(colorSpaceXform), - matrix, filterMode)); - } + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, + GrSamplerParams(SkShader::kClamp_TileMode, filterMode))); + } static sk_sp<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkMatrix& matrix, const GrSamplerParams& p) { - return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(std::move(proxy), - std::move(colorSpaceXform), - matrix, p)); + return sk_sp<GrFragmentProcessor>( + new GrSimpleTextureEffect(std::move(proxy), std::move(colorSpaceXform), matrix, p)); } - - ~GrSimpleTextureEffect() override {} - - const char* name() const override { return "SimpleTexture"; } - + const char* name() const override { return "SimpleTextureEffect"; } private: - GrSimpleTextureEffect(sk_sp<GrTextureProxy>, - sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, - GrSamplerParams::FilterMode); - - GrSimpleTextureEffect(sk_sp<GrTextureProxy>, - sk_sp<GrColorSpaceXform>, const SkMatrix& matrix, - const GrSamplerParams&); - + GrSimpleTextureEffect(sk_sp<GrTextureProxy> image, sk_sp<GrColorSpaceXform> colorXform, SkMatrix44 matrix, + GrSamplerParams samplerParams +) + : INHERITED((OptimizationFlags) + kCompatibleWithCoverageAsAlpha_OptimizationFlag | + (GrPixelConfigIsOpaque(image->config()) ? kPreservesOpaqueInput_OptimizationFlag : + kNone_OptimizationFlags) +) + , fImage(std::move(image), + samplerParams +) + , fColorXform(colorXform) + , fMatrix(matrix) + , fImageCoordTransform( + matrix +, fImage.proxy()) { + this->addTextureSampler(&fImage); + this->addCoordTransform(&fImageCoordTransform); + this->initClassID<GrSimpleTextureEffect>(); + } GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; - - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; - - bool onIsEqual(const GrFragmentProcessor& other) const override { return true; } - + void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) const override; + bool onIsEqual(const GrFragmentProcessor&) const override; GR_DECLARE_FRAGMENT_PROCESSOR_TEST - - typedef GrSingleTextureEffect INHERITED; + TextureSampler fImage; + sk_sp<GrColorSpaceXform> fColorXform; + SkMatrix44 fMatrix; + GrCoordTransform fImageCoordTransform; + typedef GrFragmentProcessor INHERITED; }; - +#endif #endif |