2 * Copyright (c) 2016 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/adaptors/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::Load( const VisualUrl& url,
53 ImageDimensions dimensions,
54 FittingMode::Type fittingMode,
55 SamplingMode::Type samplingMode,
56 bool orientationCorrection )
58 if( !mIsLoadThreadStarted )
61 mIsLoadThreadStarted = true;
64 mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection ) );
69 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
74 Toolkit::DevelAsyncImageLoader::PixelBufferLoadedSignalType& AsyncImageLoader::PixelBufferLoadedSignal()
76 return mPixelBufferLoadedSignal;
79 bool AsyncImageLoader::Cancel( uint32_t loadingTaskId )
81 return mLoadThread.CancelTask( loadingTaskId );
84 void AsyncImageLoader::CancelAll()
86 mLoadThread.CancelAll();
89 void AsyncImageLoader::ProcessLoadedImage()
91 while( LoadingTask *next = mLoadThread.NextCompletedTask() )
93 if( mPixelBufferLoadedSignal.GetConnectionCount() > 0 )
95 mPixelBufferLoadedSignal.Emit( next->id, next->pixelBuffer );
97 else if( mLoadedSignal.GetConnectionCount() > 0 )
100 if( next->pixelBuffer )
102 pixelData = Devel::PixelBuffer::Convert( next->pixelBuffer );
104 mLoadedSignal.Emit( next->id, pixelData );
111 } // namespace Internal
113 } // namespace Toolkit