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/devel-api/adaptor-framework/bitmap-loader.h>
23 #include <dali/integration-api/adaptors/adaptor.h>
34 AsyncImageLoader::AsyncImageLoader()
36 mLoadThread( new EventThreadCallback( MakeCallback( this, &AsyncImageLoader::ProcessLoadedImage ) ) ),
38 mIsLoadThreadStarted( false )
42 AsyncImageLoader::~AsyncImageLoader()
44 mLoadThread.CancelAll();
47 IntrusivePtr<AsyncImageLoader> AsyncImageLoader::New()
49 IntrusivePtr<AsyncImageLoader> internal = new AsyncImageLoader();
53 uint32_t AsyncImageLoader::Load( const std::string& url,
55 FittingMode::Type fittingMode,
56 SamplingMode::Type samplingMode,
57 bool orientationCorrection )
59 if( !mIsLoadThreadStarted )
62 mIsLoadThreadStarted = true;
65 BitmapLoader loader = BitmapLoader::New( url, size, fittingMode, samplingMode, orientationCorrection );
67 mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, loader ) );
72 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
77 bool AsyncImageLoader::Cancel( uint32_t loadingTaskId )
79 return mLoadThread.CancelTask( loadingTaskId );
82 void AsyncImageLoader::CancelAll()
84 mLoadThread.CancelAll();
87 void AsyncImageLoader::ProcessLoadedImage()
89 while( LoadingTask *next = mLoadThread.NextCompletedTask() )
91 mLoadedSignal.Emit( next->id, next->loader.GetPixelData() );
96 } // namespace Internal
98 } // namespace Toolkit