Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 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_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 | |
| 26 | namespace android { |
| 27 | |
| 28 | class IGraphicBufferProducer; |
| 29 | class IGraphicBufferConsumer; |
| 30 | class GLConsumer; |
| 31 | |
| 32 | namespace companion { |
| 33 | namespace virtualcamera { |
| 34 | |
| 35 | // Encapsulates GLConsumer & Surface for rendering into EGL texture. |
| 36 | class 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 | |
| 60 | private: |
| 61 | sp<IGraphicBufferProducer> mBufferProducer; |
| 62 | sp<IGraphicBufferConsumer> mBufferConsumer; |
| 63 | sp<GLConsumer> mGlConsumer; |
| 64 | sp<Surface> mSurface; |
| 65 | GLuint mTextureId; |
| 66 | const uint32_t mWidth; |
| 67 | const uint32_t mHeight; |
| 68 | }; |
| 69 | |
| 70 | } // namespace virtualcamera |
| 71 | } // namespace companion |
| 72 | } // namespace android |
| 73 | |
| 74 | #endif // ANDROID_COMPANION_VIRTUALCAMERA_EGLSURFACETEXTURE_H |