blob: bd2b80529a9407c7b98223d47b51b1af4b27d2f4 [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
Ethan Nicholas68990be2017-07-13 09:36:52 -04002 * Copyright 2017 Google Inc.
bsalomon@google.com68b58c92013-01-17 16:50:08 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Ethan Nicholas68990be2017-07-13 09:36:52 -04008/*
9 * This file was autogenerated from GrSimpleTextureEffect.fp; do not modify.
10 */
bsalomon@google.com68b58c92013-01-17 16:50:08 +000011#include "GrSimpleTextureEffect.h"
Ethan Nicholas68990be2017-07-13 09:36:52 -040012#if SK_SUPPORT_GPU
brianosman77320db2016-09-07 08:09:10 -070013#include "glsl/GrGLSLColorSpaceXformHelper.h"
egdaniel64c47282015-11-13 06:54:19 -080014#include "glsl/GrGLSLFragmentProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080015#include "glsl/GrGLSLFragmentShaderBuilder.h"
Ethan Nicholas68990be2017-07-13 09:36:52 -040016#include "glsl/GrGLSLProgramBuilder.h"
17#include "SkSLCPP.h"
18#include "SkSLUtil.h"
19class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020public:
Ethan Nicholas68990be2017-07-13 09:36:52 -040021 GrGLSLSimpleTextureEffect() {}
robertphillips9cdb9922016-02-03 12:25:40 -080022 void emitCode(EmitArgs& args) override {
cdalton85285412016-02-18 12:37:07 -080023 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
Ethan Nicholas68990be2017-07-13 09:36:52 -040024 const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040025 (void)_outer;
Ethan Nicholas68990be2017-07-13 09:36:52 -040026 fColorSpaceHelper.emitCode(args.fUniformHandler, _outer.colorXform().get());
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040027 SkSL::String sk_TransformedCoords2D_0 =
28 fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
29 fragBuilder->codeAppendf(
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040030 "float4 _tmpVar1;%s = %s * %stexture(%s, %s).%s%s;\n", args.fOutputColor,
31 args.fInputColor ? args.fInputColor : "float4(1)",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040032 fColorSpaceHelper.isValid() ? "(_tmpVar1 = " : "",
33 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
34 sk_TransformedCoords2D_0.c_str(),
35 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
36 fColorSpaceHelper.isValid()
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040037 ? SkStringPrintf(", float4(clamp((%s * float4(_tmpVar1.rgb, 1.0)).rgb, "
38 "0.0, _tmpVar1.a), _tmpVar1.a))",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040039 args.fUniformHandler->getUniformCStr(
40 fColorSpaceHelper.gamutXformUniform()))
41 .c_str()
42 : "");
bsalomon@google.com68b58c92013-01-17 16:50:08 +000043 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040044
Ethan Nicholas68990be2017-07-13 09:36:52 -040045private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040046 void onSetData(const GrGLSLProgramDataManager& pdman,
47 const GrFragmentProcessor& _proc) override {
Ethan Nicholas68990be2017-07-13 09:36:52 -040048 const GrSimpleTextureEffect& _outer = _proc.cast<GrSimpleTextureEffect>();
49 {
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040050 if (fColorSpaceHelper.isValid()) {
51 fColorSpaceHelper.setData(pdman, _outer.colorXform().get());
52 }
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000053 }
54 }
Ethan Nicholas68990be2017-07-13 09:36:52 -040055 UniformHandle fImageVar;
Brian Osmanc624d9d2017-03-08 11:42:02 -050056 GrGLSLColorSpaceXformHelper fColorSpaceHelper;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000057};
Ethan Nicholas68990be2017-07-13 09:36:52 -040058GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
59 return new GrGLSLSimpleTextureEffect();
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000060}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040061void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
62 GrProcessorKeyBuilder* b) const {
Ethan Nicholas68990be2017-07-13 09:36:52 -040063 b->add32(GrColorSpaceXform::XformKey(fColorXform.get()));
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000064}
Ethan Nicholas68990be2017-07-13 09:36:52 -040065bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
66 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040067 (void)that;
Ethan Nicholas68990be2017-07-13 09:36:52 -040068 if (fImage != that.fImage) return false;
69 if (fColorXform != that.fColorXform) return false;
70 if (fMatrix != that.fMatrix) return false;
71 return true;
72}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040073GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
74 : INHERITED(src.optimizationFlags())
75 , fImage(src.fImage)
76 , fColorXform(src.fColorXform)
77 , fMatrix(src.fMatrix)
78 , fImageCoordTransform(src.fImageCoordTransform) {
79 this->initClassID<GrSimpleTextureEffect>();
80 this->addTextureSampler(&fImage);
81 this->addCoordTransform(&fImageCoordTransform);
82}
83sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
84 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
85}
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000086GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
Ethan Nicholasbaf981f2017-07-12 13:51:34 +000087#if GR_TEST_UTILS
Ethan Nicholas68990be2017-07-13 09:36:52 -040088sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* testData) {
Ethan Nicholas68990be2017-07-13 09:36:52 -040089 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
90 : GrProcessorUnitTest::kAlphaTextureIdx;
bsalomon@google.comc7818882013-03-20 19:19:53 +000091 static const SkShader::TileMode kTileModes[] = {
Ethan Nicholas480c90a2017-07-25 16:45:15 -040092 SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode,
bsalomon@google.comc7818882013-03-20 19:19:53 +000093 };
94 SkShader::TileMode tileModes[] = {
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040095 kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
96 kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
bsalomon@google.comc7818882013-03-20 19:19:53 +000097 };
Ethan Nicholasb9f6afb2017-07-27 16:02:37 -040098 GrSamplerParams params(tileModes, testData->fRandom->nextBool()
99 ? GrSamplerParams::kBilerp_FilterMode
100 : GrSamplerParams::kNone_FilterMode);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000101
Ethan Nicholas68990be2017-07-13 09:36:52 -0400102 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
103 sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom);
104 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform),
105 matrix);
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000106}
Hal Canary6f6961e2017-01-31 13:50:44 -0500107#endif
Ethan Nicholas68990be2017-07-13 09:36:52 -0400108#endif