• 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 
16 #ifndef NdkNativeWindow_NativeImageAdaptor_H
17 #define NdkNativeWindow_NativeImageAdaptor_H
18 
19 #include <ace/xcomponent/native_interface_xcomponent.h>
20 #include <bits/alltypes.h>
21 #include <napi/native_api.h>
22 #include <native_buffer/native_buffer.h>
23 #include <native_image/native_image.h>
24 #include <native_window/external_window.h>
25 #include <EGL/egl.h>
26 #include <EGL/eglext.h>
27 #include <GLES3/gl3.h>
28 #include <sys/mman.h>
29 #include <mutex>
30 
31 namespace NativeWindowSample {
32 class NativeImageAdaptor {
33 public:
34     ~NativeImageAdaptor();
35     static NativeImageAdaptor *GetInstance();
36     static napi_value GetAvailableCount(napi_env env, napi_callback_info info);
37     static napi_value NapiOnProduceBuffer(napi_env env, napi_callback_info info);
38     static void OnFrameAvailable(void *context);
39     void DealCallback(void *context);
40     bool Export(napi_env env, napi_value exports);
41     void ProduceBuffer(uint32_t value);
42     void InitEGLEnv();
43     EGLDisplay GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list);
44     bool CheckEglExtension(const char *eglExtensions, const char *eglExtension);
45     int32_t GetCount();
46 private:
47     OHNativeWindow *nativeWindow_;
48     OH_NativeImage *image_;
49     int32_t height_;
50     int32_t width_;
51     int32_t availableBufferCount_;
52     EGLConfig config_;
53     EGLContext eglContext_;
54     EGLDisplay eglDisplay_;
55     std::mutex opMutex_;
56 };
57 }
58 #endif // NdkNativeWindow_NativeImageAdaptor_H
59