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 "src/core/SkUtils.h" |
14 | #include "src/gpu/GrTexture.h" |
15 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
16 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
17 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
18 | #include "src/sksl/SkSLCPP.h" |
19 | #include "src/sksl/SkSLUtil.h" |
20 | class GrGLSLClampFragmentProcessor : public GrGLSLFragmentProcessor { |
21 | public: |
22 | GrGLSLClampFragmentProcessor() {} |
23 | void emitCode(EmitArgs& args) override { |
24 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
25 | const GrClampFragmentProcessor& _outer = args.fFp.cast<GrClampFragmentProcessor>(); |
26 | (void)_outer; |
27 | auto clampToPremul = _outer.clampToPremul; |
28 | (void)clampToPremul; |
29 | SkString _sample464 = this->invokeChild(0, args); |
30 | fragBuilder->codeAppendf( |
31 | R"SkSL(half4 inputColor = %s; |
32 | @if (%s) { |
33 | half alpha = clamp(inputColor.w, 0.0, 1.0); |
34 | %s = half4(clamp(inputColor.xyz, 0.0, alpha), alpha); |
35 | } else { |
36 | %s = clamp(inputColor, 0.0, 1.0); |
37 | } |
38 | )SkSL" , |
39 | _sample464.c_str(), (_outer.clampToPremul ? "true" : "false" ), args.fOutputColor, |
40 | args.fOutputColor); |
41 | } |
42 | |
43 | private: |
44 | void onSetData(const GrGLSLProgramDataManager& pdman, |
45 | const GrFragmentProcessor& _proc) override {} |
46 | }; |
47 | GrGLSLFragmentProcessor* GrClampFragmentProcessor::onCreateGLSLInstance() const { |
48 | return new GrGLSLClampFragmentProcessor(); |
49 | } |
50 | void GrClampFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
51 | GrProcessorKeyBuilder* b) const { |
52 | b->add32((uint32_t)clampToPremul); |
53 | } |
54 | bool GrClampFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { |
55 | const GrClampFragmentProcessor& that = other.cast<GrClampFragmentProcessor>(); |
56 | (void)that; |
57 | if (clampToPremul != that.clampToPremul) return false; |
58 | return true; |
59 | } |
60 | GrClampFragmentProcessor::GrClampFragmentProcessor(const GrClampFragmentProcessor& src) |
61 | : INHERITED(kGrClampFragmentProcessor_ClassID, src.optimizationFlags()) |
62 | , clampToPremul(src.clampToPremul) { |
63 | this->cloneAndRegisterAllChildProcessors(src); |
64 | } |
65 | std::unique_ptr<GrFragmentProcessor> GrClampFragmentProcessor::clone() const { |
66 | return std::make_unique<GrClampFragmentProcessor>(*this); |
67 | } |
68 | #if GR_TEST_UTILS |
69 | SkString GrClampFragmentProcessor::onDumpInfo() const { |
70 | return SkStringPrintf("(clampToPremul=%s)" , (clampToPremul ? "true" : "false" )); |
71 | } |
72 | #endif |
73 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrClampFragmentProcessor); |
74 | #if GR_TEST_UTILS |
75 | std::unique_ptr<GrFragmentProcessor> GrClampFragmentProcessor::TestCreate(GrProcessorTestData* d) { |
76 | return GrClampFragmentProcessor::Make(d->inputFP(), d->fRandom->nextBool()); |
77 | } |
78 | #endif |
79 | |