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