blob: 35f85e28070606168582e77f615a3f24f269eb1e [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_EGLFRAMEBUFFER_H
18#define ANDROID_COMPANION_VIRTUALCAMERA_EGLFRAMEBUFFER_H
19
20#define EGL_EGLEXT_PROTOTYPES
21#define GL_GLEXT_PROTOTYPES
22
23#include <memory>
24
25#include "EGL/egl.h"
26#include "EGL/eglext.h"
27#include "GLES/gl.h"
28
29namespace android {
30namespace companion {
31namespace virtualcamera {
32
33// Encapsulates EGL Framebuffer backed by AHardwareBuffer instance.
34//
35// Note that the framebuffer is tied to EGLDisplay connection.
36class EglFrameBuffer {
37 public:
38 EglFrameBuffer(EGLDisplay display, std::shared_ptr<AHardwareBuffer> hwBuffer);
39 virtual ~EglFrameBuffer();
40
41 // Prepare for rendering into the framebuffer.
42 bool beforeDraw();
43
44 // Finishes rendering into the framebuffer.
45 bool afterDraw();
46
47 // Return width of framebuffer (in pixels).
48 int getWidth() const;
49
50 // Return height of framebuffer (in pixels).
51 int getHeight() const;
52
53 private:
54 // Keeping shared_ptr to hardware buffer instance here prevents it from being
55 // freed while tied to EGL framebufer / EGL texture.
56 std::shared_ptr<AHardwareBuffer> mHardwareBuffer;
57 EGLDisplay mEglDisplay;
58 EGLImageKHR mEglImageKhr{EGL_NO_IMAGE_KHR};
59 GLuint mTextureId;
60 GLuint mFramebufferId;
61
62 int mWidth;
63 int mHeight;
64};
65
66} // namespace virtualcamera
67} // namespace companion
68} // namespace android
69
70#endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLFRAMEBUFFER_H