1 /* 2 * Copyright (c) 2022 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 EGL_MANAGER_H 17 #define EGL_MANAGER_H 18 19 #include <GLES3/gl32.h> 20 #include <EGL/egl.h> 21 #include <EGL/eglext.h> 22 #include "ec_log.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 namespace OHOS { 29 namespace Rosen { 30 class EglManager { 31 public: 32 static constexpr int EGL_SUPPORT_VERSION = 3; 33 static constexpr int EGL_LIMIT_VERSION = 4; GetInstance()34 static EglManager& GetInstance() 35 { 36 static EglManager manager; 37 return manager; 38 } 39 ~EglManager()40 ~EglManager() 41 { 42 Deinit(); 43 } 44 EGLConfig GetConfig(int version, EGLDisplay eglDisplay); 45 EGLBoolean Init(); 46 EGLBoolean IsEGLContextInCurrentThread(EGLDisplay display, EGLContext context); 47 48 private: 49 EglManager()50 EglManager() : EGLDisplay_(EGL_NO_DISPLAY), EGLConfig_(nullptr), EGLContext_(EGL_NO_CONTEXT), 51 currentSurface_(nullptr) {} 52 EglManager(const EglManager&) = delete; 53 EglManager& operator=(const EglManager&) = delete; 54 void Deinit(); 55 bool RetryEGLContext(); 56 bool InitializeEGLDisplay(); 57 bool CreateEGLSurface(); 58 bool CreateAndSetEGLContext(); 59 60 EGLDisplay EGLDisplay_; 61 EGLConfig EGLConfig_; 62 EGLContext EGLContext_; 63 EGLSurface currentSurface_; 64 #ifndef ANDROID_PLATFORM 65 NativeWindow *EGLWindow_ = nullptr; 66 #endif 67 bool initialized_ = false; 68 int EGLWidth_ = 0; 69 int EGLHeight_ = 0; 70 }; 71 } // namespace Rosen 72 } // namespace OHOS 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #endif // EGL_MANAGER_H 79