Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / integration-api / platform-abstraction.h
1 #ifndef DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
2 #define DALI_INTEGRATION_PLATFORM_ABSTRACTION_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22
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>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 using ResourceId      = uint32_t;
35 using ResourcePointer = IntrusivePtr<Dali::RefObject>;
36
37 /**
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.
41  */
42 class PlatformAbstraction
43 {
44 public:
45
46   // Resource Loading
47
48   /**
49    * @brief Determine the size of an image the resource loaders will provide when
50    * given the same image loading parameters.
51    *
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
57    * dimensions.
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.
63    */
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;
69
70   /**
71    * @brief Determine the size of an image the resource loaders will provide when
72    * given the same image loading parameters.
73    *
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
79    * dimensions.
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.
85    */
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;
91
92   /**
93    * Request an image from the native filesystem. This is a synchronous request, i.e.
94    * it will block the main loop whilst executing.
95    *
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
101    */
102   virtual ResourcePointer LoadImageSynchronously( const BitmapResourceType& resourceType, const std::string& resourcePath ) = 0;
103
104   /**
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.
109    *
110    * @return A pointer to the decoded buffer.
111    */
112   virtual BitmapPtr DecodeBuffer( const BitmapResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
113
114   /**
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.
119    */
120   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< uint8_t >& buffer ) const = 0;
121
122   /**
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.
128    */
129   virtual bool SaveShaderBinaryFile( const std::string& filename, const uint8_t * buffer, uint32_t numBytes ) const = 0;
130
131   /**
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
136    */
137   virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback ) = 0;
138
139   /**
140    * Cancels a running timer
141    * @param[in] timerId the ID reference returned when the timer was started
142    */
143   virtual void CancelTimer ( uint32_t timerId ) = 0;
144
145 protected:
146
147   /**
148    * Virtual destructor.
149    */
150   virtual ~PlatformAbstraction() {}
151
152 }; // class PlatformAbstraction
153
154 } // namespace Integration
155
156 } // namespace Dali
157
158 #endif // DALI_INTEGRATION_PLATFORM_ABSTRACTION_H