• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <js_native_api.h>
17 #include <js_native_api_types.h>
18 #include <cstdint>
19 
20 #include "native_common.h"
21 #include "plugin_common.h"
22 #include "plugin_manager.h"
23 #include "plugin_render.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 std::unordered_map<std::string, PluginRender*> PluginRender::instance_;
30 
31 OH_NativeXComponent_Callback PluginRender::callback_;
32 
33 uint32_t PluginRender::isCreated_ = 0;
34 uint32_t PluginRender::xcHeight_ = 0;
35 uint32_t PluginRender::xcWidth_ = 0;
36 double PluginRender::off_x = 0;
37 double PluginRender::off_y = 0;
38 uint32_t PluginRender::toolType_ = 5;
39 uint32_t PluginRender::mousecallback_ = 0;
40 float PluginRender::tiltX_ = 0;
41 float PluginRender::tiltY_ = 0;
42 uint32_t PluginRender::touchType = 4;
43 OH_NativeXComponent_TouchEvent PluginRender::testTouchEvent_;
44 OH_NativeXComponent_MouseEvent PluginRender::testMouseEvent_;
45 OH_NativeXComponent_MouseEvent_Callback PluginRender::mouseEventcallback_;
46 
OnSurfaceCreatedCB(OH_NativeXComponent * component,void * window)47 void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
48 {
49     LOGE("OnSurfaceCreatedCB");
50     int32_t ret;
51     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
52     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
53     ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
54     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
55         return;
56     }
57 
58     std::string id(idStr);
59     auto render = PluginRender::GetInstance(id);
60     render->OnSurfaceCreated(component, window);
61 }
62 
OnSurfaceChangedCB(OH_NativeXComponent * component,void * window)63 void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
64 {
65     int32_t ret;
66     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
67     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
68     ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
69     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
70         return;
71     }
72 
73     std::string id(idStr);
74     auto render = PluginRender::GetInstance(id);
75     render->OnSurfaceChanged(component, window);
76 }
77 
OnSurfaceDestroyedCB(OH_NativeXComponent * component,void * window)78 void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
79 {
80     int32_t ret;
81     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
82     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
83     ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
84     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
85         return;
86     }
87 
88     std::string id(idStr);
89     auto render = PluginRender::GetInstance(id);
90     render->OnSurfaceDestroyed(component, window);
91 }
92 
DispatchTouchEventCB(OH_NativeXComponent * component,void * window)93 void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
94 {
95     LOGE("DispatchTouchEventCB");
96     int32_t ret;
97     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
98     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
99     ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
100     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
101         return;
102     }
103     std::string id(idStr);
104     auto render = PluginRender::GetInstance(id);
105     render->DispatchTouchEvent(component, window);
106 }
107 
DispatchMouseEventCB(OH_NativeXComponent * component,void * window)108 void DispatchMouseEventCB(OH_NativeXComponent* component, void* window)
109 {
110     LOGD("DispatchMouseEventCB");
111     int32_t ret;
112     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
113     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
114     ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
115     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
116         return;
117     }
118     std::string id(idStr);
119     auto render = PluginRender::GetInstance(id);
120     render->DispatchMouseEvent(component, window);
121 }
122 
PluginRender(std::string & id)123 PluginRender::PluginRender(std::string& id)
124 {
125     id_ = id;
126     component_ = nullptr;
127     eglCore_ = new EGLCore(id);
128     auto renderCallback = PluginRender::GetNXComponentCallback();
129     renderCallback->OnSurfaceCreated = OnSurfaceCreatedCB;
130     renderCallback->OnSurfaceChanged = OnSurfaceChangedCB;
131     renderCallback->OnSurfaceDestroyed = OnSurfaceDestroyedCB;
132     renderCallback->DispatchTouchEvent = DispatchTouchEventCB;
133     auto renderMouseEventCallback = PluginRender::GetNXComponentMouseEventCallback();
134     renderMouseEventCallback->DispatchMouseEvent = DispatchMouseEventCB;
135 }
136 
GetInstance(std::string & id)137 PluginRender* PluginRender::GetInstance(std::string& id)
138 {
139     if (instance_.find(id) == instance_.end()) {
140         PluginRender*  instance = new PluginRender(id);
141         instance_[id] = instance;
142         return instance;
143     } else {
144         return instance_[id];
145     }
146 }
147 
GetNXComponentCallback()148 OH_NativeXComponent_Callback* PluginRender::GetNXComponentCallback()
149 {
150     return &PluginRender::callback_;
151 }
152 
GetNXComponentMouseEventCallback()153 OH_NativeXComponent_MouseEvent_Callback* PluginRender::GetNXComponentMouseEventCallback()
154 {
155     return &PluginRender::mouseEventcallback_;
156 }
157 
SetNativeXComponent(OH_NativeXComponent * component)158 void PluginRender::SetNativeXComponent(OH_NativeXComponent* component)
159 {
160     component_ = component;
161     OH_NativeXComponent_RegisterCallback(component_, &PluginRender::callback_);
162     uint32_t mousecallback = OH_NativeXComponent_RegisterMouseEventCallback(component_,
163         &PluginRender::mouseEventcallback_);
164     mousecallback_ = mousecallback;
165 }
166 
OnSurfaceCreated(OH_NativeXComponent * component,void * window)167 void PluginRender::OnSurfaceCreated(OH_NativeXComponent* component, void* window)
168 {
169     LOGE("xclog PluginRender::OnSurfaceCreated");
170 
171     int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
172 
173     LOGE("xclog Offset : x = %{public}f, y = %{public}f ", x_, y_);
174     if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
175         eglCore_->GLContextInit(window, width_, height_);
176         isCreated_++;
177         xcHeight_ = height_;
178         xcWidth_ = width_;
179 
180         LOGE("xclog PluginRender::OnSurfaceCreated success ");
181         LOGE("xclog PluginRender::OnSurfaceCreated iscreated %{public}d", isCreated_);
182     } else {
183         LOGE("xclog PluginRender::OnSurfaceCreated failed");
184     }
185 }
186 
OnSurfaceChanged(OH_NativeXComponent * component,void * window)187 void PluginRender::OnSurfaceChanged(OH_NativeXComponent* component, void* window)
188 {
189     LOGE("PluginRender::OnSurfaceChanged");
190     int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
191     int32_t ret1;
192     if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
193         xcHeight_ = height_;
194         xcWidth_ = width_;
195         LOGE("xclog after width = %{public}d, height = %{public}d", xcWidth_, xcHeight_);
196         ret1= OH_NativeXComponent_GetXComponentOffset(component, window, &x_, &y_);
197         off_x = x_;
198         off_y = y_;
199 
200         if (ret1 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
201             LOGE("xclog Offset : x = %{public}lf, y = %{public}lf ", off_x, off_y);
202         } else {
203             LOGE("xclog Offset get failed");
204         }
205 
206         LOGE("xclog PluginRender::GetOffset ");
207         LOGE("xclog Offset : x = %{public}lf, y = %{public}lf ", off_x, off_y);
208     }
209 }
210 
OnSurfaceDestroyed(OH_NativeXComponent * component,void * window)211 void PluginRender::OnSurfaceDestroyed(OH_NativeXComponent* component, void* window)
212 {
213     LOGE("xclog PluginRender::OnSurfaceDestroyed");
214     isCreated_--;
215     LOGE("xclog PluginRender::OnSurfaceDestroyed iscreated %{public}d", isCreated_);
216 }
217 
DispatchTouchEvent(OH_NativeXComponent * component,void * window)218 void PluginRender::DispatchTouchEvent(OH_NativeXComponent* component, void* window)
219 {
220     int32_t ret = OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_);
221     if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
222         testTouchEvent_ = touchEvent_;
223         LOGE("Touch Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f",
224             touchEvent_.x, touchEvent_.y, touchEvent_.screenX, touchEvent_.screenY);
225         for (uint32_t i = 0; i < touchEvent_.numPoints; i++) {
226             LOGE("Touch Info : dots[%{public}d] id %{public}d x = %{public}f, y = %{public}f", i,
227                 touchEvent_.touchPoints[i].id, touchEvent_.touchPoints[i].x, touchEvent_.touchPoints[i].y);
228             LOGE("Touch Info : screenx = %{public}f, screeny = %{public}f",
229                 touchEvent_.touchPoints[i].screenX, touchEvent_.touchPoints[i].screenY);
230             OH_NativeXComponent_TouchPointToolType toolType = OH_NativeXComponent_TouchPointToolType::OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN;
231             float tiltX = 123.0;
232             float tiltY = 321.0;
233             [[maybe_unused]] int32_t ret1;
234             [[maybe_unused]] int32_t ret2;
235             [[maybe_unused]] int32_t ret3;
236             ret1 = OH_NativeXComponent_GetTouchPointToolType(component, i, &toolType);
237             ret2 = OH_NativeXComponent_GetTouchPointTiltX(component, i, &tiltX);
238             ret3 = OH_NativeXComponent_GetTouchPointTiltY(component, i, &tiltY);
239             toolType_ = toolType;
240             tiltX_ = tiltX;
241             tiltY_ = tiltY;
242             LOGE("Touch Info : DispatchTouchEvent dots[%{public}d] toolType=%{public}u, tiltX=%{public}f, tiltY=%{public}f",
243                 i, toolType, tiltX, tiltY);
244         }
245     } else {
246         LOGE("Touch fail");
247     }
248 }
249 
Export(napi_env env,napi_value exports)250 napi_value PluginRender::Export(napi_env env, napi_value exports)
251 {
252     LOGE("PluginRender::Export");
253     // Register JS API
254     napi_property_descriptor desc[] = {
255         DECLARE_NAPI_FUNCTION("changeShape", PluginRender::NapiChangeShape),
256         DECLARE_NAPI_FUNCTION("drawTriangle", PluginRender::NapiDrawTriangle),
257         DECLARE_NAPI_FUNCTION("changeColor", PluginRender::NapiChangeColor),
258         DECLARE_NAPI_FUNCTION("TestGetXComponentId", PluginRender::TestGetXComponentId),
259         DECLARE_NAPI_FUNCTION("TestOnSurfaceCreated", PluginRender::TestOnSurfaceCreated),
260         DECLARE_NAPI_FUNCTION("TestGetXComponentSize_Height", PluginRender::TestGetXComponentSize_Height),
261         DECLARE_NAPI_FUNCTION("TestGetXComponentSize_Width", PluginRender::TestGetXComponentSize_Width),
262         DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_x", PluginRender::TestGetXComponentOffset_x),
263         DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_y", PluginRender::TestGetXComponentOffset_y),
264         DECLARE_NAPI_FUNCTION("TestGetXComponent_TouchEvent", PluginRender::TestGetXComponent_TouchEvent),
265         DECLARE_NAPI_FUNCTION("TestGetXComponent_MouseEvent", PluginRender::TestGetXComponent_MouseEvent),
266         DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tilty", PluginRender::TestGetXComponentpointtool_tilty),
267         DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_type", PluginRender::TestGetXComponentpointtool_type),
268         DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tiltx", PluginRender::TestGetXComponentpointtool_tiltx),
269         DECLARE_NAPI_FUNCTION("TestGetXComponent_RegisterMouseEventCallback",
270             PluginRender::TestGetXComponent_RegisterMouseEventCallback),
271 
272     };
273     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
274     return exports;
275 }
276 
DispatchMouseEvent(OH_NativeXComponent * component,void * window)277 void PluginRender::DispatchMouseEvent(OH_NativeXComponent* component, void* window)
278 {
279     LOGE("----------TestMouse Mouse Info DispatchMouseEvent 11");
280     int32_t ret = OH_NativeXComponent_GetMouseEvent(component, window, &mouseEvent_);
281     LOGE("----------TestMouse Mouse Info DispatchMouseEvent");
282     if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
283         testMouseEvent_ = mouseEvent_;
284         LOGE("TestMouse Mouse Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f",
285             mouseEvent_.x, mouseEvent_.y, mouseEvent_.screenX, mouseEvent_.screenY);
286         LOGE("TestMouse Mouse Info : action = %{public}d, button = %{public}d", mouseEvent_.action, mouseEvent_.button);
287     } else {
288         LOGE("Mouse Info fail");
289     }
290 }
291 
NapiChangeShape(napi_env env,napi_callback_info info)292 napi_value PluginRender::NapiChangeShape(napi_env env, napi_callback_info info)
293 {
294     LOGE("NapiChangeShape");
295     napi_value exportInstance;
296     napi_value thisArg;
297     [[maybe_unused]] napi_status status;
298     OH_NativeXComponent *nativeXComponent = nullptr;
299 
300     int32_t ret;
301     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
302     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
303 
304     NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
305 
306     status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
307     if (status != napi_ok) {
308         return nullptr;
309     };
310 
311     status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
312     if (status != napi_ok) {
313         return nullptr;
314     }
315 
316     ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
317     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
318         return nullptr;
319     }
320 
321     std::string id(idStr);
322     PluginRender* instance = PluginRender::GetInstance(id);
323     if (instance) {
324         instance->eglCore_->ChangeShape();
325     }
326     return nullptr;
327 }
328 
NapiDrawTriangle(napi_env env,napi_callback_info info)329 napi_value PluginRender::NapiDrawTriangle(napi_env env, napi_callback_info info)
330 {
331     LOGE("NapiDrawTriangle");
332     napi_value exportInstance;
333     napi_value thisArg;
334     napi_status status;
335     OH_NativeXComponent *nativeXComponent = nullptr;
336 
337     int32_t ret;
338     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
339     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
340 
341     NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
342 
343     status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
344     if (status != napi_ok) {
345         return nullptr;
346     };
347 
348     status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
349     if (status != napi_ok) {
350         return nullptr;
351     }
352 
353     ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
354     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
355         return nullptr;
356     }
357 
358     std::string id(idStr);
359     PluginRender* instance = PluginRender::GetInstance(id);
360     if (instance) {
361         instance->eglCore_->DrawTriangle();
362     }
363     return nullptr;
364 }
365 
NapiChangeColor(napi_env env,napi_callback_info info)366 napi_value PluginRender::NapiChangeColor(napi_env env, napi_callback_info info)
367 {
368     LOGE("NapiChangeColor");
369     napi_value exportInstance;
370     napi_value thisArg;
371     napi_status status;
372     OH_NativeXComponent *nativeXComponent = nullptr;
373 
374     int32_t ret;
375     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
376     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
377 
378     NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
379 
380     status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
381     if (status != napi_ok) {
382         return nullptr;
383     }
384 
385     status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
386     if (status != napi_ok) {
387         return nullptr;
388     }
389 
390     ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
391     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
392         return nullptr;
393     }
394 
395     std::string id(idStr);
396     PluginRender* instance = PluginRender::GetInstance(id);
397     if (instance) {
398         instance->eglCore_->ChangeColor();
399     }
400     return nullptr;
401 }
402 
TestGetXComponentId(napi_env env,napi_callback_info info)403 napi_value PluginRender::TestGetXComponentId(napi_env env, napi_callback_info info)
404 {
405     napi_value thisArg;
406     [[maybe_unused]] napi_status status;
407     napi_value exportInstance;
408     OH_NativeXComponent *nativeXComponent = nullptr;
409 
410     int32_t ret;
411     char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
412     uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
413 
414     NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
415     status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
416     if (status != napi_ok) {
417         return nullptr;
418     };
419 
420     status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
421     if (status != napi_ok) {
422         return nullptr;
423     };
424 
425     ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
426     if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
427         return nullptr;
428     }
429 
430     std::string id(idStr);
431 
432     napi_value output;
433     NAPI_CALL(env, napi_create_string_utf8(env, idStr, id.length(), &output));
434 
435     return output;
436 }
437 
TestOnSurfaceCreated(napi_env env,napi_callback_info info)438 napi_value PluginRender::TestOnSurfaceCreated(napi_env env, napi_callback_info info)
439 {
440     LOGE("xclog iscreated instance.size ");
441 
442     napi_value output;
443     NAPI_CALL(env, napi_get_boolean(env, isCreated_ == instance_.size(), &output));
444     LOGE("xclog iscreated instance.size ");
445 
446     return output;
447 }
448 
TestGetXComponentSize_Height(napi_env env,napi_callback_info info)449 napi_value PluginRender::TestGetXComponentSize_Height(napi_env env, napi_callback_info info)
450 {
451     LOGE("xclog running PluginRender::TestGetXComponentSize_Height");
452     napi_value output;
453     NAPI_CALL(env, napi_create_uint32(env, xcHeight_, &output));
454     LOGE("xclog  TestGetXComponentSize_Height %{public}d ", xcHeight_);
455     return output;
456 }
457 
TestGetXComponentSize_Width(napi_env env,napi_callback_info info)458 napi_value PluginRender::TestGetXComponentSize_Width(napi_env env, napi_callback_info info)
459 {
460     LOGE("xclog running PluginRender::TestGetXComponentSize_Width");
461     napi_value output;
462     NAPI_CALL(env, napi_create_uint32(env, xcWidth_, &output));
463     LOGE("xclog  TestGetXComponentSize_Width %{public}d ", xcWidth_);
464     return output;
465 }
466 
TestGetXComponentOffset_x(napi_env env,napi_callback_info info)467 napi_value PluginRender::TestGetXComponentOffset_x(napi_env env, napi_callback_info info)
468 {
469     LOGE("xclog running PluginRender::TestGetXComponentOffset_x");
470 
471     napi_value output;
472     NAPI_CALL(env, napi_create_double(env, off_x, &output));
473     LOGE("xclog TestGetXComponentOffset_x : %{public}f", off_x);
474 
475     return output;
476 }
477 
TestGetXComponentOffset_y(napi_env env,napi_callback_info info)478 napi_value PluginRender::TestGetXComponentOffset_y(napi_env env, napi_callback_info info)
479 {
480     LOGE("xclog running PluginRender::TestGetXComponentOffset_y");
481 
482     napi_value output;
483     NAPI_CALL(env, napi_create_double(env, off_y, &output));
484     LOGE("xclog TestGetXComponentOffset_y : %{public}f", off_y);
485 
486     return output;
487 }
488 
TestGetXComponentpointtool_tiltx(napi_env env,napi_callback_info info)489 napi_value PluginRender::TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info)
490 {
491     LOGE("xclog running PluginRender::TestGetXComponentpointtool_tiltx");
492 
493     napi_value output;
494     NAPI_CALL(env, napi_create_double(env, tiltX_, &output));
495     LOGE("xclog TestGetXComponentpointtool_tiltx : %{public}f", tiltX_);
496 
497     return output;
498 }
499 
TestGetXComponentpointtool_tilty(napi_env env,napi_callback_info info)500 napi_value PluginRender::TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info)
501 {
502     LOGE("xclog running PluginRender::TestGetXComponentpointtool_tilty");
503 
504     napi_value output;
505     NAPI_CALL(env, napi_create_double(env, tiltY_, &output));
506     LOGE("xclog TestGetXComponentpointtool_tilty : %{public}f", tiltY_);
507 
508     return output;
509 }
510 
TestGetXComponentpointtool_type(napi_env env,napi_callback_info info)511 napi_value PluginRender::TestGetXComponentpointtool_type(napi_env env, napi_callback_info info)
512 {
513     LOGE("xclog running PluginRender::TestGetXComponentpointtool_type");
514 
515     napi_value output;
516     NAPI_CALL(env, napi_create_double(env, toolType_, &output));
517     LOGE("xclog TestGetXComponentpointtool_type : %{public}u", toolType_);
518 
519     return output;
520 }
521 
TestGetXComponent_TouchEvent(napi_env env,napi_callback_info info)522 napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info)
523 {
524     LOGE("xclog running PluginRender::TestGetXComponent_TouchEvent");
525 
526     napi_value surf_x;
527     napi_value surf_y;
528     napi_value t_type;
529 
530     NAPI_CALL(env, napi_create_double(env, testTouchEvent_.x, &(surf_x)));
531     NAPI_CALL(env, napi_create_double(env, testTouchEvent_.y, &(surf_y)));
532     NAPI_CALL(env, napi_create_uint32(env, testTouchEvent_.type, &(t_type)));
533 
534     napi_value obj;
535     NAPI_CALL(env, napi_create_object(env, &obj));
536     NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X", surf_x));  // float x
537     NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y", surf_y));  // float y
538     NAPI_CALL(env, napi_set_named_property(env, obj, "touchType", t_type));  // int32_t
539 
540     return obj;
541 }
542 
TestGetXComponent_MouseEvent(napi_env env,napi_callback_info info)543 napi_value PluginRender::TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info)
544 {
545     LOGE("xclog running PluginRender::TestGetXComponent_MouseEvent");
546 
547     napi_value surf_x;
548     napi_value surf_y;
549     napi_value t_button;
550 
551     NAPI_CALL(env, napi_create_double(env, testMouseEvent_.x, &(surf_x)));
552     NAPI_CALL(env, napi_create_double(env, testMouseEvent_.y, &(surf_y)));
553     NAPI_CALL(env, napi_create_uint32(env, testMouseEvent_.button, &(t_button)));
554 
555     napi_value obj;
556     NAPI_CALL(env, napi_create_object(env, &obj));
557     NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X1", surf_x));  // float x
558     NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y1", surf_y));  // float y
559     NAPI_CALL(env, napi_set_named_property(env, obj, "mousebutton", t_button));  // int32_t
560 
561     return obj;
562 }
563 
564 
TestGetXComponent_RegisterMouseEventCallback(napi_env env,napi_callback_info info)565 napi_value PluginRender::TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info)
566 {
567     LOGE("xclog running PluginRender::TestGetXComponent_RegisterMouseEventCallback");
568 
569     napi_value callback_;
570     NAPI_CALL(env, napi_create_double(env, mousecallback_, &(callback_)));
571 
572     napi_value obj;
573     NAPI_CALL(env, napi_create_object(env, &obj));
574     NAPI_CALL(env, napi_set_named_property(env, obj, "MouseCallback_", callback_));  // float x
575 
576     return obj;
577 }
578 
579 #ifdef __cplusplus
580 }
581 #endif
582