Remove ResourceThreadDistanceField
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / slp / resource-loader / resource-bitmap-requester.cpp
1 /*
2  * Copyright (c) 2014 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 #include "resource-bitmap-requester.h"
19 #include <dali/integration-api/resource-cache.h>
20
21 using namespace Dali::Integration;
22
23 namespace Dali
24 {
25 namespace SlpPlatform
26 {
27
28 ResourceBitmapRequester::ResourceBitmapRequester( ResourceLoader& resourceLoader )
29 : ResourceRequesterBase( resourceLoader )
30 {
31   mThreadImageLocal  = new ResourceThreadImage( resourceLoader, false );
32   mThreadImageRemote  = new ResourceThreadImage( resourceLoader, true );
33 }
34
35 ResourceBitmapRequester::~ResourceBitmapRequester()
36 {
37   delete mThreadImageLocal;
38   delete mThreadImageRemote;
39 }
40
41 void ResourceBitmapRequester::Pause()
42 {
43   mThreadImageLocal->Pause();
44   mThreadImageRemote->Pause();
45 }
46
47 void ResourceBitmapRequester::Resume()
48 {
49   mThreadImageLocal->Resume();
50   mThreadImageRemote->Resume();
51 }
52
53 void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
54 {
55   DALI_ASSERT_DEBUG( (0 != dynamic_cast<BitmapResourceType*>(request.GetType())) && "Only requsts for bitmap resources can ever be routed to ResourceBitmapRequester.\n");
56   BitmapResourceType* resType = static_cast<BitmapResourceType*>(request.GetType());
57   if( resType )
58   {
59     // Work out what thread to decode / load the image on:
60     ResourceThreadBase* const localImageThread = mThreadImageLocal;
61     ResourceThreadBase* const remoteImageThread = mThreadImageRemote;
62     ResourceThreadBase* workerThread;
63
64     // Work out if the resource is in memory, a file, or in a remote server:
65     ResourceThreadBase::RequestType requestType;
66     if( request.GetResource().Get() )
67     {
68       requestType = ResourceThreadBase::RequestDecode;
69       workerThread = localImageThread;
70     }
71     else
72     {
73       const std::string& resourcePath = request.GetPath();
74       if( resourcePath.length() > 7 && strncasecmp( resourcePath.c_str(), "http://", 7 ) == 0 )
75       {
76         requestType = ResourceThreadBase::RequestDownload;
77         workerThread = remoteImageThread;
78       }
79       else
80       {
81         requestType = ResourceThreadBase::RequestLoad;
82         workerThread = localImageThread;
83       }
84     }
85
86     // Dispatch the job to the right thread:
87     workerThread->AddRequest( request, requestType );
88   }
89 }
90
91 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
92 {
93   // Nothing to do
94   return RESOURCE_COMPLETELY_LOADED;
95 }
96
97 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
98 {
99   // Nothing to do
100 }
101
102 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
103 {
104   mThreadImageLocal->CancelRequest(id);
105   mThreadImageRemote->CancelRequest(id);
106 }
107
108 } // SlpPlatform
109 } // Dali