[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image-visual-shader-feature-builder.h
1 #ifndef DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FEATURE_BUILDER_H
2 #define DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FEATURE_BUILDER_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/rendering/texture.h>
22 #include <dali/devel-api/rendering/texture-devel.h>
23 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
24
25 // INTERNAL INCLUDES
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Internal
32 {
33 /**
34  * ImageVisualShaderFeature contains feature lists what image visual shader need to know.
35  */
36 namespace ImageVisualShaderFeature
37 {
38 namespace TextureAtlas
39 {
40 /**
41  * @brief Whether use texture with atlas, or not
42  */
43 enum Type
44 {
45   DISABLED = 0, ///< Image visual doesn't use ATLAS
46   ENABLED       ///< Image visual uses ATLAS
47 };
48 } // namespace TextureAtlas
49
50 namespace DefaultTextureWrapMode
51 {
52 /**
53  * @brief Whether apply to texture wraping in default, or not
54  */
55 enum Type
56 {
57   APPLY = 0,   ///< Image visual applies to wraping texture in default
58   DO_NOT_APPLY ///< Image visual doesn't apply to wraping texture in default
59 };
60 } // namespace DefaultTextureWrapMode
61
62 namespace RoundedCorner
63 {
64 /**
65  * @brief Whether use rounded corner, or not
66  */
67 enum Type
68 {
69   DISABLED = 0, ///< Image visual doesn't use rounded corner
70   ENABLED       ///< Image visual uses rounded corner
71 };
72 } // namespace RoundedCorner
73
74 namespace Borderline
75 {
76 /**
77  * @brief Whether use borderline, or not
78  */
79 enum Type
80 {
81   DISABLED = 0, ///< Image visual doesn't use borderline
82   ENABLED       ///< Image visual uses borderline
83 };
84 } // namespace Borderline
85
86 namespace ChangeFragmentShader
87 {
88 /**
89  * @brief Whether native image change the default fragment shader, or not
90  */
91 enum Type
92 {
93   DONT_CHANGE = 0, ///< Native image doesn't change default fragment shader.
94   NEED_CHANGE,     ///< Native image changes default fragment shader. We need another shader cache.
95   UNDECIDED,       ///< Undecided.
96 };
97 } // namespace ChangeFragmentShader
98
99 namespace AlphaMaskingOnRendering
100 {
101 /**
102  * @brief Whether use runtime alpha masking in shader, or not
103  */
104 enum Type
105 {
106   DISABLED = 0, ///< Image visual doesn't use runtime alpha masking
107   ENABLED       ///< Image visual uses runtime alpha masking
108 };
109 } // namespace AlphaMaskingOnRendering
110
111 namespace ColorConversion
112 {
113 /**
114  * @brief Whether the color format conversion is needed or not
115  */
116 enum Type
117 {
118   DONT_NEED = 0,      ///< Not need to convert
119   YUV_TO_RGB,         ///< Need yuv to rgb conversion
120   UNIFIED_YUV_AND_RGB ///< Need to support both yuv conversion case and normal case.
121 };
122 } // namespace ColorConversion
123
124 } // namespace ImageVisualShaderFeature
125
126 /**
127  * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader()
128  */
129 class ImageVisualShaderFeatureBuilder
130 {
131 public:
132   ImageVisualShaderFeatureBuilder();
133
134   ImageVisualShaderFeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas);
135
136   ImageVisualShaderFeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode);
137
138   ImageVisualShaderFeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner);
139
140   ImageVisualShaderFeatureBuilder& EnableBorderline(bool enableBorderline);
141
142   ImageVisualShaderFeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture);
143
144   ImageVisualShaderFeatureBuilder& EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering);
145
146   ImageVisualShaderFeatureBuilder& EnableYuvToRgb(bool enableYuvToRgb, bool enableUnifiedYuvAndRgb = false);
147
148   VisualFactoryCache::ShaderType GetShaderType();
149
150   ImageVisualShaderFeature::ChangeFragmentShader::Type NeedToChangeFragmentShader();
151
152   void GetVertexShaderPrefixList(std::string& vertexShaderPrefixList);
153   void GetFragmentShaderPrefixList(std::string& fragmentShaderPrefixList);
154
155   Dali::Texture GetTexture();
156
157   bool IsEnabledAlphaMaskingOnRendering() const;
158
159 private:
160   ImageVisualShaderFeature::TextureAtlas::Type            mTextureAtlas : 2;            ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED
161   ImageVisualShaderFeature::DefaultTextureWrapMode::Type  mDefaultTextureWrapMode : 2;  ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY
162   ImageVisualShaderFeature::RoundedCorner::Type           mRoundedCorner : 2;           ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
163   ImageVisualShaderFeature::Borderline::Type              mBorderline : 2;              ///< Whether use borderline, or not. default as Borderline::DISABLED
164   ImageVisualShaderFeature::AlphaMaskingOnRendering::Type mAlphaMaskingOnRendering : 2; ///< Whether use runtime alpha masking, or not. default as AlphaMaskingOnRendering::DISABLED
165   ImageVisualShaderFeature::ColorConversion::Type         mColorConversion : 2;         ///< Whether the color format conversion is needed or not
166   Dali::Texture                                           mTexture;                     ///< Texture to check whether we need to change fragment shader or not
167 };
168
169 } // namespace Internal
170
171 } // namespace Toolkit
172
173 } // namespace Dali
174
175 #endif // DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H