1 #ifndef DALI_TOOLKIT_TEXTURE_MANAGER_TYPE_H
2 #define DALI_TOOLKIT_TEXTURE_MANAGER_TYPE_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/devel-api/adaptor-framework/animated-image-loading.h>
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/vector4.h>
26 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
27 #include <dali-toolkit/internal/texture-manager/texture-upload-observer.h>
28 #include <dali-toolkit/internal/visuals/visual-url.h>
37 * @brief Define common type, enum, and struct that both TextureManager and TextureCacheManager will use.
39 namespace TextureManagerType
43 typedef std::int32_t TextureId; ///< The TextureId type. This is used as a handle to refer to a particular Texture.
44 typedef std::int32_t TextureCacheIndex; ///< The TextureCacheIndex type. This is used as a handles to refer to a particular Texture in TextureCacheManager.
45 /// Note : For the same Texture, TextureId will not be changed. But TextureCacheIndex can be chaged when TextureCacheManager
46 /// Internal container informations changed by Append or Remove.
47 typedef std::size_t TextureHash; ///< The type used to store the hash used for Texture caching.
51 static constexpr TextureId INVALID_TEXTURE_ID = -1; ///< Used to represent a null TextureId or error
52 static constexpr TextureCacheIndex INVALID_CACHE_INDEX = -1; ///< Used to represent a null TextureCacheIndex or error
57 * Whether the texture should be atlased or uploaded into it's own GPU texture
66 * Whether the pixel data should be kept in TextureManager, returned with pixelBuffer or uploaded for rendering
68 enum class StorageType
70 KEEP_PIXEL_BUFFER, ///< Keep loaded pixel buffer inside of texture manager without making texture. This could be used for inside pixel process like mask image.
71 RETURN_PIXEL_BUFFER, ///< Return loaded pixel buffer without making texture.
72 /// Because a pixel buffer cannot be used multiple texture, this pixel buffer only cached during loading, and is removed after loading is finished.
73 UPLOAD_TO_TEXTURE ///< Loaded image will be uploaded to texture and the texture will be returned.
77 * Whether the texture should be loaded synchronously or asynchronously.
86 * @brief The LoadState Enumeration represents the current state of a particular Texture's life-cycle.
90 NOT_STARTED, ///< Default
91 LOADING, ///< Loading has been started, but not finished.
92 LOAD_FINISHED, ///< Loading has finished. (for CPU storage only)
93 WAITING_FOR_MASK, ///< Loading has finished, but waiting for mask image
94 MASK_APPLYING, ///< Loading has finished, Mask is applying
95 MASK_APPLIED, ///< Loading has finished, Mask is applyied by GPU
96 UPLOADED, ///< Uploaded and ready. (For GPU upload only)
97 CANCELLED, ///< Removed before loading completed
98 LOAD_FAILED ///< Async loading failed, e.g. connection problem
102 * @brief Types of reloading policies
104 enum class ReloadPolicy
106 CACHED = 0, ///< Loads cached texture if it exists.
107 FORCED ///< Forces reloading of texture.
111 * @brief Whether to multiply alpha into color channels on load
113 enum class MultiplyOnLoad
115 LOAD_WITHOUT_MULTIPLY = 0, ///< Don't modify the image
116 MULTIPLY_ON_LOAD ///< Multiply alpha into color channels on load
122 * @brief This struct is used to manage the life-cycle of Texture loading and caching.
126 TextureInfo(const TextureId& textureId,
127 const TextureId& maskTextureId,
128 const VisualUrl& url,
129 const Dali::ImageDimensions& desiredSize,
130 const float& scaleFactor,
131 const Dali::FittingMode::Type& fittingMode,
132 const Dali::SamplingMode::Type& samplingMode,
133 const bool& loadSynchronously,
134 const bool& cropToMask,
135 const UseAtlas& useAtlas,
136 const TextureHash& hash,
137 const bool& orientationCorrection,
138 const bool& preMultiplyOnLoad,
139 const Dali::AnimatedImageLoading& animatedImageLoading,
140 const std::uint32_t& frameIndex)
142 desiredSize(desiredSize),
143 useSize(desiredSize),
144 atlasRect(0.0f, 0.0f, 1.0f, 1.0f), // Full atlas rectangle
145 textureId(textureId),
146 maskTextureId(maskTextureId),
148 scaleFactor(scaleFactor),
150 loadState(LoadState::NOT_STARTED),
151 fittingMode(fittingMode),
152 samplingMode(samplingMode),
153 storageType(StorageType::UPLOAD_TO_TEXTURE),
154 animatedImageLoading(animatedImageLoading),
155 frameIndex(frameIndex),
159 loadSynchronously(loadSynchronously),
160 cropToMask(cropToMask),
161 orientationCorrection(true),
162 preMultiplyOnLoad(preMultiplyOnLoad),
165 isAnimatedImageFormat = (animatedImageLoading) ? true : false;
169 * Container type used to store all observer clients of this Texture
171 typedef Dali::Vector<TextureUploadObserver*> ObserverListType;
173 ObserverListType observerList; ///< Container used to store all observer clients of this Texture
174 Dali::Toolkit::ImageAtlas atlas; ///< The atlas this Texture lays within (if any)
175 Dali::Devel::PixelBuffer pixelBuffer; ///< The PixelBuffer holding the image data (May be empty after upload)
176 Dali::TextureSet textureSet; ///< The TextureSet holding the Texture
177 VisualUrl url; ///< The URL of the image
178 Dali::ImageDimensions desiredSize; ///< The size requested
179 Dali::ImageDimensions useSize; ///< The size used
180 Dali::Vector4 atlasRect; ///< The atlas rect used if atlased
181 TextureId textureId; ///< The TextureId associated with this Texture
182 TextureId maskTextureId; ///< The mask TextureId to be applied on load
183 TextureHash hash; ///< The hash used to cache this Texture
184 float scaleFactor; ///< The scale factor to apply to the Texture when masking
185 std::int16_t referenceCount; ///< The reference count of clients using this Texture
186 LoadState loadState; ///< The load state showing the load progress of the Texture
187 Dali::FittingMode::Type fittingMode : 3; ///< The requested FittingMode
188 Dali::SamplingMode::Type samplingMode : 3; ///< The requested SamplingMode
189 StorageType storageType; ///< CPU storage / GPU upload;
190 Dali::AnimatedImageLoading animatedImageLoading; ///< AnimatedImageLoading that contains animated image information.
191 uint32_t frameIndex; ///< Frame index that be loaded, in case of animated image
192 uint32_t frameCount; ///< Total frame count of input animated image. If this variable is not 0, this textureInfo is for animated image file format.
193 uint32_t frameInterval; ///< Time interval between this frame and next frame of animated image.
194 UseAtlas useAtlas; ///< USE_ATLAS if an atlas was requested.
196 bool loadSynchronously : 1; ///< True if synchronous loading was requested
197 bool cropToMask : 1; ///< True if the image should be cropped to the mask size.
198 bool orientationCorrection : 1; ///< True if the image should be rotated to match exif orientation data
199 bool preMultiplyOnLoad : 1; ///< True if the image's color should be multiplied by it's alpha
200 bool preMultiplied : 1; ///< True if the image's color was multiplied by it's alpha
201 bool isAnimatedImageFormat : 1; ///< true if the image is requested from animated image visual.
204 } // namespace TextureManagerType
206 } // namespace Internal
208 } // namespace Toolkit
212 #endif // DALI_TOOLKIT_TEXTURE_MANAGER_TYPE_H