• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*c
2  * Copyright (c) 2025 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 #include "node_component_snapshot.h"
17 
18 #include "node/node_model.h"
19 #include "pixelmap_native_impl.h"
20 
21 #include "base/utils/utils.h"
22 #include "frameworks/base/error/error_code.h"
23 #include "frameworks/core/components_ng/base/frame_node.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
OH_ArkUI_CreateSnapshotOptions()29 ArkUI_SnapshotOptions* OH_ArkUI_CreateSnapshotOptions()
30 {
31     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
32     CHECK_NULL_RETURN(impl, nullptr);
33     auto snapshotOptions = impl->getSnapshotAPI()->createSnapshotOptions();
34     return reinterpret_cast<ArkUI_SnapshotOptions*>(snapshotOptions);
35 }
36 
OH_ArkUI_DestroySnapshotOptions(ArkUI_SnapshotOptions * snapshotOptions)37 void OH_ArkUI_DestroySnapshotOptions(ArkUI_SnapshotOptions* snapshotOptions)
38 {
39     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
40     CHECK_NULL_VOID(impl);
41     auto options = reinterpret_cast<ArkUISnapshotOptions*>(snapshotOptions);
42     impl->getSnapshotAPI()->destroySnapshotOptions(options);
43 }
44 
OH_ArkUI_SnapshotOptions_SetScale(ArkUI_SnapshotOptions * snapshotOptions,float scale)45 int32_t OH_ArkUI_SnapshotOptions_SetScale(ArkUI_SnapshotOptions* snapshotOptions, float scale)
46 {
47     CHECK_NULL_RETURN(snapshotOptions, ArkUI_ErrorCode::ARKUI_ERROR_CODE_PARAM_INVALID);
48     if (!OHOS::Ace::GreatNotEqual(scale, 0.0)) {
49         return ArkUI_ErrorCode::ARKUI_ERROR_CODE_PARAM_INVALID;
50     }
51     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
52     CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_INTERNAL_ERROR);
53     auto result = impl->getSnapshotAPI()->snapshotOptionsSetScale(
54         reinterpret_cast<ArkUISnapshotOptions*>(snapshotOptions), scale);
55     return result;
56 }
57 
OH_ArkUI_GetNodeSnapshot(ArkUI_NodeHandle node,ArkUI_SnapshotOptions * snapshotOptions,OH_PixelmapNative ** pixelmap)58 int32_t OH_ArkUI_GetNodeSnapshot(
59     ArkUI_NodeHandle node, ArkUI_SnapshotOptions* snapshotOptions, OH_PixelmapNative** pixelmap)
60 {
61     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
62     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
63     CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_INTERNAL_ERROR);
64     auto options = reinterpret_cast<ArkUISnapshotOptions*>(snapshotOptions);
65     std::shared_ptr<OHOS::Media::PixelMap> tmpPixel;
66     auto result = impl->getSnapshotAPI()->getSyncSnapshot(node->uiNodeHandle, options, &tmpPixel);
67     switch (result) {
68         case OHOS::Ace::ERROR_CODE_PARAM_INVALID:
69             return ARKUI_ERROR_CODE_PARAM_INVALID;
70         case OHOS::Ace::ERROR_CODE_NO_ERROR:
71             if (tmpPixel) {
72                 *pixelmap = new (std::nothrow) OH_PixelmapNative(tmpPixel);
73                 return ARKUI_ERROR_CODE_NO_ERROR;
74             }
75             return ARKUI_ERROR_CODE_INTERNAL_ERROR;
76         case OHOS::Ace::ERROR_CODE_COMPONENT_SNAPSHOT_TIMEOUT:
77             return ARKUI_ERROR_CODE_COMPONENT_SNAPSHOT_TIMEOUT;
78         default:
79             return ARKUI_ERROR_CODE_INTERNAL_ERROR;
80     }
81 }
82 
83 #ifdef __cplusplus
84 };
85 #endif