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

Commit 76e6d585 authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Android (Google) Code Review
Browse files

Merge "SF: Split processHotplug" into main

parents fe156ba7 bb8267b6
Loading
Loading
Loading
Loading
+40 −32
Original line number Diff line number Diff line
@@ -3516,49 +3516,40 @@ bool SurfaceFlinger::configureLocked() {
    for (const auto [hwcDisplayId, connection] : events) {
        if (auto info = getHwComposer().onHotplug(hwcDisplayId, connection)) {
            const auto displayId = info->id;
            const bool connected = connection == hal::Connection::CONNECTED;
            const ftl::Concat displayString("display ", displayId.value, "(HAL ID ", hwcDisplayId,
                                            ')');

            if (const char* const log =
                        processHotplug(displayId, hwcDisplayId, connected, std::move(*info))) {
                ALOGI("%s display %s (HAL ID %" PRIu64 ")", log, to_string(displayId).c_str(),
                      hwcDisplayId);
            if (connection == hal::Connection::CONNECTED) {
                if (!processHotplugConnect(displayId, hwcDisplayId, std::move(*info),
                                           displayString.c_str())) {
                    if (FlagManager::getInstance().hotplug2()) {
                        mScheduler->dispatchHotplugError(
                                static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN));
                    }
                    getHwComposer().disconnectDisplay(displayId);
                }
            } else {
                processHotplugDisconnect(displayId, displayString.c_str());
            }

    return !events.empty();
        }

const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId,
                                           hal::HWDisplayId hwcDisplayId, bool connected,
                                           DisplayIdentificationInfo&& info) {
    const auto displayOpt = mPhysicalDisplays.get(displayId);
    if (!connected) {
        LOG_ALWAYS_FATAL_IF(!displayOpt);
        const auto& display = displayOpt->get();

        if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) {
            mCurrentState.displays.removeItemsAt(index);
    }

        mPhysicalDisplays.erase(displayId);
        return "Disconnecting";
    return !events.empty();
}

bool SurfaceFlinger::processHotplugConnect(PhysicalDisplayId displayId,
                                           hal::HWDisplayId hwcDisplayId,
                                           DisplayIdentificationInfo&& info,
                                           const char* displayString) {
    auto [displayModes, activeMode] = loadDisplayModes(displayId);
    if (!activeMode) {
        ALOGE("Failed to hotplug display %s", to_string(displayId).c_str());
        if (FlagManager::getInstance().hotplug2()) {
            mScheduler->dispatchHotplugError(
                    static_cast<int32_t>(DisplayHotplugEvent::ERROR_UNKNOWN));
        }
        getHwComposer().disconnectDisplay(displayId);
        return nullptr;
        ALOGE("Failed to hotplug %s", displayString);
        return false;
    }

    ui::ColorModes colorModes = getHwComposer().getColorModes(displayId);

    if (displayOpt) {
    if (const auto displayOpt = mPhysicalDisplays.get(displayId)) {
        const auto& display = displayOpt->get();
        const auto& snapshot = display.snapshot();

@@ -3577,7 +3568,8 @@ const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId,
        auto& state = mCurrentState.displays.editValueFor(it->second.token());
        state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId.
        state.physical->activeMode = std::move(activeMode);
        return "Reconnecting";
        ALOGI("Reconnecting %s", displayString);
        return true;
    }

    const sp<IBinder> token = sp<BBinder>::make();
@@ -3597,7 +3589,23 @@ const char* SurfaceFlinger::processHotplug(PhysicalDisplayId displayId,
    state.displayName = std::move(info.name);

    mCurrentState.displays.add(token, state);
    return "Connecting";
    ALOGI("Connecting %s", displayString);
    return true;
}

void SurfaceFlinger::processHotplugDisconnect(PhysicalDisplayId displayId,
                                              const char* displayString) {
    ALOGI("Disconnecting %s", displayString);

    const auto displayOpt = mPhysicalDisplays.get(displayId);
    LOG_ALWAYS_FATAL_IF(!displayOpt);
    const auto& display = displayOpt->get();

    if (const ssize_t index = mCurrentState.displays.indexOfKey(display.token()); index >= 0) {
        mCurrentState.displays.removeItemsAt(index);
    }

    mPhysicalDisplays.erase(displayId);
}

void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId,
+5 −4
Original line number Diff line number Diff line
@@ -1059,10 +1059,11 @@ private:
    bool configureLocked() REQUIRES(mStateLock) REQUIRES(kMainThreadContext)
            EXCLUDES(mHotplugMutex);

    // Returns a string describing the hotplug, or nullptr if it was rejected.
    const char* processHotplug(PhysicalDisplayId, hal::HWDisplayId, bool connected,
                               DisplayIdentificationInfo&&) REQUIRES(mStateLock)
            REQUIRES(kMainThreadContext);
    // Returns false on hotplug failure.
    bool processHotplugConnect(PhysicalDisplayId, hal::HWDisplayId, DisplayIdentificationInfo&&,
                               const char* displayString) REQUIRES(mStateLock, kMainThreadContext);
    void processHotplugDisconnect(PhysicalDisplayId, const char* displayString)
            REQUIRES(mStateLock, kMainThreadContext);

    sp<DisplayDevice> setupNewDisplayDeviceInternal(
            const wp<IBinder>& displayToken,