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