• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "GrTexture.h"
16 #include "SkSLCPP.h"
17 #include "SkSLUtil.h"
18 class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
19 public:
GrGLSLSimpleTextureEffect()20     GrGLSLSimpleTextureEffect() {}
emitCode(EmitArgs & args)21     void emitCode(EmitArgs& args) override {
22         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23         const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
24         (void)_outer;
25         auto matrix = _outer.matrix();
26         (void)matrix;
27         SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
28         fragBuilder->codeAppendf(
29                 "%s = %s * texture(%s, %s).%s;\n", args.fOutputColor, args.fInputColor,
30                 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
31                 sk_TransformedCoords2D_0.c_str(),
32                 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
33     }
34 
35 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)36     void onSetData(const GrGLSLProgramDataManager& pdman,
37                    const GrFragmentProcessor& _proc) override {}
38 };
onCreateGLSLInstance() const39 GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
40     return new GrGLSLSimpleTextureEffect();
41 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const42 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
43                                                   GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const44 bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
45     const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
46     (void)that;
47     if (fImage != that.fImage) return false;
48     if (fMatrix != that.fMatrix) return false;
49     return true;
50 }
GrSimpleTextureEffect(const GrSimpleTextureEffect & src)51 GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src)
52         : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags())
53         , fImage(src.fImage)
54         , fMatrix(src.fMatrix)
55         , fImageCoordTransform(src.fImageCoordTransform) {
56     this->setTextureSamplerCnt(1);
57     this->addCoordTransform(&fImageCoordTransform);
58 }
clone() const59 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const {
60     return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this));
61 }
onTextureSampler(int index) const62 const GrFragmentProcessor::TextureSampler& GrSimpleTextureEffect::onTextureSampler(
63         int index) const {
64     return IthTextureSampler(index, fImage);
65 }
66 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
67 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * testData)68 std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(
69         GrProcessorTestData* testData) {
70     int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
71                                                : GrProcessorUnitTest::kAlphaTextureIdx;
72     GrSamplerState::WrapMode wrapModes[2];
73     GrTest::TestWrapModes(testData->fRandom, wrapModes);
74     if (!testData->caps()->npotTextureTileSupport()) {
75         // Performing repeat sampling on npot textures will cause asserts on HW
76         // that lacks support.
77         wrapModes[0] = GrSamplerState::WrapMode::kClamp;
78         wrapModes[1] = GrSamplerState::WrapMode::kClamp;
79     }
80 
81     GrSamplerState params(wrapModes, testData->fRandom->nextBool()
82                                              ? GrSamplerState::Filter::kBilerp
83                                              : GrSamplerState::Filter::kNearest);
84 
85     const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
86     return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params);
87 }
88 #endif
89