Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[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
23 #include <dali/integration-api/resource-cache.h>
24 #include <dali/integration-api/bitmap.h> ///@todo Remove this include (a bunch of stuff needs to include it though)
25 #include <dali/public-api/images/image-operations.h>
26
27 namespace Dali
28 {
29
30 namespace Integration
31 {
32
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() = 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() = 0;
76
77   // Resource Loading
78
79   /**
80    * @brief Determine the size of an image the resource loaders will provide when
81    * given the same image loading parameters.
82    *
83    * This is a synchronous request.
84    * This function is used to determine the size of an image before it has loaded.
85    * @param[in] filename name of the image.
86    * @param[in] size The requested size for the image.
87    * @param[in] fittingMode The method to use to map the source image to the desired
88    * dimensions.
89    * @param[in] samplingMode The image filter to use if the image needs to be
90    * downsampled to the requested size.
91    * @param[in] orientationCorrection Whether to use image metadata to rotate or
92    * flip the image, e.g., from portrait to landscape.
93    * @return dimensions that image will have if it is loaded with given parameters.
94    */
95   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
96                                                ImageDimensions size = ImageDimensions( 0, 0 ),
97                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
98                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
99                                                bool orientationCorrection = true) = 0;
100
101   /**
102    @brief Determine the size of an image the resource loaders will provide when
103    * given the same image loading parameters.
104    *
105    * This is a synchronous request.
106    * This function is used to determine the size of an image before it has loaded.
107    * @param[in] filename name of the image.
108    * @param[in] size The requested size for the image.
109    * @param[in] fittingMode The method to use to map the source image to the desired
110    * dimensions.
111    * @param[in] samplingMode The image filter to use if the image needs to be
112    * downsampled to the requested size.
113    * @param[in] orientationCorrection Whether to use image metadata to rotate or
114    * flip the image, e.g., from portrait to landscape.
115    * @return dimensions that image will have if it is loaded with given parameters.
116    */
117   virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
118                                                ImageDimensions size = ImageDimensions( 0, 0 ),
119                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
120                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
121                                                bool orientationCorrection = true) = 0;
122
123   /**
124    * Request a resource from the native filesystem. This is an asynchronous request.
125    * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
126    * resource loading operation. Loading resources in separate worker thread is recommended.
127    * Multi-threading note: this method will be called from the main thread only i.e. not
128    * from within the Core::Render() method.
129    * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
130    * returns; the loading process should take a copy.
131    */
132   virtual void LoadResource(const ResourceRequest& request) = 0;
133
134   /**
135    * Request a resource from the native filesystem. This is a synchronous request, i.e.
136    * it will block the main loop whilst executing. It should therefore be used sparingly.
137    *
138    * Multi-threading note: this method will be called from the main thread only i.e. not
139    * from within the Core::Render() method.
140    * @param[in] resourceType The type of resource to load
141    * @param[in] resourcePath The path to the resource
142    * @return A pointer to a ref-counted resource
143    */
144   virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
145
146   /**
147    * Request that a resource be saved to the native filesystem.
148    * This is an asynchronous request.
149    */
150   virtual void SaveResource(const ResourceRequest& request) = 0;
151
152   /**
153    * Cancel an ongoing LoadResource() request.
154    * Multi-threading note: this method will be called from the main thread only i.e. not
155    * from within the Core::Render() method.
156    * @param[in] id The ID of the resource to cancel.
157    * @param[in] typeId The ID type of the resource to cancel.
158    */
159   virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
160
161   /**
162    * Query whether any asynchronous LoadResource() requests are ongoing.
163    * Multi-threading note: this method may be called from either the main or rendering thread.
164    * @return True if resources are being loaded.
165    */
166   virtual bool IsLoading() = 0;
167
168   /**
169    * Retrieve newly loaded resources.
170    * If no resources have finished loading, then this method returns immediately.
171    * Multi-threading note: this method will be called from the update thread, from within
172    * the UpdateManager::Update() method.
173    * @param[in] cache The resource cache to fill.
174    */
175   virtual void GetResources(ResourceCache& cache) = 0;
176
177   /**
178    * Waits for the asynchronous loader threads (if any) to finish.
179    * This will be only be called before Core destruction; no resource loading requests will be
180    * made following this method.
181    */
182   virtual void JoinLoaderThreads() = 0;
183
184   // Font Queries
185
186   /**
187    * Called by Dali to retrieve the default font family & style for the platform.
188    * Multi-threading note: this method will be called from the main thread only i.e. not
189    * from within the Core::Render() method.
190    * @param[out] The default font family.
191    * @param[out] The default font style.
192    */
193   virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const = 0;
194
195   /**
196    * Called by Dali to retrieve the default font size for the platform.
197    * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
198    * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
199    * Multi-threading note: this method will be called from the main thread only i.e. not
200    * from within the Core::Render() method.
201    * @return The default font size.
202    */
203   virtual int GetDefaultFontSize() const = 0;
204
205   /**
206    * Sets horizontal and vertical pixels per inch value that is used by the display
207    * @param[in] dpiHorizontal horizontal dpi value
208    * @param[in] dpiVertical   vertical dpi value
209    */
210   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0;
211
212   /**
213    * Load a file into a buffer
214    * @param[in] filename The filename to load
215    * @param[out] buffer  A buffer to receive the file.
216    * @result             true if the file is loaded.
217    */
218   virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
219
220   /**
221    * Load a file into a buffer
222    * @param[in] filename The filename to save
223    * @param[out] buffer  A buffer containing some data
224    *                     The buffer is implemeneted with a std::vector. The size() member specifies the buffer length.
225    * @result             true if the file is saved.
226    */
227   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const = 0;
228
229   /**
230    * Get a pointer to the DynamicsFactory.
231    */
232   virtual DynamicsFactory* GetDynamicsFactory() = 0;
233
234   /**
235    * Load a shader binary file into a buffer
236    * @param[in] filename The shader binary filename to load
237    * @param[out] buffer  A buffer to receive the file.
238    * @result             true if the file is loaded.
239    */
240   virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
241
242 }; // class PlatformAbstraction
243
244 } // namespace Integration
245
246 } // namespace Dali
247
248 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__