2 * Copyright (c) 2020 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>
33 AsyncImageLoader::AsyncImageLoader()
35 mLoadThread( new EventThreadCallback( MakeCallback( this, &AsyncImageLoader::ProcessLoadedImage ) ) ),
37 mIsLoadThreadStarted( false )
41 AsyncImageLoader::~AsyncImageLoader()
43 mLoadThread.CancelAll();
46 IntrusivePtr<AsyncImageLoader> AsyncImageLoader::New()
48 IntrusivePtr<AsyncImageLoader> internal = new AsyncImageLoader();
52 uint32_t AsyncImageLoader::LoadAnimatedImage( Dali::AnimatedImageLoading animatedImageLoading,
55 if( !mIsLoadThreadStarted )
58 mIsLoadThreadStarted = true;
60 mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, animatedImageLoading, frameIndex ) );
65 uint32_t AsyncImageLoader::Load( const VisualUrl& url,
66 ImageDimensions dimensions,
67 FittingMode::Type fittingMode,
68 SamplingMode::Type samplingMode,
69 bool orientationCorrection,
70 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
72 if( !mIsLoadThreadStarted )
75 mIsLoadThreadStarted = true;
77 mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection, preMultiplyOnLoad ) );
82 uint32_t AsyncImageLoader::ApplyMask( Devel::PixelBuffer pixelBuffer,
83 Devel::PixelBuffer maskPixelBuffer,
86 DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
88 if( !mIsLoadThreadStarted )
91 mIsLoadThreadStarted = true;
93 mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad ) );
98 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
100 return mLoadedSignal;
103 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
105 return mPixelBufferLoadedSignal;
108 bool AsyncImageLoader::Cancel( uint32_t loadingTaskId )
110 return mLoadThread.CancelTask( loadingTaskId );
113 void AsyncImageLoader::CancelAll()
115 mLoadThread.CancelAll();
118 void AsyncImageLoader::ProcessLoadedImage()
120 while( LoadingTask *next = mLoadThread.NextCompletedTask() )
122 if( mPixelBufferLoadedSignal.GetConnectionCount() > 0 )
124 mPixelBufferLoadedSignal.Emit( next->id, next->pixelBuffer );
126 else if( mLoadedSignal.GetConnectionCount() > 0 )
129 if( next->pixelBuffer )
131 pixelData = Devel::PixelBuffer::Convert( next->pixelBuffer );
133 mLoadedSignal.Emit( next->id, pixelData );
140 } // namespace Internal
142 } // namespace Toolkit