Dali 3D User Interface Engine
tizen-platform-abstraction.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 
19 
20 #ifndef DALI_PROFILE_UBUNTU
21 #include <vconf.h>
22 #endif // DALI_PROFILE_UBUNTU
23 #include <dirent.h>
24 
28 
29 // INTERNAL INCLUDES
32 #include "portable/file-closer.h"
33 
34 namespace Dali
35 {
36 
38 {
40 }
41 
42 
43 namespace TizenPlatform
44 {
45 
47 : mResourceLoader(new ResourceLoader),
48  mDataStoragePath( "" )
49 {
50 }
51 
53 {
54  delete mResourceLoader;
55 }
56 
58 {
59  if (mResourceLoader)
60  {
62  }
63 }
64 
66 {
67  if (mResourceLoader)
68  {
70  }
71 }
72 
74 {
75  int fontSize( -1 );
76 
77 #ifndef DALI_PROFILE_UBUNTU
78  vconf_get_int( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &fontSize );
79 #endif // DALI_PROFILE_UBUNTU
80 
81  return fontSize;
82 }
83 
85  ImageDimensions size,
86  FittingMode::Type fittingMode,
87  SamplingMode::Type samplingMode,
88  bool orientationCorrection )
89 {
90  return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
91 }
92 
94  ImageDimensions size,
95  FittingMode::Type fittingMode,
96  SamplingMode::Type samplingMode,
97  bool orientationCorrection )
98 {
99  return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
100 }
101 
103 {
104  if (mResourceLoader)
105  {
106  mResourceLoader->LoadResource(request);
107  }
108 }
109 
111 {
112  return ImageLoader::LoadResourceSynchronously( resourceType, resourcePath );
113 }
114 
116 {
117  Integration::BitmapPtr bitmap = 0;
118 
119  Dali::Internal::Platform::FileCloser fileCloser( buffer, size, "rb" );
120  FILE * const fp = fileCloser.GetFile();
121  if( fp )
122  {
123  bool result = ImageLoader::ConvertStreamToBitmap( resourceType, "", fp, StubbedResourceLoadingClient(), bitmap );
124  if ( !result || !bitmap )
125  {
126  bitmap.Reset();
127  DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
128  }
129  }
130 
131  return bitmap;
132 }
133 
135 {
136  if (mResourceLoader)
137  {
138  mResourceLoader->CancelLoad(id, typeId);
139  }
140 }
141 
143 {
144  if (mResourceLoader)
145  {
147  }
148 }
149 
150 bool TizenPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
151 {
152  bool result = false;
153 
154  if( mResourceLoader )
155  {
156  result = mResourceLoader->LoadFile( filename, buffer );
157  }
158 
159  return result;
160 }
161 
162 std::string TizenPlatformAbstraction::LoadFile( const std::string& filename )
163 {
164  std::string result;
165  if (mResourceLoader)
166  {
167  result = mResourceLoader->LoadFile(filename);
168  }
169 
170  return result;
171 }
172 
174 {
175  delete mResourceLoader;
176  mResourceLoader = NULL;
177 }
178 
179 bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
180 {
181  bool result = false;
182 
183 #ifdef SHADERBIN_CACHE_ENABLED
184  std::string path;
185 
186  // First check the system location where shaders are stored at install time:
187  if( mResourceLoader )
188  {
189  path = DALI_SHADERBIN_DIR;
190  path += filename;
191  result = mResourceLoader->LoadFile( path, buffer );
192  }
193 
194  // Fallback to the cache of shaders stored after previous runtime compilations:
195  // On desktop this looks in the current working directory that the app was launched from.
196  if( mResourceLoader && result == false )
197  {
198  path = mDataStoragePath;
199  path += filename;
200  result = mResourceLoader->LoadFile( path, buffer );
201  }
202 #endif
203 
204  return result;
205 }
206 
207 bool TizenPlatformAbstraction::SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
208 {
209  bool result = false;
210 
211 #ifdef SHADERBIN_CACHE_ENABLED
212 
213  // Fallback to the cache of shaders stored after previous runtime compilations:
214  // On desktop this looks in the current working directory that the app was launched from.
215  if( mResourceLoader )
216  {
217  std::string path = mDataStoragePath;
218  path += filename;
219  result = mResourceLoader->SaveFile( path, buffer, numBytes );
220  }
221 #endif
222 
223  return result;
224 }
225 
226 void TizenPlatformAbstraction::SetDataStoragePath( const std::string& path )
227 {
228  mDataStoragePath = path;
229 }
230 
231 } // namespace TizenPlatform
232 
233 } // namespace Dali
Dali Docs Home
Read more about Dali