• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <napi/native_api.h>
22 #include <ace/xcomponent/native_interface_xcomponent.h>
23 #include "vulkan_example.h"
24 #include <thread>
25 #include <condition_variable>
26 
27 class PluginRender {
28   public:
29     explicit PluginRender(std::string &id);
30     ~PluginRender();
31     static PluginRender *GetInstance(std::string &id);
32     static OH_NativeXComponent_Callback *GetNXComponentCallback();
33     void SetNativeXComponent(OH_NativeXComponent *component);
34     napi_value Export(napi_env env, napi_value exports);
35     static napi_value NapiStopMovingOrRestart(napi_env env, napi_callback_info info);
36     // Callback, called by ACE XComponent
37     void OnSurfaceCreated(OH_NativeXComponent *component, void *window);
38     void OnSurfaceChanged(OH_NativeXComponent *component, void *window);
39     void OnSurfaceDestroyed(OH_NativeXComponent *component, void *window);
40     void DispatchTouchEvent(OH_NativeXComponent *component, void *window);
41 
42 private:
43     void RenderThread();
44     static std::unordered_map<std::string, PluginRender *> instance_;
45     static OH_NativeXComponent_Callback callback_;
46     static bool isTriangleRotational_;
47     static std::mutex mutex_;
48     static std::condition_variable con_;
49     std::unique_ptr<vkExample::VulkanExample> vulkanExample_ = nullptr;
50 
51     std::string id_;
52     OH_NativeXComponent *component_;
53     OH_NativeXComponent_TouchEvent touchEvent_;
54     uint64_t width_;
55     uint64_t height_;
56     std::thread renderThread_;
57 };
58 
59 #endif // PLUGIN_RENDER_H
60