• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NATIVE_XCOMPONENT_EGL_CORE_H
16 #define NATIVE_XCOMPONENT_EGL_CORE_H
17 
18 #include <EGL/egl.h>
19 #include <EGL/eglext.h>
20 #include <GLES3/gl3.h>
21 #include <string>
22 
23 namespace NativeXComponentSample {
24 class EGLCore {
25 public:
EGLCore()26     explicit EGLCore() {};
~EGLCore()27     ~EGLCore() {}
28     bool EglContextInit(void* window, int width, int height);
29     bool CreateEnvironment();
30     void Draw(int& hasDraw);
31     void DrawBmp(uint32_t fd, uint32_t off, uint32_t len, int& hasDraw);
32     void Background();
33     void TRBackground();
34     void ChangeColor(int& hasChangeColor);
35     void Release();
36     void UpdateSize(int width, int height);
37 
38     uint32_t fd_;
39     uint32_t foff_;
40     uint32_t flen_;
41 private:
42     GLuint LoadShader(GLenum type, const char* shaderSrc);
43     GLuint CreateProgram(const char* vertexShader, const char* fragShader);
44     GLuint TRCreateProgram(const char *vertexShader, const char *fragShader);
45     GLint PrepareDraw();
46     bool ExecuteDrawBG(GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize);
47     bool ExecuteDrawStar(GLint position, const GLfloat* color, const GLfloat shapeVertices[], unsigned long vertSize);
48     bool ExecuteDrawNewStar(GLint position, const GLfloat* color,
49                             const GLfloat shapeVertices[], unsigned long vertSize);
50     void Rotate2d(GLfloat centerX, GLfloat centerY, GLfloat* rotateX, GLfloat* rotateY, GLfloat theta);
51     bool FinishDraw();
52     GLuint LoadTexture();
53     void CheckCompileErrors(unsigned int shader, std::string type);
54     void Display(GLuint texID);
55 
56 private:
57     EGLNativeWindowType eglWindow_;
58     EGLDisplay eglDisplay_ = EGL_NO_DISPLAY;
59     EGLConfig eglConfig_ = EGL_NO_CONFIG_KHR;
60     EGLSurface eglSurface_ = EGL_NO_SURFACE;
61     EGLContext eglContext_ = EGL_NO_CONTEXT;
62     GLuint program_;
63     bool flag_ = false;
64     int width_;
65     int height_;
66     GLfloat widthPercent_;
67 };
68 } // namespace NativeXComponentSample
69 #endif // NATIVE_XCOMPONENT_EGL_CORE_H
70