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/devel-api/images/image-operations.h>
33 class DynamicsFactory;
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.
41 class PlatformAbstraction
45 virtual ~PlatformAbstraction() {}
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.
57 virtual void GetTimeMicroseconds(unsigned int& seconds, unsigned int& microSeconds) = 0;
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.
67 virtual void Suspend() = 0;
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.
75 virtual void Resume() = 0;
80 * @brief Determine the size of an image the resource loaders will provide when
81 * given the same image loading parameters.
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
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.
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;
102 @brief Determine the size of an image the resource loaders will provide when
103 * given the same image loading parameters.
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
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.
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;
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.
132 virtual void LoadResource(const ResourceRequest& request) = 0;
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.
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
144 virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
147 * Request that a resource be saved to the native filesystem.
148 * This is an asynchronous request.
150 virtual void SaveResource(const ResourceRequest& request) = 0;
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.
159 virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
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.
166 virtual bool IsLoading() = 0;
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.
175 virtual void GetResources(ResourceCache& cache) = 0;
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.
182 virtual void JoinLoaderThreads() = 0;
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.
193 virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const = 0;
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.
203 virtual int GetDefaultFontSize() const = 0;
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
210 virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0;
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.
218 virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
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.
227 virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const = 0;
230 * Get a pointer to the DynamicsFactory.
232 virtual DynamicsFactory* GetDynamicsFactory() = 0;
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.
240 virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
242 }; // class PlatformAbstraction
244 } // namespace Integration
248 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__