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