2 * Copyright (c) 2014 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.
18 #include "resource-bitmap-requester.h"
19 #include <dali/integration-api/resource-cache.h>
21 using namespace Dali::Integration;
28 ResourceBitmapRequester::ResourceBitmapRequester( ResourceLoader& resourceLoader )
29 : ResourceRequesterBase( resourceLoader )
31 mThreadImageLocal = new ResourceThreadImage( resourceLoader, false );
32 mThreadImageRemote = new ResourceThreadImage( resourceLoader, true );
33 mThreadDistanceField = new ResourceThreadDistanceField( resourceLoader );
36 ResourceBitmapRequester::~ResourceBitmapRequester()
38 delete mThreadImageLocal;
39 delete mThreadImageRemote;
40 delete mThreadDistanceField;
43 void ResourceBitmapRequester::Pause()
45 mThreadImageLocal->Pause();
46 mThreadImageRemote->Pause();
47 mThreadDistanceField->Pause();
50 void ResourceBitmapRequester::Resume()
52 mThreadImageLocal->Resume();
53 mThreadImageRemote->Resume();
54 mThreadDistanceField->Resume();
57 void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
59 DALI_ASSERT_DEBUG( (0 != dynamic_cast<BitmapResourceType*>(request.GetType())) && "Only requsts for bitmap resources can ever be routed to ResourceBitmapRequester.\n");
60 BitmapResourceType* resType = static_cast<BitmapResourceType*>(request.GetType());
63 // Work out what thread to decode / load the image on:
64 ResourceThreadBase* const localImageThread = mThreadImageLocal;
65 ResourceThreadBase* const remoteImageThread = mThreadImageRemote;
66 ResourceThreadBase* const distanceFieldThread = mThreadDistanceField ;
67 ResourceThreadBase* workerThread;
69 // Work out if the resource is in memory, a file, or in a remote server:
70 ResourceThreadBase::RequestType requestType;
71 if( request.GetResource().Get() )
73 requestType = ResourceThreadBase::RequestDecode;
74 workerThread = localImageThread;
78 const std::string& resourcePath = request.GetPath();
79 if( resourcePath.length() > 7 && strncasecmp( resourcePath.c_str(), "http://", 7 ) == 0 )
81 requestType = ResourceThreadBase::RequestDownload;
82 workerThread = remoteImageThread;
86 requestType = ResourceThreadBase::RequestLoad;
87 workerThread = localImageThread;
91 if( resType->imageAttributes.IsDistanceField() )
93 workerThread = distanceFieldThread;
96 // Dispatch the job to the right thread:
97 workerThread->AddRequest( request, requestType );
101 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
104 return RESOURCE_COMPLETELY_LOADED;
107 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
112 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
114 mThreadImageLocal->CancelRequest(id);
115 mThreadImageRemote->CancelRequest(id);
116 mThreadDistanceField->CancelRequest(id);