Merge "Stop copying Property::Maps in ImageView SetProperty" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / image-loader / async-image-loader-impl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "async-image-loader-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/adaptors/adaptor.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal
31 {
32
33 AsyncImageLoader::AsyncImageLoader()
34 : mLoadedSignal(),
35   mLoadThread( new EventThreadCallback( MakeCallback( this, &AsyncImageLoader::ProcessLoadedImage ) ) ),
36   mLoadTaskId( 0u ),
37   mIsLoadThreadStarted( false )
38 {
39 }
40
41 AsyncImageLoader::~AsyncImageLoader()
42 {
43   mLoadThread.CancelAll();
44 }
45
46 IntrusivePtr<AsyncImageLoader> AsyncImageLoader::New()
47 {
48   IntrusivePtr<AsyncImageLoader> internal = new AsyncImageLoader();
49   return internal;
50 }
51
52 uint32_t AsyncImageLoader::Load( const std::string& url,
53                                  ImageDimensions dimensions,
54                                  FittingMode::Type fittingMode,
55                                  SamplingMode::Type samplingMode,
56                                  bool orientationCorrection )
57 {
58   if( !mIsLoadThreadStarted )
59   {
60     mLoadThread.Start();
61     mIsLoadThreadStarted = true;
62   }
63
64   mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, url, dimensions, fittingMode, samplingMode, orientationCorrection ) );
65
66   return mLoadTaskId;
67 }
68
69 Toolkit::AsyncImageLoader::ImageLoadedSignalType& AsyncImageLoader::ImageLoadedSignal()
70 {
71   return mLoadedSignal;
72 }
73
74 bool AsyncImageLoader::Cancel( uint32_t loadingTaskId )
75 {
76   return mLoadThread.CancelTask( loadingTaskId );
77 }
78
79 void AsyncImageLoader::CancelAll()
80 {
81   mLoadThread.CancelAll();
82 }
83
84 void AsyncImageLoader::ProcessLoadedImage()
85 {
86   while( LoadingTask *next =  mLoadThread.NextCompletedTask() )
87   {
88     mLoadedSignal.Emit( next->id, next->pixelData );
89     delete next;
90   }
91 }
92
93 } // namespace Internal
94
95 } // namespace Toolkit
96
97 } // namespace Dali