[dali_1.2.39] Merge branch 'devel/master'
[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) 2016 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
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33
34 typedef IntrusivePtr<Dali::RefObject> ResourcePointer;
35
36 /**
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.
40  */
41 class PlatformAbstraction
42 {
43 public:
44
45   /**
46    * Virtual destructor.
47    */
48   virtual ~PlatformAbstraction() {}
49
50   // Resource Loading
51
52   /**
53    * @brief Determine the size of an image the resource loaders will provide when
54    * given the same image loading parameters.
55    *
56    * This is a synchronous request.
57    * This function is used to determine the size of an image before it has loaded.
58    * @param[in] filename name of the image.
59    * @param[in] size The requested size for the image.
60    * @param[in] fittingMode The method to use to map the source image to the desired
61    * dimensions.
62    * @param[in] samplingMode The image filter to use if the image needs to be
63    * downsampled to the requested size.
64    * @param[in] orientationCorrection Whether to use image metadata to rotate or
65    * flip the image, e.g., from portrait to landscape.
66    * @return dimensions that image will have if it is loaded with given parameters.
67    */
68   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
69                                                ImageDimensions size = ImageDimensions( 0, 0 ),
70                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
71                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
72                                                bool orientationCorrection = true) = 0;
73
74   /**
75    * @brief Determine the size of an image the resource loaders will provide when
76    * given the same image loading parameters.
77    *
78    * This is a synchronous request.
79    * This function is used to determine the size of an image before it has loaded.
80    * @param[in] filename name of the image.
81    * @param[in] size The requested size for the image.
82    * @param[in] fittingMode The method to use to map the source image to the desired
83    * dimensions.
84    * @param[in] samplingMode The image filter to use if the image needs to be
85    * downsampled to the requested size.
86    * @param[in] orientationCorrection Whether to use image metadata to rotate or
87    * flip the image, e.g., from portrait to landscape.
88    * @return dimensions that image will have if it is loaded with given parameters.
89    */
90   virtual ImageDimensions GetClosestImageSize( ResourcePointer resourceBuffer,
91                                                ImageDimensions size = ImageDimensions( 0, 0 ),
92                                                FittingMode::Type fittingMode = FittingMode::SHRINK_TO_FIT,
93                                                SamplingMode::Type samplingMode = SamplingMode::BOX,
94                                                bool orientationCorrection = true) = 0;
95
96   /**
97    * Request a resource from the native filesystem. This is a synchronous request, i.e.
98    * it will block the main loop whilst executing. It should therefore be used sparingly.
99    *
100    * Multi-threading note: this method will be called from the main thread only i.e. not
101    * from within the Core::Render() method.
102    * @param[in] resourceType The type of resource to load
103    * @param[in] resourcePath The path to the resource
104    * @return A pointer to a ref-counted resource
105    */
106   virtual ResourcePointer LoadResourceSynchronously( const ResourceType& resourceType, const std::string& resourcePath ) = 0;
107
108   /**
109    * Decode a buffer of data synchronously.
110    * @param[in] resourceType The type of resource to load
111    * @param[in] buffer The decoded data
112    * @param[in] bufferSize The size of the buffer used by the decoded data.
113    *
114    * @return A pointer to the decoded buffer.
115    */
116   virtual BitmapPtr DecodeBuffer( const ResourceType& resourceType, uint8_t * buffer, size_t bufferSize ) = 0;
117
118   /**
119    * Load a shader binary file into a buffer
120    * @param[in] filename The shader binary filename to load
121    * @param[out] buffer  A buffer to receive the file.
122    * @result             true if the file is loaded.
123    */
124   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const = 0;
125
126   /**
127    * Save a shader binary file to the resource file system.
128    * @param[in] filename The shader binary filename to save to.
129    * @param[in] buffer  A buffer to write the file from.
130    * @param[in] numbytes Size of the buffer.
131    * @result             true if the file is saved, else false.
132    */
133   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const = 0;
134
135 }; // class PlatformAbstraction
136
137 } // namespace Integration
138
139 } // namespace Dali
140
141 #endif // __DALI_INTEGRATION_PLATFORM_ABSTRACTION_H__