blob: faad7c414ba19ddb34f39fa1c9061f06c02ccb1a [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_EGLSURFACETEXTURE_H
18#define ANDROID_COMPANION_VIRTUALCAMERA_EGLSURFACETEXTURE_H
19
20#include <cstdint>
21
22#include "GLES/gl.h"
23#include "gui/Surface.h"
24#include "utils/RefBase.h"
25
26namespace android {
27
28class IGraphicBufferProducer;
29class IGraphicBufferConsumer;
30class GLConsumer;
31
32namespace companion {
33namespace virtualcamera {
34
35// Encapsulates GLConsumer & Surface for rendering into EGL texture.
36class EglSurfaceTexture {
37 public:
38 // Create new EGL Texture with specified size.
39 EglSurfaceTexture(uint32_t width, uint32_t height);
40 ~EglSurfaceTexture();
41
42 // Get Surface backing up the texture.
43 sp<Surface> getSurface();
44
45 // Get GraphicBuffer backing the current texture.
46 sp<GraphicBuffer> getCurrentBuffer();
47
48 // Get width of surface / texture.
49 uint32_t getWidth() const;
50
51 // Get height of surface / texture.
52 uint32_t getHeight() const;
53
54 // Update the texture with the most recent submitted buffer.
55 // Most be called on thread with EGL context.
56 //
57 // Returns EGL texture id of the texture.
58 GLuint updateTexture();
59
Jan Sebechlebsky99492e32023-12-20 09:49:45 +010060 // Returns EGL texture id of the underlying texture.
61 GLuint getTextureId() const;
62
63 // Returns 4x4 transformation matrix in column-major order,
64 // which should be applied to EGL texture coordinates
65 // before sampling from the texture backed by android native buffer,
66 // so the corresponding region of the underlying buffer is sampled.
67 //
68 // See SurfaceTexture.getTransformMatrix for more details.
69 std::array<float, 16> getTransformMatrix();
70
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010071 private:
72 sp<IGraphicBufferProducer> mBufferProducer;
73 sp<IGraphicBufferConsumer> mBufferConsumer;
74 sp<GLConsumer> mGlConsumer;
75 sp<Surface> mSurface;
76 GLuint mTextureId;
77 const uint32_t mWidth;
78 const uint32_t mHeight;
79};
80
81} // namespace virtualcamera
82} // namespace companion
83} // namespace android
84
85#endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLSURFACETEXTURE_H