1 #ifndef DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H
2 #define DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H
5 * Copyright (c) 2022 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.
21 #include <dali/public-api/signals/connection-tracker.h>
25 #include <dali-toolkit/internal/image-loader/async-image-loader-impl.h>
26 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
35 * @brief Helper class to keep the relation between AsyncImageLoader and corresponding LoadingInfo container
37 class TextureAsyncLoadingHelper : public ConnectionTracker
40 * Struct to hold information about a requested Async load.
41 * This is used to look up a TextureManager::TextureId from the returned AsyncLoad Id.
43 struct AsyncLoadingInfo
45 AsyncLoadingInfo(TextureManager::TextureId textureId)
46 : textureId(textureId),
51 TextureManager::TextureId textureId; ///< The external Texture Id assigned to this load
52 std::uint32_t loadId; ///< The load Id used by the async loader to reference this load
57 * @brief Create an TextureAsyncLoadingHelper.
58 * @param[in] textureManager Reference to the texture manager
60 TextureAsyncLoadingHelper(TextureManager& textureManager);
63 * @brief Load a new frame of animated image
64 * @param[in] textureId TextureId to reference the texture that will be loaded
65 * @param[in] animatedImageLoading The AnimatedImageLoading to load animated image
66 * @param[in] frameIndex The frame index of a frame to be loaded frame
68 void LoadAnimatedImage(const TextureManager::TextureId& textureId,
69 Dali::AnimatedImageLoading animatedImageLoading,
70 const std::uint32_t& frameIndex);
73 * @brief Load a new texture.
74 * @param[in] textureId TextureId to reference the texture that will be loaded
75 * @param[in] url The URL of the image to load
76 * @param[in] desiredSize The size the image is likely to appear at.
77 * This can be set to 0,0 for automatic
78 * @param[in] fittingMode The FittingMode to use
79 * @param[in] samplingMode The SamplingMode to use
80 * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
81 * e.g., from portrait to landscape
82 * @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.
84 void Load(const TextureManager::TextureId& textureId,
86 const Dali::ImageDimensions& desiredSize,
87 const Dali::FittingMode::Type& fittingMode,
88 const Dali::SamplingMode::Type& samplingMode,
89 const bool& orientationCorrection,
90 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
94 * @param [in] textureId of the texture
95 * @param [in] pixelBuffer of the to be masked image
96 * @param [in] maskPixelBuffer of the mask image
97 * @param [in] contentScale The factor to scale the content
98 * @param [in] cropToMask Whether to crop the content to the mask size
99 * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
101 void ApplyMask(const TextureManager::TextureId& textureId,
102 Devel::PixelBuffer pixelBuffer,
103 Devel::PixelBuffer maskPixelBuffer,
104 const float& contentScale,
105 const bool& cropToMask,
106 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
109 TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
110 TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
112 TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs);
113 TextureAsyncLoadingHelper& operator=(TextureAsyncLoadingHelper&& rhs) = delete;
115 private: // Private typedefs:
116 typedef std::deque<AsyncLoadingInfo> AsyncLoadingInfoContainerType; ///< The container type used to manage Asynchronous loads in progress
120 * @brief Main constructor that used by all other constructors
122 TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader loader,
123 TextureManager& textureManager,
124 AsyncLoadingInfoContainerType&& loadingInfoContainer);
127 * @brief Callback to be called when texture loading is complete, it passes the pixel buffer on to texture manager.
128 * @param[in] id Loader id
129 * @param[in] pixelBuffer Image data
131 void AsyncLoadComplete(std::uint32_t id, Devel::PixelBuffer pixelBuffer);
133 private: // Member Variables:
134 Toolkit::AsyncImageLoader mLoader;
135 TextureManager& mTextureManager;
136 AsyncLoadingInfoContainerType mLoadingInfoContainer;
139 } // namespace Internal
141 } // namespace Toolkit
145 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H