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 CPP_EVS_SAMPLEDRIVER_AIDL_INCLUDE_GLWRAPPER_H 18 #define CPP_EVS_SAMPLEDRIVER_AIDL_INCLUDE_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 #include <aidl/android/frameworks/automotive/display/ICarDisplayProxy.h> 27 #include <aidl/android/hardware/automotive/evs/BufferDesc.h> 28 #include <android-base/logging.h> 29 #include <android-base/thread_annotations.h> 30 #include <cutils/native_handle.h> 31 32 namespace aidl::android::hardware::automotive::evs::implementation { 33 34 namespace automotivedisplay = ::aidl::android::frameworks::automotive::display; 35 36 class GlWrapper { 37 public: 38 GlWrapper() = default; 39 bool initialize(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 40 uint64_t displayId); 41 void shutdown(); 42 43 bool updateImageTexture( 44 buffer_handle_t handle, 45 const ::aidl::android::hardware::graphics::common::HardwareBufferDescription& 46 description); 47 void renderImageToScreen(); 48 49 void showWindow(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 50 uint64_t displayId); 51 void hideWindow(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 52 uint64_t displayId); 53 getWidth()54 unsigned getWidth() { return mWidth; }; getHeight()55 unsigned getHeight() { return mHeight; }; 56 57 private: 58 EGLDisplay mDisplay; 59 EGLSurface mSurface; 60 EGLContext mContext; 61 62 unsigned mWidth = 0; 63 unsigned mHeight = 0; 64 65 EGLImageKHR mKHRimage = EGL_NO_IMAGE_KHR; 66 67 GLuint mTextureMap = 0; 68 GLuint mShaderProgram = 0; 69 70 // Opaque handle for a native hardware buffer defined in 71 // frameworks/native/opengl/include/EGL/eglplatform.h 72 ANativeWindow* mWindow; 73 }; 74 75 } // namespace aidl::android::hardware::automotive::evs::implementation 76 77 #endif // CPP_EVS_SAMPLEDRIVER_AIDL_INCLUDE_GLWRAPPER_H 78