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::ApplyMask(Devel::PixelBuffer pixelBuffer,
80 Devel::PixelBuffer maskPixelBuffer,
83 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
85 if(!mIsLoadThreadStarted)
88 mIsLoadThreadStarted = true;
90 mLoadThread.AddTask(new LoadingTask(++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad));
95 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
100 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
102 return mPixelBufferLoadedSignal;
105 bool AsyncImageLoader::Cancel(uint32_t loadingTaskId)
107 return mLoadThread.CancelTask(loadingTaskId);
110 void AsyncImageLoader::CancelAll()
112 mLoadThread.CancelAll();
115 void AsyncImageLoader::ProcessLoadedImage()
117 while(LoadingTask* next = mLoadThread.NextCompletedTask())
119 if(mPixelBufferLoadedSignal.GetConnectionCount() > 0)
121 mPixelBufferLoadedSignal.Emit(next->id, next->pixelBuffer);
123 else if(mLoadedSignal.GetConnectionCount() > 0)
126 if(next->pixelBuffer)
128 pixelData = Devel::PixelBuffer::Convert(next->pixelBuffer);
130 mLoadedSignal.Emit(next->id, pixelData);
137 } // namespace Internal
139 } // namespace Toolkit