1 #ifndef DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H
2 #define DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H
5 * Copyright (c) 2023 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/pixel-buffer.h>
22 #include <dali/devel-api/adaptor-framework/texture-upload-manager.h>
23 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
24 #include <dali/public-api/adaptor-framework/async-task-manager.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/rendering/texture.h>
29 #include <dali-toolkit/devel-api/image-loader/async-image-loader-devel.h>
30 #include <dali-toolkit/internal/texture-manager/texture-manager-type.h>
31 #include <dali-toolkit/internal/visuals/visual-url.h>
39 class FastTrackLoadingTask;
40 using FastTrackLoadingTaskPtr = IntrusivePtr<FastTrackLoadingTask>;
43 * @brief The task of loading image and uploading texture on fast track.
44 * It is available that upload the loaded image data on texture at image loader threads.
46 class FastTrackLoadingTask : public AsyncTask
52 FastTrackLoadingTask(const VisualUrl& url,
53 ImageDimensions dimensions,
54 FittingMode::Type fittingMode,
55 SamplingMode::Type samplingMode,
56 bool orientationCorrection,
57 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
59 CallbackBase* callback);
64 ~FastTrackLoadingTask() override;
67 * @brief Process the task accodring to the type
69 void Process() override;
72 * @brief Whether the task is ready to process.
73 * @return True if the task is ready to process.
75 bool IsReady() override;
79 FastTrackLoadingTask(const FastTrackLoadingTask& queue) = delete;
80 FastTrackLoadingTask& operator=(const FastTrackLoadingTask& queue) = delete;
83 * @brief Create textures for this task.
84 * @note This should be called in construct timing.
86 void PrepareTexture();
89 * @brief Load the image.
94 * @brief Multiply alpha if required.
96 * @param[in,out] pixelBuffer target pixel buffer that need to be multiplied alpha.
98 void MultiplyAlpha(Dali::Devel::PixelBuffer pixelBuffer);
101 * @brief Upload loaded pixelBuffer into texture
103 void UploadToTexture();
107 * @brief Complete callback.
109 * @param[in] task The pointer of task who call this callback.
111 void OnComplete(AsyncTaskPtr task);
114 VisualUrl mUrl; ///< url of the image to load.
115 std::vector<Dali::Texture> mTextures; ///< textures for regular image.
118 ImageDimensions mDimensions; ///< dimensions to load
119 FittingMode::Type mFittingMode; ///< fitting options
120 SamplingMode::Type mSamplingMode; ///< sampling options
121 DevelAsyncImageLoader::PreMultiplyOnLoad mPreMultiplyOnLoad;
122 std::unique_ptr<CallbackBase> mCallback;
124 // Texture Upload relative API
125 Dali::Devel::TextureUploadManager mTextureUploadManager;
127 // Note : mPixelData is invalid after upload requested. We should keep image size informations.
128 struct ImageInformation
134 Pixel::Format format;
136 std::vector<ImageInformation> mImageInformations;
138 std::vector<Dali::PixelData> mPixelData;
140 bool mOrientationCorrection : 1; ///< If orientation correction is needed
143 bool mLoadSuccess : 1; ///< Whether image load successed or not.
144 bool mLoadPlanesAvaliable : 1; ///< If image valid to load as planes or not.
145 bool mPremultiplied : 1; ///< True if the image's color was multiplied by it's alpha
146 bool mPlanesLoaded : 1; ///< True if the image load as planes.
149 } // namespace Internal
151 } // namespace Toolkit
155 #endif // DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H