1 #ifndef DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
2 #define DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/rendering/texture-set.h>
28 #include <dali/devel-api/common/owner-container.h>
29 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
32 #include <dali-toolkit/devel-api/image-loader/async-image-loader-devel.h>
33 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
34 #include <dali-toolkit/public-api/image-loader/async-image-loader.h>
35 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
36 #include <dali-toolkit/internal/visuals/visual-url.h>
37 #include <dali-toolkit/internal/helpers/round-robin-container-view.h>
38 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
49 class ImageAtlasManager;
50 typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
53 * The TextureManager provides a common Image loading API for Visuals.
55 * The TextureManager is responsible for providing sync, async, atlased and non-atlased loads.
56 * Texture caching is provided and performed when possible.
57 * Broken Images are automatically provided on load failure.
59 class TextureManager : public ConnectionTracker
63 typedef int32_t TextureId; ///< The TextureId type. This is used as a handle to refer to a particular Texture.
64 static const int INVALID_TEXTURE_ID = -1; ///< Used to represent a null TextureId or error
67 * Whether the texture should be atlased or uploaded into it's own GPU texture
76 * Whether the pixel data should be kept in TextureManager, or uploaded for rendering
85 * Whether the texture should be loaded synchronously or asynchronously.
94 * @brief The LoadState Enumeration represents the current state of a particular Texture's life-cycle.
98 NOT_STARTED, ///< Default
99 LOADING, ///< Loading has been started, but not finished.
100 LOAD_FINISHED, ///< Loading has finished. (for CPU storage only)
101 WAITING_FOR_MASK,///< Loading has finished, but waiting for mask image
102 MASK_APPLYING, ///< Loading has finished, Mask is applying
103 MASK_APPLIED, ///< Loading has finished, Mask is applyied by GPU
104 UPLOADED, ///< Uploaded and ready. (For GPU upload only)
105 CANCELLED, ///< Removed before loading completed
106 LOAD_FAILED ///< Async loading failed, e.g. connection problem
110 * @brief Types of reloading policies
112 enum class ReloadPolicy
114 CACHED = 0, ///< Loads cached texture if it exists.
115 FORCED ///< Forces reloading of texture.
119 * @brief Whether to multiply alpha into color channels on load
121 enum class MultiplyOnLoad
123 LOAD_WITHOUT_MULTIPLY = 0, ///< Don't modify the image
124 MULTIPLY_ON_LOAD ///< Multiply alpha into color channels on load
132 ~MaskingData() = default;
134 VisualUrl mAlphaMaskUrl;
135 TextureManager::TextureId mAlphaMaskId;
136 float mContentScaleFactor;
139 using MaskingDataPointer = std::unique_ptr<MaskingData>;
143 * Class to provide lifecycle event on destruction of texture manager.
145 struct LifecycleObserver
148 * Called shortly before the texture manager is destroyed.
150 virtual void TextureManagerDestroyed() = 0;
163 // TextureManager Main API:
166 * @brief Requests an image load of the given URL to get PixelBuffer.
168 * The parameters are used to specify how the image is loaded.
169 * The observer has the LoadComplete method called when the load is ready.
171 * @param[in] url The URL of the image to load
172 * @param[in] desiredSize The size the image is likely to appear at. This can be set to 0,0 for automatic
173 * @param[in] fittingMode The FittingMode to use
174 * @param[in] samplingMode The SamplingMode to use
175 * @param[in] synchronousLoading true if the URL should be loaded synchronously
176 * @param[in] textureObserver The client object should inherit from this and provide the "UploadCompleted" virtual.
177 * This is called when an image load completes (or fails).
178 * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
179 * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
180 * image has no alpha channel
182 * @return The pixel buffer containing the image, or empty if still loading.
185 Devel::PixelBuffer LoadPixelBuffer( const VisualUrl& url,
186 Dali::ImageDimensions desiredSize,
187 Dali::FittingMode::Type fittingMode,
188 Dali::SamplingMode::Type samplingMode,
189 bool synchronousLoading,
190 TextureUploadObserver* textureObserver,
191 bool orientationCorrection,
192 TextureManager::MultiplyOnLoad& preMultiplyOnLoad );
196 * @brief Requests an image load of the given URL.
198 * The parameters are used to specify how the image is loaded.
199 * The observer has the UploadComplete method called when the load is ready.
201 * When the client has finished with the Texture, Remove() should be called.
203 * @param[in] url The URL of the image to load
204 * @param[in] desiredSize The size the image is likely to appear at. This can be set to 0,0 for automatic
205 * @param[in] fittingMode The FittingMode to use
206 * @param[in] samplingMode The SamplingMode to use
207 * @param[in, out] maskInfo Mask info structure
208 * @param[in] synchronousLoading true if the URL should be loaded synchronously
209 * @param[out] textureId, The textureId of the URL
210 * @param[out] textureRect The rectangle within the texture atlas that this URL occupies,
211 * this is the rectangle in normalized coordinates.
212 * @param[out] textureRectSize The rectangle within the texture atlas that this URL occupies,
213 * this is the same rectangle in pixels.
214 * @param[in,out] atlasingStatus Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
215 * be loaded, and marked successful, but this will be set to false.
216 * If atlasing succeeds, this will be set to true.
217 * @param[out] loadingStatus The loading status of the texture
218 * @param[in] wrapModeU Horizontal Wrap mode
219 * @param[in] wrapModeV Vertical Wrap mode
220 * @param[in] textureObserver The client object should inherit from this and provide the "UploadCompleted" virtual.
221 * This is called when an image load completes (or fails).
222 * @param[in] atlasObserver This is used if the texture is atlased, and will be called instead of
223 * textureObserver.UploadCompleted
224 * @param[in] imageAtlasManager The atlas manager to use for atlasing textures
225 * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
226 * @param[in] reloadPolicy Forces a reload of the texture even if already cached
227 * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
228 * image has no alpha channel
230 * @return The texture set containing the image, or empty if still loading.
233 TextureSet LoadTexture( const VisualUrl& url,
234 Dali::ImageDimensions desiredSize,
235 Dali::FittingMode::Type fittingMode,
236 Dali::SamplingMode::Type samplingMode,
237 MaskingDataPointer& maskInfo,
238 bool synchronousLoading,
239 TextureManager::TextureId& textureId,
240 Vector4& textureRect,
241 Dali::ImageDimensions& textureRectSize,
242 bool& atlasingStatus,
244 Dali::WrapMode::Type wrapModeU,
245 Dali::WrapMode::Type wrapModeV,
246 TextureUploadObserver* textureObserver,
247 AtlasUploadObserver* atlasObserver,
248 ImageAtlasManagerPtr imageAtlasManager,
249 bool orientationCorrection,
250 TextureManager::ReloadPolicy reloadPolicy,
251 MultiplyOnLoad& preMultiplyOnLoad );
254 * @brief Requests an image load of the given URL.
256 * The parameters are used to specify how the image is loaded.
257 * The observer has the UploadComplete method called when the load is ready.
259 * When the client has finished with the Texture, Remove() should be called.
261 * @param[in] url The URL of the image to load
262 * @param[in] desiredSize The size the image is likely to appear at. This can be set to 0,0 for automatic
263 * @param[in] fittingMode The FittingMode to use
264 * @param[in] samplingMode The SamplingMode to use
265 * @param[in] useAtlasing Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be loaded, and marked successful,
266 * but "useAtlasing" will be set to false in the "UploadCompleted" callback from the TextureManagerUploadObserver.
267 * @param[in] observer The client object should inherit from this and provide the "UploadCompleted" virtual.
268 * This is called when an image load completes (or fails).
269 * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
270 * @param[in] reloadPolicy Forces a reload of the texture even if already cached
271 * @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
272 * @return A TextureId to use as a handle to reference this Texture
274 TextureId RequestLoad( const VisualUrl& url,
275 const ImageDimensions desiredSize,
276 FittingMode::Type fittingMode,
277 Dali::SamplingMode::Type samplingMode,
278 const UseAtlas useAtlasing,
279 TextureUploadObserver* observer,
280 bool orientationCorrection,
281 TextureManager::ReloadPolicy reloadPolicy,
282 MultiplyOnLoad& preMultiplyOnLoad );
285 * @brief Requests an image load of the given URL, when the texture has
286 * have loaded, it will perform a blend with the image mask, and upload
287 * the blended texture.
289 * The parameters are used to specify how the image is loaded.
290 * The observer has the UploadComplete method called when the load is ready.
292 * When the client has finished with the Texture, Remove() should be called.
294 * @param[in] url The URL of the image to load
295 * @param[in] maskTextureId The texture id of an image to mask this with
296 * (can be INVALID if no masking required)
297 * @param[in] contentScale The scale factor to apply to the image before masking
298 * @param[in] desiredSize The size the image is likely to appear at. This can be set to 0,0 for automatic
299 * @param[in] fittingMode The FittingMode to use
300 * @param[in] samplingMode The SamplingMode to use
301 * @param[in] useAtlasing Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
302 * be loaded, and marked successful,
303 * but "useAtlasing" will be set to false in the "UploadCompleted" callback from
304 * the TextureManagerUploadObserver.
305 * @param[in] cropToMask Only used with masking, this will crop the scaled image to the mask size.
306 * If false, then the mask will be scaled to fit the image before being applied.
307 * @param[in] observer The client object should inherit from this and provide the "UploadCompleted"
309 * This is called when an image load completes (or fails).
310 * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
311 * @param[in] reloadPolicy Forces a reload of the texture even if already cached
312 * @param[in] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
313 * image has no alpha channel
314 * @return A TextureId to use as a handle to reference this Texture
316 TextureId RequestLoad( const VisualUrl& url,
317 TextureId maskTextureId,
319 const ImageDimensions desiredSize,
320 FittingMode::Type fittingMode,
321 Dali::SamplingMode::Type samplingMode,
322 const UseAtlas useAtlasing,
324 TextureUploadObserver* observer,
325 bool orientationCorrection,
326 TextureManager::ReloadPolicy reloadPolicy,
327 MultiplyOnLoad& preMultiplyOnLoad );
330 * Requests a masking image to be loaded. This mask is not uploaded to GL,
331 * instead, it is stored in CPU memory, and can be used for CPU blending.
333 TextureId RequestMaskLoad( const VisualUrl& maskUrl );
336 * @brief Remove a Texture from the TextureManager.
338 * Textures are cached and therefore only the removal of the last
339 * occurrence of a Texture will cause its removal internally.
341 * @param[in] textureId The ID of the Texture to remove.
342 * @param[in] textureObserver The texture observer.
344 void Remove( const TextureManager::TextureId textureId, TextureUploadObserver* textureObserver );
347 * @brief Get the visualUrl associated with the texture id.
348 * @param[in] textureId The texture Id to get
349 * @return The visual Url associated with the texture id.
351 VisualUrl GetVisualUrl( TextureId textureId );
354 * @brief Get the current state of a texture
355 * @param[in] textureId The texture id to query
356 * @return The loading state if the texture is valid, or NOT_STARTED if the textureId
359 LoadState GetTextureState( TextureId textureId );
362 * @brief Get the associated texture set if the texture id is valid
363 * @param[in] textureId The texture Id to look up
364 * @return the associated texture set, or an empty handle if textureId is not valid
366 TextureSet GetTextureSet( TextureId textureId );
369 * Adds an external texture to the texture manager
370 * @param[in] texture The texture to add
371 * @return string containing the URL for the texture
373 std::string AddExternalTexture( TextureSet& texture );
376 * Removes an external texture from texture manager
377 * @param[in] url The string containing the texture to remove
378 * @return handle to the texture
380 TextureSet RemoveExternalTexture( const std::string& url );
383 * Add an observer to the object.
384 * @param[in] observer The observer to add.
386 void AddObserver( TextureManager::LifecycleObserver& observer );
389 * Remove an observer from the object
390 * @pre The observer has already been added.
391 * @param[in] observer The observer to remove.
393 void RemoveObserver( TextureManager::LifecycleObserver& observer );
396 * @brief Set an image to be used when a visual has failed to correctly render
397 * @param[in] brokenImageUrl The broken image url.
399 void SetBrokenImageUrl(const std::string& brokenImageUrl);
404 * @brief Requests an image load of the given URL, when the texture has
405 * have loaded, if there is a valid maskTextureId, it will perform a
406 * CPU blend with the mask, and upload the blend texture.
408 * The parameters are used to specify how the image is loaded.
409 * The observer has the UploadComplete method called when the load is ready.
411 * When the client has finished with the Texture, Remove() should be called.
413 * @param[in] url The URL of the image to load
414 * @param[in] maskTextureId The texture id of an image to use as a mask. If no mask is required, then set
415 * to INVALID_TEXTURE_ID
416 * @param[in] contentScale The scaling factor to apply to the content when masking
417 * @param[in] desiredSize The size the image is likely to appear at. This can be set to 0,0 for automatic
418 * @param[in] fittingMode The FittingMode to use
419 * @param[in] samplingMode The SamplingMode to use
420 * @param[in] useAtlasing Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be
421 * loaded, and marked successful, but "useAtlasing" will be set to false in the
422 * "UploadCompleted" callback from the TextureManagerUploadObserver.
423 * @param[in] cropToMask Whether to crop the target after masking, or scale the mask to the image before
425 * @param[in] storageType, Whether the pixel data is stored in the cache or uploaded to the GPU
426 * @param[in] observer The client object should inherit from this and provide the "UploadCompleted"
428 * This is called when an image load completes (or fails).
429 * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
430 * @param[in] reloadPolicy Forces a reload of the texture even if already cached
431 * @param[in] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if
433 * @return A TextureId to use as a handle to reference this Texture
435 TextureId RequestLoadInternal(
436 const VisualUrl& url,
437 TextureId maskTextureId,
439 const ImageDimensions desiredSize,
440 FittingMode::Type fittingMode,
441 Dali::SamplingMode::Type samplingMode,
444 StorageType storageType,
445 TextureUploadObserver* observer,
446 bool orientationCorrection,
447 TextureManager::ReloadPolicy reloadPolicy,
448 MultiplyOnLoad& preMultiplyOnLoad,
449 bool loadPixelBuffer );
452 * @brief Get the current state of a texture
453 * @param[in] textureId The texture id to query
454 * @return The loading state if the texture is valid, or NOT_STARTED if the textureId
457 LoadState GetTextureStateInternal( TextureId textureId );
459 typedef size_t TextureHash; ///< The type used to store the hash used for Texture caching.
464 * @brief This struct is used to manage the life-cycle of Texture loading and caching.
468 TextureInfo( TextureId textureId,
469 TextureId maskTextureId,
470 const VisualUrl& url,
471 ImageDimensions desiredSize,
473 FittingMode::Type fittingMode,
474 Dali::SamplingMode::Type samplingMode,
475 bool loadSynchronously,
478 TextureManager::TextureHash hash,
479 bool orientationCorrection,
480 bool preMultiplyOnLoad,
481 bool loadPixelBuffer )
483 desiredSize( desiredSize ),
484 useSize( desiredSize ),
485 atlasRect( 0.0f, 0.0f, 1.0f, 1.0f ), // Full atlas rectangle
486 textureId( textureId ),
487 maskTextureId( maskTextureId ),
489 scaleFactor( scaleFactor ),
490 referenceCount( 1u ),
491 loadState( NOT_STARTED ),
492 fittingMode( fittingMode ),
493 samplingMode( samplingMode ),
494 storageType( UPLOAD_TO_TEXTURE ),
495 loadSynchronously( loadSynchronously ),
496 useAtlas( useAtlas ),
497 cropToMask( cropToMask ),
498 orientationCorrection( true ),
499 preMultiplyOnLoad( preMultiplyOnLoad ),
500 preMultiplied( false ),
501 loadPixelBuffer( loadPixelBuffer )
506 * Container type used to store all observer clients of this Texture
508 typedef Dali::Vector< TextureUploadObserver* > ObserverListType;
510 ObserverListType observerList; ///< Container used to store all observer clients of this Texture
511 Toolkit::ImageAtlas atlas; ///< The atlas this Texture lays within (if any)
512 Devel::PixelBuffer pixelBuffer;///< The PixelBuffer holding the image data (May be empty after upload)
513 TextureSet textureSet; ///< The TextureSet holding the Texture
514 VisualUrl url; ///< The URL of the image
515 ImageDimensions desiredSize; ///< The size requested
516 ImageDimensions useSize; ///< The size used
517 Vector4 atlasRect; ///< The atlas rect used if atlased
518 TextureId textureId; ///< The TextureId associated with this Texture
519 TextureId maskTextureId; ///< The mask TextureId to be applied on load
520 TextureManager::TextureHash hash; ///< The hash used to cache this Texture
521 float scaleFactor; ///< The scale factor to apply to the Texture when masking
522 int16_t referenceCount; ///< The reference count of clients using this Texture
523 LoadState loadState:4; ///< The load state showing the load progress of the Texture
524 FittingMode::Type fittingMode:2; ///< The requested FittingMode
525 Dali::SamplingMode::Type samplingMode:3; ///< The requested SamplingMode
526 StorageType storageType:2; ///< CPU storage / GPU upload;
527 bool loadSynchronously:1; ///< True if synchronous loading was requested
528 UseAtlas useAtlas:2; ///< USE_ATLAS if an atlas was requested.
529 ///< This is updated to false if atlas is not used
530 bool cropToMask:1; ///< true if the image should be cropped to the mask size.
531 bool orientationCorrection:1; ///< true if the image should be rotated to match exif orientation data
532 bool preMultiplyOnLoad:1; ///< true if the image's color should be multiplied by it's alpha
533 bool preMultiplied:1; ///< true if the image's color was multiplied by it's alpha
534 bool loadPixelBuffer:1; ///< true if the image is needed to be returned as PixelBuffer
538 * Structure to hold info about a texture load queued during NotifyObservers
540 struct LoadQueueElement
542 LoadQueueElement( TextureId textureId, TextureUploadObserver* observer )
543 : mTextureId( textureId ),
544 mObserver( observer )
548 TextureId mTextureId; ///< The texture id of the requested load.
549 TextureUploadObserver* mObserver; ///< Observer of texture load.
553 * Struct to hold information about a requested Async load.
554 * This is used to look up a TextureManager::TextureId from the returned AsyncLoad Id.
556 struct AsyncLoadingInfo
558 AsyncLoadingInfo( TextureId textureId )
559 : textureId( textureId ),
564 TextureId textureId; ///< The external Texture Id assigned to this load
565 uint32_t loadId; ///< The load Id used by the async loader to reference this load
570 typedef std::deque<AsyncLoadingInfo> AsyncLoadingInfoContainerType; ///< The container type used to manage Asynchronous loads in progress
571 typedef std::vector<TextureInfo> TextureInfoContainerType; ///< The container type used to manage the life-cycle and caching of Textures
574 * @brief Initiate a load or queue load if NotifyObservers is invoking callbacks
575 * @param[in] textureInfo The TextureInfo struct associated with the Texture
576 * @param[in] observer The observer wishing to observe the texture upload
578 void LoadOrQueueTexture( TextureInfo& textureInfo, TextureUploadObserver* observer );
581 * @brief Queue a texture load to be subsequently handled by ProcessQueuedTextures.
582 * @param[in] textureInfo The TextureInfo struct associated with the Texture
583 * @param[in] observer The observer wishing to observe the texture upload
585 void QueueLoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer );
588 * @brief Used internally to initiate a load.
589 * @param[in] textureInfo The TextureInfo struct associated with the Texture
590 * @param[in] observer The observer wishing to observe the texture upload
592 void LoadTexture( TextureInfo& textureInfo, TextureUploadObserver* observer );
595 * @brief Initiate load of textures queued whilst NotifyObservers invoking callbacks.
597 void ProcessQueuedTextures();
600 * Add the observer to the observer list
601 * @param[in] textureInfo The TextureInfo struct associated with the texture
602 * @param[in] observer The observer wishing to observe the texture upload
604 void ObserveTexture( TextureInfo & textureInfo, TextureUploadObserver* observer );
607 * @brief This signal handler is called when the async local loader finishes loading.
608 * @param[in] id This is the async image loaders Id
609 * @param[in] pixelBuffer The loaded image data
611 void AsyncLocalLoadComplete( uint32_t id, Devel::PixelBuffer pixelBuffer );
614 * @brief This signal handler is called when the async local loader finishes loading.
615 * @param[in] id This is the async image loaders Id
616 * @param[in] pixelBuffer The loaded image data
618 void AsyncRemoteLoadComplete( uint32_t id, Devel::PixelBuffer pixelBuffer );
621 * Common method to handle loading completion
622 * @param[in] container The Async loading container
623 * @param[in] id This is the async image loaders Id
624 * @param[in] pixelBuffer The loaded image data
626 void AsyncLoadComplete( AsyncLoadingInfoContainerType& container, uint32_t id, Devel::PixelBuffer pixelBuffer );
629 * @brief Performs Post-Load steps including atlasing.
630 * @param[in] textureInfo The struct associated with this Texture
631 * @param[in] pixelBuffer The image pixelBuffer
632 * @return True if successful
634 void PostLoad( TextureManager::TextureInfo& textureInfo, Devel::PixelBuffer& pixelBuffer );
637 * Check if there is a texture waiting to be masked. If there
638 * is then apply this mask and upload it.
639 * @param[in] maskTextureInfo The texture info of the mask that has just loaded.
641 void CheckForWaitingTexture( TextureInfo& maskTextureInfo );
644 * Apply the mask to the pixelBuffer.
645 * @param[in] textureInfo The information of texture to apply the mask to
646 * @param[in] maskTextureId The texture id of the mask.
648 void ApplyMask( TextureInfo& textureInfo, TextureId maskTextureId );
651 * Upload the texture specified in pixelBuffer to the appropriate location
652 * @param[in] pixelBuffer The image data to upload
653 * @param[in] textureInfo The texture info containing the location to
656 void UploadTexture( Devel::PixelBuffer& pixelBuffer, TextureInfo& textureInfo );
659 * Mark the texture as complete, and inform observers
660 * @param[in] textureInfo The struct associated with this Texture
662 void UploadComplete( TextureInfo& textureInfo );
665 * Notify the current observers that the texture upload is complete,
666 * then remove the observers from the list.
667 * @param[in] textureInfo The struct associated with this Texture
668 * @param[in] success If the pixel data was retrieved successfully and uploaded to GPU
670 void NotifyObservers( TextureInfo& textureInfo, bool success );
673 * @brief Generates a new, unique TextureId
674 * @return A unique TextureId
676 TextureManager::TextureId GenerateUniqueTextureId();
679 * @brief Used to lookup an index into the TextureInfoContainer from a TextureId
680 * @param[in] textureId The TextureId to look up
681 * @return The cache index
683 int GetCacheIndexFromId( TextureId textureId );
687 * @brief Generates a hash for caching based on the input parameters.
688 * Only applies size, fitting mode andsampling mode if the size is specified.
689 * Only applies maskTextureId if it isn't INVALID_TEXTURE_ID
690 * Always applies useAtlas.
691 * @param[in] url The URL of the image to load
692 * @param[in] size The image size
693 * @param[in] fittingMode The FittingMode to use
694 * @param[in] samplingMode The SamplingMode to use
695 * @param[in] useAtlas True if atlased
696 * @param[in] maskTextureId The masking texture id (or INVALID_TEXTURE_ID)
697 * @return A hash of the provided data for caching.
699 TextureHash GenerateHash( const std::string& url, const ImageDimensions size,
700 const FittingMode::Type fittingMode,
701 const Dali::SamplingMode::Type samplingMode, const UseAtlas useAtlas,
702 TextureId maskTextureId );
705 * @brief Looks up a cached texture by its hash.
706 * If found, the given parameters are used to check there is no hash-collision.
707 * @param[in] hash The hash to look up
708 * @param[in] url The URL of the image to load
709 * @param[in] size The image size
710 * @param[in] fittingMode The FittingMode to use
711 * @param[in] samplingMode The SamplingMode to use
712 * @param[in] useAtlas True if atlased
713 * @param[in] maskTextureId Optional texture ID to use to mask this image
714 * @return A TextureId of a cached Texture if found. Or INVALID_TEXTURE_ID if not found.
716 TextureManager::TextureId FindCachedTexture(
717 const TextureManager::TextureHash hash,
718 const std::string& url,
719 const ImageDimensions size,
720 const FittingMode::Type fittingMode,
721 const Dali::SamplingMode::Type samplingMode,
723 TextureId maskTextureId,
724 MultiplyOnLoad preMultiplyOnLoad);
729 * @brief Helper class to keep the relation between AsyncImageLoader and corresponding LoadingInfo container
731 class AsyncLoadingHelper : public ConnectionTracker
735 * @brief Create an AsyncLoadingHelper.
736 * @param[in] textureManager Reference to the texture manager
738 AsyncLoadingHelper(TextureManager& textureManager);
741 * @brief Load a new texture.
742 * @param[in] textureId TextureId to reference the texture that will be loaded
743 * @param[in] url The URL of the image to load
744 * @param[in] desiredSize The size the image is likely to appear at.
745 * This can be set to 0,0 for automatic
746 * @param[in] fittingMode The FittingMode to use
747 * @param[in] samplingMode The SamplingMode to use
748 * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
749 * e.g., from portrait to landscape
750 * @param[in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
752 void Load(TextureId textureId,
753 const VisualUrl& url,
754 ImageDimensions desiredSize,
755 FittingMode::Type fittingMode,
756 SamplingMode::Type samplingMode,
757 bool orientationCorrection,
758 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
762 * @param [in] id of the texture
763 * @param [in] pixelBuffer of the to be masked image
764 * @param [in] maskPixelBuffer of the mask image
765 * @param [in] contentScale The factor to scale the content
766 * @param [in] cropToMask Whether to crop the content to the mask size
767 * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
769 void ApplyMask( TextureId textureId,
770 Devel::PixelBuffer pixelBuffer,
771 Devel::PixelBuffer maskPixelBuffer,
774 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
777 AsyncLoadingHelper(const AsyncLoadingHelper&) = delete;
778 AsyncLoadingHelper& operator=(const AsyncLoadingHelper&) = delete;
780 AsyncLoadingHelper(AsyncLoadingHelper&& rhs);
781 AsyncLoadingHelper& operator=(AsyncLoadingHelper&&rhs) = delete;
785 * @brief Main constructor that used by all other constructors
787 AsyncLoadingHelper( Toolkit::AsyncImageLoader loader,
788 TextureManager& textureManager,
789 AsyncLoadingInfoContainerType&& loadingInfoContainer );
792 * @brief Callback to be called when texture loading is complete, it passes the pixel buffer on to texture manager.
793 * @param[in] id Loader id
794 * @param[in] pixelBuffer Image data
796 void AsyncLoadComplete( uint32_t id, Devel::PixelBuffer pixelBuffer );
799 Toolkit::AsyncImageLoader mLoader;
800 TextureManager& mTextureManager;
801 AsyncLoadingInfoContainerType mLoadingInfoContainer;
804 struct ExternalTextureInfo
807 TextureSet textureSet;
813 * Deleted copy constructor.
815 TextureManager( const TextureManager& ) = delete;
818 * Deleted assignment operator.
820 TextureManager& operator=( const TextureManager& rhs ) = delete;
823 * This is called by the TextureManagerUploadObserver when an observer is destroyed.
824 * We use the callback to know when to remove an observer from our notify list.
825 * @param[in] observer The observer that generated the callback
827 void ObserverDestroyed( TextureUploadObserver* observer );
829 private: // Member Variables:
831 TextureInfoContainerType mTextureInfoContainer; ///< Used to manage the life-cycle and caching of Textures
832 RoundRobinContainerView< AsyncLoadingHelper > mAsyncLocalLoaders; ///< The Asynchronous image loaders used to provide all local async loads
833 RoundRobinContainerView< AsyncLoadingHelper > mAsyncRemoteLoaders; ///< The Asynchronous image loaders used to provide all remote async loads
834 std::vector< ExternalTextureInfo > mExternalTextures; ///< Externally provided textures
835 Dali::Vector<LifecycleObserver*> mLifecycleObservers; ///< Lifecycle observers of texture manager
836 Dali::Vector<LoadQueueElement> mLoadQueue; ///< Queue of textures to load after NotifyObservers
837 std::string mBrokenImageUrl; ///< Broken image url
838 TextureId mCurrentTextureId; ///< The current value used for the unique Texture Id generation
839 bool mQueueLoadFlag; ///< Flag that causes Load Textures to be queued.
845 } // namespace Toolkit
849 #endif // DALI_TOOLKIT_TEXTURE_MANAGER_IMPL_H