• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TestGetXComponentStatus(napi_env env, napi_callback_info info);
41     void Export(napi_env env, napi_value exports);
42     void OnSurfaceChanged(OH_NativeXComponent* component, void* window);
43     void OnTouchEvent(OH_NativeXComponent* component, void* window);
44     void OnMouseEvent(OH_NativeXComponent* component, void* window);
45     void OnHoverEvent(OH_NativeXComponent* component, bool isHover);
46     void OnFocusEvent(OH_NativeXComponent* component, void* window);
47     void OnBlurEvent(OH_NativeXComponent* component, void* window);
48     void OnKeyEvent(OH_NativeXComponent* component, void* window);
49     void RegisterCallback(OH_NativeXComponent* nativeXComponent);
50 
51 public:
52     static std::unordered_map<std::string, PluginRender*> instance_;
53     EGLCore* eglCore_;
54     std::string id_;
55     static int32_t hasDraw_;
56     static int32_t hasChangeColor_;
57 
58 private:
59     OH_NativeXComponent_Callback renderCallback_;
60     OH_NativeXComponent_MouseEvent_Callback mouseCallback_;
61 };
62 } // namespace NativeXComponentSample
63 #endif // NATIVE_XCOMPONENT_PLUGIN_RENDER_H
64