1 #ifndef DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H
2 #define DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
24 #include <string_view>
33 * ImageVisualShaderFeature contains feature lists what image visual shader need to know.
35 namespace ImageVisualShaderFeature
37 namespace TextureAtlas
40 * @brief Whether use texture with atlas, or not
44 DISABLED = 0, ///< Image visual doesn't use ATLAS
45 ENABLED ///< Image visual uses ATLAS
47 } // namespace TextureAtlas
49 namespace DefaultTextureWrapMode
52 * @brief Whether apply to texture wraping in default, or not
56 APPLY = 0, ///< Image visual applies to wraping texture in default
57 DO_NOT_APPLY ///< Image visual doesn't apply to wraping texture in default
59 } // namespace DefaultTextureWrapMode
61 namespace RoundedCorner
64 * @brief Whether use rounded corner, or not
68 DISABLED = 0, ///< Image visual doesn't use rounded corner
69 ENABLED ///< Image visual uses rounded corner
71 } // namespace RoundedCorner
76 * @brief Whether use borderline, or not
80 DISABLED = 0, ///< Image visual doesn't use borderline
81 ENABLED ///< Image visual uses borderline
83 } // namespace Borderline
85 namespace ChangeFragmentShader
88 * @brief Whether native image change the default fragment shader, or not
92 DONT_CHANGE = 0, ///< Native image doesn't change default fragment shader.
93 NEED_CHANGE, ///< Native image changes default fragment shader. We need another shader cache.
94 UNDECIDED, ///< Undecided.
96 } // namespace ChangeFragmentShader
98 namespace AlphaMaskingOnRendering
101 * @brief Whether use runtime alpha masking in shader, or not
105 DISABLED = 0, ///< Image visual doesn't use runtime alpha masking
106 ENABLED ///< Image visual uses runtime alpha masking
108 } // namespace AlphaMaskingOnRendering
110 namespace ColorConversion
113 * @brief Whether the color format conversion is needed or not
117 DONT_NEED = 0, ///< Not need to convert
118 YUV_TO_RGB, ///< Need yuv to rgb conversion
119 UNIFIED_YUV_AND_RGB ///< Need to support both yuv conversion case and normal case.
121 } // namespace ColorConversion
124 * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader()
126 struct FeatureBuilder
129 : mTextureAtlas(TextureAtlas::DISABLED),
130 mDefaultTextureWrapMode(DefaultTextureWrapMode::APPLY),
131 mRoundedCorner(RoundedCorner::DISABLED),
132 mBorderline(Borderline::DISABLED),
133 mAlphaMaskingOnRendering(AlphaMaskingOnRendering::DISABLED),
134 mColorConversion(ColorConversion::DONT_NEED),
139 FeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas);
140 FeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode);
141 FeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner);
142 FeatureBuilder& EnableBorderline(bool enableBorderline);
143 FeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture);
144 FeatureBuilder& EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering);
145 FeatureBuilder& EnableYuvToRgb(bool enableYuvToRgb, bool enableUnifiedYuvAndRgb = false);
147 TextureAtlas::Type mTextureAtlas : 2; ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED
148 DefaultTextureWrapMode::Type mDefaultTextureWrapMode : 2; ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY
149 RoundedCorner::Type mRoundedCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
150 Borderline::Type mBorderline : 2; ///< Whether use borderline, or not. default as Borderline::DISABLED
151 AlphaMaskingOnRendering::Type mAlphaMaskingOnRendering : 2; ///< Whether use runtime alpha masking, or not. default as AlphaMaskingOnRendering::DISABLED
152 ColorConversion::Type mColorConversion : 2; ///< Whether the color format conversion is needed or not
153 Dali::Texture mTexture; ///< Texture to check whether we need to change fragment shader or not
156 } // namespace ImageVisualShaderFeature
159 * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
161 class ImageVisualShaderFactory
167 ImageVisualShaderFactory();
172 ~ImageVisualShaderFactory();
175 * @brief Get the standard image rendering shader.
176 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
177 * @param[in] featureBuilder Collection of current image shader's features
178 * @return The standard image rendering shader with features.
180 Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder);
183 * @brief Request the default vertex shader source.
184 * @return The default vertex shader source.
186 std::string_view GetVertexShaderSource();
189 * @brief Request the default fragment shader source.
190 * @return The default fragment shader source.
192 std::string_view GetFragmentShaderSource();
196 * Undefined copy constructor.
198 ImageVisualShaderFactory(const ImageVisualShaderFactory&);
201 * Undefined assignment operator.
203 ImageVisualShaderFactory& operator=(const ImageVisualShaderFactory& rhs);
207 * @brief Cached information whether native image should change fragment shader.
208 * Default it is ChangeFragmentShader::UNDECIDED.
209 * If we have any chance to check native image source apply fragment shader,
210 * this vaule will be changed one of these : ChangeFragmentShader::DONT_CHANGE or ChangeFragmentShader::NEED_CHANGE
212 * After result cached, this value will not be changed.
214 * If value is DONT_CHANGE, ImageVisualShaderFactory::GetShader never call ApplyNativeFragmentShader.
215 * Else, ImageVisualShaderFactory::GetShader will call ApplyNativeFragmentShader if native image source texture come.
217 ImageVisualShaderFeature::ChangeFragmentShader::Type mFragmentShaderNeedChange : 3;
220 } // namespace Internal
222 } // namespace Toolkit
226 #endif // DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H