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;
66 public: // Implementation of AsyncTask
68 * @copydoc Dali::AsyncTask::Process()
70 void Process() override;
73 * @copydoc Dali::AsyncTask::IsReady()
75 bool IsReady() override;
78 * @copydoc Dali::AsyncTask::GetTaskName()
80 std::string_view GetTaskName() const override
82 return "FastTrackLoadingTask";
87 FastTrackLoadingTask(const FastTrackLoadingTask& queue) = delete;
88 FastTrackLoadingTask& operator=(const FastTrackLoadingTask& queue) = delete;
91 * @brief Create textures for this task.
92 * @note This should be called in construct timing.
94 void PrepareTexture();
97 * @brief Load the image.
102 * @brief Multiply alpha if required.
104 * @param[in,out] pixelBuffer target pixel buffer that need to be multiplied alpha.
106 void MultiplyAlpha(Dali::Devel::PixelBuffer pixelBuffer);
109 * @brief Upload loaded pixelBuffer into texture
111 void UploadToTexture();
115 * @brief Complete callback.
117 * @param[in] task The pointer of task who call this callback.
119 void OnComplete(AsyncTaskPtr task);
122 VisualUrl mUrl; ///< url of the image to load.
123 std::vector<Dali::Texture> mTextures; ///< textures for regular image.
126 ImageDimensions mDimensions; ///< dimensions to load
127 FittingMode::Type mFittingMode; ///< fitting options
128 SamplingMode::Type mSamplingMode; ///< sampling options
129 DevelAsyncImageLoader::PreMultiplyOnLoad mPreMultiplyOnLoad;
130 std::unique_ptr<CallbackBase> mCallback;
132 // Texture Upload relative API
133 Dali::Devel::TextureUploadManager mTextureUploadManager;
135 // Note : mPixelData is invalid after upload requested. We should keep image size informations.
136 struct ImageInformation
142 Pixel::Format format;
144 std::vector<ImageInformation> mImageInformations;
146 std::vector<Dali::PixelData> mPixelData;
148 bool mOrientationCorrection : 1; ///< If orientation correction is needed
151 bool mLoadSuccess : 1; ///< Whether image load successed or not.
152 bool mLoadPlanesAvaliable : 1; ///< If image valid to load as planes or not.
153 bool mPremultiplied : 1; ///< True if the image's color was multiplied by it's alpha
154 bool mPlanesLoaded : 1; ///< True if the image load as planes.
157 } // namespace Internal
159 } // namespace Toolkit
163 #endif // DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H