1 #ifndef DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
2 #define DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
5 * Copyright (c) 2019 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/images/image-operations.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/signals/callback.h>
34 typedef uint32_t ResourceId;
35 typedef IntrusivePtr<Dali::RefObject> ResourcePointer;
38 * PlatformAbstraction is an abstract interface, used by Dali to access platform specific services.
39 * A concrete implementation must be created for each platform, and provided when creating the
40 * Dali::Integration::Core object.
42 class PlatformAbstraction
49 * @brief Determine the size of an image the resource loaders will provide when
50 * given the same image loading parameters.
52 * This is a synchronous request.
53 * This function is used to determine the size of an image before it has loaded.
54 * @param[in] filename name of the image.
55 * @param[in] size The requested size for the image.
56 * @param[in] fittingMode The method to use to map the source image to the desired
58 * @param[in] samplingMode The image filter to use if the image needs to be
59 * downsampled to the requested size.
60 * @param[in] orientationCorrection Whether to use image metadata to rotate or
61 * flip the image, e.g., from portrait to landscape.
62 * @return dimensions that image will have if it is loaded with given parameters.
64 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
65 ImageDimensions size = ImageDimensions( 0, 0 ),
66 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
67 SamplingMode::Type samplingMode = SamplingMode::BOX,
68 bool orientationCorrection = true) = 0;
71 * @brief Determine the size of an image the resource loaders will provide when
72 * given the same image loading parameters.
74 * This is a synchronous request.
75 * This function is used to determine the size of an image before it has loaded.
76 * @param[in] filename name of the image.
77 * @param[in] size The requested size for the image.
78 * @param[in] fittingMode The method to use to map the source image to the desired
80 * @param[in] samplingMode The image filter to use if the image needs to be
81 * downsampled to the requested size.
82 * @param[in] orientationCorrection Whether to use image metadata to rotate or
83 * flip the image, e.g., from portrait to landscape.
84 * @return dimensions that image will have if it is loaded with given parameters.
86 virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
87 ImageDimensions size = ImageDimensions( 0, 0 ),
88 FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
89 SamplingMode::Type samplingMode = SamplingMode::BOX,
90 bool orientationCorrection = true) = 0;
93 * Request an image from the native filesystem. This is a synchronous request, i.e.
94 * it will block the main loop whilst executing.
96 * Multi-threading note: this method will be called from the main thread only i.e. not
97 * from within the Core::Render() method.
98 * @param[in] resourceType The type of resource to load
99 * @param[in] resourcePath The path to the resource
100 * @return A pointer to a ref-counted resource
102 virtual ResourcePointer LoadImageSynchronously( const BitmapResourceType& resourceType, const std::string& resourcePath ) = 0;
105 * Decode a buffer of data synchronously.
106 * @param[in] resourceType The type of resource to load
107 * @param[in] buffer The decoded data
108 * @param[in] bufferSize The size of the buffer used by the decoded data.
110 * @return A pointer to the decoded buffer.
112 virtual BitmapPtr DecodeBuffer( const BitmapResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
115 * Load a shader binary file into a buffer
116 * @param[in] filename The shader binary filename to load
117 * @param[out] buffer A buffer to receive the file.
118 * @result true if the file is loaded.
120 virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< uint8_t >& buffer ) const = 0;
123 * Save a shader binary file to the resource file system.
124 * @param[in] filename The shader binary filename to save to.
125 * @param[in] buffer A buffer to write the file from.
126 * @param[in] numbytes Size of the buffer.
127 * @result true if the file is saved, else false.
129 virtual bool SaveShaderBinaryFile( const std::string& filename, const uint8_t * buffer, uint32_t numBytes ) const = 0;
132 * Sets a callback to occur in the future
133 * @param[in] milliseconds number of milliseconds to wait until executing the callback
134 * @param[in] callback function to call when the timer expires
135 * @result a timer reference ID, to be used for cancelling the timer
137 virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback ) = 0;
140 * Cancels a running timer
141 * @param[in] timerId the ID reference returned when the timer was started
143 virtual void CancelTimer ( uint32_t timerId ) = 0;
148 * Virtual destructor.
150 virtual ~PlatformAbstraction() {}
152 }; // class PlatformAbstraction
154 } // namespace Integration
158 #endif // DALI_INTEGRATION_PLATFORM_ABSTRACTION_H