Added support for loading image files synchronously
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / slp / slp-platform-abstraction.h
1 #ifndef __DALI_SLP_PLATFORM_ABSTRACTION_H__
2 #define __DALI_SLP_PLATFORM_ABSTRACTION_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 #include <dali/integration-api/platform-abstraction.h>
21 #include <dali/integration-api/resource-cache.h>
22 #include <dali/public-api/common/dali-common.h>
23
24 #include <ft2build.h>
25 #include FT_FREETYPE_H
26 #include <string>
27
28 namespace Dali
29 {
30
31 /**
32  * Construct a platform abstraction and return it.
33  */
34 DALI_IMPORT_API Integration::PlatformAbstraction* CreatePlatformAbstraction();
35
36 namespace SlpPlatform
37 {
38
39 class DynamicsFactory;
40 class ResourceLoader;
41
42 /**
43  * Concrete implementation of the platform abstraction class.
44  */
45 class SlpPlatformAbstraction : public Integration::PlatformAbstraction
46 {
47
48 public: // Construction & Destruction
49
50   /**
51    * Constructor
52    */
53   SlpPlatformAbstraction();
54
55   /**
56    * Destructor
57    */
58   virtual ~SlpPlatformAbstraction();
59
60 public: // PlatformAbstraction overrides
61
62   /**
63    * @copydoc PlatformAbstraction::GetTimeMicroseconds()
64    */
65   virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
66
67   /**
68    * @copydoc PlatformAbstraction::Suspend()
69    */
70   virtual void Suspend();
71
72   /**
73    * @copydoc PlatformAbstraction::Resume()
74    */
75   virtual void Resume();
76
77   /**
78    * @copydoc PlatformAbstraction::GetClosestImageSize()
79    */
80   virtual void GetClosestImageSize( const std::string& filename,
81                                     const ImageAttributes& attributes,
82                                     Vector2& closestSize );
83
84   /**
85    * @copydoc PlatformAbstraction::GetClosestImageSize()
86    */
87   virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
88                                     const ImageAttributes& attributes,
89                                     Vector2& closestSize );
90
91   /**
92    * @copydoc PlatformAbstraction::LoadResource()
93    */
94   virtual void LoadResource(const Integration::ResourceRequest& request);
95
96   /**
97    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
98    */
99   virtual Integration::ResourcePointer LoadResourceSynchronously(const Integration::ResourceType& resourceType, const std::string& resourcePath);
100
101   /**
102    * @copydoc PlatformAbstraction::SaveResource()
103    */
104   virtual void SaveResource(const Integration::ResourceRequest& request);
105
106   /**
107    * @copydoc PlatformAbstraction::CancelLoad()
108    */
109   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
110
111   /**
112    * @copydoc PlatformAbstraction::GetResources()
113    */
114   virtual void GetResources(Integration::ResourceCache& cache);
115
116   /**
117    * @copydoc PlatformAbstraction::IsLoading()
118    */
119   virtual bool IsLoading();
120
121   /**
122    * @copydoc PlatformAbstraction::JoinLoaderThreads()
123    */
124   virtual void JoinLoaderThreads();
125
126   /**
127    *@copydoc PlatformAbstraction::GetDefaultFontFamily()
128    */
129   virtual std::string GetDefaultFontFamily() const;
130
131   /**
132    *@copydoc PlatformAbstraction::GetDefaultFontSize()
133    */
134   virtual const float GetDefaultFontSize() const;
135
136   /**
137    *@copydoc PlatformAbstraction::GetFontLineHeightFromCapsHeight()
138    */
139   virtual const PixelSize GetFontLineHeightFromCapsHeight(const std::string fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const;
140
141   /**
142    * @copydoc PlatformAbstraction::GetGlyphData()
143    */
144   virtual Integration::GlyphSet* GetGlyphData ( const Dali::Integration::TextResourceType& textRequest,
145                                                 const std::string& fontFamily,
146                                                 bool getBitmap) const;
147
148   /**
149    * @copydoc PlatformAbstraction::GetCachedGlyphData()
150    */
151   virtual Integration::GlyphSet* GetCachedGlyphData( const Integration::TextResourceType& textRequest,
152                                                      const std::string& fontFamily ) const;
153
154   /**
155    * @copydoc PlatformAbstraction::GetGlobalMetrics()
156    */
157   virtual void GetGlobalMetrics( const std::string& fontFamily,
158                                  const std::string& fontStyle,
159                                  Integration::GlobalMetrics& globalMetrics ) const;
160
161   /**
162    * @copydoc PlatformAbstraction::SetDpi()
163    */
164   virtual void SetDpi (unsigned int DpiHorizontal, unsigned int DpiVertical);
165
166   /**
167    * @copydoc PlatformAbstraction::GetFontFamilyForChars()
168    */
169   std::string GetFontFamilyForChars(const TextArray& charsRequested) const;
170
171   /**
172    * @copydoc PlatformAbstraction::AllGlyphsSupported()
173    */
174   bool AllGlyphsSupported(const std::string &fontFamily, const std::string& fontStyle, const TextArray& charsRequested) const;
175
176   /**
177    * @copydoc PlatformAbstraction::ValidateFontFamilyName()
178    */
179   virtual bool ValidateFontFamilyName(const std::string& fontFamily, const std::string& fontStyle, bool& isDefaultSystemFont, std::string& closestMatch, std::string& closestStyleMatch) const;
180
181   /**
182    * @copydoc PlatformAbstraction::GetFontList()
183    */
184   virtual std::vector<std::string> GetFontList ( Dali::Integration::PlatformAbstraction::FontListMode mode ) const;
185
186   /**
187    * @copydoc PlatformAbstraction::LoadFile()
188    */
189   virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
190
191   /**
192    * @copydoc PlatformAbstraction::LoadFile()
193    */
194   virtual std::string LoadFile( const std::string& filename );
195
196   /**
197    * @copydoc PlatformAbstraction::SaveFile()
198    */
199   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const;
200
201   /**
202    * @copydoc PlatformAbstraction::UpdateDefaultsFromDevice();
203    */
204   virtual void UpdateDefaultsFromDevice();
205
206   /**
207    * @copydoc PlatformAbstraction::GetDynamicsFactory();
208    */
209   virtual Integration::DynamicsFactory* GetDynamicsFactory();
210
211   /**
212    * @copydoc PlatformAbstraction::ReadGlobalMetricsFromCacheFile
213    */
214   virtual bool ReadGlobalMetricsFromCache( const std::string& fontFamily,
215                                            const std::string& fontStyle,
216                                            Integration::GlobalMetrics& globalMetrics );
217
218   /**
219    * @copydoc PlatformAbstraction::WriteGlobalMetricsToCacheFile
220    */
221   virtual void WriteGlobalMetricsToCache( const std::string& fontFamily,
222                                           const std::string& fontStyle,
223                                           const Integration::GlobalMetrics& globalMetrics );
224
225   /**
226    * @copydoc PlatformAbstraction::ReadMetricsFromCacheFile
227    */
228   virtual bool ReadMetricsFromCache( const std::string& fontFamily,
229                                      const std::string& fontStyle,
230                                      std::vector<Integration::GlyphMetrics>& glyphMetricsContainer );
231
232   /**
233    * @copydoc PlatformAbstraction::WriteMetricsToCacheFile
234    */
235   virtual void WriteMetricsToCache( const std::string& fontFamily,
236                                     const std::string& fontStyle,
237                                     const Integration::GlyphSet& glyphSet );
238
239 private:
240   ResourceLoader* mResourceLoader;
241   FT_Library mFreeTypeHandle;       ///< Freetype library
242   std::string mDefaultFontFamily;
243   std::string mDefaultFontStyle;
244   float mDefaultFontSize;
245   std::string mDefaultThemeFile;
246   DynamicsFactory* mDynamicsFactory;
247 };
248
249 }  // namespace SlpPlatform
250 }  // namespace Dali
251
252 #endif // __DALI_SLP_PLATFORM_ABSTRACTION_H__