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 #ifndef _PLUGIN_RENDER_H_ 17 #define _PLUGIN_RENDER_H_ 18 19 #include <string> 20 #include <unordered_map> 21 22 #include <native_interface_xcomponent.h> 23 #include <napi/native_api.h> 24 25 #include "egl_core.h" 26 27 class PluginRender { 28 public: 29 explicit PluginRender(std::string& id); 30 static PluginRender* GetInstance(std::string& id); 31 static OH_NativeXComponent_Callback* GetNXComponentCallback(); 32 static OH_NativeXComponent_MouseEvent_Callback* GetNXComponentMouseEventCallback(); 33 34 void SetNativeXComponent(OH_NativeXComponent* component); 35 36 public: 37 // NAPI interface 38 napi_value Export(napi_env env, napi_value exports); 39 40 // Exposed to JS developers by NAPI 41 static napi_value NapiChangeShape(napi_env env, napi_callback_info info); 42 static napi_value NapiDrawTriangle(napi_env env, napi_callback_info info); 43 static napi_value NapiChangeColor(napi_env env, napi_callback_info info); 44 static napi_value NapiChangeColorWorker(napi_env env, napi_callback_info info); 45 46 // xts interfaces 47 static napi_value TestGetXComponentId(napi_env env, napi_callback_info info); 48 static napi_value TestOnSurfaceCreated(napi_env env, napi_callback_info info); 49 static napi_value TestGetXComponentSize_Height(napi_env env, napi_callback_info info); 50 static napi_value TestGetXComponentSize_Width(napi_env env, napi_callback_info info); 51 static napi_value TestGetXComponentOffset_x(napi_env env, napi_callback_info info); 52 static napi_value TestGetXComponentOffset_y(napi_env env, napi_callback_info info); 53 static napi_value TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info); 54 static napi_value TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info); 55 static napi_value TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info); 56 static napi_value TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info); 57 static napi_value TestGetXComponentpointtool_type(napi_env env, napi_callback_info info); 58 static napi_value TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info); 59 // Callback, called by ACE XComponent 60 void OnSurfaceCreated(OH_NativeXComponent* component, void* window); 61 62 void OnSurfaceChanged(OH_NativeXComponent* component, void* window); 63 64 void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); 65 66 void DispatchTouchEvent(OH_NativeXComponent* component, void* window); 67 68 void DispatchMouseEvent(OH_NativeXComponent* component, void* window); 69 70 public: 71 static std::unordered_map<std::string, PluginRender*> instance_; 72 static OH_NativeXComponent_Callback callback_; 73 static uint32_t isCreated_; 74 static uint32_t xcHeight_; 75 static uint32_t xcWidth_; 76 static uint32_t toolType_; 77 static float tiltX_; 78 static float tiltY_; 79 static uint32_t mousecallback_; 80 static double off_x; 81 static double off_y; 82 static uint32_t touchType; 83 static OH_NativeXComponent_TouchEvent testTouchEvent_; 84 static OH_NativeXComponent_MouseEvent testMouseEvent_; 85 static OH_NativeXComponent_MouseEvent_Callback mouseEventcallback_; 86 87 OH_NativeXComponent* component_; 88 EGLCore* eglCore_; 89 90 std::string id_; 91 uint64_t width_; 92 uint64_t height_; 93 94 double x_; 95 double y_; 96 OH_NativeXComponent_TouchEvent touchEvent_; 97 OH_NativeXComponent_MouseEvent mouseEvent_; 98 }; 99 100 #endif // _PLUGIN_RENDER_H_ 101