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