Merge branch 'master' into tizen
[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   mThreadImage  = new ResourceThreadImage( resourceLoader );
32   mThreadDistanceField = new ResourceThreadDistanceField( resourceLoader );
33 }
34
35 ResourceBitmapRequester::~ResourceBitmapRequester()
36 {
37   delete mThreadImage;
38   delete mThreadDistanceField;
39 }
40
41 void ResourceBitmapRequester::Pause()
42 {
43   mThreadImage->Pause();
44   mThreadDistanceField->Pause();
45 }
46
47 void ResourceBitmapRequester::Resume()
48 {
49   mThreadImage->Resume();
50   mThreadDistanceField->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 if the resource is in memory or a file:
60     const ResourceThreadBase::RequestType requestType = request.GetResource().Get() ? ResourceThreadBase::RequestDecode : ResourceThreadBase::RequestLoad;
61
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;
66
67     // Dispatch the job to the right thread:
68     workerThread->AddRequest( request, requestType );
69   }
70 }
71
72 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
73 {
74   // Nothing to do
75   return RESOURCE_COMPLETELY_LOADED;
76 }
77
78 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
79 {
80   // Nothing to do
81 }
82
83 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
84 {
85   mThreadImage->CancelRequest(id);
86   mThreadDistanceField->CancelRequest(id);
87 }
88
89 Integration::ResourcePointer ResourceBitmapRequester::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
90 {
91   // TODO - Refactor common code out of thread
92   return mThreadImage->LoadResourceSynchronously( resourceType, resourcePath );
93 }
94
95 void ResourceBitmapRequester::GetClosestImageSize( const std::string& filename,
96                                                    const ImageAttributes& attributes,
97                                                    Vector2 &closestSize )
98 {
99   // TODO - Refactor common code out of thread
100   mThreadImage->GetClosestImageSize(filename, attributes, closestSize );
101 }
102
103 void ResourceBitmapRequester::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
104                                                    const ImageAttributes& attributes,
105                                                    Vector2 &closestSize )
106 {
107   // TODO - Refactor common code out of thread
108   mThreadImage->GetClosestImageSize(resourceBuffer, attributes, closestSize );
109 }
110
111 } // SlpPlatform
112 } // Dali