Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / images / native-image-interface.h
1 #ifndef DALI_NATIVE_IMAGE_INTERFACE_H
2 #define DALI_NATIVE_IMAGE_INTERFACE_H
3
4 /*
5  * Copyright (c) 2020 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 // EXTERNAL INCLUDES
22 #include <cstddef>
23 #include <cstdint> // uint32_t
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/object/ref-object.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_core_images
33  * @{
34  */
35
36 /**
37  * @brief Abstract interface to provide platform-specific support for handling image data.
38  *
39  * For example, an implementation could use EGL extensions, etc.
40  * @SINCE_1_0.0
41  */
42 class NativeImageInterface : public Dali::RefObject
43 {
44 public:
45   class Extension; ///< Forward declare future extension interface
46
47   /**
48    * @brief Creates the resource for the NativeImage.
49    *
50    * e.g. For the EglImageKHR extension, this corresponds to calling eglCreateImageKHR().
51    * @SINCE_1_9.23
52    * @return false If the initialization fails
53    * @pre The graphics subsystem has been initialized
54    */
55   virtual bool CreateResource() = 0;
56
57   /**
58    * @brief Destroys the resource for the NativeImage.
59    *
60    * e.g. For the EglImageKHR extension, this corresponds to calling eglDestroyImageKHR().
61    * @SINCE_1_9.23
62    * @pre The graphics subsystem has been initialized
63    */
64   virtual void DestroyResource() = 0;
65
66   /**
67    * @brief Uses the NativeImage as a texture for rendering.
68    *
69    * @SINCE_1_0.0
70    * @return An error code from the graphics subsystem.
71    * @pre The graphics subsystem has been initialized
72    */
73   virtual uint32_t TargetTexture() = 0;
74
75   /**
76    * @brief Called internally when the texture is bound in the GPU
77    *
78    * The correct texture sampler has already been bound before the function gets called.
79    * @SINCE_1_0.0
80    * @pre The graphics subsystem has been initialized
81    */
82   virtual void PrepareTexture() = 0;
83
84   /**
85    * @brief Returns the width of the NativeImage.
86    *
87    * @SINCE_1_0.0
88    * @return Width
89    */
90   virtual uint32_t GetWidth() const = 0;
91
92   /**
93    * @brief Returns the height of the NativeImage.
94    *
95    * @SINCE_1_0.0
96    * @return Height
97    */
98   virtual uint32_t GetHeight() const = 0;
99
100   /**
101   * @brief Queries whether blending is required.
102   * @SINCE_1_0.0
103   * @return True if blending is required
104   */
105   virtual bool RequiresBlending() const = 0;
106
107   /**
108    * @brief Get the texture target for binding native image as texture.
109    *
110    * @SINCE_1_9.23
111    * @return Texture target.
112    */
113   virtual int GetTextureTarget() const = 0;
114
115   /**
116    * @brief Get custom fragment prefix for rendering native image.
117    *
118    * @SINCE_1_9.23
119    * @return Custom fragment prefix code as string.
120    */
121   virtual const char* GetCustomFragmentPrefix() const = 0;
122
123   /**
124    * @brief Get custom sampler type name for rendering native image.
125    *
126    * @SINCE_1_9.23
127    * @return Custom sampler type name.
128    */
129   virtual const char* GetCustomSamplerTypename() const = 0;
130
131   /**
132    * @brief Retrieves the internal native image.
133    *
134    * @SINCE_1_9.23
135    * @return Any object containing the internal native image source
136    */
137   virtual Any GetNativeImageHandle() const = 0;
138
139   /**
140    * @brief Determine if the source for the native image has changed characteristics.
141    *
142    * @SINCE_1_9.23
143    * @return true if the source data has modified any characteristics of the
144    * native image, for example if the size of the buffer has changed.
145    */
146   virtual bool SourceChanged() const = 0;
147
148   /**
149    * @brief Retrieves the extension for the interface.
150    *
151    * @SINCE_1_0.0
152    * @return The extension if available, NULL otherwise
153    */
154   virtual Extension* GetExtension()
155   {
156     return nullptr;
157   }
158
159 protected:
160   /**
161    * @brief A reference counted object may only be deleted by calling Unreference().
162    *
163    * The implementation should destroy the NativeImage resources.
164    * @SINCE_1_0.0
165    */
166   ~NativeImageInterface() override = default;
167 };
168
169 /**
170  * @brief Pointer to Dali::NativeImageInterface.
171  * @SINCE_1_0.0
172  */
173 using NativeImageInterfacePtr = Dali::IntrusivePtr<NativeImageInterface>;
174
175 /**
176  * @}
177  */
178 } // namespace Dali
179
180 #endif // DALI_NATIVE_IMAGE_INTERFACE_H