2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include "resource-bitmap-requester.h"
18 #include <dali/integration-api/resource-cache.h>
20 using namespace Dali::Integration;
27 ResourceBitmapRequester::ResourceBitmapRequester( ResourceLoader& resourceLoader )
28 : ResourceRequesterBase( resourceLoader )
30 mThreadImage = new ResourceThreadImage( resourceLoader );
31 mThreadDistanceField = new ResourceThreadDistanceField( resourceLoader );
34 ResourceBitmapRequester::~ResourceBitmapRequester()
37 delete mThreadDistanceField;
40 void ResourceBitmapRequester::Pause()
42 mThreadImage->Pause();
43 mThreadDistanceField->Pause();
46 void ResourceBitmapRequester::Resume()
48 mThreadImage->Resume();
49 mThreadDistanceField->Resume();
52 void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
54 DALI_ASSERT_DEBUG( (0 != dynamic_cast<ImageResourceType*>(request.GetType())) && "Only requsts for bitmap resources can ever be routed to ResourceBitmapRequester.\n");
55 ImageResourceType* resType = static_cast<ImageResourceType*>(request.GetType());
58 // Work out if the resource is in memory or a file:
59 const ResourceThreadBase::RequestType requestType = request.GetResource().Get() ? ResourceThreadBase::RequestDecode : ResourceThreadBase::RequestLoad;
61 // Work out what thread to decode / load the image on:
62 ResourceThreadBase* const imageThread = mThreadImage;
63 ResourceThreadBase* const distanceFieldThread = mThreadDistanceField ;
64 ResourceThreadBase* const workerThread = ( !resType->imageAttributes.IsDistanceField() ) ? imageThread : distanceFieldThread;
66 // Dispatch the job to the right thread:
67 workerThread->AddRequest( request, requestType );
71 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
74 return RESOURCE_COMPLETELY_LOADED;
77 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
82 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
84 mThreadImage->CancelRequest(id);
85 mThreadDistanceField->CancelRequest(id);
88 Integration::ResourcePointer ResourceBitmapRequester::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
90 // TODO - Refactor common code out of thread
91 return mThreadImage->LoadResourceSynchronously( resourceType, resourcePath );
94 void ResourceBitmapRequester::GetClosestImageSize( const std::string& filename,
95 const ImageAttributes& attributes,
96 Vector2 &closestSize )
98 // TODO - Refactor common code out of thread
99 mThreadImage->GetClosestImageSize(filename, attributes, closestSize );
102 void ResourceBitmapRequester::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
103 const ImageAttributes& attributes,
104 Vector2 &closestSize )
106 // TODO - Refactor common code out of thread
107 mThreadImage->GetClosestImageSize(resourceBuffer, attributes, closestSize );