DALi Version 2.2.11
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / texture-manager / texture-manager-impl.h
1 #ifndef DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
2 #define DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
3
4 /*
5  * Copyright (c) 2022 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/adaptor-framework/animated-image-loading.h>
22 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
23 #include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
24 #include <dali/public-api/adaptor-framework/round-robin-container-view.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/rendering/geometry.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
30 #include <dali-toolkit/internal/texture-manager/texture-cache-manager.h>
31 #include <dali-toolkit/internal/texture-manager/texture-manager-type.h>
32 #include <dali-toolkit/internal/texture-manager/texture-upload-observer.h>
33 #include <dali-toolkit/internal/visuals/visual-url.h>
34
35 namespace Dali
36 {
37 namespace Toolkit
38 {
39 namespace Internal
40 {
41 class ImageAtlasManager;
42 typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
43 class TextureAsyncLoadingHelper;
44
45 /**
46  * The TextureManager provides a common Image loading API for Visuals.
47  *
48  * The TextureManager is responsible for providing sync, async, atlased and non-atlased
49  * CPU time alpha masking, animated image loads.
50  *
51  * Texture caching is provided and performed by TextureCacheManager.
52  * TextureUploadObserver.LoadComplete called when async load completed.
53  */
54 class TextureManager : public ConnectionTracker
55 {
56 public:
57   // Copy enum and types and const values that TextureManager will use.
58   using TextureId         = TextureManagerType::TextureId;
59   using TextureCacheIndex = TextureManagerType::TextureCacheIndex;
60   using TextureHash       = TextureManagerType::TextureHash;
61
62   static constexpr TextureId         INVALID_TEXTURE_ID  = TextureManagerType::INVALID_TEXTURE_ID;
63   static constexpr TextureCacheIndex INVALID_CACHE_INDEX = TextureManagerType::INVALID_CACHE_INDEX;
64
65   using UseAtlas       = TextureManagerType::UseAtlas;
66   using StorageType    = TextureManagerType::StorageType;
67   using LoadType       = TextureManagerType::LoadType;
68   using LoadState      = TextureManagerType::LoadState;
69   using ReloadPolicy   = TextureManagerType::ReloadPolicy;
70   using MultiplyOnLoad = TextureManagerType::MultiplyOnLoad;
71   using TextureInfo    = TextureManagerType::TextureInfo;
72
73 public:
74   struct MaskingData
75   {
76     MaskingData();
77     ~MaskingData() = default;
78
79     VisualUrl                 mAlphaMaskUrl;
80     TextureManager::TextureId mAlphaMaskId;
81     float                     mContentScaleFactor;
82     bool                      mCropToMask;
83     bool                      mPreappliedMasking;
84     bool                      mMaskImageLoadingFailed;
85   };
86   using MaskingDataPointer = std::unique_ptr<MaskingData>;
87
88   /**
89    * Class to provide lifecycle event on destruction of texture manager.
90    */
91   struct LifecycleObserver
92   {
93     /**
94      * Called shortly before the texture manager is destroyed.
95      */
96     virtual void TextureManagerDestroyed() = 0;
97   };
98
99   /**
100    * Constructor.
101    */
102   TextureManager();
103
104   /**
105    * Destructor.
106    */
107   ~TextureManager() override;
108
109   // TextureManager Main API:
110
111   /**
112    * @brief Requests an frame of animated image load.
113    *
114    * The parameters are used to specify how the animated image is loaded.
115    * The observer has the LoadComplete method called when the load is ready.
116    *
117    * @param[in]  url                   The URL of the image to load
118    * @param[in]  animatedImageLoading  The AnimatedImageLoading that contain the animated image information
119    * @param[in]  frameIndex            The frame index to load.
120    * @param[out] textureId             The textureId of the frame
121    * @param[in, out] maskInfo          Mask info structure
122    * @param[in]  desiredSize           The size the image is likely to appear at. This can be set to 0, 0 for automatic
123    * @param[in]  fittingMode           The FittingMode to use
124    * @param[in]  samplingMode          The SamplingMode to use
125    * @param[in]  synchronousLoading    true if the frame should be loaded synchronously
126    * @param[in]  textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
127    *                                   This is called when an image load completes (or fails).
128    * @param[in,out] preMultiplyOnLoad  True if the image color should be multiplied by it's alpha. Set to false if the
129    *                                   image has no alpha channel
130    *
131    * @return                           The texture set containing the frame of animated image, or empty if still loading.
132    */
133   TextureSet LoadAnimatedImageTexture(const VisualUrl&                url,
134                                       Dali::AnimatedImageLoading      animatedImageLoading,
135                                       const uint32_t&                 frameIndex,
136                                       TextureManager::TextureId&      textureId,
137                                       MaskingDataPointer&             maskInfo,
138                                       const Dali::ImageDimensions&    desiredSize,
139                                       const Dali::FittingMode::Type&  fittingMode,
140                                       const Dali::SamplingMode::Type& samplingMode,
141                                       const bool&                     synchronousLoading,
142                                       TextureUploadObserver*          textureObserver,
143                                       TextureManager::MultiplyOnLoad& preMultiplyOnLoad);
144
145   /**
146    * @brief Requests an image load of the given URL to get PixelBuffer.
147    *
148    * The parameters are used to specify how the image is loaded.
149    * The observer has the LoadComplete method called when the load is ready.
150    *
151    * @param[in] url                   The URL of the image to load
152    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
153    * @param[in] fittingMode           The FittingMode to use
154    * @param[in] samplingMode          The SamplingMode to use
155    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
156    * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
157    *                                  This is called when an image load completes (or fails).
158    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
159    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
160    *                                  image has no alpha channel
161    *
162    * @return                          The pixel buffer containing the image, or empty if still loading.
163    */
164   Devel::PixelBuffer LoadPixelBuffer(
165     const VisualUrl&                url,
166     const Dali::ImageDimensions&    desiredSize,
167     const Dali::FittingMode::Type&  fittingMode,
168     const Dali::SamplingMode::Type& samplingMode,
169     const bool&                     synchronousLoading,
170     TextureUploadObserver*          textureObserver,
171     const bool&                     orientationCorrection,
172     TextureManager::MultiplyOnLoad& preMultiplyOnLoad);
173
174   /**
175    * @brief Requests an image load of the given URL.
176    *
177    * The parameters are used to specify how the image is loaded.
178    * The observer has the LoadComplete method called when the load is ready.
179    *
180    * When the client has finished with the Texture, Remove() should be called.
181    *
182    * @param[in] url                   The URL of the image to load
183    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
184    * @param[in] fittingMode           The FittingMode to use
185    * @param[in] samplingMode          The SamplingMode to use
186    * @param[in, out] maskInfo         Mask info structure
187    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
188    * @param[out] textureId,           The textureId of the URL
189    * @param[out] textureRect          The rectangle within the texture atlas that this URL occupies,
190    *                                  this is the rectangle in normalized coordinates.
191    * @param[out] textureRectSize      The rectangle within the texture atlas that this URL occupies,
192    *                                  this is the same rectangle in pixels.
193    * @param[in,out] atlasingStatus    Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
194    *                                  be loaded, and marked successful, but this will be set to false.
195    *                                  If atlasing succeeds, this will be set to true.
196    * @param[out] loadingStatus        The loading status of the texture
197    * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
198    *                                  This is called when an image load completes (or fails).
199    * @param[in] atlasObserver         This is used if the texture is atlased, and will be called instead of
200    *                                  textureObserver.LoadCompleted
201    * @param[in] imageAtlasManager     The atlas manager to use for atlasing textures
202    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
203    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
204    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
205    *                                  image has no alpha channel
206    *
207    * @return                          The texture set containing the image, or empty if still loading.
208    */
209   TextureSet LoadTexture(
210     const VisualUrl&                    url,
211     const Dali::ImageDimensions&        desiredSize,
212     const Dali::FittingMode::Type&      fittingMode,
213     const Dali::SamplingMode::Type&     samplingMode,
214     MaskingDataPointer&                 maskInfo,
215     const bool&                         synchronousLoading,
216     TextureManager::TextureId&          textureId,
217     Dali::Vector4&                      textureRect,
218     Dali::ImageDimensions&              textureRectSize,
219     bool&                               atlasingStatus,
220     bool&                               loadingStatus,
221     TextureUploadObserver*              textureObserver,
222     AtlasUploadObserver*                atlasObserver,
223     ImageAtlasManagerPtr                imageAtlasManager,
224     const bool&                         orientationCorrection,
225     const TextureManager::ReloadPolicy& reloadPolicy,
226     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad);
227
228   /**
229    * @brief Remove a Texture from the TextureManager.
230    *
231    * Textures are cached and therefore only the removal of the last
232    * occurrence of a Texture will cause its removal internally.
233    *
234    * @param[in] textureId The ID of the Texture to remove.
235    * @param[in] textureObserver The texture observer.
236    */
237   void Remove(const TextureManager::TextureId& textureId, TextureUploadObserver* textureObserver);
238
239   /**
240    * Add an observer to the object.
241    * @param[in] observer The observer to add.
242    */
243   void AddObserver(TextureManager::LifecycleObserver& observer);
244
245   /**
246    * Remove an observer from the object
247    * @pre The observer has already been added.
248    * @param[in] observer The observer to remove.
249    */
250   void RemoveObserver(TextureManager::LifecycleObserver& observer);
251
252   /**
253    * @brief Returns the geometry associated with texture.
254    * @param[in] textureId Id of the texture
255    * @param[out] frontElements number of front elements
256    * @param[out] backElements number of back elements
257    * @return Returns valid geometry object
258    */
259   Geometry GetRenderGeometry(const TextureManager::TextureId& textureId, std::uint32_t& frontElements, std::uint32_t& backElements);
260
261   /**
262    * @brief Returns the textureSet in texture manager.
263    * @param[in] textureId Id of the texture
264    * @return The textureSet in texture manager. These textures include YUV textures or images and masks.
265    */
266   TextureSet GetTextureSet(const TextureManager::TextureId& textureId);
267
268   /**
269    * @brief Returns the textureSet in texture manager.
270    * @param[in] textureInfo the information of the texture
271    * @return The textureSet in texture manager. These textures include YUV textures or images and masks.
272    */
273   TextureSet GetTextureSet(const TextureManager::TextureInfo& textureInfo);
274
275 public:
276   // API list that need to access TextureCacheManager.
277
278   /**
279    * @copydoc TextureCacheManager::GetVisualUrl
280    */
281   inline VisualUrl GetVisualUrl(const TextureManager::TextureId& textureId)
282   {
283     return mTextureCacheManager.GetVisualUrl(textureId);
284   }
285
286   /**
287    * @copydoc TextureCacheManager::GetTexture
288    */
289   inline Texture GetTexture(const TextureManager::TextureId& textureId)
290   {
291     return mTextureCacheManager.GetTexture(textureId);
292   }
293
294   /**
295    * @copydoc TextureCacheManager::RemoveExternalTexture
296    */
297   inline TextureSet RemoveExternalTexture(const std::string& url)
298   {
299     return mTextureCacheManager.RemoveExternalTexture(url);
300   }
301
302   /**
303    * @copydoc TextureCacheManager::RemoveEncodedImageBuffer
304    */
305   inline EncodedImageBuffer RemoveEncodedImageBuffer(const std::string& url)
306   {
307     return mTextureCacheManager.RemoveEncodedImageBuffer(url);
308   }
309
310   /**
311    * @copydoc TextureCacheManager::UseExternalResource
312    */
313   inline void UseExternalResource(const VisualUrl& url)
314   {
315     mTextureCacheManager.UseExternalResource(url);
316   }
317
318   /**
319    * @copydoc TextureCacheManager::GetEncodedImageBuffer
320    */
321   inline EncodedImageBuffer GetEncodedImageBuffer(const std::string& url)
322   {
323     return mTextureCacheManager.GetEncodedImageBuffer(url);
324   }
325
326   /**
327    * @copydoc TextureCacheManager::AddExternalTexture
328    */
329   inline std::string AddExternalTexture(const TextureSet& texture)
330   {
331     return mTextureCacheManager.AddExternalTexture(texture);
332   }
333
334   /**
335    * @copydoc TextureCacheManager::AddEncodedImageBuffer
336    */
337   inline std::string AddEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer)
338   {
339     return mTextureCacheManager.AddEncodedImageBuffer(encodedImageBuffer);
340   }
341
342 public: // Load Request API
343   /**
344    * @brief Requests an image load of the given URL.
345    *
346    * The parameters are used to specify how the image is loaded.
347    * The observer has the LoadComplete method called when the load is ready.
348    *
349    * When the client has finished with the Texture, Remove() should be called.
350    *
351    * @param[in] url                   The URL of the image to load
352    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
353    * @param[in] fittingMode           The FittingMode to use
354    * @param[in] samplingMode          The SamplingMode to use
355    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be loaded, and marked successful,
356    *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from the TextureManagerUploadObserver.
357    * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted" virtual.
358    *                                  This is called when an image load completes (or fails).
359    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
360    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
361    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the image has no alpha channel
362    * @param[in] synchronousLoading    True if the frame should be loaded synchronously. If you skip this parameter,
363    *                                  default is false.
364    * @return                          A TextureId to use as a handle to reference this Texture
365    */
366   TextureId RequestLoad(
367     const VisualUrl&                    url,
368     const ImageDimensions&              desiredSize,
369     const Dali::FittingMode::Type&      fittingMode,
370     const Dali::SamplingMode::Type&     samplingMode,
371     const TextureManager::UseAtlas&     useAtlasing,
372     TextureUploadObserver*              observer,
373     const bool&                         orientationCorrection,
374     const TextureManager::ReloadPolicy& reloadPolicy,
375     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
376     const bool&                         synchronousLoading = false);
377
378   /**
379    * @brief Requests an image load of the given URL, when the texture has
380    * have loaded, it will perform a blend with the image mask, and upload
381    * the blended texture.
382    *
383    * The parameters are used to specify how the image is loaded.
384    * The observer has the LoadComplete method called when the load is ready.
385    *
386    * When the client has finished with the Texture, Remove() should be called.
387    *
388    * @param[in] url                   The URL of the image to load
389    * @param[in] maskTextureId         The texture id of an image to mask this with
390    *                                  (can be INVALID if no masking required)
391    * @param[in] contentScale          The scale factor to apply to the image before masking
392    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
393    * @param[in] fittingMode           The FittingMode to use
394    * @param[in] samplingMode          The SamplingMode to use
395    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
396    *                                  be loaded, and marked successful,
397    *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from
398    *                                  the TextureManagerUploadObserver.
399    * @param[in] cropToMask            Only used with masking, this will crop the scaled image to the mask size.
400    *                                  If false, then the mask will be scaled to fit the image before being applied.
401    * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
402    *                                  virtual.
403    *                                  This is called when an image load completes (or fails).
404    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
405    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
406    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
407    *                                  image has no alpha channel
408    * @param[in] synchronousLoading    True if the frame should be loaded synchronously. If you skip this parameter,
409    *                                  default is false.
410    * @return                          A TextureId to use as a handle to reference this Texture
411    */
412   TextureId RequestLoad(
413     const VisualUrl&                    url,
414     const TextureManager::TextureId&    maskTextureId,
415     const float&                        contentScale,
416     const ImageDimensions&              desiredSize,
417     const Dali::FittingMode::Type&      fittingMode,
418     const Dali::SamplingMode::Type&     samplingMode,
419     const TextureManager::UseAtlas&     useAtlasing,
420     const bool&                         cropToMask,
421     TextureUploadObserver*              observer,
422     const bool&                         orientationCorrection,
423     const TextureManager::ReloadPolicy& reloadPolicy,
424     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
425     const bool&                         synchronousLoading = false);
426
427   /**
428    * @brief Requests a masking image to be loaded. This mask is not uploaded to GL,
429    * instead, it is stored in CPU memory, and can be used for CPU blending.
430    * @param[in] maskUrl            The URL of the mask image to load
431    * @param[in] storageType,       Whether the pixel data is stored in the cache or uploaded to the GPU
432    * @param[in] synchronousLoading True if the frame should be loaded synchronously. If you skip this parameter,
433    *                               default is false.
434    * @return                       A TextureId to use as a handle to reference this mask Texture
435    */
436   TextureId RequestMaskLoad(
437     const VisualUrl& maskUrl,
438     StorageType      storageType,
439     const bool&      synchronousLoading = false);
440
441 private:
442   /**
443    * @brief Requests an image load of the given URL, when the texture has
444    * have loaded, if there is a valid maskTextureId, it will perform a
445    * CPU blend with the mask, and upload the blend texture.
446    *
447    * The parameters are used to specify how the image is loaded.
448    * The observer has the LoadComplete method called when the load is ready.
449    *
450    * When the client has finished with the Texture, Remove() should be called.
451    *
452    * @param[in] url                   The URL of the image to load
453    * @param[in] maskTextureId         The texture id of an image to use as a mask. If no mask is required, then set
454    *                                  to INVALID_TEXTURE_ID
455    * @param[in] contentScale          The scaling factor to apply to the content when masking
456    * @param[in] desiredSize           The size the image is likely to appear at. This can be set to 0,0 for automatic
457    * @param[in] fittingMode           The FittingMode to use
458    * @param[in] samplingMode          The SamplingMode to use
459    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be
460    *                                  loaded, and marked successful, but "useAtlasing" will be set to false in the
461    *                                  "LoadCompleted" callback from the TextureManagerUploadObserver.
462    * @param[in] cropToMask            Whether to crop the target after masking, or scale the mask to the image before
463    *                                  masking.
464    * @param[in] storageType,          Whether the pixel data is stored in the cache or uploaded to the GPU
465    * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
466    *                                  virtual.
467    *                                  This is called when an image load completes (or fails).
468    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
469    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
470    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if
471    *                                  there is no alpha
472    * @param[in] animatedImageLoading  The AnimatedImageLoading to load animated image
473    * @param[in] frameIndex            The frame index of a frame to be loaded frame
474    * @param[in] synchronousLoading    True if the frame should be loaded synchronously. If you skip this parameter,
475    *                                  default is false.
476    * @return                          A TextureId to use as a handle to reference this Texture
477    */
478   TextureId RequestLoadInternal(
479     const VisualUrl&                    url,
480     const TextureManager::TextureId&    maskTextureId,
481     const float&                        contentScale,
482     const Dali::ImageDimensions&        desiredSize,
483     const Dali::FittingMode::Type&      fittingMode,
484     const Dali::SamplingMode::Type&     samplingMode,
485     const TextureManager::UseAtlas&     useAtlas,
486     const bool&                         cropToMask,
487     const TextureManager::StorageType&  storageType,
488     TextureUploadObserver*              observer,
489     const bool&                         orientationCorrection,
490     const TextureManager::ReloadPolicy& reloadPolicy,
491     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
492     Dali::AnimatedImageLoading          animatedImageLoading,
493     const std::uint32_t&                frameIndex,
494     const bool&                         synchronousLoading);
495
496   /**
497    * @brief Load a new image synchronously.
498    * @param[in] url                   The URL of the image to load
499    * @param[in] desiredSize           The size the image is likely to appear at.
500    *                                  This can be set to 0,0 for automatic
501    * @param[in] fittingMode           The FittingMode to use
502    * @param[in] samplingMode          The SamplingMode to use
503    * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
504    *                                  e.g., from portrait to landscape
505    * @param[in] loadYuvPlanes         True if the image should be loaded as yuv planes
506    * @param[out] pixelBuffers         The image pixelBuffer
507    * @return PixelBuffer of loaded image.
508    */
509   void LoadImageSynchronously(
510     const VisualUrl&                 url,
511     const Dali::ImageDimensions&     desiredSize,
512     const Dali::FittingMode::Type&   fittingMode,
513     const Dali::SamplingMode::Type&  samplingMode,
514     const bool&                      orientationCorrection,
515     const bool&                      loadYuvPlanes,
516     std::vector<Devel::PixelBuffer>& pixelBuffers);
517
518 private:
519   // Load and queue
520
521   /**
522    * Structure to hold info about a texture load queued during NotifyObservers
523    */
524   struct QueueElement
525   {
526     QueueElement(TextureManager::TextureId textureId, TextureUploadObserver* observer)
527     : mTextureId(textureId),
528       mObserver(observer)
529     {
530     }
531
532     TextureManager::TextureId mTextureId; ///< The texture id of the requested load.
533     TextureUploadObserver*    mObserver;  ///< Observer of texture load.
534   };
535
536   /**
537    * @brief Initiate a load or queue load if NotifyObservers is invoking callbacks
538    * @param[in] textureInfo The TextureInfo struct associated with the Texture
539    * @param[in] observer The observer wishing to observe the texture upload
540    */
541   void LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
542
543   /**
544    * @brief Queue a texture load to be subsequently handled by ProcessQueuedTextures.
545    * @param[in] textureInfo The TextureInfo struct associated with the Texture
546    * @param[in] observer The observer wishing to observe the texture upload
547    */
548   void QueueLoadTexture(const TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
549
550   /**
551    * @brief Used internally to initiate a load.
552    * @param[in] textureInfo The TextureInfo struct associated with the Texture
553    * @param[in] observer The observer wishing to observe the texture upload
554    */
555   void LoadTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
556
557   /**
558    * @brief Initiate load of textures queued whilst NotifyObservers invoking callbacks.
559    */
560   void ProcessLoadQueue();
561
562   /**
563    * @brief Initiate remove of texture queued whilst NotifyObservers invoking callbacks.
564    */
565   void ProcessRemoveQueue();
566
567   /**
568    * Add the observer to the observer list
569    * @param[in] textureInfo The TextureInfo struct associated with the texture
570    * @param[in] observer The observer wishing to observe the texture upload
571    */
572   void ObserveTexture(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
573
574   /**
575    * @brief Performs Post-Load steps including atlasing.
576    * @param[in] textureInfo  The struct associated with this Texture
577    * @param[in] pixelBuffers The image pixelBuffer
578    * @return    True if successful
579    */
580   void PostLoad(TextureManager::TextureInfo& textureInfo, std::vector<Devel::PixelBuffer>& pixelBuffers);
581
582   /**
583    * Check if there is a texture waiting to be masked. If there
584    * is then apply this mask and upload it.
585    * @param[in] maskTextureInfo The texture info of the mask that has just loaded.
586    */
587   void CheckForWaitingTexture(TextureManager::TextureInfo& maskTextureInfo);
588
589   /**
590    * Apply the mask to the pixelBuffer.
591    * @param[in] textureInfo The information of texture to apply the mask to
592    * @param[in] maskTextureId The texture id of the mask.
593    */
594   void ApplyMask(TextureManager::TextureInfo& textureInfo, const TextureManager::TextureId& maskTextureId);
595
596   /**
597    * Upload the texture specified in pixelBuffer to the appropriate location
598    * @param[in] pixelBuffers The image data to upload
599    * @param[in] textureInfo  The texture info containing the location to store the data to.
600    */
601   void UploadTextures(std::vector<Devel::PixelBuffer>& pixelBuffers, TextureManager::TextureInfo& textureInfo);
602
603   /**
604    * Notify the current observers that the texture upload is complete,
605    * then remove the observers from the list.
606    * @param[in] textureInfo The struct associated with this Texture
607    * @param[in] success If the pixel data was retrieved successfully and uploaded to GPU
608    */
609   void NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success);
610
611   /**
612    * Call LoadComplete to the observer.
613    * @param[in] observer    The client object should inherit from this and provide the "LoadCompleted"
614    * @param[in] textureInfo The struct associated with this Texture
615    * @param[in] success     If the pixel data was retrieved successfully and uploaded to GPU
616    */
617   void EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success);
618
619   /**
620    * @brief Remove observer in textureInfo
621    *
622    * @param textureInfo The struct associated with this Texture.
623    * @param observer The observer wishing to remove.
624    */
625   void RemoveTextureObserver(TextureManager::TextureInfo& textureInfo, TextureUploadObserver* observer);
626
627 public:
628   /**
629    * @brief Common method to handle loading completion.
630    * TextureAsyncLoadingHelper will call this API After async loading finished.
631    * @param[in] textureId    The ID of the texture load complete.
632    * @param[in] pixelBuffers The loaded image data
633    */
634   void AsyncLoadComplete(const TextureManager::TextureId& textureId, std::vector<Devel::PixelBuffer>& pixelBuffers);
635
636 private:
637   /**
638    * Deleted copy constructor.
639    */
640   TextureManager(const TextureManager&) = delete;
641
642   /**
643    * Deleted assignment operator.
644    */
645   TextureManager& operator=(const TextureManager& rhs) = delete;
646
647   /**
648    * This is called by the TextureManagerUploadObserver when an observer is destroyed.
649    * We use the callback to know when to remove an observer from our notify list.
650    * @param[in] observer The observer that generated the callback
651    */
652   void ObserverDestroyed(TextureUploadObserver* observer);
653
654 private:                                                             // Member Variables:
655   TextureCacheManager                        mTextureCacheManager;   ///< Manager the life-cycle and caching of Textures
656   std::unique_ptr<TextureAsyncLoadingHelper> mAsyncLoader;           ///< The Asynchronous image loader used to provide all local async loads
657   Dali::Vector<LifecycleObserver*>           mLifecycleObservers;    ///< Lifecycle observers of texture manager
658   Dali::Vector<QueueElement>                 mLoadQueue;             ///< Queue of textures to load after NotifyObservers
659   Dali::Vector<QueueElement>                 mRemoveQueue;           ///< Queue of textures to remove after NotifyObservers
660   TextureManager::TextureId                  mLoadingQueueTextureId; ///< TextureId when it is loading. it causes Load Textures to be queued.
661   bool                                       mLoadYuvPlanes;         ///< A global flag to specify if the image should be loaded as yuv planes
662 };
663
664 } // namespace Internal
665
666 } // namespace Toolkit
667
668 } // namespace Dali
669
670 #endif // DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H