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 | #ifndef GrClampFragmentProcessor_DEFINED |
12 | #define GrClampFragmentProcessor_DEFINED |
13 | |
14 | #include "include/core/SkM44.h" |
15 | #include "include/core/SkTypes.h" |
16 | |
17 | #include "src/gpu/GrFragmentProcessor.h" |
18 | |
19 | class GrClampFragmentProcessor : public GrFragmentProcessor { |
20 | public: |
21 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override { |
22 | SkPMColor4f input = ConstantOutputForConstantInput(this->childProcessor(0), inColor); |
23 | float clampedAlpha = SkTPin(input.fA, 0.f, 1.f); |
24 | float clampVal = clampToPremul ? clampedAlpha : 1.f; |
25 | return {SkTPin(input.fR, 0.f, clampVal), SkTPin(input.fG, 0.f, clampVal), |
26 | SkTPin(input.fB, 0.f, clampVal), clampedAlpha}; |
27 | } |
28 | static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP, |
29 | bool clampToPremul) { |
30 | return std::unique_ptr<GrFragmentProcessor>( |
31 | new GrClampFragmentProcessor(std::move(inputFP), clampToPremul)); |
32 | } |
33 | GrClampFragmentProcessor(const GrClampFragmentProcessor& src); |
34 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
35 | const char* name() const override { return "ClampFragmentProcessor" ; } |
36 | bool clampToPremul; |
37 | |
38 | private: |
39 | GrClampFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP, bool clampToPremul) |
40 | : INHERITED(kGrClampFragmentProcessor_ClassID, |
41 | (OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get()) |
42 | : kAll_OptimizationFlags) & |
43 | (kConstantOutputForConstantInput_OptimizationFlag | |
44 | kPreservesOpaqueInput_OptimizationFlag)) |
45 | , clampToPremul(clampToPremul) { |
46 | this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough()); |
47 | } |
48 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
49 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
50 | bool onIsEqual(const GrFragmentProcessor&) const override; |
51 | #if GR_TEST_UTILS |
52 | SkString onDumpInfo() const override; |
53 | #endif |
54 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
55 | typedef GrFragmentProcessor INHERITED; |
56 | }; |
57 | #endif |
58 | |