aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects/GrSimpleTextureEffect.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-07-13 09:36:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-13 14:07:02 +0000
commit68990be759f663bafdb7c1b746adce15557cda7f (patch)
treeb982e218f45fa02188bb38fe767797ff6315edcf /src/gpu/effects/GrSimpleTextureEffect.cpp
parentc20b5f83595073c02009ff3c0a8a77aca6ad1e71 (diff)
Re-land of "converted GrSimpleTextureEffect to sksl"
This reverts commit baf981f71614e7a2fbe6af2726e65126d431ed8e. Bug: skia: Change-Id: I36f6bfb616f1ec2b89043e3a6f7cbdf473bc9588 Reviewed-on: https://skia-review.googlesource.com/22369 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/gpu/effects/GrSimpleTextureEffect.cpp')
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.cpp130
1 files changed, 50 insertions, 80 deletions
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp
index 938fb04ab9..181d0f788e 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 _tmpVar1;%s = %s * %stexture(%s, %s).%s%s;\n", args.fOutputColor, args.fInputColor ? args.fInputColor : "vec4(1)", fColorSpaceHelper.isValid() ? "(_tmpVar1 = " : "", fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), sk_TransformedCoords2D_0.c_str(), fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(), fColorSpaceHelper.isValid() ? SkStringPrintf(", vec4(clamp((%s * vec4(_tmpVar1.rgb, 1.0)).rgb, 0.0, _tmpVar1.a), _tmpVar1.a))", args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform())).c_str() : "");
}
-
-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