1 /* 2 * Copyright (c) 2023 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 #ifndef NATIVE_XCOMPONENT_PLUGIN_RENDER_H 16 #define NATIVE_XCOMPONENT_PLUGIN_RENDER_H 17 18 #include <ace/xcomponent/native_interface_xcomponent.h> 19 #include <napi/native_api.h> 20 #include <string> 21 #include <unordered_map> 22 23 #include "egl_core.h" 24 25 namespace NativeXComponentSample { 26 class PluginRender { 27 public: 28 explicit PluginRender(std::string& id); ~PluginRender()29 ~PluginRender() 30 { 31 if (eglCore_ != nullptr) { 32 eglCore_->Release(); 33 delete eglCore_; 34 eglCore_ = nullptr; 35 } 36 } 37 static PluginRender* GetInstance(std::string& id); 38 static void Release(std::string& id); 39 static napi_value NapiDrawPattern(napi_env env, napi_callback_info info); 40 static napi_value NapiStop(napi_env env, napi_callback_info info); 41 static napi_value NapiPlay(napi_env env, napi_callback_info info); 42 static napi_value NapiGetInfo(napi_env env, napi_callback_info info); 43 static napi_value TestGetXComponentStatus(napi_env env, napi_callback_info info); 44 void Export(napi_env env, napi_value exports); 45 void OnSurfaceChanged(OH_NativeXComponent* component, void* window); 46 void OnTouchEvent(OH_NativeXComponent* component, void* window); 47 void OnMouseEvent(OH_NativeXComponent* component, void* window); 48 void OnHoverEvent(OH_NativeXComponent* component, bool isHover); 49 void OnFocusEvent(OH_NativeXComponent* component, void* window); 50 void OnBlurEvent(OH_NativeXComponent* component, void* window); 51 void OnKeyEvent(OH_NativeXComponent* component, void* window); 52 void RegisterCallback(OH_NativeXComponent* nativeXComponent); 53 54 public: 55 static std::unordered_map<std::string, PluginRender*> instance_; 56 EGLCore* eglCore_; 57 std::string id_; 58 uint32_t fd_; 59 uint32_t foff_; 60 uint32_t flen_; 61 static int32_t hasDraw_; 62 static int32_t hasChangeColor_; 63 64 private: 65 OH_NativeXComponent_Callback renderCallback_; 66 OH_NativeXComponent_MouseEvent_Callback mouseCallback_; 67 }; 68 } // namespace NativeXComponentSample 69 #endif // NATIVE_XCOMPONENT_PLUGIN_RENDER_H 70