1 /*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 /**************************************************************************************************
9 *** This file was autogenerated from GrSimpleTextureEffect.fp; do not modify.
10 **************************************************************************************************/
11 #include "GrSimpleTextureEffect.h"
12
13 #include "include/gpu/GrTexture.h"
14 #include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
15 #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
16 #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
17 #include "src/sksl/SkSLCPP.h"
18 #include "src/sksl/SkSLUtil.h"
19 class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
20 public:
GrGLSLSimpleTextureEffect()21 GrGLSLSimpleTextureEffect() {}
emitCode(EmitArgs & args)22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
25 (void)_outer;
26 auto matrix = _outer.matrix;
27 (void)matrix;
28 SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
29 fragBuilder->codeAppendf(
30 "%s = %s * sample(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
31 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]),
32 sk_TransformedCoords2D_0.c_str(),
33 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
34 }
35
36 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)37 void onSetData(const GrGLSLProgramDataManager& pdman,
38 const GrFragmentProcessor& _proc) override {}
39 };
onCreateGLSLInstance() const40 GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
41 return new GrGLSLSimpleTextureEffect();
42 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const43 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
44 GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const45 bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
46 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
47 (void)that;
48 if (image != that.image) return false;
49 if (matrix != that.matrix) return false;
50 return true;
51 }
GrSimpleTextureEffect(const GrSimpleTextureEffect & src)52 GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
53 : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
54 , imageCoordTransform(src.imageCoordTransform)
55 , image(src.image)
56 , matrix(src.matrix) {
57 this->setTextureSamplerCnt(1);
58 this->addCoordTransform(&imageCoordTransform);
59 }
clone() const60 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
61 return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
62 }
onTextureSampler(int index) const63 const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
64 int index) const {
65 return IthTextureSampler(index, image);
66 }
67 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
68 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * testData)69 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
70 GrProcessorTestData* testData) {
71 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
72 : GrProcessorUnitTest::kAlphaTextureIdx;
73 GrSamplerState::WrapMode wrapModes[2];
74 GrTest::TestWrapModes(testData->fRandom, wrapModes);
75 if (!testData->caps()->npotTextureTileSupport()) {
76 // Performing repeat sampling on npot textures will cause asserts on HW
77 // that lacks support.
78 wrapModes[0] = GrSamplerState::WrapMode::kClamp;
79 wrapModes[1] = GrSamplerState::WrapMode::kClamp;
80 }
81
82 GrSamplerState params(wrapModes, testData->fRandom->nextBool()
83 ? GrSamplerState::Filter::kBilerp
84 : GrSamplerState::Filter::kNearest);
85
86 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
87 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
88 }
89 #endif
90