diff options
12 files changed, 66 insertions, 26 deletions
diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp index cc2f6c7cb3..369021995c 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp @@ -78,6 +78,7 @@ using AidlDisplayConnectionType = using AidlColorTransform = aidl::android::hardware::graphics::common::ColorTransform; using AidlDataspace = aidl::android::hardware::graphics::common::Dataspace; +using AidlDisplayHotplugEvent = aidl::android::hardware::graphics::common::DisplayHotplugEvent; using AidlFRect = aidl::android::hardware::graphics::common::FRect; using AidlRect = aidl::android::hardware::graphics::common::Rect; using AidlTransform = aidl::android::hardware::graphics::common::Transform; @@ -174,9 +175,9 @@ public: AidlIComposerCallbackWrapper(HWC2::ComposerCallback& callback) : mCallback(callback) {} ::ndk::ScopedAStatus onHotplug(int64_t in_display, bool in_connected) override { - const auto connection = in_connected ? V2_4::IComposerCallback::Connection::CONNECTED - : V2_4::IComposerCallback::Connection::DISCONNECTED; - mCallback.onComposerHalHotplug(translate<Display>(in_display), connection); + const auto event = in_connected ? AidlDisplayHotplugEvent::CONNECTED + : AidlDisplayHotplugEvent::DISCONNECTED; + mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event); return ::ndk::ScopedAStatus::ok(); } @@ -216,6 +217,12 @@ public: return ::ndk::ScopedAStatus::ok(); } + ::ndk::ScopedAStatus onHotplugEvent(int64_t in_display, + AidlDisplayHotplugEvent event) override { + mCallback.onComposerHalHotplugEvent(translate<Display>(in_display), event); + return ::ndk::ScopedAStatus::ok(); + } + private: HWC2::ComposerCallback& mCallback; }; diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index e7f807f553..29fe38008d 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -38,6 +38,7 @@ #include "Hal.h" #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> +#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> #include <aidl/android/hardware/graphics/composer3/Capability.h> #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h> #include <aidl/android/hardware/graphics/composer3/Color.h> @@ -64,15 +65,16 @@ class Layer; namespace hal = android::hardware::graphics::composer::hal; +using aidl::android::hardware::graphics::common::DisplayHotplugEvent; using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; // Implement this interface to receive hardware composer events. // // These callback functions will generally be called on a hwbinder thread, but -// when first registering the callback the onComposerHalHotplug() function will -// immediately be called on the thread calling registerCallback(). +// when first registering the callback the onComposerHalHotplugEvent() function +// will immediately be called on the thread calling registerCallback(). struct ComposerCallback { - virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0; + virtual void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) = 0; virtual void onComposerHalRefresh(hal::HWDisplayId) = 0; virtual void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp, std::optional<hal::VsyncPeriodNanos>) = 0; diff --git a/services/surfaceflinger/DisplayHardware/Hal.h b/services/surfaceflinger/DisplayHardware/Hal.h index 20f7548bea..31c2833229 100644 --- a/services/surfaceflinger/DisplayHardware/Hal.h +++ b/services/surfaceflinger/DisplayHardware/Hal.h @@ -20,6 +20,7 @@ #include <android/hardware/graphics/composer/2.4/IComposer.h> #include <android/hardware/graphics/composer/2.4/IComposerClient.h> +#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> #include <aidl/android/hardware/graphics/common/Hdr.h> #include <aidl/android/hardware/graphics/composer3/Composition.h> #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h> @@ -58,6 +59,7 @@ using Connection = IComposerCallback::Connection; using ContentType = IComposerClient::ContentType; using Capability = IComposer::Capability; using ClientTargetProperty = IComposerClient::ClientTargetProperty; +using DisplayHotplugEvent = aidl::android::hardware::graphics::common::DisplayHotplugEvent; using DisplayRequest = IComposerClient::DisplayRequest; using DisplayType = IComposerClient::DisplayType; using HWConfigId = V2_1::Config; diff --git a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp index 1e7c6da592..ed52b9583c 100644 --- a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp @@ -25,6 +25,7 @@ #include "HidlComposerHal.h" #include <SurfaceFlingerProperties.h> +#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> #include <android/binder_manager.h> #include <composer-command-buffer/2.2/ComposerCommandBuffer.h> #include <hidl/HidlTransportSupport.h> @@ -38,6 +39,7 @@ #include <algorithm> #include <cinttypes> +using aidl::android::hardware::graphics::common::DisplayHotplugEvent; using aidl::android::hardware::graphics::common::HdrConversionCapability; using aidl::android::hardware::graphics::common::HdrConversionStrategy; using aidl::android::hardware::graphics::composer3::Capability; @@ -64,8 +66,13 @@ public: ComposerCallbackBridge(ComposerCallback& callback, bool vsyncSwitchingSupported) : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {} + // For code sharing purposes, `ComposerCallback` (implemented by SurfaceFlinger) + // replaced `onComposerHalHotplug` with `onComposerHalHotplugEvent` by converting + // from HIDL's connection into an AIDL DisplayHotplugEvent. Return<void> onHotplug(Display display, Connection connection) override { - mCallback.onComposerHalHotplug(display, connection); + const auto event = connection == Connection::CONNECTED ? DisplayHotplugEvent::CONNECTED + : DisplayHotplugEvent::DISCONNECTED; + mCallback.onComposerHalHotplugEvent(display, event); return Void(); } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index bcad6acb71..85c16b716d 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2101,15 +2101,28 @@ void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t t } } -void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, - hal::Connection connection) { - { - std::lock_guard<std::mutex> lock(mHotplugMutex); - mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); +void SurfaceFlinger::onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, + DisplayHotplugEvent event) { + if (event == DisplayHotplugEvent::CONNECTED || event == DisplayHotplugEvent::DISCONNECTED) { + hal::Connection connection = (event == DisplayHotplugEvent::CONNECTED) + ? hal::Connection::CONNECTED + : hal::Connection::DISCONNECTED; + { + std::lock_guard<std::mutex> lock(mHotplugMutex); + mPendingHotplugEvents.push_back(HotplugEvent{hwcDisplayId, connection}); + } + + if (mScheduler) { + mScheduler->scheduleConfigure(); + } + + return; } - if (mScheduler) { - mScheduler->scheduleConfigure(); + if (FlagManager::getInstance().hotplug2()) { + ALOGD("SurfaceFlinger got hotplug event=%d", static_cast<int32_t>(event)); + // TODO(b/311403559): use enum type instead of int + mScheduler->onHotplugConnectionError(mAppConnectionHandle, static_cast<int32_t>(event)); } } @@ -7057,7 +7070,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r const hal::HWDisplayId hwcId = (Mutex::Autolock(mStateLock), getHwComposer().getPrimaryHwcDisplayId()); - onComposerHalHotplug(hwcId, hal::Connection::CONNECTED); + onComposerHalHotplugEvent(hwcId, DisplayHotplugEvent::CONNECTED); return NO_ERROR; } // Modify the max number of display frames stored within FrameTimeline diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index e90f8feb6e..788fe73519 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -106,6 +106,7 @@ #include <vector> #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h> +#include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h> #include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h> #include "Client.h" @@ -130,6 +131,7 @@ class FrameTracer; class ScreenCapturer; class WindowInfosListenerInvoker; +using ::aidl::android::hardware::graphics::common::DisplayHotplugEvent; using ::aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; using frontend::TransactionHandler; using gui::CaptureArgs; @@ -629,7 +631,7 @@ private: // HWC2::ComposerCallback overrides: void onComposerHalVsync(hal::HWDisplayId, nsecs_t timestamp, std::optional<hal::VsyncPeriodNanos>) override; - void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) override; + void onComposerHalHotplugEvent(hal::HWDisplayId, DisplayHotplugEvent) override; void onComposerHalRefresh(hal::HWDisplayId) override; void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&) override; diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer_utils.h index 1a951b34ac..b2dc20e216 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer_utils.h +++ b/services/surfaceflinger/fuzzer/surfaceflinger_displayhardware_fuzzer_utils.h @@ -41,6 +41,7 @@ class SurfaceComposerClient; namespace android::hardware::graphics::composer::hal { +using aidl::android::hardware::graphics::common::DisplayHotplugEvent; using aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; using ::android::hardware::Return; using ::android::hardware::Void; @@ -52,7 +53,9 @@ public: : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {} Return<void> onHotplug(HWDisplayId display, Connection connection) override { - mCallback->onComposerHalHotplug(display, connection); + const auto event = connection == Connection::CONNECTED ? DisplayHotplugEvent::CONNECTED + : DisplayHotplugEvent::DISCONNECTED; + mCallback->onComposerHalHotplugEvent(display, event); return Void(); } @@ -94,7 +97,7 @@ private: struct TestHWC2ComposerCallback : public HWC2::ComposerCallback { virtual ~TestHWC2ComposerCallback() = default; - void onComposerHalHotplug(HWDisplayId, Connection){}; + void onComposerHalHotplugEvent(HWDisplayId, DisplayHotplugEvent) {} void onComposerHalRefresh(HWDisplayId) {} void onComposerHalVsync(HWDisplayId, int64_t, std::optional<VsyncPeriodNanos>) {} void onComposerHalVsyncPeriodTimingChanged(HWDisplayId, const VsyncPeriodChangeTimeline&) {} diff --git a/services/surfaceflinger/tests/unittests/DisplayDevice_InitiateModeChange.cpp b/services/surfaceflinger/tests/unittests/DisplayDevice_InitiateModeChange.cpp index 3873b0c076..bd80d88392 100644 --- a/services/surfaceflinger/tests/unittests/DisplayDevice_InitiateModeChange.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayDevice_InitiateModeChange.cpp @@ -43,7 +43,8 @@ public: PrimaryDisplayVariant::setupNativeWindowSurfaceCreationCallExpectations(this); PrimaryDisplayVariant::setupHwcGetActiveConfigCallExpectations(this); - mFlinger.onComposerHalHotplug(PrimaryDisplayVariant::HWC_DISPLAY_ID, Connection::CONNECTED); + mFlinger.onComposerHalHotplugEvent(PrimaryDisplayVariant::HWC_DISPLAY_ID, + DisplayHotplugEvent::CONNECTED); mFlinger.configureAndCommit(); mDisplay = PrimaryDisplayVariant::makeFakeExistingDisplayInjector(this) diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp index 4a2273182e..d3ce4f2b90 100644 --- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp +++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp @@ -57,6 +57,7 @@ using namespace std::chrono_literals; using Hwc2::Config; +using ::aidl::android::hardware::graphics::common::DisplayHotplugEvent; using ::aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData; using hal::IComposerClient; using ::testing::_; @@ -555,7 +556,8 @@ TEST_F(HWComposerTest, notifyExpectedPresentRenderRateChanged) { } struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> { - MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection)); + MOCK_METHOD(void, onComposerHalHotplugEvent, (hal::HWDisplayId, DisplayHotplugEvent), + (override)); MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId)); MOCK_METHOD3(onComposerHalVsync, void(hal::HWDisplayId, int64_t timestamp, std::optional<hal::VsyncPeriodNanos>)); diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp index 3558ba6f09..01c0a966eb 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp @@ -46,7 +46,8 @@ public: setupScheduler(selectorPtr); - mFlinger.onComposerHalHotplug(PrimaryDisplayVariant::HWC_DISPLAY_ID, Connection::CONNECTED); + mFlinger.onComposerHalHotplugEvent(PrimaryDisplayVariant::HWC_DISPLAY_ID, + DisplayHotplugEvent::CONNECTED); mFlinger.configureAndCommit(); auto vsyncController = std::make_unique<mock::VsyncController>(); diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp index 1210d0b472..a270dc91f2 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp @@ -27,10 +27,10 @@ TEST_F(HotplugTest, schedulesConfigureToProcessHotplugEvents) { EXPECT_CALL(*mFlinger.scheduler(), scheduleConfigure()).Times(2); constexpr HWDisplayId hwcDisplayId1 = 456; - mFlinger.onComposerHalHotplug(hwcDisplayId1, Connection::CONNECTED); + mFlinger.onComposerHalHotplugEvent(hwcDisplayId1, DisplayHotplugEvent::CONNECTED); constexpr HWDisplayId hwcDisplayId2 = 654; - mFlinger.onComposerHalHotplug(hwcDisplayId2, Connection::DISCONNECTED); + mFlinger.onComposerHalHotplugEvent(hwcDisplayId2, DisplayHotplugEvent::DISCONNECTED); const auto& pendingEvents = mFlinger.mutablePendingHotplugEvents(); ASSERT_EQ(2u, pendingEvents.size()); @@ -45,7 +45,7 @@ TEST_F(HotplugTest, schedulesFrameToCommitDisplayTransaction) { EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); constexpr HWDisplayId displayId1 = 456; - mFlinger.onComposerHalHotplug(displayId1, Connection::DISCONNECTED); + mFlinger.onComposerHalHotplugEvent(displayId1, DisplayHotplugEvent::DISCONNECTED); mFlinger.configure(); // The configure stage should consume the hotplug queue and produce a display transaction. diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index cf48c76a5b..0909178777 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -466,8 +466,8 @@ public: mFlinger->commitTransactionsLocked(transactionFlags); } - void onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, hal::Connection connection) { - mFlinger->onComposerHalHotplug(hwcDisplayId, connection); + void onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, DisplayHotplugEvent event) { + mFlinger->onComposerHalHotplugEvent(hwcDisplayId, event); } auto setDisplayStateLocked(const DisplayState& s) { |