Fix minor coverity issues
[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   /**
67    * @brief Process the task accodring to the type
68    */
69   void Process() override;
70
71   /**
72    * @brief Whether the task is ready to process.
73    * @return True if the task is ready to process.
74    */
75   bool IsReady() override;
76
77 private:
78   // Undefined
79   FastTrackLoadingTask(const FastTrackLoadingTask& queue) = delete;
80   FastTrackLoadingTask& operator=(const FastTrackLoadingTask& queue) = delete;
81
82   /**
83    * @brief Create textures for this task.
84    * @note This should be called in construct timing.
85    */
86   void PrepareTexture();
87
88   /**
89    * @brief Load the image.
90    */
91   void Load();
92
93   /**
94    * @brief Multiply alpha if required.
95    *
96    * @param[in,out] pixelBuffer target pixel buffer that need to be multiplied alpha.
97    */
98   void MultiplyAlpha(Dali::Devel::PixelBuffer pixelBuffer);
99
100   /**
101    * @brief Upload loaded pixelBuffer into texture
102    */
103   void UploadToTexture();
104
105 private:
106   /**
107    * @brief Complete callback.
108    *
109    * @param[in] task The pointer of task who call this callback.
110    */
111   void OnComplete(AsyncTaskPtr task);
112
113 public:
114   VisualUrl                  mUrl;      ///< url of the image to load.
115   std::vector<Dali::Texture> mTextures; ///< textures for regular image.
116
117 private:
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;
123
124   // Texture Upload relative API
125   Dali::Devel::TextureUploadManager mTextureUploadManager;
126
127   // Note : mPixelData is invalid after upload requested. We should keep image size informations.
128   struct ImageInformation
129   {
130     uint32_t resourceId;
131
132     uint32_t      width;
133     uint32_t      height;
134     Pixel::Format format;
135   };
136   std::vector<ImageInformation> mImageInformations;
137
138   std::vector<Dali::PixelData> mPixelData;
139
140   bool mOrientationCorrection : 1; ///< If orientation correction is needed
141
142 public:
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.
147 };
148
149 } // namespace Internal
150
151 } // namespace Toolkit
152
153 } // namespace Dali
154
155 #endif // DALI_TOOLKIT_FAST_TRACK_IMAGE_LOADING_TASK_H