BufferImage Usage Removal
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-factory-cache.h
1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H
3
4 /*
5  * Copyright (c) 2020 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/math/uint-16-pair.h>
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/rendering/geometry.h>
24 #include <dali/public-api/rendering/shader.h>
25 #include <dali/devel-api/common/owner-container.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/internal/visuals/npatch-loader.h>
29 #include <dali-toolkit/internal/visuals/svg/svg-rasterize-thread.h>
30 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
31 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
32
33 namespace Dali
34 {
35 class Image;
36
37 namespace Toolkit
38 {
39
40 namespace Internal
41 {
42 class ImageAtlasManager;
43 class NPatchLoader;
44 class TextureManager;
45
46 typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
47
48
49 /**
50  * Caches shaders and geometries. Owned by VisualFactory.
51  */
52 class VisualFactoryCache
53 {
54 public:
55
56   /**
57    * Type of shader for caching.
58    */
59   enum ShaderType
60   {
61     COLOR_SHADER,
62     COLOR_SHADER_ROUNDED_CORNER,
63     COLOR_SHADER_BLUR_EDGE,
64     BORDER_SHADER,
65     BORDER_SHADER_ANTI_ALIASING,
66     GRADIENT_SHADER_LINEAR_USER_SPACE,
67     GRADIENT_SHADER_LINEAR_BOUNDING_BOX,
68     GRADIENT_SHADER_RADIAL_USER_SPACE,
69     GRADIENT_SHADER_RADIAL_BOUNDING_BOX,
70     GRADIENT_SHADER_LINEAR_USER_SPACE_ROUNDED_CORNER,
71     GRADIENT_SHADER_LINEAR_BOUNDING_BOX_ROUNDED_CORNER,
72     GRADIENT_SHADER_RADIAL_USER_SPACE_ROUNDED_CORNER,
73     GRADIENT_SHADER_RADIAL_BOUNDING_BOX_ROUNDED_CORNER,
74     IMAGE_SHADER,
75     IMAGE_SHADER_ATLAS_DEFAULT_WRAP,
76     IMAGE_SHADER_ATLAS_CUSTOM_WRAP,
77     IMAGE_SHADER_ROUNDED_CORNER,
78     NINE_PATCH_SHADER,
79     NINE_PATCH_MASK_SHADER,
80     TEXT_SHADER_MULTI_COLOR_TEXT,
81     TEXT_SHADER_MULTI_COLOR_TEXT_WITH_STYLE,
82     TEXT_SHADER_SINGLE_COLOR_TEXT,
83     TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE,
84     TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_EMOJI,
85     TEXT_SHADER_SINGLE_COLOR_TEXT_WITH_STYLE_AND_EMOJI,
86     ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REFLECT,
87     ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_REPEAT,
88     ANIMATED_GRADIENT_SHADER_LINEAR_BOUNDING_CLAMP,
89     ANIMATED_GRADIENT_SHADER_LINEAR_USER_REFLECT,
90     ANIMATED_GRADIENT_SHADER_LINEAR_USER_REPEAT,
91     ANIMATED_GRADIENT_SHADER_LINEAR_USER_CLAMP,
92     ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REFLECT,
93     ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_REPEAT,
94     ANIMATED_GRADIENT_SHADER_RADIAL_BOUNDING_CLAMP,
95     ANIMATED_GRADIENT_SHADER_RADIAL_USER_REFLECT,
96     ANIMATED_GRADIENT_SHADER_RADIAL_USER_REPEAT,
97     ANIMATED_GRADIENT_SHADER_RADIAL_USER_CLAMP,
98     WIREFRAME_SHADER,
99     ARC_BUTT_CAP_SHADER,
100     ARC_ROUND_CAP_SHADER,
101     SHADER_TYPE_MAX = ARC_ROUND_CAP_SHADER
102   };
103
104   /**
105    * Type of geometry for caching.
106    */
107   enum GeometryType
108   {
109     QUAD_GEOMETRY,
110     BORDER_GEOMETRY,
111     NINE_PATCH_GEOMETRY,
112     NINE_PATCH_BORDER_GEOMETRY,
113     WIREFRAME_GEOMETRY,
114     GEOMETRY_TYPE_MAX = WIREFRAME_GEOMETRY
115   };
116
117 public:
118
119   /**
120    * @brief Constructor
121    *
122    * @param[in] preMultiplyOnLoad True if image visuals should pre-multiply alpha on image load.
123    */
124   VisualFactoryCache( bool preMultiplyOnLoad );
125
126   /**
127    * @brief Destructor
128    */
129   ~VisualFactoryCache();
130
131   /**
132    * Request geometry of the given type.
133    * @return The geometry of the required type if it exist in the cache. Otherwise, an empty handle is returned.
134    */
135   Geometry GetGeometry( GeometryType type );
136
137   /**
138    * Cache the geometry of the give type.
139    * @param[in] type The geometry type.
140    * @param[in] geometry The geometry for caching.
141    */
142   void SaveGeometry( GeometryType type, Geometry geometry);
143
144   /**
145    * Request shader of the given type.
146    * @return The shader of the required type if it exist in the cache. Otherwise, an empty handle is returned.
147    */
148   Shader GetShader( ShaderType type );
149
150   /**
151    * Cache the geometry of the give type.
152    * @param[in] type The geometry type.
153    * @param[in] geometry The geometry for caching.
154    */
155   void SaveShader( ShaderType type, Shader shader );
156
157   /*
158    * Greate the quad geometry.
159    * Quad geometry is shared by multiple kind of Renderer, so implement it in the factory-cache.
160    */
161   static Geometry CreateQuadGeometry();
162
163   /**
164    * Create the grid geometry.
165    * @param[in] gridSize The size of the grid.
166    * @return The created grid geometry.
167    */
168   static Geometry CreateGridGeometry( Uint16Pair gridSize );
169
170   /**
171    * @brief Returns an image to be used when a visual has failed to correctly render
172    * @return The broken image handle.
173    */
174   Image GetBrokenVisualImage();
175
176   /**
177    * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
178    */
179   void SetPreMultiplyOnLoad( bool preMultiply );
180
181   /**
182    * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
183    */
184   bool GetPreMultiplyOnLoad();
185
186   /**
187    * @brief Set an image to be used when a visual has failed to correctly render
188    * @param[in] brokenImageUrl The broken image url.
189    */
190   void SetBrokenImageUrl(const std::string& brokenImageUrl);
191
192 public:
193   /**
194    * Get the image atlas manager.
195    * @return A pointer to the atlas manager
196    */
197   ImageAtlasManagerPtr GetAtlasManager();
198
199   /**
200    * Get the texture manager
201    * @return A reference to the texture manager
202    */
203   TextureManager& GetTextureManager();
204
205   /**
206    * Get the N-Patch texture cache.
207    * @return A reference to the N patch loader
208    */
209   NPatchLoader& GetNPatchLoader();
210
211   /**
212    * Get the SVG rasterization thread.
213    * @return A raw pointer pointing to the SVG rasterization thread.
214    */
215   SvgRasterizeThread* GetSVGRasterizationThread();
216
217   /**
218    * Get the vector animation thread.
219    * @return A raw pointer pointing to the vector animation thread.
220    */
221   VectorAnimationThread& GetVectorAnimationThread();
222
223 private: // for svg rasterization thread
224
225   /**
226    * Applies the rasterized image to material
227    */
228   void ApplyRasterizedSVGToSampler();
229
230 protected:
231
232   /**
233    * Undefined copy constructor.
234    */
235   VisualFactoryCache(const VisualFactoryCache&);
236
237   /**
238    * Undefined assignment operator.
239    */
240   VisualFactoryCache& operator=(const VisualFactoryCache& rhs);
241
242 private:
243   Geometry mGeometry[GEOMETRY_TYPE_MAX+1];
244   Shader mShader[SHADER_TYPE_MAX+1];
245
246   ImageAtlasManagerPtr                     mAtlasManager;
247   TextureManager                           mTextureManager;
248   NPatchLoader                             mNPatchLoader;
249   SvgRasterizeThread*                      mSvgRasterizeThread;
250   std::unique_ptr< VectorAnimationThread > mVectorAnimationThread;
251   std::string                              mBrokenImageUrl;
252   bool                                     mPreMultiplyOnLoad;
253 };
254
255 } // namespace Internal
256
257 } // namespace Toolkit
258
259 } // namespace Dali
260
261 #endif // DALI_TOOLKIT_VISUAL_FACTORY_CACHE_H