From 45190af3cd8eb47f9bfc9ab42628cde9eb9431b6 Mon Sep 17 00:00:00 2001 From: liukaii Date: Tue, 7 Jan 2025 19:36:08 +0800 Subject: [PATCH] add snapshot c-api Signed-off-by: liukaii --- arkui/ace_engine/native/libace.ndk.json | 16 +++++++++ arkui/ace_engine/native/native_node.h | 18 ++++++++++ arkui/ace_engine/native/native_type.h | 46 +++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/arkui/ace_engine/native/libace.ndk.json b/arkui/ace_engine/native/libace.ndk.json index 1d822febf..2fef2d908 100644 --- a/arkui/ace_engine/native/libace.ndk.json +++ b/arkui/ace_engine/native/libace.ndk.json @@ -2470,5 +2470,21 @@ { "first_introduced": "14", "name": "OH_ArkUI_KeyEvent_SetConsumed" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_CreateSnapshotOptions" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_DestroySnapshotOptions" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_SnapshotOptions_SetScale" + }, + { + "first_introduced": "16", + "name": "OH_ArkUI_GetNodeSnapshot" } ] \ No newline at end of file diff --git a/arkui/ace_engine/native/native_node.h b/arkui/ace_engine/native/native_node.h index fd1db5f20..c4518aa64 100644 --- a/arkui/ace_engine/native/native_node.h +++ b/arkui/ace_engine/native/native_node.h @@ -7949,6 +7949,24 @@ float OH_ArkUI_SystemFontStyleEvent_GetFontSizeScale(const ArkUI_SystemFontStyle */ float OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontStyleEvent* event); +/** + * @brief get the snapshot pixelmap for the given node, + * will get error if the node is not on the tree or is not rendered yet. + * Note: the pixelmap should be released through OH_PixelmapNative_Release when it's not used any more. + * + * @param node Indicates the target node. + * @param snapshotOptions The given configuration for taking snapshot, can be null for using default. + * @param pixelmap Pixelmap pointer created by system, it's the out result. + * @return Returns the result code. + * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * Returns {@link ARKUI_ERROR_CODE_INTERNAL_ERROR} if some internal error occurs. + * Returns {@link ARKUI_ERROR_CODE_COMPONENT_SNAPSHOT_TIMEOUT} if the snapshot taking is timeout. + * @since 16 + */ +int32_t OH_ArkUI_GetNodeSnapshot(ArkUI_NodeHandle node, ArkUI_SnapshotOptions* snapshotOptions, + OH_PixelmapNative** pixelMap); + #ifdef __cplusplus }; #endif diff --git a/arkui/ace_engine/native/native_type.h b/arkui/ace_engine/native/native_type.h index ca825e62b..71425998e 100644 --- a/arkui/ace_engine/native/native_type.h +++ b/arkui/ace_engine/native/native_type.h @@ -1906,6 +1906,11 @@ typedef enum { ARKUI_ERROR_CODE_NO_ERROR = 0, /** @error Parameter error. */ ARKUI_ERROR_CODE_PARAM_INVALID = 401, + /** + * @error Internal error occurs. + * @since 16 + */ + ARKUI_ERROR_CODE_INTERNAL_ERROR = 100001, /** @error The component does not support specific properties or events. */ ARKUI_ERROR_CODE_ATTRIBUTE_OR_EVENT_NOT_SUPPORTED = 106102, /** @error The corresponding operation does not support nodes created by ArkTS. */ @@ -1928,6 +1933,11 @@ typedef enum { ARKUI_ERROR_CODE_GET_INFO_FAILED = 106201, /** The buffer size is not large enough. */ ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR = 106202, + /** + * @error The snapshot taking is timeout. + * @since 16 + */ + ARKUI_ERROR_CODE_COMPONENT_SNAPSHOT_TIMEOUT = 160002, /** The component is not a scroll container. */ ARKUI_ERROR_CODE_NON_SCROLLABLE_CONTAINER = 180001, /** The buffer is not large enough. */ @@ -2207,6 +2217,13 @@ typedef enum { */ typedef struct ArkUI_SystemFontStyleEvent ArkUI_SystemFontStyleEvent; +/** + * @brief Defines the options for taking snapshot. + * + * @since 16 + */ +typedef struct ArkUI_SnapshotOptions ArkUI_SnapshotOptions; + /** * @brief Creates a size constraint. * @@ -3935,6 +3952,35 @@ ArkUI_NodeHandle OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex(ArkUI_ActiveChildren * @since 14 */ int32_t OH_ArkUI_ActiveChildrenInfo_GetCount(ArkUI_ActiveChildrenInfo* handle); + +/** + * @brief Creates an option for taking snapshot, the returned value must be released through + * {@link OH_ArkUI_SnapshotOptions_Dispose} when it's not used anymore. + * + * @return Returns the pointer to the created snapshot options object.If the object returns a null pointer, + * it indicates a creation failure, and the reason for the failure may be that the address space is full. + * @since 16 + */ +ArkUI_SnapshotOptions* OH_ArkUI_CreateSnapshotOptions(); + +/** + * @brief Dispose a snapshot option object. + * + * @param snapshotOptions Indicates the pointer to the snapshot option. + * @since 16 + */ +void OH_ArkUI_DestroySnapshotOptions(ArkUI_SnapshotOptions* snapshotOptions); + +/** + * @brief Config the snapshot option with scale. + * + * @param snapshotOptions Indicates the pointer to the snapshot option. + * @param scale Indicates the scale property to take the snapshot. + * @return Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * @since 16 + */ +void OH_ArkUI_SnapshotOptions_SetScale(ArkUI_SnapshotOptions* snapshotOptions, float scale); #ifdef __cplusplus }; #endif -- Gitee