1 #ifndef DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
2 #define DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
5 * Copyright (c) 2020 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/bitmap.h>
24 #include <dali/integration-api/resource-types.h>
25 #include <dali/public-api/common/dali-vector.h>
26 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/signals/callback.h>
33 using ResourceId = uint32_t;
34 using ResourcePointer = IntrusivePtr<Dali::RefObject>;
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
47 * @brief Determine the size of an image the resource loaders will provide when
48 * given the same image loading parameters.
50 * This is a synchronous request.
51 * This function is used to determine the size of an image before it has loaded.
52 * @param[in] filename name of the image.
53 * @param[in] size The requested size for the image.
54 * @param[in] fittingMode The method to use to map the source image to the desired
56 * @param[in] samplingMode The image filter to use if the image needs to be
57 * downsampled to the requested size.
58 * @param[in] orientationCorrection Whether to use image metadata to rotate or
59 * flip the image, e.g., from portrait to landscape.
60 * @return dimensions that image will have if it is loaded with given parameters.
62 virtual ImageDimensions GetClosestImageSize(const std::string& filename,
63 ImageDimensions size = ImageDimensions(0, 0),
64 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
65 SamplingMode::Type samplingMode = SamplingMode::BOX,
66 bool orientationCorrection = true) = 0;
69 * @brief Determine the size of an image the resource loaders will provide when
70 * given the same image loading parameters.
72 * This is a synchronous request.
73 * This function is used to determine the size of an image before it has loaded.
74 * @param[in] filename name of the image.
75 * @param[in] size The requested size for the image.
76 * @param[in] fittingMode The method to use to map the source image to the desired
78 * @param[in] samplingMode The image filter to use if the image needs to be
79 * downsampled to the requested size.
80 * @param[in] orientationCorrection Whether to use image metadata to rotate or
81 * flip the image, e.g., from portrait to landscape.
82 * @return dimensions that image will have if it is loaded with given parameters.
84 virtual ImageDimensions GetClosestImageSize(ResourcePointer resourceBuffer,
85 ImageDimensions size = ImageDimensions(0, 0),
86 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
87 SamplingMode::Type samplingMode = SamplingMode::BOX,
88 bool orientationCorrection = true) = 0;
91 * Request an image from the native filesystem. This is a synchronous request, i.e.
92 * it will block the main loop whilst executing.
94 * Multi-threading note: this method will be called from the main thread only i.e. not
95 * from within the Core::Render() method.
96 * @param[in] resourceType The type of resource to load
97 * @param[in] resourcePath The path to the resource
98 * @return A pointer to a ref-counted resource
100 virtual ResourcePointer LoadImageSynchronously(const BitmapResourceType& resourceType, const std::string& resourcePath) = 0;
103 * Decode a buffer of data synchronously.
104 * @param[in] resourceType The type of resource to load
105 * @param[in] buffer The decoded data
106 * @param[in] bufferSize The size of the buffer used by the decoded data.
108 * @return A pointer to the decoded buffer.
110 virtual BitmapPtr DecodeBuffer(const BitmapResourceType& resourceType, uint8_t* buffer, size_t bufferSize) = 0;
113 * Load a shader binary file into a buffer
114 * @param[in] filename The shader binary filename to load
115 * @param[out] buffer A buffer to receive the file.
116 * @result true if the file is loaded.
118 virtual bool LoadShaderBinaryFile(const std::string& filename, Dali::Vector<uint8_t>& buffer) const = 0;
121 * Save a shader binary file to the resource file system.
122 * @param[in] filename The shader binary filename to save to.
123 * @param[in] buffer A buffer to write the file from.
124 * @param[in] numbytes Size of the buffer.
125 * @result true if the file is saved, else false.
127 virtual bool SaveShaderBinaryFile(const std::string& filename, const uint8_t* buffer, uint32_t numBytes) const = 0;
130 * Sets a callback to occur in the future
131 * @param[in] milliseconds number of milliseconds to wait until executing the callback
132 * @param[in] callback function to call when the timer expires
133 * @result a timer reference ID, to be used for cancelling the timer
135 virtual uint32_t StartTimer(uint32_t milliseconds, CallbackBase* callback) = 0;
138 * Cancels a running timer
139 * @param[in] timerId the ID reference returned when the timer was started
141 virtual void CancelTimer(uint32_t timerId) = 0;
145 * Virtual destructor.
147 virtual ~PlatformAbstraction()
151 }; // class PlatformAbstraction
153 } // namespace Integration
157 #endif // DALI_INTEGRATION_PLATFORM_ABSTRACTION_H