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

Commit 17029d81 authored by Gil Dekel's avatar Gil Dekel
Browse files

SF: Cache display port in physical DisplaySnapshot

In order to be able to remove direct dependencies on a DisplayId's int
value, we have to find alternatives for the API it provides. One such
piece of data is a display port, which is encoded directly in the ID int
value.

Cache the port as it is retrieved from HWC into DisplaySnapshot when
they are updated or created so it can be served later via alternative
ISurfaceComposer APIs.

Bug: 374163881
Bug: 377307639
Flag: EXEMPT refactor
Test: libsurfaceflinger_unittest
Change-Id: I7a7e38695ca6065238644457986f12dcce4b59d0
parent ffca0ade
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -26,11 +26,12 @@

namespace android::display {

DisplaySnapshot::DisplaySnapshot(PhysicalDisplayId displayId,
DisplaySnapshot::DisplaySnapshot(PhysicalDisplayId displayId, uint8_t port,
                                 ui::DisplayConnectionType connectionType,
                                 DisplayModes&& displayModes, ui::ColorModes&& colorModes,
                                 std::optional<DeviceProductInfo>&& deviceProductInfo)
      : mDisplayId(displayId),
        mPort(port),
        mConnectionType(connectionType),
        mDisplayModes(std::move(displayModes)),
        mColorModes(std::move(colorModes)),
@@ -62,6 +63,8 @@ ui::ColorModes DisplaySnapshot::filterColorModes(bool supportsWideColor) const {
void DisplaySnapshot::dump(utils::Dumper& dumper) const {
    using namespace std::string_view_literals;

    dumper.dump("port"sv, mPort);

    dumper.dump("connectionType"sv, ftl::enum_string(mConnectionType));

    dumper.dump("colorModes"sv);
+5 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <cstdint>
#include <optional>

#include <ui/ColorMode.h>
@@ -30,13 +31,14 @@ namespace android::display {
// Immutable state of a physical display, captured on hotplug.
class DisplaySnapshot {
public:
    DisplaySnapshot(PhysicalDisplayId, ui::DisplayConnectionType, DisplayModes&&, ui::ColorModes&&,
                    std::optional<DeviceProductInfo>&&);
    DisplaySnapshot(PhysicalDisplayId, uint8_t, ui::DisplayConnectionType, DisplayModes&&,
                    ui::ColorModes&&, std::optional<DeviceProductInfo>&&);

    DisplaySnapshot(const DisplaySnapshot&) = delete;
    DisplaySnapshot(DisplaySnapshot&&) = default;

    PhysicalDisplayId displayId() const { return mDisplayId; }
    uint8_t port() const { return mPort; }
    ui::DisplayConnectionType connectionType() const { return mConnectionType; }

    std::optional<DisplayModeId> translateModeId(hal::HWConfigId) const;
@@ -51,6 +53,7 @@ public:

private:
    const PhysicalDisplayId mDisplayId;
    const uint8_t mPort;
    const ui::DisplayConnectionType mConnectionType;

    // Effectively const except in move constructor.
+6 −3
Original line number Diff line number Diff line
@@ -3631,10 +3631,13 @@ std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDispl
            deviceProductInfo = snapshot.deviceProductInfo();
        }

        // Use the cached port via snapshot because we are updating an existing
        // display on reconnect.
        const auto it =
                mPhysicalDisplays.try_replace(displayId, display.token(), displayId,
                                              snapshot.connectionType(), std::move(displayModes),
                                              std::move(colorModes), std::move(deviceProductInfo));
                                              snapshot.port(), snapshot.connectionType(),
                                              std::move(displayModes), std::move(colorModes),
                                              std::move(deviceProductInfo));

        auto& state = mCurrentState.displays.editValueFor(it->second.token());
        state.sequenceId = DisplayDeviceState{}.sequenceId; // Generate new sequenceId.
@@ -3647,7 +3650,7 @@ std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(PhysicalDispl
    const ui::DisplayConnectionType connectionType =
            getHwComposer().getDisplayConnectionType(displayId);

    mPhysicalDisplays.try_emplace(displayId, token, displayId, connectionType,
    mPhysicalDisplays.try_emplace(displayId, token, displayId, info.port, connectionType,
                                  std::move(displayModes), std::move(colorModes),
                                  std::move(info.deviceProductInfo));

+5 −3
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ struct CommitAndCompositeTest : testing::Test {
                compositionengine::impl::createDisplay(mFlinger.getCompositionEngine(),
                                                       std::move(compostionEngineDisplayArgs));
        mDisplay = FakeDisplayDeviceInjector(mFlinger, compositionDisplay,
                                             ui::DisplayConnectionType::Internal, HWC_DISPLAY,
                                             kIsPrimary)
                                             ui::DisplayConnectionType::Internal,
                                             DEFAULT_DISPLAY_PORT, HWC_DISPLAY, kIsPrimary)
                           .setDisplaySurface(mDisplaySurface)
                           .setNativeWindow(mNativeWindow)
                           .setPowerMode(hal::PowerMode::ON)
@@ -68,7 +68,9 @@ struct CommitAndCompositeTest : testing::Test {
    using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector;

    static constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID;
    static constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
    static constexpr uint8_t DEFAULT_DISPLAY_PORT = 42u;
    static constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID =
            PhysicalDisplayId::fromPort(DEFAULT_DISPLAY_PORT);
    static constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
    static constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;

+4 −2
Original line number Diff line number Diff line
@@ -76,7 +76,8 @@ constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DIS
constexpr hal::HWLayerId HWC_LAYER = 5000;
constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0);

constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
constexpr uint8_t DEFAULT_DISPLAY_PORT = 42u;
constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(DEFAULT_DISPLAY_PORT);
constexpr int DEFAULT_DISPLAY_WIDTH = 1920;
constexpr int DEFAULT_DISPLAY_HEIGHT = 1024;

@@ -276,7 +277,8 @@ struct BaseDisplayVariant {

        test->mDisplay =
                FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
                                          kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
                                          kDisplayConnectionType, DEFAULT_DISPLAY_PORT, HWC_DISPLAY,
                                          kIsPrimary)
                        .setDisplaySurface(test->mDisplaySurface)
                        .setNativeWindow(test->mNativeWindow)
                        .setSecure(Derived::IS_SECURE)
Loading