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
67 * @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.
69 void LoadAnimatedImage(const TextureManager::TextureId& textureId,
70 Dali::AnimatedImageLoading animatedImageLoading,
71 const std::uint32_t& frameIndex,
72 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
75 * @brief Load a new texture.
76 * @param[in] textureId TextureId to reference the texture that will be loaded
77 * @param[in] url The URL of the image to load
78 * @param[in] desiredSize The size the image is likely to appear at.
79 * This can be set to 0,0 for automatic
80 * @param[in] fittingMode The FittingMode to use
81 * @param[in] samplingMode The SamplingMode to use
82 * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
83 * e.g., from portrait to landscape
84 * @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.
85 * @param[in] loadYuvPlanes True if the image should be loaded as yuv planes
87 void Load(const TextureManager::TextureId& textureId,
89 const Dali::ImageDimensions& desiredSize,
90 const Dali::FittingMode::Type& fittingMode,
91 const Dali::SamplingMode::Type& samplingMode,
92 const bool& orientationCorrection,
93 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad,
94 const bool& loadYuvPlanes);
98 * @param [in] textureId of the texture
99 * @param [in] pixelBuffer of the to be masked image
100 * @param [in] maskPixelBuffer of the mask image
101 * @param [in] contentScale The factor to scale the content
102 * @param [in] cropToMask Whether to crop the content to the mask size
103 * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
105 void ApplyMask(const TextureManager::TextureId& textureId,
106 Devel::PixelBuffer pixelBuffer,
107 Devel::PixelBuffer maskPixelBuffer,
108 const float& contentScale,
109 const bool& cropToMask,
110 const DevelAsyncImageLoader::PreMultiplyOnLoad& preMultiplyOnLoad);
113 TextureAsyncLoadingHelper(const TextureAsyncLoadingHelper&) = delete;
114 TextureAsyncLoadingHelper& operator=(const TextureAsyncLoadingHelper&) = delete;
116 TextureAsyncLoadingHelper(TextureAsyncLoadingHelper&& rhs);
117 TextureAsyncLoadingHelper& operator=(TextureAsyncLoadingHelper&& rhs) = delete;
119 private: // Private typedefs:
120 typedef std::deque<AsyncLoadingInfo> AsyncLoadingInfoContainerType; ///< The container type used to manage Asynchronous loads in progress
124 * @brief Main constructor that used by all other constructors
126 TextureAsyncLoadingHelper(Toolkit::AsyncImageLoader loader,
127 TextureManager& textureManager,
128 AsyncLoadingInfoContainerType&& loadingInfoContainer);
131 * @brief Callback to be called when texture loading is complete, it passes the pixel buffer list on to texture manager.
132 * @param[in] id Loader id
133 * @param[in] pixelBuffers Image data
135 void AsyncLoadComplete(std::uint32_t id, std::vector<Devel::PixelBuffer>& pixelBuffers);
137 private: // Member Variables:
138 Toolkit::AsyncImageLoader mLoader;
139 TextureManager& mTextureManager;
140 AsyncLoadingInfoContainerType mLoadingInfoContainer;
143 } // namespace Internal
145 } // namespace Toolkit
149 #endif // DALI_TOOLKIT_TEXTURE_ASYNC_LOADING_HELPER_H