1 /*
2 * Copyright 2019 Google LLC
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 GrClampFragmentProcessor.fp; do not modify.
10 **************************************************************************************************/
11 #include "GrClampFragmentProcessor.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 GrGLSLClampFragmentProcessor : public GrGLSLFragmentProcessor {
20 public:
GrGLSLClampFragmentProcessor()21 GrGLSLClampFragmentProcessor() {}
emitCode(EmitArgs & args)22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrClampFragmentProcessor& _outer = args.fFp.cast<GrClampFragmentProcessor>();
25 (void)_outer;
26 auto clampToPremul = _outer.clampToPremul;
27 (void)clampToPremul;
28 fragBuilder->codeAppendf(
29 "@if (%s) {\n half alpha = clamp(%s.w, 0.0, 1.0);\n %s = half4(clamp(%s.xyz, "
30 "0.0, alpha), alpha);\n} else {\n %s = clamp(%s, 0.0, 1.0);\n}\n",
31 (_outer.clampToPremul ? "true" : "false"), args.fInputColor, args.fOutputColor,
32 args.fInputColor, args.fOutputColor, args.fInputColor);
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* GrClampFragmentProcessor::onCreateGLSLInstance() const {
40 return new GrGLSLClampFragmentProcessor();
41 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const42 void GrClampFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
43 GrProcessorKeyBuilder* b) const {
44 b->add32((int32_t)clampToPremul);
45 }
onIsEqual(const GrFragmentProcessor & other) const46 bool GrClampFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
47 const GrClampFragmentProcessor& that = other.cast<GrClampFragmentProcessor>();
48 (void)that;
49 if (clampToPremul != that.clampToPremul) return false;
50 return true;
51 }
GrClampFragmentProcessor(const GrClampFragmentProcessor & src)52 GrClampFragmentProcessor::GrClampFragmentProcessor(const GrClampFragmentProcessor& src)
53 : INHERITED(kGrClampFragmentProcessor_ClassID, src.optimizationFlags())
54 , clampToPremul(src.clampToPremul) {}
clone() const55 std::unique_ptr<GrFragmentProcessor> GrClampFragmentProcessor::clone() const {
56 return std::unique_ptr<GrFragmentProcessor>(new GrClampFragmentProcessor(*this));
57 }
58 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrClampFragmentProcessor);
59 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * d)60 std::unique_ptr<GrFragmentProcessor> GrClampFragmentProcessor::TestCreate(GrProcessorTestData* d) {
61 return GrClampFragmentProcessor::Make(d->fRandom->nextBool());
62 }
63 #endif
64