[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / fast-track-loading-task.h
1 #ifndef DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H
2 #define DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
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>
27
28 // INTERNAL INCLUDES
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>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 namespace Internal
38 {
39 class FastTrackLoadingTask;
40 using FastTrackLoadingTaskPtr = IntrusivePtr<FastTrackLoadingTask>;
41
42 /**
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.
45  */
46 class FastTrackLoadingTask : public AsyncTask
47 {
48 public:
49   /**
50    * @brief Constructor.
51    */
52   FastTrackLoadingTask(const VisualUrl&                         url,
53                        ImageDimensions                          dimensions,
54                        FittingMode::Type                        fittingMode,
55                        SamplingMode::Type                       samplingMode,
56                        bool                                     orientationCorrection,
57                        DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
58                        bool                                     loadPlanes,
59                        CallbackBase*                            callback);
60
61   /**
62    * @brief Destructor.
63    */
64   ~FastTrackLoadingTask() override;
65
66 public: // Implementation of AsyncTask
67   /**
68    * @copydoc Dali::AsyncTask::Process()
69    */
70   void Process() override;
71
72   /**
73    * @copydoc Dali::AsyncTask::IsReady()
74    */
75   bool IsReady() override;
76
77   /**
78    * @copydoc Dali::AsyncTask::GetTaskName()
79    */
80   std::string_view GetTaskName() const override
81   {
82     return "FastTrackLoadingTask";
83   }
84
85 private:
86   // Undefined
87   FastTrackLoadingTask(const FastTrackLoadingTask& queue) = delete;
88   FastTrackLoadingTask& operator=(const FastTrackLoadingTask& queue) = delete;
89
90   /**
91    * @brief Create textures for this task.
92    * @note This should be called in construct timing.
93    */
94   void PrepareTexture();
95
96   /**
97    * @brief Load the image.
98    */
99   void Load();
100
101   /**
102    * @brief Multiply alpha if required.
103    *
104    * @param[in,out] pixelBuffer target pixel buffer that need to be multiplied alpha.
105    */
106   void MultiplyAlpha(Dali::Devel::PixelBuffer pixelBuffer);
107
108   /**
109    * @brief Upload loaded pixelBuffer into texture
110    */
111   void UploadToTexture();
112
113 private:
114   /**
115    * @brief Complete callback.
116    *
117    * @param[in] task The pointer of task who call this callback.
118    */
119   void OnComplete(AsyncTaskPtr task);
120
121 public:
122   VisualUrl                  mUrl;      ///< url of the image to load.
123   std::vector<Dali::Texture> mTextures; ///< textures for regular image.
124
125 private:
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;
131
132   // Texture Upload relative API
133   Dali::Devel::TextureUploadManager mTextureUploadManager;
134
135   // Note : mPixelData is invalid after upload requested. We should keep image size informations.
136   struct ImageInformation
137   {
138     uint32_t resourceId;
139
140     uint32_t      width;
141     uint32_t      height;
142     Pixel::Format format;
143   };
144   std::vector<ImageInformation> mImageInformations;
145
146   std::vector<Dali::PixelData> mPixelData;
147
148   bool mOrientationCorrection : 1; ///< If orientation correction is needed
149
150 public:
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.
155 };
156
157 } // namespace Internal
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif // DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H