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