diff --git a/graphic/graphic_2d/native_image/libnative_image.ndk.json b/graphic/graphic_2d/native_image/libnative_image.ndk.json index fbc8a27c01f860937c342084c7510c5cefa0e878..c591bf0fd4313549f7db25d9257c799d48002116 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 0f6fd61eab9c5e53d272ed76dc531b3874ca99fc..d5447f0a5a6e9697fad0fee881e91b2de5b4d657 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 a65d302914b9c7443cd87b729bb7acbd5274d46e..84a481ba224c213da4c2cc5928c90778048867bd 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 */