2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "async-image-loader-impl.h"
22 #include <dali/integration-api/adaptor-framework/adaptor.h>
30 AsyncImageLoader::AsyncImageLoader()
32 mLoadThread(new EventThreadCallback(MakeCallback(this, &AsyncImageLoader::ProcessLoadedImage))),
34 mIsLoadThreadStarted(false)
38 AsyncImageLoader::~AsyncImageLoader()
40 mLoadThread.CancelAll();
43 IntrusivePtr<AsyncImageLoader> AsyncImageLoader::New()
45 IntrusivePtr<AsyncImageLoader> internal = new AsyncImageLoader();
49 uint32_t AsyncImageLoader::LoadAnimatedImage(Dali::AnimatedImageLoading animatedImageLoading,
51 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
53 if(!mIsLoadThreadStarted)
56 mIsLoadThreadStarted = true;
58 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex, preMultiplyOnLoad));
63 uint32_t AsyncImageLoader::Load(const VisualUrl& url,
64 ImageDimensions dimensions,
65 FittingMode::Type fittingMode,
66 SamplingMode::Type samplingMode,
67 bool orientationCorrection,
68 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad,
71 if(!mIsLoadThreadStarted)
74 mIsLoadThreadStarted = true;
76 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad, loadPlanes));
81 uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
82 ImageDimensions dimensions,
83 FittingMode::Type fittingMode,
84 SamplingMode::Type samplingMode,
85 bool orientationCorrection,
86 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
88 if(!mIsLoadThreadStarted)
91 mIsLoadThreadStarted = true;
93 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
98 uint32_t AsyncImageLoader::ApplyMask(Devel::PixelBuffer pixelBuffer,
99 Devel::PixelBuffer maskPixelBuffer,
102 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
104 if(!mIsLoadThreadStarted)
107 mIsLoadThreadStarted = true;
109 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad));
114 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
116 return mLoadedSignal;
119 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
121 return mPixelBufferLoadedSignal;
124 bool AsyncImageLoader::Cancel(uint32_t loadingTaskId)
126 return mLoadThread.CancelTask(loadingTaskId);
129 void AsyncImageLoader::CancelAll()
131 mLoadThread.CancelAll();
134 void AsyncImageLoader::ProcessLoadedImage()
136 while(LoadingTask* next = mLoadThread.NextCompletedTask())
138 if(mPixelBufferLoadedSignal.GetConnectionCount() > 0)
140 mPixelBufferLoadedSignal.Emit(next->id, next->pixelBuffers);
142 else if(mLoadedSignal.GetConnectionCount() > 0)
145 if(!next->pixelBuffers.empty())
147 pixelData = Devel::PixelBuffer::Convert(next->pixelBuffers[0]);
149 mLoadedSignal.Emit(next->id, pixelData);
156 } // namespace Internal
158 } // namespace Toolkit