1 #ifndef __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__
2 #define __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 #include <dali/public-api/common/dali-vector.h>
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.
39 class PlatformAbstraction
43 virtual ~PlatformAbstraction() {}
48 * Get the monotonic time since an unspecified reference point.
49 * This is used by Dali to calculate time intervals during animations; the interval is
50 * recalculated when Dali is resumed with Dali::Integration::Core::Resume().
51 * Multi-threading note: this method may be called from either the main or rendering thread.
52 * @param[out] seconds The time in seconds since the reference point.
53 * @param[out] microSeconds The remainder in microseconds.
55 virtual void GetTimeMicroseconds(unsigned int& seconds, unsigned int& microSeconds) = 0;
58 * Tell the platform abstraction that Dali is ready to pause, such as when the
59 * application enters a background state.
60 * Allows background threads to pause their work until Resume() is called.
61 * This is a good time to release recreatable data such as memory caches
62 * to cooperate with other apps and reduce the chance of this one being
63 * force-killed in a low memory situation.
65 virtual void Suspend() = 0;
68 * Tell the platform abstraction that Dali is resuming from a pause, such as
69 * when it has transitioned from a background state to a foreground one.
70 * It is time to wake up sleeping background threads and recreate memory
71 * caches and other temporary data.
73 virtual void Resume() = 0;
78 * @brief Determine the size of an image the resource loaders will provide when
79 * given the same image loading parameters.
81 * This is a synchronous request.
82 * This function is used to determine the size of an image before it has loaded.
83 * @param[in] filename name of the image.
84 * @param[in] size The requested size for the image.
85 * @param[in] fittingMode The method to use to map the source image to the desired
87 * @param[in] samplingMode The image filter to use if the image needs to be
88 * downsampled to the requested size.
89 * @param[in] orientationCorrection Whether to use image metadata to rotate or
90 * flip the image, e.g., from portrait to landscape.
91 * @return dimensions that image will have if it is loaded with given parameters.
93 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
94 ImageDimensions size = ImageDimensions( 0, 0 ),
95 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
96 SamplingMode::Type samplingMode = SamplingMode::BOX,
97 bool orientationCorrection = true) = 0;
100 @brief Determine the size of an image the resource loaders will provide when
101 * given the same image loading parameters.
103 * This is a synchronous request.
104 * This function is used to determine the size of an image before it has loaded.
105 * @param[in] filename name of the image.
106 * @param[in] size The requested size for the image.
107 * @param[in] fittingMode The method to use to map the source image to the desired
109 * @param[in] samplingMode The image filter to use if the image needs to be
110 * downsampled to the requested size.
111 * @param[in] orientationCorrection Whether to use image metadata to rotate or
112 * flip the image, e.g., from portrait to landscape.
113 * @return dimensions that image will have if it is loaded with given parameters.
115 virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
116 ImageDimensions size = ImageDimensions( 0, 0 ),
117 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
118 SamplingMode::Type samplingMode = SamplingMode::BOX,
119 bool orientationCorrection = true) = 0;
122 * Request a resource from the native filesystem. This is an asynchronous request.
123 * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
124 * resource loading operation. Loading resources in separate worker thread is recommended.
125 * Multi-threading note: this method will be called from the main thread only i.e. not
126 * from within the Core::Render() method.
127 * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
128 * returns; the loading process should take a copy.
130 virtual void LoadResource(const ResourceRequest& request) = 0;
133 * Request a resource from the native filesystem. This is a synchronous request, i.e.
134 * it will block the main loop whilst executing. It should therefore be used sparingly.
136 * Multi-threading note: this method will be called from the main thread only i.e. not
137 * from within the Core::Render() method.
138 * @param[in] resourceType The type of resource to load
139 * @param[in] resourcePath The path to the resource
140 * @return A pointer to a ref-counted resource
142 virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
145 * Request that a resource be saved to the native filesystem.
146 * This is an asynchronous request.
148 virtual void SaveResource(const ResourceRequest& request) = 0;
151 * Cancel an ongoing LoadResource() request.
152 * Multi-threading note: this method will be called from the main thread only i.e. not
153 * from within the Core::Render() method.
154 * @param[in] id The ID of the resource to cancel.
155 * @param[in] typeId The ID type of the resource to cancel.
157 virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
160 * Query whether any asynchronous LoadResource() requests are ongoing.
161 * Multi-threading note: this method may be called from either the main or rendering thread.
162 * @return True if resources are being loaded.
164 virtual bool IsLoading() = 0;
167 * Retrieve newly loaded resources.
168 * If no resources have finished loading, then this method returns immediately.
169 * Multi-threading note: this method will be called from the update thread, from within
170 * the UpdateManager::Update() method.
171 * @param[in] cache The resource cache to fill.
173 virtual void GetResources(ResourceCache& cache) = 0;
176 * Waits for the asynchronous loader threads (if any) to finish.
177 * This will be only be called before Core destruction; no resource loading requests will be
178 * made following this method.
180 virtual void JoinLoaderThreads() = 0;
185 * Called by Dali to retrieve the default font family & style for the platform.
186 * Multi-threading note: this method will be called from the main thread only i.e. not
187 * from within the Core::Render() method.
188 * @param[out] The default font family.
189 * @param[out] The default font style.
191 virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const = 0;
194 * Called by Dali to retrieve the default font size for the platform.
195 * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
196 * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
197 * Multi-threading note: this method will be called from the main thread only i.e. not
198 * from within the Core::Render() method.
199 * @return The default font size.
201 virtual int GetDefaultFontSize() const = 0;
204 * Sets horizontal and vertical pixels per inch value that is used by the display
205 * @param[in] dpiHorizontal horizontal dpi value
206 * @param[in] dpiVertical vertical dpi value
208 virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0;
211 * Load a file into a buffer
212 * @param[in] filename The filename to load
213 * @param[out] buffer A buffer to receive the file.
214 * @result true if the file is loaded.
216 virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
219 * Load a file into a buffer
220 * @param[in] filename The filename to save
221 * @param[out] buffer A buffer containing some data
222 * The buffer is implemeneted with a Dali::Vector. The size() member specifies the buffer length.
223 * @result true if the file is saved.
225 virtual bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const = 0;
228 * Load a shader binary file into a buffer
229 * @param[in] filename The shader binary filename to load
230 * @param[out] buffer A buffer to receive the file.
231 * @result true if the file is loaded.
233 virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
236 * Save a shader binary file to the resource file system.
237 * @param[in] filename The shader binary filename to save to.
238 * @param[in] buffer A buffer to write the file from.
239 * @param[in] numbytes Size of the buffer.
240 * @result true if the file is saved, else false.
242 virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const = 0;
244 }; // class PlatformAbstraction
246 } // namespace Integration
250 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__