1 /* 2 * Copyright (c) 2025 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 NATIVE_XCOMPONENT_PLUGIN_RENDER_H 17 #define NATIVE_XCOMPONENT_PLUGIN_RENDER_H 18 19 #include <ace/xcomponent/native_interface_xcomponent.h> 20 #include <napi/native_api.h> 21 #include <string> 22 #include <unordered_map> 23 24 #include "EglCore.h" 25 26 namespace NativeXComponentSample { 27 class PluginRender { 28 public: 29 explicit PluginRender(std::string &id); ~PluginRender()30 ~PluginRender() 31 { 32 if (eglCore != nullptr) { 33 eglCore->Release(); 34 delete eglCore; 35 eglCore = nullptr; 36 } 37 } 38 static PluginRender *GetInstance(std::string &id); 39 static void Release(std::string &id); 40 void Export(napi_env env, napi_value exports); 41 void OnSurfaceChanged(OH_NativeXComponent *component, void *window); 42 void OnTouchEvent(OH_NativeXComponent *component, void *window); 43 void RegisterCallback(OH_NativeXComponent *nativeXComponent); 44 45 public: 46 static std::unordered_map<std::string, PluginRender *> instance; 47 EGLCore *eglCore; 48 std::string id; 49 static int32_t hasDraw; 50 static int32_t hasChangeColor; 51 52 private: 53 OH_NativeXComponent_Callback renderCallback; 54 OH_NativeXComponent_MouseEvent_Callback mouseCallback; 55 }; 56 } // namespace NativeXComponentSample 57 #endif // NATIVE_XCOMPONENT_PLUGIN_RENDER_H