1 #ifndef DALI_TOOLKIT_IMAGE_LOAD_THREAD_H
2 #define DALI_TOOLKIT_IMAGE_LOAD_THREAD_H
5 * Copyright (c) 2020 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/public-api/common/dali-vector.h>
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/devel-api/threading/conditional-wait.h>
25 #include <dali/devel-api/threading/mutex.h>
26 #include <dali/devel-api/threading/thread.h>
27 #include <dali/devel-api/adaptor-framework/event-thread-callback.h>
28 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30 #include <dali-toolkit/devel-api/image-loader/async-image-loader-devel.h>
31 #include <dali/integration-api/adaptor-framework/log-factory-interface.h>
43 * The task of loading and packing an image into the atlas.
49 * @param [in] id of the task
50 * @param [in] animatedImageLoading The AnimatedImageLoading to load animated image
51 * @param [in] frameIndex The frame index of a frame to be loaded frame
53 LoadingTask( uint32_t id,
54 Dali::AnimatedImageLoading animatedImageLoading,
55 uint32_t frameIndex );
59 * @param [in] id of the task
60 * @param [in] url The URL of the image file to load.
61 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
62 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
63 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
64 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
65 * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
67 LoadingTask( uint32_t id,
69 ImageDimensions dimensions,
70 FittingMode::Type fittingMode,
71 SamplingMode::Type samplingMode,
72 bool orientationCorrection,
73 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
77 * @param [in] id of the task
78 * @param [in] pixelBuffer of the to be masked image
79 * @param [in] maskPixelBuffer of the mask image
80 * @param [in] contentScale The factor to scale the content
81 * @param [in] cropToMask Whether to crop the content to the mask size
82 * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
84 LoadingTask( uint32_t id,
85 Devel::PixelBuffer pixelBuffer,
86 Devel::PixelBuffer maskPixelBuffer,
89 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
104 void MultiplyAlpha();
109 LoadingTask( const LoadingTask& queue );
112 LoadingTask& operator=( const LoadingTask& queue );
116 Devel::PixelBuffer pixelBuffer; ///< pixelBuffer handle after successful load
117 ///< or pixelBuffer to be masked image in the mask task
118 VisualUrl url; ///< url of the image to load
119 uint32_t id; ///< The unique id associated with this task.
120 ImageDimensions dimensions; ///< dimensions to load
121 FittingMode::Type fittingMode; ///< fitting options
122 SamplingMode::Type samplingMode; ///< sampling options
123 bool orientationCorrection:1; ///< if orientation correction is needed
124 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad; //< if the image's color should be multiplied by it's alpha
126 bool isMaskTask; ///< whether this task is for mask or not
127 Devel::PixelBuffer maskPixelBuffer; ///< pixelBuffer of mask image
128 float contentScale; ///< The factor to scale the content
129 bool cropToMask; ///< Whether to crop the content to the mask size
130 Dali::AnimatedImageLoading animatedImageLoading;
136 * The worker thread for image loading.
138 class ImageLoadThread : public Thread
145 * @param[in] mTrigger The trigger to wake up the main thread.
147 ImageLoadThread( EventThreadCallback* mTrigger );
152 virtual ~ImageLoadThread();
155 * Add a task in to the loading queue
157 * @param[in] task The task added to the queue.
159 * @note This class takes ownership of the task object
161 void AddTask( LoadingTask* task );
164 * Pop the next task out from the completed queue.
166 * @return The next task to be processed.
168 LoadingTask* NextCompletedTask();
171 * Remove the loading task from the waiting queue.
173 bool CancelTask( uint32_t loadingTaskId );
176 * Remove all the loading tasks in the waiting queue.
183 * Pop the next loading task out from the queue to process.
185 * @return The next task to be processed.
187 LoadingTask* NextTaskToProcess();
190 * Add a task in to the loading queue
192 * @param[in] task The task added to the queue.
194 void AddCompletedTask( LoadingTask* task );
199 * The entry function of the worker thread.
200 * It fetches loading task from the loadQueue, loads the image and adds to the completeQueue.
207 ImageLoadThread( const ImageLoadThread& thread );
210 ImageLoadThread& operator=( const ImageLoadThread& thread );
214 Vector< LoadingTask* > mLoadQueue; ///<The task queue with images for loading.
215 Vector< LoadingTask* > mCompleteQueue; ///<The task queue with images loaded.
216 EventThreadCallback* mTrigger;
217 const Dali::LogFactoryInterface& mLogFactory; ///< The log factory
219 ConditionalWait mConditionalWait;
223 } // namespace Internal
225 } // namespace Toolkit
229 #endif // DALI_TOOLKIT_IMAGE_LOAD_THREAD_H