• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef IMAGE_RENDER_H
17 #define IMAGE_RENDER_H
18 
19 #include <EGL/egl.h>
20 #include <GLES2/gl2.h>
21 
22 class ImageRender {
23 public:
24     ImageRender();
25     ~ImageRender();
26 
27     bool InitEGL(EGLNativeWindowType window, uint64_t width, uint64_t height);
28     bool MakeCurrentContext();
29     void UpdateViewport();
30     void UpdateWindowInfo(uint64_t width, uint64_t height);
31     void SetTexture(GLuint textureId, GLuint textureTarget);
32     void Render();
33     void Cleanup();
34     void SetTransformMatrix(const float matrix[16]);
35 
36 private:
37     void SetupVertexAttributes();
38     void DisableVertexAttributes();
39     bool InitializeEGLDisplay();
40     bool ChooseEGLConfig();
41     bool CreateEGLContext();
42     bool CreateEGLSurface();
43     bool CompileAndLinkShaders();
44     void PrintProgramLinkError(GLuint program);
45     GLuint CompileShader(GLenum type, const char* source);
46     void PrintShaderCompileError(GLuint shader);
47 
48     EGLDisplay display_ = EGL_NO_DISPLAY;
49     EGLSurface surface_ = EGL_NO_SURFACE;
50     EGLContext context_ = EGL_NO_CONTEXT;
51     EGLConfig config_ = nullptr;
52     EGLNativeWindowType window_ = 0;
53     uint64_t width_ = 0;
54     uint64_t height_ = 0;
55     GLuint shaderProgram_ = 0;
56     GLint positionAttrib_ = -1;
57     GLint texCoordAttrib_ = -1;
58     GLint textureUniform_ = -1;
59     GLuint textureId_ = 0;
60     GLuint textureTarget_ = 0;
61     float transformMatrix_[16] = { 0.0f };
62 };
63 
64 #endif // IMAGE_RENDER_H
65