1 #ifndef DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H
2 #define DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H
5 * Copyright (c) 2022 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
120 } // namespace ColorConversion
123 * @brief Collection of current image visual feature. Only use for ImageVisualShaderFactory::GetShader()
125 struct FeatureBuilder
128 : mTextureAtlas(TextureAtlas::DISABLED),
129 mDefaultTextureWrapMode(DefaultTextureWrapMode::APPLY),
130 mRoundedCorner(RoundedCorner::DISABLED),
131 mBorderline(Borderline::DISABLED),
132 mAlphaMaskingOnRendering(AlphaMaskingOnRendering::DISABLED),
133 mColorConversion(ColorConversion::DONT_NEED),
138 FeatureBuilder& EnableTextureAtlas(bool enableTextureAtlas);
139 FeatureBuilder& ApplyDefaultTextureWrapMode(bool applyDefaultTextureWrapMode);
140 FeatureBuilder& EnableRoundedCorner(bool enableRoundedCorner);
141 FeatureBuilder& EnableBorderline(bool enableBorderline);
142 FeatureBuilder& SetTextureForFragmentShaderCheck(const Dali::Texture& texture);
143 FeatureBuilder& EnableAlphaMaskingOnRendering(bool enableAlphaMaskingOnRendering);
144 FeatureBuilder& EnableYuvToRgb(bool enableYuvToRgb);
146 TextureAtlas::Type mTextureAtlas : 2; ///< Whether use texture with atlas, or not. default as TextureAtlas::DISABLED
147 DefaultTextureWrapMode::Type mDefaultTextureWrapMode : 2; ///< Whether apply to texture wraping in default, or not. default as DefaultTextureWrapMode::APPLY
148 RoundedCorner::Type mRoundedCorner : 2; ///< Whether use rounded corner, or not. default as RoundedCorner::DISABLED
149 Borderline::Type mBorderline : 2; ///< Whether use borderline, or not. default as Borderline::DISABLED
150 AlphaMaskingOnRendering::Type mAlphaMaskingOnRendering : 2; ///< Whether use runtime alpha masking, or not. default as AlphaMaskingOnRendering::DISABLED
151 ColorConversion::Type mColorConversion : 2; ///< Whether the color format conversion is needed or not
152 Dali::Texture mTexture; ///< Texture to check whether we need to change fragment shader or not
155 } // namespace ImageVisualShaderFeature
158 * ImageVisualShaderFactory is an object that provides and shares shaders between image visuals
160 class ImageVisualShaderFactory
166 ImageVisualShaderFactory();
171 ~ImageVisualShaderFactory();
174 * @brief Get the standard image rendering shader.
175 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
176 * @param[in] featureBuilder Collection of current image shader's features
177 * @return The standard image rendering shader with features.
179 Shader GetShader(VisualFactoryCache& factoryCache, const ImageVisualShaderFeature::FeatureBuilder& featureBuilder);
182 * @brief Request the default vertex shader source.
183 * @return The default vertex shader source.
185 std::string_view GetVertexShaderSource();
188 * @brief Request the default fragment shader source.
189 * @return The default fragment shader source.
191 std::string_view GetFragmentShaderSource();
195 * Undefined copy constructor.
197 ImageVisualShaderFactory(const ImageVisualShaderFactory&);
200 * Undefined assignment operator.
202 ImageVisualShaderFactory& operator=(const ImageVisualShaderFactory& rhs);
206 * @brief Cached information whether native image should change fragment shader.
207 * Default it is ChangeFragmentShader::UNDECIDED.
208 * If we have any chance to check native image source apply fragment shader,
209 * this vaule will be changed one of these : ChangeFragmentShader::DONT_CHANGE or ChangeFragmentShader::NEED_CHANGE
211 * After result cached, this value will not be changed.
213 * If value is DONT_CHANGE, ImageVisualShaderFactory::GetShader never call ApplyNativeFragmentShader.
214 * Else, ImageVisualShaderFactory::GetShader will call ApplyNativeFragmentShader if native image source texture come.
216 ImageVisualShaderFeature::ChangeFragmentShader::Type mFragmentShaderNeedChange : 3;
219 } // namespace Internal
221 } // namespace Toolkit
225 #endif // DALI_TOOLKIT_IMAGE_VISUAL_SHADER_FACTORY_H