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 void CreateContext(int version); 74 private: EglManager()75 EglManager() : eglDisplay_(EGL_NO_DISPLAY), eglConfig_(nullptr), eglContext_(EGL_NO_CONTEXT), 76 currentSurface_(nullptr) {} 77 EglManager(const EglManager&) = delete; 78 EglManager& operator=(const EglManager&) = delete; 79 EGLDisplay eglDisplay_; 80 EGLConfig eglConfig_; 81 EGLContext eglContext_; 82 EGLSurface currentSurface_; 83 NativeWindow *eglWindow_ = nullptr; 84 bool initialized_ = false; 85 int32_t eglWidth_ = 0; 86 int32_t eglHeight_ = 0; 87 }; 88 } // namespace Rosen 89 } // namespace OHOS 90 #ifdef __cplusplus 91 } 92 #endif 93 #endif // WEBGL_EGL_MANAGER_H 94