1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_CACHE_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.
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/integration-api/shader-precompiler.h>
23 #include <dali/public-api/math/uint-16-pair.h>
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/rendering/geometry.h>
26 #include <dali/public-api/rendering/shader.h>
29 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
30 #include <dali-toolkit/internal/visuals/npatch-loader.h>
31 #include <dali/devel-api/rendering/renderer-devel.h>
41 class ImageAtlasManager;
44 class VectorAnimationManager;
46 typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
49 * Caches shaders and geometries. Owned by VisualFactory.
51 class VisualFactoryCache
55 * Type of shader for caching.
60 COLOR_SHADER_ROUNDED_CORNER,
61 COLOR_SHADER_BORDERLINE,
62 COLOR_SHADER_ROUNDED_BORDERLINE,
63 COLOR_SHADER_BLUR_EDGE,
64 COLOR_SHADER_ROUNDED_CORNER_BLUR_EDGE,
66 BORDER_SHADER_ANTI_ALIASING,
67 GRADIENT_SHADER_LINEAR_BOUNDING_BOX,
68 GRADIENT_SHADER_LINEAR_BOUNDING_BOX_ROUNDED_CORNER,
69 GRADIENT_SHADER_LINEAR_BOUNDING_BOX_BORDERLINE,
70 GRADIENT_SHADER_LINEAR_BOUNDING_BOX_ROUNDED_BORDERLINE,
71 GRADIENT_SHADER_LINEAR_USER_SPACE,
72 GRADIENT_SHADER_LINEAR_USER_SPACE_ROUNDED_CORNER,
73 GRADIENT_SHADER_LINEAR_USER_SPACE_BORDERLINE,
74 GRADIENT_SHADER_LINEAR_USER_SPACE_ROUNDED_BORDERLINE,
75 GRADIENT_SHADER_RADIAL_BOUNDING_BOX,
76 GRADIENT_SHADER_RADIAL_BOUNDING_BOX_ROUNDED_CORNER,
77 GRADIENT_SHADER_RADIAL_BOUNDING_BOX_BORDERLINE,
78 GRADIENT_SHADER_RADIAL_BOUNDING_BOX_ROUNDED_BORDERLINE,
79 GRADIENT_SHADER_RADIAL_USER_SPACE,
80 GRADIENT_SHADER_RADIAL_USER_SPACE_ROUNDED_CORNER,
81 GRADIENT_SHADER_RADIAL_USER_SPACE_BORDERLINE,
82 GRADIENT_SHADER_RADIAL_USER_SPACE_ROUNDED_BORDERLINE,
84 IMAGE_SHADER_ROUNDED_CORNER,
85 IMAGE_SHADER_BORDERLINE,
86 IMAGE_SHADER_ROUNDED_BORDERLINE,
88 IMAGE_SHADER_ROUNDED_CORNER_MASKING,
89 IMAGE_SHADER_BORDERLINE_MASKING,
90 IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING,
91 IMAGE_SHADER_ATLAS_DEFAULT_WRAP,
92 IMAGE_SHADER_ATLAS_CUSTOM_WRAP,
93 IMAGE_SHADER_YUV_TO_RGB,
94 IMAGE_SHADER_ROUNDED_CORNER_YUV_TO_RGB,
95 IMAGE_SHADER_BORDERLINE_YUV_TO_RGB,
96 IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_TO_RGB,
97 IMAGE_SHADER_YUV_AND_RGB,
98 IMAGE_SHADER_ROUNDED_CORNER_YUV_AND_RGB,
99 IMAGE_SHADER_BORDERLINE_YUV_AND_RGB,
100 IMAGE_SHADER_ROUNDED_BORDERLINE_YUV_AND_RGB,
102 NATIVE_IMAGE_SHADER_ROUNDED_CORNER,
103 NATIVE_IMAGE_SHADER_BORDERLINE,
104 NATIVE_IMAGE_SHADER_ROUNDED_BORDERLINE,
105 NATIVE_IMAGE_SHADER_MASKING,
106 NATIVE_IMAGE_SHADER_ROUNDED_CORNER_MASKING,
107 NATIVE_IMAGE_SHADER_BORDERLINE_MASKING,
108 NATIVE_IMAGE_SHADER_ROUNDED_BORDERLINE_MASKING,
110 NINE_PATCH_MASK_SHADER,
111 TEXT_SHADER_SINGLE_COLOR_TEXT,
112 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE,
113 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_OVERLAY,
114 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_OVERLAY,
115 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI,
116 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI,
117 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_OVERLAY_AND_EMOJI,
118 TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_OVERLAY_AND_EMOJI,
119 TEXT_SHADER_MULTI_COLOR_TEXT,
120 TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE,
121 TEXT_SHADER_MULTI_COLOR_TEXT_WITH_OVERLAY,
122 TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE_AND_OVERLAY,
123 ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REFLECT,
124 ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REPEAT,
125 ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_CLAMP,
126 ANIMATED_GRADIENT_SHADER_LINEAR_USER_REFLECT,
127 ANIMATED_GRADIENT_SHADER_LINEAR_USER_REPEAT,
128 ANIMATED_GRADIENT_SHADER_LINEAR_USER_CLAMP,
129 ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REFLECT,
130 ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REPEAT,
131 ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_CLAMP,
132 ANIMATED_GRADIENT_SHADER_RADIAL_USER_REFLECT,
133 ANIMATED_GRADIENT_SHADER_RADIAL_USER_REPEAT,
134 ANIMATED_GRADIENT_SHADER_RADIAL_USER_CLAMP,
137 ARC_ROUND_CAP_SHADER,
138 SHADER_TYPE_MAX = ARC_ROUND_CAP_SHADER
142 * Type of geometry for caching.
149 NINE_PATCH_BORDER_GEOMETRY,
151 GEOMETRY_TYPE_MAX = WIREFRAME_GEOMETRY
158 * @param[in] preMultiplyOnLoad True if image visuals should pre-multiply alpha on image load.
160 VisualFactoryCache(bool preMultiplyOnLoad);
165 ~VisualFactoryCache();
168 * Request geometry of the given type.
169 * @return The geometry of the required type if it exist in the cache. Otherwise, an empty handle is returned.
171 Geometry GetGeometry(GeometryType type);
174 * Cache the geometry of the give type.
175 * @param[in] type The geometry type.
176 * @param[in] geometry The geometry for caching.
178 void SaveGeometry(GeometryType type, Geometry geometry);
181 * Request shader of the given type.
182 * @return The shader of the required type if it exist in the cache. Otherwise, an empty handle is returned.
184 Shader GetShader(ShaderType type);
187 * Cache the geometry of the give type.
188 * @param[in] type The geometry type.
189 * @param[in] geometry The geometry for caching.
191 void SaveShader(ShaderType type, Shader shader);
194 * Greate the quad geometry.
195 * Quad geometry is shared by multiple kind of Renderer, so implement it in the factory-cache.
197 static Geometry CreateQuadGeometry();
200 * Create the grid geometry.
201 * @param[in] gridSize The size of the grid.
202 * @return The created grid geometry.
204 static Geometry CreateGridGeometry(Uint16Pair gridSize);
207 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
209 void SetPreMultiplyOnLoad(bool preMultiply);
212 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
214 bool GetPreMultiplyOnLoad() const;
217 * @brief Set an image to be used when a visual has failed to correctly render
218 * @param[in] brokenImageUrlList The broken image url list
220 void SetBrokenImageUrl(std::string& defaultBrokenUrl, const std::vector<std::string>& brokenImageUrlList);
223 * @brief Update the broken image Renderer object
224 * @param[in,out] renderer renderer for broken image
225 * @param[in] size the size of actor
226 * @param[in] rendererIsImage True if input renderer use image shader already.
227 * If true, we don't need to create new renderer when broken image is single image.
228 * Most of user experience use normal images. So It can reduce runtime.
230 void UpdateBrokenImageRenderer(Renderer& renderer, const Vector2& size, const bool& rendererIsImage = true);
233 * @brief Get whether we support YUV Planes load or not.
235 * @return True if we support to load YUV Planes. False otherwise.
237 bool GetLoadYuvPlanes() const;
241 * Get the image atlas manager.
242 * @return A pointer to the atlas manager
244 ImageAtlasManagerPtr GetAtlasManager();
247 * Get the texture manager
248 * @return A reference to the texture manager
250 TextureManager& GetTextureManager();
253 * Get the N-Patch texture cache.
254 * @return A reference to the N patch loader
256 NPatchLoader& GetNPatchLoader();
259 * Get the vector animation manager.
260 * @return A reference to the vector animation manager.
262 VectorAnimationManager& GetVectorAnimationManager();
266 * Undefined copy constructor.
268 VisualFactoryCache(const VisualFactoryCache&);
271 * Undefined assignment operator.
273 VisualFactoryCache& operator=(const VisualFactoryCache& rhs);
277 * @brief Returns a cached Texture to use when a visual has failed to correctly render
278 * @param[in] brokenIndex The index of broken image
280 * @return The broken image texture.
282 Texture GetBrokenVisualImage(uint32_t brokenIndex);
285 * @brief Gets the Proper broken image index
286 * @param[in] size The size of actor
288 * @return The index of broken image
290 int32_t GetProperBrokenImageIndex(const Vector2& size);
293 * @brief Apply a texture and uniforms
295 * @param[in,out] renderer The renderer for broken image
296 * @param[in] index The index of broken image
298 void ApplyTextureAndUniforms(Renderer& renderer, int index);
301 * @brief Gets a geometry for npatch image
303 * @param[in] index the index of broken image
304 * @return The Geometry for NPatch
306 Geometry GetNPatchGeometry(int index);
309 * @brief Gets the Npatch Shader object
311 * @param[in] index The index of broken image
312 * @return The Shader for NPatch
314 Shader GetNPatchShader(int index);
317 * @brief Returns a broken image type
318 * @param[in] index BrokenImage index
319 * @return The broken image type.
321 VisualUrl::Type GetBrokenImageVisualType(int index);
324 struct BrokenImageInfo
329 npatchId(NPatchData::INVALID_NPATCH_DATA_ID),
341 VisualUrl::Type visualType;
343 NPatchData::NPatchDataId npatchId;
349 Geometry mGeometry[GEOMETRY_TYPE_MAX + 1];
350 Shader mShader[SHADER_TYPE_MAX + 1];
352 bool mLoadYuvPlanes; ///< A global flag to specify if the image should be loaded as yuv planes
354 ImageAtlasManagerPtr mAtlasManager;
355 TextureManager mTextureManager;
356 NPatchLoader mNPatchLoader;
358 std::unique_ptr<VectorAnimationManager> mVectorAnimationManager;
359 bool mPreMultiplyOnLoad;
360 std::vector<BrokenImageInfo> mBrokenImageInfoContainer;
361 std::string mDefaultBrokenImageUrl;
362 bool mUseDefaultBrokenImageOnly;
365 } // namespace Internal
367 } // namespace Toolkit
371 #endif // DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H