blob: 6dc30807e7e7bb8ed4328fca54e37f3fbc9aaa14 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
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
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020020#include <memory>
21
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010022#include "EGL/egl.h"
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020023#include "system/window.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010024
25namespace android {
26namespace companion {
27namespace 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.
34class EglDisplayContext {
35 public:
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020036 EglDisplayContext(std::shared_ptr<ANativeWindow> nativeWindow = nullptr);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010037 ~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
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020050 void swapBuffers() const;
51
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010052 private:
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020053 std::shared_ptr<ANativeWindow> mNativeWindow;
54
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010055 EGLDisplay mEglDisplay;
Jan Sebechlebsky288900f2024-05-24 14:47:54 +020056 EGLSurface mEglSurface;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010057 EGLContext mEglContext;
58 EGLConfig mEglConfig;
59};
60
61} // namespace virtualcamera
62} // namespace companion
63} // namespace android
64
65#endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLDISPLAYCONTEXT_H