From c7b54e8a9d9165220d787df53f2b15ea23ee43c5 Mon Sep 17 00:00:00 2001 From: m00472246 Date: Fri, 12 Jul 2024 11:57:51 +0800 Subject: [PATCH] =?UTF-8?q?NativeImage=E5=AF=B9=E5=A4=96=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?NativeWindowBuffer=E9=9C=80=E6=B1=82=20Signed-off-by:=20m004722?= =?UTF-8?q?46=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: m00472246 --- .../native_image/libnative_image.ndk.json | 10 +++- .../graphic_2d/native_image/native_image.h | 49 +++++++++++++++++++ .../native_window/graphic_error_code.h | 4 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/graphic/graphic_2d/native_image/libnative_image.ndk.json b/graphic/graphic_2d/native_image/libnative_image.ndk.json index fbc8a27c01f..c591bf0fd43 100644 --- a/graphic/graphic_2d/native_image/libnative_image.ndk.json +++ b/graphic/graphic_2d/native_image/libnative_image.ndk.json @@ -10,5 +10,13 @@ { "name": "OH_NativeImage_SetOnFrameAvailableListener" }, { "name": "OH_NativeImage_UnsetOnFrameAvailableListener" }, { "name": "OH_NativeImage_Destroy" }, - { "name": "OH_NativeImage_GetTransformMatrixV2" } + { "name": "OH_NativeImage_GetTransformMatrixV2" }, + { + "first_introduced": "12", + "name": "OH_NativeImage_AcquireNativeWindowBuffer" + }, + { + "first_introduced": "12", + "name": "OH_NativeImage_ReleaseNativeWindowBuffer" + } ] \ No newline at end of file diff --git a/graphic/graphic_2d/native_image/native_image.h b/graphic/graphic_2d/native_image/native_image.h index 0f6fd61eab9..d5447f0a5a6 100644 --- a/graphic/graphic_2d/native_image/native_image.h +++ b/graphic/graphic_2d/native_image/native_image.h @@ -46,6 +46,11 @@ extern "C" { struct OH_NativeImage; typedef struct OH_NativeImage OH_NativeImage; typedef struct NativeWindow OHNativeWindow; +/** + * @brief define the new type name OHNativeWindowBuffer for struct NativeWindowBuffer. + * @since 12 + */ +typedef struct NativeWindowBuffer OHNativeWindowBuffer; /** * @brief The callback function of frame available. * @@ -215,6 +220,50 @@ void OH_NativeImage_Destroy(OH_NativeImage** image); */ int32_t OH_NativeImage_GetTransformMatrixV2(OH_NativeImage* image, float matrix[16]); +/** + * @brief Acquire an OHNativeWindowBuffer through an OH_NativeImage instance for content consumer.\n + * This method can not be used at the same time with OH_NativeImage_UpdateSurfaceImage.\n + * This method will create an OHNativeWindowBuffer.\n + * When using OHNativeWindowBuffer, need to increase its reference count + * by OH_NativeWindow_NativeObjectReference.\n + * When the OHNativeWindowBuffer is used up, its reference count needs to be decremented + * by OH_NativeWindow_NativeObjectUnreference.\n + * This interface needs to be used in conjunction with OH_NativeImage_ReleaseNativeWindowBuffer<\b>, + * otherwise memory leaks will occur.\n + * When the fenceFd is used up, you need to close it.\n + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeImage + * @param image Indicates the pointer to a OH_NativeImage instance. + * @param nativeWindowBuffer Indicates the pointer to an OHNativeWindowBuffer point. + * @param fenceFd Indicates the pointer to a file descriptor handle. + * @return {@link NATIVE_ERROR_OK} 0 - Success. + * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - image, nativeWindowBuffer, fenceFd is NULL. + * {@link NATIVE_ERROR_NO_BUFFER} 40601000 - No buffer for consume. + * @since 12 + * @version 1.0 + */ +int32_t OH_NativeImage_AcquireNativeWindowBuffer(OH_NativeImage* image, + OHNativeWindowBuffer** nativeWindowBuffer, int* fenceFd); + +/** + * @brief Release the OHNativeWindowBuffer to the buffer queue through an + * OH_NativeImage instance for reuse.\n + * The fenceFd will be close by system.\n + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeImage + * @param image Indicates the pointer to a OH_NativeImage instance. + * @param nativeWindowBuffer Indicates the pointer to an OHNativeWindowBuffer instance. + * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. + * @return {@link NATIVE_ERROR_OK} 0 - Success. + * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - image, nativeWindowBuffer is NULL. + * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - nativeWindowBuffer state invalid. + * {@link NATIVE_ERROR_BUFFER_NOT_IN_CACHE} 41210000 - nativeWindowBuffer not in cache. + * @since 12 + * @version 1.0 + */ +int32_t OH_NativeImage_ReleaseNativeWindowBuffer(OH_NativeImage* image, + OHNativeWindowBuffer* nativeWindowBuffer, int fenceFd); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_window/graphic_error_code.h b/graphic/graphic_2d/native_window/graphic_error_code.h index a65d302914b..84a481ba224 100644 --- a/graphic/graphic_2d/native_window/graphic_error_code.h +++ b/graphic/graphic_2d/native_window/graphic_error_code.h @@ -70,6 +70,10 @@ typedef enum OHNativeErrorCode { NATIVE_ERROR_BUFFER_QUEUE_FULL = 41209000, /** @error buffer is not in the cache queue */ NATIVE_ERROR_BUFFER_NOT_IN_CACHE = 41210000, + /** @error the consumer is disconnected */ + NATIVE_ERROR_CONSUMER_DISCONNECTED = 41211000, + /** @error the consumer not register listener */ + NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED = 41212000, /** @error the current device or platform does not support it */ NATIVE_ERROR_UNSUPPORTED = 50102000, /** @error unknown error, please check log */ -- Gitee