[dali_2.3.41] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-factory.h
1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_H
3
4 /*
5  * Copyright (c) 2024 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
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/images/image-operations.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/object/property-map.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
28
29 namespace Dali
30 {
31 class Image;
32 struct Vector4;
33
34 namespace Toolkit
35 {
36 namespace Internal DALI_INTERNAL
37 {
38 class VisualFactory;
39 }
40
41 /**
42  * @brief VisualFactory is a singleton object that provides and shares visuals between controls
43  *
44  * By setting environment variable 'DALI_DEBUG_RENDERING', a debug visual is used which renders a quad wireframe.
45  *
46  * The visual type is required in the property map for requesting a visual.
47  *
48  * | %Property Name           | Type              |
49  * |--------------------------|-------------------|
50  * | visualType               | INTEGER or STRING |
51  * | shader                   | MAP               |
52  */
53 class DALI_TOOLKIT_API VisualFactory : public BaseHandle
54 {
55 public:
56   enum CreationOptions
57   {
58     NONE = 0,
59
60     IMAGE_VISUAL_LOAD_STATIC_IMAGES_ONLY = 1 << 0, ///< Load static images only when we use the image visual.
61   };
62
63   /**
64    * @brief Create or retrieve VisualFactory singleton.
65    *
66    * @return A handle to the VisualFactory control.
67    */
68   static VisualFactory Get();
69
70   /**
71    * @brief Create a VisualFactory handle.
72    *
73    * Calling member functions with an uninitialised handle is not allowed.
74    */
75   VisualFactory();
76
77   /**
78    * @brief Destructor
79    *
80    * This is non-virtual since derived Handle types must not contain data or virtual methods.
81    */
82   ~VisualFactory();
83
84   /**
85    * @brief This copy constructor is required for (smart) pointer semantics.
86    *
87    * @param[in] handle A reference to the copied handle.
88    */
89   VisualFactory(const VisualFactory& handle);
90
91   /**
92    * @brief This assignment operator is required for (smart) pointer semantics.
93    *
94    * @param [in] handle  A reference to the copied handle.
95    * @return A reference to this.
96    */
97   VisualFactory& operator=(const VisualFactory& handle);
98
99   /**
100    * @brief Request the visual
101    *
102    * @param[in] propertyMap The map contains the properties required by the visual.
103    *            The content of the map determines the type of visual that will be returned.
104    * @return The handle to the created visual
105    */
106   Visual::Base CreateVisual(const Property::Map& propertyMap);
107
108   /**
109    * @brief Request the visual with some options
110    *
111    * @param[in] propertyMap The map contains the properties required by the visual.
112    *            The content of the map determines the type of visual that will be returned.
113    * @param[in] creationOptions The creation option.
114    * @return The handle to the created visual
115    */
116   Visual::Base CreateVisual(const Property::Map& propertyMap, CreationOptions creationOptions);
117
118   /**
119    * @brief Request the visual to render the given resource at the url.
120    *
121    * @param[in] url The URL to the resource to be rendered.
122    * @param[in] size The width and height to fit the loaded image to.
123    * @return The pointer pointing to the visual
124    */
125   Visual::Base CreateVisual(const std::string& url, ImageDimensions size);
126
127   /**
128    * @brief Request the visual to render the given resource at the url with some options.
129    *
130    * @param[in] url The URL to the resource to be rendered.
131    * @param[in] size The width and height to fit the loaded image to.
132    * @param[in] creationOptions The creation option.
133    * @return The pointer pointing to the visual
134    */
135   Visual::Base CreateVisual(const std::string& url, ImageDimensions size, CreationOptions creationOptions);
136
137   /**
138    * @brief Enable or disable premultiplying alpha in images and image visuals.
139    *
140    * The default is to enable pre-multiplication on load.
141    *
142    * Applications that have assets with pre-multiplied alpha already applied should turn this option off.
143    *
144    * @param[in] preMultiply True if loaded images for image visuals should have alpha multiplied into the color
145    * channels.
146    */
147   void SetPreMultiplyOnLoad(bool preMultiply);
148
149   /**
150    * @brief Get the setting for automatically pre-multiplying image visual images on load.
151    *
152    * @return True if loaded images have pre-multiplied alpha applied on load, false otherwise.
153    */
154   bool GetPreMultiplyOnLoad() const;
155
156   /**
157    * @brief Set the default creation options when we skip the creation options parameter.
158    *
159    * @param[in] creationOptions The default creation options for the visual factory.
160    */
161   void SetDefaultCreationOptions(CreationOptions creationOptions);
162
163   /**
164    * @brief Set the default creation options when we skip the creation options parameter.
165    *
166    * @return The default creation options for the visual factory.
167    */
168   CreationOptions GetDefaultCreationOptions() const;
169
170   /**
171    * @brief Discard visual base. It will keep reference of visual until idle callback called.
172    *
173    * @param[in] visual Discarded visual base.
174    */
175   void DiscardVisual(Visual::Base visual);
176
177   /**
178    * @brief Compile the visual shader in advance. Afterwards,
179    * when a visual using a new shader is requested, the pre-compiled shader is used.
180    *
181    * @note It is recommended that this method be called at the top of the application code.
182    * @note Using precompiled shaders is helpful when the application is complex and uses
183    * many different styles of visual options. On the other hand,if most visuals are the same
184    * and the application is simple, it may use memory unnecessarily or slow down the application launching speed.
185    */
186   void UsePreCompiledShader();
187
188 private:
189   explicit DALI_INTERNAL VisualFactory(Internal::VisualFactory* impl);
190 };
191
192 } // namespace Toolkit
193
194 } // namespace Dali
195
196 #endif // DALI_TOOLKIT_VISUAL_FACTORY_H