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
46 virtual ~PlatformAbstraction() {}
51 * Get the monotonic time since an unspecified reference point with more precision.
52 * Multi-threading note: this method may be called from any thread.
53 * @param[out] seconds The time in seconds since the reference point.
54 * @param[out] nanoseconds The remainder in nanoseconds.
56 virtual void GetTimeNanoseconds( uint64_t& seconds, uint64_t& nanoseconds ) = 0;
61 * Tell the platform abstraction that Dali is ready to pause, such as when the
62 * application enters a background state.
63 * Allows background threads to pause their work until Resume() is called.
64 * This is a good time to release recreatable data such as memory caches
65 * to cooperate with other apps and reduce the chance of this one being
66 * force-killed in a low memory situation.
68 virtual void Suspend() = 0;
71 * Tell the platform abstraction that Dali is resuming from a pause, such as
72 * when it has transitioned from a background state to a foreground one.
73 * It is time to wake up sleeping background threads and recreate memory
74 * caches and other temporary data.
76 virtual void Resume() = 0;
81 * @brief Determine the size of an image the resource loaders will provide when
82 * given the same image loading parameters.
84 * This is a synchronous request.
85 * This function is used to determine the size of an image before it has loaded.
86 * @param[in] filename name of the image.
87 * @param[in] size The requested size for the image.
88 * @param[in] fittingMode The method to use to map the source image to the desired
90 * @param[in] samplingMode The image filter to use if the image needs to be
91 * downsampled to the requested size.
92 * @param[in] orientationCorrection Whether to use image metadata to rotate or
93 * flip the image, e.g., from portrait to landscape.
94 * @return dimensions that image will have if it is loaded with given parameters.
96 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
97 ImageDimensions size = ImageDimensions( 0, 0 ),
98 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
99 SamplingMode::Type samplingMode = SamplingMode::BOX,
100 bool orientationCorrection = true) = 0;
103 * @brief Determine the size of an image the resource loaders will provide when
104 * given the same image loading parameters.
106 * This is a synchronous request.
107 * This function is used to determine the size of an image before it has loaded.
108 * @param[in] filename name of the image.
109 * @param[in] size The requested size for the image.
110 * @param[in] fittingMode The method to use to map the source image to the desired
112 * @param[in] samplingMode The image filter to use if the image needs to be
113 * downsampled to the requested size.
114 * @param[in] orientationCorrection Whether to use image metadata to rotate or
115 * flip the image, e.g., from portrait to landscape.
116 * @return dimensions that image will have if it is loaded with given parameters.
118 virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
119 ImageDimensions size = ImageDimensions( 0, 0 ),
120 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
121 SamplingMode::Type samplingMode = SamplingMode::BOX,
122 bool orientationCorrection = true) = 0;
125 * Request a resource from the native filesystem. This is an asynchronous request.
126 * After this method returns, FillResourceCache() will be called to retrieve the result(s) of the
127 * resource loading operation. Loading resources in separate worker thread is recommended.
128 * Multi-threading note: this method will be called from the main thread only i.e. not
129 * from within the Core::Render() method.
130 * @param[in] request A unique resource request. This is not guaranteed to survive after LoadResource
131 * returns; the loading process should take a copy.
133 virtual void LoadResource(const ResourceRequest& request) = 0;
136 * Request a resource from the native filesystem. This is a synchronous request, i.e.
137 * it will block the main loop whilst executing. It should therefore be used sparingly.
139 * Multi-threading note: this method will be called from the main thread only i.e. not
140 * from within the Core::Render() method.
141 * @param[in] resourceType The type of resource to load
142 * @param[in] resourcePath The path to the resource
143 * @return A pointer to a ref-counted resource
145 virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
148 * Decode a buffer of data synchronously.
149 * @param[in] resourceType The type of resource to load
150 * @param[in] buffer The decoded data
151 * @param[in] bufferSize The size of the buffer used by the decoded data.
153 * @return A pointer to the decoded buffer.
155 virtual BitmapPtr DecodeBuffer( const ResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
158 * Cancel an ongoing LoadResource() request.
159 * Multi-threading note: this method will be called from the main thread only i.e. not
160 * from within the Core::Render() method.
161 * @param[in] id The ID of the resource to cancel.
162 * @param[in] typeId The ID type of the resource to cancel.
164 virtual void CancelLoad(ResourceId id, ResourceTypeId typeId) = 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 size for the platform.
186 * This is an accessibility size, which is mapped to a UI Control specific point-size in stylesheets.
187 * For example if zero the smallest size, this could potentially map to TextLabel point-size 8.
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 * @return The default font size.
192 virtual int GetDefaultFontSize() const = 0;
195 * Load a file into a buffer
196 * @param[in] filename The filename to load
197 * @param[out] buffer A buffer to receive the file.
198 * @result true if the file is loaded.
200 virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
203 * Load a shader binary file into a buffer
204 * @param[in] filename The shader binary filename to load
205 * @param[out] buffer A buffer to receive the file.
206 * @result true if the file is loaded.
208 virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
211 * Save a shader binary file to the resource file system.
212 * @param[in] filename The shader binary filename to save to.
213 * @param[in] buffer A buffer to write the file from.
214 * @param[in] numbytes Size of the buffer.
215 * @result true if the file is saved, else false.
217 virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const = 0;
219 }; // class PlatformAbstraction
221 } // namespace Integration
225 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__