1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "egl_core.h"
17
18 #include <EGL/egl.h>
19 #include <EGL/eglext.h>
20 #include <EGL/eglplatform.h>
21 #include <GLES3/gl3.h>
22 #include <cmath>
23 #include <cstdio>
24 #include <hilog/log.h>
25
26 #include "../common/common.h"
27 #include "plugin_render.h"
28
29 namespace NativeXComponentSample {
30 namespace {
31 constexpr int32_t NUM_9 = 9;
32 constexpr int32_t NUM_8 = 8;
33 constexpr int32_t NUM_7 = 7;
34 constexpr int32_t NUM_6 = 6;
35 constexpr int32_t NUM_5 = 5;
36 constexpr int32_t NUM_4 = 4;
37 constexpr int32_t NUM_3 = 3;
38 constexpr int32_t NUM_2 = 2;
39 constexpr int32_t NUM_1 = 1;
40 constexpr int32_t NUM_1024 = 1024;
41 constexpr int32_t NUM_180 = 180;
42 constexpr int32_t NUM_72 = 72;
43 constexpr int32_t NUM_54 = 54;
44 constexpr int32_t NUM_18 = 18;
45 /**
46 * Vertex shader.
47 */
48 const char EGLDRAW_VERTEX_SHADER[] = "#version 300 es\n"
49 "layout(location = 0) in vec4 a_position;\n"
50 "layout(location = 1) in vec4 a_color; \n"
51 "out vec4 v_color; \n"
52 "void main() \n"
53 "{ \n"
54 " gl_Position = a_position; \n"
55 " v_color = a_color; \n"
56 "} \n";
57
58 /**
59 * Fragment shader.
60 */
61 const char EGLDRAW_FRAGMENT_SHADER[] = "#version 300 es\n"
62 "precision mediump float; \n"
63 "in vec4 v_color; \n"
64 "out vec4 fragColor; \n"
65 "void main() \n"
66 "{ \n"
67 " fragColor = v_color; \n"
68 "} \n";
69
70 /**
71 * Texture Render Vertex shader.
72 */
73 const char EGLTR_VERTEX_SHADER[] = "#version 300 es\n"
74 "layout (location = 0) in vec3 aPos; \n"
75 "layout (location = 1) in vec3 aColor; \n"
76 "layout (location = 2) in vec2 aTexCoord; \n"
77 "out vec3 ourColor; \n"
78 "out vec2 TexCoord; \n"
79 "void main() \n"
80 "{ \n"
81 " gl_Position = vec4(aPos, 1.0); \n"
82 " ourColor = aColor; \n"
83 " TexCoord = vec2(aTexCoord.x, aTexCoord.y); \n"
84 "} \n";
85
86 /**
87 * Texture Render Fragment shader.
88 */
89 const char EGLTR_FRAGMENT_SHADER[] = "#version 300 es \n"
90 "precision mediump float; \n"
91 "in vec3 ourColor; \n"
92 "in vec2 TexCoord; \n"
93 "uniform lowp sampler2D texture1; \n"
94 "out vec4 FragColor; \n"
95 "void main() \n"
96 "{ \n"
97 " FragColor = texture(texture1, TexCoord); \n"
98 "} \n";
99
100 /**
101 * Background color #801dae 青莲.
102 */
103 const GLfloat QL_BACKGROUND_COLOR[] = {128.0f / 255, 29.0f / 255, 174.0f / 255, 1.0f};
104
105 /**
106 * Background color #f20c00 石榴红.
107 */
108 const GLfloat SLH_BACKGROUND_COLOR[] = {242.0f / 255, 12.0f / 255, 00.0f / 255, 1.0f};
109
110 /**
111 * Background color #f20c00 花青.
112 */
113 const GLfloat HQ_BACKGROUND_COLOR[] = {00.0f / 255, 52.0f / 255, 114.0f / 255, 1.0f};
114
115 /**
116 * Draw color #7E8FFB.
117 */
118 const GLfloat DRAW_COLOR[] = {126.0f / 255, 143.0f / 255, 251.0f / 255, 1.0f};
119
120 /**
121 * Draw color #a3d900.
122 */
123 const GLfloat CH_DRAW_COLOR[] = {126.0f / 255, 143.0f / 255, 251.0f / 255, 1.0f};
124
125 /**
126 * Draw color #057748.
127 */
128 const GLfloat SHL_DRAW_COLOR[] = {5.0f / 255, 119.0f / 255, 72.0f / 255, 1.0f};
129
130
131 /**
132 * Change color #92D6CC.
133 */
134 const GLfloat CHANGE_COLOR[] = {146.0f / 255, 214.0f / 255, 204.0f / 255, 1.0f};
135
136 /**
137 * Background area.
138 */
139 const GLfloat BACKGROUND_RECTANGLE_VERTICES[] = {-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f};
140
141 /**
142 * Get context parameter count.
143 */
144 const size_t GET_CONTEXT_PARAM_CNT = 1;
145
146 /**
147 * Fifty percent.
148 */
149 const float FIFTY_PERCENT = 0.5;
150
151 /**
152 * Pointer size.
153 */
154 const GLint POINTER_SIZE = 2;
155
156 /**
157 * Triangle fan size.
158 */
159 const GLsizei TRIANGLE_FAN_SIZE = 4;
160
161 /**
162 * Egl red size default.
163 */
164 const int EGL_RED_SIZE_DEFAULT = 8;
165
166 /**
167 * Egl green size default.
168 */
169 const int EGL_GREEN_SIZE_DEFAULT = 8;
170
171 /**
172 * Egl blue size default.
173 */
174 const int EGL_BLUE_SIZE_DEFAULT = 8;
175
176 /**
177 * Egl alpha size default.
178 */
179 const int EGL_ALPHA_SIZE_DEFAULT = 8;
180
181 /**
182 * Default x position.
183 */
184 const int DEFAULT_X_POSITION = 0;
185
186 /**
187 * Default y position.
188 */
189 const int DEFAULT_Y_POSITION = 0;
190
191 /**
192 * Gl red default.
193 */
194 const GLfloat GL_RED_DEFAULT = 0.0;
195
196 /**
197 * Gl green default.
198 */
199 const GLfloat GL_GREEN_DEFAULT = 0.0;
200
201 /**
202 * Gl blue default.
203 */
204 const GLfloat GL_BLUE_DEFAULT = 0.0;
205
206 /**
207 * Gl alpha default.
208 */
209 const GLfloat GL_ALPHA_DEFAULT = 1.0;
210
211 /**
212 * Program error.
213 */
214 const GLuint PROGRAM_ERROR = 0;
215
216 /**
217 * Shape vertices size.
218 */
219 const int SHAPE_VERTICES_SIZE = 8;
220
221 /**
222 * Position handle name.
223 */
224 const char POSITION_NAME[] = "a_position";
225
226 /**
227 * Position error.
228 */
229 const GLint POSITION_ERROR = -1;
230
231 /**
232 * Config attribute list.
233 */
234 const EGLint ATTRIB_LIST[] = {
235 // Key,value.
236 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, EGL_RED_SIZE_DEFAULT, EGL_GREEN_SIZE, EGL_GREEN_SIZE_DEFAULT,
237 EGL_BLUE_SIZE, EGL_BLUE_SIZE_DEFAULT, EGL_ALPHA_SIZE, EGL_ALPHA_SIZE_DEFAULT, EGL_RENDERABLE_TYPE,
238 EGL_OPENGL_ES2_BIT,
239 // End.
240 EGL_NONE};
241
242 /**
243 * Context attributes.
244 */
245 const EGLint CONTEXT_ATTRIBS[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
246 } // namespace
EglContextInit(void * window,int width,int height)247 bool EGLCore::EglContextInit(void* window, int width, int height)
248 {
249 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "EglContextInit execute");
250 if ((window == nullptr) || (width <= 0) || (height <= 0)) {
251 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "EglContextInit: param error");
252 return false;
253 }
254
255 UpdateSize(width, height);
256 eglWindow_ = static_cast<EGLNativeWindowType>(window);
257
258 // Init display.
259 eglDisplay_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
260 if (eglDisplay_ == EGL_NO_DISPLAY) {
261 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglGetDisplay: unable to get EGL display");
262 return false;
263 }
264
265 EGLint majorVersion;
266 EGLint minorVersion;
267 if (!eglInitialize(eglDisplay_, &majorVersion, &minorVersion)) {
268 OH_LOG_Print(
269 LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglInitialize: unable to get initialize EGL display");
270 return false;
271 }
272
273 // Select configuration.
274 const EGLint maxConfigSize = 1;
275 EGLint numConfigs;
276 if (!eglChooseConfig(eglDisplay_, ATTRIB_LIST, &eglConfig_, maxConfigSize, &numConfigs)) {
277 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglChooseConfig: unable to choose configs");
278 return false;
279 }
280
281 return CreateEnvironment();
282 }
283
CreateEnvironment()284 bool EGLCore::CreateEnvironment()
285 {
286 // Create surface.
287 if (eglWindow_ == nullptr) {
288 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglWindow_ is null");
289 return false;
290 }
291 eglSurface_ = eglCreateWindowSurface(eglDisplay_, eglConfig_, eglWindow_, NULL);
292 if (eglSurface_ == nullptr) {
293 OH_LOG_Print(
294 LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglCreateWindowSurface: unable to create");
295 eglTerminate(eglDisplay_);
296 return false;
297 }
298 // Create context.
299 eglContext_ = eglCreateContext(eglDisplay_, eglConfig_, EGL_NO_CONTEXT, CONTEXT_ATTRIBS);
300 if (eglContext_ == nullptr) {
301 OH_LOG_Print(
302 LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglCreateWindowSurface: unable to create");
303 eglDestroySurface(eglDisplay_, eglSurface_);
304 eglTerminate(eglDisplay_);
305 return false;
306 }
307
308 if (!eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_)) {
309 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "eglMakeCurrent failed");
310 eglDestroyContext(eglDisplay_, eglContext_);
311 eglDestroySurface(eglDisplay_, eglSurface_);
312 eglTerminate(eglDisplay_);
313 return false;
314 }
315 // Create program.
316 program_ = TRCreateProgram(EGLTR_VERTEX_SHADER, EGLTR_FRAGMENT_SHADER);
317 if (program_ == PROGRAM_ERROR) {
318 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "CreateProgram: unable to create program");
319 return false;
320 }
321 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "CreateProgram: success!");
322 return true;
323 }
324
TRBackground()325 void EGLCore::TRBackground()
326 {
327 float vertices[] = {
328 // positions // colors // texture coords
329 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
330 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
331 -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f // bottom left
332 };
333 unsigned int indices[] = {
334 0, 1, 3, // first triangle
335 1, 2, 3 // second triangle
336 };
337 unsigned int vbo = 0;
338 unsigned int vao = 0;
339 unsigned int ebo = 0;
340 glGenVertexArrays(1, &vao);
341 glGenBuffers(1, &vbo);
342 glGenBuffers(1, &ebo);
343
344 glBindVertexArray(vao);
345
346 glBindBuffer(GL_ARRAY_BUFFER, vbo);
347 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
348
349 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
350 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
351
352 // position attribute
353 glVertexAttribPointer(0, NUM_3, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)0);
354 glEnableVertexAttribArray(0);
355 // color attribute
356 glVertexAttribPointer(1, NUM_3, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)(NUM_3 * sizeof(float)));
357 glEnableVertexAttribArray(1);
358 // texture coord attribute
359 glVertexAttribPointer(NUM_2, NUM_2, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)(NUM_6 * sizeof(float)));
360 glEnableVertexAttribArray(NUM_2);
361
362 // load and create a texture
363 // -------------------------
364 unsigned int texture;
365 glGenTextures(1, &texture);
366 // all upcoming GL_TEXTURE_2D operations now have effect on this texture object
367 glBindTexture(GL_TEXTURE_2D, texture);
368 // set the texture wrapping parameters
369 // set texture wrapping to GL_CLAMP_TO_EDGE (default wrapping method)
370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
371 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
372 // set texture filtering parameters
373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
375 // load image, create texture and generate mipmaps
376
377 glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
378 glClear(GL_COLOR_BUFFER_BIT);
379
380 glBindTexture(GL_TEXTURE_2D, texture);
381
382 glUseProgram(program_);
383
384 glBindVertexArray(vao);
385 glDrawElements(GL_TRIANGLES, NUM_6, GL_UNSIGNED_INT, 0);
386
387 eglSwapBuffers(eglDisplay_, eglSurface_);
388 }
389
Background()390 void EGLCore::Background()
391 {
392 GLint position = PrepareDraw();
393 if (position == POSITION_ERROR) {
394 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Background get position failed");
395 return;
396 }
397
398 if (!ExecuteDrawBG(position, SLH_BACKGROUND_COLOR,
399 BACKGROUND_RECTANGLE_VERTICES, sizeof(BACKGROUND_RECTANGLE_VERTICES))) {
400 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Background execute draw failed");
401 return;
402 }
403
404 if (!FinishDraw()) {
405 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Background FinishDraw failed");
406 return;
407 }
408 }
409
loadTexture()410 GLuint EGLCore::loadTexture()
411 {
412 uint32_t bmpWidth = 0;
413 uint32_t bmpHeight = 0;
414 uint32_t bmpSize = 0;
415 uint8_t bmpBit = 0;
416
417 //------------------------------------------------------------
418 // 读文件
419 FILE *file = fdopen(fd_, "r");
420 if (file == NULL) {
421 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fdopen failed!");
422 return false;
423 }
424
425 // 取文件
426 if (fseek(file, foff_ + NUM_18, SEEK_SET) != 0) {
427 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fseek failed!");
428 return false;
429 }
430
431 if (fread(&bmpWidth, NUM_4, NUM_1, file) != 0) {
432 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fread failed!");
433 }
434
435 if (fread(&bmpHeight, NUM_4, NUM_1, file) != 0) {
436 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fread failed!");
437 }
438 if (fread(&bmpBit, NUM_1, NUM_1, file) != 0) {
439 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fread failed!");
440 }
441 if (fread(&bmpBit, NUM_1, NUM_1, file) != 0) {
442 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fread failed!");
443 }
444 if (fread(&bmpBit, NUM_1, NUM_1, file) != 0) {
445 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fread failed!");
446 }
447 bmpSize = flen_ - NUM_54;
448
449 unsigned char *bmpData = (unsigned char *)malloc(bmpSize);
450 if (bmpData == NULL) {
451 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB malloc failed!");
452 fclose(file);
453 return false;
454 }
455 if (fseek(file, foff_ + NUM_54, SEEK_SET) != 0) {
456 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fseek failed!");
457 return false;
458 }
459 size_t readCnt = fread(bmpData, bmpSize, NUM_1, file);
460 if (readCnt == 0) {
461 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB read_cnt is 0!");
462 }
463
464 if (fclose(file) != 0) {
465 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fclose failed!");
466 return false;
467 }
468
469 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "bmp_width: %{public}d", bmpWidth);
470 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "bmp_height: %{public}d", bmpHeight);
471 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "bmp_size: %{public}d", bmpSize);
472 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "bmp_bit: %{public}d", bmpBit);
473 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "read_cnt: %{public}zu", readCnt);
474
475 free(bmpData);
476 return 0;
477 }
478
display(GLuint texGround)479 void EGLCore::display(GLuint texGround)
480 {
481 // 清空颜色缓冲区
482 glClear(GL_COLOR_BUFFER_BIT);
483
484 // 使用着色器程序
485 glUseProgram(program_);
486
487 // 绑定纹理
488 glBindTexture(GL_TEXTURE_2D, texGround);
489
490 // 获取顶点坐标和纹理坐标的位置
491 GLint aPositionLocation = glGetAttribLocation(program_, "aPosition");
492 GLint aTexCoordLocation = glGetAttribLocation(program_, "aTexCoord");
493
494 // 启用顶点属性数组
495 glEnableVertexAttribArray(aPositionLocation);
496 glEnableVertexAttribArray(aTexCoordLocation);
497
498 // 设置顶点属性指针
499 glVertexAttribPointer(aPositionLocation, NUM_3, GL_FLOAT, GL_FALSE, 0, BACKGROUND_RECTANGLE_VERTICES);
500 glVertexAttribPointer(aTexCoordLocation, NUM_2, GL_FLOAT, GL_FALSE, 0, BACKGROUND_RECTANGLE_VERTICES);
501
502 // 绘制矩形
503 glDrawArrays(GL_TRIANGLES, 0, NUM_6);
504
505 // 禁用顶点属性数组
506 glDisableVertexAttribArray(aPositionLocation);
507 glDisableVertexAttribArray(aTexCoordLocation);
508
509 eglSwapBuffers(eglDisplay_, eglSurface_);
510 }
511
DrawBmp(uint32_t fd,uint32_t foff,uint32_t flen,int & hasDraw)512 void EGLCore::DrawBmp(uint32_t fd, uint32_t foff, uint32_t flen, int& hasDraw)
513 {
514 flag_ = false;
515 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "Drawbmp");
516
517 FILE *file = fdopen(fd, "r");
518 if (file == NULL) {
519 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fdopen failed!");
520 return;
521 }
522
523 if (fseek(file, foff, SEEK_SET) != 0) {
524 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fseek failed!");
525 fclose(file);
526 return;
527 }
528
529 if (flen <= 0) {
530 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "ResfdExecuteCB fseek failed!");
531 fclose(file);
532 return;
533 }
534 unsigned char *mediaData = new unsigned char[flen];
535 if (mediaData == NULL) {
536 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "new buffer failed!");
537 fclose(file);
538 return;
539 }
540 size_t readCnt = fread(mediaData, sizeof(unsigned char), flen, file);
541 if (readCnt > 0) {
542 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "readcnt: %{public}zu", readCnt);
543 }
544
545 int width = 0;
546 int height = 0;
547 unsigned char *pdata = mediaData + NUM_18;
548 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "width: %{public}d", *((uint32_t *)pdata));
549 width = *((uint32_t *)pdata);
550 pdata = mediaData + NUM_18 + NUM_4;
551 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "height: %{public}d", *((uint32_t *)pdata));
552 height = *((uint32_t *)pdata);
553
554 float vertices[] = {
555 // positions // colors // texture coords
556 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 2.0f, 2.0f, // top right
557 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 2.0f, -1.0f, // bottom right
558 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, // bottom left
559 -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 2.0f // top left
560 };
561
562 unsigned int indices[] = {
563 0, 1, 3, // first triangle
564 1, 2, 3 // second triangle
565 };
566 unsigned int vbo = 0;
567 unsigned int vao = 0;
568 unsigned int ebo = 0;
569 glGenVertexArrays(1, &vao);
570 glGenBuffers(1, &vbo);
571 glGenBuffers(1, &ebo);
572
573 glBindVertexArray(vao);
574
575 glBindBuffer(GL_ARRAY_BUFFER, vbo);
576 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
577
578 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
579 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
580
581 // position attribute
582 glVertexAttribPointer(0, NUM_3, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)0);
583 glEnableVertexAttribArray(0);
584 // color attribute
585 glVertexAttribPointer(1, NUM_3, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)(NUM_3 * sizeof(float)));
586 glEnableVertexAttribArray(1);
587 // texture coord attribute
588 glVertexAttribPointer(NUM_2, NUM_2, GL_FLOAT, GL_FALSE, NUM_8 * sizeof(float), (void*)(NUM_6 * sizeof(float)));
589 glEnableVertexAttribArray(NUM_2);
590
591 // load and create a texture
592 // -------------------------
593 unsigned int texture;
594 glGenTextures(1, &texture);
595 glBindTexture(GL_TEXTURE_2D, texture);
596 // all upcoming GL_TEXTURE_2D operations now have effect on this texture object
597 // set the texture wrapping parameters
598 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
599 // set texture wrapping to GL_CLAMP_TO_EDGE (default wrapping method)
600 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
601 // set texture filtering parameters
602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
604 // load image, create texture and generate mipmaps
605
606 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, mediaData);
607 glGenerateMipmap(GL_TEXTURE_2D);
608
609 glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
610 glClear(GL_COLOR_BUFFER_BIT);
611
612 glBindTexture(GL_TEXTURE_2D, texture);
613
614 glUseProgram(program_);
615
616 glBindVertexArray(vao);
617 glDrawElements(GL_TRIANGLES, NUM_6, GL_UNSIGNED_INT, 0);
618
619 eglSwapBuffers(eglDisplay_, eglSurface_);
620
621 hasDraw = 1;
622 flag_ = true;
623 }
624
Draw(int & hasDraw)625 void EGLCore::Draw(int& hasDraw)
626 {
627 flag_ = false;
628 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "Draw");
629 GLint position = PrepareDraw();
630 if (position == POSITION_ERROR) {
631 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw get position failed");
632 return;
633 }
634
635 if (!ExecuteDrawBG(position, QL_BACKGROUND_COLOR,
636 BACKGROUND_RECTANGLE_VERTICES, sizeof(BACKGROUND_RECTANGLE_VERTICES))) {
637 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw execute draw background failed");
638 return;
639 }
640
641 // Divided into five quadrilaterals and calculate one of the quadrilateral's Vertices
642 GLfloat rotateX = 0;
643 GLfloat rotateY = FIFTY_PERCENT * height_;
644 GLfloat centerX = 0;
645 // Convert DEG(54° & 18°) to RAD
646 GLfloat centerY = -rotateY * (M_PI / NUM_180 * NUM_54) * (M_PI / NUM_180 * NUM_54);
647 // Convert DEG(18°) to RAD
648 GLfloat leftX = -rotateY * (M_PI / NUM_180 * NUM_18);
649 GLfloat leftY = 0;
650 // Convert DEG(18°) to RAD
651 GLfloat rightX = rotateY * (M_PI / NUM_180 * NUM_18);
652 GLfloat rightY = 0;
653
654 const GLfloat shapeVertices[] = { centerX / width_, centerY / height_, leftX / width_, leftY / height_,
655 rotateX / width_, rotateY / height_, rightX / width_, rightY / height_ };
656
657 if (!ExecuteDrawStar(position, DRAW_COLOR, shapeVertices, sizeof(shapeVertices))) {
658 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw execute draw shape failed");
659 return;
660 }
661
662 if (!FinishDraw()) {
663 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw FinishDraw failed");
664 return;
665 }
666 hasDraw = 1;
667
668 flag_ = true;
669 }
670
ChangeColor(int & hasChangeColor)671 void EGLCore::ChangeColor(int& hasChangeColor)
672 {
673 if (!flag_) {
674 return;
675 }
676 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "EGLCore", "ChangeColor");
677 GLint position = PrepareDraw();
678 if (position == POSITION_ERROR) {
679 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ChangeColor get position failed");
680 return;
681 }
682
683 if (!ExecuteDrawBG(position, SLH_BACKGROUND_COLOR,
684 BACKGROUND_RECTANGLE_VERTICES, sizeof(BACKGROUND_RECTANGLE_VERTICES))) {
685 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ChangeColor execute draw background failed");
686 return;
687 }
688
689 // Divided into five quadrilaterals and calculate one of the quadrilateral's Vertices
690 GLfloat rotateX = 0;
691 GLfloat rotateY = FIFTY_PERCENT * height_;
692 GLfloat centerX = 0;
693 // Convert DEG(54° & 18°) to RAD
694 GLfloat centerY = -rotateY * (M_PI / NUM_180 * NUM_54) * (M_PI / NUM_180 * NUM_18);
695 // Convert DEG(18°) to RAD
696 GLfloat leftX = -rotateY * (M_PI / NUM_180 * NUM_18);
697 GLfloat leftY = 0;
698 // Convert DEG(18°) to RAD
699 GLfloat rightX = rotateY * (M_PI / NUM_180 * NUM_18);
700 GLfloat rightY = 0;
701
702 const GLfloat shapeVertices[] = { centerX / width_, centerY / height_, leftX / width_, leftY / height_,
703 rotateX / width_, rotateY / height_, rightX / width_, rightY / height_ };
704
705 if (!ExecuteDrawNewStar(0, CHANGE_COLOR, shapeVertices, sizeof(shapeVertices))) {
706 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw execute draw shape failed");
707 return;
708 }
709
710 // Convert DEG(72°) to RAD
711 GLfloat rad = M_PI / NUM_180 * NUM_72;
712 // Rotate four times
713 for (int i = 0; i < NUM_4; ++i) {
714 Rotate2d(centerX, centerY, &rotateX, &rotateY, rad);
715 Rotate2d(centerX, centerY, &leftX, &leftY, rad);
716 Rotate2d(centerX, centerY, &rightX, &rightY, rad);
717 const GLfloat shapeVertices[] = { centerX / width_, centerY / height_, leftX / width_, leftY / height_,
718 rotateX / width_, rotateY / height_, rightX / width_, rightY / height_ };
719
720 if (!ExecuteDrawNewStar(position, CHANGE_COLOR, shapeVertices, sizeof(shapeVertices))) {
721 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Draw execute draw shape failed");
722 return;
723 }
724 }
725
726 if (!FinishDraw()) {
727 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ChangeColor FinishDraw failed");
728 }
729 hasChangeColor = 1;
730 }
731
PrepareDraw()732 GLint EGLCore::PrepareDraw()
733 {
734 if ((eglDisplay_ == nullptr) || (eglSurface_ == nullptr) || (eglContext_ == nullptr) ||
735 (!eglMakeCurrent(eglDisplay_, eglSurface_, eglSurface_, eglContext_))) {
736 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "PrepareDraw: param error");
737 return POSITION_ERROR;
738 }
739
740 // The gl function has no return value.
741 glViewport(DEFAULT_X_POSITION, DEFAULT_Y_POSITION, width_, height_);
742 glClearColor(GL_RED_DEFAULT, GL_GREEN_DEFAULT, GL_BLUE_DEFAULT, GL_ALPHA_DEFAULT);
743 glClear(GL_COLOR_BUFFER_BIT);
744 glUseProgram(program_);
745
746 return glGetAttribLocation(program_, POSITION_NAME);
747 }
748
ExecuteDrawBG(GLint position,const GLfloat * color,const GLfloat shapeVertices[],unsigned long vertSize)749 bool EGLCore::ExecuteDrawBG(GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize)
750 {
751 if ((position > 0) || (color == nullptr) || (vertSize / sizeof(shapeVertices[0])) != SHAPE_VERTICES_SIZE) {
752 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ExecuteDraw: param error");
753 return false;
754 }
755
756 // The gl function has no return value.
757 glVertexAttribPointer(position, POINTER_SIZE, GL_FLOAT, GL_FALSE, 0, shapeVertices);
758 glEnableVertexAttribArray(position);
759 glVertexAttrib4fv(1, color);
760 glDrawArrays(GL_TRIANGLE_FAN, 0, TRIANGLE_FAN_SIZE);
761 glDisableVertexAttribArray(position);
762
763 return true;
764 }
765
ExecuteDrawStar(GLint position,const GLfloat * color,const GLfloat shapeVertices[],unsigned long vertSize)766 bool EGLCore::ExecuteDrawStar(
767 GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize)
768 {
769 if ((position > 0) || (color == nullptr) || (vertSize / sizeof(shapeVertices[0])) != SHAPE_VERTICES_SIZE) {
770 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ExecuteDraw: param error");
771 return false;
772 }
773
774 // The gl function has no return value.
775 glVertexAttribPointer(position, POINTER_SIZE, GL_FLOAT, GL_FALSE, 0, shapeVertices);
776 glVertexAttribPointer(1, POINTER_SIZE, GL_FLOAT, GL_FALSE, 0, color);
777 glEnableVertexAttribArray(position);
778 glEnableVertexAttribArray(1);
779 glVertexAttrib4fv(1, color);
780 glDrawArrays(GL_TRIANGLE_FAN, 0, TRIANGLE_FAN_SIZE);
781 glDisableVertexAttribArray(position);
782 glDisableVertexAttribArray(1);
783
784 return true;
785 }
786
ExecuteDrawNewStar(GLint position,const GLfloat * color,const GLfloat shapeVertices[],unsigned long vertSize)787 bool EGLCore::ExecuteDrawNewStar(
788 GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize)
789 {
790 if ((position > 0) || (color == nullptr) || (vertSize / sizeof(shapeVertices[0])) != SHAPE_VERTICES_SIZE) {
791 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "ExecuteDraw: param error");
792 return false;
793 }
794
795 // The gl function has no return value.
796 glVertexAttribPointer(position, POINTER_SIZE, GL_FLOAT, GL_FALSE, 0, shapeVertices);
797 glEnableVertexAttribArray(position);
798 glVertexAttrib4fv(1, color);
799 glDrawArrays(GL_TRIANGLE_FAN, 0, TRIANGLE_FAN_SIZE);
800 glDisableVertexAttribArray(position);
801
802 return true;
803 }
804
Rotate2d(GLfloat centerX,GLfloat centerY,GLfloat * rotateX,GLfloat * rotateY,GLfloat theta)805 void EGLCore::Rotate2d(GLfloat centerX, GLfloat centerY, GLfloat* rotateX, GLfloat* rotateY, GLfloat theta)
806 {
807 GLfloat tempX = cos(theta) * (*rotateX - centerX) - sin(theta) * (*rotateY - centerY);
808 GLfloat tempY = sin(theta) * (*rotateX - centerX) + cos(theta) * (*rotateY - centerY);
809 *rotateX = tempX + centerX;
810 *rotateY = tempY + centerY;
811 }
812
FinishDraw()813 bool EGLCore::FinishDraw()
814 {
815 // The gl function has no return value.
816 glFlush();
817 glFinish();
818 return eglSwapBuffers(eglDisplay_, eglSurface_);
819 }
820
LoadShader(GLenum type,const char * shaderSrc)821 GLuint EGLCore::LoadShader(GLenum type, const char* shaderSrc)
822 {
823 if ((type <= 0) || (shaderSrc == nullptr)) {
824 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glCreateShader type or shaderSrc error");
825 return PROGRAM_ERROR;
826 }
827
828 GLuint shader = glCreateShader(type);
829 if (shader == 0) {
830 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glCreateShader unable to load shader");
831 return PROGRAM_ERROR;
832 }
833
834 // The gl function has no return value.
835 glShaderSource(shader, 1, &shaderSrc, nullptr);
836 glCompileShader(shader);
837
838 GLint compiled;
839 glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
840 if (compiled != 0) {
841 return shader;
842 }
843
844 GLint infoLen = 0;
845 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
846 if (infoLen <= 1) {
847 glDeleteShader(shader);
848 return PROGRAM_ERROR;
849 }
850
851 char* infoLog = (char*)malloc(sizeof(char) * (infoLen + 1));
852 if (infoLog != nullptr) {
853 glGetShaderInfoLog(shader, infoLen, nullptr, infoLog);
854 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glCompileShader error = %s", infoLog);
855 free(infoLog);
856 infoLog = nullptr;
857 }
858 glDeleteShader(shader);
859 return PROGRAM_ERROR;
860 }
861
checkCompileErrors(unsigned int shader,std::string type)862 void EGLCore::checkCompileErrors(unsigned int shader, std::string type)
863 {
864 int success;
865 char infoLog[NUM_1024];
866 if (type != "PROGRAM") {
867 glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
868 if (!success) {
869 glGetShaderInfoLog(shader, NUM_1024, NULL, infoLog);
870 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore",
871 "ERROR::SHADER_COMPILATION_ERROR of type: %{public}s", type.c_str());
872 }
873 } else {
874 glGetProgramiv(shader, GL_LINK_STATUS, &success);
875 if (!success) {
876 glGetProgramInfoLog(shader, NUM_1024, NULL, infoLog);
877 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore",
878 "ERROR::PROGRAM_LINKING_ERROR of type: %{public}s", type.c_str());
879 }
880 }
881 }
882
TRCreateProgram(const char * vertexShader,const char * fragShader)883 GLuint EGLCore::TRCreateProgram(const char *vertexShader, const char *fragShader)
884 {
885 if ((vertexShader == nullptr) || (fragShader == nullptr)) {
886 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore",
887 "createProgram: vertexShader or fragShader is null");
888 return PROGRAM_ERROR;
889 }
890
891 unsigned int vertex = 0;
892 unsigned int fragment = 0;
893 // vertex shader
894 vertex = glCreateShader(GL_VERTEX_SHADER);
895 glShaderSource(vertex, 1, &vertexShader, NULL);
896 glCompileShader(vertex);
897 checkCompileErrors(vertex, "VERTEX");
898 // fragment Shader
899 fragment = glCreateShader(GL_FRAGMENT_SHADER);
900 glShaderSource(fragment, 1, &fragShader, NULL);
901 glCompileShader(fragment);
902 checkCompileErrors(fragment, "FRAGMENT");
903
904 GLuint program = glCreateProgram();
905 if (program == PROGRAM_ERROR) {
906 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram program error");
907 glDeleteShader(vertex);
908 glDeleteShader(fragment);
909 return PROGRAM_ERROR;
910 }
911
912 // The gl function has no return value.
913 glAttachShader(program, vertex);
914 glAttachShader(program, fragment);
915 glLinkProgram(program);
916 checkCompileErrors(program, "PROGRAM");
917 GLint linked;
918 glGetProgramiv(program, GL_LINK_STATUS, &linked);
919 if (linked != 0) {
920 glDeleteShader(vertex);
921 glDeleteShader(fragment);
922 return program;
923 }
924
925 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram linked error");
926 GLint infoLen = 0;
927 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
928 if (infoLen > 1) {
929 char *infoLog = (char *)malloc(sizeof(char) * (infoLen + 1));
930 glGetProgramInfoLog(program, infoLen, nullptr, infoLog);
931 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glLinkProgram error = %{public}s", infoLog);
932 free(infoLog);
933 infoLog = nullptr;
934 }
935 glDeleteShader(vertex);
936 glDeleteShader(fragment);
937 glDeleteProgram(program);
938 return PROGRAM_ERROR;
939 }
940
CreateProgram(const char * vertexShader,const char * fragShader)941 GLuint EGLCore::CreateProgram(const char* vertexShader, const char* fragShader)
942 {
943 if ((vertexShader == nullptr) || (fragShader == nullptr)) {
944 OH_LOG_Print(
945 LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram: vertexShader or fragShader is null");
946 return PROGRAM_ERROR;
947 }
948
949 GLuint vertex = LoadShader(GL_VERTEX_SHADER, vertexShader);
950 if (vertex == PROGRAM_ERROR) {
951 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram vertex error");
952 return PROGRAM_ERROR;
953 }
954
955 GLuint fragment = LoadShader(GL_FRAGMENT_SHADER, fragShader);
956 if (fragment == PROGRAM_ERROR) {
957 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram fragment error");
958 return PROGRAM_ERROR;
959 }
960
961 GLuint program = glCreateProgram();
962 if (program == PROGRAM_ERROR) {
963 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram program error");
964 glDeleteShader(vertex);
965 glDeleteShader(fragment);
966 return PROGRAM_ERROR;
967 }
968
969 // The gl function has no return value.
970 glAttachShader(program, vertex);
971 glAttachShader(program, fragment);
972 glLinkProgram(program);
973
974 GLint linked;
975 glGetProgramiv(program, GL_LINK_STATUS, &linked);
976 if (linked != 0) {
977 glDeleteShader(vertex);
978 glDeleteShader(fragment);
979 return program;
980 }
981
982 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "createProgram linked error");
983 GLint infoLen = 0;
984 glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen);
985 if (infoLen > 1) {
986 char* infoLog = (char*)malloc(sizeof(char) * (infoLen + 1));
987 glGetProgramInfoLog(program, infoLen, nullptr, infoLog);
988 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "glLinkProgram error = %s", infoLog);
989 free(infoLog);
990 infoLog = nullptr;
991 }
992 glDeleteShader(vertex);
993 glDeleteShader(fragment);
994 glDeleteProgram(program);
995 return PROGRAM_ERROR;
996 }
997
UpdateSize(int width,int height)998 void EGLCore::UpdateSize(int width, int height)
999 {
1000 width_ = width;
1001 height_ = height;
1002 if (width_ > 0) {
1003 widthPercent_ = FIFTY_PERCENT * height_ / width_;
1004 }
1005 }
1006
Release()1007 void EGLCore::Release()
1008 {
1009 if ((eglDisplay_ == nullptr) || (eglSurface_ == nullptr) || (!eglDestroySurface(eglDisplay_, eglSurface_))) {
1010 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglDestroySurface failed");
1011 }
1012
1013 if ((eglDisplay_ == nullptr) || (eglContext_ == nullptr) || (!eglDestroyContext(eglDisplay_, eglContext_))) {
1014 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglDestroyContext failed");
1015 }
1016
1017 if ((eglDisplay_ == nullptr) || (!eglTerminate(eglDisplay_))) {
1018 OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCore", "Release eglTerminate failed");
1019 }
1020 }
1021 } // namespace NativeXComponentSample
1022