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