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