1 /*
2  * Copyright 2018 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 GrTextureGradientColorizer.fp; do not modify.
10  **************************************************************************************************/
11 #include "GrTextureGradientColorizer.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 GrGLSLTextureGradientColorizer : public GrGLSLFragmentProcessor {
19 public:
GrGLSLTextureGradientColorizer()20     GrGLSLTextureGradientColorizer() {}
emitCode(EmitArgs & args)21     void emitCode(EmitArgs& args) override {
22         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23         const GrTextureGradientColorizer& _outer = args.fFp.cast<GrTextureGradientColorizer>();
24         (void)_outer;
25         fragBuilder->codeAppendf(
26                 "half2 coord = half2(%s.x, 0.5);\n%s = texture(%s, float2(coord)).%s;\n",
27                 args.fInputColor, args.fOutputColor,
28                 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
29                 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str());
30     }
31 
32 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)33     void onSetData(const GrGLSLProgramDataManager& pdman,
34                    const GrFragmentProcessor& _proc) override {}
35 };
onCreateGLSLInstance() const36 GrGLSLFragmentProcessor* GrTextureGradientColorizer::onCreateGLSLInstance() const {
37     return new GrGLSLTextureGradientColorizer();
38 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const39 void GrTextureGradientColorizer::onGetGLSLProcessorKey(const GrShaderCaps& caps,
40                                                        GrProcessorKeyBuilder* b) const {}
onIsEqual(const GrFragmentProcessor & other) const41 bool GrTextureGradientColorizer::onIsEqual(const GrFragmentProcessor& other) const {
42     const GrTextureGradientColorizer& that = other.cast<GrTextureGradientColorizer>();
43     (void)that;
44     if (fGradient != that.fGradient) return false;
45     return true;
46 }
GrTextureGradientColorizer(const GrTextureGradientColorizer & src)47 GrTextureGradientColorizer::GrTextureGradientColorizer(const GrTextureGradientColorizer& src)
48         : INHERITED(kGrTextureGradientColorizer_ClassID, src.optimizationFlags())
49         , fGradient(src.fGradient) {
50     this->setTextureSamplerCnt(1);
51 }
clone() const52 std::unique_ptr<GrFragmentProcessor> GrTextureGradientColorizer::clone() const {
53     return std::unique_ptr<GrFragmentProcessor>(new GrTextureGradientColorizer(*this));
54 }
onTextureSampler(int index) const55 const GrFragmentProcessor::TextureSampler& GrTextureGradientColorizer::onTextureSampler(
56         int index) const {
57     return IthTextureSampler(index, fGradient);
58 }
59