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 int32_t ret1;
234 int32_t ret2;
235 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 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 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 status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
417 ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
418 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
419 return nullptr;
420 }
421
422 std::string id(idStr);
423
424 napi_value output;
425 NAPI_CALL(env, napi_create_string_utf8(env, idStr, id.length(), &output));
426
427 return output;
428 }
429
TestOnSurfaceCreated(napi_env env,napi_callback_info info)430 napi_value PluginRender::TestOnSurfaceCreated(napi_env env, napi_callback_info info)
431 {
432 LOGE("xclog iscreated instance.size ");
433
434 napi_value output;
435 NAPI_CALL(env, napi_get_boolean(env, isCreated_ == instance_.size(), &output));
436 LOGE("xclog iscreated instance.size ");
437
438 return output;
439 }
440
TestGetXComponentSize_Height(napi_env env,napi_callback_info info)441 napi_value PluginRender::TestGetXComponentSize_Height(napi_env env, napi_callback_info info)
442 {
443 LOGE("xclog running PluginRender::TestGetXComponentSize_Height");
444 napi_value output;
445 NAPI_CALL(env, napi_create_uint32(env, xcHeight_, &output));
446 LOGE("xclog TestGetXComponentSize_Height %{public}d ", xcHeight_);
447 return output;
448 }
449
TestGetXComponentSize_Width(napi_env env,napi_callback_info info)450 napi_value PluginRender::TestGetXComponentSize_Width(napi_env env, napi_callback_info info)
451 {
452 LOGE("xclog running PluginRender::TestGetXComponentSize_Width");
453 napi_value output;
454 NAPI_CALL(env, napi_create_uint32(env, xcWidth_, &output));
455 LOGE("xclog TestGetXComponentSize_Width %{public}d ", xcWidth_);
456 return output;
457 }
458
TestGetXComponentOffset_x(napi_env env,napi_callback_info info)459 napi_value PluginRender::TestGetXComponentOffset_x(napi_env env, napi_callback_info info)
460 {
461 LOGE("xclog running PluginRender::TestGetXComponentOffset_x");
462
463 napi_value output;
464 NAPI_CALL(env, napi_create_double(env, off_x, &output));
465 LOGE("xclog TestGetXComponentOffset_x : %{public}f", off_x);
466
467 return output;
468 }
469
TestGetXComponentOffset_y(napi_env env,napi_callback_info info)470 napi_value PluginRender::TestGetXComponentOffset_y(napi_env env, napi_callback_info info)
471 {
472 LOGE("xclog running PluginRender::TestGetXComponentOffset_y");
473
474 napi_value output;
475 NAPI_CALL(env, napi_create_double(env, off_y, &output));
476 LOGE("xclog TestGetXComponentOffset_y : %{public}f", off_y);
477
478 return output;
479 }
480
TestGetXComponentpointtool_tiltx(napi_env env,napi_callback_info info)481 napi_value PluginRender::TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info)
482 {
483 LOGE("xclog running PluginRender::TestGetXComponentpointtool_tiltx");
484
485 napi_value output;
486 NAPI_CALL(env, napi_create_double(env, tiltX_, &output));
487 LOGE("xclog TestGetXComponentpointtool_tiltx : %{public}f", tiltX_);
488
489 return output;
490 }
491
TestGetXComponentpointtool_tilty(napi_env env,napi_callback_info info)492 napi_value PluginRender::TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info)
493 {
494 LOGE("xclog running PluginRender::TestGetXComponentpointtool_tilty");
495
496 napi_value output;
497 NAPI_CALL(env, napi_create_double(env, tiltY_, &output));
498 LOGE("xclog TestGetXComponentpointtool_tilty : %{public}f", tiltY_);
499
500 return output;
501 }
502
TestGetXComponentpointtool_type(napi_env env,napi_callback_info info)503 napi_value PluginRender::TestGetXComponentpointtool_type(napi_env env, napi_callback_info info)
504 {
505 LOGE("xclog running PluginRender::TestGetXComponentpointtool_type");
506
507 napi_value output;
508 NAPI_CALL(env, napi_create_double(env, toolType_, &output));
509 LOGE("xclog TestGetXComponentpointtool_type : %{public}u", toolType_);
510
511 return output;
512 }
513
TestGetXComponent_TouchEvent(napi_env env,napi_callback_info info)514 napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info)
515 {
516 LOGE("xclog running PluginRender::TestGetXComponent_TouchEvent");
517
518 napi_value surf_x;
519 napi_value surf_y;
520 napi_value t_type;
521
522 NAPI_CALL(env, napi_create_double(env, testTouchEvent_.x, &(surf_x)));
523 NAPI_CALL(env, napi_create_double(env, testTouchEvent_.y, &(surf_y)));
524 NAPI_CALL(env, napi_create_uint32(env, testTouchEvent_.type, &(t_type)));
525
526 napi_value obj;
527 NAPI_CALL(env, napi_create_object(env, &obj));
528 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X", surf_x)); // float x
529 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y", surf_y)); // float y
530 NAPI_CALL(env, napi_set_named_property(env, obj, "touchType", t_type)); // int32_t
531
532 return obj;
533 }
534
TestGetXComponent_MouseEvent(napi_env env,napi_callback_info info)535 napi_value PluginRender::TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info)
536 {
537 LOGE("xclog running PluginRender::TestGetXComponent_MouseEvent");
538
539 napi_value surf_x;
540 napi_value surf_y;
541 napi_value t_button;
542
543 NAPI_CALL(env, napi_create_double(env, testMouseEvent_.x, &(surf_x)));
544 NAPI_CALL(env, napi_create_double(env, testMouseEvent_.y, &(surf_y)));
545 NAPI_CALL(env, napi_create_uint32(env, testMouseEvent_.button, &(t_button)));
546
547 napi_value obj;
548 NAPI_CALL(env, napi_create_object(env, &obj));
549 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X1", surf_x)); // float x
550 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y1", surf_y)); // float y
551 NAPI_CALL(env, napi_set_named_property(env, obj, "mousebutton", t_button)); // int32_t
552
553 return obj;
554 }
555
556
TestGetXComponent_RegisterMouseEventCallback(napi_env env,napi_callback_info info)557 napi_value PluginRender::TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info)
558 {
559 LOGE("xclog running PluginRender::TestGetXComponent_RegisterMouseEventCallback");
560
561 napi_value callback_;
562 NAPI_CALL(env, napi_create_double(env, mousecallback_, &(callback_)));
563
564 napi_value obj;
565 NAPI_CALL(env, napi_create_object(env, &obj));
566 NAPI_CALL(env, napi_set_named_property(env, obj, "MouseCallback_", callback_)); // float x
567
568 return obj;
569 }
570
571 #ifdef __cplusplus
572 }
573 #endif