Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be6e8dc3 authored by Huihong Luo's avatar Huihong Luo Committed by Android (Google) Code Review
Browse files

Merge "Use the new HWC api to handle hotplug event" into main

parents cd1eab2b 791bef99
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -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;
};
+5 −3
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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;
+8 −1
Original line number Diff line number Diff line
@@ -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();
    }

+21 −8
Original line number Diff line number Diff line
@@ -2101,8 +2101,12 @@ void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t t
    }
}

void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId,
                                          hal::Connection 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});
@@ -2111,6 +2115,15 @@ void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId,
        if (mScheduler) {
            mScheduler->scheduleConfigure();
        }

        return;
    }

    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));
    }
}

void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged(
@@ -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
Loading