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 mThreadImage = new ResourceThreadImage( resourceLoader );
32 mThreadDistanceField = new ResourceThreadDistanceField( resourceLoader );
35 ResourceBitmapRequester::~ResourceBitmapRequester()
38 delete mThreadDistanceField;
41 void ResourceBitmapRequester::Pause()
43 mThreadImage->Pause();
44 mThreadDistanceField->Pause();
47 void ResourceBitmapRequester::Resume()
49 mThreadImage->Resume();
50 mThreadDistanceField->Resume();
53 void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
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());
59 // Work out if the resource is in memory or a file:
60 const ResourceThreadBase::RequestType requestType = request.GetResource().Get() ? ResourceThreadBase::RequestDecode : ResourceThreadBase::RequestLoad;
62 // Work out what thread to decode / load the image on:
63 ResourceThreadBase* const imageThread = mThreadImage;
64 ResourceThreadBase* const distanceFieldThread = mThreadDistanceField ;
65 ResourceThreadBase* const workerThread = ( !resType->imageAttributes.IsDistanceField() ) ? imageThread : distanceFieldThread;
67 // Dispatch the job to the right thread:
68 workerThread->AddRequest( request, requestType );
72 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
75 return RESOURCE_COMPLETELY_LOADED;
78 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
83 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
85 mThreadImage->CancelRequest(id);
86 mThreadDistanceField->CancelRequest(id);
89 Integration::ResourcePointer ResourceBitmapRequester::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
91 // TODO - Refactor common code out of thread
92 return mThreadImage->LoadResourceSynchronously( resourceType, resourcePath );
95 void ResourceBitmapRequester::GetClosestImageSize( const std::string& filename,
96 const ImageAttributes& attributes,
97 Vector2 &closestSize )
99 // TODO - Refactor common code out of thread
100 mThreadImage->GetClosestImageSize(filename, attributes, closestSize );
103 void ResourceBitmapRequester::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
104 const ImageAttributes& attributes,
105 Vector2 &closestSize )
107 // TODO - Refactor common code out of thread
108 mThreadImage->GetClosestImageSize(resourceBuffer, attributes, closestSize );