From a524a098e9280897a965bae16efd27469ff01ea4 Mon Sep 17 00:00:00 2001 From: Marin Shalamanov Date: Mon, 27 Jul 2020 21:39:55 +0200 Subject: Use type safe display IDs. Use a type safe wrapper around uint64_t for display ids. We also modify the format of the EDID generated physical display IDs by setting bit 62 to 1, which will indicate that the display id is stable across reboot. Bug: 160679868 Test: m && flash device Test: take screnshot on device Test: atest surfaceflinger_unittest Change-Id: Ie2c7c2b737e0882fa4208c059caa85b7ded922b2 --- libs/gui/DisplayEventDispatcher.cpp | 5 +- libs/gui/ISurfaceComposer.cpp | 17 +- libs/gui/include/gui/ISurfaceComposer.h | 2 +- libs/nativedisplay/AChoreographer.cpp | 10 +- libs/ui/include/ui/DisplayId.h | 102 +++++++++++ libs/ui/include/ui/PhysicalDisplayId.h | 32 ---- libs/ui/include_vndk/ui/DisplayId.h | 1 + libs/ui/include_vndk/ui/PhysicalDisplayId.h | 1 - .../display/AutomotiveDisplayProxyService.cpp | 6 +- .../CompositionEngine/tests/DisplayTest.cpp | 5 +- .../CompositionEngine/tests/MockHWComposer.h | 6 +- .../CompositionEngine/tests/RenderSurfaceTest.cpp | 2 +- services/surfaceflinger/DisplayDevice.h | 2 +- .../DisplayHardware/DisplayIdentification.cpp | 38 +--- .../DisplayHardware/DisplayIdentification.h | 41 +---- .../surfaceflinger/DisplayHardware/HWComposer.cpp | 11 +- .../surfaceflinger/DisplayHardware/HWComposer.h | 201 ++++++++++----------- services/surfaceflinger/Scheduler/EventThread.cpp | 18 +- services/surfaceflinger/SurfaceFlinger.cpp | 44 +++-- services/surfaceflinger/SurfaceFlinger.h | 10 +- .../tests/fakehwc/SFFakeHwc_test.cpp | 36 ++-- .../tests/unittests/CompositionTest.cpp | 2 +- .../tests/unittests/DisplayIdentificationTest.cpp | 6 +- .../tests/unittests/DisplayTransactionTest.cpp | 68 +++---- .../tests/unittests/EventThreadTest.cpp | 6 +- .../tests/unittests/SchedulerTest.cpp | 2 +- .../tests/unittests/TestableSurfaceFlinger.h | 4 +- 27 files changed, 355 insertions(+), 323 deletions(-) create mode 100644 libs/ui/include/ui/DisplayId.h delete mode 100644 libs/ui/include/ui/PhysicalDisplayId.h create mode 120000 libs/ui/include_vndk/ui/DisplayId.h delete mode 120000 libs/ui/include_vndk/ui/PhysicalDisplayId.h diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp index b33bc9e556..51fbb9748b 100644 --- a/libs/gui/DisplayEventDispatcher.cpp +++ b/libs/gui/DisplayEventDispatcher.cpp @@ -121,9 +121,8 @@ int DisplayEventDispatcher::handleEvent(int, int events, void*) { PhysicalDisplayId vsyncDisplayId; uint32_t vsyncCount; if (processPendingEvents(&vsyncTimestamp, &vsyncDisplayId, &vsyncCount)) { - ALOGV("dispatcher %p ~ Vsync pulse: timestamp=%" PRId64 - ", displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", count=%d", - this, ns2ms(vsyncTimestamp), vsyncDisplayId, vsyncCount); + ALOGV("dispatcher %p ~ Vsync pulse: timestamp=%" PRId64 ", displayId=%s, count=%d", this, + ns2ms(vsyncTimestamp), to_string(vsyncDisplayId).c_str(), vsyncCount); mWaitingForVsync = false; dispatchVsync(vsyncTimestamp, vsyncDisplayId, vsyncCount); } diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 6881be3e77..762cd10069 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -327,8 +327,11 @@ public: data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) == NO_ERROR) { - std::vector displayIds; - if (reply.readUint64Vector(&displayIds) == NO_ERROR) { + std::vector rawIds; + if (reply.readUint64Vector(&rawIds) == NO_ERROR) { + std::vector displayIds(rawIds.size()); + std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(), + [](uint64_t rawId) { return PhysicalDisplayId(rawId); }); return displayIds; } } @@ -339,7 +342,7 @@ public: virtual sp getPhysicalDisplayToken(PhysicalDisplayId displayId) const { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeUint64(displayId); + data.writeUint64(displayId.value); remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply); return reply.readStrongBinder(); } @@ -1417,7 +1420,7 @@ status_t BnSurfaceComposer::onTransact( } case GET_PHYSICAL_DISPLAY_TOKEN: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - PhysicalDisplayId displayId = data.readUint64(); + PhysicalDisplayId displayId(data.readUint64()); sp display = getPhysicalDisplayToken(displayId); reply->writeStrongBinder(display); return NO_ERROR; @@ -1819,7 +1822,11 @@ status_t BnSurfaceComposer::onTransact( } case GET_PHYSICAL_DISPLAY_IDS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - return reply->writeUint64Vector(getPhysicalDisplayIds()); + std::vector ids = getPhysicalDisplayIds(); + std::vector rawIds(ids.size()); + std::transform(ids.begin(), ids.end(), rawIds.begin(), + [](PhysicalDisplayId id) { return id.value; }); + return reply->writeUint64Vector(rawIds); } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 645714a915..6d225e0180 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -27,11 +27,11 @@ #include #include +#include #include #include #include #include -#include #include #include diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp index e458b2ecfb..ebc8909179 100644 --- a/libs/nativedisplay/AChoreographer.cpp +++ b/libs/nativedisplay/AChoreographer.cpp @@ -363,9 +363,8 @@ void Choreographer::dispatchVsync(nsecs_t timestamp, PhysicalDisplayId, uint32_t } void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool connected) { - ALOGV("choreographer %p ~ received hotplug event (displayId=%" - ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", connected=%s), ignoring.", - this, displayId, toString(connected)); + ALOGV("choreographer %p ~ received hotplug event (displayId=%s, connected=%s), ignoring.", + this, to_string(displayId).c_str(), toString(connected)); } // TODO(b/74619554): The PhysicalDisplayId is ignored because currently @@ -375,9 +374,8 @@ void Choreographer::dispatchHotplug(nsecs_t, PhysicalDisplayId displayId, bool c // PhysicalDisplayId should no longer be ignored. void Choreographer::dispatchConfigChanged(nsecs_t, PhysicalDisplayId displayId, int32_t configId, nsecs_t vsyncPeriod) { - ALOGV("choreographer %p ~ received config change event " - "(displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", configId=%d).", - this, displayId, configId); + ALOGV("choreographer %p ~ received config change event (displayId=%s, configId=%d).", + this, to_string(displayId).c_str(), configId); const nsecs_t lastPeriod = mLatestVsyncPeriod; std::vector callbacks{}; diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h new file mode 100644 index 0000000000..9eb54836af --- /dev/null +++ b/libs/ui/include/ui/DisplayId.h @@ -0,0 +1,102 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace android { + +// ID of a physical or a virtual display. This class acts as a type safe wrapper around uint64_t. +struct DisplayId { + // TODO(b/162612135) Remove default constructor + DisplayId() = default; + constexpr DisplayId(const DisplayId&) = default; + DisplayId& operator=(const DisplayId&) = default; + + uint64_t value; + +protected: + explicit constexpr DisplayId(uint64_t id) : value(id) {} +}; + +static_assert(sizeof(DisplayId) == sizeof(uint64_t)); + +inline bool operator==(DisplayId lhs, DisplayId rhs) { + return lhs.value == rhs.value; +} + +inline bool operator!=(DisplayId lhs, DisplayId rhs) { + return !(lhs == rhs); +} + +inline std::string to_string(DisplayId displayId) { + return std::to_string(displayId.value); +} + +// DisplayId of a physical display, such as the internal display or externally connected display. +struct PhysicalDisplayId : DisplayId { + // Flag indicating that the ID is stable across reboots. + static constexpr uint64_t FLAG_STABLE = 1ULL << 62; + + // Returns a stable ID based on EDID information. + static constexpr PhysicalDisplayId fromEdid(uint8_t port, uint16_t manufacturerId, + uint32_t modelHash) { + return PhysicalDisplayId(FLAG_STABLE, port, manufacturerId, modelHash); + } + + // Returns an unstable ID. If EDID is available using "fromEdid" is preferred. + static constexpr PhysicalDisplayId fromPort(uint8_t port) { + constexpr uint16_t kManufacturerId = 0; + constexpr uint32_t kModelHash = 0; + return PhysicalDisplayId(0, port, kManufacturerId, kModelHash); + } + + // TODO(b/162612135) Remove default constructor + PhysicalDisplayId() = default; + explicit constexpr PhysicalDisplayId(uint64_t id) : DisplayId(id) {} + explicit constexpr PhysicalDisplayId(DisplayId other) : DisplayId(other.value) {} + + constexpr uint16_t getManufacturerId() const { return static_cast(value >> 40); } + + constexpr uint8_t getPort() const { return static_cast(value); } + +private: + constexpr PhysicalDisplayId(uint64_t flags, uint8_t port, uint16_t manufacturerId, + uint32_t modelHash) + : DisplayId(flags | (static_cast(manufacturerId) << 40) | + (static_cast(modelHash) << 8) | port) {} +}; + +static_assert(sizeof(PhysicalDisplayId) == sizeof(uint64_t)); + +} // namespace android + +namespace std { + +template <> +struct hash { + size_t operator()(android::DisplayId displayId) const { + return hash()(displayId.value); + } +}; + +template <> +struct hash : hash {}; + +} // namespace std diff --git a/libs/ui/include/ui/PhysicalDisplayId.h b/libs/ui/include/ui/PhysicalDisplayId.h deleted file mode 100644 index 1a345acc86..0000000000 --- a/libs/ui/include/ui/PhysicalDisplayId.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#define ANDROID_PHYSICAL_DISPLAY_ID_FORMAT PRIu64 - -namespace android { - -using PhysicalDisplayId = uint64_t; - -constexpr uint8_t getPhysicalDisplayPort(PhysicalDisplayId displayId) { - return static_cast(displayId); -} - -} // namespace android diff --git a/libs/ui/include_vndk/ui/DisplayId.h b/libs/ui/include_vndk/ui/DisplayId.h new file mode 120000 index 0000000000..73c9fe8d68 --- /dev/null +++ b/libs/ui/include_vndk/ui/DisplayId.h @@ -0,0 +1 @@ +../../include/ui/DisplayId.h \ No newline at end of file diff --git a/libs/ui/include_vndk/ui/PhysicalDisplayId.h b/libs/ui/include_vndk/ui/PhysicalDisplayId.h deleted file mode 120000 index 6e3fb1e62e..0000000000 --- a/libs/ui/include_vndk/ui/PhysicalDisplayId.h +++ /dev/null @@ -1 +0,0 @@ -../../include/ui/PhysicalDisplayId.h \ No newline at end of file diff --git a/services/automotive/display/AutomotiveDisplayProxyService.cpp b/services/automotive/display/AutomotiveDisplayProxyService.cpp index 4767406931..321bb8342d 100644 --- a/services/automotive/display/AutomotiveDisplayProxyService.cpp +++ b/services/automotive/display/AutomotiveDisplayProxyService.cpp @@ -34,7 +34,7 @@ AutomotiveDisplayProxyService::getIGraphicBufferProducer(uint64_t id) { sp displayToken = nullptr; sp surfaceControl = nullptr; if (it == mDisplays.end()) { - displayToken = SurfaceComposerClient::getPhysicalDisplayToken(id); + displayToken = SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(id)); if (displayToken == nullptr) { ALOGE("Given display id, 0x%lX, is invalid.", (unsigned long)id); return nullptr; @@ -145,7 +145,7 @@ Return AutomotiveDisplayProxyService::getDisplayIdList(getDisplayIdList_cb auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); ids.resize(displayIds.size()); for (auto i = 0; i < displayIds.size(); ++i) { - ids[i] = displayIds[i]; + ids[i] = displayIds[i].value; } _cb(ids); @@ -157,7 +157,7 @@ Return AutomotiveDisplayProxyService::getDisplayInfo(uint64_t id, getDispl HwDisplayConfig activeConfig; HwDisplayState activeState; - auto displayToken = SurfaceComposerClient::getPhysicalDisplayToken(id); + auto displayToken = SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(id)); if (displayToken == nullptr) { ALOGE("Given display id, 0x%lX, is invalid.", (unsigned long)id); } else { diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp index 09f37fba18..378c0501b4 100644 --- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp @@ -56,8 +56,9 @@ using testing::Sequence; using testing::SetArgPointee; using testing::StrictMock; -constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; -constexpr DisplayId VIRTUAL_DISPLAY_ID = DisplayId{43}; +constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId{42}; +// TODO(b/160679868) Use VirtualDisplayId +constexpr PhysicalDisplayId VIRTUAL_DISPLAY_ID = PhysicalDisplayId{43}; constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; constexpr int32_t DEFAULT_LAYER_STACK = 123; diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index 75a4fec8fb..1dd5df4770 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -46,7 +46,7 @@ public: MOCK_METHOD3(allocateVirtualDisplay, std::optional(uint32_t, uint32_t, ui::PixelFormat*)); - MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, DisplayId)); + MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, PhysicalDisplayId)); MOCK_METHOD1(createLayer, HWC2::Layer*(DisplayId)); MOCK_METHOD2(destroyLayer, void(DisplayId, HWC2::Layer*)); MOCK_METHOD3(getDeviceCompositionChanges, @@ -107,8 +107,8 @@ public: MOCK_CONST_METHOD1(getHwcDisplayId, std::optional(int32_t)); MOCK_CONST_METHOD0(getInternalHwcDisplayId, std::optional()); MOCK_CONST_METHOD0(getExternalHwcDisplayId, std::optional()); - MOCK_CONST_METHOD1(toPhysicalDisplayId, std::optional(hal::HWDisplayId)); - MOCK_CONST_METHOD1(fromPhysicalDisplayId, std::optional(DisplayId)); + MOCK_CONST_METHOD1(toPhysicalDisplayId, std::optional(hal::HWDisplayId)); + MOCK_CONST_METHOD1(fromPhysicalDisplayId, std::optional(PhysicalDisplayId)); }; } // namespace mock diff --git a/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp b/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp index fd47e453c8..519cc575cf 100644 --- a/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp @@ -33,7 +33,7 @@ namespace { constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; -constexpr std::optional DEFAULT_DISPLAY_ID = std::make_optional(DisplayId{123u}); +constexpr std::optional DEFAULT_DISPLAY_ID = {PhysicalDisplayId(123u)}; const std::string DEFAULT_DISPLAY_NAME = "Mock Display"; using testing::_; diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 576488c558..28906f8cee 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -194,7 +194,7 @@ private: struct DisplayDeviceState { struct Physical { - DisplayId id; + PhysicalDisplayId id; DisplayConnectionType type; hardware::graphics::composer::hal::HWDisplayId hwcDisplayId; std::optional deviceProductInfo; diff --git a/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp b/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp index 52a6380ebd..98209bb9e4 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp +++ b/services/surfaceflinger/DisplayHardware/DisplayIdentification.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconversion" - #undef LOG_TAG #define LOG_TAG "DisplayIdentification" @@ -38,7 +34,6 @@ using byte_view = std::basic_string_view; constexpr size_t kEdidBlockSize = 128; constexpr size_t kEdidHeaderLength = 5; -constexpr uint16_t kFallbackEdidManufacturerId = 0; constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu; std::optional getEdidDescriptorType(const byte_view& view) { @@ -126,8 +121,8 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) { constexpr uint8_t kVendorSpecificDataBlockTag = 0x3; if (tag == kVendorSpecificDataBlockTag) { - const uint32_t ieeeRegistrationId = - dataBlock[1] | (dataBlock[2] << 8) | (dataBlock[3] << 16); + const uint32_t ieeeRegistrationId = static_cast( + dataBlock[1] | (dataBlock[2] << 8) | (dataBlock[3] << 16)); constexpr uint32_t kHdmiIeeeRegistrationId = 0xc03; if (ieeeRegistrationId == kHdmiIeeeRegistrationId) { @@ -152,14 +147,6 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) { } // namespace -uint16_t DisplayId::manufacturerId() const { - return static_cast(value >> 40); -} - -DisplayId DisplayId::fromEdid(uint8_t port, uint16_t manufacturerId, uint32_t modelHash) { - return {(static_cast(manufacturerId) << 40) | (static_cast(modelHash) << 8) | port}; -} - bool isEdid(const DisplayIdentificationData& data) { const uint8_t kMagic[] = {0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0}; return data.size() >= sizeof(kMagic) && @@ -184,7 +171,7 @@ std::optional parseEdid(const DisplayIdentificationData& edid) { // Plug and play ID encoded as big-endian 16-bit value. const uint16_t manufacturerId = - (edid[kManufacturerOffset] << 8) | edid[kManufacturerOffset + 1]; + static_cast((edid[kManufacturerOffset] << 8) | edid[kManufacturerOffset + 1]); const auto pnpId = getPnpId(manufacturerId); if (!pnpId) { @@ -197,7 +184,8 @@ std::optional parseEdid(const DisplayIdentificationData& edid) { ALOGE("Invalid EDID: product ID is truncated."); return {}; } - const uint16_t productId = edid[kProductIdOffset] | (edid[kProductIdOffset + 1] << 8); + const uint16_t productId = + static_cast(edid[kProductIdOffset] | (edid[kProductIdOffset + 1] << 8)); constexpr size_t kManufactureWeekOffset = 16; if (edid.size() < kManufactureWeekOffset + sizeof(uint8_t)) { @@ -323,8 +311,8 @@ std::optional getPnpId(uint16_t manufacturerId) { return a && b && c ? std::make_optional(PnpId{a, b, c}) : std::nullopt; } -std::optional getPnpId(DisplayId displayId) { - return getPnpId(displayId.manufacturerId()); +std::optional getPnpId(PhysicalDisplayId displayId) { + return getPnpId(displayId.getManufacturerId()); } std::optional parseDisplayIdentificationData( @@ -339,21 +327,15 @@ std::optional parseDisplayIdentificationData( return {}; } - const auto displayId = DisplayId::fromEdid(port, edid->manufacturerId, edid->modelHash); + const auto displayId = PhysicalDisplayId::fromEdid(port, edid->manufacturerId, edid->modelHash); return DisplayIdentificationInfo{.id = displayId, .name = std::string(edid->displayName), .deviceProductInfo = buildDeviceProductInfo(*edid)}; } -DisplayId getFallbackDisplayId(uint8_t port) { - return DisplayId::fromEdid(port, kFallbackEdidManufacturerId, 0); -} - -DisplayId getVirtualDisplayId(uint32_t id) { - return DisplayId::fromEdid(0, kVirtualEdidManufacturerId, id); +PhysicalDisplayId getVirtualDisplayId(uint32_t id) { + return PhysicalDisplayId::fromEdid(0, kVirtualEdidManufacturerId, id); } } // namespace android -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic pop // ignored "-Wconversion" diff --git a/services/surfaceflinger/DisplayHardware/DisplayIdentification.h b/services/surfaceflinger/DisplayHardware/DisplayIdentification.h index 4819d1d18b..fbea4e5fe3 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayIdentification.h +++ b/services/surfaceflinger/DisplayHardware/DisplayIdentification.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,38 +24,18 @@ #include #include -#include +#include #define LEGACY_DISPLAY_TYPE_PRIMARY 0 #define LEGACY_DISPLAY_TYPE_EXTERNAL 1 namespace android { -struct DisplayId { - using Type = PhysicalDisplayId; - Type value; - - uint16_t manufacturerId() const; - - static DisplayId fromEdid(uint8_t port, uint16_t manufacturerId, uint32_t modelHash); -}; - -inline bool operator==(DisplayId lhs, DisplayId rhs) { - return lhs.value == rhs.value; -} - -inline bool operator!=(DisplayId lhs, DisplayId rhs) { - return !(lhs == rhs); -} - -inline std::string to_string(DisplayId displayId) { - return std::to_string(displayId.value); -} using DisplayIdentificationData = std::vector; struct DisplayIdentificationInfo { - DisplayId id; + PhysicalDisplayId id; std::string name; std::optional deviceProductInfo; }; @@ -94,23 +74,12 @@ struct Edid { bool isEdid(const DisplayIdentificationData&); std::optional parseEdid(const DisplayIdentificationData&); std::optional getPnpId(uint16_t manufacturerId); -std::optional getPnpId(DisplayId); +std::optional getPnpId(PhysicalDisplayId); std::optional parseDisplayIdentificationData( uint8_t port, const DisplayIdentificationData&); -DisplayId getFallbackDisplayId(uint8_t port); -DisplayId getVirtualDisplayId(uint32_t id); +PhysicalDisplayId getVirtualDisplayId(uint32_t id); } // namespace android -namespace std { - -template <> -struct hash { - size_t operator()(android::DisplayId displayId) const { - return hash()(displayId.value); - } -}; - -} // namespace std diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 7a2f0f34ee..05ef599dda 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -284,7 +284,8 @@ std::optional HWComposer::allocateVirtualDisplay(uint32_t width, uint return displayId; } -void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) { +void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, + PhysicalDisplayId displayId) { if (!mInternalHwcDisplayId) { mInternalHwcDisplayId = hwcDisplayId; } else if (mInternalHwcDisplayId != hwcDisplayId && !mExternalHwcDisplayId) { @@ -865,7 +866,8 @@ void HWComposer::dump(std::string& result) const { result.append(mComposer->dumpDebugInfo()); } -std::optional HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const { +std::optional HWComposer::toPhysicalDisplayId( + hal::HWDisplayId hwcDisplayId) const { if (const auto it = mPhysicalDisplayIdMap.find(hwcDisplayId); it != mPhysicalDisplayIdMap.end()) { return it->second; @@ -873,7 +875,8 @@ std::optional HWComposer::toPhysicalDisplayId(hal::HWDisplayId hwcDis return {}; } -std::optional HWComposer::fromPhysicalDisplayId(DisplayId displayId) const { +std::optional HWComposer::fromPhysicalDisplayId( + PhysicalDisplayId displayId) const { if (const auto it = mDisplayData.find(displayId); it != mDisplayData.end() && !it->second.isVirtual) { return it->second.hwcDisplay->getId(); @@ -937,7 +940,7 @@ std::optional HWComposer::onHotplugConnect( port = isPrimary ? LEGACY_DISPLAY_TYPE_PRIMARY : LEGACY_DISPLAY_TYPE_EXTERNAL; } - return DisplayIdentificationInfo{.id = getFallbackDisplayId(port), + return DisplayIdentificationInfo{.id = PhysicalDisplayId::fromPort(port), .name = isPrimary ? "Internal display" : "External display", .deviceProductInfo = std::nullopt}; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index b8000386ac..698e3afa46 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -84,23 +84,22 @@ public: virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0; - virtual bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort, + virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, DisplayIdentificationData* outData) const = 0; - virtual bool hasCapability(hal::Capability capability) const = 0; - virtual bool hasDisplayCapability(DisplayId displayId, - hal::DisplayCapability capability) const = 0; + virtual bool hasCapability(hal::Capability) const = 0; + virtual bool hasDisplayCapability(DisplayId, hal::DisplayCapability) const = 0; // Attempts to allocate a virtual display and returns its ID if created on the HWC device. virtual std::optional allocateVirtualDisplay(uint32_t width, uint32_t height, - ui::PixelFormat* format) = 0; + ui::PixelFormat*) = 0; - virtual void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) = 0; + virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0; // Attempts to create a new layer on this display - virtual HWC2::Layer* createLayer(DisplayId displayId) = 0; + virtual HWC2::Layer* createLayer(DisplayId) = 0; // Destroy a previously created layer - virtual void destroyLayer(DisplayId displayId, HWC2::Layer* layer) = 0; + virtual void destroyLayer(DisplayId, HWC2::Layer*) = 0; // Gets any required composition change requests from the HWC device. // @@ -113,104 +112,97 @@ public: DisplayId, bool frameUsesClientComposition, std::optional* outChanges) = 0; - virtual status_t setClientTarget(DisplayId displayId, uint32_t slot, - const sp& acquireFence, const sp& target, - ui::Dataspace dataspace) = 0; + virtual status_t setClientTarget(DisplayId, uint32_t slot, const sp& acquireFence, + const sp& target, ui::Dataspace) = 0; // Present layers to the display and read releaseFences. - virtual status_t presentAndGetReleaseFences(DisplayId displayId) = 0; + virtual status_t presentAndGetReleaseFences(DisplayId) = 0; // set power mode - virtual status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) = 0; + virtual status_t setPowerMode(DisplayId, hal::PowerMode) = 0; // Sets a color transform to be applied to the result of composition - virtual status_t setColorTransform(DisplayId displayId, const mat4& transform) = 0; + virtual status_t setColorTransform(DisplayId, const mat4& transform) = 0; // reset state when an external, non-virtual display is disconnected - virtual void disconnectDisplay(DisplayId displayId) = 0; + virtual void disconnectDisplay(DisplayId) = 0; // get the present fence received from the last call to present. - virtual sp getPresentFence(DisplayId displayId) const = 0; + virtual sp getPresentFence(DisplayId) const = 0; // Get last release fence for the given layer - virtual sp getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const = 0; + virtual sp getLayerReleaseFence(DisplayId, HWC2::Layer*) const = 0; // Set the output buffer and acquire fence for a virtual display. // Returns INVALID_OPERATION if displayId is not a virtual display. - virtual status_t setOutputBuffer(DisplayId displayId, const sp& acquireFence, + virtual status_t setOutputBuffer(DisplayId, const sp& acquireFence, const sp& buffer) = 0; // After SurfaceFlinger has retrieved the release fences for all the frames, // it can call this to clear the shared pointers in the release fence map - virtual void clearReleaseFences(DisplayId displayId) = 0; + virtual void clearReleaseFences(DisplayId) = 0; // Fetches the HDR capabilities of the given display - virtual status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) = 0; + virtual status_t getHdrCapabilities(DisplayId, HdrCapabilities* outCapabilities) = 0; - virtual int32_t getSupportedPerFrameMetadata(DisplayId displayId) const = 0; + virtual int32_t getSupportedPerFrameMetadata(DisplayId) const = 0; // Returns the available RenderIntent of the given display. - virtual std::vector getRenderIntents(DisplayId displayId, - ui::ColorMode colorMode) const = 0; + virtual std::vector getRenderIntents(DisplayId, ui::ColorMode) const = 0; - virtual mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) = 0; + virtual mat4 getDataspaceSaturationMatrix(DisplayId, ui::Dataspace) = 0; // Returns the attributes of the color sampling engine. - virtual status_t getDisplayedContentSamplingAttributes(DisplayId displayId, - ui::PixelFormat* outFormat, + virtual status_t getDisplayedContentSamplingAttributes(DisplayId, ui::PixelFormat* outFormat, ui::Dataspace* outDataspace, uint8_t* outComponentMask) = 0; - virtual status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, + virtual status_t setDisplayContentSamplingEnabled(DisplayId, bool enabled, uint8_t componentMask, uint64_t maxFrames) = 0; - virtual status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, - uint64_t timestamp, + virtual status_t getDisplayedContentSample(DisplayId, uint64_t maxFrames, uint64_t timestamp, DisplayedFrameStats* outStats) = 0; // Sets the brightness of a display. - virtual std::future setDisplayBrightness(DisplayId displayId, float brightness) = 0; + virtual std::future setDisplayBrightness(DisplayId, float brightness) = 0; // Events handling --------------------------------------------------------- // Returns stable display ID (and display name on connection of new or previously disconnected // display), or std::nullopt if hotplug event was ignored. // This function is called from SurfaceFlinger. - virtual std::optional onHotplug(hal::HWDisplayId hwcDisplayId, - hal::Connection connection) = 0; + virtual std::optional onHotplug(hal::HWDisplayId, + hal::Connection) = 0; - virtual bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) = 0; - virtual void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) = 0; + virtual bool onVsync(hal::HWDisplayId, int64_t timestamp) = 0; + virtual void setVsyncEnabled(DisplayId, hal::Vsync enabled) = 0; - virtual nsecs_t getRefreshTimestamp(DisplayId displayId) const = 0; - virtual bool isConnected(DisplayId displayId) const = 0; + virtual nsecs_t getRefreshTimestamp(DisplayId) const = 0; + virtual bool isConnected(DisplayId) const = 0; // Non-const because it can update configMap inside of mDisplayData virtual std::vector> getConfigs( - DisplayId displayId) const = 0; + DisplayId) const = 0; - virtual std::shared_ptr getActiveConfig( - DisplayId displayId) const = 0; - virtual int getActiveConfigIndex(DisplayId displayId) const = 0; + virtual std::shared_ptr getActiveConfig(DisplayId) const = 0; + virtual int getActiveConfigIndex(DisplayId) const = 0; - virtual std::vector getColorModes(DisplayId displayId) const = 0; + virtual std::vector getColorModes(DisplayId) const = 0; - virtual status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, - ui::RenderIntent renderIntent) = 0; + virtual status_t setActiveColorMode(DisplayId, ui::ColorMode mode, ui::RenderIntent) = 0; virtual bool isUsingVrComposer() const = 0; // Composer 2.4 virtual DisplayConnectionType getDisplayConnectionType(DisplayId) const = 0; - virtual bool isVsyncPeriodSwitchSupported(DisplayId displayId) const = 0; - virtual nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const = 0; + virtual bool isVsyncPeriodSwitchSupported(DisplayId) const = 0; + virtual nsecs_t getDisplayVsyncPeriod(DisplayId) const = 0; virtual status_t setActiveConfigWithConstraints( - DisplayId displayId, size_t configId, - const hal::VsyncPeriodChangeConstraints& constraints, + DisplayId, size_t configId, const hal::VsyncPeriodChangeConstraints&, hal::VsyncPeriodChangeTimeline* outTimeline) = 0; - virtual status_t setAutoLowLatencyMode(DisplayId displayId, bool on) = 0; + virtual status_t setAutoLowLatencyMode(DisplayId, bool on) = 0; virtual status_t getSupportedContentTypes( - DisplayId displayId, std::vector* outSupportedContentTypes) = 0; - virtual status_t setContentType(DisplayId displayId, hal::ContentType contentType) = 0; + DisplayId, std::vector* outSupportedContentTypes) = 0; + virtual status_t setContentType(DisplayId, hal::ContentType) = 0; virtual const std::unordered_map& getSupportedLayerGenericMetadata() const = 0; @@ -223,8 +215,8 @@ public: virtual std::optional getInternalHwcDisplayId() const = 0; virtual std::optional getExternalHwcDisplayId() const = 0; - virtual std::optional toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const = 0; - virtual std::optional fromPhysicalDisplayId(DisplayId displayId) const = 0; + virtual std::optional toPhysicalDisplayId(hal::HWDisplayId) const = 0; + virtual std::optional fromPhysicalDisplayId(PhysicalDisplayId) const = 0; }; namespace impl { @@ -238,118 +230,112 @@ public: void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override; - bool getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort, + bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, DisplayIdentificationData* outData) const override; - bool hasCapability(hal::Capability capability) const override; - bool hasDisplayCapability(DisplayId displayId, - hal::DisplayCapability capability) const override; + bool hasCapability(hal::Capability) const override; + bool hasDisplayCapability(DisplayId, hal::DisplayCapability) const override; // Attempts to allocate a virtual display and returns its ID if created on the HWC device. std::optional allocateVirtualDisplay(uint32_t width, uint32_t height, - ui::PixelFormat* format) override; + ui::PixelFormat*) override; // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated. - void allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, DisplayId displayId) override; + void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override; // Attempts to create a new layer on this display - HWC2::Layer* createLayer(DisplayId displayId) override; + HWC2::Layer* createLayer(DisplayId) override; // Destroy a previously created layer - void destroyLayer(DisplayId displayId, HWC2::Layer* layer) override; + void destroyLayer(DisplayId, HWC2::Layer*) override; status_t getDeviceCompositionChanges( DisplayId, bool frameUsesClientComposition, std::optional* outChanges) override; - status_t setClientTarget(DisplayId displayId, uint32_t slot, const sp& acquireFence, - const sp& target, ui::Dataspace dataspace) override; + status_t setClientTarget(DisplayId, uint32_t slot, const sp& acquireFence, + const sp& target, ui::Dataspace) override; // Present layers to the display and read releaseFences. - status_t presentAndGetReleaseFences(DisplayId displayId) override; + status_t presentAndGetReleaseFences(DisplayId) override; // set power mode - status_t setPowerMode(DisplayId displayId, hal::PowerMode mode) override; + status_t setPowerMode(DisplayId, hal::PowerMode mode) override; // Sets a color transform to be applied to the result of composition - status_t setColorTransform(DisplayId displayId, const mat4& transform) override; + status_t setColorTransform(DisplayId, const mat4& transform) override; // reset state when an external, non-virtual display is disconnected - void disconnectDisplay(DisplayId displayId) override; + void disconnectDisplay(DisplayId) override; // get the present fence received from the last call to present. - sp getPresentFence(DisplayId displayId) const override; + sp getPresentFence(DisplayId) const override; // Get last release fence for the given layer - sp getLayerReleaseFence(DisplayId displayId, HWC2::Layer* layer) const override; + sp getLayerReleaseFence(DisplayId, HWC2::Layer*) const override; // Set the output buffer and acquire fence for a virtual display. // Returns INVALID_OPERATION if displayId is not a virtual display. - status_t setOutputBuffer(DisplayId displayId, const sp& acquireFence, + status_t setOutputBuffer(DisplayId, const sp& acquireFence, const sp& buffer) override; // After SurfaceFlinger has retrieved the release fences for all the frames, // it can call this to clear the shared pointers in the release fence map - void clearReleaseFences(DisplayId displayId) override; + void clearReleaseFences(DisplayId) override; // Fetches the HDR capabilities of the given display - status_t getHdrCapabilities(DisplayId displayId, HdrCapabilities* outCapabilities) override; + status_t getHdrCapabilities(DisplayId, HdrCapabilities* outCapabilities) override; - int32_t getSupportedPerFrameMetadata(DisplayId displayId) const override; + int32_t getSupportedPerFrameMetadata(DisplayId) const override; // Returns the available RenderIntent of the given display. - std::vector getRenderIntents(DisplayId displayId, - ui::ColorMode colorMode) const override; + std::vector getRenderIntents(DisplayId, ui::ColorMode) const override; - mat4 getDataspaceSaturationMatrix(DisplayId displayId, ui::Dataspace dataspace) override; + mat4 getDataspaceSaturationMatrix(DisplayId, ui::Dataspace) override; // Returns the attributes of the color sampling engine. - status_t getDisplayedContentSamplingAttributes(DisplayId displayId, ui::PixelFormat* outFormat, + status_t getDisplayedContentSamplingAttributes(DisplayId, ui::PixelFormat* outFormat, ui::Dataspace* outDataspace, uint8_t* outComponentMask) override; - status_t setDisplayContentSamplingEnabled(DisplayId displayId, bool enabled, - uint8_t componentMask, uint64_t maxFrames) override; - status_t getDisplayedContentSample(DisplayId displayId, uint64_t maxFrames, uint64_t timestamp, + status_t setDisplayContentSamplingEnabled(DisplayId, bool enabled, uint8_t componentMask, + uint64_t maxFrames) override; + status_t getDisplayedContentSample(DisplayId, uint64_t maxFrames, uint64_t timestamp, DisplayedFrameStats* outStats) override; - std::future setDisplayBrightness(DisplayId displayId, float brightness) override; + std::future setDisplayBrightness(DisplayId, float brightness) override; // Events handling --------------------------------------------------------- // Returns stable display ID (and display name on connection of new or previously disconnected // display), or std::nullopt if hotplug event was ignored. - std::optional onHotplug(hal::HWDisplayId hwcDisplayId, - hal::Connection connection) override; + std::optional onHotplug(hal::HWDisplayId, hal::Connection) override; - bool onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) override; - void setVsyncEnabled(DisplayId displayId, hal::Vsync enabled) override; + bool onVsync(hal::HWDisplayId, int64_t timestamp) override; + void setVsyncEnabled(DisplayId, hal::Vsync enabled) override; - nsecs_t getRefreshTimestamp(DisplayId displayId) const override; - bool isConnected(DisplayId displayId) const override; + nsecs_t getRefreshTimestamp(DisplayId) const override; + bool isConnected(DisplayId) const override; // Non-const because it can update configMap inside of mDisplayData - std::vector> getConfigs( - DisplayId displayId) const override; + std::vector> getConfigs(DisplayId) const override; - std::shared_ptr getActiveConfig( - DisplayId displayId) const override; - int getActiveConfigIndex(DisplayId displayId) const override; + std::shared_ptr getActiveConfig(DisplayId) const override; + int getActiveConfigIndex(DisplayId) const override; - std::vector getColorModes(DisplayId displayId) const override; + std::vector getColorModes(DisplayId) const override; - status_t setActiveColorMode(DisplayId displayId, ui::ColorMode mode, - ui::RenderIntent renderIntent) override; + status_t setActiveColorMode(DisplayId, ui::ColorMode, ui::RenderIntent) override; bool isUsingVrComposer() const override; // Composer 2.4 DisplayConnectionType getDisplayConnectionType(DisplayId) const override; - bool isVsyncPeriodSwitchSupported(DisplayId displayId) const override; - nsecs_t getDisplayVsyncPeriod(DisplayId displayId) const override; - status_t setActiveConfigWithConstraints(DisplayId displayId, size_t configId, - const hal::VsyncPeriodChangeConstraints& constraints, + bool isVsyncPeriodSwitchSupported(DisplayId) const override; + nsecs_t getDisplayVsyncPeriod(DisplayId) const override; + status_t setActiveConfigWithConstraints(DisplayId, size_t configId, + const hal::VsyncPeriodChangeConstraints&, hal::VsyncPeriodChangeTimeline* outTimeline) override; - status_t setAutoLowLatencyMode(DisplayId displayId, bool) override; - status_t getSupportedContentTypes(DisplayId displayId, std::vector*) override; - status_t setContentType(DisplayId displayId, hal::ContentType) override; + status_t setAutoLowLatencyMode(DisplayId, bool) override; + status_t getSupportedContentTypes(DisplayId, std::vector*) override; + status_t setContentType(DisplayId, hal::ContentType) override; const std::unordered_map& getSupportedLayerGenericMetadata() const override; @@ -366,17 +352,16 @@ public: return mExternalHwcDisplayId; } - std::optional toPhysicalDisplayId(hal::HWDisplayId hwcDisplayId) const override; - std::optional fromPhysicalDisplayId(DisplayId displayId) const override; + std::optional toPhysicalDisplayId(hal::HWDisplayId) const override; + std::optional fromPhysicalDisplayId(PhysicalDisplayId) const override; private: // For unit tests friend TestableSurfaceFlinger; - std::optional onHotplugConnect(hal::HWDisplayId hwcDisplayId); - std::optional onHotplugDisconnect(hal::HWDisplayId hwcDisplayId); - bool shouldIgnoreHotplugConnect(hal::HWDisplayId hwcDisplayId, - bool hasDisplayIdentificationData) const; + std::optional onHotplugConnect(hal::HWDisplayId); + std::optional onHotplugDisconnect(hal::HWDisplayId); + bool shouldIgnoreHotplugConnect(hal::HWDisplayId, bool hasDisplayIdentificationData) const; void loadCapabilities(); void loadLayerMetadataSupport(); @@ -411,7 +396,7 @@ private: std::unordered_map mSupportedLayerGenericMetadata; bool mRegisteredCallback = false; - std::unordered_map mPhysicalDisplayIdMap; + std::unordered_map mPhysicalDisplayIdMap; std::optional mInternalHwcDisplayId; std::optional mExternalHwcDisplayId; bool mHasMultiDisplaySupport = false; diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index cee36a121f..2020e0cb29 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -74,18 +74,16 @@ std::string toString(const EventThreadConnection& connection) { std::string toString(const DisplayEventReceiver::Event& event) { switch (event.header.type) { case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG: - return StringPrintf("Hotplug{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", %s}", - event.header.displayId, + return StringPrintf("Hotplug{displayId=%s, %s}", + to_string(event.header.displayId).c_str(), event.hotplug.connected ? "connected" : "disconnected"); case DisplayEventReceiver::DISPLAY_EVENT_VSYNC: - return StringPrintf("VSync{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT - ", count=%u, expectedVSyncTimestamp=%" PRId64 "}", - event.header.displayId, event.vsync.count, + return StringPrintf("VSync{displayId=%s, count=%u, expectedVSyncTimestamp=%" PRId64 "}", + to_string(event.header.displayId).c_str(), event.vsync.count, event.vsync.expectedVSyncTimestamp); case DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED: - return StringPrintf("ConfigChanged{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT - ", configId=%u}", - event.header.displayId, event.config.configId); + return StringPrintf("ConfigChanged{displayId=%s, configId=%u}", + to_string(event.header.displayId).c_str(), event.config.configId); default: return "Event{}"; } @@ -508,8 +506,8 @@ void EventThread::dump(std::string& result) const { StringAppendF(&result, "%s: state=%s VSyncState=", mThreadName, toCString(mState)); if (mVSyncState) { - StringAppendF(&result, "{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", count=%u%s}\n", - mVSyncState->displayId, mVSyncState->count, + StringAppendF(&result, "{displayId=%s, count=%u%s}\n", + to_string(mVSyncState->displayId).c_str(), mVSyncState->count, mVSyncState->synthetic ? ", synthetic" : ""); } else { StringAppendF(&result, "none\n"); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 7d5cb67ebe..b32b7fe7bc 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -565,11 +565,11 @@ std::vector SurfaceFlinger::getPhysicalDisplayIds() const { std::vector displayIds; displayIds.reserve(mPhysicalDisplayTokens.size()); - displayIds.push_back(internalDisplayId->value); + displayIds.push_back(*internalDisplayId); for (const auto& [id, token] : mPhysicalDisplayTokens) { if (id != *internalDisplayId) { - displayIds.push_back(id.value); + displayIds.push_back(id); } } @@ -578,7 +578,7 @@ std::vector SurfaceFlinger::getPhysicalDisplayIds() const { sp SurfaceFlinger::getPhysicalDisplayToken(PhysicalDisplayId displayId) const { Mutex::Autolock lock(mStateLock); - return getPhysicalDisplayTokenLocked(DisplayId{displayId}); + return getPhysicalDisplayTokenLocked(displayId); } status_t SurfaceFlinger::getColorManagement(bool* outGetColorManagement) const { @@ -738,10 +738,11 @@ void SurfaceFlinger::init() { signalTransaction(); })); }; - mVrFlinger = dvr::VrFlinger::Create(getHwComposer().getComposer(), - getHwComposer() - .fromPhysicalDisplayId(*display->getId()) - .value_or(0), + auto hwcDisplayId = + getHwComposer() + .fromPhysicalDisplayId(static_cast(*display->getId())) + .value_or(0); + mVrFlinger = dvr::VrFlinger::Create(getHwComposer().getComposer(), hwcDisplayId, vrFlingerRequestDisplayCallback); if (!mVrFlinger) { ALOGE("Failed to start vrflinger"); @@ -1106,7 +1107,8 @@ void SurfaceFlinger::setActiveConfigInternal() { const nsecs_t vsyncPeriod = mRefreshRateConfigs->getRefreshRateFromConfigId(mUpcomingActiveConfig.configId) .getVsyncPeriod(); - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, display->getId()->value, + mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, + static_cast(*display->getId()), mUpcomingActiveConfig.configId, vsyncPeriod); } } @@ -2440,7 +2442,7 @@ void SurfaceFlinger::processDisplayHotplugEventsLocked() { continue; } - const DisplayId displayId = info->id; + const auto displayId = info->id; const auto it = mPhysicalDisplayTokens.find(displayId); if (event.connection == hal::Connection::CONNECTED) { @@ -2654,7 +2656,7 @@ void SurfaceFlinger::processDisplayAdded(const wp& displayToken, mDisplays.emplace(displayToken, display); if (!state.isVirtual()) { LOG_FATAL_IF(!displayId); - dispatchDisplayHotplugEvent(displayId->value, true); + dispatchDisplayHotplugEvent(static_cast(*displayId), true); } if (display->isPrimary()) { @@ -2670,7 +2672,7 @@ void SurfaceFlinger::processDisplayRemoved(const wp& displayToken) { if (!display->isVirtual()) { LOG_FATAL_IF(!displayId); - dispatchDisplayHotplugEvent(displayId->value, false); + dispatchDisplayHotplugEvent(static_cast(*displayId), false); } } @@ -2960,7 +2962,7 @@ void SurfaceFlinger::changeRefreshRate(const RefreshRate& refreshRate, changeRefreshRateLocked(refreshRate, event); } -void SurfaceFlinger::initScheduler(DisplayId primaryDisplayId) { +void SurfaceFlinger::initScheduler(PhysicalDisplayId primaryDisplayId) { if (mScheduler) { // In practice it's not allowed to hotplug in/out the primary display once it's been // connected during startup, but some tests do it, so just warn and return. @@ -3009,8 +3011,8 @@ void SurfaceFlinger::initScheduler(DisplayId primaryDisplayId) { // anyway since there are no connected apps at this point. const nsecs_t vsyncPeriod = mRefreshRateConfigs->getRefreshRateFromConfigId(currentConfig).getVsyncPeriod(); - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, primaryDisplayId.value, - currentConfig, vsyncPeriod); + mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, primaryDisplayId, currentConfig, + vsyncPeriod); } void SurfaceFlinger::commitTransaction() @@ -4564,7 +4566,8 @@ void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { if (!displayId) { continue; } - const auto hwcDisplayId = getHwComposer().fromPhysicalDisplayId(*displayId); + const auto hwcDisplayId = + getHwComposer().fromPhysicalDisplayId(static_cast(*displayId)); if (!hwcDisplayId) { continue; } @@ -5508,8 +5511,8 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) { } sp SurfaceFlinger::getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) { - const sp displayToken = getPhysicalDisplayTokenLocked(DisplayId{displayOrLayerStack}); - if (displayToken) { + if (const sp displayToken = + getPhysicalDisplayTokenLocked(PhysicalDisplayId{displayOrLayerStack})) { return getDisplayDeviceLocked(displayToken); } // Couldn't find display by displayId. Try to get display by layerStack since virtual displays @@ -5955,7 +5958,9 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( const nsecs_t vsyncPeriod = getHwComposer() .getConfigs(*displayId)[policy->defaultConfig.value()] ->getVsyncPeriod(); - mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle, display->getId()->value, + mScheduler->onNonPrimaryDisplayConfigChanged(mAppConnectionHandle, + static_cast( + *display->getId()), policy->defaultConfig, vsyncPeriod); return NO_ERROR; } @@ -5987,7 +5992,8 @@ status_t SurfaceFlinger::setDesiredDisplayConfigSpecsInternal( const nsecs_t vsyncPeriod = mRefreshRateConfigs->getRefreshRateFromConfigId(display->getActiveConfig()) .getVsyncPeriod(); - mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, display->getId()->value, + mScheduler->onPrimaryDisplayConfigChanged(mAppConnectionHandle, + static_cast(*display->getId()), display->getActiveConfig(), vsyncPeriod); toggleKernelIdleTimer(); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index d56321da0c..f447b0643b 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -613,7 +613,7 @@ private: void updateInputWindowInfo(); void commitInputWindowCommands() REQUIRES(mStateLock); void updateCursorAsync(); - void initScheduler(DisplayId primaryDisplayId); + void initScheduler(PhysicalDisplayId primaryDisplayId); /* handlePageFlip - latch a new buffer if available and compute the dirty * region. Returns whether a new buffer has been latched, i.e., whether it @@ -888,7 +888,8 @@ private: /* * Display identification */ - sp getPhysicalDisplayTokenLocked(DisplayId displayId) const REQUIRES(mStateLock) { + sp getPhysicalDisplayTokenLocked(PhysicalDisplayId displayId) const + REQUIRES(mStateLock) { const auto it = mPhysicalDisplayTokens.find(displayId); return it != mPhysicalDisplayTokens.end() ? it->second : nullptr; } @@ -909,7 +910,7 @@ private: return displayId ? getPhysicalDisplayTokenLocked(*displayId) : nullptr; } - std::optional getInternalDisplayIdLocked() const REQUIRES(mStateLock) { + std::optional getInternalDisplayIdLocked() const REQUIRES(mStateLock) { const auto hwcDisplayId = getHwComposer().getInternalHwcDisplayId(); return hwcDisplayId ? getHwComposer().toPhysicalDisplayId(*hwcDisplayId) : std::nullopt; } @@ -1078,7 +1079,8 @@ private: // this may only be written from the main thread with mStateLock held // it may be read from other threads with mStateLock held std::map, sp> mDisplays GUARDED_BY(mStateLock); - std::unordered_map> mPhysicalDisplayTokens GUARDED_BY(mStateLock); + std::unordered_map> mPhysicalDisplayTokens + GUARDED_BY(mStateLock); std::unordered_map> mLayersByLocalBinderToken GUARDED_BY(mStateLock); diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp index a03fd89297..87fc08a828 100644 --- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp +++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp @@ -72,6 +72,9 @@ using Attribute = V2_4::IComposerClient::Attribute; /////////////////////////////////////////////// +constexpr PhysicalDisplayId kPrimaryDisplayId = PhysicalDisplayId::fromPort(PRIMARY_DISPLAY); +constexpr PhysicalDisplayId kExternalDisplayId = PhysicalDisplayId::fromPort(EXTERNAL_DISPLAY); + struct TestColor { public: uint8_t r; @@ -272,6 +275,10 @@ protected: mFakeComposerClient->runVSyncAndWait(); } + bool waitForHotplugEvent(Display displayId, bool connected) { + return waitForHotplugEvent(PhysicalDisplayId(displayId), connected); + } + bool waitForHotplugEvent(PhysicalDisplayId displayId, bool connected) { int waitCount = 20; while (waitCount--) { @@ -280,9 +287,8 @@ protected: mReceivedDisplayEvents.pop_front(); ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, - "event hotplug: displayId %" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT - ", connected %d\t", - event.header.displayId, event.hotplug.connected); + "event hotplug: displayId %s, connected %d\t", + to_string(event.header.displayId).c_str(), event.hotplug.connected); if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG && event.header.displayId == displayId && event.hotplug.connected == connected) { @@ -295,7 +301,8 @@ protected: return false; } - bool waitForConfigChangedEvent(PhysicalDisplayId displayId, int32_t configId) { + bool waitForConfigChangedEvent(Display display, int32_t configId) { + PhysicalDisplayId displayId(display); int waitCount = 20; while (waitCount--) { while (!mReceivedDisplayEvents.empty()) { @@ -303,9 +310,8 @@ protected: mReceivedDisplayEvents.pop_front(); ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED, - "event config: displayId %" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT - ", configId %d\t", - event.header.displayId, event.config.configId); + "event config: displayId %s, configId %d\t", + to_string(event.header.displayId).c_str(), event.config.configId); if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_CONFIG_CHANGED && event.header.displayId == displayId && event.config.configId == configId) { @@ -335,7 +341,7 @@ protected: EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true)); { - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(EXTERNAL_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); DisplayConfig config; @@ -367,7 +373,7 @@ protected: EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, false)); { - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(EXTERNAL_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_TRUE(display == nullptr); DisplayConfig config; @@ -396,7 +402,7 @@ protected: waitForDisplayTransaction(); EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true)); - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(EXTERNAL_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); DisplayConfig config; @@ -503,7 +509,7 @@ protected: waitForDisplayTransaction(); EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true)); - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(EXTERNAL_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); DisplayConfig config; @@ -619,7 +625,7 @@ protected: waitForDisplayTransaction(); EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true)); - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(EXTERNAL_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId); EXPECT_FALSE(display == nullptr); DisplayConfig config; @@ -808,7 +814,7 @@ protected: EXPECT_TRUE(waitForHotplugEvent(PRIMARY_DISPLAY, false)); { - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(PRIMARY_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); EXPECT_TRUE(display == nullptr); DisplayConfig config; @@ -834,7 +840,7 @@ protected: EXPECT_TRUE(waitForHotplugEvent(PRIMARY_DISPLAY, true)); { - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(PRIMARY_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); EXPECT_FALSE(display == nullptr); DisplayConfig config; @@ -988,7 +994,7 @@ protected: ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); ALOGI("TransactionTest::SetUp - display"); - const auto display = SurfaceComposerClient::getPhysicalDisplayToken(PRIMARY_DISPLAY); + const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId); ASSERT_FALSE(display == nullptr); DisplayConfig config; diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp index 9add6a52af..7d9ac19d91 100644 --- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp +++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp @@ -81,7 +81,7 @@ constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DIS constexpr hal::HWLayerId HWC_LAYER = 5000; constexpr Transform DEFAULT_TRANSFORM = static_cast(0); -constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; +constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(42); constexpr int DEFAULT_DISPLAY_WIDTH = 1920; constexpr int DEFAULT_DISPLAY_HEIGHT = 1024; diff --git a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp index cc6a60ce27..02ce07904e 100644 --- a/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayIdentificationTest.cpp @@ -396,10 +396,10 @@ TEST(DisplayIdentificationTest, deviceProductInfo) { } } -TEST(DisplayIdentificationTest, getFallbackDisplayId) { +TEST(DisplayIdentificationTest, fromPort) { // Manufacturer ID should be invalid. - ASSERT_FALSE(getPnpId(getFallbackDisplayId(0))); - ASSERT_FALSE(getPnpId(getFallbackDisplayId(0xffu))); + ASSERT_FALSE(getPnpId(PhysicalDisplayId::fromPort(0))); + ASSERT_FALSE(getPnpId(PhysicalDisplayId::fromPort(0xffu))); } TEST(DisplayIdentificationTest, getVirtualDisplayId) { diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp index 9130b04499..175f6a86c7 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp @@ -253,7 +253,7 @@ void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { sp DisplayTransactionTest::injectDefaultInternalDisplay( std::function injectExtra) { - constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{777}; + constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(777); constexpr int DEFAULT_DISPLAY_WIDTH = 1080; constexpr int DEFAULT_DISPLAY_HEIGHT = 1920; constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0; @@ -332,10 +332,10 @@ const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp -struct PhysicalDisplayId {}; +struct PhysicalDisplayIdType {}; -template -using VirtualDisplayId = std::integral_constant; +template +using VirtualDisplayIdType = std::integral_constant; struct NoDisplayId {}; @@ -343,18 +343,18 @@ template struct IsPhysicalDisplayId : std::bool_constant {}; template -struct IsPhysicalDisplayId> : std::bool_constant {}; +struct IsPhysicalDisplayId> : std::bool_constant {}; template struct DisplayIdGetter; template -struct DisplayIdGetter> { - static std::optional get() { +struct DisplayIdGetter> { + static std::optional get() { if (!PhysicalDisplay::HAS_IDENTIFICATION_DATA) { - return getFallbackDisplayId(static_cast(PhysicalDisplay::PRIMARY) - ? LEGACY_DISPLAY_TYPE_PRIMARY - : LEGACY_DISPLAY_TYPE_EXTERNAL); + return PhysicalDisplayId::fromPort(static_cast(PhysicalDisplay::PRIMARY) + ? LEGACY_DISPLAY_TYPE_PRIMARY + : LEGACY_DISPLAY_TYPE_EXTERNAL); } const auto info = @@ -364,9 +364,10 @@ struct DisplayIdGetter> { } }; -template -struct DisplayIdGetter> { - static std::optional get() { return DisplayId{displayId}; } +template +struct DisplayIdGetter> { + // TODO(b/160679868) Use VirtualDisplayId + static std::optional get() { return PhysicalDisplayId{displayId}; } }; template <> @@ -380,7 +381,7 @@ struct DisplayConnectionTypeGetter { }; template -struct DisplayConnectionTypeGetter> { +struct DisplayConnectionTypeGetter> { static constexpr std::optional value = PhysicalDisplay::CONNECTION_TYPE; }; @@ -391,19 +392,19 @@ struct HwcDisplayIdGetter { constexpr HWDisplayId HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID = 1010; -template -struct HwcDisplayIdGetter> { +template +struct HwcDisplayIdGetter> { static constexpr std::optional value = HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID; }; template -struct HwcDisplayIdGetter> { +struct HwcDisplayIdGetter> { static constexpr std::optional value = PhysicalDisplay::HWC_DISPLAY_ID; }; // DisplayIdType can be: -// 1) PhysicalDisplayId<...> for generated ID of physical display backed by HWC. -// 2) VirtualDisplayId<...> for hard-coded ID of virtual display backed by HWC. +// 1) PhysicalDisplayIdType<...> for generated ID of physical display backed by HWC. +// 2) VirtualDisplayIdType<...> for hard-coded ID of virtual display backed by HWC. // 3) NoDisplayId for virtual display without HWC backing. template @@ -631,10 +632,11 @@ constexpr uint32_t GRALLOC_USAGE_PHYSICAL_DISPLAY = template struct PhysicalDisplayVariant - : DisplayVariant, width, height, critical, Async::FALSE, - Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, + : DisplayVariant, width, height, critical, + Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, + GRALLOC_USAGE_PHYSICAL_DISPLAY>, HwcDisplayVariant, width, height, + DisplayVariant, width, height, critical, Async::FALSE, Secure::TRUE, PhysicalDisplay::PRIMARY, GRALLOC_USAGE_PHYSICAL_DISPLAY>, PhysicalDisplay> {}; @@ -720,14 +722,14 @@ constexpr uint32_t GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY = GRALLOC_USAGE_HW_COMPOSER template struct HwcVirtualDisplayVariant - : DisplayVariant, width, height, Critical::FALSE, Async::TRUE, secure, - Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, - HwcDisplayVariant< - HWC_VIRTUAL_DISPLAY_HWC_DISPLAY_ID, DisplayType::VIRTUAL, - DisplayVariant, width, height, Critical::FALSE, Async::TRUE, - secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> { - using Base = DisplayVariant, width, height, Critical::FALSE, Async::TRUE, - secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>; + : DisplayVariant, width, height, Critical::FALSE, Async::TRUE, + secure, Primary::FALSE, GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>, + HwcDisplayVariant, width, height, Critical::FALSE, + Async::TRUE, secure, Primary::FALSE, + GRALLOC_USAGE_HWC_VIRTUAL_DISPLAY>> { + using Base = DisplayVariant, width, height, Critical::FALSE, + Async::TRUE, secure, Primary::FALSE, GRALLOC_USAGE_HW_COMPOSER>; using Self = HwcVirtualDisplayVariant; static std::shared_ptr injectCompositionDisplay( @@ -1821,7 +1823,9 @@ void SetupNewDisplayDeviceInternalTest::setupNewDisplayDeviceInternalTest() { ASSERT_TRUE(displayId); const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value; ASSERT_TRUE(hwcDisplayId); - state.physical = {.id = *displayId, .type = *connectionType, .hwcDisplayId = *hwcDisplayId}; + state.physical = {.id = static_cast(*displayId), + .type = *connectionType, + .hwcDisplayId = *hwcDisplayId}; } state.isSecure = static_cast(Case::Display::SECURE); @@ -1997,7 +2001,7 @@ void HandleTransactionLockedTest::verifyDisplayIsConnected(const sp& di ASSERT_TRUE(displayId); const auto hwcDisplayId = Case::Display::HWC_DISPLAY_ID_OPT::value; ASSERT_TRUE(hwcDisplayId); - expectedPhysical = {.id = *displayId, + expectedPhysical = {.id = static_cast(*displayId), .type = *connectionType, .hwcDisplayId = *hwcDisplayId}; } diff --git a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp index b90b566eee..aab6d01f01 100644 --- a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp +++ b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp @@ -36,9 +36,9 @@ namespace android { namespace { -constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID = 111; -constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID = 222; -constexpr PhysicalDisplayId DISPLAY_ID_64BIT = 0xabcd12349876fedcULL; +constexpr PhysicalDisplayId INTERNAL_DISPLAY_ID(111); +constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID(222); +constexpr PhysicalDisplayId DISPLAY_ID_64BIT(0xabcd12349876fedcULL); class MockVSyncSource : public VSyncSource { public: diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index 382199dc9f..f756b9e630 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -41,7 +41,7 @@ using testing::Return; namespace android { -constexpr PhysicalDisplayId PHYSICAL_DISPLAY_ID = 999; +constexpr PhysicalDisplayId PHYSICAL_DISPLAY_ID(999); class SchedulerTest : public testing::Test { protected: diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 256e048fee..215056c5b8 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -643,7 +643,9 @@ public: if (const auto type = mCreationArgs.connectionType) { LOG_ALWAYS_FATAL_IF(!displayId); LOG_ALWAYS_FATAL_IF(!mHwcDisplayId); - state.physical = {.id = *displayId, .type = *type, .hwcDisplayId = *mHwcDisplayId}; + state.physical = {.id = static_cast(*displayId), + .type = *type, + .hwcDisplayId = *mHwcDisplayId}; } state.isSecure = mCreationArgs.isSecure; -- cgit v1.2.3-59-g8ed1b