1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "napi/native_api.h"
17f6603c60Sopenharmony_ci#include "native_common.h"
18f6603c60Sopenharmony_ci#include <ace/xcomponent/native_interface_xcomponent.h>
19f6603c60Sopenharmony_ci#include <EGL/egl.h>
20f6603c60Sopenharmony_ci#include <EGL/eglext.h>
21f6603c60Sopenharmony_ci#include <EGL/eglplatform.h>
22f6603c60Sopenharmony_ci#include <GLES3/gl3.h>
23f6603c60Sopenharmony_ci#define NO_ERR 0
24f6603c60Sopenharmony_ci#define SUCCESS 1
25f6603c60Sopenharmony_ci#define FAIL (-1)
26f6603c60Sopenharmony_ci#define TRUE 1
27f6603c60Sopenharmony_ci#define FALSE 0
28f6603c60Sopenharmony_ci#define RGB_SIZE 0x08
29f6603c60Sopenharmony_ci#define INIT_WIDTH 0x08
30f6603c60Sopenharmony_ci#define INIT_HEIGHT 0x08
31f6603c60Sopenharmony_ci#define GL_CLIENT_VERSION 0x02
32f6603c60Sopenharmony_ci#define GL_MAJOR_VERSION_2 0x02
33f6603c60Sopenharmony_ci#define GL_MAJOR_VERSION_3 0x03
34f6603c60Sopenharmony_ci#define GL_MINOR_VERSION_0 0x00
35f6603c60Sopenharmony_ci#define EGL_ONE 0x01
36f6603c60Sopenharmony_ci#define GL_VERSION_15 0x0F
37f6603c60Sopenharmony_ci#define GL_MAJOR_VERSION_MARK 0x0A
38f6603c60Sopenharmony_citypedef struct _MyEGLWindow {
39f6603c60Sopenharmony_ci    EGLDisplay eglDisplay;
40f6603c60Sopenharmony_ci    EGLSurface eglLSurface;
41f6603c60Sopenharmony_ci    EGLContext eglContext;
42f6603c60Sopenharmony_ci    EGLConfig eglConfig;
43f6603c60Sopenharmony_ci    EGLint eglVersion;
44f6603c60Sopenharmony_ci} MyEGLWindow;
45f6603c60Sopenharmony_ci
46f6603c60Sopenharmony_cistatic napi_value createMyEglWindow(napi_env env, MyEGLWindow *myEGLWindow)
47f6603c60Sopenharmony_ci{
48f6603c60Sopenharmony_ci    if (myEGLWindow == nullptr) {
49f6603c60Sopenharmony_ci        return nullptr;
50f6603c60Sopenharmony_ci    }
51f6603c60Sopenharmony_ci    myEGLWindow->eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
52f6603c60Sopenharmony_ci    NAPI_ASSERT(env, myEGLWindow->eglDisplay != EGL_NO_DISPLAY, "eglInitialize error");
53f6603c60Sopenharmony_ci    EGLint majorVersion = GL_MAJOR_VERSION_2;
54f6603c60Sopenharmony_ci    EGLint minorVersion = GL_MINOR_VERSION_0;
55f6603c60Sopenharmony_ci    EGLBoolean Ret = eglInitialize(myEGLWindow->eglDisplay, &majorVersion, &minorVersion);
56f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglInitialize error");
57f6603c60Sopenharmony_ci    myEGLWindow->eglVersion = majorVersion * GL_MAJOR_VERSION_MARK + minorVersion;
58f6603c60Sopenharmony_ci    EGLint clientVersion = majorVersion == GL_MAJOR_VERSION_3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT;
59f6603c60Sopenharmony_ci    const EGLint configAttribs[] = {
60f6603c60Sopenharmony_ci        EGL_RED_SIZE,   RGB_SIZE, EGL_GREEN_SIZE,      RGB_SIZE,      EGL_BLUE_SIZE,    RGB_SIZE,
61f6603c60Sopenharmony_ci        EGL_ALPHA_SIZE, RGB_SIZE, EGL_RENDERABLE_TYPE, clientVersion, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
62f6603c60Sopenharmony_ci        EGL_NONE,       EGL_NONE};
63f6603c60Sopenharmony_ci    EGLint numConfigs = 0x00;
64f6603c60Sopenharmony_ci    Ret = eglChooseConfig(myEGLWindow->eglDisplay, configAttribs, &myEGLWindow->eglConfig, EGL_ONE, &numConfigs);
65f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglChooseConfig error");
66f6603c60Sopenharmony_ci    const EGLint surfaceAttribs[] = {EGL_WIDTH,          INIT_WIDTH,       EGL_HEIGHT,         INIT_HEIGHT,
67f6603c60Sopenharmony_ci                                     EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
68f6603c60Sopenharmony_ci                                     EGL_NONE,           EGL_NONE};
69f6603c60Sopenharmony_ci    myEGLWindow->eglLSurface = eglCreatePbufferSurface(myEGLWindow->eglDisplay, myEGLWindow->eglConfig, surfaceAttribs);
70f6603c60Sopenharmony_ci    NAPI_ASSERT(env, myEGLWindow->eglLSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
71f6603c60Sopenharmony_ci    const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, GL_CLIENT_VERSION, EGL_NONE, EGL_NONE};
72f6603c60Sopenharmony_ci    myEGLWindow->eglContext =
73f6603c60Sopenharmony_ci        eglCreateContext(myEGLWindow->eglDisplay, myEGLWindow->eglConfig, EGL_NO_CONTEXT, contextAttribs);
74f6603c60Sopenharmony_ci    NAPI_ASSERT(env, myEGLWindow->eglContext != EGL_NO_CONTEXT, "eglCreateContext error");
75f6603c60Sopenharmony_ci    Ret = eglMakeCurrent(myEGLWindow->eglDisplay, myEGLWindow->eglLSurface, myEGLWindow->eglLSurface,
76f6603c60Sopenharmony_ci                         myEGLWindow->eglContext);
77f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglMakeCurrent error");
78f6603c60Sopenharmony_ci    return nullptr;
79f6603c60Sopenharmony_ci}
80f6603c60Sopenharmony_ci
81f6603c60Sopenharmony_cistatic napi_value destroyMyEglWindow(napi_env env, MyEGLWindow *myEGLWindow)
82f6603c60Sopenharmony_ci{
83f6603c60Sopenharmony_ci    if (myEGLWindow == nullptr) {
84f6603c60Sopenharmony_ci        return nullptr;
85f6603c60Sopenharmony_ci    }
86f6603c60Sopenharmony_ci    if (myEGLWindow->eglDisplay != EGL_NO_DISPLAY) {
87f6603c60Sopenharmony_ci        EGLBoolean Ret = eglTerminate(myEGLWindow->eglDisplay);
88f6603c60Sopenharmony_ci        NAPI_ASSERT_BASE(env, Ret == EGL_TRUE, "eglTerminate error", EGL_FALSE);
89f6603c60Sopenharmony_ci    }
90f6603c60Sopenharmony_ci    myEGLWindow->eglDisplay = EGL_NO_DISPLAY;
91f6603c60Sopenharmony_ci    myEGLWindow->eglLSurface = EGL_NO_SURFACE;
92f6603c60Sopenharmony_ci    myEGLWindow->eglContext = EGL_NO_CONTEXT;
93f6603c60Sopenharmony_ci    myEGLWindow->eglConfig = nullptr;
94f6603c60Sopenharmony_ci    return nullptr;
95f6603c60Sopenharmony_ci}
96f6603c60Sopenharmony_ci
97f6603c60Sopenharmony_cistatic napi_value eglGetErrorInit()
98f6603c60Sopenharmony_ci{
99f6603c60Sopenharmony_ci    EGLint eglError = NO_ERR;
100f6603c60Sopenharmony_ci    do {
101f6603c60Sopenharmony_ci        eglError = eglGetError();
102f6603c60Sopenharmony_ci    } while (eglError != EGL_SUCCESS);
103f6603c60Sopenharmony_ci    return nullptr;
104f6603c60Sopenharmony_ci}
105f6603c60Sopenharmony_cistatic const EGLint surfaceAttr[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
106f6603c60Sopenharmony_ci
107f6603c60Sopenharmony_cistatic const EGLint confAttr[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
108f6603c60Sopenharmony_ci                                  EGL_BLUE_SIZE,    8,
109f6603c60Sopenharmony_ci                                  EGL_GREEN_SIZE,   8,
110f6603c60Sopenharmony_ci                                  EGL_RED_SIZE,     8,
111f6603c60Sopenharmony_ci                                  EGL_ALPHA_SIZE,   8,
112f6603c60Sopenharmony_ci                                  EGL_DEPTH_SIZE,   16,
113f6603c60Sopenharmony_ci                                  EGL_NONE};
114f6603c60Sopenharmony_ci
115f6603c60Sopenharmony_cistatic napi_value EglChooseConfig(napi_env env, napi_callback_info info)
116f6603c60Sopenharmony_ci{
117f6603c60Sopenharmony_ci    EGLint numConfigs;
118f6603c60Sopenharmony_ci    EGLConfig config = nullptr;
119f6603c60Sopenharmony_ci    EGLint config_size = 1;
120f6603c60Sopenharmony_ci    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
121f6603c60Sopenharmony_ci    NAPI_ASSERT(env, display != EGL_NO_DISPLAY, "eglGetDisplay error");
122f6603c60Sopenharmony_ci    eglInitialize(display, nullptr, nullptr);
123f6603c60Sopenharmony_ci    EGLBoolean Ret = eglChooseConfig(display, confAttr, &config, config_size, &numConfigs);
124f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglChooseConfig error");
125f6603c60Sopenharmony_ci    eglReleaseThread();
126f6603c60Sopenharmony_ci    eglTerminate(display);
127f6603c60Sopenharmony_ci    napi_value result = nullptr;
128f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
129f6603c60Sopenharmony_ci    return result;
130f6603c60Sopenharmony_ci}
131f6603c60Sopenharmony_ci
132f6603c60Sopenharmony_cistatic napi_value EglChooseConfigAbnormal(napi_env env, napi_callback_info info)
133f6603c60Sopenharmony_ci{
134f6603c60Sopenharmony_ci    EGLint numConfigs;
135f6603c60Sopenharmony_ci    EGLConfig config = nullptr;
136f6603c60Sopenharmony_ci    EGLDisplay display = nullptr;
137f6603c60Sopenharmony_ci    EGLint config_size = 1;
138f6603c60Sopenharmony_ci    EGLBoolean Ret = eglChooseConfig(display, confAttr, &config, config_size, &numConfigs);
139f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglChooseConfig error");
140f6603c60Sopenharmony_ci    napi_value result = nullptr;
141f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
142f6603c60Sopenharmony_ci    return result;
143f6603c60Sopenharmony_ci}
144f6603c60Sopenharmony_ci
145f6603c60Sopenharmony_cistatic napi_value EglCopyBuffersAbnormal(napi_env env, napi_callback_info info)
146f6603c60Sopenharmony_ci{
147f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
148f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
149f6603c60Sopenharmony_ci    EGLint numConfigs;
150f6603c60Sopenharmony_ci    EGLint config_size = 1;
151f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
152f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
153f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
154f6603c60Sopenharmony_ci
155f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
156f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = nullptr;
157f6603c60Sopenharmony_ci    EGLNativePixmapType mNativeDisplay = 0;
158f6603c60Sopenharmony_ci    EGLBoolean Ret = eglCopyBuffers(m_eglDisplay, m_eglSurface, mNativeDisplay);
159f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglCopyBuffers error");
160f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
161f6603c60Sopenharmony_ci    eglReleaseThread();
162f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
163f6603c60Sopenharmony_ci    napi_value result = nullptr;
164f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
165f6603c60Sopenharmony_ci    return result;
166f6603c60Sopenharmony_ci}
167f6603c60Sopenharmony_ci
168f6603c60Sopenharmony_cistatic napi_value EglCreateContext(napi_env env, napi_callback_info info)
169f6603c60Sopenharmony_ci{
170f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
171f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
172f6603c60Sopenharmony_ci    EGLint numConfigs;
173f6603c60Sopenharmony_ci    EGLint config_size = 1;
174f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
175f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
176f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
177f6603c60Sopenharmony_ci
178f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
179f6603c60Sopenharmony_ci
180f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
181f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
182f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
183f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
184f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglCtx != EGL_NO_CONTEXT, "eglCreateContext error");
185f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
186f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
187f6603c60Sopenharmony_ci    eglReleaseThread();
188f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
189f6603c60Sopenharmony_ci    napi_value result = nullptr;
190f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
191f6603c60Sopenharmony_ci    return result;
192f6603c60Sopenharmony_ci}
193f6603c60Sopenharmony_ci
194f6603c60Sopenharmony_cistatic napi_value EglCreateContextAbnormal(napi_env env, napi_callback_info info)
195f6603c60Sopenharmony_ci{
196f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
197f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
198f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
199f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
200f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglCtx == EGL_NO_CONTEXT, "eglCreateContext error");
201f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
202f6603c60Sopenharmony_ci    eglReleaseThread();
203f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
204f6603c60Sopenharmony_ci    napi_value result = nullptr;
205f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
206f6603c60Sopenharmony_ci    return result;
207f6603c60Sopenharmony_ci}
208f6603c60Sopenharmony_ci
209f6603c60Sopenharmony_cistatic napi_value EglCreatePbufferSurface(napi_env env, napi_callback_info info)
210f6603c60Sopenharmony_ci{
211f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
212f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
213f6603c60Sopenharmony_ci    EGLint numConfigs;
214f6603c60Sopenharmony_ci    EGLint config_size = 1;
215f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
216f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
217f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
218f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
219f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
220f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
221f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
222f6603c60Sopenharmony_ci    eglReleaseThread();
223f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
224f6603c60Sopenharmony_ci    napi_value result = nullptr;
225f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
226f6603c60Sopenharmony_ci    return result;
227f6603c60Sopenharmony_ci}
228f6603c60Sopenharmony_ci
229f6603c60Sopenharmony_cistatic napi_value EglCreatePbufferSurfaceAbnormal(napi_env env, napi_callback_info info)
230f6603c60Sopenharmony_ci{
231f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
232f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
233f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
234f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
235f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
236f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
237f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface == EGL_NO_SURFACE, "eglCreatePbufferSurface error");
238f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
239f6603c60Sopenharmony_ci    eglReleaseThread();
240f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
241f6603c60Sopenharmony_ci    napi_value result = nullptr;
242f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
243f6603c60Sopenharmony_ci    return result;
244f6603c60Sopenharmony_ci}
245f6603c60Sopenharmony_ci
246f6603c60Sopenharmony_cistatic napi_value EglCreatePixmapSurfaceAbnormal(napi_env env, napi_callback_info info)
247f6603c60Sopenharmony_ci{
248f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
249f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
250f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
251f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
252f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
253f6603c60Sopenharmony_ci    EGLNativePixmapType pixmap = 0;
254f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePixmapSurface(m_eglDisplay, m_eglConf, pixmap, surfaceAttr);
255f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface == EGL_NO_SURFACE, "eglCreatePixmapSurface error");
256f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
257f6603c60Sopenharmony_ci    eglReleaseThread();
258f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
259f6603c60Sopenharmony_ci    napi_value result = nullptr;
260f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
261f6603c60Sopenharmony_ci    return result;
262f6603c60Sopenharmony_ci}
263f6603c60Sopenharmony_ci
264f6603c60Sopenharmony_cistatic napi_value EglCreateWindowSurfaceAbnormal(napi_env env, napi_callback_info info)
265f6603c60Sopenharmony_ci{
266f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
267f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
268f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
269f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
270f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
271f6603c60Sopenharmony_ci    NativeWindowType window = 0;
272f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConf, window, surfaceAttr);
273f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface == EGL_NO_SURFACE, "eglCreateWindowSurface error");
274f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
275f6603c60Sopenharmony_ci    eglReleaseThread();
276f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
277f6603c60Sopenharmony_ci    napi_value result = nullptr;
278f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
279f6603c60Sopenharmony_ci    return result;
280f6603c60Sopenharmony_ci}
281f6603c60Sopenharmony_ci
282f6603c60Sopenharmony_cistatic napi_value EglDestroyContext(napi_env env, napi_callback_info info)
283f6603c60Sopenharmony_ci{
284f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
285f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
286f6603c60Sopenharmony_ci    EGLint numConfigs;
287f6603c60Sopenharmony_ci    EGLint config_size = 1;
288f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
289f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
290f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
291f6603c60Sopenharmony_ci
292f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
293f6603c60Sopenharmony_ci
294f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
295f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
296f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
297f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
298f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroyContext(m_eglDisplay, m_eglCtx);
299f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglDestroyContext error");
300f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
301f6603c60Sopenharmony_ci    eglReleaseThread();
302f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
303f6603c60Sopenharmony_ci    napi_value result = nullptr;
304f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
305f6603c60Sopenharmony_ci    return result;
306f6603c60Sopenharmony_ci}
307f6603c60Sopenharmony_ci
308f6603c60Sopenharmony_cistatic napi_value EglDestroyContextAbnormal(napi_env env, napi_callback_info info)
309f6603c60Sopenharmony_ci{
310f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
311f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
312f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, nullptr);
313f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroyContext(m_eglDisplay, m_eglCtx);
314f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglDestroyContext error");
315f6603c60Sopenharmony_ci    eglReleaseThread();
316f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
317f6603c60Sopenharmony_ci    napi_value result = nullptr;
318f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
319f6603c60Sopenharmony_ci    return result;
320f6603c60Sopenharmony_ci}
321f6603c60Sopenharmony_ci
322f6603c60Sopenharmony_cistatic napi_value EglDestroySurface(napi_env env, napi_callback_info info)
323f6603c60Sopenharmony_ci{
324f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
325f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
326f6603c60Sopenharmony_ci    EGLint numConfigs;
327f6603c60Sopenharmony_ci    EGLint config_size = 1;
328f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
329f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
330f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
331f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
332f6603c60Sopenharmony_ci
333f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
334f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
335f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroySurface(m_eglDisplay, m_eglSurface);
336f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglDestroySurface error");
337f6603c60Sopenharmony_ci    eglReleaseThread();
338f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
339f6603c60Sopenharmony_ci    napi_value result = nullptr;
340f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
341f6603c60Sopenharmony_ci    return result;
342f6603c60Sopenharmony_ci}
343f6603c60Sopenharmony_ci
344f6603c60Sopenharmony_cistatic napi_value EglDestroySurfaceAbnormal(napi_env env, napi_callback_info info)
345f6603c60Sopenharmony_ci{
346f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
347f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
348f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
349f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
350f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
351f6603c60Sopenharmony_ci
352f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
353f6603c60Sopenharmony_ci
354f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroySurface(m_eglDisplay, m_eglSurface);
355f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglDestroySurface error");
356f6603c60Sopenharmony_ci    eglReleaseThread();
357f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
358f6603c60Sopenharmony_ci    napi_value result = nullptr;
359f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
360f6603c60Sopenharmony_ci    return result;
361f6603c60Sopenharmony_ci}
362f6603c60Sopenharmony_ci
363f6603c60Sopenharmony_cistatic napi_value EglGetConfigAttrib(napi_env env, napi_callback_info info)
364f6603c60Sopenharmony_ci{
365f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
366f6603c60Sopenharmony_ci    EGLConfig m_eglConf[10];
367f6603c60Sopenharmony_ci    EGLint numConfigs;
368f6603c60Sopenharmony_ci    EGLint config_size = 10;
369f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
370f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
371f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
372f6603c60Sopenharmony_ci
373f6603c60Sopenharmony_ci    eglGetConfigs(m_eglDisplay, m_eglConf, config_size, &numConfigs);
374f6603c60Sopenharmony_ci    EGLBoolean Ret;
375f6603c60Sopenharmony_ci    for (int i = 0; i < numConfigs; ++i) {
376f6603c60Sopenharmony_ci        Ret = eglGetConfigAttrib(m_eglDisplay, m_eglConf[i], EGL_ALPHA_SIZE, &numConfigs);
377f6603c60Sopenharmony_ci    }
378f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglGetConfigAttrib error");
379f6603c60Sopenharmony_ci    eglReleaseThread();
380f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
381f6603c60Sopenharmony_ci    napi_value result = nullptr;
382f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
383f6603c60Sopenharmony_ci    return result;
384f6603c60Sopenharmony_ci}
385f6603c60Sopenharmony_ci
386f6603c60Sopenharmony_cistatic napi_value EglGetConfigAttribAbnormal(napi_env env, napi_callback_info info)
387f6603c60Sopenharmony_ci{
388f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
389f6603c60Sopenharmony_ci    EGLConfig m_eglConf[10];
390f6603c60Sopenharmony_ci    EGLint numConfigs;
391f6603c60Sopenharmony_ci    EGLint config_size = 10;
392f6603c60Sopenharmony_ci    eglGetConfigs(m_eglDisplay, m_eglConf, config_size, &numConfigs);
393f6603c60Sopenharmony_ci    EGLBoolean Ret;
394f6603c60Sopenharmony_ci    for (int i = 0; i < numConfigs; ++i) {
395f6603c60Sopenharmony_ci        Ret = eglGetConfigAttrib(m_eglDisplay, m_eglConf[i], EGL_BUFFER_SIZE, &numConfigs);
396f6603c60Sopenharmony_ci    }
397f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglGetConfigAttrib error");
398f6603c60Sopenharmony_ci    eglReleaseThread();
399f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
400f6603c60Sopenharmony_ci    napi_value result = nullptr;
401f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
402f6603c60Sopenharmony_ci    return result;
403f6603c60Sopenharmony_ci}
404f6603c60Sopenharmony_ci
405f6603c60Sopenharmony_cistatic napi_value EglGetConfigs(napi_env env, napi_callback_info info)
406f6603c60Sopenharmony_ci{
407f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
408f6603c60Sopenharmony_ci    EGLConfig m_eglConf[10];
409f6603c60Sopenharmony_ci    EGLint numConfigs;
410f6603c60Sopenharmony_ci    EGLint config_size = 10;
411f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
412f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
413f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
414f6603c60Sopenharmony_ci
415f6603c60Sopenharmony_ci    EGLBoolean Ret = eglGetConfigs(m_eglDisplay, m_eglConf, config_size, &numConfigs);
416f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglGetConfigs error");
417f6603c60Sopenharmony_ci    eglReleaseThread();
418f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
419f6603c60Sopenharmony_ci    napi_value result = nullptr;
420f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
421f6603c60Sopenharmony_ci    return result;
422f6603c60Sopenharmony_ci}
423f6603c60Sopenharmony_ci
424f6603c60Sopenharmony_cistatic napi_value EglGetConfigsAbnormal(napi_env env, napi_callback_info info)
425f6603c60Sopenharmony_ci{
426f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
427f6603c60Sopenharmony_ci    EGLConfig m_eglConf[10];
428f6603c60Sopenharmony_ci    EGLint numConfigs;
429f6603c60Sopenharmony_ci    EGLint config_size = 10;
430f6603c60Sopenharmony_ci
431f6603c60Sopenharmony_ci    EGLBoolean Ret = eglGetConfigs(m_eglDisplay, m_eglConf, config_size, &numConfigs);
432f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglGetConfigs error");
433f6603c60Sopenharmony_ci    eglReleaseThread();
434f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
435f6603c60Sopenharmony_ci    napi_value result = nullptr;
436f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
437f6603c60Sopenharmony_ci    return result;
438f6603c60Sopenharmony_ci}
439f6603c60Sopenharmony_ci
440f6603c60Sopenharmony_cistatic napi_value EglGetCurrentDisplay(napi_env env, napi_callback_info info)
441f6603c60Sopenharmony_ci{
442f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
443f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
444f6603c60Sopenharmony_ci    EGLint numConfigs;
445f6603c60Sopenharmony_ci    EGLint config_size = 1;
446f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
447f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
448f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
449f6603c60Sopenharmony_ci
450f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
451f6603c60Sopenharmony_ci
452f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
453f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
454f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
455f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
456f6603c60Sopenharmony_ci    eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx);
457f6603c60Sopenharmony_ci    m_eglDisplay = eglGetCurrentDisplay();
458f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetCurrentDisplay error");
459f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
460f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
461f6603c60Sopenharmony_ci    eglReleaseThread();
462f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
463f6603c60Sopenharmony_ci    napi_value result = nullptr;
464f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
465f6603c60Sopenharmony_ci    return result;
466f6603c60Sopenharmony_ci}
467f6603c60Sopenharmony_ci
468f6603c60Sopenharmony_cistatic napi_value EglGetCurrentDisplayAbnormal(napi_env env, napi_callback_info info)
469f6603c60Sopenharmony_ci{
470f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
471f6603c60Sopenharmony_ci    m_eglDisplay = eglGetCurrentDisplay();
472f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay == EGL_NO_DISPLAY, "eglGetCurrentDisplay error");
473f6603c60Sopenharmony_ci    eglReleaseThread();
474f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
475f6603c60Sopenharmony_ci    napi_value result = nullptr;
476f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
477f6603c60Sopenharmony_ci    return result;
478f6603c60Sopenharmony_ci}
479f6603c60Sopenharmony_ci
480f6603c60Sopenharmony_cistatic napi_value EglGetCurrentSurface(napi_env env, napi_callback_info info)
481f6603c60Sopenharmony_ci{
482f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
483f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
484f6603c60Sopenharmony_ci    EGLint numConfigs;
485f6603c60Sopenharmony_ci    EGLint config_size = 1;
486f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
487f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
488f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
489f6603c60Sopenharmony_ci
490f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
491f6603c60Sopenharmony_ci
492f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
493f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
494f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
495f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
496f6603c60Sopenharmony_ci    eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx);
497f6603c60Sopenharmony_ci    m_eglDisplay = eglGetCurrentDisplay();
498f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetCurrentDisplay error");
499f6603c60Sopenharmony_ci    m_eglSurface = eglGetCurrentSurface(EGL_DRAW);
500f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglGetCurrentSurface error");
501f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
502f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
503f6603c60Sopenharmony_ci    eglReleaseThread();
504f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
505f6603c60Sopenharmony_ci    napi_value result = nullptr;
506f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
507f6603c60Sopenharmony_ci    return result;
508f6603c60Sopenharmony_ci}
509f6603c60Sopenharmony_ci
510f6603c60Sopenharmony_cistatic napi_value EglGetCurrentSurfaceAbnormal(napi_env env, napi_callback_info info)
511f6603c60Sopenharmony_ci{
512f6603c60Sopenharmony_ci    eglGetCurrentDisplay();
513f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglGetCurrentSurface(EGL_DRAW);
514f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface == EGL_NO_SURFACE, "eglGetCurrentSurface error");
515f6603c60Sopenharmony_ci    napi_value result = nullptr;
516f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
517f6603c60Sopenharmony_ci    return result;
518f6603c60Sopenharmony_ci}
519f6603c60Sopenharmony_ci
520f6603c60Sopenharmony_cistatic napi_value EglGetDisplay(napi_env env, napi_callback_info info)
521f6603c60Sopenharmony_ci{
522f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
523f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
524f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
525f6603c60Sopenharmony_ci    eglReleaseThread();
526f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
527f6603c60Sopenharmony_ci    napi_value result = nullptr;
528f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
529f6603c60Sopenharmony_ci    return result;
530f6603c60Sopenharmony_ci}
531f6603c60Sopenharmony_ci
532f6603c60Sopenharmony_cistatic napi_value EglGetError(napi_env env, napi_callback_info info)
533f6603c60Sopenharmony_ci{
534f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
535f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
536f6603c60Sopenharmony_ci    eglGetErrorInit();
537f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
538f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
539f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglCtx == EGL_NO_CONTEXT, "eglGetCurrentSurface error");
540f6603c60Sopenharmony_ci    EGLint Ret = eglGetError();
541f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_BAD_DISPLAY, "eglGetError error");
542f6603c60Sopenharmony_ci    eglReleaseThread();
543f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
544f6603c60Sopenharmony_ci    napi_value result = nullptr;
545f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
546f6603c60Sopenharmony_ci    return result;
547f6603c60Sopenharmony_ci}
548f6603c60Sopenharmony_ci
549f6603c60Sopenharmony_citypedef EGLBoolean (*PFNCREATEIMAGEKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const int *);
550f6603c60Sopenharmony_cistatic napi_value EglGetProcAddress(napi_env env, napi_callback_info info)
551f6603c60Sopenharmony_ci{
552f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
553f6603c60Sopenharmony_ci    PFNCREATEIMAGEKHR createImageKHR = (PFNCREATEIMAGEKHR)eglGetProcAddress("eglCreateImageKHR");
554f6603c60Sopenharmony_ci    NAPI_ASSERT(env, createImageKHR != nullptr, "eglGetProcAddress error");
555f6603c60Sopenharmony_ci    eglReleaseThread();
556f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
557f6603c60Sopenharmony_ci    napi_value result = nullptr;
558f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
559f6603c60Sopenharmony_ci    return result;
560f6603c60Sopenharmony_ci}
561f6603c60Sopenharmony_ci
562f6603c60Sopenharmony_cistatic napi_value EglGetProcAddressAbnormal(napi_env env, napi_callback_info info)
563f6603c60Sopenharmony_ci{
564f6603c60Sopenharmony_ci    PFNCREATEIMAGEKHR createImageKHR = (PFNCREATEIMAGEKHR)eglGetProcAddress("eglCreateImageKHR1");
565f6603c60Sopenharmony_ci    NAPI_ASSERT(env, createImageKHR == nullptr, "eglGetProcAddress error");
566f6603c60Sopenharmony_ci    napi_value result = nullptr;
567f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
568f6603c60Sopenharmony_ci    return result;
569f6603c60Sopenharmony_ci}
570f6603c60Sopenharmony_ci
571f6603c60Sopenharmony_cistatic napi_value EglInitialize(napi_env env, napi_callback_info info)
572f6603c60Sopenharmony_ci{
573f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
574f6603c60Sopenharmony_ci    EGLBoolean Ret = eglInitialize(m_eglDisplay, nullptr, nullptr);
575f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglGetProcAddress error");
576f6603c60Sopenharmony_ci    eglReleaseThread();
577f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
578f6603c60Sopenharmony_ci    napi_value result = nullptr;
579f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
580f6603c60Sopenharmony_ci    return result;
581f6603c60Sopenharmony_ci}
582f6603c60Sopenharmony_ci
583f6603c60Sopenharmony_cistatic napi_value EglInitializeAbnormal(napi_env env, napi_callback_info info)
584f6603c60Sopenharmony_ci{
585f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
586f6603c60Sopenharmony_ci    EGLBoolean Ret = eglInitialize(m_eglDisplay, nullptr, nullptr);
587f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglGetProcAddress error");
588f6603c60Sopenharmony_ci    eglReleaseThread();
589f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
590f6603c60Sopenharmony_ci    napi_value result = nullptr;
591f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
592f6603c60Sopenharmony_ci    return result;
593f6603c60Sopenharmony_ci}
594f6603c60Sopenharmony_ci
595f6603c60Sopenharmony_cistatic napi_value EglMakeCurrent(napi_env env, napi_callback_info info)
596f6603c60Sopenharmony_ci{
597f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
598f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
599f6603c60Sopenharmony_ci    EGLint numConfigs;
600f6603c60Sopenharmony_ci    EGLint config_size = 1;
601f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
602f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
603f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
604f6603c60Sopenharmony_ci
605f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
606f6603c60Sopenharmony_ci
607f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
608f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
609f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
610f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
611f6603c60Sopenharmony_ci    EGLBoolean Ret = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx);
612f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglMakeCurrent error");
613f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
614f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
615f6603c60Sopenharmony_ci    eglReleaseThread();
616f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
617f6603c60Sopenharmony_ci    napi_value result = nullptr;
618f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
619f6603c60Sopenharmony_ci    return result;
620f6603c60Sopenharmony_ci}
621f6603c60Sopenharmony_ci
622f6603c60Sopenharmony_cistatic napi_value EglMakeCurrentAbnormal(napi_env env, napi_callback_info info)
623f6603c60Sopenharmony_ci{
624f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
625f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = nullptr;
626f6603c60Sopenharmony_ci    EGLContext m_eglCtx = nullptr;
627f6603c60Sopenharmony_ci    EGLBoolean Ret = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglCtx);
628f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglMakeCurrent error");
629f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
630f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
631f6603c60Sopenharmony_ci    eglReleaseThread();
632f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
633f6603c60Sopenharmony_ci    napi_value result = nullptr;
634f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
635f6603c60Sopenharmony_ci    return result;
636f6603c60Sopenharmony_ci}
637f6603c60Sopenharmony_ci
638f6603c60Sopenharmony_cistatic napi_value EglQueryContext(napi_env env, napi_callback_info info)
639f6603c60Sopenharmony_ci{
640f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
641f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
642f6603c60Sopenharmony_ci    EGLint numConfigs;
643f6603c60Sopenharmony_ci    EGLint config_size = 1;
644f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
645f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
646f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
647f6603c60Sopenharmony_ci
648f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
649f6603c60Sopenharmony_ci
650f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
651f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
652f6603c60Sopenharmony_ci    const EGLint ctxAttr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
653f6603c60Sopenharmony_ci    EGLContext m_eglCtx = eglCreateContext(m_eglDisplay, m_eglConf, EGL_NO_CONTEXT, ctxAttr);
654f6603c60Sopenharmony_ci    EGLBoolean Ret = eglQueryContext(m_eglDisplay, m_eglCtx, EGL_CONTEXT_CLIENT_VERSION, &numConfigs);
655f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglQueryContext error");
656f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
657f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
658f6603c60Sopenharmony_ci    eglReleaseThread();
659f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
660f6603c60Sopenharmony_ci    napi_value result = nullptr;
661f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
662f6603c60Sopenharmony_ci    return result;
663f6603c60Sopenharmony_ci}
664f6603c60Sopenharmony_ci
665f6603c60Sopenharmony_cistatic napi_value EglQueryContextAbnormal(napi_env env, napi_callback_info info)
666f6603c60Sopenharmony_ci{
667f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
668f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
669f6603c60Sopenharmony_ci    EGLint numConfigs;
670f6603c60Sopenharmony_ci    EGLint config_size = 1;
671f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
672f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
673f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
674f6603c60Sopenharmony_ci
675f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
676f6603c60Sopenharmony_ci
677f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
678f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
679f6603c60Sopenharmony_ci    EGLContext m_eglCtx = nullptr;
680f6603c60Sopenharmony_ci    EGLBoolean Ret = eglQueryContext(m_eglDisplay, m_eglCtx, EGL_CONTEXT_CLIENT_VERSION, &numConfigs);
681f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglQueryContext error");
682f6603c60Sopenharmony_ci    eglDestroyContext(m_eglDisplay, m_eglCtx);
683f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
684f6603c60Sopenharmony_ci    eglReleaseThread();
685f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
686f6603c60Sopenharmony_ci    napi_value result = nullptr;
687f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
688f6603c60Sopenharmony_ci    return result;
689f6603c60Sopenharmony_ci}
690f6603c60Sopenharmony_ci
691f6603c60Sopenharmony_cistatic napi_value EglQueryString(napi_env env, napi_callback_info info)
692f6603c60Sopenharmony_ci{
693f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
694f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
695f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
696f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
697f6603c60Sopenharmony_ci    const char *vendor = eglQueryString(m_eglDisplay, EGL_VENDOR);
698f6603c60Sopenharmony_ci    NAPI_ASSERT(env, vendor != nullptr, "eglQueryString error");
699f6603c60Sopenharmony_ci
700f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
701f6603c60Sopenharmony_ci    napi_value result = nullptr;
702f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
703f6603c60Sopenharmony_ci    return result;
704f6603c60Sopenharmony_ci}
705f6603c60Sopenharmony_ci
706f6603c60Sopenharmony_cistatic napi_value EglQueryStringAbnormal(napi_env env, napi_callback_info info)
707f6603c60Sopenharmony_ci{
708f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
709f6603c60Sopenharmony_ci    const char *vendor = eglQueryString(m_eglDisplay, EGL_VENDOR);
710f6603c60Sopenharmony_ci    NAPI_ASSERT(env, vendor == nullptr, "eglQueryString error");
711f6603c60Sopenharmony_ci
712f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
713f6603c60Sopenharmony_ci    napi_value result = nullptr;
714f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
715f6603c60Sopenharmony_ci    return result;
716f6603c60Sopenharmony_ci}
717f6603c60Sopenharmony_ci
718f6603c60Sopenharmony_cistatic napi_value EglQuerySurface(napi_env env, napi_callback_info info)
719f6603c60Sopenharmony_ci{
720f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
721f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
722f6603c60Sopenharmony_ci    EGLint numConfigs;
723f6603c60Sopenharmony_ci    EGLint config_size = 1;
724f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
725f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
726f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
727f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
728f6603c60Sopenharmony_ci
729f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = eglCreatePbufferSurface(m_eglDisplay, m_eglConf, surfaceAttr);
730f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
731f6603c60Sopenharmony_ci    EGLint width;
732f6603c60Sopenharmony_ci    EGLBoolean Ret = eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH, &width);
733f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == TRUE, "eglQuerySurface error");
734f6603c60Sopenharmony_ci    eglDestroySurface(m_eglDisplay, m_eglSurface);
735f6603c60Sopenharmony_ci    eglReleaseThread();
736f6603c60Sopenharmony_ci    eglTerminate(m_eglDisplay);
737f6603c60Sopenharmony_ci    napi_value result = nullptr;
738f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
739f6603c60Sopenharmony_ci    return result;
740f6603c60Sopenharmony_ci}
741f6603c60Sopenharmony_ci
742f6603c60Sopenharmony_cistatic napi_value EglQuerySurfaceAbnormal(napi_env env, napi_callback_info info)
743f6603c60Sopenharmony_ci{
744f6603c60Sopenharmony_ci    EGLDisplay m_eglDisplay = nullptr;
745f6603c60Sopenharmony_ci    EGLConfig m_eglConf = nullptr;
746f6603c60Sopenharmony_ci    EGLint numConfigs;
747f6603c60Sopenharmony_ci    EGLint config_size = 1;
748f6603c60Sopenharmony_ci    m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
749f6603c60Sopenharmony_ci    NAPI_ASSERT(env, m_eglDisplay != EGL_NO_DISPLAY, "eglGetDisplay error");
750f6603c60Sopenharmony_ci    eglInitialize(m_eglDisplay, nullptr, nullptr);
751f6603c60Sopenharmony_ci    eglChooseConfig(m_eglDisplay, confAttr, &m_eglConf, config_size, &numConfigs);
752f6603c60Sopenharmony_ci
753f6603c60Sopenharmony_ci    EGLSurface m_eglSurface = nullptr;
754f6603c60Sopenharmony_ci    EGLint width;
755f6603c60Sopenharmony_ci    EGLBoolean Ret = eglQuerySurface(m_eglDisplay, m_eglSurface, EGL_WIDTH, &width);
756f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == FALSE, "eglQuerySurface error");
757f6603c60Sopenharmony_ci    napi_value result = nullptr;
758f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
759f6603c60Sopenharmony_ci    return result;
760f6603c60Sopenharmony_ci}
761f6603c60Sopenharmony_ci
762f6603c60Sopenharmony_cistatic napi_value EglSwapBuffers(napi_env env, napi_callback_info info)
763f6603c60Sopenharmony_ci{
764f6603c60Sopenharmony_ci    (void)info;
765f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
766f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
767f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSwapBuffers(myEGLWindow.eglDisplay, myEGLWindow.eglLSurface);
768f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglSwapBuffers error");
769f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
770f6603c60Sopenharmony_ci    napi_value result = nullptr;
771f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
772f6603c60Sopenharmony_ci    return result;
773f6603c60Sopenharmony_ci}
774f6603c60Sopenharmony_ci
775f6603c60Sopenharmony_cistatic napi_value EglSwapBuffersAbnormal(napi_env env, napi_callback_info info)
776f6603c60Sopenharmony_ci{
777f6603c60Sopenharmony_ci    (void)info;
778f6603c60Sopenharmony_ci    eglGetErrorInit();
779f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSwapBuffers(EGL_NO_DISPLAY, EGL_NO_SURFACE);
780f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglGetError error");
781f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
782f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
783f6603c60Sopenharmony_ci    napi_value result = nullptr;
784f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
785f6603c60Sopenharmony_ci    return result;
786f6603c60Sopenharmony_ci}
787f6603c60Sopenharmony_ci
788f6603c60Sopenharmony_cistatic napi_value EglTerminate(napi_env env, napi_callback_info info)
789f6603c60Sopenharmony_ci{
790f6603c60Sopenharmony_ci    (void)info;
791f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
792f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
793f6603c60Sopenharmony_ci    EGLBoolean Ret = eglTerminate(myEGLWindow.eglDisplay);
794f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglTerminate error");
795f6603c60Sopenharmony_ci    napi_value result = nullptr;
796f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
797f6603c60Sopenharmony_ci    return result;
798f6603c60Sopenharmony_ci}
799f6603c60Sopenharmony_ci
800f6603c60Sopenharmony_cistatic napi_value EglTerminateAbnormal(napi_env env, napi_callback_info info)
801f6603c60Sopenharmony_ci{
802f6603c60Sopenharmony_ci    (void)info;
803f6603c60Sopenharmony_ci    eglGetErrorInit();
804f6603c60Sopenharmony_ci    EGLBoolean Ret = eglTerminate(EGL_NO_DISPLAY);
805f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglGetError error");
806f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
807f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
808f6603c60Sopenharmony_ci    napi_value result = nullptr;
809f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
810f6603c60Sopenharmony_ci    return result;
811f6603c60Sopenharmony_ci}
812f6603c60Sopenharmony_ci
813f6603c60Sopenharmony_cistatic napi_value EglWaitGL(napi_env env, napi_callback_info info)
814f6603c60Sopenharmony_ci{
815f6603c60Sopenharmony_ci    (void)info;
816f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
817f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
818f6603c60Sopenharmony_ci    EGLBoolean Ret = eglWaitGL();
819f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglWaitGL error");
820f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
821f6603c60Sopenharmony_ci    napi_value result = nullptr;
822f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
823f6603c60Sopenharmony_ci    return result;
824f6603c60Sopenharmony_ci}
825f6603c60Sopenharmony_ci
826f6603c60Sopenharmony_cistatic napi_value EglWaitNative(napi_env env, napi_callback_info info)
827f6603c60Sopenharmony_ci{
828f6603c60Sopenharmony_ci    (void)info;
829f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
830f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
831f6603c60Sopenharmony_ci    EGLBoolean Ret = eglWaitNative(EGL_CORE_NATIVE_ENGINE);
832f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglWaitNative error");
833f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
834f6603c60Sopenharmony_ci    napi_value result = nullptr;
835f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
836f6603c60Sopenharmony_ci    return result;
837f6603c60Sopenharmony_ci}
838f6603c60Sopenharmony_ci
839f6603c60Sopenharmony_cistatic napi_value EglBindTexImage(napi_env env, napi_callback_info info)
840f6603c60Sopenharmony_ci{
841f6603c60Sopenharmony_ci    (void)info;
842f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
843f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
844f6603c60Sopenharmony_ci    const EGLint surfaceAttribs[] = {EGL_WIDTH,          INIT_WIDTH,       EGL_HEIGHT,         INIT_HEIGHT,
845f6603c60Sopenharmony_ci                                     EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
846f6603c60Sopenharmony_ci                                     EGL_NONE,           EGL_NONE};
847f6603c60Sopenharmony_ci    EGLSurface eglLSurface = eglCreatePbufferSurface(myEGLWindow.eglDisplay, myEGLWindow.eglConfig, surfaceAttribs);
848f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglLSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
849f6603c60Sopenharmony_ci    GLuint texture = GL_ZERO;
850f6603c60Sopenharmony_ci    glGenTextures(GL_ONE, &texture);
851f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
852f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
853f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
854f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
855f6603c60Sopenharmony_ci    EGLBoolean Ret = eglBindTexImage(myEGLWindow.eglDisplay, eglLSurface, EGL_BACK_BUFFER);
856f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglBindTexImage error");
857f6603c60Sopenharmony_ci    Ret = eglReleaseTexImage(myEGLWindow.eglDisplay, eglLSurface, EGL_BACK_BUFFER);
858f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglReleaseTexImage error");
859f6603c60Sopenharmony_ci    Ret = eglDestroySurface(myEGLWindow.eglDisplay, eglLSurface);
860f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySurface error");
861f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
862f6603c60Sopenharmony_ci    napi_value result = nullptr;
863f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
864f6603c60Sopenharmony_ci    return result;
865f6603c60Sopenharmony_ci}
866f6603c60Sopenharmony_ci
867f6603c60Sopenharmony_cistatic napi_value EglBindTexImageAbnormal(napi_env env, napi_callback_info info)
868f6603c60Sopenharmony_ci{
869f6603c60Sopenharmony_ci    (void)info;
870f6603c60Sopenharmony_ci    EGLBoolean Ret = eglBindTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, 0x00);
871f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglBindTexImage error");
872f6603c60Sopenharmony_ci    napi_value result = nullptr;
873f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
874f6603c60Sopenharmony_ci    return result;
875f6603c60Sopenharmony_ci}
876f6603c60Sopenharmony_ci
877f6603c60Sopenharmony_cistatic napi_value EglReleaseTexImage(napi_env env, napi_callback_info info)
878f6603c60Sopenharmony_ci{
879f6603c60Sopenharmony_ci    (void)info;
880f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
881f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
882f6603c60Sopenharmony_ci    const EGLint surfaceAttribs[] = {EGL_WIDTH,          INIT_WIDTH,       EGL_HEIGHT,         INIT_HEIGHT,
883f6603c60Sopenharmony_ci                                     EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
884f6603c60Sopenharmony_ci                                     EGL_NONE,           EGL_NONE};
885f6603c60Sopenharmony_ci    EGLSurface eglLSurface = eglCreatePbufferSurface(myEGLWindow.eglDisplay, myEGLWindow.eglConfig, surfaceAttribs);
886f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglLSurface != EGL_NO_SURFACE, "eglCreatePbufferSurface error");
887f6603c60Sopenharmony_ci    GLuint texture = GL_ZERO;
888f6603c60Sopenharmony_ci    glGenTextures(GL_ONE, &texture);
889f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
890f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
891f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
892f6603c60Sopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
893f6603c60Sopenharmony_ci    EGLBoolean Ret = eglBindTexImage(myEGLWindow.eglDisplay, eglLSurface, EGL_BACK_BUFFER);
894f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglBindTexImage error");
895f6603c60Sopenharmony_ci    Ret = eglReleaseTexImage(myEGLWindow.eglDisplay, eglLSurface, EGL_BACK_BUFFER);
896f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglReleaseTexImage error");
897f6603c60Sopenharmony_ci    Ret = eglDestroySurface(myEGLWindow.eglDisplay, eglLSurface);
898f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySurface error");
899f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
900f6603c60Sopenharmony_ci    napi_value result = nullptr;
901f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
902f6603c60Sopenharmony_ci    return result;
903f6603c60Sopenharmony_ci}
904f6603c60Sopenharmony_ci
905f6603c60Sopenharmony_cistatic napi_value EglReleaseTexImageAbnormal(napi_env env, napi_callback_info info)
906f6603c60Sopenharmony_ci{
907f6603c60Sopenharmony_ci    (void)info;
908f6603c60Sopenharmony_ci    EGLBoolean Ret = eglReleaseTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, 0x00);
909f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglReleaseTexImage error");
910f6603c60Sopenharmony_ci    napi_value result = nullptr;
911f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
912f6603c60Sopenharmony_ci    return result;
913f6603c60Sopenharmony_ci}
914f6603c60Sopenharmony_ci
915f6603c60Sopenharmony_cistatic napi_value EglSurfaceAttrib(napi_env env, napi_callback_info info)
916f6603c60Sopenharmony_ci{
917f6603c60Sopenharmony_ci    (void)info;
918f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
919f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
920f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSurfaceAttrib(myEGLWindow.eglDisplay, myEGLWindow.eglLSurface, EGL_MIPMAP_LEVEL, EGL_ONE);
921f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglSurfaceAttrib error");
922f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
923f6603c60Sopenharmony_ci    napi_value result = nullptr;
924f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
925f6603c60Sopenharmony_ci    return result;
926f6603c60Sopenharmony_ci}
927f6603c60Sopenharmony_ci
928f6603c60Sopenharmony_cistatic napi_value EglSurfaceAttribAbnormal(napi_env env, napi_callback_info info)
929f6603c60Sopenharmony_ci{
930f6603c60Sopenharmony_ci    (void)info;
931f6603c60Sopenharmony_ci    eglGetErrorInit();
932f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSurfaceAttrib(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_MIPMAP_LEVEL, EGL_ONE);
933f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglSurfaceAttrib error");
934f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
935f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
936f6603c60Sopenharmony_ci    napi_value result = nullptr;
937f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
938f6603c60Sopenharmony_ci    return result;
939f6603c60Sopenharmony_ci}
940f6603c60Sopenharmony_ci
941f6603c60Sopenharmony_cistatic napi_value EglSwapInterval(napi_env env, napi_callback_info info)
942f6603c60Sopenharmony_ci{
943f6603c60Sopenharmony_ci    (void)info;
944f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
945f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
946f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSwapInterval(myEGLWindow.eglDisplay, EGL_ONE);
947f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglSwapInterval error");
948f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
949f6603c60Sopenharmony_ci    napi_value result = nullptr;
950f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
951f6603c60Sopenharmony_ci    return result;
952f6603c60Sopenharmony_ci}
953f6603c60Sopenharmony_ci
954f6603c60Sopenharmony_cistatic napi_value EglSwapIntervalAbnormal(napi_env env, napi_callback_info info)
955f6603c60Sopenharmony_ci{
956f6603c60Sopenharmony_ci    (void)info;
957f6603c60Sopenharmony_ci    eglGetErrorInit();
958f6603c60Sopenharmony_ci    EGLBoolean Ret = eglSwapInterval(EGL_NO_DISPLAY, EGL_ONE);
959f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglSwapInterval error");
960f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
961f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
962f6603c60Sopenharmony_ci    napi_value result = nullptr;
963f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
964f6603c60Sopenharmony_ci    return result;
965f6603c60Sopenharmony_ci}
966f6603c60Sopenharmony_ci
967f6603c60Sopenharmony_cistatic napi_value EglBindAPI(napi_env env, napi_callback_info info)
968f6603c60Sopenharmony_ci{
969f6603c60Sopenharmony_ci    (void)info;
970f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
971f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
972f6603c60Sopenharmony_ci    EGLBoolean Ret = eglBindAPI(EGL_OPENGL_ES_API);
973f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglBindAPI error");
974f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
975f6603c60Sopenharmony_ci    napi_value result = nullptr;
976f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
977f6603c60Sopenharmony_ci    return result;
978f6603c60Sopenharmony_ci}
979f6603c60Sopenharmony_ci
980f6603c60Sopenharmony_cistatic napi_value EglBindAPIAbnormal(napi_env env, napi_callback_info info)
981f6603c60Sopenharmony_ci{
982f6603c60Sopenharmony_ci    (void)info;
983f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
984f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
985f6603c60Sopenharmony_ci    EGLBoolean Ret = eglBindAPI(EGL_OPENGL_API);
986f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglBindAPI error");
987f6603c60Sopenharmony_ci    Ret = eglBindAPI(EGL_OPENVG_API);
988f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglBindAPI error");
989f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
990f6603c60Sopenharmony_ci    napi_value result = nullptr;
991f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
992f6603c60Sopenharmony_ci    return result;
993f6603c60Sopenharmony_ci}
994f6603c60Sopenharmony_ci
995f6603c60Sopenharmony_cistatic napi_value EglQueryAPI(napi_env env, napi_callback_info info)
996f6603c60Sopenharmony_ci{
997f6603c60Sopenharmony_ci    (void)info;
998f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
999f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1000f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglQueryAPI() == EGL_OPENGL_ES_API, "eglQueryAPI error");
1001f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1002f6603c60Sopenharmony_ci    napi_value result = nullptr;
1003f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1004f6603c60Sopenharmony_ci    return result;
1005f6603c60Sopenharmony_ci}
1006f6603c60Sopenharmony_ci
1007f6603c60Sopenharmony_cistatic napi_value EglCreatePbufferFromClientBufferAbnormal(napi_env env, napi_callback_info info)
1008f6603c60Sopenharmony_ci{
1009f6603c60Sopenharmony_ci    (void)info;
1010f6603c60Sopenharmony_ci    eglGetErrorInit();
1011f6603c60Sopenharmony_ci    EGLSurface eglSurface =
1012f6603c60Sopenharmony_ci        eglCreatePbufferFromClientBuffer(EGL_NO_DISPLAY, EGL_OPENVG_IMAGE, nullptr, nullptr, nullptr);
1013f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglSurface == EGL_NO_SURFACE, "eglCreatePbufferFromClientBuffer error");
1014f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1015f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1016f6603c60Sopenharmony_ci    napi_value result = nullptr;
1017f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1018f6603c60Sopenharmony_ci    return result;
1019f6603c60Sopenharmony_ci}
1020f6603c60Sopenharmony_ci
1021f6603c60Sopenharmony_cistatic napi_value EglReleaseThread(napi_env env, napi_callback_info info)
1022f6603c60Sopenharmony_ci{
1023f6603c60Sopenharmony_ci    (void)info;
1024f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1025f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1026f6603c60Sopenharmony_ci    EGLBoolean Ret = eglReleaseThread();
1027f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglReleaseThread error");
1028f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1029f6603c60Sopenharmony_ci    napi_value result = nullptr;
1030f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1031f6603c60Sopenharmony_ci    return result;
1032f6603c60Sopenharmony_ci}
1033f6603c60Sopenharmony_ci
1034f6603c60Sopenharmony_cistatic napi_value EglWaitClient(napi_env env, napi_callback_info info)
1035f6603c60Sopenharmony_ci{
1036f6603c60Sopenharmony_ci    (void)info;
1037f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1038f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1039f6603c60Sopenharmony_ci    EGLBoolean Ret = eglWaitClient();
1040f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglWaitClient error");
1041f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1042f6603c60Sopenharmony_ci    napi_value result = nullptr;
1043f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1044f6603c60Sopenharmony_ci    return result;
1045f6603c60Sopenharmony_ci}
1046f6603c60Sopenharmony_ci
1047f6603c60Sopenharmony_cistatic napi_value EglGetCurrentContext(napi_env env, napi_callback_info info)
1048f6603c60Sopenharmony_ci{
1049f6603c60Sopenharmony_ci    (void)info;
1050f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1051f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1052f6603c60Sopenharmony_ci    EGLContext eglContext = eglGetCurrentContext();
1053f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglContext != EGL_NO_CONTEXT, "eglGetCurrentContext error");
1054f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1055f6603c60Sopenharmony_ci    napi_value result = nullptr;
1056f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1057f6603c60Sopenharmony_ci    return result;
1058f6603c60Sopenharmony_ci}
1059f6603c60Sopenharmony_ci
1060f6603c60Sopenharmony_cistatic napi_value EglCreateSync(napi_env env, napi_callback_info info)
1061f6603c60Sopenharmony_ci{
1062f6603c60Sopenharmony_ci    (void)info;
1063f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1064f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1065f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1066f6603c60Sopenharmony_ci        const EGLAttrib attr[] = {EGL_NONE};
1067f6603c60Sopenharmony_ci        EGLSync eglSync = eglCreateSync(myEGLWindow.eglDisplay, EGL_SYNC_FENCE, attr);
1068f6603c60Sopenharmony_ci        NAPI_ASSERT(env, eglSync != EGL_NO_SYNC, "eglCreateSync error");
1069f6603c60Sopenharmony_ci        EGLBoolean Ret = eglDestroySync(myEGLWindow.eglDisplay, eglSync);
1070f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySync error");
1071f6603c60Sopenharmony_ci    }
1072f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1073f6603c60Sopenharmony_ci    napi_value result = nullptr;
1074f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1075f6603c60Sopenharmony_ci    return result;
1076f6603c60Sopenharmony_ci}
1077f6603c60Sopenharmony_ci
1078f6603c60Sopenharmony_cistatic napi_value EglCreateSyncAbnormal(napi_env env, napi_callback_info info)
1079f6603c60Sopenharmony_ci{
1080f6603c60Sopenharmony_ci    (void)info;
1081f6603c60Sopenharmony_ci    eglGetErrorInit();
1082f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1083f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1084f6603c60Sopenharmony_ci    EGLSync eglSync = eglCreateSync(EGL_NO_DISPLAY, EGL_SYNC_FENCE, nullptr);
1085f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglSync == EGL_NO_SYNC, "eglCreateSync error");
1086f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1087f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1088f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1089f6603c60Sopenharmony_ci    napi_value result = nullptr;
1090f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1091f6603c60Sopenharmony_ci    return result;
1092f6603c60Sopenharmony_ci}
1093f6603c60Sopenharmony_ci
1094f6603c60Sopenharmony_cistatic napi_value EglDestroySync(napi_env env, napi_callback_info info)
1095f6603c60Sopenharmony_ci{
1096f6603c60Sopenharmony_ci    (void)info;
1097f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1098f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1099f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1100f6603c60Sopenharmony_ci        const EGLAttrib attr[] = {EGL_NONE};
1101f6603c60Sopenharmony_ci        EGLSync eglSync = eglCreateSync(myEGLWindow.eglDisplay, EGL_SYNC_FENCE, attr);
1102f6603c60Sopenharmony_ci        NAPI_ASSERT(env, eglSync != EGL_NO_SYNC, "eglCreateSync error");
1103f6603c60Sopenharmony_ci        EGLBoolean Ret = eglDestroySync(myEGLWindow.eglDisplay, eglSync);
1104f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySync error");
1105f6603c60Sopenharmony_ci    }
1106f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1107f6603c60Sopenharmony_ci    napi_value result = nullptr;
1108f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1109f6603c60Sopenharmony_ci    return result;
1110f6603c60Sopenharmony_ci}
1111f6603c60Sopenharmony_ci
1112f6603c60Sopenharmony_cistatic napi_value EglDestroySyncAbnormal(napi_env env, napi_callback_info info)
1113f6603c60Sopenharmony_ci{
1114f6603c60Sopenharmony_ci    (void)info;
1115f6603c60Sopenharmony_ci    eglGetErrorInit();
1116f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroySync(EGL_NO_DISPLAY, EGL_NO_SYNC);
1117f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglDestroySync error");
1118f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1119f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1120f6603c60Sopenharmony_ci    napi_value result = nullptr;
1121f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1122f6603c60Sopenharmony_ci    return result;
1123f6603c60Sopenharmony_ci}
1124f6603c60Sopenharmony_ci
1125f6603c60Sopenharmony_cistatic napi_value EglClientWaitSync(napi_env env, napi_callback_info info)
1126f6603c60Sopenharmony_ci{
1127f6603c60Sopenharmony_ci    (void)info;
1128f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1129f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1130f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1131f6603c60Sopenharmony_ci        const EGLAttrib attr[] = {EGL_NONE};
1132f6603c60Sopenharmony_ci        EGLSync eglSync = eglCreateSync(myEGLWindow.eglDisplay, EGL_SYNC_FENCE, attr);
1133f6603c60Sopenharmony_ci        NAPI_ASSERT(env, eglSync != EGL_NO_SYNC, "eglCreateSync error");
1134f6603c60Sopenharmony_ci        EGLBoolean Ret = eglClientWaitSync(myEGLWindow.eglDisplay, eglSync, 0x00, EGL_FOREVER);
1135f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglClientWaitSync error");
1136f6603c60Sopenharmony_ci        Ret = eglDestroySync(myEGLWindow.eglDisplay, eglSync);
1137f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySync error");
1138f6603c60Sopenharmony_ci    }
1139f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1140f6603c60Sopenharmony_ci    napi_value result = nullptr;
1141f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1142f6603c60Sopenharmony_ci    return result;
1143f6603c60Sopenharmony_ci}
1144f6603c60Sopenharmony_ci
1145f6603c60Sopenharmony_cistatic napi_value EglClientWaitSyncAbnormal(napi_env env, napi_callback_info info)
1146f6603c60Sopenharmony_ci{
1147f6603c60Sopenharmony_ci    (void)info;
1148f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1149f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1150f6603c60Sopenharmony_ci    EGLBoolean Ret = eglClientWaitSync(myEGLWindow.eglDisplay, EGL_NO_SYNC, 0x00, EGL_FOREVER);
1151f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglClientWaitSync error");
1152f6603c60Sopenharmony_ci    napi_value result = nullptr;
1153f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1154f6603c60Sopenharmony_ci    return result;
1155f6603c60Sopenharmony_ci}
1156f6603c60Sopenharmony_ci
1157f6603c60Sopenharmony_cistatic napi_value EglGetSyncAttrib(napi_env env, napi_callback_info info)
1158f6603c60Sopenharmony_ci{
1159f6603c60Sopenharmony_ci    (void)info;
1160f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1161f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1162f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1163f6603c60Sopenharmony_ci        const EGLAttrib attr[] = {EGL_NONE};
1164f6603c60Sopenharmony_ci        EGLSync eglSync = eglCreateSync(myEGLWindow.eglDisplay, EGL_SYNC_FENCE, attr);
1165f6603c60Sopenharmony_ci        NAPI_ASSERT(env, eglSync != EGL_NO_SYNC, "eglCreateSync error");
1166f6603c60Sopenharmony_ci        EGLAttrib value[1] = {0x00};
1167f6603c60Sopenharmony_ci        EGLBoolean Ret = eglGetSyncAttrib(myEGLWindow.eglDisplay, eglSync, EGL_SYNC_TYPE, value);
1168f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglGetSyncAttrib error");
1169f6603c60Sopenharmony_ci        Ret = eglDestroySync(myEGLWindow.eglDisplay, eglSync);
1170f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySync error");
1171f6603c60Sopenharmony_ci    }
1172f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1173f6603c60Sopenharmony_ci    napi_value result = nullptr;
1174f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1175f6603c60Sopenharmony_ci    return result;
1176f6603c60Sopenharmony_ci}
1177f6603c60Sopenharmony_ci
1178f6603c60Sopenharmony_cistatic napi_value EglGetSyncAttribAbnormal(napi_env env, napi_callback_info info)
1179f6603c60Sopenharmony_ci{
1180f6603c60Sopenharmony_ci    (void)info;
1181f6603c60Sopenharmony_ci    eglGetErrorInit();
1182f6603c60Sopenharmony_ci    EGLAttrib value[1] = {0x00};
1183f6603c60Sopenharmony_ci    EGLBoolean Ret = eglGetSyncAttrib(EGL_NO_DISPLAY, EGL_NO_SYNC, EGL_SYNC_TYPE, value);
1184f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglGetSyncAttrib error");
1185f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1186f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1187f6603c60Sopenharmony_ci    napi_value result = nullptr;
1188f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1189f6603c60Sopenharmony_ci    return result;
1190f6603c60Sopenharmony_ci}
1191f6603c60Sopenharmony_ci
1192f6603c60Sopenharmony_cistatic napi_value EglCreateImage(napi_env env, napi_callback_info info)
1193f6603c60Sopenharmony_ci{
1194f6603c60Sopenharmony_ci    (void)info;
1195f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1196f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1197f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1198f6603c60Sopenharmony_ci        int texture = EGL_ONE;
1199f6603c60Sopenharmony_ci        glBindTexture(GL_TEXTURE_2D, texture);
1200f6603c60Sopenharmony_ci        glTexImage2D(GL_TEXTURE_2D, 0x00, GL_RGBA, INIT_WIDTH, INIT_HEIGHT, 0x00, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1201f6603c60Sopenharmony_ci        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1202f6603c60Sopenharmony_ci        const EGLAttrib eglAttrib[] = {EGL_GL_TEXTURE_LEVEL, 0x00, EGL_NONE};
1203f6603c60Sopenharmony_ci        EGLImage image = eglCreateImage(myEGLWindow.eglDisplay, myEGLWindow.eglContext, EGL_GL_TEXTURE_2D,
1204f6603c60Sopenharmony_ci                                        (void *)(static_cast<intptr_t>(texture)), eglAttrib);
1205f6603c60Sopenharmony_ci        NAPI_ASSERT(env, image != EGL_NO_IMAGE, "eglCreateImage error");
1206f6603c60Sopenharmony_ci        EGLBoolean Ret = eglDestroyImage(myEGLWindow.eglDisplay, image);
1207f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroyImage error");
1208f6603c60Sopenharmony_ci    }
1209f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1210f6603c60Sopenharmony_ci    napi_value result = nullptr;
1211f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1212f6603c60Sopenharmony_ci    return result;
1213f6603c60Sopenharmony_ci}
1214f6603c60Sopenharmony_ci
1215f6603c60Sopenharmony_cistatic napi_value EglCreateImageAbnormal(napi_env env, napi_callback_info info)
1216f6603c60Sopenharmony_ci{
1217f6603c60Sopenharmony_ci    (void)info;
1218f6603c60Sopenharmony_ci    eglGetErrorInit();
1219f6603c60Sopenharmony_ci    EGLImage image = eglCreateImage(EGL_NO_DISPLAY, EGL_NO_CONTEXT, EGL_GL_TEXTURE_2D, nullptr, nullptr);
1220f6603c60Sopenharmony_ci    NAPI_ASSERT(env, image == EGL_NO_IMAGE, "eglCreateImage error");
1221f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1222f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1223f6603c60Sopenharmony_ci    napi_value result = nullptr;
1224f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1225f6603c60Sopenharmony_ci    return result;
1226f6603c60Sopenharmony_ci}
1227f6603c60Sopenharmony_ci
1228f6603c60Sopenharmony_cistatic napi_value EglDestroyImage(napi_env env, napi_callback_info info)
1229f6603c60Sopenharmony_ci{
1230f6603c60Sopenharmony_ci    (void)info;
1231f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1232f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1233f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1234f6603c60Sopenharmony_ci        int texture = EGL_ONE;
1235f6603c60Sopenharmony_ci        glBindTexture(GL_TEXTURE_2D, texture);
1236f6603c60Sopenharmony_ci        glTexImage2D(GL_TEXTURE_2D, 0x00, GL_RGBA, INIT_WIDTH, INIT_HEIGHT, 0x00, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1237f6603c60Sopenharmony_ci        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1238f6603c60Sopenharmony_ci        const EGLAttrib eglAttrib[] = {EGL_GL_TEXTURE_LEVEL, 0x00, EGL_NONE};
1239f6603c60Sopenharmony_ci        EGLImage image = eglCreateImage(myEGLWindow.eglDisplay, myEGLWindow.eglContext, EGL_GL_TEXTURE_2D,
1240f6603c60Sopenharmony_ci                                        (void *)(static_cast<intptr_t>(texture)), eglAttrib);
1241f6603c60Sopenharmony_ci        NAPI_ASSERT(env, image != EGL_NO_IMAGE, "eglCreateImage error");
1242f6603c60Sopenharmony_ci        EGLBoolean Ret = eglDestroyImage(myEGLWindow.eglDisplay, image);
1243f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroyImage error");
1244f6603c60Sopenharmony_ci    }
1245f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1246f6603c60Sopenharmony_ci    napi_value result = nullptr;
1247f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1248f6603c60Sopenharmony_ci    return result;
1249f6603c60Sopenharmony_ci}
1250f6603c60Sopenharmony_ci
1251f6603c60Sopenharmony_cistatic napi_value EglDestroyImageAbnormal(napi_env env, napi_callback_info info)
1252f6603c60Sopenharmony_ci{
1253f6603c60Sopenharmony_ci    (void)info;
1254f6603c60Sopenharmony_ci    eglGetErrorInit();
1255f6603c60Sopenharmony_ci    EGLBoolean Ret = eglDestroyImage(EGL_NO_DISPLAY, EGL_NO_IMAGE);
1256f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret != EGL_TRUE, "eglDestroyImage error");
1257f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1258f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1259f6603c60Sopenharmony_ci    napi_value result = nullptr;
1260f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1261f6603c60Sopenharmony_ci    return result;
1262f6603c60Sopenharmony_ci}
1263f6603c60Sopenharmony_ci
1264f6603c60Sopenharmony_cistatic napi_value EglGetPlatformDisplay(napi_env env, napi_callback_info info)
1265f6603c60Sopenharmony_ci{
1266f6603c60Sopenharmony_ci    (void)info;
1267f6603c60Sopenharmony_ci    EGLDisplay eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_OHOS_KHR, EGL_DEFAULT_DISPLAY, nullptr);
1268f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglDisplay != EGL_NO_DISPLAY, "eglGetPlatformDisplay error");
1269f6603c60Sopenharmony_ci    EGLBoolean Ret = eglTerminate(eglDisplay);
1270f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_TRUE, "eglTerminate error");
1271f6603c60Sopenharmony_ci    napi_value result = nullptr;
1272f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1273f6603c60Sopenharmony_ci    return result;
1274f6603c60Sopenharmony_ci}
1275f6603c60Sopenharmony_ci
1276f6603c60Sopenharmony_cistatic napi_value EglGetPlatformDisplayAbnormal(napi_env env, napi_callback_info info)
1277f6603c60Sopenharmony_ci{
1278f6603c60Sopenharmony_ci    (void)info;
1279f6603c60Sopenharmony_ci    eglGetErrorInit();
1280f6603c60Sopenharmony_ci    EGLDisplay eglDisplay = eglGetPlatformDisplay(0x00, nullptr, nullptr);
1281f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglDisplay == EGL_NO_DISPLAY, "eglGetPlatformDisplay error");
1282f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1283f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_PARAMETER, "eglGetError error");
1284f6603c60Sopenharmony_ci    napi_value result = nullptr;
1285f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1286f6603c60Sopenharmony_ci    return result;
1287f6603c60Sopenharmony_ci}
1288f6603c60Sopenharmony_ci
1289f6603c60Sopenharmony_cistatic napi_value EglCreatePlatformWindowSurfaceAbnormal(napi_env env, napi_callback_info info)
1290f6603c60Sopenharmony_ci{
1291f6603c60Sopenharmony_ci    (void)info;
1292f6603c60Sopenharmony_ci    eglGetErrorInit();
1293f6603c60Sopenharmony_ci    EGLSurface eglSurface = eglCreatePlatformWindowSurface(EGL_NO_DISPLAY, nullptr, nullptr, nullptr);
1294f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglSurface == EGL_NO_SURFACE, "eglCreatePlatformWindowSurface error");
1295f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1296f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1297f6603c60Sopenharmony_ci    napi_value result = nullptr;
1298f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1299f6603c60Sopenharmony_ci    return result;
1300f6603c60Sopenharmony_ci}
1301f6603c60Sopenharmony_ci
1302f6603c60Sopenharmony_cistatic napi_value EglCreatePlatformPixmapSurfaceAbnormal(napi_env env, napi_callback_info info)
1303f6603c60Sopenharmony_ci{
1304f6603c60Sopenharmony_ci    (void)info;
1305f6603c60Sopenharmony_ci    eglGetErrorInit();
1306f6603c60Sopenharmony_ci    EGLSurface eglSurface = eglCreatePlatformPixmapSurface(EGL_NO_DISPLAY, nullptr, nullptr, nullptr);
1307f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglSurface == EGL_NO_SURFACE, "eglCreatePlatformPixmapSurface error");
1308f6603c60Sopenharmony_ci    EGLint eglError = eglGetError();
1309f6603c60Sopenharmony_ci    NAPI_ASSERT(env, eglError == EGL_BAD_DISPLAY, "eglGetError error");
1310f6603c60Sopenharmony_ci    napi_value result = nullptr;
1311f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1312f6603c60Sopenharmony_ci    return result;
1313f6603c60Sopenharmony_ci}
1314f6603c60Sopenharmony_ci
1315f6603c60Sopenharmony_cistatic napi_value EglWaitSync(napi_env env, napi_callback_info info)
1316f6603c60Sopenharmony_ci{
1317f6603c60Sopenharmony_ci    (void)info;
1318f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1319f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1320f6603c60Sopenharmony_ci    if (myEGLWindow.eglVersion >= GL_VERSION_15) {
1321f6603c60Sopenharmony_ci        const EGLAttrib attr[] = {EGL_NONE};
1322f6603c60Sopenharmony_ci        EGLSync eglSync = eglCreateSync(myEGLWindow.eglDisplay, EGL_SYNC_FENCE, attr);
1323f6603c60Sopenharmony_ci        NAPI_ASSERT(env, eglSync != EGL_NO_SYNC, "eglCreateSync error");
1324f6603c60Sopenharmony_ci        EGLBoolean Ret = eglWaitSync(myEGLWindow.eglDisplay, eglSync, 0x00);
1325f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglWaitSync error");
1326f6603c60Sopenharmony_ci        Ret = eglDestroySync(myEGLWindow.eglDisplay, eglSync);
1327f6603c60Sopenharmony_ci        NAPI_ASSERT(env, Ret == EGL_TRUE, "eglDestroySync error");
1328f6603c60Sopenharmony_ci    }
1329f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1330f6603c60Sopenharmony_ci    napi_value result = nullptr;
1331f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1332f6603c60Sopenharmony_ci    return result;
1333f6603c60Sopenharmony_ci}
1334f6603c60Sopenharmony_ci
1335f6603c60Sopenharmony_cistatic napi_value EglWaitSyncAbnormal(napi_env env, napi_callback_info info)
1336f6603c60Sopenharmony_ci{
1337f6603c60Sopenharmony_ci    (void)info;
1338f6603c60Sopenharmony_ci    MyEGLWindow myEGLWindow = {EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_CONTEXT};
1339f6603c60Sopenharmony_ci    createMyEglWindow(env, &myEGLWindow);
1340f6603c60Sopenharmony_ci    EGLBoolean Ret = eglWaitSync(myEGLWindow.eglDisplay, EGL_NO_SYNC, EGL_ONE);
1341f6603c60Sopenharmony_ci    NAPI_ASSERT(env, Ret == EGL_FALSE, "eglWaitSync error");
1342f6603c60Sopenharmony_ci    destroyMyEglWindow(env, &myEGLWindow);
1343f6603c60Sopenharmony_ci    napi_value result = nullptr;
1344f6603c60Sopenharmony_ci    napi_create_int32(env, SUCCESS, &result);
1345f6603c60Sopenharmony_ci    return result;
1346f6603c60Sopenharmony_ci}
1347f6603c60Sopenharmony_ci
1348f6603c60Sopenharmony_ciEXTERN_C_START
1349f6603c60Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports)
1350f6603c60Sopenharmony_ci{
1351f6603c60Sopenharmony_ci    napi_property_descriptor desc[] = {
1352f6603c60Sopenharmony_ci        {"eglChooseConfig", nullptr, EglChooseConfig, nullptr, nullptr, nullptr, napi_default, nullptr},
1353f6603c60Sopenharmony_ci        {"eglChooseConfigAbnormal", nullptr, EglChooseConfigAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1354f6603c60Sopenharmony_ci        {"eglCopyBuffersAbnormal", nullptr, EglCopyBuffersAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1355f6603c60Sopenharmony_ci        {"eglCreateContext", nullptr, EglCreateContext, nullptr, nullptr, nullptr, napi_default, nullptr},
1356f6603c60Sopenharmony_ci        {"eglCreateContextAbnormal", nullptr, EglCreateContextAbnormal, nullptr, nullptr, nullptr, napi_default,
1357f6603c60Sopenharmony_ci         nullptr},
1358f6603c60Sopenharmony_ci        {"eglCreatePbufferSurface", nullptr, EglCreatePbufferSurface, nullptr, nullptr, nullptr, napi_default, nullptr},
1359f6603c60Sopenharmony_ci        {"eglCreatePbufferSurfaceAbnormal", nullptr, EglCreatePbufferSurfaceAbnormal, nullptr, nullptr, nullptr,
1360f6603c60Sopenharmony_ci         napi_default, nullptr},
1361f6603c60Sopenharmony_ci        {"eglCreatePixmapSurfaceAbnormal", nullptr, EglCreatePixmapSurfaceAbnormal, nullptr, nullptr, nullptr,
1362f6603c60Sopenharmony_ci         napi_default, nullptr},
1363f6603c60Sopenharmony_ci        {"eglCreateWindowSurfaceAbnormal", nullptr, EglCreateWindowSurfaceAbnormal, nullptr, nullptr, nullptr,
1364f6603c60Sopenharmony_ci         napi_default, nullptr},
1365f6603c60Sopenharmony_ci        {"eglDestroyContext", nullptr, EglDestroyContext, nullptr, nullptr, nullptr, napi_default, nullptr},
1366f6603c60Sopenharmony_ci        {"eglDestroyContextAbnormal", nullptr, EglDestroyContextAbnormal, nullptr, nullptr, nullptr, napi_default,
1367f6603c60Sopenharmony_ci         nullptr},
1368f6603c60Sopenharmony_ci        {"eglDestroySurface", nullptr, EglDestroySurface, nullptr, nullptr, nullptr, napi_default, nullptr},
1369f6603c60Sopenharmony_ci        {"eglDestroySurfaceAbnormal", nullptr, EglDestroySurfaceAbnormal, nullptr, nullptr, nullptr, napi_default,
1370f6603c60Sopenharmony_ci         nullptr},
1371f6603c60Sopenharmony_ci        {"eglGetConfigAttrib", nullptr, EglGetConfigAttrib, nullptr, nullptr, nullptr, napi_default, nullptr},
1372f6603c60Sopenharmony_ci        {"eglGetConfigAttribAbnormal", nullptr, EglGetConfigAttribAbnormal, nullptr, nullptr, nullptr, napi_default,
1373f6603c60Sopenharmony_ci         nullptr},
1374f6603c60Sopenharmony_ci        {"eglGetConfigs", nullptr, EglGetConfigs, nullptr, nullptr, nullptr, napi_default, nullptr},
1375f6603c60Sopenharmony_ci        {"eglGetConfigsAbnormal", nullptr, EglGetConfigsAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1376f6603c60Sopenharmony_ci        {"eglGetCurrentDisplay", nullptr, EglGetCurrentDisplay, nullptr, nullptr, nullptr, napi_default, nullptr},
1377f6603c60Sopenharmony_ci        {"eglGetCurrentDisplayAbnormal", nullptr, EglGetCurrentDisplayAbnormal, nullptr, nullptr, nullptr, napi_default,
1378f6603c60Sopenharmony_ci         nullptr},
1379f6603c60Sopenharmony_ci        {"eglGetCurrentSurface", nullptr, EglGetCurrentSurface, nullptr, nullptr, nullptr, napi_default, nullptr},
1380f6603c60Sopenharmony_ci        {"eglGetCurrentSurfaceAbnormal", nullptr, EglGetCurrentSurfaceAbnormal, nullptr, nullptr, nullptr, napi_default,
1381f6603c60Sopenharmony_ci         nullptr},
1382f6603c60Sopenharmony_ci        {"eglGetDisplay", nullptr, EglGetDisplay, nullptr, nullptr, nullptr, napi_default, nullptr},
1383f6603c60Sopenharmony_ci        {"eglGetError", nullptr, EglGetError, nullptr, nullptr, nullptr, napi_default, nullptr},
1384f6603c60Sopenharmony_ci        {"eglGetProcAddress", nullptr, EglGetProcAddress, nullptr, nullptr, nullptr, napi_default, nullptr},
1385f6603c60Sopenharmony_ci        {"eglGetProcAddressAbnormal", nullptr, EglGetProcAddressAbnormal, nullptr, nullptr, nullptr, napi_default,
1386f6603c60Sopenharmony_ci         nullptr},
1387f6603c60Sopenharmony_ci        {"eglInitialize", nullptr, EglInitialize, nullptr, nullptr, nullptr, napi_default, nullptr},
1388f6603c60Sopenharmony_ci        {"eglInitializeAbnormal", nullptr, EglInitializeAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1389f6603c60Sopenharmony_ci        {"eglMakeCurrent", nullptr, EglMakeCurrent, nullptr, nullptr, nullptr, napi_default, nullptr},
1390f6603c60Sopenharmony_ci        {"eglMakeCurrentAbnormal", nullptr, EglMakeCurrentAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1391f6603c60Sopenharmony_ci        {"eglQueryContext", nullptr, EglQueryContext, nullptr, nullptr, nullptr, napi_default, nullptr},
1392f6603c60Sopenharmony_ci        {"eglQueryContextAbnormal", nullptr, EglQueryContextAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1393f6603c60Sopenharmony_ci        {"eglQueryString", nullptr, EglQueryString, nullptr, nullptr, nullptr, napi_default, nullptr},
1394f6603c60Sopenharmony_ci        {"eglQueryStringAbnormal", nullptr, EglQueryStringAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1395f6603c60Sopenharmony_ci        {"eglQuerySurface", nullptr, EglQuerySurface, nullptr, nullptr, nullptr, napi_default, nullptr},
1396f6603c60Sopenharmony_ci        {"eglQuerySurfaceAbnormal", nullptr, EglQuerySurfaceAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1397f6603c60Sopenharmony_ci        {"eglSwapBuffers", nullptr, EglSwapBuffers, nullptr, nullptr, nullptr, napi_default, nullptr},
1398f6603c60Sopenharmony_ci        {"eglSwapBuffersAbnormal", nullptr, EglSwapBuffersAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1399f6603c60Sopenharmony_ci        {"eglTerminate", nullptr, EglTerminate, nullptr, nullptr, nullptr, napi_default, nullptr},
1400f6603c60Sopenharmony_ci        {"eglTerminateAbnormal", nullptr, EglTerminateAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1401f6603c60Sopenharmony_ci        {"eglWaitGL", nullptr, EglWaitGL, nullptr, nullptr, nullptr, napi_default, nullptr},
1402f6603c60Sopenharmony_ci        {"eglWaitNative", nullptr, EglWaitNative, nullptr, nullptr, nullptr, napi_default, nullptr},
1403f6603c60Sopenharmony_ci        {"eglBindTexImage", nullptr, EglBindTexImage, nullptr, nullptr, nullptr, napi_default, nullptr},
1404f6603c60Sopenharmony_ci        {"eglBindTexImageAbnormal", nullptr, EglBindTexImageAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1405f6603c60Sopenharmony_ci        {"eglReleaseTexImage", nullptr, EglReleaseTexImage, nullptr, nullptr, nullptr, napi_default, nullptr},
1406f6603c60Sopenharmony_ci        {"eglReleaseTexImageAbnormal", nullptr, EglReleaseTexImageAbnormal, nullptr, nullptr, nullptr, napi_default,
1407f6603c60Sopenharmony_ci         nullptr},
1408f6603c60Sopenharmony_ci        {"eglSurfaceAttrib", nullptr, EglSurfaceAttrib, nullptr, nullptr, nullptr, napi_default, nullptr},
1409f6603c60Sopenharmony_ci        {"eglSurfaceAttribAbnormal", nullptr, EglSurfaceAttribAbnormal, nullptr, nullptr, nullptr, napi_default,
1410f6603c60Sopenharmony_ci         nullptr},
1411f6603c60Sopenharmony_ci        {"eglSwapInterval", nullptr, EglSwapInterval, nullptr, nullptr, nullptr, napi_default, nullptr},
1412f6603c60Sopenharmony_ci        {"eglSwapIntervalAbnormal", nullptr, EglSwapIntervalAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1413f6603c60Sopenharmony_ci        {"eglBindAPI", nullptr, EglBindAPI, nullptr, nullptr, nullptr, napi_default, nullptr},
1414f6603c60Sopenharmony_ci        {"eglBindAPIAbnormal", nullptr, EglBindAPIAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1415f6603c60Sopenharmony_ci        {"eglQueryAPI", nullptr, EglQueryAPI, nullptr, nullptr, nullptr, napi_default, nullptr},
1416f6603c60Sopenharmony_ci        {"eglCreatePbufferFromClientBufferAbnormal", nullptr, EglCreatePbufferFromClientBufferAbnormal, nullptr,
1417f6603c60Sopenharmony_ci         nullptr, nullptr, napi_default, nullptr},
1418f6603c60Sopenharmony_ci        {"eglReleaseThread", nullptr, EglReleaseThread, nullptr, nullptr, nullptr, napi_default, nullptr},
1419f6603c60Sopenharmony_ci        {"eglWaitClient", nullptr, EglWaitClient, nullptr, nullptr, nullptr, napi_default, nullptr},
1420f6603c60Sopenharmony_ci        {"eglGetCurrentContext", nullptr, EglGetCurrentContext, nullptr, nullptr, nullptr, napi_default, nullptr},
1421f6603c60Sopenharmony_ci        {"eglCreateSync", nullptr, EglCreateSync, nullptr, nullptr, nullptr, napi_default, nullptr},
1422f6603c60Sopenharmony_ci        {"eglCreateSyncAbnormal", nullptr, EglCreateSyncAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1423f6603c60Sopenharmony_ci        {"eglDestroySync", nullptr, EglDestroySync, nullptr, nullptr, nullptr, napi_default, nullptr},
1424f6603c60Sopenharmony_ci        {"eglDestroySyncAbnormal", nullptr, EglDestroySyncAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1425f6603c60Sopenharmony_ci        {"eglClientWaitSync", nullptr, EglClientWaitSync, nullptr, nullptr, nullptr, napi_default, nullptr},
1426f6603c60Sopenharmony_ci        {"eglClientWaitSyncAbnormal", nullptr, EglClientWaitSyncAbnormal, nullptr, nullptr, nullptr, napi_default,
1427f6603c60Sopenharmony_ci         nullptr},
1428f6603c60Sopenharmony_ci        {"eglGetSyncAttrib", nullptr, EglGetSyncAttrib, nullptr, nullptr, nullptr, napi_default, nullptr},
1429f6603c60Sopenharmony_ci        {"eglGetSyncAttribAbnormal", nullptr, EglGetSyncAttribAbnormal, nullptr, nullptr, nullptr, napi_default,
1430f6603c60Sopenharmony_ci         nullptr},
1431f6603c60Sopenharmony_ci        {"eglCreateImage", nullptr, EglCreateImage, nullptr, nullptr, nullptr, napi_default, nullptr},
1432f6603c60Sopenharmony_ci        {"eglCreateImageAbnormal", nullptr, EglCreateImageAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1433f6603c60Sopenharmony_ci        {"eglDestroyImage", nullptr, EglDestroyImage, nullptr, nullptr, nullptr, napi_default, nullptr},
1434f6603c60Sopenharmony_ci        {"eglDestroyImageAbnormal", nullptr, EglDestroyImageAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1435f6603c60Sopenharmony_ci        {"eglGetPlatformDisplay", nullptr, EglGetPlatformDisplay, nullptr, nullptr, nullptr, napi_default, nullptr},
1436f6603c60Sopenharmony_ci        {"eglGetPlatformDisplayAbnormal", nullptr, EglGetPlatformDisplayAbnormal, nullptr, nullptr, nullptr,
1437f6603c60Sopenharmony_ci         napi_default, nullptr},
1438f6603c60Sopenharmony_ci        {"eglCreatePlatformWindowSurfaceAbnormal", nullptr, EglCreatePlatformWindowSurfaceAbnormal, nullptr, nullptr,
1439f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1440f6603c60Sopenharmony_ci        {"eglCreatePlatformPixmapSurfaceAbnormal", nullptr, EglCreatePlatformPixmapSurfaceAbnormal, nullptr, nullptr,
1441f6603c60Sopenharmony_ci         nullptr, napi_default, nullptr},
1442f6603c60Sopenharmony_ci        {"eglWaitSync", nullptr, EglWaitSync, nullptr, nullptr, nullptr, napi_default, nullptr},
1443f6603c60Sopenharmony_ci        {"eglWaitSyncAbnormal", nullptr, EglWaitSyncAbnormal, nullptr, nullptr, nullptr, napi_default, nullptr},
1444f6603c60Sopenharmony_ci    };
1445f6603c60Sopenharmony_ci    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1446f6603c60Sopenharmony_ci    return exports;
1447f6603c60Sopenharmony_ci}
1448f6603c60Sopenharmony_ciEXTERN_C_END
1449f6603c60Sopenharmony_ci
1450f6603c60Sopenharmony_cistatic napi_module demoModule = {
1451f6603c60Sopenharmony_ci    .nm_version = 1,
1452f6603c60Sopenharmony_ci    .nm_flags = 0,
1453f6603c60Sopenharmony_ci    .nm_filename = nullptr,
1454f6603c60Sopenharmony_ci    .nm_register_func = Init,
1455f6603c60Sopenharmony_ci    .nm_modname = "eglndk",
1456f6603c60Sopenharmony_ci    .nm_priv = ((void *)0),
1457f6603c60Sopenharmony_ci    .reserved = {0},
1458f6603c60Sopenharmony_ci};
1459f6603c60Sopenharmony_ci
1460f6603c60Sopenharmony_ciextern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
1461