1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <GLES2/gl2.h>
18 #include "Texture.h"
19 
20 #ifndef SF_RENDER_ENGINE_DESCRIPTION_H_
21 #define SF_RENDER_ENGINE_DESCRIPTION_H_
22 
23 namespace android {
24 
25 class Program;
26 
27 /*
28  * This holds the state of the rendering engine. This class is used
29  * to generate a corresponding GLSL program and set the appropriate
30  * uniform.
31  *
32  * Program and ProgramCache are friends and access the state directly
33  */
34 class Description {
35 public:
36     Description() = default;
37     ~Description() = default;
38 
39     void setPremultipliedAlpha(bool premultipliedAlpha);
40     void setOpaque(bool opaque);
41     void setTexture(const Texture& texture);
42     void disableTexture();
43     void setColor(const half4& color);
44     void setProjectionMatrix(const mat4& mtx);
45     void setSaturationMatrix(const mat4& mtx);
46     void setColorMatrix(const mat4& mtx);
47     void setInputTransformMatrix(const mat3& matrix);
48     void setOutputTransformMatrix(const mat4& matrix);
49     bool hasInputTransformMatrix() const;
50     bool hasOutputTransformMatrix() const;
51     bool hasColorMatrix() const;
52     bool hasSaturationMatrix() const;
53     const mat4& getColorMatrix() const;
54 
55     void setY410BT2020(bool enable);
56 
57     enum class TransferFunction : int {
58         LINEAR,
59         SRGB,
60         ST2084,
61         HLG,  // Hybrid Log-Gamma for HDR.
62     };
63     void setInputTransferFunction(TransferFunction transferFunction);
64     void setOutputTransferFunction(TransferFunction transferFunction);
65     void setDisplayMaxLuminance(const float maxLuminance);
66 
67 private:
68     friend class Program;
69     friend class ProgramCache;
70 
71     // whether textures are premultiplied
72     bool mPremultipliedAlpha = false;
73     // whether this layer is marked as opaque
74     bool mOpaque = true;
75 
76     // Texture this layer uses
77     Texture mTexture;
78     bool mTextureEnabled = false;
79 
80     // color used when texturing is disabled or when setting alpha.
81     half4 mColor;
82 
83     // true if the sampled pixel values are in Y410/BT2020 rather than RGBA
84     bool mY410BT2020 = false;
85 
86     // transfer functions for the input/output
87     TransferFunction mInputTransferFunction = TransferFunction::LINEAR;
88     TransferFunction mOutputTransferFunction = TransferFunction::LINEAR;
89 
90     float mDisplayMaxLuminance;
91 
92     // projection matrix
93     mat4 mProjectionMatrix;
94     mat4 mColorMatrix;
95     mat4 mSaturationMatrix;
96     mat3 mInputTransformMatrix;
97     mat4 mOutputTransformMatrix;
98 };
99 
100 } /* namespace android */
101 
102 #endif /* SF_RENDER_ENGINE_DESCRIPTION_H_ */
103