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