• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 WEBGL_EGL_MANAGER_H
17 #define WEBGL_EGL_MANAGER_H
18 
19 #include <GLES2/gl2.h>
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 namespace OHOS {
28 namespace Rosen {
29 class EglManager {
30 public:
GetInstance()31     static EglManager& GetInstance()
32     {
33         static EglManager manager;
34         return manager;
35     }
36 
~EglManager()37     ~EglManager() {}
38 
SetCurrentSurface(EGLSurface eglSurface)39     void SetCurrentSurface(EGLSurface eglSurface)
40     {
41         currentSurface_ = eglSurface;
42     }
43 
SetPbufferAttributes(int eglWidth,int eglHeight)44     void SetPbufferAttributes(int eglWidth, int eglHeight)
45     {
46         eglWidth_ = eglWidth;
47         eglHeight_ = eglHeight;
48     }
49 
GetCurrentSurface()50     EGLSurface GetCurrentSurface() const
51     {
52         return currentSurface_;
53     }
54 
GetEGLDisplay()55     EGLDisplay GetEGLDisplay() const
56     {
57         return eglDisplay_;
58     }
59 
GetEGLContext()60     EGLContext GetEGLContext() const
61     {
62         return eglContext_;
63     }
64 
65     EGLConfig GetConfig(int version, EGLDisplay eglDisplay);
66 
67     void MakeCurrentIfNeeded(EGLSurface newEGLSurface);
68 
69     void Init();
70 
71     EGLSurface CreateSurface(NativeWindow* window);
72 
73 private:
EglManager()74     EglManager() : eglDisplay_(EGL_NO_DISPLAY), eglConfig_(nullptr), eglContext_(EGL_NO_CONTEXT),
75         currentSurface_(nullptr) {}
76     EglManager(const EglManager&) = delete;
77     EglManager& operator=(const EglManager&) = delete;
78     EGLDisplay eglDisplay_;
79     EGLConfig eglConfig_;
80     EGLContext eglContext_;
81     EGLSurface currentSurface_;
82     NativeWindow *eglWindow_ = nullptr;
83     bool initialized_ = false;
84     int32_t eglWidth_ = 0;
85     int32_t eglHeight_ = 0;
86 };
87 } // namespace Rosen
88 } // namespace OHOS
89 #ifdef __cplusplus
90 }
91 #endif
92 #endif // WEBGL_EGL_MANAGER_H
93