DALi Version 1.2.28
[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) 2016 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>
25 #include <dali/public-api/images/image-operations.h>
26 #include <dali/public-api/common/dali-vector.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33
34 /**
35  * PlatformAbstraction is an abstract interface, used by Dali to access platform specific services.
36  * A concrete implementation must be created for each platform, and provided when creating the
37  * Dali::Integration::Core object.
38  */
39 class PlatformAbstraction
40 {
41 public:
42
43   /**
44    * Virtual destructor.
45    */
46   virtual ~PlatformAbstraction() {}
47
48   // DALi Lifecycle
49
50   /**
51    * Tell the platform abstraction that Dali is ready to pause, such as when the
52    * application enters a background state.
53    * Allows background threads to pause their work until Resume() is called.
54    * This is a good time to release recreatable data such as memory caches
55    * to cooperate with other apps and reduce the chance of this one being
56    * force-killed in a low memory situation.
57    */
58   virtual void Suspend() = 0;
59
60   /**
61    * Tell the platform abstraction that Dali is resuming from a pause, such as
62    * when it has transitioned from a background state to a foreground one.
63    * It is time to wake up sleeping background threads and recreate memory
64    * caches and other temporary data.
65    */
66   virtual void Resume() = 0;
67
68   // Resource Loading
69
70   /**
71    * @brief Determine the size of an image the resource loaders will provide when
72    * given the same image loading parameters.
73    *
74    * This is a synchronous request.
75    * This function is used to determine the size of an image before it has loaded.
76    * @param[in] filename name of the image.
77    * @param[in] size The requested size for the image.
78    * @param[in] fittingMode The method to use to map the source image to the desired
79    * dimensions.
80    * @param[in] samplingMode The image filter to use if the image needs to be
81    * downsampled to the requested size.
82    * @param[in] orientationCorrection Whether to use image metadata to rotate or
83    * flip the image, e.g., from portrait to landscape.
84    * @return dimensions that image will have if it is loaded with given parameters.
85    */
86   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
87                                                ImageDimensions size = ImageDimensions( 0, 0 ),
88                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
89                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
90                                                bool orientationCorrection = true) = 0;
91
92   /**
93    * @brief Determine the size of an image the resource loaders will provide when
94    * given the same image loading parameters.
95    *
96    * This is a synchronous request.
97    * This function is used to determine the size of an image before it has loaded.
98    * @param[in] filename name of the image.
99    * @param[in] size The requested size for the image.
100    * @param[in] fittingMode The method to use to map the source image to the desired
101    * dimensions.
102    * @param[in] samplingMode The image filter to use if the image needs to be
103    * downsampled to the requested size.
104    * @param[in] orientationCorrection Whether to use image metadata to rotate or
105    * flip the image, e.g., from portrait to landscape.
106    * @return dimensions that image will have if it is loaded with given parameters.
107    */
108   virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
109                                                ImageDimensions size = ImageDimensions( 0, 0 ),
110                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
111                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
112                                                bool orientationCorrection = true) = 0;
113
114   /**
115    * Request a resource from the native filesystem. This is an asynchronous request.
116    * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
117    * resource loading operation. Loading resources in separate worker thread is recommended.
118    * Multi-threading note: this method will be called from the main thread only i.e. not
119    * from within the Core::Render() method.
120    * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
121    * returns; the loading process should take a copy.
122    */
123   virtual void LoadResource(const ResourceRequest& request) = 0;
124
125   /**
126    * Request a resource from the native filesystem. This is a synchronous request, i.e.
127    * it will block the main loop whilst executing. It should therefore be used sparingly.
128    *
129    * Multi-threading note: this method will be called from the main thread only i.e. not
130    * from within the Core::Render() method.
131    * @param[in] resourceType The type of resource to load
132    * @param[in] resourcePath The path to the resource
133    * @return A pointer to a ref-counted resource
134    */
135   virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
136
137   /**
138    * Decode a buffer of data synchronously.
139    * @param[in] resourceType The type of resource to load
140    * @param[in] buffer The decoded data
141    * @param[in] bufferSize The size of the buffer used by the decoded data.
142    *
143    * @return A pointer to the decoded buffer.
144    */
145   virtual BitmapPtr DecodeBuffer( const ResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
146
147   /**
148    * Cancel an ongoing LoadResource() request.
149    * Multi-threading note: this method will be called from the main thread only i.e. not
150    * from within the Core::Render() method.
151    * @param[in] id The ID of the resource to cancel.
152    * @param[in] typeId The ID type of the resource to cancel.
153    */
154   virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
155
156   /**
157    * Retrieve newly loaded resources.
158    * If no resources have finished loading, then this method returns immediately.
159    * Multi-threading note: this method will be called from the update thread, from within
160    * the UpdateManager::Update() method.
161    * @param[in] cache The resource cache to fill.
162    */
163   virtual void GetResources(ResourceCache& cache) = 0;
164
165   /**
166    * Waits for the asynchronous loader threads (if any) to finish.
167    * This will be only be called before Core destruction; no resource loading requests will be
168    * made following this method.
169    */
170   virtual void JoinLoaderThreads() = 0;
171
172   // Font Queries
173
174   /**
175    * Called by Dali to retrieve the default font size for the platform.
176    * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
177    * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
178    * Multi-threading note: this method will be called from the main thread only i.e. not
179    * from within the Core::Render() method.
180    * @return The default font size.
181    */
182   virtual int GetDefaultFontSize() const = 0;
183
184   /**
185    * Load a file into a buffer
186    * @param[in] filename The filename to load
187    * @param[out] buffer  A buffer to receive the file.
188    * @result             true if the file is loaded.
189    */
190   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
191
192   /**
193    * Load a shader binary file into a buffer
194    * @param[in] filename The shader binary filename to load
195    * @param[out] buffer  A buffer to receive the file.
196    * @result             true if the file is loaded.
197    */
198   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
199
200   /**
201    * Save a shader binary file to the resource file system.
202    * @param[in] filename The shader binary filename to save to.
203    * @param[in] buffer  A buffer to write the file from.
204    * @param[in] numbytes Size of the buffer.
205    * @result             true if the file is saved, else false.
206    */
207   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const = 0;
208
209 }; // class PlatformAbstraction
210
211 } // namespace Integration
212
213 } // namespace Dali
214
215 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__