• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdlib>
17 #include "napi/native_api.h"
18 #include "native_common.h"
19 #include "Gl4ApiTest.h"
20 
getError(const napi_env env,const GLenum glError)21 static napi_value getError(const napi_env env, const GLenum glError)
22 {
23     napi_value result = nullptr;
24     if (GL_NO_ERROR == glError) {
25         napi_create_int32(env, SUCCESS, &result);
26     } else {
27         napi_create_int32(env, FAILED, &result);
28     }
29     return result;
30 }
31 
GLTextureARBTest(napi_env env,napi_callback_info info)32 static napi_value GLTextureARBTest(napi_env env, napi_callback_info info)
33 {
34     (void)info;
35     Gl4ApiTest gl4ApiTest;
36     gl4ApiTest.InitContext(nullptr);
37     GLenum glError = gl4ApiTest.GLTextureARBAbnormal();
38     gl4ApiTest.Release();
39     return getError(env, glError);
40 }
41 
GLBufferARBTest(napi_env env,napi_callback_info info)42 static napi_value GLBufferARBTest(napi_env env, napi_callback_info info)
43 {
44     (void)info;
45     Gl4ApiTest gl4ApiTest;
46     gl4ApiTest.InitContext(nullptr);
47     GLenum glError = gl4ApiTest.GLBufferARBAbnormal();
48     gl4ApiTest.Release();
49     return getError(env, glError);
50 }
51 
GLUniformARBTest(napi_env env,napi_callback_info info)52 static napi_value GLUniformARBTest(napi_env env, napi_callback_info info)
53 {
54     (void)info;
55     Gl4ApiTest gl4ApiTest;
56     gl4ApiTest.InitContext(nullptr);
57     GLenum glError = gl4ApiTest.GLUniformARBAbnormal();
58     gl4ApiTest.Release();
59     return getError(env, glError);
60 }
61 
GLUniformMatrixARBTest(napi_env env,napi_callback_info info)62 static napi_value GLUniformMatrixARBTest(napi_env env, napi_callback_info info)
63 {
64     (void)info;
65     Gl4ApiTest gl4ApiTest;
66     gl4ApiTest.InitContext(nullptr);
67     GLenum glError = gl4ApiTest.GLUniformMatrixARBAbnormal();
68     gl4ApiTest.Release();
69     return getError(env, glError);
70 }
71 
GLLineStippleHalfEmpty(napi_env env,napi_callback_info info)72 static napi_value GLLineStippleHalfEmpty(napi_env env, napi_callback_info info)
73 {
74     // 测试标准虚线模式
75     glEnable(GL_LINE_STIPPLE);
76     glLineStipple(1, 0x00FF);  // 一半像素实线一半像素空白
77     GLenum glError = glGetError();
78     glDisable(GL_LINE_STIPPLE); // 清理状态
79     return getError(env, glError);
80 }
81 
82 EXTERN_C_START
Init(napi_env env,napi_value exports)83 static napi_value Init(napi_env env, napi_value exports)
84 {
85     napi_property_descriptor desc[] = {
86         {"gLTextureARBTest", nullptr, GLTextureARBTest, nullptr, nullptr, nullptr, napi_default, nullptr},
87         {"gLBufferARBTest", nullptr, GLBufferARBTest, nullptr, nullptr, nullptr, napi_default, nullptr},
88         {"gLUniformARBTest", nullptr, GLUniformARBTest, nullptr, nullptr, nullptr, napi_default, nullptr},
89         {"gLUniformMatrixARBTest", nullptr, GLUniformMatrixARBTest, nullptr, nullptr, nullptr, napi_default, nullptr},
90         {"glLineStippleHalfEmpty", nullptr, GLLineStippleHalfEmpty, nullptr, nullptr, nullptr, napi_default, nullptr},
91     };
92     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
93     setenv("NEED_OPENGL", "1", 1);
94     setenv("MESA_GL_VERSION_OVERRIDE", "4.2", 1);
95     return exports;
96 }
97 EXTERN_C_END
98 
99 static napi_module demoModule = {
100     .nm_version = 1,
101     .nm_flags = 0,
102     .nm_filename = nullptr,
103     .nm_register_func = Init,
104     .nm_modname = "media",
105     .nm_priv = ((void *)0),
106     .reserved = {0},
107 };
108 
RegisterEntryModule(void)109 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }