Add CURRENT_FRAME_NUMBER and TOTAL_FRAME_NUMBER properties to the AnimatedImageVisual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch-data.h
1 #ifndef DALI_TOOLKIT_NPATCH_DATA_H
2 #define DALI_TOOLKIT_NPATCH_DATA_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 <string>
22 #include <dali/public-api/rendering/texture-set.h>
23 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
27 #include <dali-toolkit/devel-api/utility/npatch-utilities.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class NPatchData : public Dali::Toolkit::TextureUploadObserver
39 {
40 public:
41   typedef int32_t NPatchDataId;                 ///< The NPatchDataId type. This is used as a handle to refer to a particular Npatch Data.
42   static const int INVALID_NPATCH_DATA_ID = -1; ///< Used to represent a null TextureId or error
43
44   /**
45    * @brief Loading State of the NPatch image.
46    */
47   enum class LoadingState
48   {
49     LOADING = 0,   ///< NPatch is on loading.
50     LOAD_COMPLETE, ///< NPatch loading is completed successfully.
51     LOAD_FAILED    ///< NPatch loading is failed.
52   };
53
54 public:
55
56   /**
57    * Constructor
58    */
59   NPatchData();
60
61   /**
62    * Destructor, non-virtual as not a base class
63    */
64   ~NPatchData();
65
66 public:
67
68   /**
69    * @brief Set cache data id.
70    *
71    * @param [in] id cache data id
72    */
73   void SetId(const NPatchDataId id);
74
75   /**
76    * @brief Retrieve cache data id
77    *
78    * @return cache data id.
79    */
80   NPatchDataId GetId() const;
81
82   /**
83    * @brief Add TextureUploadObserver that uses the image of this cache data.
84    *
85    * @param [in] textureObserver the TextureUploadObserver that uses the image of this cache data.
86    */
87   void AddObserver(TextureUploadObserver* textureObserver);
88
89   /**
90    * @brief Remove TextureUploadObserver.
91    *
92    * @param [in] textureObserver the TextureUploadObserver that will be removed in this cache data.
93    */
94   void RemoveObserver(TextureUploadObserver* textureObserver);
95
96   /**
97    * @brief Retrieve the number of observer.
98    *
99    * @return Return the number of observer.
100    */
101   uint32_t GetObserverCount() const;
102
103   /**
104    * @brief Set NPatch image url.
105    *
106    * @param [in] url NPatch image url
107    */
108   void SetUrl(const std::string url);
109
110   /**
111    * @brief Retrieve the image url.
112    *
113    * @return Return the image url.
114    */
115   std::string GetUrl() const;
116
117   /**
118    * @brief Set texture set on the cache data
119    *
120    * @param [in] textureSet loaded texture set
121    */
122   void SetTextures(const TextureSet textureSet);
123
124   /**
125    * @brief Retrieve loaded texture set.
126    *
127    * @return Return loaded texture set.
128    */
129   TextureSet GetTextures() const;
130
131   /**
132    * @brief Set X directional stretchPixels
133    *
134    * @param [in] stretchPixelsX stretchPixels for X direction
135    */
136   void SetStretchPixelsX(const NPatchUtility::StretchRanges stretchPixelsX);
137
138   /**
139    * @brief Set Y directional stretchPixels
140    *
141    * @param [in] stretchPixelsY stretchPixels for Y direction
142    */
143   void SetStretchPixelsY(const NPatchUtility::StretchRanges stretchPixelsY);
144
145   /**
146    * @brief Retrieve stretchPixels for X direction.
147    *
148    * @return Return stretchPixels for X direction.
149    */
150   NPatchUtility::StretchRanges GetStretchPixelsX() const;
151
152   /**
153    * @brief Retrieve stretchPixels for Y direction.
154    *
155    * @return Return stretchPixels for Y direction.
156    */
157   NPatchUtility::StretchRanges GetStretchPixelsY() const;
158
159   /**
160    * @brief Set cache data hash.
161    *
162    * @param [in] hash cache hash
163    */
164   void SetHash(std::size_t hash);
165
166   /**
167    * @brief Retrieve hash value of the cache.
168    *
169    * @return Return hash value of the cache.
170    */
171   std::size_t GetHash() const;
172
173   /**
174    * @brief Set croppedWidth of NPatch
175    *
176    * @param [in] croppedWidth croppedWidth of NPatch
177    */
178   void SetCroppedWidth(uint32_t croppedWidth);
179
180   /**
181    * @brief Set croppedHeight of NPatch
182    *
183    * @param [in] croppedHeight croppedHeight of NPatch
184    */
185   void SetCroppedHeight(uint32_t croppedHeight);
186
187   /**
188    * @brief Retrieve croppedWidth of NPatch.
189    *
190    * @return Return croppedWidth of NPatch.
191    */
192   uint32_t GetCroppedWidth() const;
193
194   /**
195    * @brief Retrieve croppedHeight of NPatch.
196    *
197    * @return Return croppedHeight of NPatch.
198    */
199   uint32_t GetCroppedHeight() const;
200
201   /**
202    * @brief Set border of NPatch.
203    *
204    * @param [in] border border of NPatch
205    */
206   void SetBorder(const Rect<int> border);
207
208   /**
209    * @brief Retrieve border of NPatch.
210    *
211    * @return Return border of NPatch.
212    */
213   Rect<int> GetBorder() const;
214
215   /**
216    * @brief Set whether the loaded image is premultiplied or not
217    *
218    * @param [in] preMultiplyOnLoad whether the loaded image is premultiplied or not
219    */
220   void SetPreMultiplyOnLoad(bool preMultiplyOnLoad);
221
222   /**
223    * @brief Retrieve whether the loaded image is premultiplied or not.
224    *
225    * @return Return true if the image is premultiplied alpha.
226    */
227   bool IsPreMultiplied() const;
228
229   /**
230    * @brief Set current loading state.
231    *
232    * @param [in] loadingState current loading state
233    */
234   void SetLoadingState(const LoadingState loadingState);
235
236   /**
237    * @brief Retrieve current loading state.
238    *
239    * @return Return current loading state.
240    */
241   LoadingState GetLoadingState() const;
242
243
244   /**
245    * @brief Retrieve NPatch rendering data.
246    *
247    * @return Return NPatch rendering data.
248    */
249   void* GetRenderingMap() const;
250
251   /**
252    * @brief Set loaded pixel buffer for the cache data.
253    *
254    * @param [in] pixelBuffer loaded pixel buffer.
255    * @param [in] preMultiplied whether the loaded image is premultiplied or not
256    */
257   void SetLoadedNPatchData( Devel::PixelBuffer& pixelBuffer, bool preMultiplied );
258
259 private:
260
261   /**
262    * @copydoc TextureUploadObserver::UploadCompleted
263    *
264    * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
265    * This callback is the place to add the renderer as it would be called once the loading is finished.
266    */
267   void UploadComplete( bool loadSuccess, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied ) override {}
268
269   /**
270    * @copydoc TextureUploadObserver::LoadComplete
271    *
272    * To avoid rendering garbage pixels, renderer should be added to actor after the resources are ready.
273    * This callback is the place to add the renderer as it would be called once the loading is finished.
274    */
275   void LoadComplete( bool loadSuccess, Devel::PixelBuffer pixelBuffer, const VisualUrl& url, bool preMultiplied ) override;
276
277
278 private:
279
280   using ObserverListType = Dali::Vector<TextureUploadObserver*>;
281
282   NPatchDataId                 mId;
283   ObserverListType             mObserverList;      ///< Container used to store all observer clients of this Texture
284   std::string                  mUrl;               ///< Url of the N-Patch
285   TextureSet                   mTextureSet;        ///< Texture containing the cropped image
286   NPatchUtility::StretchRanges mStretchPixelsX;    ///< X stretch pixels
287   NPatchUtility::StretchRanges mStretchPixelsY;    ///< Y stretch pixels
288   std::size_t                  mHash;              ///< Hash code for the Url
289   uint32_t                     mCroppedWidth;      ///< Width of the cropped middle part of N-patch
290   uint32_t                     mCroppedHeight;     ///< Height of the cropped middle part of N-patch
291   Rect<int>                    mBorder;            ///< The size of the border
292   LoadingState                 mLoadingState;      ///< True if the data loading is completed
293   bool                         mPreMultiplyOnLoad; ///< Whether to multiply alpha into color channels on load
294   void*                        mRenderingMap;      ///< NPatch rendering data
295 };
296
297 } // namespace Internal
298
299 } // namespace Toolkit
300
301 } // namespace Dali
302
303 #endif // DALI_TOOLKIT_NPATCH_DATA_H