Changyeon Jo | 33ba66b | 2022-01-16 16:33:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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_HARDWARE_AUTOMOTIVE_EVS_V1_1_DISPLAY_GLWRAPPER_H |
| 18 | #define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_DISPLAY_GLWRAPPER_H |
| 19 | |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h> |
| 22 | #include <android/hardware/automotive/evs/1.1/types.h> |
| 23 | #include <bufferqueueconverter/BufferQueueConverter.h> |
| 24 | |
| 25 | #include <EGL/egl.h> |
| 26 | #include <EGL/eglext.h> |
| 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
| 29 | #include <GLES3/gl3.h> |
| 30 | #include <GLES3/gl3ext.h> |
| 31 | |
| 32 | namespace android::hardware::automotive::evs::V1_1::implementation { |
| 33 | |
| 34 | using frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService; |
| 35 | using hardware::graphics::bufferqueue::V2_0::IGraphicBufferProducer; |
| 36 | |
| 37 | class GlWrapper { |
| 38 | public: |
| 39 | GlWrapper() : mSurfaceHolder(android::SurfaceHolderUniquePtr(nullptr, nullptr)) {} |
| 40 | bool initialize(const sp<IAutomotiveDisplayProxyService>& service, uint64_t displayId); |
| 41 | void shutdown(); |
| 42 | |
| 43 | bool updateImageTexture(const V1_0::BufferDesc& buffer); |
| 44 | bool updateImageTexture(const BufferDesc& buffer); |
| 45 | void renderImageToScreen(); |
| 46 | |
| 47 | void showWindow(sp<IAutomotiveDisplayProxyService>& service, uint64_t id); |
| 48 | void hideWindow(sp<IAutomotiveDisplayProxyService>& service, uint64_t id); |
| 49 | |
| 50 | unsigned getWidth() { return mWidth; }; |
| 51 | unsigned getHeight() { return mHeight; }; |
| 52 | |
| 53 | private: |
| 54 | sp<IGraphicBufferProducer> mGfxBufferProducer; |
| 55 | |
| 56 | EGLDisplay mDisplay; |
| 57 | EGLSurface mSurface; |
| 58 | EGLContext mContext; |
| 59 | |
| 60 | unsigned mWidth = 0; |
| 61 | unsigned mHeight = 0; |
| 62 | |
| 63 | EGLImageKHR mKHRimage = EGL_NO_IMAGE_KHR; |
| 64 | |
| 65 | GLuint mTextureMap = 0; |
| 66 | GLuint mShaderProgram = 0; |
| 67 | |
| 68 | // Opaque handle for a native hardware buffer defined in |
| 69 | // frameworks/native/opengl/include/EGL/eglplatform.h |
| 70 | ANativeWindow* mWindow; |
| 71 | |
| 72 | // Pointer to a Surface wrapper. |
| 73 | android::SurfaceHolderUniquePtr mSurfaceHolder; |
| 74 | }; |
| 75 | |
| 76 | } // namespace android::hardware::automotive::evs::V1_1::implementation |
| 77 | |
| 78 | #endif // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_DISPLAY_GLWRAPPER_H |