2 * Copyright (c) 2021 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,
52 if(!mIsLoadThreadStarted)
55 mIsLoadThreadStarted = true;
57 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, animatedImageLoading, frameIndex));
62 uint32_t AsyncImageLoader::Load(const VisualUrl& url,
63 ImageDimensions dimensions,
64 FittingMode::Type fittingMode,
65 SamplingMode::Type samplingMode,
66 bool orientationCorrection,
67 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
69 if(!mIsLoadThreadStarted)
72 mIsLoadThreadStarted = true;
74 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
79 uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
80 ImageDimensions dimensions,
81 FittingMode::Type fittingMode,
82 SamplingMode::Type samplingMode,
83 bool orientationCorrection,
84 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
86 if(!mIsLoadThreadStarted)
89 mIsLoadThreadStarted = true;
91 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
96 uint32_t AsyncImageLoader::ApplyMask(Devel::PixelBuffer pixelBuffer,
97 Devel::PixelBuffer maskPixelBuffer,
100 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
102 if(!mIsLoadThreadStarted)
105 mIsLoadThreadStarted = true;
107 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad));
112 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
114 return mLoadedSignal;
117 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
119 return mPixelBufferLoadedSignal;
122 bool AsyncImageLoader::Cancel(uint32_t loadingTaskId)
124 return mLoadThread.CancelTask(loadingTaskId);
127 void AsyncImageLoader::CancelAll()
129 mLoadThread.CancelAll();
132 void AsyncImageLoader::ProcessLoadedImage()
134 while(LoadingTask* next = mLoadThread.NextCompletedTask())
136 if(mPixelBufferLoadedSignal.GetConnectionCount() > 0)
138 mPixelBufferLoadedSignal.Emit(next->id, next->pixelBuffer);
140 else if(mLoadedSignal.GetConnectionCount() > 0)
143 if(next->pixelBuffer)
145 pixelData = Devel::PixelBuffer::Convert(next->pixelBuffer);
147 mLoadedSignal.Emit(next->id, pixelData);
154 } // namespace Internal
156 } // namespace Toolkit