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

Commit afa7afa4 authored by Gil Dekel's avatar Gil Dekel Committed by Android (Google) Code Review
Browse files

Merge changes I63ed72a2,Ie678616d into main

* changes:
  SF: Physical Display ID duplication avoidance
  SF testing: Use BOOL_SUBSTITUTE instead of bools
parents 1e88a722 d3b08a78
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -3817,6 +3817,13 @@ std::optional<DisplayModeId> SurfaceFlinger::processHotplugConnect(
        PhysicalDisplayId displayId, hal::HWDisplayId hwcDisplayId,
        display::DisplayIdentificationInfo&& info, const char* displayString,
        HWComposer::HotplugEvent event) {
    if (FlagManager::getInstance().stable_edid_ids() &&
        info.hotplugStatus == display::HotplugStatus::Connected && hasDisplayWithId(displayId)) {
        ALOGE("Display with HAL ID %" PRIu64 " produced a duplicate display ID %" PRIu64 ".",
              hwcDisplayId, displayId.value);
        return std::nullopt;
    }

    auto [displayModes, activeMode] = loadDisplayModes(displayId);
    if (!activeMode) {
        ALOGE("Failed to hotplug %s", displayString);
+5 −0
Original line number Diff line number Diff line
@@ -1093,6 +1093,11 @@ private:
        return it == mDisplays.end() ? nullptr : it->second;
    }

    bool hasDisplayWithId(DisplayId displayId) const REQUIRES(mStateLock) {
        return hasDisplay(
                [displayId](const auto& display) { return display.getId() == displayId; });
    }

    std::vector<PhysicalDisplayId> getPhysicalDisplayIdsLocked() const REQUIRES(mStateLock);

    // mark a region of a layer stack dirty. this updates the dirty
+25 −27
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@
#include "mock/DisplayHardware/MockDisplayMode.h"
#include "mock/MockEventThread.h"
#include "mock/MockNativeWindowSurface.h"
#include "mock/MockVsyncController.h"
#include "mock/PowerAdvisor/MockPowerAdvisor.h"
#include "mock/system/window/MockNativeWindow.h"

@@ -161,6 +160,7 @@ constexpr int POWER_MODE_LEET = 1337; // An out of range power mode value
#define BOOL_SUBSTITUTE(TYPENAME) enum class TYPENAME : bool { FALSE = false, TRUE = true };

BOOL_SUBSTITUTE(Async);
BOOL_SUBSTITUTE(HasIdentificationData);
BOOL_SUBSTITUTE(Primary);
BOOL_SUBSTITUTE(Secure);
BOOL_SUBSTITUTE(Virtual);
@@ -185,7 +185,7 @@ struct DisplayIdGetter;
template <typename PhysicalDisplay>
struct DisplayIdGetter<PhysicalDisplayIdType<PhysicalDisplay>> {
    static DisplayIdVariant get() {
        if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
        if (PhysicalDisplay::HAS_IDENTIFICATION_DATA == HasIdentificationData::FALSE) {
            return PhysicalDisplayId::fromPort(static_cast<bool>(PhysicalDisplay::PRIMARY)
                                                       ? LEGACY_DISPLAY_TYPE_PRIMARY
                                                       : LEGACY_DISPLAY_TYPE_EXTERNAL);
@@ -491,7 +491,7 @@ struct HwcDisplayVariant {

        setupHwcGetConfigsCallExpectations(test);

        if (PhysicalDisplay::HAS_IDENTIFICATION_DATA) {
        if (PhysicalDisplay::HAS_IDENTIFICATION_DATA == HasIdentificationData::TRUE) {
            EXPECT_CALL(*test->mComposer, getDisplayIdentificationData(HWC_DISPLAY_ID, _, _, _))
                    .WillOnce(DoAll(SetArgPointee<1>(PhysicalDisplay::PORT),
                                    SetArgPointee<2>(PhysicalDisplay::GET_IDENTIFICATION_DATA()),
@@ -515,8 +515,7 @@ constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY =

constexpr int PHYSICAL_DISPLAY_FLAGS = 0x1;

template <typename PhysicalDisplay, int width, int height,
          Secure secure = (PhysicalDisplay::SECURE) ? Secure::TRUE : Secure::FALSE>
template <typename PhysicalDisplay, int width, int height, Secure secure = PhysicalDisplay::SECURE>
struct PhysicalDisplayVariant
      : DisplayVariant<PhysicalDisplayIdType<PhysicalDisplay>, width, height, Async::FALSE, secure,
                       PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY,
@@ -527,73 +526,72 @@ struct PhysicalDisplayVariant
                                         GRALLOC_USAGE_PHYSICAL_DISPLAY, PHYSICAL_DISPLAY_FLAGS>,
                          PhysicalDisplay> {};

template <bool hasIdentificationData>
template <HasIdentificationData hasIdentificationData>
struct PrimaryDisplay {
    static constexpr auto CONNECTION_TYPE = ui::DisplayConnectionType::Internal;
    static constexpr Primary PRIMARY = Primary::TRUE;
    static constexpr bool SECURE = true;
    static constexpr Secure SECURE = Secure::TRUE;
    static constexpr uint8_t PORT = 255;
    static constexpr HWDisplayId HWC_DISPLAY_ID = 1001;
    static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
    static constexpr HasIdentificationData HAS_IDENTIFICATION_DATA = hasIdentificationData;
    static constexpr auto GET_IDENTIFICATION_DATA = getInternalEdid;
};

template <ui::DisplayConnectionType connectionType, bool hasIdentificationData, bool secure,
          HWDisplayId hwDisplayId = 1002>
template <ui::DisplayConnectionType connectionType, HasIdentificationData hasIdentificationData,
          Secure secure, HWDisplayId hwDisplayId = 1002>
struct SecondaryDisplay {
    static constexpr auto CONNECTION_TYPE = connectionType;
    static constexpr Primary PRIMARY = Primary::FALSE;
    static constexpr bool SECURE = secure;
    static constexpr Secure SECURE = secure;
    static constexpr uint8_t PORT = 254;
    static constexpr HWDisplayId HWC_DISPLAY_ID = hwDisplayId;
    static constexpr bool HAS_IDENTIFICATION_DATA = hasIdentificationData;
    static constexpr HasIdentificationData HAS_IDENTIFICATION_DATA = hasIdentificationData;
    static constexpr auto GET_IDENTIFICATION_DATA =
            connectionType == ui::DisplayConnectionType::Internal ? getInternalEdid
                                                                  : getExternalEdid;
};

constexpr bool kSecure = true;
constexpr bool kNonSecure = false;

template <bool secure>
template <Secure secure>
struct TertiaryDisplay {
    static constexpr auto CONNECTION_TYPE = ui::DisplayConnectionType::External;
    static constexpr Primary PRIMARY = Primary::FALSE;
    static constexpr bool SECURE = secure;
    static constexpr Secure SECURE = secure;
    static constexpr uint8_t PORT = 253;
    static constexpr HWDisplayId HWC_DISPLAY_ID = 1003;
    static constexpr auto GET_IDENTIFICATION_DATA = getExternalEdid;
};

using PrimaryDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<false>, 3840, 2160>;
using PrimaryDisplayVariant =
        PhysicalDisplayVariant<PrimaryDisplay<HasIdentificationData::FALSE>, 3840, 2160>;

using InnerDisplayVariant = PhysicalDisplayVariant<PrimaryDisplay<true>, 1840, 2208>;
using InnerDisplayVariant =
        PhysicalDisplayVariant<PrimaryDisplay<HasIdentificationData::TRUE>, 1840, 2208>;
using OuterDisplayVariant =
        PhysicalDisplayVariant<SecondaryDisplay<ui::DisplayConnectionType::Internal,
                                                /*hasIdentificationData=*/true, kSecure>,
                                                HasIdentificationData::TRUE, Secure::TRUE>,
                               1080, 2092>;
using OuterDisplayNonSecureVariant =
        PhysicalDisplayVariant<SecondaryDisplay<ui::DisplayConnectionType::Internal,
                                                /*hasIdentificationData=*/true, kNonSecure>,
                                                HasIdentificationData::TRUE, Secure::FALSE>,
                               1080, 2092>;

template <HWDisplayId hwDisplayId = 1002>
using ExternalDisplayWithIdentificationVariant = PhysicalDisplayVariant<
        SecondaryDisplay<ui::DisplayConnectionType::External,
                         /*hasIdentificationData=*/true, kNonSecure, hwDisplayId>,
        SecondaryDisplay<ui::DisplayConnectionType::External, HasIdentificationData::TRUE,
                         Secure::FALSE, hwDisplayId>,
        1920, 1280>;
using ExternalDisplayVariant =
        PhysicalDisplayVariant<SecondaryDisplay<ui::DisplayConnectionType::External,
                                                /*hasIdentificationData=*/false, kSecure>,
                                                HasIdentificationData::FALSE, Secure::TRUE>,
                               1920, 1280>;
using ExternalDisplayNonSecureVariant =
        PhysicalDisplayVariant<SecondaryDisplay<ui::DisplayConnectionType::External,
                                                /*hasIdentificationData=*/false, kNonSecure>,
                                                HasIdentificationData::FALSE, Secure::FALSE>,
                               1920, 1280>;

using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay<kSecure>, 1600, 1200>;
using TertiaryDisplayVariant = PhysicalDisplayVariant<TertiaryDisplay<Secure::TRUE>, 1600, 1200>;
using TertiaryDisplayNonSecureVariant =
        PhysicalDisplayVariant<TertiaryDisplay<kNonSecure>, 1600, 1200>;
        PhysicalDisplayVariant<TertiaryDisplay<Secure::FALSE>, 1600, 1200>;

// A virtual display not supported by the HWC.
constexpr uint32_t GRALLOC_USAGE_NONHWC_VIRTUAL_DISPLAY = 0;
+6 −4
Original line number Diff line number Diff line
@@ -278,8 +278,9 @@ TEST_F(DisplayTransactionCommitTest, ignoresHotplugConnectIfPrimaryAndExternalAl
    // TODO: This is an unnecessary call.
    EXPECT_CALL(*mComposer,
                getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _, _))
            .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay<kSecure>::PORT),
                            SetArgPointee<2>(TertiaryDisplay<kSecure>::GET_IDENTIFICATION_DATA()),
            .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay<Secure::TRUE>::PORT),
                            SetArgPointee<2>(
                                    TertiaryDisplay<Secure::TRUE>::GET_IDENTIFICATION_DATA()),
                            SetArgPointee<3>(android::ScreenPartStatus::UNSUPPORTED),
                            Return(Error::NONE)));

@@ -295,8 +296,9 @@ TEST_F(DisplayTransactionCommitTest,
    // TODO: This is an unnecessary call.
    EXPECT_CALL(*mComposer,
                getDisplayIdentificationData(TertiaryDisplayVariant::HWC_DISPLAY_ID, _, _, _))
            .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay<kSecure>::PORT),
                            SetArgPointee<2>(TertiaryDisplay<kSecure>::GET_IDENTIFICATION_DATA()),
            .WillOnce(DoAll(SetArgPointee<1>(TertiaryDisplay<Secure::TRUE>::PORT),
                            SetArgPointee<2>(
                                    TertiaryDisplay<Secure::TRUE>::GET_IDENTIFICATION_DATA()),
                            SetArgPointee<3>(android::ScreenPartStatus::UNSUPPORTED),
                            Return(Error::NONE)));