1 /*
2  * Copyright (c) 2022 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 #include <gtest/gtest.h>
16 #include "native_vsync.h"
17 #include "cstring"
18 #include "string"
19 #include "GLES3/gl3.h"
20 #include <GLES3/gl32.h>
21 #include "EGL/egl.h"
22 #include <EGL/eglext.h>
23 #include <vector>
24 #include <iostream>
25 
26 #undef LOG_DOMAIN
27 #define LOG_DOMAIN 0xD003200
28 
29 #ifndef LOGI
30 #define LOGI(FMT, VARS...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "HMG_LOG", FMT, ##VARS))
31 
32 #endif
33 
34 using namespace testing;
35 using namespace testing::ext;
36 
37 namespace OHOS {
38     namespace Rosen {
39         class OH_GLES_ExtensionTest : public testing::Test {
40         };
41 
42         namespace {
43             /*
44              * @tc.name: OH_GLES_Extension001
45              * @tc.desc: test for OH_GLES_Extension
46              * @tc.type: FUNC
47              */
48 
HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension001, Function | MediumTest | Level2)49             HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension001, Function | MediumTest | Level2)
50             {
51                 EGLDisplay display;
52                 EGLConfig config;
53                 EGLContext context;
54                 EGLSurface surfaceCache;
55                 EGLint majorVersion;
56                 EGLint minorVersion;
57                 EGLint numConfigs;
58                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
59                 eglInitialize(display, &majorVersion, &minorVersion);
60                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
61                 eglInitialize(display, &majorVersion, &minorVersion);
62                 EGLint attribs[] = {
63                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
64                     EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
65                     EGL_RED_SIZE, 8, EGL_NONE};
66                 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
67                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
68                 surfaceCache = eglCreatePbufferSurface(display, config, NULL);
69                 eglMakeCurrent(display, surfaceCache, surfaceCache, context);
70                 char *strTest = new char[1024];
71                 strTest = (char *)glGetString(GL_VERSION);
72                 string strTest2(strTest);
73                 vector<string> vv;
74                 string my = "";
75                 strTest2 = strTest2 + ' ';
76                 for (int i = 0; i < strTest2.size() - 1; i++)
77                 {
78                     if (strTest2[i + 1] == ' ')
79                     {
80                         vv.push_back(my);
81                         my = "";
82                     }
83                     else
84                     {
85                         my += strTest2[i];
86                     }
87                 }
88 
89                 map<string, string> myMap;
90                 myMap["glBufferPageCommitmentMemNV"] = "GL_NV_memory_object_sparse";
91                 myMap["glCreateSemaphoresNV"] = "GL_NV_timeline_semaphore";
92                 myMap["glExtrapolateTex2DQCOM"] = "GL_QCOM_frame_extrapolation";
93 
94                 bool isHave1 = strTest2.find("GL_NV_memory_object_sparse") != -1 ? true : false;
95                 bool isHave2 = strTest2.find("GL_NV_timeline_semaphore") != -1 ? true : false;
96                 bool isHave3 = strTest2.find("GL_QCOM_frame_extrapolation") != -1 ? true : false;
97 
98                 ASSERT_EQ(isHave1, 0);
99                 ASSERT_EQ(isHave2, 0);
100                 ASSERT_EQ(isHave3, 0);
101             }
102 
103             /*
104              * @tc.name: OH_GLES_Extension002
105              * @tc.desc: test for OH_GLES_Extension
106              * @tc.type: FUNC
107              */
108 
HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension002, Function | MediumTest | Level2)109             HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension002, Function | MediumTest | Level2)
110             {
111                 EGLDisplay display;
112                 EGLConfig config;
113                 EGLContext context;
114                 EGLSurface surfaceCache;
115                 EGLint majorVersion;
116                 EGLint minorVersion;
117                 EGLint numConfigs;
118                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
119                 eglInitialize(display, &majorVersion, &minorVersion);
120                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
121                 eglInitialize(display, &majorVersion, &minorVersion);
122                 EGLint attribs[] = {
123                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
124                     EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
125                     EGL_RED_SIZE, 8, EGL_NONE};
126                 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
127                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
128                 surfaceCache = eglCreatePbufferSurface(display, config, NULL);
129                 eglMakeCurrent(display, surfaceCache, surfaceCache, context);
130                 char *strTest = new char[1024];
131                 strTest = (char *)glGetString(GL_VERSION);
132                 string strTest2(strTest);
133                 vector<string> vv;
134                 string my = "";
135                 strTest2 = strTest2 + ' ';
136                 for (int i = 0; i < strTest2.size() - 1; i++)
137                 {
138                     if (strTest2[i + 1] == ' ')
139                     {
140                         vv.push_back(my);
141                         my = "";
142                     }
143                     else
144                     {
145                         my += strTest2[i];
146                     }
147                 }
148 
149                 map<string, string> myMap;
150                 myMap["glFramebufferParameteriMESA"] = "GL_MESA_framebuffer_flip_y";
151                 myMap["glGetFramebufferParameterivMESA"] = "GL_MESA_framebuffer_flip_y";
152                 myMap["glGetSemaphoreParameterivNV"] = "GL_NV_timeline_semaphore";
153 
154                 bool isHave1 = strTest2.find("GL_MESA_framebuffer_flip_y") != -1 ? true : false;
155                 bool isHave2 = strTest2.find("GL_MESA_framebuffer_flip_y") != -1 ? true : false;
156                 bool isHave3 = strTest2.find("GL_NV_timeline_semaphore") != -1 ? true : false;
157 
158                 ASSERT_EQ(isHave1, 0);
159                 ASSERT_EQ(isHave2, 0);
160                 ASSERT_EQ(isHave3, 0);
161             }
162 
163             /*
164              * @tc.name: OH_GLES_Extension003
165              * @tc.desc: test for OH_GLES_Extension
166              * @tc.type: FUNC
167              */
168 
HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension003, Function | MediumTest | Level2)169             HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension003, Function | MediumTest | Level2)
170             {
171                 EGLDisplay display;
172                 EGLConfig config;
173                 EGLContext context;
174                 EGLSurface surfaceCache;
175                 EGLint majorVersion;
176                 EGLint minorVersion;
177                 EGLint numConfigs;
178                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
179                 eglInitialize(display, &majorVersion, &minorVersion);
180                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
181                 eglInitialize(display, &majorVersion, &minorVersion);
182                 EGLint attribs[] = {
183                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
184                     EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
185                     EGL_RED_SIZE, 8, EGL_NONE};
186                 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
187                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
188                 surfaceCache = eglCreatePbufferSurface(display, config, NULL);
189                 eglMakeCurrent(display, surfaceCache, surfaceCache, context);
190                 char *strTest = new char[1024];
191                 strTest = (char *)glGetString(GL_VERSION);
192                 string strTest2(strTest);
193                 vector<string> vv;
194                 string my = "";
195                 strTest2 = strTest2 + ' ';
196                 for (int i = 0; i < strTest2.size() - 1; i++)
197                 {
198                     if (strTest2[i + 1] == ' ')
199                     {
200                         vv.push_back(my);
201                         my = "";
202                     }
203                     else
204                     {
205                         my += strTest2[i];
206                     }
207                 }
208 
209                 map<string, string> myMap;
210                 myMap["glNamedBufferPageCommitmentMemNV"] = "GL_NV_memory_object_sparse";
211                 myMap["glSemaphoreParameterivNV"] = "GL_NV_timeline_semaphore";
212                 myMap["glShadingRateQCOM"] = "GL_QCOM_shading_rate";
213 
214                 bool isHave1 = strTest2.find("GL_NV_memory_object_sparse") != -1 ? true : false;
215                 bool isHave2 = strTest2.find("GL_NV_timeline_semaphore") != -1 ? true : false;
216                 bool isHave3 = strTest2.find("GL_QCOM_shading_rate") != -1 ? true : false;
217 
218                 ASSERT_EQ(isHave1, 0);
219                 ASSERT_EQ(isHave2, 0);
220                 ASSERT_EQ(isHave3, 0);
221             }
222 
223             /*
224              * @tc.name: OH_GLES_Extension004
225              * @tc.desc: test for OH_GLES_Extension
226              * @tc.type: FUNC
227              */
228 
HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension004, Function | MediumTest | Level2)229             HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension004, Function | MediumTest | Level2)
230             {
231                 EGLDisplay display;
232                 EGLConfig config;
233                 EGLContext context;
234                 EGLSurface surfaceCache;
235                 EGLint majorVersion;
236                 EGLint minorVersion;
237                 EGLint numConfigs;
238                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
239                 eglInitialize(display, &majorVersion, &minorVersion);
240                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
241                 eglInitialize(display, &majorVersion, &minorVersion);
242                 EGLint attribs[] = {
243                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
244                     EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
245                     EGL_RED_SIZE, 8, EGL_NONE};
246                 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
247                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
248                 surfaceCache = eglCreatePbufferSurface(display, config, NULL);
249                 eglMakeCurrent(display, surfaceCache, surfaceCache, context);
250                 char *strTest = new char[1024];
251                 strTest = (char *)glGetString(GL_VERSION);
252                 string strTest2(strTest);
253                 vector<string> vv;
254                 string my = "";
255                 strTest2 = strTest2 + ' ';
256                 for (int i = 0; i < strTest2.size() - 1; i++)
257                 {
258                     if (strTest2[i + 1] == ' ')
259                     {
260                         vv.push_back(my);
261                         my = "";
262                     }
263                     else
264                     {
265                         my += strTest2[i];
266                     }
267                 }
268 
269                 map<string, string> myMap;
270                 myMap["glTexEstimateMotionQCOM"] = "GL_QCOM_motion_estimation";
271                 myMap["glTexEstimateMotionRegionsQCOM"] = "GL_QCOM_motion_estimation";
272                 myMap["glTexPageCommitmentMemNV"] = "GL_NV_memory_object_sparse";
273 
274                 bool isHave1 = strTest2.find("GL_QCOM_motion_estimation") != -1 ? true : false;
275                 bool isHave2 = strTest2.find("GL_NV_memory_object_sparse") != -1 ? true : false;
276                 bool isHave3 = strTest2.find("GL_NV_memory_object_sparse") != -1 ? true : false;
277 
278                 ASSERT_EQ(isHave1, 0);
279                 ASSERT_EQ(isHave2, 0);
280                 ASSERT_EQ(isHave3, 0);
281             }
282 
283             /*
284              * @tc.name: OH_GLES_Extension005
285              * @tc.desc: test for OH_GLES_Extension
286              * @tc.type: FUNC
287              */
288 
HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension005, Function | MediumTest | Level2)289             HWTEST_F(OH_GLES_ExtensionTest, OH_GLES_Extension005, Function | MediumTest | Level2)
290             {
291                 EGLDisplay display;
292                 EGLConfig config;
293                 EGLContext context;
294                 EGLSurface surfaceCache;
295                 EGLint majorVersion;
296                 EGLint minorVersion;
297                 EGLint numConfigs;
298                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
299                 eglInitialize(display, &majorVersion, &minorVersion);
300                 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
301                 eglInitialize(display, &majorVersion, &minorVersion);
302                 EGLint attribs[] = {
303                     EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
304                     EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8,
305                     EGL_RED_SIZE, 8, EGL_NONE};
306                 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
307                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
308                 surfaceCache = eglCreatePbufferSurface(display, config, NULL);
309                 eglMakeCurrent(display, surfaceCache, surfaceCache, context);
310                 char *strTest = new char[1024];
311                 strTest = (char *)glGetString(GL_VERSION);
312                 string strTest2(strTest);
313                 vector<string> vv;
314                 string my = "";
315                 strTest2 = strTest2 + ' ';
316                 for (int i = 0; i < strTest2.size() - 1; i++)
317                 {
318                     if (strTest2[i + 1] == ' ')
319                     {
320                         vv.push_back(my);
321                         my = "";
322                     }
323                     else
324                     {
325                         my += strTest2[i];
326                     }
327                 }
328 
329                 map<string, string> myMap;
330                 myMap["glTexturePageCommitmentMemNV"] = "GL_NV_memory_object_sparse";
331                 myMap["TexStorageAttribs2DEXT"] = "GL_EXT_texture_storage_compression";
332                 myMap["TexStorageAttribs3DEXT"] = "GL_EXT_texture_storage_compression";
333 
334                 bool isHave1 = strTest2.find("GL_EXT_texture_storage_compression") != -1 ? true : false;
335                 bool isHave2 = strTest2.find("GL_EXT_texture_storage_compression") != -1 ? true : false;
336                 bool isHave3 = strTest2.find("GL_QCOM_motion_estimation") != -1 ? true : false;
337 
338                 ASSERT_EQ(isHave1, 0);
339                 ASSERT_EQ(isHave2, 0);
340                 ASSERT_EQ(isHave3, 0);
341             }
342         } // namespace
343     }     // namespace Rosen
344 } // namespace OHOS