From 130d5a3aa0cc0810075c0e87c3196fb8f34d4dd6 Mon Sep 17 00:00:00 2001 From: Changyeon Jo Date: Tue, 29 Aug 2023 14:55:03 -0700 Subject: [PATCH] Update the default EVS HAL implementation Remove H2BGraphicBufferProducer usages from the default EVS HAL implementation. Bug: 297601247 Bug: 298091684 Test: Run evs_app on the cuttlefish emulator. Change-Id: Ibca21d8e9cf87deb79c0050f9adcf02b5f16d34b --- automotive/evs/aidl/impl/default/Android.bp | 5 ++- .../aidl/impl/default/include/EvsEnumerator.h | 1 + .../aidl/impl/default/include/EvsGlDisplay.h | 1 + .../evs/aidl/impl/default/include/GlWrapper.h | 9 +--- .../aidl/impl/default/src/EvsGlDisplay.cpp | 2 +- .../evs/aidl/impl/default/src/GlWrapper.cpp | 43 ++++++------------- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/automotive/evs/aidl/impl/default/Android.bp b/automotive/evs/aidl/impl/default/Android.bp index 70c523b5fa..79ee956641 100644 --- a/automotive/evs/aidl/impl/default/Android.bp +++ b/automotive/evs/aidl/impl/default/Android.bp @@ -60,12 +60,15 @@ cc_binary { "libyuv", ], static_libs: [ - "android.frameworks.automotive.display-V1-ndk", + "android.frameworks.automotive.display-V2-ndk", "android.hardware.automotive.evs-V2-ndk", "android.hardware.common-V2-ndk", "libaidlcommonsupport", "libcutils", ], + header_libs: [ + "libgui_aidl_headers", + ], local_include_dirs: ["include"], include_dirs: ["frameworks/native/include/"], required: ["evs_mock_hal_configuration.xml"], diff --git a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h index 259c266721..3897b4e7c6 100644 --- a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h +++ b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/automotive/evs/aidl/impl/default/include/EvsGlDisplay.h b/automotive/evs/aidl/impl/default/include/EvsGlDisplay.h index ceabd9e863..0865a04109 100644 --- a/automotive/evs/aidl/impl/default/include/EvsGlDisplay.h +++ b/automotive/evs/aidl/impl/default/include/EvsGlDisplay.h @@ -23,6 +23,7 @@ #include #include #include +#include #include diff --git a/automotive/evs/aidl/impl/default/include/GlWrapper.h b/automotive/evs/aidl/impl/default/include/GlWrapper.h index adb250c8e1..7ff6104bb9 100644 --- a/automotive/evs/aidl/impl/default/include/GlWrapper.h +++ b/automotive/evs/aidl/impl/default/include/GlWrapper.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace aidl::android::hardware::automotive::evs::implementation { @@ -33,7 +33,6 @@ namespace automotivedisplay = ::aidl::android::frameworks::automotive::display; class GlWrapper { public: - GlWrapper() : mSurfaceHolder(::android::SurfaceHolderUniquePtr(nullptr, nullptr)) {} bool initialize(const std::shared_ptr& svc, uint64_t displayId); void shutdown(); @@ -53,9 +52,6 @@ class GlWrapper { unsigned getHeight() { return mHeight; }; private: - ::android::sp<::android::hardware::graphics::bufferqueue::V2_0::IGraphicBufferProducer> - mGfxBufferProducer; - EGLDisplay mDisplay; EGLSurface mSurface; EGLContext mContext; @@ -71,9 +67,6 @@ class GlWrapper { // Opaque handle for a native hardware buffer defined in // frameworks/native/opengl/include/EGL/eglplatform.h ANativeWindow* mWindow; - - // Pointer to a Surface wrapper. - ::android::SurfaceHolderUniquePtr mSurfaceHolder; }; } // namespace aidl::android::hardware::automotive::evs::implementation diff --git a/automotive/evs/aidl/impl/default/src/EvsGlDisplay.cpp b/automotive/evs/aidl/impl/default/src/EvsGlDisplay.cpp index e5f8e4c84a..5b5cbcc9ae 100644 --- a/automotive/evs/aidl/impl/default/src/EvsGlDisplay.cpp +++ b/automotive/evs/aidl/impl/default/src/EvsGlDisplay.cpp @@ -352,8 +352,8 @@ ScopedAStatus EvsGlDisplay::getTargetBuffer(BufferDesc* _aidl_return) { BufferDesc bufferDescToSend = { .buffer = { - .handle = std::move(::android::dupToAidl(mBuffer.handle)), .description = mBuffer.description, + .handle = std::move(::android::dupToAidl(mBuffer.handle)), }, .pixelSizeBytes = 4, // RGBA_8888 is 4-byte-per-pixel format .bufferId = mBuffer.fingerprint, diff --git a/automotive/evs/aidl/impl/default/src/GlWrapper.cpp b/automotive/evs/aidl/impl/default/src/GlWrapper.cpp index 0ee5ecb734..a9d02138b2 100644 --- a/automotive/evs/aidl/impl/default/src/GlWrapper.cpp +++ b/automotive/evs/aidl/impl/default/src/GlWrapper.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -183,20 +184,6 @@ GLuint buildShaderProgram(const char* vtxSrc, const char* pxlSrc) { return program; } -::android::sp convertNativeHandleToHGBP(const NativeHandle& aidlHandle) { - native_handle_t* handle = ::android::dupFromAidl(aidlHandle); - if (handle->numFds != 0 || handle->numInts < std::ceil(sizeof(size_t) / sizeof(int))) { - LOG(ERROR) << "Invalid native handle"; - return nullptr; - } - ::android::hardware::hidl_vec halToken; - halToken.setToExternal(reinterpret_cast(const_cast(&(handle->data[1]))), - handle->data[0]); - ::android::sp hgbp = - HGraphicBufferProducer::castFrom(::android::retrieveHalInterface(halToken)); - return std::move(hgbp); -} - } // namespace namespace aidl::android::hardware::automotive::evs::implementation { @@ -226,30 +213,19 @@ bool GlWrapper::initialize(const std::shared_ptr& pWindowProxy } LOG(INFO) << "Display resolution is " << mWidth << "x" << mHeight; - NativeHandle aidlHandle; - status = pWindowProxy->getHGraphicBufferProducer(displayId, &aidlHandle); + aidl::android::view::Surface shimSurface; + status = pWindowProxy->getSurface(displayId, &shimSurface); if (!status.isOk()) { - LOG(ERROR) << "Failed to get IGraphicBufferProducer from ICarDisplayProxy."; + LOG(ERROR) << "Failed to obtain the surface."; return false; } - mGfxBufferProducer = convertNativeHandleToHGBP(aidlHandle); - if (!mGfxBufferProducer) { - LOG(ERROR) << "Failed to convert a NativeHandle to HGBP."; - return false; - } - - mSurfaceHolder = getSurfaceFromHGBP(mGfxBufferProducer); - if (mSurfaceHolder == nullptr) { - LOG(ERROR) << "Failed to get a Surface from HGBP."; - return false; - } - - mWindow = getNativeWindow(mSurfaceHolder.get()); + mWindow = shimSurface.get(); if (mWindow == nullptr) { LOG(ERROR) << "Failed to get a native window from Surface."; return false; } + ANativeWindow_acquire(mWindow); // Set up our OpenGL ES context associated with the default display mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); @@ -350,7 +326,12 @@ void GlWrapper::shutdown() { mDisplay = EGL_NO_DISPLAY; // Release the window - mSurfaceHolder = nullptr; + if (mWindow == nullptr) { + return; + } + + ANativeWindow_release(mWindow); + mWindow = nullptr; } void GlWrapper::showWindow(const std::shared_ptr& pWindowProxy, uint64_t id) {