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 =
29                 fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint);
30         fragBuilder->codeAppendf(
31                 "%s = %s * sample(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
32                 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]),
33                 _outer.computeLocalCoordsInVertexShader() ? sk_TransformedCoords2D_0.c_str()
34                                                           : "_coords",
35                 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
36     }
37 
38 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)39     void onSetData(const GrGLSLProgramDataManager& pdman,
40                    const GrFragmentProcessor& _proc) override {}
41 };
onCreateGLSLInstance() const42 GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
43     return new GrGLSLSimpleTextureEffect();
44 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const45 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
46                                                   GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const47 bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
48     const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
49     (void)that;
50     if (image != that.image) return false;
51     if (matrix != that.matrix) return false;
52     return true;
53 }
GrSimpleTextureEffect(const GrSimpleTextureEffect & src)54 GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
55         : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
56         , imageCoordTransform(src.imageCoordTransform)
57         , image(src.image)
58         , matrix(src.matrix) {
59     this->setTextureSamplerCnt(1);
60     this->addCoordTransform(&imageCoordTransform);
61 }
clone() const62 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
63     return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
64 }
onTextureSampler(int index) const65 const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
66         int index) const {
67     return IthTextureSampler(index, image);
68 }
69 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
70 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * testData)71 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
72         GrProcessorTestData* testData) {
73     int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
74                                                : GrProcessorUnitTest::kAlphaTextureIdx;
75     GrSamplerState::WrapMode wrapModes[2];
76     GrTest::TestWrapModes(testData->fRandom, wrapModes);
77     if (!testData->caps()->npotTextureTileSupport()) {
78         // Performing repeat sampling on npot textures will cause asserts on HW
79         // that lacks support.
80         wrapModes[0] = GrSamplerState::WrapMode::kClamp;
81         wrapModes[1] = GrSamplerState::WrapMode::kClamp;
82     }
83 
84     GrSamplerState params(wrapModes, testData->fRandom->nextBool()
85                                              ? GrSamplerState::Filter::kBilerp
86                                              : GrSamplerState::Filter::kNearest);
87 
88     const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
89     return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx),
90                                        testData->textureProxyColorType(texIdx), matrix, params);
91 }
92 #endif
93