Merge "Increased precision of texture coordinate in textured mesh shader" into tizen
[platform/core/uifw/dali-core.git] / dali / integration-api / platform-abstraction.h
1 #ifndef __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__
2 #define __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/glyph-set.h>
23 #include <dali/integration-api/resource-cache.h>
24 #include <dali/integration-api/text-array.h>
25
26 namespace Dali
27 {
28
29 namespace Integration
30 {
31
32 class Bitmap;
33 class DynamicsFactory;
34
35
36 /**
37  * PlatformAbstraction is an abstract interface, used by Dali to access platform specific services.
38  * A concrete implementation must be created for each platform, and provided when creating the
39  * Dali::Integration::Core object.
40  */
41 class PlatformAbstraction
42 {
43 public:
44
45   virtual ~PlatformAbstraction() {}
46
47   // Dali Lifecycle
48
49   /**
50    * Get the monotonic time since an unspecified reference point.
51    * This is used by Dali to calculate time intervals during animations; the interval is
52    * recalculated when Dali is resumed with Dali::Integration::Core::Resume().
53    * Multi-threading note: this method may be called from either the main or rendering thread.
54    * @param[out] seconds The time in seconds since the reference point.
55    * @param[out] microSeconds The remainder in microseconds.
56    */
57   virtual void GetTimeMicroseconds(unsigned int& seconds, unsigned int& microSeconds) = 0;
58
59   /**
60    * Tell the platform abstraction that Dali is ready to pause, such as when the
61    * application enters a background state.
62    * Allows background threads to pause their work until Resume() is called.
63    * This is a good time to release recreatable data such as memory caches
64    * to cooperate with other apps and reduce the chance of this one being
65    * force-killed in a low memory situation.
66    */
67   virtual void Suspend() {} ///!ToDo: Make pure virtual once dali-adaptor patch is in place = 0;
68
69   /**
70    * Tell the platform abstraction that Dali is resuming from a pause, such as
71    * when it has transitioned from a background state to a foreground one.
72    * It is time to wake up sleeping background threads and recreate memory
73    * caches and other temporary data.
74    */
75   virtual void Resume() {} ///!ToDo: Make pure virtual once dali-adaptor patch is in place = 0;
76
77   // Resource Loading
78
79   /**
80    * Determine the size of an image the resource loaders will provide when given the same
81    * image attributes.
82    * This is a synchronous request.
83    * This function is used to determine the size of an image before it has loaded.
84    * @param[in] filename name of the image.
85    * @param[in] attributes The attributes used to load the image
86    * @param[out] closestSize Size of the image that will be loaded.
87    */
88   virtual void GetClosestImageSize( const std::string& filename,
89                                     const ImageAttributes& attributes,
90                                     Vector2& closestSize ) = 0;
91
92   /**
93    * Determine the size of an image the resource loaders will provide when given the same
94    * image attributes.
95    * This is a synchronous request.
96    * This function is used to determine the size of an image before it has loaded.
97    * @param[in] resourceBuffer A pointer to an encoded image buffer
98    * @param[in] attributes The attributes used to load the image
99    * @param[out] closestSize Size of the image that will be loaded.
100    */
101   virtual void GetClosestImageSize( ResourcePointer resourceBuffer,
102                                     const ImageAttributes& attributes,
103                                     Vector2& closestSize ) = 0;
104
105   /**
106    * Request a resource from the native filesystem. This is an asynchronous request.
107    * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
108    * resource loading operation. Loading resources in separate worker thread is recommended.
109    * Multi-threading note: this method will be called from the main thread only i.e. not
110    * from within the Core::Render() method.
111    * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
112    * returns; the loading process should take a copy.
113    */
114   virtual void LoadResource(const ResourceRequest& request) = 0;
115
116   /**
117    * Request a resource from the native filesystem. This is a synchronous request, i.e.
118    * it will block the main loop whilst executing. It should therefore be used sparingly.
119    *
120    * Multi-threading note: this method will be called from the main thread only i.e. not
121    * from within the Core::Render() method.
122    * @param[in] resourceType The type of resource to load
123    * @param[in] resourcePath The path to the resource
124    * @return A pointer to a ref-counted resource
125    */
126   virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
127
128   /**
129    * Request that a resource be saved to the native filesystem.
130    * This is an asynchronous request.
131    */
132   virtual void SaveResource(const ResourceRequest& request) = 0;
133   /**
134    * Cancel an ongoing LoadResource() request.
135    * Multi-threading note: this method will be called from the main thread only i.e. not
136    * from within the Core::Render() method.
137    * @param[in] id The ID of the resource to cancel.
138    * @param[in] typeId The ID type of the resource to cancel.
139    */
140   virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
141
142   /**
143    * Query whether any asynchronous LoadResource() requests are ongoing.
144    * Multi-threading note: this method may be called from either the main or rendering thread.
145    * @return True if resources are being loaded.
146    */
147   virtual bool IsLoading() = 0;
148
149   /**
150    * Retrieve newly loaded resources.
151    * If no resources have finished loading, then this method returns immediately.
152    * Multi-threading note: this method will be called from the update thread, from within
153    * the UpdateManager::Update() method.
154    * @param[in] cache The resource cache to fill.
155    */
156   virtual void GetResources(ResourceCache& cache) = 0;
157
158   /**
159    * Waits for the asynchronous loader threads (if any) to finish.
160    * This will be only be called before Core destruction; no resource loading requests will be
161    * made following this method.
162    */
163   virtual void JoinLoaderThreads() = 0;
164
165   // Font Queries
166
167   /**
168    * Called by Dali to retrieve the default font family for the platform.
169    * Multi-threading note: this method will be called from the main thread only i.e. not
170    * from within the Core::Render() method.
171    * @return The default font family.
172    */
173   virtual const std::string& GetDefaultFontFamily() const = 0;
174
175   /**
176    * Called by Dali to retrieve the default font size for the platform in points.
177    * Multi-threading note: this method will be called from the main thread only i.e. not
178    * from within the Core::Render() method.
179    * @return The default font size.
180    */
181   virtual float GetDefaultFontSize() const = 0;
182
183   /**
184    * Gets a font line height to match a given caps-height
185    *
186    * @note fontFamily and fontStyle must have been validated previously.
187    * @see ValidateFontFamilyName().
188    *
189    * @param[in] fontFamily The name of the font's family
190    * @param[in] fontStyle  The style of the font
191    * @param[in] capsHeight The caps-height in pixels
192    */
193   virtual PixelSize GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, CapsHeight capsHeight) const = 0;
194
195   /**
196    * Called by Font objects to synchronously query glyph data.
197    *
198    * @note fontFamily and font style, included in the resource request,  must have been validated previously.
199    * @see ValidateFontFamilyName().
200    *
201    * @note Font's style goes inside the textRequest parameter
202    * @param[in] textRequest  Resource request. Includes font's style.
203    * @param[in] fontFamily   The name of the font's family
204    * @param[in] getBitmap    Whether to load bitmaps for the symbols as well
205    * @return A GlyphSet pointer with a list of the requested glyph metrics.
206    */
207   virtual Integration::GlyphSet* GetGlyphData ( const Integration::TextResourceType& textRequest,
208                                                 const std::string& fontFamily,
209                                                 bool getBitmap) const = 0;
210
211   /**
212    * Called by GlyphResourceManager to synchronously load glyph data.
213    *
214    * @note fontFamily and font style, included in the resource request,  must have been validated previously.
215    * @see ValidateFontFamilyName().
216    *
217    * @param[in] textRequest     resource request
218    * @param[in] fontFamily      name of the font's family
219    * @return A GlyphSet pointer containing the requested glyph bitmaps.
220    */
221   virtual Integration::GlyphSet* GetCachedGlyphData( const TextResourceType& textRequest,
222                                                      const std::string& fontFamily ) const = 0;
223
224   /**
225    * Called by Font objects to synchronously query global font metrics.
226    *
227    * @note fontFamily and fontStyle, must have been validated previously.
228    * @see ValidateFontFamilyName().
229    *
230    * @param[in] fontFamily     The name of the font's family
231    * @param[in] fontStyle      The style of the font
232    * @param[out] globalMetrics font requested global metrics.
233    */
234   virtual void GetGlobalMetrics( const std::string& fontFamily,
235                                  const std::string& fontStyle,
236                                  Integration::GlobalMetrics& globalMetrics ) const = 0;
237
238   /**
239    * Sets horizontal and vertical pixels per inch value that is used by the display
240    * @param[in] dpiHorizontal horizontal dpi value
241    * @param[in] dpiVertical   vertical dpi value
242    */
243   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0;
244
245   /**
246    * Returns the name of the font's family for displayed text.
247    * If possible, the returned font name should be able to display all characters in text.
248    * Otherwise returns closest match.
249    * @param[in] charsRequested displayed text
250    */
251   virtual const std::string& GetFontFamilyForChars(const TextArray& charsRequested) const = 0;
252
253   /**
254    * Checks whether all characters of text could be displayed with specified font family.
255    *
256    * @note fontFamily and fontStyle must have been validated previously.
257    * @see ValidateFontFamilyName().
258    *
259    * @param[in] fontFamily     The name of the font's family
260    * @param[in] fontStyle      The style of the font
261    * @param[in] text     displayed text
262    */
263   virtual bool AllGlyphsSupported(const std::string& fontFamily, const std::string& fontStyle, const TextArray& text) const = 0;
264
265   /**
266    * Checks whether fontName is a valid font family name and fontStyle is a valid font style.
267    * closestFontFamilyMatch and closestFontStyleMatch are always set to the best matching font
268    * or the system default font if no near match is detected.
269    * @param[in] fontFamily     The name of the font's family
270    * @param[in] fontStyle      The style of the font
271    * @param[out] isDefaultSystemFont Whether this font has been created with a default system font.
272    * @param[out] closestFontFamilyMatch Name of the font's family found based on the user input family's name
273    * @param[out] closestFontStyleMatch  Name of the font's style found based on the user input font's style
274    * @return Whether a valid match has been found.
275    */
276   virtual bool ValidateFontFamilyName(const std::string& fontFamily, const std::string& fontStyle, bool& isDefaultSystemFont, std::string& closestFontFamilyMatch, std::string& closestFontStyleMatch) const = 0;
277
278   /**
279    * The mode for GetFontList()
280    */
281   enum FontListMode
282   {
283     LIST_SYSTEM_FONTS,
284     LIST_APPLICATION_FONTS,
285     LIST_ALL_FONTS
286   };
287
288   /**
289    * Gets a list of fonts installed on the system.
290    * @param[in] mode which fonts to include in the list.
291    * @param[out] fontList The list of font family names.
292    */
293   virtual void GetFontList( FontListMode mode, std::vector<std::string>& fontList ) const = 0;
294
295   /**
296    * Load a file into a buffer
297    * @param[in] filename The filename to load
298    * @param[out] buffer  A buffer to receive the file.
299    * @result             true if the file is loaded.
300    */
301   virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
302
303   /**
304    * Load a file into a buffer
305    * @param[in] filename The filename to save
306    * @param[out] buffer  A buffer containing some data
307    *                     The buffer is implemeneted with a std::vector. The size() member specifies the buffer length.
308    * @result             true if the file is saved.
309    */
310   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const = 0;
311
312   /**
313    * This method re-loads the device defaults that Dali uses. Adaptor will call this
314    * when devices settings change.
315    */
316   virtual void UpdateDefaultsFromDevice() = 0;
317
318   /**
319    * Get a pointer to the DynamicsFactory.
320    */
321   virtual DynamicsFactory* GetDynamicsFactory() = 0;
322
323   /**
324    * Read from the metrics cache into the global metrics parameter
325    *
326    * @note fontFamily and fontStyle must have been validated previously.
327    * @see ValidateFontFamilyName().
328    *
329    * @param[in] fontFamily The name of the font family
330    * @param[in] fontStyle The name of the font style
331    * @param[out] globalMetrics The data store to write into
332    * @return \e true if the operation succeeded
333    */
334   virtual bool ReadGlobalMetricsFromCache( const std::string& fontFamily,
335                                            const std::string& fontStyle,
336                                            Integration::GlobalMetrics& globalMetrics ) = 0;
337
338   /**
339    *
340    * @note fontFamily and fontStyle must have been validated previously.
341    * @see ValidateFontFamilyName().
342    *
343    * Write the global metrics parameter to the metrics cache
344    * @param[in] fontFamily The name of the font family
345    * @param[in] fontStyle The name of the font style
346    * @param[out] globalMetrics The data store to write
347    */
348   virtual void WriteGlobalMetricsToCache( const std::string& fontFamily,
349                                           const std::string& fontStyle,
350                                           const Integration::GlobalMetrics& globalMetrics ) = 0;
351
352   /**
353    * Read the metrics from the cache into the supplied vector
354    *
355    * @note fontFamily and fontStyle must have been validated previously.
356    * @see ValidateFontFamilyName().
357    *
358    * @param[in] fontFamily The name of the font family
359    * @param[in] fontStyle The name of the font style
360    * @param[out] glyphMetricsContainer The vector of metrics to write
361    * @return true if the operation succeeded
362    */
363   virtual bool ReadMetricsFromCache( const std::string& fontFamily,
364                                      const std::string& fontStyle,
365                                      std::vector<Integration::GlyphMetrics>& glyphMetricsContainer ) = 0;
366
367   /**
368    * Write the metrics to the cache
369    *
370    * @note fontFamily and fontStyle must have been validated previously.
371    * @see ValidateFontFamilyName().
372    *
373    * @param[in] fontFamily The name of the font family
374    * @param[in] fontStyle The name of the font style
375    * @param[in] glyphSet The set of metrics to write
376    */
377   virtual void WriteMetricsToCache( const std::string& fontFamily,
378                                     const std::string& fontStyle,
379                                     const Integration::GlyphSet& glyphSet ) = 0;
380
381   /**
382    * Retrieves file names from the given directory.
383    *
384    * @param[in] directoryName The directory name.
385    * @param[out] fileNames The file names in the given directory.
386    */
387   virtual void GetFileNamesFromDirectory( const std::string& directoryName,
388                                           std::vector<std::string>& fileNames ) = 0;
389
390   /**
391    * Retrieves the glyph image which represents the character.
392    *
393    * @param[in] fontFamily The font's family name.
394    * @param[in] fontStyle The font's style.
395    * @param[in] fontSize The font's size (in points).
396    * @param[in] character The given character.
397    *
398    * @return A bitmap representing the character.
399    */
400   virtual Integration::BitmapPtr GetGlyphImage( const std::string& fontFamily, const std::string& fontStyle, float fontSize, uint32_t character ) const = 0;
401
402 }; // class PlatformAbstraction
403
404 } // namespace Integration
405
406 } // namespace Dali
407
408 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__