1 /*
2  * Copyright (c) 2024 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 #include <ace/xcomponent/native_interface_xcomponent.h>
22 #include <napi/native_api.h>
23 
24 #include "egl_core.h"
25 
26 namespace OHOS {
27 class PluginRender {
28 public:
29     explicit PluginRender(const 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     static napi_value NapiDrawRectangle(napi_env env, napi_callback_info info);
41     static void Export(napi_env env, napi_value exports);
42 
43 public:
44     static std::unordered_map<std::string, PluginRender *> instance_;
45     static OH_NativeXComponent_Callback callback_;
46 
47     EGLCore *eglcore_ = nullptr;
48     std::string id_ = "";
49 };
50 } // namespace OHOS
51 #endif // PLUGIN_RENDER_H