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 GrColorMatrixFragmentProcessor.fp; do not modify. |
10 | **************************************************************************************************/ |
11 | #ifndef GrColorMatrixFragmentProcessor_DEFINED |
12 | #define GrColorMatrixFragmentProcessor_DEFINED |
13 | #include "include/core/SkTypes.h" |
14 | #include "include/core/SkM44.h" |
15 | |
16 | #include "src/gpu/GrCoordTransform.h" |
17 | #include "src/gpu/GrFragmentProcessor.h" |
18 | class GrColorMatrixFragmentProcessor : public GrFragmentProcessor { |
19 | public: |
20 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override { |
21 | SkColor4f color; |
22 | if (unpremulInput) { |
23 | color = input.unpremul(); |
24 | } else { |
25 | color.fR = input.fR; |
26 | color.fG = input.fG; |
27 | color.fB = input.fB; |
28 | color.fA = input.fA; |
29 | } |
30 | auto v4 = m.map(color.fR, color.fG, color.fB, color.fA) + v; |
31 | color = {v4.x, v4.y, v4.z, v4.w}; |
32 | color.fA = SkTPin(color.fA, 0.f, 1.f); |
33 | if (clampRGBOutput) { |
34 | color.fR = SkTPin(color.fR, 0.f, 1.f); |
35 | color.fG = SkTPin(color.fG, 0.f, 1.f); |
36 | color.fB = SkTPin(color.fB, 0.f, 1.f); |
37 | } |
38 | if (premulOutput) { |
39 | return color.premul(); |
40 | } else { |
41 | return {color.fR, color.fG, color.fB, color.fA}; |
42 | } |
43 | } |
44 | |
45 | static std::unique_ptr<GrFragmentProcessor> Make(const float matrix[20], |
46 | bool unpremulInput, |
47 | bool clampRGBOutput, |
48 | bool premulOutput) { |
49 | SkM44 m44(matrix[0], matrix[1], matrix[2], matrix[3], matrix[5], matrix[6], matrix[7], |
50 | matrix[8], matrix[10], matrix[11], matrix[12], matrix[13], matrix[15], matrix[16], |
51 | matrix[17], matrix[18]); |
52 | SkV4 v4 = {matrix[4], matrix[9], matrix[14], matrix[19]}; |
53 | return std::unique_ptr<GrFragmentProcessor>(new GrColorMatrixFragmentProcessor( |
54 | m44, v4, unpremulInput, clampRGBOutput, premulOutput)); |
55 | } |
56 | GrColorMatrixFragmentProcessor(const GrColorMatrixFragmentProcessor& src); |
57 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
58 | const char* name() const override { return "ColorMatrixFragmentProcessor" ; } |
59 | SkM44 m; |
60 | SkV4 v; |
61 | bool unpremulInput; |
62 | bool clampRGBOutput; |
63 | bool premulOutput; |
64 | |
65 | private: |
66 | GrColorMatrixFragmentProcessor( |
67 | SkM44 m, SkV4 v, bool unpremulInput, bool clampRGBOutput, bool premulOutput) |
68 | : INHERITED(kGrColorMatrixFragmentProcessor_ClassID, |
69 | (OptimizationFlags)kConstantOutputForConstantInput_OptimizationFlag) |
70 | , m(m) |
71 | , v(v) |
72 | , unpremulInput(unpremulInput) |
73 | , clampRGBOutput(clampRGBOutput) |
74 | , premulOutput(premulOutput) {} |
75 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
76 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
77 | bool onIsEqual(const GrFragmentProcessor&) const override; |
78 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
79 | typedef GrFragmentProcessor INHERITED; |
80 | }; |
81 | #endif |
82 | |