1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NDK_INCLUDE_NATIVE_IMAGE_H_ 17 #define NDK_INCLUDE_NATIVE_IMAGE_H_ 18 19 /** 20 * @addtogroup OH_NativeImage 21 * @{ 22 * 23 * @brief Provides the native image capability. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 26 * @since 9 27 * @version 1.0 28 */ 29 30 /** 31 * @file native_image.h 32 * 33 * @brief Defines the functions for obtaining and using a native image. 34 * 35 * @library libnative_image.so 36 * @since 9 37 * @version 1.0 38 */ 39 40 #include <stdint.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 struct OH_NativeImage; 47 typedef struct OH_NativeImage OH_NativeImage; 48 typedef struct NativeWindow OHNativeWindow; 49 50 /** 51 * @brief The callback function of frame available. 52 * 53 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 54 * @param context User defined context, returned to the user in the callback function 55 * @since 11 56 * @version 1.0 57 */ 58 typedef void (*OH_OnFrameAvailable)(void *context); 59 60 /** 61 * @brief A listener for native image, use <b>OH_NativeImage_SetOnFrameAvailableListener</b> to register \n 62 * the listener object to <b>OH_NativeImage</b>, the callback will be triggered when there is available frame 63 * 64 * @since 11 65 * @version 1.0 66 */ 67 typedef struct OH_OnFrameAvailableListener { 68 void *context; 69 OH_OnFrameAvailable onFrameAvailable; 70 } OH_OnFrameAvailableListener; 71 72 73 /** 74 * @brief Create a <b>OH_NativeImage</b> related to an Opengl ES texture and target. \n 75 * 76 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 77 * @param textureId Indicates the id of the Opengl ES texture which the native image attached to. 78 * @param textureTarget Indicates the Opengl ES target. 79 * @return Returns the pointer to the <b>OH_NativeImage</b> instance created if the operation is successful, \n 80 * returns <b>NULL</b> otherwise. 81 * @since 9 82 * @version 1.0 83 */ 84 OH_NativeImage* OH_NativeImage_Create(uint32_t textureId, uint32_t textureTarget); 85 86 /** 87 * @brief Acquire the OHNativeWindow for the OH_NativeImage. This OHNativeWindow should be released by \n 88 * OH_NativeWindow_DestroyNativeWindow when no longer needed. 89 * 90 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 91 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 92 * @return Returns the pointer to the OHNativeWindow if the operation is successful, returns <b>NULL</b> otherwise. 93 * @since 9 94 * @version 1.0 95 */ 96 OHNativeWindow* OH_NativeImage_AcquireNativeWindow(OH_NativeImage* image); 97 98 /** 99 * @brief Attach the OH_NativeImage to Opengl ES context, and the Opengl ES texture is bound to the \n 100 * GL_TEXTURE_EXTERNAL_OES, which will update by the OH_NativeImage. 101 * 102 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 103 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 104 * @param textureId Indicates the id of the Opengl ES texture which the native image attached to. 105 * @return Returns an error code, 0 is success, otherwise, failed. 106 * @since 9 107 * @version 1.0 108 */ 109 int32_t OH_NativeImage_AttachContext(OH_NativeImage* image, uint32_t textureId); 110 111 /** 112 * @brief Detach the OH_NativeImage from the Opengl ES context. 113 * 114 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 115 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 116 * @return Returns an error code, 0 is success, otherwise, failed. 117 * @since 9 118 * @version 1.0 119 */ 120 121 int32_t OH_NativeImage_DetachContext(OH_NativeImage* image); 122 123 /** 124 * @brief Update the related Opengl ES texture with the OH_NativeImage acquired buffer. 125 * 126 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 127 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 128 * @return Returns an error code, 0 is success, otherwise, failed. 129 * @since 9 130 * @version 1.0 131 */ 132 int32_t OH_NativeImage_UpdateSurfaceImage(OH_NativeImage* image); 133 134 /** 135 * @brief Get the timestamp of the texture image set by the most recent call to OH_NativeImage_UpdateSurfaceImage. 136 * 137 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 138 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 139 * @return Returns the timestamp associated to the texture image. 140 * @since 9 141 * @version 1.0 142 */ 143 int64_t OH_NativeImage_GetTimestamp(OH_NativeImage* image); 144 145 /** 146 * @brief Obtains the transform matrix of the texture image set by the most recent call to \n 147 * OH_NativeImage_UpdateSurfaceImage. 148 * 149 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 150 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 151 * @param matrix Indicates the retrieved 4*4 transform matrix . 152 * @return Returns an error code, 0 is success, otherwise, failed. 153 * @since 9 154 * @version 1.0 155 */ 156 int32_t OH_NativeImage_GetTransformMatrix(OH_NativeImage* image, float matrix[16]); 157 158 /** 159 * @brief Obtains the native image's surface id. 160 * 161 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 162 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 163 * @param surfaceId Indicates the surface id. 164 * @return Returns an error code, 0 is success, otherwise, failed. 165 * @since 11 166 * @version 1.0 167 */ 168 int32_t OH_NativeImage_GetSurfaceId(OH_NativeImage* image, uint64_t* surfaceId); 169 170 /** 171 * @brief Set the frame available callback. 172 * 173 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 174 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 175 * @param listener Indicates the callback function. 176 * @return Returns an error code, 0 is success, otherwise, failed. 177 * @since 11 178 * @version 1.0 179 */ 180 int32_t OH_NativeImage_SetOnFrameAvailableListener(OH_NativeImage* image, OH_OnFrameAvailableListener listener); 181 182 /** 183 * @brief Unset the frame available callback. 184 * 185 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 186 * @param image Indicates the pointer to a <b>OH_NativeImage</b> instance. 187 * @return Returns an error code, 0 is success, otherwise, failed. 188 * @since 11 189 * @version 1.0 190 */ 191 int32_t OH_NativeImage_UnsetOnFrameAvailableListener(OH_NativeImage* image); 192 193 /** 194 * @brief Destroy the <b>OH_NativeImage</b> created by OH_NativeImage_Create, and the pointer to \n 195 * <b>OH_NativeImage</b> will be null after this operation. 196 * 197 * @syscap SystemCapability.Graphic.Graphic2D.NativeImage 198 * @param image Indicates the pointer to a <b>OH_NativeImage</b> pointer. 199 * @since 9 200 * @version 1.0 201 */ 202 void OH_NativeImage_Destroy(OH_NativeImage** image); 203 204 #ifdef __cplusplus 205 } 206 #endif 207 208 /** @} */ 209 #endif