1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_COMPANION_VIRTUALCAMERA_EGLDISPLAYCONTEXT_H 18 #define ANDROID_COMPANION_VIRTUALCAMERA_EGLDISPLAYCONTEXT_H 19 20 #include <memory> 21 22 #include "EGL/egl.h" 23 #include "system/window.h" 24 25 namespace android { 26 namespace companion { 27 namespace virtualcamera { 28 29 // Encapsulated EGLDisplay & EGLContext. 30 // 31 // Upon construction, this object will create and configure new 32 // EGLDisplay & EGLContext and will destroy them once it goes 33 // out of scope. 34 class EglDisplayContext { 35 public: 36 EglDisplayContext(std::shared_ptr<ANativeWindow> nativeWindow = nullptr); 37 ~EglDisplayContext(); 38 39 // Sets EGLDisplay & EGLContext for current thread. 40 // 41 // Returns true on success, false otherwise. 42 bool makeCurrent(); 43 44 EGLDisplay getEglDisplay() const; 45 46 // Returns true if this instance encapsulates successfully initialized 47 // EGLDisplay & EGLContext. 48 bool isInitialized() const; 49 50 void swapBuffers() const; 51 52 private: 53 std::shared_ptr<ANativeWindow> mNativeWindow; 54 55 EGLDisplay mEglDisplay; 56 EGLSurface mEglSurface; 57 EGLContext mEglContext; 58 EGLConfig mEglConfig; 59 }; 60 61 } // namespace virtualcamera 62 } // namespace companion 63 } // namespace android 64 65 #endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLDISPLAYCONTEXT_H 66