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,
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)
70 if(!mIsLoadThreadStarted)
73 mIsLoadThreadStarted = true;
75 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
80 uint32_t AsyncImageLoader::LoadEncodedImageBuffer(const EncodedImageBuffer& encodedImageBuffer,
81 ImageDimensions dimensions,
82 FittingMode::Type fittingMode,
83 SamplingMode::Type samplingMode,
84 bool orientationCorrection,
85 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
87 if(!mIsLoadThreadStarted)
90 mIsLoadThreadStarted = true;
92 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, encodedImageBuffer, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad));
97 uint32_t AsyncImageLoader::ApplyMask(Devel::PixelBuffer pixelBuffer,
98 Devel::PixelBuffer maskPixelBuffer,
101 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
103 if(!mIsLoadThreadStarted)
106 mIsLoadThreadStarted = true;
108 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad));
113 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
115 return mLoadedSignal;
118 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
120 return mPixelBufferLoadedSignal;
123 bool AsyncImageLoader::Cancel(uint32_t loadingTaskId)
125 return mLoadThread.CancelTask(loadingTaskId);
128 void AsyncImageLoader::CancelAll()
130 mLoadThread.CancelAll();
133 void AsyncImageLoader::ProcessLoadedImage()
135 while(LoadingTask* next = mLoadThread.NextCompletedTask())
137 if(mPixelBufferLoadedSignal.GetConnectionCount() > 0)
139 mPixelBufferLoadedSignal.Emit(next->id, next->pixelBuffer);
141 else if(mLoadedSignal.GetConnectionCount() > 0)
144 if(next->pixelBuffer)
146 pixelData = Devel::PixelBuffer::Convert(next->pixelBuffer);
148 mLoadedSignal.Emit(next->id, pixelData);
155 } // namespace Internal
157 } // namespace Toolkit