1 /*
2 * Copyright (c) 2021-2024 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 "native_interface_xcomponent.h"
17
18 #include "node/node_model.h"
19
20 #include "base/error/error_code.h"
21 #include "frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h"
22 #include "frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
OH_NativeXComponent_GetXComponentId(OH_NativeXComponent * component,char * id,uint64_t * size)28 int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size)
29 {
30 if ((component == nullptr) || (id == nullptr) || (size == nullptr)) {
31 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
32 }
33 if (((*size) == 0) || ((*size) > (OH_XCOMPONENT_ID_LEN_MAX + 1))) {
34 LOGE("The referenced value of 'size' should be in the range (0, OH_XCOMPONENT_ID_LEN_MAX + 1]");
35 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
36 }
37 return component->GetXComponentId(id, size);
38 }
39
OH_NativeXComponent_GetXComponentSize(OH_NativeXComponent * component,const void * window,uint64_t * width,uint64_t * height)40 int32_t OH_NativeXComponent_GetXComponentSize(
41 OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height)
42 {
43 if ((component == nullptr) || (window == nullptr) || (width == nullptr) || (height == nullptr)) {
44 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
45 }
46 return component->GetXComponentSize(window, width, height);
47 }
48
OH_NativeXComponent_GetXComponentOffset(OH_NativeXComponent * component,const void * window,double * x,double * y)49 int32_t OH_NativeXComponent_GetXComponentOffset(
50 OH_NativeXComponent* component, const void* window, double* x, double* y)
51 {
52 if ((component == nullptr) || (window == nullptr) || (x == nullptr) || (y == nullptr)) {
53 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
54 }
55 return component->GetXComponentOffset(window, x, y);
56 }
57
OH_NativeXComponent_GetTouchEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_TouchEvent * touchEvent)58 int32_t OH_NativeXComponent_GetTouchEvent(
59 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent)
60 {
61 if ((component == nullptr) || (window == nullptr) || (touchEvent == nullptr)) {
62 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
63 }
64 return component->GetTouchEvent(window, touchEvent);
65 }
66
OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent * component,uint32_t pointIndex,OH_NativeXComponent_TouchPointToolType * toolType)67 int32_t OH_NativeXComponent_GetTouchPointToolType(
68 OH_NativeXComponent* component, uint32_t pointIndex, OH_NativeXComponent_TouchPointToolType* toolType)
69 {
70 if ((component == nullptr) || (toolType == nullptr)) {
71 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
72 }
73 return component->GetToolType(pointIndex, toolType);
74 }
75
OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltX)76 int32_t OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltX)
77 {
78 if ((component == nullptr) || (tiltX == nullptr)) {
79 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
80 }
81 return component->GetTiltX(pointIndex, tiltX);
82 }
83
OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltY)84 int32_t OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltY)
85 {
86 if ((component == nullptr) || (tiltY == nullptr)) {
87 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
88 }
89 return component->GetTiltY(pointIndex, tiltY);
90 }
91
OH_NativeXComponent_GetTouchPointWindowX(OH_NativeXComponent * component,uint32_t pointIndex,float * windowX)92 int32_t OH_NativeXComponent_GetTouchPointWindowX(OH_NativeXComponent* component, uint32_t pointIndex, float* windowX)
93 {
94 if ((component == nullptr) || (windowX == nullptr)) {
95 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
96 }
97 return component->GetWindowX(pointIndex, windowX);
98 }
99
OH_NativeXComponent_GetTouchPointWindowY(OH_NativeXComponent * component,uint32_t pointIndex,float * windowY)100 int32_t OH_NativeXComponent_GetTouchPointWindowY(OH_NativeXComponent* component, uint32_t pointIndex, float* windowY)
101 {
102 if ((component == nullptr) || (windowY == nullptr)) {
103 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
104 }
105 return component->GetWindowY(pointIndex, windowY);
106 }
107
OH_NativeXComponent_GetTouchPointDisplayX(OH_NativeXComponent * component,uint32_t pointIndex,float * displayX)108 int32_t OH_NativeXComponent_GetTouchPointDisplayX(OH_NativeXComponent* component, uint32_t pointIndex, float* displayX)
109 {
110 if ((component == nullptr) || (displayX == nullptr)) {
111 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
112 }
113 return component->GetDisplayX(pointIndex, displayX);
114 }
115
OH_NativeXComponent_GetTouchPointDisplayY(OH_NativeXComponent * component,uint32_t pointIndex,float * displayY)116 int32_t OH_NativeXComponent_GetTouchPointDisplayY(OH_NativeXComponent* component, uint32_t pointIndex, float* displayY)
117 {
118 if ((component == nullptr) || (displayY == nullptr)) {
119 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
120 }
121 return component->GetDisplayY(pointIndex, displayY);
122 }
123
OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent * component,const void * window,int32_t * size,OH_NativeXComponent_HistoricalPoint ** historicalPoints)124 int32_t OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent* component, const void* window,
125 int32_t* size, OH_NativeXComponent_HistoricalPoint** historicalPoints)
126 {
127 if ((component == nullptr) || (window == nullptr)) {
128 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
129 }
130 return component->GetHistoryPoints(window, size, historicalPoints);
131 }
132
OH_NativeXComponent_GetMouseEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_MouseEvent * mouseEvent)133 int32_t OH_NativeXComponent_GetMouseEvent(
134 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_MouseEvent* mouseEvent)
135 {
136 if ((component == nullptr) || (window == nullptr) || (mouseEvent == nullptr)) {
137 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
138 }
139 return component->GetMouseEvent(window, mouseEvent);
140 }
141
OH_NativeXComponent_RegisterCallback(OH_NativeXComponent * component,OH_NativeXComponent_Callback * callback)142 int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback)
143 {
144 if ((component == nullptr) || (callback == nullptr)) {
145 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
146 }
147 return component->RegisterCallback(callback);
148 }
149
OH_NativeXComponent_RegisterMouseEventCallback(OH_NativeXComponent * component,OH_NativeXComponent_MouseEvent_Callback * callback)150 int32_t OH_NativeXComponent_RegisterMouseEventCallback(
151 OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent_Callback* callback)
152 {
153 if ((component == nullptr) || (callback == nullptr)) {
154 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
155 }
156 return component->RegisterMouseEventCallback(callback);
157 }
158
OH_NativeXComponent_RegisterFocusEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))159 int32_t OH_NativeXComponent_RegisterFocusEventCallback(
160 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
161 {
162 if ((component == nullptr) || (callback == nullptr)) {
163 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
164 }
165 return component->RegisterFocusEventCallback(callback);
166 }
167
OH_NativeXComponent_RegisterKeyEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))168 int32_t OH_NativeXComponent_RegisterKeyEventCallback(
169 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
170 {
171 if ((component == nullptr) || (callback == nullptr)) {
172 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
173 }
174 return component->RegisterKeyEventCallback(callback);
175 }
176
OH_NativeXComponent_RegisterBlurEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))177 int32_t OH_NativeXComponent_RegisterBlurEventCallback(
178 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
179 {
180 if ((component == nullptr) || (callback == nullptr)) {
181 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
182 }
183 return component->RegisterBlurEventCallback(callback);
184 }
185
OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent * component,OH_NativeXComponent_KeyEvent ** keyEvent)186 int32_t OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent* component, OH_NativeXComponent_KeyEvent** keyEvent)
187 {
188 if ((component == nullptr) || (keyEvent == nullptr)) {
189 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
190 }
191 return component->GetKeyEvent(keyEvent);
192 }
193
OH_NativeXComponent_GetKeyEventAction(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyAction * action)194 int32_t OH_NativeXComponent_GetKeyEventAction(
195 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyAction* action)
196 {
197 if ((keyEvent == nullptr) || (action == nullptr)) {
198 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
199 }
200 (*action) = keyEvent->action;
201 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
202 }
203
OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyCode * code)204 int32_t OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyCode* code)
205 {
206 if ((keyEvent == nullptr) || (code == nullptr)) {
207 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
208 }
209 (*code) = keyEvent->code;
210 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
211 }
212
OH_NativeXComponent_GetKeyEventSourceType(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_EventSourceType * sourceType)213 int32_t OH_NativeXComponent_GetKeyEventSourceType(
214 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_EventSourceType* sourceType)
215 {
216 if ((keyEvent == nullptr) || (sourceType == nullptr)) {
217 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
218 }
219 (*sourceType) = keyEvent->sourceType;
220 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
221 }
222
OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * deviceId)223 int32_t OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* deviceId)
224 {
225 if ((keyEvent == nullptr) || (deviceId == nullptr)) {
226 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
227 }
228 (*deviceId) = keyEvent->deviceId;
229 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
230 }
231
OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * timestamp)232 int32_t OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* timestamp)
233 {
234 if ((keyEvent == nullptr) || (timestamp == nullptr)) {
235 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
236 }
237 (*timestamp) = keyEvent->timestamp;
238 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
239 }
240
OH_NativeXComponent_SetExpectedFrameRateRange(OH_NativeXComponent * component,OH_NativeXComponent_ExpectedRateRange * range)241 int32_t OH_NativeXComponent_SetExpectedFrameRateRange(
242 OH_NativeXComponent* component, OH_NativeXComponent_ExpectedRateRange* range)
243 {
244 if (component == nullptr || range == nullptr) {
245 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
246 }
247 return component->SetExpectedFrameRateRange(range);
248 }
249
OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,uint64_t timestamp,uint64_t targetTimestamp))250 int32_t OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent* component,
251 void (*callback)(OH_NativeXComponent* component, uint64_t timestamp, uint64_t targetTimestamp))
252 {
253 if (component == nullptr) {
254 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
255 }
256 return component->RegisterOnFrameCallback(callback);
257 }
258
OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent * component)259 int32_t OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent* component)
260 {
261 if (component == nullptr) {
262 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
263 }
264 return component->UnregisterOnFrameCallback();
265 }
266
OH_NativeXComponent_AttachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)267 int32_t OH_NativeXComponent_AttachNativeRootNode(
268 OH_NativeXComponent* component, ArkUI_NodeHandle root)
269 {
270 if ((component == nullptr) || (root == nullptr) || !OHOS::Ace::NodeModel::CheckIsCNode(root)) {
271 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
272 }
273 return component->AttachNativeRootNode(root->uiNodeHandle);
274 }
275
OH_NativeXComponent_DetachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)276 int32_t OH_NativeXComponent_DetachNativeRootNode(
277 OH_NativeXComponent* component, ArkUI_NodeHandle root)
278 {
279 if ((component == nullptr) || (root == nullptr) || !OHOS::Ace::NodeModel::CheckIsCNode(root)) {
280 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
281 }
282 return component->DetachNativeRootNode(root->uiNodeHandle);
283 }
284
OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,ArkUI_UIInputEvent * event,ArkUI_UIInputEvent_Type type),ArkUI_UIInputEvent_Type type)285 int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
286 void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
287 ArkUI_UIInputEvent_Type type)
288 {
289 if ((component == nullptr) || (callback == nullptr)) {
290 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
291 }
292 if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) {
293 return component->RegisterUIAxisEventCallback(callback);
294 }
295 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
296 }
297
OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent * component,bool needSoftKeyboard)298 int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard)
299 {
300 return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
301 }
302
OH_NativeXComponent_RegisterSurfaceShowCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))303 int32_t OH_NativeXComponent_RegisterSurfaceShowCallback(
304 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
305 {
306 return (component && callback) ? component->RegisterSurfaceShowCallback(callback)
307 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
308 }
309
OH_NativeXComponent_RegisterSurfaceHideCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))310 int32_t OH_NativeXComponent_RegisterSurfaceHideCallback(
311 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
312 {
313 return (component && callback) ? component->RegisterSurfaceHideCallback(callback)
314 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
315 }
316
OH_NativeXComponent_RegisterOnTouchInterceptCallback(OH_NativeXComponent * component,HitTestMode (* callback)(OH_NativeXComponent * component,ArkUI_UIInputEvent * event))317 int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback(
318 OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event))
319 {
320 if ((component == nullptr) || (callback == nullptr)) {
321 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
322 }
323 return component->RegisterOnTouchInterceptCallback(callback);
324 }
325
OH_NativeXComponent_GetTouchEventSourceType(OH_NativeXComponent * component,int32_t pointId,OH_NativeXComponent_EventSourceType * sourceType)326 int32_t OH_NativeXComponent_GetTouchEventSourceType(
327 OH_NativeXComponent* component, int32_t pointId, OH_NativeXComponent_EventSourceType* sourceType)
328 {
329 return (component && sourceType) ? component->GetSourceType(pointId, sourceType)
330 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
331 }
332
OH_NativeXComponent_GetNativeXComponent(ArkUI_NodeHandle node)333 OH_NativeXComponent* OH_NativeXComponent_GetNativeXComponent(ArkUI_NodeHandle node)
334 {
335 if (node == nullptr || (node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
336 return nullptr;
337 }
338 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
339 return reinterpret_cast<OH_NativeXComponent*>(
340 nodeModifiers->getXComponentModifier()->getNativeXComponent(node->uiNodeHandle));
341 }
342
OH_NativeXComponent_GetNativeAccessibilityProvider(OH_NativeXComponent * component,ArkUI_AccessibilityProvider ** handle)343 int32_t OH_NativeXComponent_GetNativeAccessibilityProvider(
344 OH_NativeXComponent* component, ArkUI_AccessibilityProvider** handle)
345 {
346 if ((component == nullptr) || (handle == nullptr)) {
347 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
348 }
349
350 return component->GetAccessibilityProvider(handle);
351 }
352
OH_NativeXComponent_RegisterKeyEventCallbackWithResult(OH_NativeXComponent * component,bool (* callback)(OH_NativeXComponent * component,void * window))353 int32_t OH_NativeXComponent_RegisterKeyEventCallbackWithResult(
354 OH_NativeXComponent* component, bool (*callback)(OH_NativeXComponent* component, void* window))
355 {
356 if ((component == nullptr) || (callback == nullptr)) {
357 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
358 }
359 return component->RegisterKeyEventCallbackWithResult(callback);
360 }
361
OH_ArkUI_XComponent_StartImageAnalyzer(ArkUI_NodeHandle node,void * userData,void (* callback)(ArkUI_NodeHandle node,ArkUI_XComponent_ImageAnalyzerState statusCode,void * userData))362 int32_t OH_ArkUI_XComponent_StartImageAnalyzer(ArkUI_NodeHandle node, void* userData,
363 void (*callback)(ArkUI_NodeHandle node, ArkUI_XComponent_ImageAnalyzerState statusCode, void* userData))
364 {
365 if ((!OHOS::Ace::NodeModel::IsValidArkUINode(node)) ||
366 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE) ||
367 (callback == nullptr)) {
368 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
369 }
370 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
371 nodeModifiers->getXComponentModifier()->startImageAnalyzer(node->uiNodeHandle, node, userData,
372 reinterpret_cast<XComponentAnalyzerCallback>(callback));
373 return OHOS::Ace::ERROR_CODE_NO_ERROR;
374 }
375
OH_ArkUI_XComponent_StopImageAnalyzer(ArkUI_NodeHandle node)376 int32_t OH_ArkUI_XComponent_StopImageAnalyzer(ArkUI_NodeHandle node)
377 {
378 if ((!OHOS::Ace::NodeModel::IsValidArkUINode(node)) ||
379 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
380 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
381 }
382 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
383 nodeModifiers->getXComponentModifier()->stopImageAnalyzer(node->uiNodeHandle);
384 return OHOS::Ace::ERROR_CODE_NO_ERROR;
385 }
386
OH_ArkUI_SurfaceHolder_Create(ArkUI_NodeHandle node)387 OH_ArkUI_SurfaceHolder* OH_ArkUI_SurfaceHolder_Create(ArkUI_NodeHandle node)
388 {
389 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
390 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
391 return nullptr;
392 }
393 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
394 CHECK_NULL_RETURN(impl, nullptr);
395 auto nodeModifiers = impl->getNodeModifiers();
396 CHECK_NULL_RETURN(nodeModifiers, nullptr);
397 auto xComponentModifier = nodeModifiers->getXComponentModifier();
398 CHECK_NULL_RETURN(xComponentModifier, nullptr);
399 auto* surfaceHolder =
400 reinterpret_cast<OH_ArkUI_SurfaceHolder*>(xComponentModifier->createSurfaceHolder(node->uiNodeHandle));
401 CHECK_NULL_RETURN(surfaceHolder, nullptr);
402 surfaceHolder->node_ = node;
403 return surfaceHolder;
404 }
405
OH_ArkUI_SurfaceHolder_Dispose(OH_ArkUI_SurfaceHolder * surfaceHolder)406 void OH_ArkUI_SurfaceHolder_Dispose(OH_ArkUI_SurfaceHolder* surfaceHolder)
407 {
408 if (surfaceHolder) {
409 auto node = surfaceHolder->node_;
410 if (OHOS::Ace::NodeModel::IsValidArkUINode(node)) {
411 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
412 CHECK_NULL_VOID(impl);
413 auto nodeModifiers = impl->getNodeModifiers();
414 CHECK_NULL_VOID(nodeModifiers);
415 auto xComponentModifier = nodeModifiers->getXComponentModifier();
416 CHECK_NULL_VOID(xComponentModifier);
417 xComponentModifier->dispose(node->uiNodeHandle);
418 }
419 }
420 delete surfaceHolder;
421 }
422
OH_ArkUI_SurfaceHolder_SetUserData(OH_ArkUI_SurfaceHolder * surfaceHolder,void * userData)423 int32_t OH_ArkUI_SurfaceHolder_SetUserData(OH_ArkUI_SurfaceHolder* surfaceHolder, void* userData)
424 {
425 if (surfaceHolder == nullptr) {
426 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
427 }
428 surfaceHolder->userData_ = userData;
429 return OHOS::Ace::ERROR_CODE_NO_ERROR;
430 }
431
OH_ArkUI_SurfaceHolder_GetUserData(OH_ArkUI_SurfaceHolder * surfaceHolder)432 void* OH_ArkUI_SurfaceHolder_GetUserData(OH_ArkUI_SurfaceHolder* surfaceHolder)
433 {
434 if (surfaceHolder == nullptr) {
435 return nullptr;
436 }
437 return surfaceHolder->userData_;
438 }
439
OH_ArkUI_SurfaceCallback_Create(void)440 OH_ArkUI_SurfaceCallback* OH_ArkUI_SurfaceCallback_Create(void)
441 {
442 OH_ArkUI_SurfaceCallback* surfaceCallback = new OH_ArkUI_SurfaceCallback();
443 return surfaceCallback;
444 }
445
OH_ArkUI_SurfaceCallback_Dispose(OH_ArkUI_SurfaceCallback * callback)446 void OH_ArkUI_SurfaceCallback_Dispose(OH_ArkUI_SurfaceCallback* callback)
447 {
448 delete callback;
449 }
450
OH_ArkUI_SurfaceCallback_SetSurfaceCreatedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceCreated)(OH_ArkUI_SurfaceHolder * surfaceHolder))451 void OH_ArkUI_SurfaceCallback_SetSurfaceCreatedEvent(
452 OH_ArkUI_SurfaceCallback* callback, void (*onSurfaceCreated)(OH_ArkUI_SurfaceHolder* surfaceHolder))
453 {
454 CHECK_NULL_VOID(callback);
455 callback->OnSurfaceCreated = onSurfaceCreated;
456 }
457
OH_ArkUI_SurfaceCallback_SetSurfaceChangedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceChanged)(OH_ArkUI_SurfaceHolder * surfaceHolder,uint64_t width,uint64_t height))458 void OH_ArkUI_SurfaceCallback_SetSurfaceChangedEvent(OH_ArkUI_SurfaceCallback* callback,
459 void (*onSurfaceChanged)(OH_ArkUI_SurfaceHolder* surfaceHolder, uint64_t width, uint64_t height))
460 {
461 CHECK_NULL_VOID(callback);
462 callback->OnSurfaceChanged = onSurfaceChanged;
463 }
464
OH_ArkUI_SurfaceCallback_SetSurfaceDestroyedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceDestroyed)(OH_ArkUI_SurfaceHolder * surfaceHolder))465 void OH_ArkUI_SurfaceCallback_SetSurfaceDestroyedEvent(
466 OH_ArkUI_SurfaceCallback* callback,
467 void (*onSurfaceDestroyed)(OH_ArkUI_SurfaceHolder* surfaceHolder))
468 {
469 CHECK_NULL_VOID(callback);
470 callback->OnSurfaceDestroyed = onSurfaceDestroyed;
471 }
472
OH_ArkUI_SurfaceHolder_AddSurfaceCallback(OH_ArkUI_SurfaceHolder * surfaceHolder,OH_ArkUI_SurfaceCallback * callback)473 int32_t OH_ArkUI_SurfaceHolder_AddSurfaceCallback(
474 OH_ArkUI_SurfaceHolder* surfaceHolder, OH_ArkUI_SurfaceCallback* callback)
475 {
476 if ((surfaceHolder == nullptr) || (callback == nullptr)) {
477 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
478 }
479 return surfaceHolder->AddSurfaceCallback(callback);
480 }
481
OH_ArkUI_SurfaceHolder_RemoveSurfaceCallback(OH_ArkUI_SurfaceHolder * surfaceHolder,OH_ArkUI_SurfaceCallback * callback)482 int32_t OH_ArkUI_SurfaceHolder_RemoveSurfaceCallback(
483 OH_ArkUI_SurfaceHolder* surfaceHolder, OH_ArkUI_SurfaceCallback* callback)
484 {
485 if ((surfaceHolder == nullptr) || (callback == nullptr)) {
486 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
487 }
488 return surfaceHolder->RemoveSurfaceCallback(callback);
489 }
490
OH_ArkUI_XComponent_GetNativeWindow(OH_ArkUI_SurfaceHolder * surfaceHolder)491 OHNativeWindow* OH_ArkUI_XComponent_GetNativeWindow(OH_ArkUI_SurfaceHolder* surfaceHolder)
492 {
493 if (surfaceHolder == nullptr) {
494 return nullptr;
495 }
496 return surfaceHolder->nativeWindow_;
497 }
498
OH_ArkUI_XComponent_SetAutoInitialize(ArkUI_NodeHandle node,bool autoInitialize)499 int32_t OH_ArkUI_XComponent_SetAutoInitialize(ArkUI_NodeHandle node, bool autoInitialize)
500 {
501 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
502 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
503 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
504 }
505 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
506 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
507 auto nodeModifiers = impl->getNodeModifiers();
508 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
509 auto xComponentModifier = nodeModifiers->getXComponentModifier();
510 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
511 return xComponentModifier->setAutoInitialize(node->uiNodeHandle, autoInitialize);
512 }
513
OH_ArkUI_XComponent_Initialize(ArkUI_NodeHandle node)514 int32_t OH_ArkUI_XComponent_Initialize(ArkUI_NodeHandle node)
515 {
516 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
517 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
518 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
519 }
520 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
521 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
522 auto nodeModifiers = impl->getNodeModifiers();
523 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
524 auto xComponentModifier = nodeModifiers->getXComponentModifier();
525 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
526 return xComponentModifier->initialize(node->uiNodeHandle);
527 }
528
OH_ArkUI_XComponent_Finalize(ArkUI_NodeHandle node)529 int32_t OH_ArkUI_XComponent_Finalize(ArkUI_NodeHandle node)
530 {
531 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
532 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
533 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
534 }
535 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
536 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
537 auto nodeModifiers = impl->getNodeModifiers();
538 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
539 auto xComponentModifier = nodeModifiers->getXComponentModifier();
540 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
541 return xComponentModifier->finalize(node->uiNodeHandle);
542 }
543
OH_ArkUI_XComponent_IsInitialized(ArkUI_NodeHandle node,bool * isInitialized)544 int32_t OH_ArkUI_XComponent_IsInitialized(ArkUI_NodeHandle node, bool* isInitialized)
545 {
546 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
547 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE) ||
548 !isInitialized) {
549 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
550 }
551 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
552 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
553 auto nodeModifiers = impl->getNodeModifiers();
554 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
555 auto xComponentModifier = nodeModifiers->getXComponentModifier();
556 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
557 ArkUI_Bool value = 0;
558 auto res = xComponentModifier->isInitialized(node->uiNodeHandle, &value);
559 *isInitialized = value;
560 return res;
561 }
562
563 #ifdef __cplusplus
564 };
565 #endif
566