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 ROSENRENDER_ROSEN_WEBGL_EGL_MANAGER 17 #define ROSENRENDER_ROSEN_WEBGL_EGL_MANAGER 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 mCurrentSurface = eglSurface; 42 } 43 SetPbufferAttributes(int eglWidth,int eglHeight)44 void SetPbufferAttributes(int eglWidth, int eglHeight) 45 { 46 mEglWidth = eglWidth; 47 mEglHeight = eglHeight; 48 } 49 GetCurrentSurface()50 EGLSurface GetCurrentSurface() const 51 { 52 return mCurrentSurface; 53 } 54 GetEGLDisplay()55 EGLDisplay GetEGLDisplay() const 56 { 57 return mEGLDisplay; 58 } 59 GetEGLContext()60 EGLContext GetEGLContext() const 61 { 62 return mEGLContext; 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() : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT), 75 mCurrentSurface(nullptr) {} 76 EglManager(const EglManager&) = delete; 77 EglManager& operator=(const EglManager&) = delete; 78 EGLDisplay mEGLDisplay; 79 EGLConfig mEGLConfig; 80 EGLContext mEGLContext; 81 EGLSurface mCurrentSurface; 82 NativeWindow *mEglWindow = nullptr; 83 bool initialized = false; 84 int mEglWidth = 0; 85 int mEglHeight = 0; 86 }; 87 } // namespace Rosen 88 } // namespace OHOS 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 #endif // ROSENRENDER_ROSEN_WEBGL_EGL_MANAGER 95