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>
34 * PlatformAbstraction is an abstract interface, used by Dali to access platform specific services.
35 * A concrete implementation must be created for each platform, and provided when creating the
36 * Dali::Integration::Core object.
38 class PlatformAbstraction
42 virtual ~PlatformAbstraction() {}
47 * Get the monotonic time since an unspecified reference point.
48 * This is used by Dali to calculate time intervals during animations; the interval is
49 * recalculated when Dali is resumed with Dali::Integration::Core::Resume().
50 * Multi-threading note: this method may be called from either the main or rendering thread.
51 * @param[out] seconds The time in seconds since the reference point.
52 * @param[out] microSeconds The remainder in microseconds.
54 virtual void GetTimeMicroseconds(unsigned int& seconds, unsigned int& microSeconds) = 0;
57 * Tell the platform abstraction that Dali is ready to pause, such as when the
58 * application enters a background state.
59 * Allows background threads to pause their work until Resume() is called.
60 * This is a good time to release recreatable data such as memory caches
61 * to cooperate with other apps and reduce the chance of this one being
62 * force-killed in a low memory situation.
64 virtual void Suspend() = 0;
67 * Tell the platform abstraction that Dali is resuming from a pause, such as
68 * when it has transitioned from a background state to a foreground one.
69 * It is time to wake up sleeping background threads and recreate memory
70 * caches and other temporary data.
72 virtual void Resume() = 0;
77 * @brief Determine the size of an image the resource loaders will provide when
78 * given the same image loading parameters.
80 * This is a synchronous request.
81 * This function is used to determine the size of an image before it has loaded.
82 * @param[in] filename name of the image.
83 * @param[in] size The requested size for the image.
84 * @param[in] fittingMode The method to use to map the source image to the desired
86 * @param[in] samplingMode The image filter to use if the image needs to be
87 * downsampled to the requested size.
88 * @param[in] orientationCorrection Whether to use image metadata to rotate or
89 * flip the image, e.g., from portrait to landscape.
90 * @return dimensions that image will have if it is loaded with given parameters.
92 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
93 ImageDimensions size = ImageDimensions( 0, 0 ),
94 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
95 SamplingMode::Type samplingMode = SamplingMode::BOX,
96 bool orientationCorrection = true) = 0;
99 @brief Determine the size of an image the resource loaders will provide when
100 * given the same image loading parameters.
102 * This is a synchronous request.
103 * This function is used to determine the size of an image before it has loaded.
104 * @param[in] filename name of the image.
105 * @param[in] size The requested size for the image.
106 * @param[in] fittingMode The method to use to map the source image to the desired
108 * @param[in] samplingMode The image filter to use if the image needs to be
109 * downsampled to the requested size.
110 * @param[in] orientationCorrection Whether to use image metadata to rotate or
111 * flip the image, e.g., from portrait to landscape.
112 * @return dimensions that image will have if it is loaded with given parameters.
114 virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
115 ImageDimensions size = ImageDimensions( 0, 0 ),
116 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
117 SamplingMode::Type samplingMode = SamplingMode::BOX,
118 bool orientationCorrection = true) = 0;
121 * Request a resource from the native filesystem. This is an asynchronous request.
122 * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
123 * resource loading operation. Loading resources in separate worker thread is recommended.
124 * Multi-threading note: this method will be called from the main thread only i.e. not
125 * from within the Core::Render() method.
126 * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
127 * returns; the loading process should take a copy.
129 virtual void LoadResource(const ResourceRequest& request) = 0;
132 * Request a resource from the native filesystem. This is a synchronous request, i.e.
133 * it will block the main loop whilst executing. It should therefore be used sparingly.
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] resourceType The type of resource to load
138 * @param[in] resourcePath The path to the resource
139 * @return A pointer to a ref-counted resource
141 virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
144 * Request that a resource be saved to the native filesystem.
145 * This is an asynchronous request.
147 virtual void SaveResource(const ResourceRequest& request) = 0;
150 * Cancel an ongoing LoadResource() request.
151 * Multi-threading note: this method will be called from the main thread only i.e. not
152 * from within the Core::Render() method.
153 * @param[in] id The ID of the resource to cancel.
154 * @param[in] typeId The ID type of the resource to cancel.
156 virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 0;
159 * Query whether any asynchronous LoadResource() requests are ongoing.
160 * Multi-threading note: this method may be called from either the main or rendering thread.
161 * @return True if resources are being loaded.
163 virtual bool IsLoading() = 0;
166 * Retrieve newly loaded resources.
167 * If no resources have finished loading, then this method returns immediately.
168 * Multi-threading note: this method will be called from the update thread, from within
169 * the UpdateManager::Update() method.
170 * @param[in] cache The resource cache to fill.
172 virtual void GetResources(ResourceCache& cache) = 0;
175 * Waits for the asynchronous loader threads (if any) to finish.
176 * This will be only be called before Core destruction; no resource loading requests will be
177 * made following this method.
179 virtual void JoinLoaderThreads() = 0;
184 * Called by Dali to retrieve the default font family & style for the platform.
185 * Multi-threading note: this method will be called from the main thread only i.e. not
186 * from within the Core::Render() method.
187 * @param[out] The default font family.
188 * @param[out] The default font style.
190 virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const = 0;
193 * Called by Dali to retrieve the default font size for the platform.
194 * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
195 * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
196 * Multi-threading note: this method will be called from the main thread only i.e. not
197 * from within the Core::Render() method.
198 * @return The default font size.
200 virtual int GetDefaultFontSize() const = 0;
203 * Sets horizontal and vertical pixels per inch value that is used by the display
204 * @param[in] dpiHorizontal horizontal dpi value
205 * @param[in] dpiVertical vertical dpi value
207 virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical) = 0;
210 * Load a file into a buffer
211 * @param[in] filename The filename to load
212 * @param[out] buffer A buffer to receive the file.
213 * @result true if the file is loaded.
215 virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
218 * Load a file into a buffer
219 * @param[in] filename The filename to save
220 * @param[out] buffer A buffer containing some data
221 * The buffer is implemeneted with a std::vector. The size() member specifies the buffer length.
222 * @result true if the file is saved.
224 virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const = 0;
227 * Load a shader binary file into a buffer
228 * @param[in] filename The shader binary filename to load
229 * @param[out] buffer A buffer to receive the file.
230 * @result true if the file is loaded.
232 virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const = 0;
234 }; // class PlatformAbstraction
236 } // namespace Integration
240 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__