1 /*
2  * Copyright (c) 2024 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 #ifndef EGL_CORE_H
16 #define EGL_CORE_H
17 
18 #include <EGL/egl.h>
19 #include <EGL/eglext.h>
20 #include <GLES3/gl3.h>
21 
22 namespace OHOS {
23 class EGLCore {
24 public:
EGLCore()25     explicit EGLCore(){};
~EGLCore()26     ~EGLCore() {}
27     bool EglContextInit(void *window, int width, int height);
28     bool CreateEnvironment();
29     void Draw();
30     void Release();
31 
32 private:
33     GLuint LoadShader(GLenum type, const char *shaderSrc);
34     GLuint CreateProgram(const char *vertexShader, const char *fragShader);
35     GLint PrepareDraw();
36     static bool ExecuteDraw(GLint position, const GLfloat *color, const GLfloat rectangleVertices[],
37         unsigned long vertSize);
38     bool FinishDraw();
39 
40 private:
41     EGLNativeWindowType eglwindow_;
42     EGLDisplay egldisplay_ = EGL_NO_DISPLAY;
43     EGLConfig eglconfig_ = EGL_NO_CONFIG_KHR;
44     EGLSurface eglsurface_ = EGL_NO_SURFACE;
45     EGLContext eglcontext_ = EGL_NO_CONTEXT;
46     GLuint program_ = 0;
47     bool flag_ = false;
48     int width_ = 0;
49     int height_ = 0;
50     GLfloat widthpercent_;
51 };
52 } // namespace OHOS
53 #endif // EGL_CORE_H
54