diff options
53 files changed, 784 insertions, 1075 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index d4defa8269..389b1bdadb 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -356,8 +356,6 @@ struct PointerCoords { float getAxisValue(int32_t axis) const; status_t setAxisValue(int32_t axis, float value); - void scale(float globalScale); - // Scale the pointer coordinates according to a global scale and a // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR // axes, however the window scaling will not. diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 53721cf6f7..0436758e72 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -123,11 +123,11 @@ public: return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY, data, &reply); } - status_t captureDisplay(uint64_t displayOrLayerStack, + status_t captureDisplay(DisplayId displayId, const sp<IScreenCaptureListener>& captureListener) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - SAFE_PARCEL(data.writeUint64, displayOrLayerStack); + SAFE_PARCEL(data.writeUint64, displayId.value); SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(captureListener)); return remote()->transact(BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID, data, &reply); @@ -281,9 +281,14 @@ public: NO_ERROR) { std::vector<uint64_t> rawIds; if (reply.readUint64Vector(&rawIds) == NO_ERROR) { - std::vector<PhysicalDisplayId> displayIds(rawIds.size()); - std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(), - [](uint64_t rawId) { return PhysicalDisplayId(rawId); }); + std::vector<PhysicalDisplayId> displayIds; + displayIds.reserve(rawIds.size()); + + for (const uint64_t rawId : rawIds) { + if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) { + displayIds.push_back(*id); + } + } return displayIds; } } @@ -1296,12 +1301,15 @@ status_t BnSurfaceComposer::onTransact( } case CAPTURE_DISPLAY_BY_ID: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - uint64_t displayOrLayerStack = 0; + uint64_t value; + SAFE_PARCEL(data.readUint64, &value); + const auto id = DisplayId::fromValue(value); + if (!id) return BAD_VALUE; + sp<IScreenCaptureListener> captureListener; - SAFE_PARCEL(data.readUint64, &displayOrLayerStack); SAFE_PARCEL(data.readStrongBinder, &captureListener); - return captureDisplay(displayOrLayerStack, captureListener); + return captureDisplay(*id, captureListener); } case CAPTURE_LAYERS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); @@ -1368,9 +1376,9 @@ status_t BnSurfaceComposer::onTransact( } case GET_PHYSICAL_DISPLAY_TOKEN: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - PhysicalDisplayId displayId(data.readUint64()); - sp<IBinder> display = getPhysicalDisplayToken(displayId); - reply->writeStrongBinder(display); + const auto id = DisplayId::fromValue<PhysicalDisplayId>(data.readUint64()); + if (!id) return BAD_VALUE; + reply->writeStrongBinder(getPhysicalDisplayToken(*id)); return NO_ERROR; } case GET_DISPLAY_STATE: { diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index aa938087e8..1bb63930a7 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -2125,12 +2125,12 @@ status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs, return s->captureDisplay(captureArgs, captureListener); } -status_t ScreenshotClient::captureDisplay(uint64_t displayOrLayerStack, +status_t ScreenshotClient::captureDisplay(DisplayId displayId, const sp<IScreenCaptureListener>& captureListener) { sp<ISurfaceComposer> s(ComposerService::getComposerService()); if (s == nullptr) return NO_INIT; - return s->captureDisplay(displayOrLayerStack, captureListener); + return s->captureDisplay(displayId, captureListener); } status_t ScreenshotClient::captureLayers(const LayerCaptureArgs& captureArgs, diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index cb0468901a..c420e4a8d4 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -114,6 +114,11 @@ public: using EventRegistrationFlags = Flags<EventRegistration>; + template <typename T> + struct SpHash { + size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); } + }; + /* * Create a connection with SurfaceFlinger. */ @@ -237,24 +242,17 @@ public: * The subregion can be optionally rotated. It will also be scaled to * match the size of the output buffer. */ - virtual status_t captureDisplay(const DisplayCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) = 0; + virtual status_t captureDisplay(const DisplayCaptureArgs&, + const sp<IScreenCaptureListener>&) = 0; - virtual status_t captureDisplay(uint64_t displayOrLayerStack, - const sp<IScreenCaptureListener>& captureListener) = 0; - - template <class AA> - struct SpHash { - size_t operator()(const sp<AA>& k) const { return std::hash<AA*>()(k.get()); } - }; + virtual status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&) = 0; /** * Capture a subtree of the layer hierarchy, potentially ignoring the root node. * This requires READ_FRAME_BUFFER permission. This function will fail if there * is a secure window on screen */ - virtual status_t captureLayers(const LayerCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) = 0; + virtual status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&) = 0; /* Clears the frame statistics for animations. * diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 0940e9d178..86f1b63e24 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -623,12 +623,9 @@ private: class ScreenshotClient { public: - static status_t captureDisplay(const DisplayCaptureArgs& captureArgs, - const sp<IScreenCaptureListener>& captureListener); - static status_t captureDisplay(uint64_t displayOrLayerStack, - const sp<IScreenCaptureListener>& captureListener); - static status_t captureLayers(const LayerCaptureArgs& captureArgs, - const sp<IScreenCaptureListener>& captureListener); + static status_t captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&); + static status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&); + static status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&); }; // --------------------------------------------------------------------------- diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index ea8c2957a1..7002adf1ba 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -752,21 +752,19 @@ public: } status_t setActiveColorMode(const sp<IBinder>& /*display*/, ColorMode /*colorMode*/) override { return NO_ERROR; } - status_t captureDisplay(const DisplayCaptureArgs& /* captureArgs */, - const sp<IScreenCaptureListener>& /* captureListener */) override { - return NO_ERROR; - } void setAutoLowLatencyMode(const sp<IBinder>& /*display*/, bool /*on*/) override {} void setGameContentType(const sp<IBinder>& /*display*/, bool /*on*/) override {} - status_t captureDisplay(uint64_t /*displayOrLayerStack*/, - const sp<IScreenCaptureListener>& /* captureListener */) override { + + status_t captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&) override { return NO_ERROR; } - virtual status_t captureLayers( - const LayerCaptureArgs& /* captureArgs */, - const sp<IScreenCaptureListener>& /* captureListener */) override { + status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&) override { return NO_ERROR; } + status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&) override { + return NO_ERROR; + } + status_t clearAnimationFrameStats() override { return NO_ERROR; } status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override { return NO_ERROR; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 70ed438112..124331fef1 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -307,10 +307,6 @@ void PointerCoords::scale(float globalScaleFactor, float windowXScale, float win scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, globalScaleFactor); } -void PointerCoords::scale(float globalScaleFactor) { - scale(globalScaleFactor, globalScaleFactor, globalScaleFactor); -} - void PointerCoords::applyOffset(float xOffset, float yOffset) { setAxisValue(AMOTION_EVENT_AXIS_X, getX() + xOffset); setAxisValue(AMOTION_EVENT_AXIS_Y, getY() + yOffset); diff --git a/libs/nativedisplay/AChoreographer.cpp b/libs/nativedisplay/AChoreographer.cpp index 0edb213089..e7bd977876 100644 --- a/libs/nativedisplay/AChoreographer.cpp +++ b/libs/nativedisplay/AChoreographer.cpp @@ -306,8 +306,9 @@ void Choreographer::scheduleLatestConfigRequest() { // Fortunately, these events are small so sending packets across the // socket should be atomic across processes. DisplayEventReceiver::Event event; - event.header = DisplayEventReceiver::Event::Header{DisplayEventReceiver::DISPLAY_EVENT_NULL, - PhysicalDisplayId(0), systemTime()}; + event.header = + DisplayEventReceiver::Event::Header{DisplayEventReceiver::DISPLAY_EVENT_NULL, + PhysicalDisplayId::fromPort(0), systemTime()}; injectEvent(event); } } diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h index d93a84cd25..d5e7cb299b 100644 --- a/libs/nativewindow/include/android/hardware_buffer.h +++ b/libs/nativewindow/include/android/hardware_buffer.h @@ -556,6 +556,7 @@ int AHardwareBuffer_lockAndGetInfo(AHardwareBuffer* _Nonnull buffer, uint64_t us int32_t* _Nonnull outBytesPerPixel, int32_t* _Nonnull outBytesPerStride) __INTRODUCED_IN(29); + /** * Get the system wide unique id for an AHardwareBuffer. * diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 74d17ced74..5a118eccd3 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -137,7 +137,6 @@ cc_library_shared { "HdrCapabilities.cpp", "PixelFormat.cpp", "PublicFormat.cpp", - "Size.cpp", "StaticDisplayInfo.cpp", ], diff --git a/libs/ui/Size.cpp b/libs/ui/Size.cpp deleted file mode 100644 index d2996d164d..0000000000 --- a/libs/ui/Size.cpp +++ /dev/null @@ -1,24 +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. - */ - -#include <ui/Size.h> - -namespace android::ui { - -const Size Size::INVALID{-1, -1}; -const Size Size::EMPTY{0, 0}; - -} // namespace android::ui diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index f196ab901a..9120972a42 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -38,12 +38,22 @@ struct DisplayId { uint64_t value; + // For deserialization. + static constexpr std::optional<DisplayId> fromValue(uint64_t); + + // As above, but also upcast to Id. + template <typename Id> + static constexpr std::optional<Id> fromValue(uint64_t value) { + if (const auto id = Id::tryCast(DisplayId(value))) { + return id; + } + return {}; + } + 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; } @@ -80,11 +90,8 @@ struct PhysicalDisplayId : DisplayId { // TODO(b/162612135) Remove default constructor PhysicalDisplayId() = default; - // TODO(b/162612135) Remove constructor - explicit constexpr PhysicalDisplayId(uint64_t id) : DisplayId(id) {} constexpr uint16_t getManufacturerId() const { return static_cast<uint16_t>(value >> 40); } - constexpr uint8_t getPort() const { return static_cast<uint8_t>(value); } private: @@ -96,10 +103,9 @@ private: explicit constexpr PhysicalDisplayId(DisplayId other) : DisplayId(other) {} }; -static_assert(sizeof(PhysicalDisplayId) == sizeof(uint64_t)); - struct VirtualDisplayId : DisplayId { using BaseId = uint32_t; + // Flag indicating that this virtual display is backed by the GPU. static constexpr uint64_t FLAG_GPU = 1ULL << 61; @@ -163,10 +169,23 @@ private: explicit constexpr HalDisplayId(DisplayId other) : DisplayId(other) {} }; +constexpr std::optional<DisplayId> DisplayId::fromValue(uint64_t value) { + if (const auto id = fromValue<PhysicalDisplayId>(value)) { + return id; + } + if (const auto id = fromValue<VirtualDisplayId>(value)) { + return id; + } + return {}; +} + +static_assert(sizeof(DisplayId) == sizeof(uint64_t)); +static_assert(sizeof(HalDisplayId) == sizeof(uint64_t)); static_assert(sizeof(VirtualDisplayId) == sizeof(uint64_t)); + +static_assert(sizeof(PhysicalDisplayId) == sizeof(uint64_t)); static_assert(sizeof(HalVirtualDisplayId) == sizeof(uint64_t)); static_assert(sizeof(GpuVirtualDisplayId) == sizeof(uint64_t)); -static_assert(sizeof(HalDisplayId) == sizeof(uint64_t)); } // namespace android diff --git a/libs/ui/include/ui/Size.h b/libs/ui/include/ui/Size.h index f1e825286e..ecc192dcae 100644 --- a/libs/ui/include/ui/Size.h +++ b/libs/ui/include/ui/Size.h @@ -23,103 +23,70 @@ #include <type_traits> #include <utility> -namespace android { -namespace ui { +namespace android::ui { -// Forward declare a few things. -struct Size; -bool operator==(const Size& lhs, const Size& rhs); - -/** - * A simple value type representing a two-dimensional size - */ +// A simple value type representing a two-dimensional size. struct Size { - int32_t width; - int32_t height; + int32_t width = -1; + int32_t height = -1; - // Special values - static const Size INVALID; - static const Size EMPTY; + constexpr Size() = default; - // ------------------------------------------------------------------------ - // Construction - // ------------------------------------------------------------------------ - - Size() : Size(INVALID) {} template <typename T> - Size(T&& w, T&& h) - : width(Size::clamp<int32_t, T>(std::forward<T>(w))), - height(Size::clamp<int32_t, T>(std::forward<T>(h))) {} - - // ------------------------------------------------------------------------ - // Accessors - // ------------------------------------------------------------------------ + constexpr Size(T w, T h) : width(clamp<int32_t>(w)), height(clamp<int32_t>(h)) {} int32_t getWidth() const { return width; } int32_t getHeight() const { return height; } + // Valid means non-negative width and height + bool isValid() const { return width >= 0 && height >= 0; } + + // Empty means zero width and height + bool isEmpty() const; + template <typename T> - void setWidth(T&& v) { - width = Size::clamp<int32_t, T>(std::forward<T>(v)); + void setWidth(T v) { + width = clamp<int32_t>(v); } + template <typename T> - void setHeight(T&& v) { - height = Size::clamp<int32_t, T>(std::forward<T>(v)); + void setHeight(T v) { + height = clamp<int32_t>(v); } - // ------------------------------------------------------------------------ - // Assignment - // ------------------------------------------------------------------------ + void set(Size size) { *this = size; } - void set(const Size& size) { *this = size; } template <typename T> - void set(T&& w, T&& h) { - set(Size(std::forward<T>(w), std::forward<T>(h))); + void set(T w, T h) { + set(Size(w, h)); } - // Sets the value to INVALID - void makeInvalid() { set(INVALID); } + // Sets the value to kInvalidSize + void makeInvalid(); - // Sets the value to EMPTY - void clear() { set(EMPTY); } + // Sets the value to kEmptySize + void clear(); - // ------------------------------------------------------------------------ - // Semantic checks - // ------------------------------------------------------------------------ - - // Valid means non-negative width and height - bool isValid() const { return width >= 0 && height >= 0; } - - // Empty means zero width and height - bool isEmpty() const { return *this == EMPTY; } - - // ------------------------------------------------------------------------ - // Clamp Helpers - // ------------------------------------------------------------------------ - - // Note: We use only features available in C++11 here for compatibility with - // external targets which include this file directly or indirectly and which - // themselves use C++11. - - // C++11 compatible replacement for std::remove_cv_reference_t [C++20] + // TODO: Replace with std::remove_cvref_t in C++20. template <typename T> - using remove_cv_reference_t = - typename std::remove_cv<typename std::remove_reference<T>::type>::type; + using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>; // Takes a value of type FromType, and ensures it can be represented as a value of type ToType, // clamping the input value to the output range if necessary. template <typename ToType, typename FromType> - static Size::remove_cv_reference_t<ToType> - clamp(typename std::enable_if< - std::numeric_limits<Size::remove_cv_reference_t<ToType>>::is_specialized && - std::numeric_limits<Size::remove_cv_reference_t<FromType>>::is_specialized, - FromType>::type v) { - using BareToType = remove_cv_reference_t<ToType>; - using BareFromType = remove_cv_reference_t<FromType>; - static constexpr auto toHighest = std::numeric_limits<BareToType>::max(); - static constexpr auto toLowest = std::numeric_limits<BareToType>::lowest(); - static constexpr auto fromHighest = std::numeric_limits<BareFromType>::max(); - static constexpr auto fromLowest = std::numeric_limits<BareFromType>::lowest(); + static constexpr remove_cvref_t<ToType> clamp(FromType v) { + using BareToType = remove_cvref_t<ToType>; + using ToLimits = std::numeric_limits<BareToType>; + + using BareFromType = remove_cvref_t<FromType>; + using FromLimits = std::numeric_limits<BareFromType>; + + static_assert(ToLimits::is_specialized && FromLimits::is_specialized); + + constexpr auto toHighest = ToLimits::max(); + constexpr auto toLowest = ToLimits::lowest(); + constexpr auto fromHighest = FromLimits::max(); + constexpr auto fromLowest = FromLimits::lowest(); // Get the closest representation of [toLowest, toHighest] in type // FromType to use to clamp the input value before conversion. @@ -127,37 +94,35 @@ struct Size { // std::common_type<...> is used to get a value-preserving type for the // top end of the range. using CommonHighestType = std::common_type_t<BareToType, BareFromType>; + using CommonLimits = std::numeric_limits<CommonHighestType>; // std::make_signed<std::common_type<...>> is used to get a // value-preserving type for the bottom end of the range, except this is // a bit trickier for non-integer types like float. - using CommonLowestType = - std::conditional_t<std::numeric_limits<CommonHighestType>::is_integer, - std::make_signed_t<std::conditional_t< - std::numeric_limits<CommonHighestType>::is_integer, - CommonHighestType, int /* not used */>>, - CommonHighestType>; + using CommonLowestType = std::conditional_t< + CommonLimits::is_integer, + std::make_signed_t<std::conditional_t<CommonLimits::is_integer, CommonHighestType, + int /* not used */>>, + CommonHighestType>; // We can then compute the clamp range in a way that can be later // trivially converted to either the 'from' or 'to' types, and be - // representabile in either. - static constexpr auto commonClampHighest = - std::min(static_cast<CommonHighestType>(fromHighest), - static_cast<CommonHighestType>(toHighest)); - static constexpr auto commonClampLowest = - std::max(static_cast<CommonLowestType>(fromLowest), - static_cast<CommonLowestType>(toLowest)); + // representable in either. + constexpr auto commonClampHighest = std::min(static_cast<CommonHighestType>(fromHighest), + static_cast<CommonHighestType>(toHighest)); + constexpr auto commonClampLowest = std::max(static_cast<CommonLowestType>(fromLowest), + static_cast<CommonLowestType>(toLowest)); - static constexpr auto fromClampHighest = static_cast<BareFromType>(commonClampHighest); - static constexpr auto fromClampLowest = static_cast<BareFromType>(commonClampLowest); + constexpr auto fromClampHighest = static_cast<BareFromType>(commonClampHighest); + constexpr auto fromClampLowest = static_cast<BareFromType>(commonClampLowest); // A clamp is needed only if the range we are clamping to is not the // same as the range of the input. - static constexpr bool isClampNeeded = + constexpr bool isClampNeeded = (fromLowest != fromClampLowest) || (fromHighest != fromClampHighest); // If a clamp is not needed, the conversion is just a trivial cast. - if (!isClampNeeded) { + if constexpr (!isClampNeeded) { return static_cast<BareToType>(v); } @@ -170,34 +135,46 @@ struct Size { // Otherwise clamping is done by using the already computed endpoints // for each type. - return (v <= fromClampLowest) - ? toClampLowest - : ((v >= fromClampHighest) ? toClampHighest : static_cast<BareToType>(v)); + if (v <= fromClampLowest) { + return toClampLowest; + } + + return v >= fromClampHighest ? toClampHighest : static_cast<BareToType>(v); } }; -// ------------------------------------------------------------------------ -// Comparisons -// ------------------------------------------------------------------------ +constexpr Size kInvalidSize; +constexpr Size kEmptySize{0, 0}; + +inline void Size::makeInvalid() { + set(kInvalidSize); +} -inline bool operator==(const Size& lhs, const Size& rhs) { +inline void Size::clear() { + set(kEmptySize); +} + +inline bool operator==(Size lhs, Size rhs) { return lhs.width == rhs.width && lhs.height == rhs.height; } -inline bool operator!=(const Size& lhs, const Size& rhs) { - return !operator==(lhs, rhs); +inline bool Size::isEmpty() const { + return *this == kEmptySize; +} + +inline bool operator!=(Size lhs, Size rhs) { + return !(lhs == rhs); } -inline bool operator<(const Size& lhs, const Size& rhs) { +inline bool operator<(Size lhs, Size rhs) { // Orders by increasing width, then height. if (lhs.width != rhs.width) return lhs.width < rhs.width; return lhs.height < rhs.height; } // Defining PrintTo helps with Google Tests. -static inline void PrintTo(const Size& size, ::std::ostream* os) { - *os << "Size(" << size.width << ", " << size.height << ")"; +inline void PrintTo(Size size, std::ostream* stream) { + *stream << "Size(" << size.width << ", " << size.height << ')'; } -} // namespace ui -} // namespace android +} // namespace android::ui diff --git a/libs/ui/tests/DisplayId_test.cpp b/libs/ui/tests/DisplayId_test.cpp index 1d908b8ef1..8ddee7e740 100644 --- a/libs/ui/tests/DisplayId_test.cpp +++ b/libs/ui/tests/DisplayId_test.cpp @@ -32,6 +32,9 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); EXPECT_TRUE(PhysicalDisplayId::tryCast(id)); EXPECT_TRUE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value)); } TEST(DisplayIdTest, createPhysicalIdFromPort) { @@ -43,6 +46,9 @@ TEST(DisplayIdTest, createPhysicalIdFromPort) { EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); EXPECT_TRUE(PhysicalDisplayId::tryCast(id)); EXPECT_TRUE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value)); } TEST(DisplayIdTest, createGpuVirtualId) { @@ -52,6 +58,9 @@ TEST(DisplayIdTest, createGpuVirtualId) { EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); EXPECT_FALSE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue<GpuVirtualDisplayId>(id.value)); } TEST(DisplayIdTest, createHalVirtualId) { @@ -61,6 +70,9 @@ TEST(DisplayIdTest, createHalVirtualId) { EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); EXPECT_TRUE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue<HalVirtualDisplayId>(id.value)); } } // namespace android::ui diff --git a/libs/ui/tests/Size_test.cpp b/libs/ui/tests/Size_test.cpp index 5f75aeabeb..acef47fb97 100644 --- a/libs/ui/tests/Size_test.cpp +++ b/libs/ui/tests/Size_test.cpp @@ -93,9 +93,8 @@ TEST(SizeTest, ValidAndEmpty) { } { - const auto& s = Size::INVALID; - EXPECT_FALSE(s.isValid()); - EXPECT_FALSE(s.isEmpty()); + EXPECT_FALSE(kInvalidSize.isValid()); + EXPECT_FALSE(kInvalidSize.isEmpty()); } { @@ -112,9 +111,8 @@ TEST(SizeTest, ValidAndEmpty) { } { - const auto& s = Size::EMPTY; - EXPECT_TRUE(s.isValid()); - EXPECT_TRUE(s.isEmpty()); + EXPECT_TRUE(kEmptySize.isValid()); + EXPECT_TRUE(kEmptySize.isEmpty()); } { diff --git a/services/automotive/display/AutomotiveDisplayProxyService.cpp b/services/automotive/display/AutomotiveDisplayProxyService.cpp index d6fc69562b..d205231033 100644 --- a/services/automotive/display/AutomotiveDisplayProxyService.cpp +++ b/services/automotive/display/AutomotiveDisplayProxyService.cpp @@ -34,7 +34,10 @@ AutomotiveDisplayProxyService::getIGraphicBufferProducer(uint64_t id) { sp<IBinder> displayToken = nullptr; sp<SurfaceControl> surfaceControl = nullptr; if (it == mDisplays.end()) { - displayToken = SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(id)); + if (const auto displayId = DisplayId::fromValue<PhysicalDisplayId>(id)) { + displayToken = SurfaceComposerClient::getPhysicalDisplayToken(*displayId); + } + if (displayToken == nullptr) { ALOGE("Given display id, 0x%lX, is invalid.", (unsigned long)id); return nullptr; @@ -157,7 +160,11 @@ Return<void> AutomotiveDisplayProxyService::getDisplayInfo(uint64_t id, getDispl HwDisplayConfig activeConfig; HwDisplayState activeState; - auto displayToken = SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(id)); + sp<IBinder> displayToken; + if (const auto displayId = DisplayId::fromValue<PhysicalDisplayId>(id)) { + displayToken = SurfaceComposerClient::getPhysicalDisplayToken(*displayId); + } + if (displayToken == nullptr) { ALOGE("Given display id, 0x%lX, is invalid.", (unsigned long)id); } else { diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp index 881024fc6e..8d6bd8a766 100644 --- a/services/inputflinger/dispatcher/Entry.cpp +++ b/services/inputflinger/dispatcher/Entry.cpp @@ -176,10 +176,11 @@ std::string KeyEntry::getDescription() const { } return StringPrintf("KeyEvent(deviceId=%d, eventTime=%" PRIu64 ", source=0x%08x, displayId=%" PRId32 ", action=%s, " - "flags=0x%08x, keyCode=%d, scanCode=%d, metaState=0x%08x, " + "flags=0x%08x, keyCode=%s(%d), scanCode=%d, metaState=0x%08x, " "repeatCount=%d), policyFlags=0x%08x", deviceId, eventTime, source, displayId, KeyEvent::actionToString(action), - flags, keyCode, scanCode, metaState, repeatCount, policyFlags); + flags, KeyEvent::getLabel(keyCode), keyCode, scanCode, metaState, + repeatCount, policyFlags); } void KeyEntry::recycle() { diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplayCreationArgs.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplayCreationArgs.h index 633668e1c2..526e7daa80 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplayCreationArgs.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/DisplayCreationArgs.h @@ -21,13 +21,10 @@ #include <string> #include <ui/DisplayId.h> -#include <ui/PixelFormat.h> #include <ui/Size.h> #include <ui/StaticDisplayInfo.h> -#include "DisplayHardware/DisplayIdentification.h" #include "DisplayHardware/PowerAdvisor.h" -#include "DisplayIdGenerator.h" namespace android::compositionengine { @@ -37,23 +34,13 @@ class CompositionEngine; * A parameter object for creating Display instances */ struct DisplayCreationArgs { - struct Physical { - DisplayId id; - ui::DisplayConnectionType type; - }; + DisplayId id; - // Required for physical displays. Gives the HWC display id for the existing - // display along with the connection type. - std::optional<Physical> physical; + // Unset for virtual displays + std::optional<ui::DisplayConnectionType> connectionType; // Size of the display in pixels - ui::Size pixels = ui::Size::INVALID; - - // Pixel format of the display - ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN); - - // True if virtual displays should be created with the HWC API if possible - bool useHwcVirtualDisplays = false; + ui::Size pixels = ui::kInvalidSize; // True if this display should be considered secure bool isSecure = false; @@ -67,9 +54,6 @@ struct DisplayCreationArgs { // Debugging. Human readable name for the display. std::string name; - - // Generator for IDs of virtual displays, which are backed by the GPU. - DisplayIdGenerator<GpuVirtualDisplayId>* gpuVirtualDisplayIdGenerator; }; /** @@ -80,29 +64,18 @@ class DisplayCreationArgsBuilder { public: DisplayCreationArgs build() { return std::move(mArgs); } - DisplayCreationArgsBuilder& setPhysical(DisplayCreationArgs::Physical physical) { - mArgs.physical = physical; + DisplayCreationArgsBuilder& setId(DisplayId id) { + mArgs.id = id; return *this; } - DisplayCreationArgsBuilder& setPixels(ui::Size pixels) { - mArgs.pixels = pixels; + DisplayCreationArgsBuilder& setConnectionType(ui::DisplayConnectionType connectionType) { + mArgs.connectionType = connectionType; return *this; } - DisplayCreationArgsBuilder& setPixelFormat(ui::PixelFormat pixelFormat) { - mArgs.pixelFormat = pixelFormat; - return *this; - } - - DisplayCreationArgsBuilder& setUseHwcVirtualDisplays(bool useHwcVirtualDisplays) { - mArgs.useHwcVirtualDisplays = useHwcVirtualDisplays; - return *this; - } - - DisplayCreationArgsBuilder& setGpuVirtualDisplayIdGenerator( - DisplayIdGenerator<GpuVirtualDisplayId>& generator) { - mArgs.gpuVirtualDisplayIdGenerator = &generator; + DisplayCreationArgsBuilder& setPixels(ui::Size pixels) { + mArgs.pixels = pixels; return *this; } diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/RenderSurfaceCreationArgs.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/RenderSurfaceCreationArgs.h index a8d372c562..4110346aa3 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/RenderSurfaceCreationArgs.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/RenderSurfaceCreationArgs.h @@ -24,21 +24,17 @@ struct ANativeWindow; -namespace android { - -namespace compositionengine { - -class Display; +namespace android::compositionengine { /** * A parameter object for creating RenderSurface instances */ struct RenderSurfaceCreationArgs { // The initial width of the surface - int32_t displayWidth; + int32_t displayWidth = -1; // The initial height of the surface - int32_t displayHeight; + int32_t displayHeight = -1; // The ANativeWindow for the buffer queue for this surface sp<ANativeWindow> nativeWindow; @@ -46,22 +42,16 @@ struct RenderSurfaceCreationArgs { // The DisplaySurface for this surface sp<DisplaySurface> displaySurface; - size_t maxTextureCacheSize; + // The maximum size of the renderengine::ExternalTexture cache + size_t maxTextureCacheSize = 0; + +private: + friend class RenderSurfaceCreationArgsBuilder; + + // Not defaulted to disable aggregate initialization. + RenderSurfaceCreationArgs() {} }; -/** - * A helper for setting up a RenderSurfaceCreationArgs value in-line. - * Prefer this builder over raw structure initialization. - * - * Instead of: - * - * RenderSurfaceCreationArgs{1000, 1000, nativeWindow, displaySurface} - * - * Prefer: - * - * RenderSurfaceCreationArgsBuilder().setDisplayWidth(1000).setDisplayHeight(1000) - * .setNativeWindow(nativeWindow).setDisplaySurface(displaySurface).Build(); - */ class RenderSurfaceCreationArgsBuilder { public: RenderSurfaceCreationArgs build() { return std::move(mArgs); } @@ -75,11 +65,11 @@ public: return *this; } RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) { - mArgs.nativeWindow = nativeWindow; + mArgs.nativeWindow = std::move(nativeWindow); return *this; } RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) { - mArgs.displaySurface = displaySurface; + mArgs.displaySurface = std::move(displaySurface); return *this; } @@ -92,5 +82,4 @@ private: RenderSurfaceCreationArgs mArgs; }; -} // namespace compositionengine -} // namespace android +} // namespace android::compositionengine diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h index 54e91ae6be..bb540ea7ee 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h @@ -80,19 +80,13 @@ public: // Internal virtual void setConfiguration(const compositionengine::DisplayCreationArgs&); - virtual std::optional<DisplayId> maybeAllocateDisplayIdForVirtualDisplay(ui::Size, - ui::PixelFormat) const; std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const; - // Testing - void setDisplayIdForTesting(DisplayId displayId); - private: bool mIsVirtual = false; bool mIsDisconnected = false; DisplayId mId; Hwc2::PowerAdvisor* mPowerAdvisor = nullptr; - DisplayIdGenerator<GpuVirtualDisplayId>* mGpuVirtualDisplayIdGenerator; }; // This template factory function standardizes the implementation details of the diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index 953eb76b63..be28449bc5 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -50,36 +50,14 @@ std::shared_ptr<Display> createDisplay( Display::~Display() = default; void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) { - mIsVirtual = !args.physical; + mId = args.id; + mIsVirtual = !args.connectionType; mPowerAdvisor = args.powerAdvisor; editState().isSecure = args.isSecure; editState().displaySpace.bounds = Rect(args.pixels); setLayerStackFilter(args.layerStackId, - args.physical && - args.physical->type == ui::DisplayConnectionType::Internal); + args.connectionType == ui::DisplayConnectionType::Internal); setName(args.name); - mGpuVirtualDisplayIdGenerator = args.gpuVirtualDisplayIdGenerator; - - if (args.physical) { - mId = args.physical->id; - } else { - std::optional<DisplayId> id; - if (args.useHwcVirtualDisplays) { - id = maybeAllocateDisplayIdForVirtualDisplay(args.pixels, args.pixelFormat); - } - if (!id) { - id = mGpuVirtualDisplayIdGenerator->nextId(); - } - LOG_ALWAYS_FATAL_IF(!id, "Failed to generate display ID"); - mId = *id; - } -} - -std::optional<DisplayId> Display::maybeAllocateDisplayIdForVirtualDisplay( - ui::Size pixels, ui::PixelFormat pixelFormat) const { - auto& hwc = getCompositionEngine().getHwComposer(); - return hwc.allocateVirtualDisplay(static_cast<uint32_t>(pixels.width), - static_cast<uint32_t>(pixels.height), &pixelFormat); } bool Display::isValid() const { @@ -102,23 +80,16 @@ std::optional<DisplayId> Display::getDisplayId() const { return mId; } -void Display::setDisplayIdForTesting(DisplayId displayId) { - mId = displayId; -} - void Display::disconnect() { if (mIsDisconnected) { return; } mIsDisconnected = true; - if (const auto id = GpuVirtualDisplayId::tryCast(mId)) { - mGpuVirtualDisplayIdGenerator->markUnused(*id); - return; + + if (const auto id = HalDisplayId::tryCast(mId)) { + getCompositionEngine().getHwComposer().disconnectDisplay(*id); } - const auto halDisplayId = HalDisplayId::tryCast(mId); - LOG_FATAL_IF(!halDisplayId); - getCompositionEngine().getHwComposer().disconnectDisplay(*halDisplayId); } void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) { diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp index e12cb57feb..1a7f75f9e4 100644 --- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.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 "-Wextra" - #include <cmath> #include <compositionengine/DisplayColorProfileCreationArgs.h> @@ -60,12 +56,12 @@ using testing::Sequence; using testing::SetArgPointee; using testing::StrictMock; -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; +constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u); +constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u}; +constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u}; + +constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080}; +constexpr uint32_t DEFAULT_LAYER_STACK = 42; struct Layer { Layer() { @@ -94,8 +90,6 @@ struct DisplayTestCommon : public testing::Test { public: using impl::Display::injectOutputLayerForTest; virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0; - - using impl::Display::maybeAllocateDisplayIdForVirtualDisplay; }; // Uses a special implementation with key internal member functions set up @@ -169,21 +163,19 @@ struct DisplayTestCommon : public testing::Test { DisplayCreationArgs getDisplayCreationArgsForPhysicalHWCDisplay() { return DisplayCreationArgsBuilder() - .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal}) - .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(ui::DisplayConnectionType::Internal) + .setPixels(DEFAULT_RESOLUTION) .setIsSecure(true) .setLayerStackId(DEFAULT_LAYER_STACK) .setPowerAdvisor(&mPowerAdvisor) .build(); } - DisplayCreationArgs getDisplayCreationArgsForNonHWCVirtualDisplay() { + DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() { return DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(false) - .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator) - .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) + .setId(GPU_VIRTUAL_DISPLAY_ID) + .setPixels(DEFAULT_RESOLUTION) .setIsSecure(false) .setLayerStackId(DEFAULT_LAYER_STACK) .setPowerAdvisor(&mPowerAdvisor) @@ -195,7 +187,6 @@ struct DisplayTestCommon : public testing::Test { StrictMock<renderengine::mock::RenderEngine> mRenderEngine; StrictMock<mock::CompositionEngine> mCompositionEngine; sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); - RandomDisplayIdGenerator<GpuVirtualDisplayId> mGpuDisplayIdGenerator; }; struct PartialMockDisplayTestCommon : public DisplayTestCommon { @@ -247,9 +238,9 @@ TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) { EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId()); } -TEST_F(DisplayCreationTest, createNonHwcVirtualDisplay) { - auto display = impl::createDisplay(mCompositionEngine, - getDisplayCreationArgsForNonHWCVirtualDisplay()); +TEST_F(DisplayCreationTest, createGpuVirtualDisplay) { + auto display = + impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay()); EXPECT_FALSE(display->isSecure()); EXPECT_TRUE(display->isVirtual()); EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId())); @@ -262,17 +253,15 @@ TEST_F(DisplayCreationTest, createNonHwcVirtualDisplay) { using DisplaySetConfigurationTest = PartialMockDisplayTestCommon; TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) { - mDisplay->setConfiguration( - DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(true) - .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal}) - .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) - .setIsSecure(true) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&mPowerAdvisor) - .setName(getDisplayNameFromCurrentTest()) - .build()); + mDisplay->setConfiguration(DisplayCreationArgsBuilder() + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(ui::DisplayConnectionType::Internal) + .setPixels(DEFAULT_RESOLUTION) + .setIsSecure(true) + .setLayerStackId(DEFAULT_LAYER_STACK) + .setPowerAdvisor(&mPowerAdvisor) + .setName(getDisplayNameFromCurrentTest()) + .build()); EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId()); EXPECT_TRUE(mDisplay->isSecure()); @@ -283,17 +272,15 @@ TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) { } TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) { - mDisplay->setConfiguration( - DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(true) - .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::External}) - .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) - .setIsSecure(false) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&mPowerAdvisor) - .setName(getDisplayNameFromCurrentTest()) - .build()); + mDisplay->setConfiguration(DisplayCreationArgsBuilder() + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(ui::DisplayConnectionType::External) + .setPixels(DEFAULT_RESOLUTION) + .setIsSecure(false) + .setLayerStackId(DEFAULT_LAYER_STACK) + .setPowerAdvisor(&mPowerAdvisor) + .setName(getDisplayNameFromCurrentTest()) + .build()); EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId()); EXPECT_FALSE(mDisplay->isSecure()); @@ -303,52 +290,17 @@ TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) { EXPECT_FALSE(mDisplay->isValid()); } -TEST_F(DisplaySetConfigurationTest, configuresHwcBackedVirtualDisplay) { - EXPECT_CALL(mHwComposer, - allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH, - Pointee(Eq(static_cast<ui::PixelFormat>( - PIXEL_FORMAT_RGBA_8888))))) - .WillOnce(Return(VIRTUAL_DISPLAY_ID)); - - mDisplay->setConfiguration( - DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(true) - .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) - .setIsSecure(false) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&mPowerAdvisor) - .setName(getDisplayNameFromCurrentTest()) - .build()); - - EXPECT_EQ(VIRTUAL_DISPLAY_ID, mDisplay->getId()); - EXPECT_FALSE(mDisplay->isSecure()); - EXPECT_TRUE(mDisplay->isVirtual()); - EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); - EXPECT_FALSE(mDisplay->getState().layerStackInternal); - EXPECT_FALSE(mDisplay->isValid()); -} +TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) { + mDisplay->setConfiguration(DisplayCreationArgsBuilder() + .setId(HAL_VIRTUAL_DISPLAY_ID) + .setPixels(DEFAULT_RESOLUTION) + .setIsSecure(false) + .setLayerStackId(DEFAULT_LAYER_STACK) + .setPowerAdvisor(&mPowerAdvisor) + .setName(getDisplayNameFromCurrentTest()) + .build()); -TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfHwcAllocationFails) { - EXPECT_CALL(mHwComposer, - allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH, - Pointee(Eq(static_cast<ui::PixelFormat>( - PIXEL_FORMAT_RGBA_8888))))) - .WillOnce(Return(std::nullopt)); - - mDisplay->setConfiguration( - DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(true) - .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator) - .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) - .setIsSecure(false) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&mPowerAdvisor) - .setName(getDisplayNameFromCurrentTest()) - .build()); - - EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId())); + EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId()); EXPECT_FALSE(mDisplay->isSecure()); EXPECT_TRUE(mDisplay->isVirtual()); EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); @@ -356,20 +308,17 @@ TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfHwcAll EXPECT_FALSE(mDisplay->isValid()); } -TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfShouldNotUseHwc) { - mDisplay->setConfiguration( - DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(false) - .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator) - .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH)) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) - .setIsSecure(false) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&mPowerAdvisor) - .setName(getDisplayNameFromCurrentTest()) - .build()); - - EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId())); +TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) { + mDisplay->setConfiguration(DisplayCreationArgsBuilder() + .setId(GPU_VIRTUAL_DISPLAY_ID) + .setPixels(DEFAULT_RESOLUTION) + .setIsSecure(false) + .setLayerStackId(DEFAULT_LAYER_STACK) + .setPowerAdvisor(&mPowerAdvisor) + .setName(getDisplayNameFromCurrentTest()) + .build()); + + EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId()); EXPECT_FALSE(mDisplay->isSecure()); EXPECT_TRUE(mDisplay->isVirtual()); EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId); @@ -476,7 +425,7 @@ TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) { TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) { using ColorProfile = Output::ColorProfile; - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args); mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>(); @@ -521,7 +470,11 @@ using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon; TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) { EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR)); EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr); - mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr}); + mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder() + .setDisplayWidth(640) + .setDisplayHeight(480) + .setNativeWindow(mNativeWindow) + .build()); EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr); } @@ -551,25 +504,25 @@ TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) { using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon; -TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNotHwcDisplay) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); +TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) { + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args); sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>(); { Output::ReleasedLayers releasedLayers; releasedLayers.emplace_back(layerXLayerFE); - nonHwcDisplay->setReleasedLayers(std::move(releasedLayers)); + gpuDisplay->setReleasedLayers(std::move(releasedLayers)); } CompositionRefreshArgs refreshArgs; refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE); - nonHwcDisplay->setReleasedLayers(refreshArgs); + gpuDisplay->setReleasedLayers(refreshArgs); - const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest(); - ASSERT_EQ(1, releasedLayers.size()); + const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest(); + ASSERT_EQ(1u, releasedLayers.size()); } TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) { @@ -585,7 +538,7 @@ TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) { mDisplay->setReleasedLayers(refreshArgs); const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); - ASSERT_EQ(1, releasedLayers.size()); + ASSERT_EQ(1u, releasedLayers.size()); } TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) { @@ -599,7 +552,7 @@ TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) { mDisplay->setReleasedLayers(refreshArgs); const auto& releasedLayers = mDisplay->getReleasedLayersForTest(); - ASSERT_EQ(2, releasedLayers.size()); + ASSERT_EQ(2u, releasedLayers.size()); ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get()); ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get()); } @@ -610,15 +563,15 @@ TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) { using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon; -TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - std::shared_ptr<Display> nonHwcDisplay = +TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) { + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + std::shared_ptr<Display> gpuDisplay = createPartialMockDisplay<Display>(mCompositionEngine, args); - EXPECT_TRUE(GpuVirtualDisplayId::tryCast(nonHwcDisplay->getId())); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId())); - nonHwcDisplay->chooseCompositionStrategy(); + gpuDisplay->chooseCompositionStrategy(); - auto& state = nonHwcDisplay->getState(); + auto& state = gpuDisplay->getState(); EXPECT_TRUE(state.usesClientComposition); EXPECT_FALSE(state.usesDeviceComposition); } @@ -700,12 +653,12 @@ TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) { using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon; -TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfNonHwcDisplay) { +TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) { EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM)) .WillOnce(Return(true)); - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)}; - EXPECT_TRUE(nonHwcDisplay->getSkipColorTransform()); + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)}; + EXPECT_TRUE(gpuDisplay->getSkipColorTransform()); } TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) { @@ -852,11 +805,11 @@ TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) { using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon; -TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnNonHwcDisplay) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)}; +TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) { + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)}; - auto result = nonHwcDisplay->presentAndGetFrameFences(); + auto result = gpuDisplay->presentAndGetFrameFences(); ASSERT_TRUE(result.presentFence.get()); EXPECT_FALSE(result.presentFence->isValid()); @@ -885,9 +838,9 @@ TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) { EXPECT_EQ(presentFence, result.presentFence); EXPECT_EQ(2u, result.layerFences.size()); - ASSERT_EQ(1, result.layerFences.count(&mLayer1.hwc2Layer)); + ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer)); EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]); - ASSERT_EQ(1, result.layerFences.count(&mLayer2.hwc2Layer)); + ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer)); EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]); } @@ -933,66 +886,66 @@ TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) { } TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args); mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); - nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); + gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); // We expect no calls to queueBuffer if composition was skipped. EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0); - nonHwcDisplay->editState().isEnabled = true; - nonHwcDisplay->editState().usesClientComposition = false; - nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); - nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; + gpuDisplay->editState().isEnabled = true; + gpuDisplay->editState().usesClientComposition = false; + gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); + gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION; CompositionRefreshArgs refreshArgs; refreshArgs.repaintEverything = false; - nonHwcDisplay->finishFrame(refreshArgs); + gpuDisplay->finishFrame(refreshArgs); } TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args); mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); - nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); + gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); // We expect a single call to queueBuffer when composition is not skipped. EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); - nonHwcDisplay->editState().isEnabled = true; - nonHwcDisplay->editState().usesClientComposition = false; - nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); - nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1)); + gpuDisplay->editState().isEnabled = true; + gpuDisplay->editState().usesClientComposition = false; + gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); + gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1)); CompositionRefreshArgs refreshArgs; refreshArgs.repaintEverything = false; - nonHwcDisplay->finishFrame(refreshArgs); + gpuDisplay->finishFrame(refreshArgs); } TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) { - auto args = getDisplayCreationArgsForNonHWCVirtualDisplay(); - std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args); + auto args = getDisplayCreationArgsForGpuVirtualDisplay(); + std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args); mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>(); - nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); + gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface)); // We expect a single call to queueBuffer when composition is not skipped. EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1); - nonHwcDisplay->editState().isEnabled = true; - nonHwcDisplay->editState().usesClientComposition = false; - nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); - nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION; + gpuDisplay->editState().isEnabled = true; + gpuDisplay->editState().usesClientComposition = false; + gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1); + gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION; CompositionRefreshArgs refreshArgs; refreshArgs.repaintEverything = true; - nonHwcDisplay->finishFrame(refreshArgs); + gpuDisplay->finishFrame(refreshArgs); } /* @@ -1017,23 +970,26 @@ struct DisplayFunctionalTest : public testing::Test { NiceMock<mock::CompositionEngine> mCompositionEngine; sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>(); sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>(); + std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated< Display>(mCompositionEngine, DisplayCreationArgsBuilder() - .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal}) - .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) - .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888)) + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(ui::DisplayConnectionType::Internal) + .setPixels(DEFAULT_RESOLUTION) .setIsSecure(true) .setLayerStackId(DEFAULT_LAYER_STACK) .setPowerAdvisor(&mPowerAdvisor) - .build() + .build()); - ); impl::RenderSurface* mRenderSurface = new impl::RenderSurface{mCompositionEngine, *mDisplay, - RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, - DEFAULT_DISPLAY_HEIGHT, mNativeWindow, - mDisplaySurface}}; + RenderSurfaceCreationArgsBuilder() + .setDisplayWidth(DEFAULT_RESOLUTION.width) + .setDisplayHeight(DEFAULT_RESOLUTION.height) + .setNativeWindow(mNativeWindow) + .setDisplaySurface(mDisplaySurface) + .build()}; }; TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) { @@ -1049,6 +1005,3 @@ TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) { } // namespace } // namespace android::compositionengine - -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic pop // ignored "-Wextra"
\ No newline at end of file diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h index cd2d09e3db..72de0b12a2 100644 --- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h +++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h @@ -39,15 +39,19 @@ public: HWComposer(); ~HWComposer() override; - MOCK_METHOD2(setConfiguration, void(HWC2::ComposerCallback*, int32_t)); + MOCK_METHOD1(setCallback, void(HWC2::ComposerCallback*)); MOCK_CONST_METHOD3(getDisplayIdentificationData, bool(hal::HWDisplayId, uint8_t*, DisplayIdentificationData*)); MOCK_CONST_METHOD1(hasCapability, bool(hal::Capability)); MOCK_CONST_METHOD2(hasDisplayCapability, bool(HalDisplayId, hal::DisplayCapability)); - MOCK_METHOD3(allocateVirtualDisplay, - std::optional<DisplayId>(uint32_t, uint32_t, ui::PixelFormat*)); + MOCK_CONST_METHOD0(getMaxVirtualDisplayCount, size_t()); + MOCK_CONST_METHOD0(getMaxVirtualDisplayDimension, size_t()); + MOCK_METHOD4(allocateVirtualDisplay, + bool(HalVirtualDisplayId, ui::Size, ui::PixelFormat*, + std::optional<PhysicalDisplayId>)); MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, PhysicalDisplayId)); + MOCK_METHOD1(createLayer, std::shared_ptr<HWC2::Layer>(HalDisplayId)); MOCK_METHOD4(getDeviceCompositionChanges, status_t(HalDisplayId, bool, std::chrono::steady_clock::time_point, diff --git a/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp b/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp index 9aeb290eb5..431cc93514 100644 --- a/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/RenderSurfaceTest.cpp @@ -14,12 +14,6 @@ * limitations under the License. */ -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#include "renderengine/ExternalTexture.h" -#include "ui/GraphicBuffer.h" -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wextra" - #include <cstdarg> #include <cstdint> @@ -32,14 +26,16 @@ #include <compositionengine/mock/NativeWindow.h> #include <compositionengine/mock/OutputLayer.h> #include <gtest/gtest.h> +#include <renderengine/ExternalTexture.h> #include <renderengine/mock/RenderEngine.h> +#include <ui/GraphicBuffer.h> namespace android::compositionengine { namespace { constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920; constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080; -constexpr DisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId(123u); +constexpr DisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u); const std::string DEFAULT_DISPLAY_NAME = "Mock Display"; using testing::_; @@ -67,9 +63,12 @@ public: sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>(); sp<mock::DisplaySurface> mDisplaySurface = new StrictMock<mock::DisplaySurface>(); impl::RenderSurface mSurface{mCompositionEngine, mDisplay, - RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH, - DEFAULT_DISPLAY_HEIGHT, mNativeWindow, - mDisplaySurface}}; + RenderSurfaceCreationArgsBuilder() + .setDisplayWidth(DEFAULT_DISPLAY_WIDTH) + .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT) + .setNativeWindow(mNativeWindow) + .setDisplaySurface(mDisplaySurface) + .build()}; }; /* @@ -367,11 +366,8 @@ TEST_F(RenderSurfaceTest, flipForwardsSignal) { mSurface.flip(); - EXPECT_EQ(501, mSurface.getPageFlipCount()); + EXPECT_EQ(501u, mSurface.getPageFlipCount()); } } // namespace } // namespace android::compositionengine - -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic pop // ignored "-Wextra"
\ No newline at end of file diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 0f18235751..ca4b6abc03 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -70,13 +70,14 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args) mIsPrimary(args.isPrimary) { mCompositionDisplay->editState().isSecure = args.isSecure; mCompositionDisplay->createRenderSurface( - compositionengine:: - RenderSurfaceCreationArgs{ANativeWindow_getWidth(args.nativeWindow.get()), - ANativeWindow_getHeight(args.nativeWindow.get()), - args.nativeWindow, args.displaySurface, - static_cast<size_t>( - SurfaceFlinger:: - maxFrameBufferAcquiredBuffers)}); + compositionengine::RenderSurfaceCreationArgsBuilder() + .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get())) + .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get())) + .setNativeWindow(std::move(args.nativeWindow)) + .setDisplaySurface(std::move(args.displaySurface)) + .setMaxTextureCacheSize( + static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)) + .build()); if (!mFlinger->mDisableClientCompositionCache && SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) { diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index bf249cdb25..33c25631bb 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -103,15 +103,21 @@ public: bool needsFiltering() const; ui::LayerStack getLayerStack() const; - // Returns the physical ID of this display. This function asserts the ID is physical and it - // shouldn't be called for other display types, e.g. virtual. + DisplayId getId() const; + + // Shorthand to upcast the ID of a display whose type is known as a precondition. PhysicalDisplayId getPhysicalId() const { - const auto displayIdOpt = PhysicalDisplayId::tryCast(getId()); - LOG_FATAL_IF(!displayIdOpt); - return *displayIdOpt; + const auto id = PhysicalDisplayId::tryCast(getId()); + LOG_FATAL_IF(!id); + return *id; + } + + VirtualDisplayId getVirtualId() const { + const auto id = VirtualDisplayId::tryCast(getId()); + LOG_FATAL_IF(!id); + return *id; } - DisplayId getId() const; const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } int32_t getSequenceId() const { return mSequenceId; } diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp index 1cbcf592db..caf0294a56 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp @@ -211,9 +211,8 @@ uint32_t Composer::getMaxVirtualDisplayCount() return unwrapRet(ret, 0); } -Error Composer::createVirtualDisplay(uint32_t width, uint32_t height, - PixelFormat* format, Display* outDisplay) -{ +Error Composer::createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, + std::optional<Display>, Display* outDisplay) { const uint32_t bufferSlotCount = 1; Error error = kDefaultError; if (mClient_2_2) { diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h index 0619b8c444..b525e63c66 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h @@ -18,6 +18,7 @@ #define ANDROID_SF_COMPOSER_HAL_H #include <memory> +#include <optional> #include <string> #include <unordered_map> #include <utility> @@ -94,8 +95,8 @@ public: virtual Error executeCommands() = 0; virtual uint32_t getMaxVirtualDisplayCount() = 0; - virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, - Display* outDisplay) = 0; + virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat*, + std::optional<Display> mirror, Display* outDisplay) = 0; virtual Error destroyVirtualDisplay(Display display) = 0; virtual Error acceptDisplayChanges(Display display) = 0; @@ -341,7 +342,7 @@ public: uint32_t getMaxVirtualDisplayCount() override; Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format, - Display* outDisplay) override; + std::optional<Display> mirror, Display* outDisplay) override; Error destroyVirtualDisplay(Display display) override; Error acceptDisplayChanges(Display display) override; diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index fae95e79c3..871465d717 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -56,20 +56,16 @@ namespace hal = android::hardware::graphics::composer::hal; // 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 onHotplugReceived() function will +// when first registering the callback the onComposerHalHotplug() function will // immediately be called on the thread calling registerCallback(). -// -// All calls receive a sequenceId, which will be the value that was supplied to -// HWC2::Device::registerCallback(). It's used to help differentiate callbacks -// from different hardware composer instances. struct ComposerCallback { - virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId, hal::Connection) = 0; - virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId) = 0; - virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp, - std::optional<hal::VsyncPeriodNanos>) = 0; - virtual void onVsyncPeriodTimingChangedReceived(int32_t sequenceId, hal::HWDisplayId, - const hal::VsyncPeriodChangeTimeline&) = 0; - virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId) = 0; + virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0; + virtual void onComposerHalRefresh(hal::HWDisplayId) = 0; + virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp, + std::optional<hal::VsyncPeriodNanos>) = 0; + virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, + const hal::VsyncPeriodChangeTimeline&) = 0; + virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0; protected: ~ComposerCallback() = default; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 36876dc7f1..32f04e56bc 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -38,7 +38,6 @@ #include <utils/Trace.h> #include "../Layer.h" // needed only for debugging -#include "../SurfaceFlinger.h" #include "../SurfaceFlingerProperties.h" #include "ComposerHal.h" #include "HWC2.h" @@ -83,25 +82,22 @@ using android::HWC2::ComposerCallback; class ComposerCallbackBridge : public hal::IComposerCallback { public: - ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId, - bool vsyncSwitchingSupported) - : mCallback(callback), - mSequenceId(sequenceId), - mVsyncSwitchingSupported(vsyncSwitchingSupported) {} - - Return<void> onHotplug(hal::HWDisplayId display, hal::Connection conn) override { - mCallback->onHotplugReceived(mSequenceId, display, conn); + ComposerCallbackBridge(ComposerCallback* callback, bool vsyncSwitchingSupported) + : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {} + + Return<void> onHotplug(hal::HWDisplayId display, hal::Connection connection) override { + mCallback->onComposerHalHotplug(display, connection); return Void(); } Return<void> onRefresh(hal::HWDisplayId display) override { - mCallback->onRefreshReceived(mSequenceId, display); + mCallback->onComposerHalRefresh(display); return Void(); } Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override { if (!mVsyncSwitchingSupported) { - mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt); + mCallback->onComposerHalVsync(display, timestamp, std::nullopt); } else { ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring."); } @@ -111,8 +107,7 @@ public: Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp, hal::VsyncPeriodNanos vsyncPeriodNanos) override { if (mVsyncSwitchingSupported) { - mCallback->onVsyncReceived(mSequenceId, display, timestamp, - std::make_optional(vsyncPeriodNanos)); + mCallback->onComposerHalVsync(display, timestamp, vsyncPeriodNanos); } else { ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring."); } @@ -120,20 +115,18 @@ public: } Return<void> onVsyncPeriodTimingChanged( - hal::HWDisplayId display, - const hal::VsyncPeriodChangeTimeline& updatedTimeline) override { - mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline); + hal::HWDisplayId display, const hal::VsyncPeriodChangeTimeline& timeline) override { + mCallback->onComposerHalVsyncPeriodTimingChanged(display, timeline); return Void(); } Return<void> onSeamlessPossible(hal::HWDisplayId display) override { - mCallback->onSeamlessPossible(mSequenceId, display); + mCallback->onComposerHalSeamlessPossible(display); return Void(); } private: - ComposerCallback* mCallback; - const int32_t mSequenceId; + ComposerCallback* const mCallback; const bool mVsyncSwitchingSupported; }; @@ -145,8 +138,9 @@ namespace impl { HWComposer::HWComposer(std::unique_ptr<Hwc2::Composer> composer) : mComposer(std::move(composer)), + mMaxVirtualDisplayDimension(static_cast<size_t>(sysprop::max_virtual_display_dimension(0))), mUpdateDeviceProductInfoOnHotplugReconnect( - android::sysprop::update_device_product_info_on_hotplug_reconnect(false)) {} + sysprop::update_device_product_info_on_hotplug_reconnect(false)) {} HWComposer::HWComposer(const std::string& composerServiceName) : HWComposer(std::make_unique<Hwc2::impl::Composer>(composerServiceName)) {} @@ -155,7 +149,7 @@ HWComposer::~HWComposer() { mDisplayData.clear(); } -void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) { +void HWComposer::setCallback(HWC2::ComposerCallback* callback) { loadCapabilities(); loadLayerMetadataSupport(); @@ -164,10 +158,9 @@ void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequ return; } mRegisteredCallback = true; - sp<ComposerCallbackBridge> callbackBridge( - new ComposerCallbackBridge(callback, sequenceId, - mComposer->isVsyncPeriodSwitchSupported())); - mComposer->registerCallback(callbackBridge); + + mComposer->registerCallback( + sp<ComposerCallbackBridge>::make(callback, mComposer->isVsyncPeriodSwitchSupported())); } bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort, @@ -243,38 +236,49 @@ bool HWComposer::onVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp) { return true; } -std::optional<DisplayId> HWComposer::allocateVirtualDisplay(uint32_t width, uint32_t height, - ui::PixelFormat* format) { - if (SurfaceFlinger::maxVirtualDisplaySize != 0 && - (width > SurfaceFlinger::maxVirtualDisplaySize || - height > SurfaceFlinger::maxVirtualDisplaySize)) { - ALOGE("%s: Display size %ux%u exceeds maximum dimension of %" PRIu64, __FUNCTION__, width, - height, SurfaceFlinger::maxVirtualDisplaySize); - return {}; +size_t HWComposer::getMaxVirtualDisplayCount() const { + return mComposer->getMaxVirtualDisplayCount(); +} + +size_t HWComposer::getMaxVirtualDisplayDimension() const { + return mMaxVirtualDisplayDimension; +} + +bool HWComposer::allocateVirtualDisplay(HalVirtualDisplayId displayId, ui::Size resolution, + ui::PixelFormat* format, + std::optional<PhysicalDisplayId> mirror) { + if (!resolution.isValid()) { + ALOGE("%s: Invalid resolution %dx%d", __func__, resolution.width, resolution.height); + return false; } - const auto displayId = mVirtualIdGenerator.nextId(); - if (!displayId) { - ALOGE("%s: No remaining virtual displays", __FUNCTION__); - return {}; + const uint32_t width = static_cast<uint32_t>(resolution.width); + const uint32_t height = static_cast<uint32_t>(resolution.height); + + if (mMaxVirtualDisplayDimension > 0 && + (width > mMaxVirtualDisplayDimension || height > mMaxVirtualDisplayDimension)) { + ALOGE("%s: Resolution %ux%u exceeds maximum dimension %zu", __func__, width, height, + mMaxVirtualDisplayDimension); + return false; } - hal::HWDisplayId hwcDisplayId = 0; - const auto error = static_cast<hal::Error>( - mComposer->createVirtualDisplay(width, height, format, &hwcDisplayId)); - if (error != hal::Error::NONE) { - ALOGE("%s: Failed to create HWC virtual display", __FUNCTION__); - mVirtualIdGenerator.markUnused(*displayId); - return {}; + std::optional<hal::HWDisplayId> hwcMirrorId; + if (mirror) { + hwcMirrorId = fromPhysicalDisplayId(*mirror); } + hal::HWDisplayId hwcDisplayId; + const auto error = static_cast<hal::Error>( + mComposer->createVirtualDisplay(width, height, format, hwcMirrorId, &hwcDisplayId)); + RETURN_IF_HWC_ERROR_FOR("createVirtualDisplay", error, displayId, false); + auto display = std::make_unique<HWC2::impl::Display>(*mComposer.get(), mCapabilities, hwcDisplayId, hal::DisplayType::VIRTUAL); display->setConnected(true); - auto& displayData = mDisplayData[*displayId]; + auto& displayData = mDisplayData[displayId]; displayData.hwcDisplay = std::move(display); displayData.isVirtual = true; - return displayId; + return true; } void HWComposer::allocatePhysicalDisplay(hal::HWDisplayId hwcDisplayId, @@ -670,13 +674,6 @@ status_t HWComposer::setColorTransform(HalDisplayId displayId, const mat4& trans void HWComposer::disconnectDisplay(HalDisplayId displayId) { RETURN_IF_INVALID_DISPLAY(displayId); auto& displayData = mDisplayData[displayId]; - - // If this was a virtual display, add its slot back for reuse by future - // virtual displays - if (displayData.isVirtual) { - mVirtualIdGenerator.markUnused(*HalVirtualDisplayId::tryCast(displayId)); - } - const auto hwcDisplayId = displayData.hwcDisplay->getId(); // TODO(b/74619554): Select internal/external display from remaining displays. @@ -983,10 +980,6 @@ void HWComposer::loadLayerMetadataSupport() { } } -uint32_t HWComposer::getMaxVirtualDisplayCount() const { - return mComposer->getMaxVirtualDisplayCount(); -} - } // namespace impl } // namespace android diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index d0c0c1105a..cd6f9f516f 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -39,7 +39,6 @@ #include <utils/StrongPointer.h> #include <utils/Timers.h> -#include "DisplayIdGenerator.h" #include "DisplayIdentification.h" #include "DisplayMode.h" #include "HWC2.h" @@ -101,7 +100,7 @@ public: virtual ~HWComposer(); - virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0; + virtual void setCallback(HWC2::ComposerCallback*) = 0; virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, DisplayIdentificationData* outData) const = 0; @@ -109,9 +108,16 @@ public: virtual bool hasCapability(hal::Capability) const = 0; virtual bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const = 0; - // Attempts to allocate a virtual display and returns its ID if created on the HWC device. - virtual std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, - ui::PixelFormat*) = 0; + virtual size_t getMaxVirtualDisplayCount() const = 0; + virtual size_t getMaxVirtualDisplayDimension() const = 0; + + // Attempts to allocate a virtual display on the HWC. The maximum number of virtual displays + // supported by the HWC can be queried in advance, but allocation may fail for other reasons. + // For virtualized compositors, the PhysicalDisplayId is a hint that this virtual display is + // a mirror of a physical display, and that the screen should be captured by the host rather + // than guest compositor. + virtual bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*, + std::optional<PhysicalDisplayId> mirror) = 0; virtual void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) = 0; @@ -246,7 +252,7 @@ public: ~HWComposer() override; - void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override; + void setCallback(HWC2::ComposerCallback*) override; bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort, DisplayIdentificationData* outData) const override; @@ -254,9 +260,11 @@ public: bool hasCapability(hal::Capability) const override; bool hasDisplayCapability(HalDisplayId, hal::DisplayCapability) const override; - // Attempts to allocate a virtual display and returns its ID if created on the HWC device. - std::optional<DisplayId> allocateVirtualDisplay(uint32_t width, uint32_t height, - ui::PixelFormat*) override; + size_t getMaxVirtualDisplayCount() const override; + size_t getMaxVirtualDisplayDimension() const override; + + bool allocateVirtualDisplay(HalVirtualDisplayId, ui::Size, ui::PixelFormat*, + std::optional<PhysicalDisplayId>) override; // Called from SurfaceFlinger, when the state for a new physical display needs to be recreated. void allocatePhysicalDisplay(hal::HWDisplayId, PhysicalDisplayId) override; @@ -402,7 +410,6 @@ private: void loadCapabilities(); void loadLayerMetadataSupport(); - uint32_t getMaxVirtualDisplayCount() const; std::unordered_map<HalDisplayId, DisplayData> mDisplayData; @@ -416,8 +423,7 @@ private: std::optional<hal::HWDisplayId> mExternalHwcDisplayId; bool mHasMultiDisplaySupport = false; - RandomDisplayIdGenerator<HalVirtualDisplayId> mVirtualIdGenerator{getMaxVirtualDisplayCount()}; - + const size_t mMaxVirtualDisplayDimension; const bool mUpdateDeviceProductInfoOnHotplugReconnect; }; diff --git a/services/surfaceflinger/DisplayIdGenerator.h b/services/surfaceflinger/DisplayIdGenerator.h index e7c69a8094..9791a2504a 100644 --- a/services/surfaceflinger/DisplayIdGenerator.h +++ b/services/surfaceflinger/DisplayIdGenerator.h @@ -27,23 +27,16 @@ namespace android { -template <typename T> +// Generates pseudo-random IDs of type GpuVirtualDisplayId or HalVirtualDisplayId. +template <typename Id> class DisplayIdGenerator { public: - virtual std::optional<T> nextId() = 0; - virtual void markUnused(T id) = 0; - -protected: - ~DisplayIdGenerator() {} -}; - -template <typename T> -class RandomDisplayIdGenerator final : public DisplayIdGenerator<T> { -public: - explicit RandomDisplayIdGenerator(size_t maxIdsCount = std::numeric_limits<size_t>::max()) + explicit DisplayIdGenerator(size_t maxIdsCount = std::numeric_limits<size_t>::max()) : mMaxIdsCount(maxIdsCount) {} - std::optional<T> nextId() override { + bool inUse() const { return !mUsedIds.empty(); } + + std::optional<Id> generateId() { if (mUsedIds.size() >= mMaxIdsCount) { return std::nullopt; } @@ -51,8 +44,7 @@ public: constexpr int kMaxAttempts = 1000; for (int attempts = 0; attempts < kMaxAttempts; attempts++) { - const auto baseId = mDistribution(mGenerator); - const T id(baseId); + const Id id{mDistribution(mGenerator)}; if (mUsedIds.count(id) == 0) { mUsedIds.insert(id); return id; @@ -62,14 +54,18 @@ public: LOG_ALWAYS_FATAL("Couldn't generate ID after %d attempts", kMaxAttempts); } - void markUnused(T id) override { mUsedIds.erase(id); } + void releaseId(Id id) { mUsedIds.erase(id); } private: const size_t mMaxIdsCount; - std::unordered_set<T> mUsedIds; + std::unordered_set<Id> mUsedIds; + + // Pseudo-random with random seed, in contrast to physical display IDs, which are stable + // across reboots. The only ISurfaceComposer exposure for these IDs is a restricted API + // for screencap, so there is little benefit in making them unpredictable. std::default_random_engine mGenerator{std::random_device()()}; - std::uniform_int_distribution<typename T::BaseId> mDistribution; + std::uniform_int_distribution<typename Id::BaseId> mDistribution; }; -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 0e222abbe2..488e6f1390 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -294,7 +294,6 @@ const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled // --------------------------------------------------------------------------- int64_t SurfaceFlinger::dispSyncPresentTimeOffset; bool SurfaceFlinger::useHwcForRgbToYuv; -uint64_t SurfaceFlinger::maxVirtualDisplaySize; bool SurfaceFlinger::hasSyncFramework; int64_t SurfaceFlinger::maxFrameBufferAcquiredBuffers; uint32_t SurfaceFlinger::maxGraphicsWidth; @@ -357,8 +356,6 @@ SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipI useHwcForRgbToYuv = force_hwc_copy_for_virtual_displays(false); - maxVirtualDisplaySize = max_virtual_display_dimension(0); - maxFrameBufferAcquiredBuffers = max_frame_buffer_acquired_buffers(2); maxGraphicsWidth = std::max(max_graphics_width(0), 0); @@ -434,10 +431,6 @@ SurfaceFlinger::SurfaceFlinger(Factory& factory) : SurfaceFlinger(factory, SkipI ALOGI_IF(mPropagateBackpressureClientComposition, "Enabling backpressure propagation for Client Composition"); - property_get("debug.sf.enable_hwc_vds", value, "0"); - mUseHwcVirtualDisplays = atoi(value); - ALOGI_IF(mUseHwcVirtualDisplays, "Enabling HWC virtual displays"); - property_get("ro.surface_flinger.supports_background_blur", value, "0"); bool supportsBlurs = atoi(value); mSupportsBlur = supportsBlurs; @@ -578,6 +571,59 @@ void SurfaceFlinger::destroyDisplay(const sp<IBinder>& displayToken) { setTransactionFlags(eDisplayTransactionNeeded); } +void SurfaceFlinger::enableHalVirtualDisplays(bool enable) { + auto& generator = mVirtualDisplayIdGenerators.hal; + if (!generator && enable) { + ALOGI("Enabling HAL virtual displays"); + generator.emplace(getHwComposer().getMaxVirtualDisplayCount()); + } else if (generator && !enable) { + ALOGW_IF(generator->inUse(), "Disabling HAL virtual displays while in use"); + generator.reset(); + } +} + +VirtualDisplayId SurfaceFlinger::acquireVirtualDisplay(ui::Size resolution, ui::PixelFormat format, + ui::LayerStack layerStack) { + if (auto& generator = mVirtualDisplayIdGenerators.hal) { + if (const auto id = generator->generateId()) { + std::optional<PhysicalDisplayId> mirror; + + if (const auto display = findDisplay([layerStack](const auto& display) { + return !display.isVirtual() && display.getLayerStack() == layerStack; + })) { + mirror = display->getPhysicalId(); + } + + if (getHwComposer().allocateVirtualDisplay(*id, resolution, &format, mirror)) { + return *id; + } + + generator->releaseId(*id); + } else { + ALOGW("%s: Exhausted HAL virtual displays", __func__); + } + + ALOGW("%s: Falling back to GPU virtual display", __func__); + } + + const auto id = mVirtualDisplayIdGenerators.gpu.generateId(); + LOG_ALWAYS_FATAL_IF(!id, "Failed to generate ID for GPU virtual display"); + return *id; +} + +void SurfaceFlinger::releaseVirtualDisplay(VirtualDisplayId displayId) { + if (const auto id = HalVirtualDisplayId::tryCast(displayId)) { + if (auto& generator = mVirtualDisplayIdGenerators.hal) { + generator->releaseId(*id); + } + return; + } + + const auto id = GpuVirtualDisplayId::tryCast(displayId); + LOG_ALWAYS_FATAL_IF(!id); + mVirtualDisplayIdGenerators.gpu.releaseId(*id); +} + std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIds() const { Mutex::Autolock lock(mStateLock); @@ -736,8 +782,13 @@ void SurfaceFlinger::init() { .build())); mCompositionEngine->setTimeStats(mTimeStats); mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName)); - mCompositionEngine->getHwComposer().setConfiguration(this, getBE().mComposerSequenceId); + mCompositionEngine->getHwComposer().setCallback(this); ClientCache::getInstance().setRenderEngine(&getRenderEngine()); + + if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) { + enableHalVirtualDisplays(true); + } + // Process any initial hotplug and resulting display changes. processDisplayHotplugEventsLocked(); const auto display = getDefaultDisplayDeviceLocked(); @@ -1596,16 +1647,11 @@ nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const { return 0; } -void SurfaceFlinger::onVsyncReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId, - int64_t timestamp, - std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { - ATRACE_NAME("SF onVsync"); +void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp, + std::optional<hal::VsyncPeriodNanos> vsyncPeriod) { + ATRACE_CALL(); Mutex::Autolock lock(mStateLock); - // Ignore any vsyncs from a previous hardware composer. - if (sequenceId != getBE().mComposerSequenceId) { - return; - } if (const auto displayId = getHwComposer().toPhysicalDisplayId(hwcDisplayId)) { auto token = getPhysicalDisplayTokenLocked(*displayId); @@ -1656,16 +1702,11 @@ void SurfaceFlinger::changeRefreshRateLocked(const RefreshRate& refreshRate, setDesiredActiveMode({refreshRate.getModeId(), event}); } -void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId, - hal::Connection connection) { - ALOGI("%s(%d, %" PRIu64 ", %s)", __FUNCTION__, sequenceId, hwcDisplayId, +void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, + hal::Connection connection) { + ALOGI("%s(%" PRIu64 ", %s)", __func__, hwcDisplayId, connection == hal::Connection::CONNECTED ? "connected" : "disconnected"); - // Ignore events that do not have the right sequenceId. - if (sequenceId != getBE().mComposerSequenceId) { - return; - } - // Only lock if we're not on the main thread. This function is normally // called on a hwbinder thread, but for the primary display it's called on // the main thread with the state lock already held, so don't attempt to @@ -1682,26 +1723,19 @@ void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcD setTransactionFlags(eDisplayTransactionNeeded); } -void SurfaceFlinger::onVsyncPeriodTimingChangedReceived( - int32_t sequenceId, hal::HWDisplayId /*display*/, - const hal::VsyncPeriodChangeTimeline& updatedTimeline) { +void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged( + hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) { Mutex::Autolock lock(mStateLock); - if (sequenceId != getBE().mComposerSequenceId) { - return; - } - mScheduler->onNewVsyncPeriodChangeTimeline(updatedTimeline); + mScheduler->onNewVsyncPeriodChangeTimeline(timeline); } -void SurfaceFlinger::onSeamlessPossible(int32_t /*sequenceId*/, hal::HWDisplayId /*display*/) { +void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) { // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE. } -void SurfaceFlinger::onRefreshReceived(int sequenceId, hal::HWDisplayId /*hwcDisplayId*/) { +void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) { Mutex::Autolock lock(mStateLock); - if (sequenceId != getBE().mComposerSequenceId) { - return; - } repaintEverythingForHWC(); } @@ -2192,11 +2226,10 @@ void SurfaceFlinger::postComposition() { mFpsReporter->dispatchLayerFps(); } hdrInfoListeners.reserve(mHdrLayerInfoListeners.size()); - for (auto& [key, value] : mHdrLayerInfoListeners) { - if (value && value->hasListeners()) { - auto listenersDisplay = getDisplayById(key); - if (listenersDisplay) { - hdrInfoListeners.emplace_back(listenersDisplay->getCompositionDisplay(), value); + for (const auto& [displayId, reporter] : mHdrLayerInfoListeners) { + if (reporter && reporter->hasListeners()) { + if (const auto display = getDisplayDeviceLocked(displayId)) { + hdrInfoListeners.emplace_back(display->getCompositionDisplay(), reporter); } } } @@ -2622,10 +2655,10 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, ALOGE_IF(status != NO_ERROR, "Unable to query width (%d)", status); status = state.surface->query(NATIVE_WINDOW_HEIGHT, &resolution.height); ALOGE_IF(status != NO_ERROR, "Unable to query height (%d)", status); - int intPixelFormat; - status = state.surface->query(NATIVE_WINDOW_FORMAT, &intPixelFormat); + int format; + status = state.surface->query(NATIVE_WINDOW_FORMAT, &format); ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); - pixelFormat = static_cast<ui::PixelFormat>(intPixelFormat); + pixelFormat = static_cast<ui::PixelFormat>(format); } else { // Virtual displays without a surface are dormant: // they have external state (layer stack, projection, @@ -2635,17 +2668,18 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, compositionengine::DisplayCreationArgsBuilder builder; if (const auto& physical = state.physical) { - builder.setPhysical({physical->id, physical->type}); + builder.setId(physical->id); + builder.setConnectionType(physical->type); + } else { + builder.setId(acquireVirtualDisplay(resolution, pixelFormat, state.layerStack)); } + builder.setPixels(resolution); - builder.setPixelFormat(pixelFormat); builder.setIsSecure(state.isSecure); builder.setLayerStackId(state.layerStack); builder.setPowerAdvisor(&mPowerAdvisor); - builder.setUseHwcVirtualDisplays(mUseHwcVirtualDisplays); - builder.setGpuVirtualDisplayIdGenerator(mGpuVirtualDisplayIdGenerator); builder.setName(state.displayName); - const auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); + auto compositionDisplay = getCompositionEngine().createDisplay(builder.build()); compositionDisplay->setLayerCachingEnabled(mLayerCachingEnabled); sp<compositionengine::DisplaySurface> displaySurface; @@ -2654,33 +2688,30 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, sp<IGraphicBufferConsumer> bqConsumer; getFactory().createBufferQueue(&bqProducer, &bqConsumer, /*consumerIsSurfaceFlinger =*/false); - DisplayId displayId = compositionDisplay->getId(); - if (state.isVirtual()) { - const auto virtualId = VirtualDisplayId::tryCast(displayId); - LOG_FATAL_IF(!virtualId); - sp<VirtualDisplaySurface> vds = - new VirtualDisplaySurface(getHwComposer(), *virtualId, state.surface, bqProducer, - bqConsumer, state.displayName); - - displaySurface = vds; - producer = vds; + const auto displayId = VirtualDisplayId::tryCast(compositionDisplay->getId()); + LOG_FATAL_IF(!displayId); + auto surface = sp<VirtualDisplaySurface>::make(getHwComposer(), *displayId, state.surface, + bqProducer, bqConsumer, state.displayName); + displaySurface = surface; + producer = std::move(surface); } else { ALOGE_IF(state.surface != nullptr, "adding a supported display, but rendering " "surface is provided (%p), ignoring it", state.surface.get()); - const auto physicalId = PhysicalDisplayId::tryCast(displayId); - LOG_FATAL_IF(!physicalId); - displaySurface = new FramebufferSurface(getHwComposer(), *physicalId, bqConsumer, - state.physical->activeMode->getSize(), - ui::Size(maxGraphicsWidth, maxGraphicsHeight)); + const auto displayId = PhysicalDisplayId::tryCast(compositionDisplay->getId()); + LOG_FATAL_IF(!displayId); + displaySurface = + sp<FramebufferSurface>::make(getHwComposer(), *displayId, bqConsumer, + state.physical->activeMode->getSize(), + ui::Size(maxGraphicsWidth, maxGraphicsHeight)); producer = bqProducer; } LOG_FATAL_IF(!displaySurface); - const auto display = setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state, - displaySurface, producer); + const auto display = setupNewDisplayDeviceInternal(displayToken, std::move(compositionDisplay), + state, displaySurface, producer); mDisplays.emplace(displayToken, display); if (!state.isVirtual()) { dispatchDisplayHotplugEvent(display->getPhysicalId(), true); @@ -2696,7 +2727,10 @@ void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { auto display = getDisplayDeviceLocked(displayToken); if (display) { display->disconnect(); - if (!display->isVirtual()) { + + if (display->isVirtual()) { + releaseVirtualDisplay(display->getVirtualId()); + } else { dispatchDisplayHotplugEvent(display->getPhysicalId(), false); } } @@ -2725,17 +2759,26 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken, const DisplayDeviceState& drawingState) { const sp<IBinder> currentBinder = IInterface::asBinder(currentState.surface); const sp<IBinder> drawingBinder = IInterface::asBinder(drawingState.surface); + + // Recreate the DisplayDevice if the surface or sequence ID changed. if (currentBinder != drawingBinder || currentState.sequenceId != drawingState.sequenceId) { - // changing the surface is like destroying and recreating the DisplayDevice getRenderEngine().cleanFramebufferCache(); + if (const auto display = getDisplayDeviceLocked(displayToken)) { display->disconnect(); + if (display->isVirtual()) { + releaseVirtualDisplay(display->getVirtualId()); + } } + mDisplays.erase(displayToken); + if (const auto& physical = currentState.physical) { getHwComposer().allocatePhysicalDisplay(physical->hwcDisplayId, physical->id); } + processDisplayAdded(displayToken, currentState); + if (currentState.physical) { const auto display = getDisplayDeviceLocked(displayToken); setPowerModeInternal(display, hal::PowerMode::ON); @@ -2831,6 +2874,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) { // Commit layer transactions. This needs to happen after display transactions are // committed because some geometry logic relies on display orientation. if ((transactionFlags & eTraversalNeeded) || mForceTraversal || displayTransactionNeeded) { + mForceTraversal = false; mCurrentState.traverse([&](Layer* layer) { uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); if (!trFlags && !displayTransactionNeeded) return; @@ -4601,7 +4645,8 @@ void SurfaceFlinger::appendSfConfigString(std::string& result) const { StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); - StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%" PRIu64, maxVirtualDisplaySize); + StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%zu", + getHwComposer().getMaxVirtualDisplayDimension()); StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, maxFrameBufferAcquiredBuffers); @@ -5359,8 +5404,8 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return NO_ERROR; } case 1021: { // Disable HWC virtual displays - n = data.readInt32(); - mUseHwcVirtualDisplays = !n; + const bool enable = data.readInt32() != 0; + static_cast<void>(schedule([this, enable] { enableHalVirtualDisplays(enable); })); return NO_ERROR; } case 1022: { // Set saturation boost @@ -5508,37 +5553,24 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } case 1035: { const int modeId = data.readInt32(); - mDebugDisplayModeSetByBackdoor = false; - - const auto displayId = [&]() -> std::optional<PhysicalDisplayId> { - uint64_t inputDisplayId = 0; - if (data.readUint64(&inputDisplayId) == NO_ERROR) { - const auto token = getPhysicalDisplayToken( - static_cast<PhysicalDisplayId>(inputDisplayId)); - if (!token) { - ALOGE("No display with id: %" PRIu64, inputDisplayId); - return std::nullopt; - } - return std::make_optional<PhysicalDisplayId>(inputDisplayId); + const auto display = [&]() -> sp<IBinder> { + uint64_t value; + if (data.readUint64(&value) != NO_ERROR) { + return getInternalDisplayToken(); } - return getInternalDisplayId(); - }(); - - if (!displayId) { - ALOGE("No display found"); - return NO_ERROR; - } - - status_t result = setActiveMode(getPhysicalDisplayToken(*displayId), modeId); - if (result != NO_ERROR) { - return result; - } + if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(value)) { + return getPhysicalDisplayToken(*id); + } - mDebugDisplayModeSetByBackdoor = true; + ALOGE("Invalid physical display ID"); + return nullptr; + }(); - return NO_ERROR; + const status_t result = setActiveMode(display, modeId); + mDebugDisplayModeSetByBackdoor = result == NO_ERROR; + return result; } case 1036: { if (data.readInt32() > 0) { @@ -5560,7 +5592,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r Mutex::Autolock lock(mStateLock); hwcId = getHwComposer().getInternalHwcDisplayId(); } - onHotplugReceived(getBE().mComposerSequenceId, *hwcId, hal::Connection::CONNECTED); + onComposerHalHotplug(*hwcId, hal::Connection::CONNECTED); return NO_ERROR; } // Modify the max number of display frames stored within FrameTimeline @@ -5601,14 +5633,11 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r std::optional<PhysicalDisplayId> inputId = std::nullopt; if (uint64_t inputDisplayId; data.readUint64(&inputDisplayId) == NO_ERROR) { - const auto token = getPhysicalDisplayToken( - static_cast<PhysicalDisplayId>(inputDisplayId)); - if (!token) { + inputId = DisplayId::fromValue<PhysicalDisplayId>(inputDisplayId); + if (!inputId || getPhysicalDisplayToken(*inputId)) { ALOGE("No display with id: %" PRIu64, inputDisplayId); return NAME_NOT_FOUND; } - - inputId = std::make_optional<PhysicalDisplayId>(inputDisplayId); } { Mutex::Autolock lock(mStateLock); @@ -5770,34 +5799,6 @@ status_t SurfaceFlinger::setSchedFifo(bool enabled) { return NO_ERROR; } -sp<DisplayDevice> SurfaceFlinger::getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) { - if (const sp<IBinder> displayToken = - getPhysicalDisplayTokenLocked(PhysicalDisplayId{displayOrLayerStack})) { - return getDisplayDeviceLocked(displayToken); - } - // Couldn't find display by displayId. Try to get display by layerStack since virtual displays - // may not have a displayId. - return getDisplayByLayerStack(displayOrLayerStack); -} - -sp<DisplayDevice> SurfaceFlinger::getDisplayById(DisplayId displayId) const { - for (const auto& [token, display] : mDisplays) { - if (display->getId() == displayId) { - return display; - } - } - return nullptr; -} - -sp<DisplayDevice> SurfaceFlinger::getDisplayByLayerStack(uint64_t layerStack) { - for (const auto& [token, display] : mDisplays) { - if (display->getLayerStack() == layerStack) { - return display; - } - } - return nullptr; -} - status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { ATRACE_CALL(); @@ -5809,7 +5810,7 @@ status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, if (!args.displayToken) return BAD_VALUE; - wp<DisplayDevice> displayWeak; + wp<const DisplayDevice> displayWeak; ui::LayerStack layerStack; ui::Size reqSize(args.width, args.height); ui::Dataspace dataspace; @@ -5850,21 +5851,22 @@ status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, captureListener); } -status_t SurfaceFlinger::captureDisplay(uint64_t displayOrLayerStack, +status_t SurfaceFlinger::captureDisplay(DisplayId displayId, const sp<IScreenCaptureListener>& captureListener) { ui::LayerStack layerStack; - wp<DisplayDevice> displayWeak; + wp<const DisplayDevice> displayWeak; ui::Size size; ui::Dataspace dataspace; { Mutex::Autolock lock(mStateLock); - sp<DisplayDevice> display = getDisplayByIdOrLayerStack(displayOrLayerStack); + + const auto display = getDisplayDeviceLocked(displayId); if (!display) { return NAME_NOT_FOUND; } - layerStack = display->getLayerStack(); - displayWeak = display; + displayWeak = display; + layerStack = display->getLayerStack(); size = display->getLayerStackSpaceRect().getSize(); dataspace = @@ -5949,7 +5951,11 @@ status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, } } - const auto display = getDisplayByLayerStack(parent->getLayerStack()); + const auto display = + findDisplay([layerStack = parent->getLayerStack()](const auto& display) { + return display.getLayerStack() == layerStack; + }); + if (!display) { return NAME_NOT_FOUND; } diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index cb8d312e9c..ee354c6ec2 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -169,11 +169,6 @@ struct SurfaceFlingerBE { }; mutable Mutex mBufferingStatsMutex; std::unordered_map<std::string, BufferingStats> mBufferingStats; - - // The composer sequence id is a monotonically increasing integer that we - // use to differentiate callbacks from different hardware composer - // instances. Each hardware composer instance gets a different sequence id. - int32_t mComposerSequenceId = 0; }; class SurfaceFlinger : public BnSurfaceComposer, @@ -228,10 +223,6 @@ public: // GL composition. static bool useHwcForRgbToYuv; - // Maximum dimension supported by HWC for virtual display. - // Equal to min(max_height, max_width). - static uint64_t maxVirtualDisplaySize; - // Controls the number of buffers SurfaceFlinger will allocate for use in // FramebufferSurface static int64_t maxFrameBufferAcquiredBuffers; @@ -624,12 +615,10 @@ private: sp<IDisplayEventConnection> createDisplayEventConnection( ISurfaceComposer::VsyncSource vsyncSource = eVsyncSourceApp, ISurfaceComposer::EventRegistrationFlags eventRegistration = {}) override; - status_t captureDisplay(const DisplayCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) override; - status_t captureDisplay(uint64_t displayOrLayerStack, - const sp<IScreenCaptureListener>& captureListener) override; - status_t captureLayers(const LayerCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) override; + + status_t captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&) override; + status_t captureDisplay(DisplayId, const sp<IScreenCaptureListener>&) override; + status_t captureLayers(const LayerCaptureArgs&, const sp<IScreenCaptureListener>&) override; status_t getDisplayStats(const sp<IBinder>& displayToken, DisplayStatInfo* stats) override; status_t getDisplayState(const sp<IBinder>& displayToken, ui::DisplayState*) @@ -716,18 +705,14 @@ private: // Implements RefBase. void onFirstRef() override; - /* - * HWC2::ComposerCallback / HWComposer::EventHandler interface - */ - void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId, int64_t timestamp, - std::optional<hal::VsyncPeriodNanos> vsyncPeriod) override; - void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId, - hal::Connection connection) override; - void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId) override; - void onVsyncPeriodTimingChangedReceived( - int32_t sequenceId, hal::HWDisplayId display, - const hal::VsyncPeriodChangeTimeline& updatedTimeline) override; - void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId display) override; + // HWC2::ComposerCallback overrides: + void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp, + std::optional<hal::VsyncPeriodNanos>) override; + void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) override; + void onComposerHalRefresh(hal::HWDisplayId) override; + void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId, + const hal::VsyncPeriodChangeTimeline&) override; + void onComposerHalSeamlessPossible(hal::HWDisplayId) override; /* * ISchedulerCallback @@ -918,10 +903,6 @@ private: bool canCaptureBlackoutContent, bool regionSampling, bool grayscale, ScreenCaptureResults&); - sp<DisplayDevice> getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) REQUIRES(mStateLock); - sp<DisplayDevice> getDisplayById(DisplayId displayId) const REQUIRES(mStateLock); - sp<DisplayDevice> getDisplayByLayerStack(uint64_t layerStack) REQUIRES(mStateLock); - // If the uid provided is not UNSET_UID, the traverse will skip any layers that don't have a // matching ownerUid void traverseLayersInLayerStack(ui::LayerStack, const int32_t uid, const LayerVector::Visitor&); @@ -963,6 +944,20 @@ private: return getDefaultDisplayDeviceLocked(); } + // Returns the first display that matches a `bool(const DisplayDevice&)` predicate. + template <typename Predicate> + sp<DisplayDevice> findDisplay(Predicate p) const REQUIRES(mStateLock) { + const auto it = std::find_if(mDisplays.begin(), mDisplays.end(), + [&](const auto& pair) { return p(*pair.second); }); + + return it == mDisplays.end() ? nullptr : it->second; + } + + sp<const DisplayDevice> getDisplayDeviceLocked(DisplayId id) const REQUIRES(mStateLock) { + // TODO(b/182939859): Replace tokens with IDs for display lookup. + return findDisplay([id](const auto& display) { return display.getId() == id; }); + } + // mark a region of a layer stack dirty. this updates the dirty // region of all screens presenting this layer stack. void invalidateLayerStack(const sp<const Layer>& layer, const Region& dirty); @@ -1080,6 +1075,14 @@ private: return hwcDisplayId ? getHwComposer().toPhysicalDisplayId(*hwcDisplayId) : std::nullopt; } + // Toggles use of HAL/GPU virtual displays. + void enableHalVirtualDisplays(bool); + + // Virtual display lifecycle for ID generation and HAL allocation. + VirtualDisplayId acquireVirtualDisplay(ui::Size, ui::PixelFormat, ui::LayerStack) + REQUIRES(mStateLock); + void releaseVirtualDisplay(VirtualDisplayId); + /* * Debugging & dumpsys */ @@ -1232,7 +1235,10 @@ private: std::unordered_map<PhysicalDisplayId, sp<IBinder>> mPhysicalDisplayTokens GUARDED_BY(mStateLock); - RandomDisplayIdGenerator<GpuVirtualDisplayId> mGpuVirtualDisplayIdGenerator; + struct { + DisplayIdGenerator<GpuVirtualDisplayId> gpu; + std::optional<DisplayIdGenerator<HalVirtualDisplayId>> hal; + } mVirtualDisplayIdGenerators; std::unordered_map<BBinder*, wp<Layer>> mLayersByLocalBinderToken GUARDED_BY(mStateLock); @@ -1255,7 +1261,7 @@ private: const std::shared_ptr<TimeStats> mTimeStats; const std::unique_ptr<FrameTracer> mFrameTracer; const std::unique_ptr<frametimeline::FrameTimeline> mFrameTimeline; - bool mUseHwcVirtualDisplays = false; + // If blurs should be enabled on this device. bool mSupportsBlur = false; // Disable blurs, for debugging diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp index 162711d6f5..a9e935df22 100644 --- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp +++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp @@ -279,7 +279,7 @@ protected: } bool waitForHotplugEvent(Display displayId, bool connected) { - return waitForHotplugEvent(PhysicalDisplayId(displayId), connected); + return waitForHotplugEvent(physicalIdFromHwcDisplayId(displayId), connected); } bool waitForHotplugEvent(PhysicalDisplayId displayId, bool connected) { @@ -305,7 +305,7 @@ protected: } bool waitForModeChangedEvent(Display display, int32_t modeId) { - PhysicalDisplayId displayId(display); + PhysicalDisplayId displayId = physicalIdFromHwcDisplayId(display); int waitCount = 20; while (waitCount--) { while (!mReceivedDisplayEvents.empty()) { diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp index b33434e34d..83575bd72e 100644 --- a/services/surfaceflinger/tests/unittests/Android.bp +++ b/services/surfaceflinger/tests/unittests/Android.bp @@ -68,7 +68,7 @@ cc_test { "SurfaceFlinger_GetDisplayNativePrimariesTest.cpp", "SurfaceFlinger_HandleTransactionLockedTest.cpp", "SurfaceFlinger_NotifyPowerBoostTest.cpp", - "SurfaceFlinger_OnHotplugReceivedTest.cpp", + "SurfaceFlinger_HotplugTest.cpp", "SurfaceFlinger_OnInitializeDisplaysTest.cpp", "SurfaceFlinger_SetDisplayStateTest.cpp", "SurfaceFlinger_SetPowerModeInternalTest.cpp", diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp index 3042450f29..fca3bfc242 100644 --- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp +++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp @@ -77,7 +77,7 @@ 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(42); +constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u); constexpr int DEFAULT_DISPLAY_WIDTH = 1920; constexpr int DEFAULT_DISPLAY_HEIGHT = 1024; @@ -105,7 +105,9 @@ public: mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats)); - setupComposer(0); + + mComposer = new Hwc2::mock::Composer(); + mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); } ~CompositionTest() { @@ -114,14 +116,6 @@ public: ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); } - void setupComposer(int virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); - } - void setupScheduler() { auto eventThread = std::make_unique<mock::EventThread>(); auto sfEventThread = std::make_unique<mock::EventThread>(); @@ -289,16 +283,16 @@ struct BaseDisplayVariant { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - auto ceDisplayArgs = - compositionengine::DisplayCreationArgsBuilder() - .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal}) - .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) - .setIsSecure(Derived::IS_SECURE) - .setLayerStackId(DEFAULT_LAYER_STACK) - .setPowerAdvisor(&test->mPowerAdvisor) - .setName(std::string("Injected display for ") + - test_info->test_case_name() + "." + test_info->name()) - .build(); + auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(ui::DisplayConnectionType::Internal) + .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) + .setIsSecure(Derived::IS_SECURE) + .setLayerStackId(DEFAULT_LAYER_STACK) + .setPowerAdvisor(&test->mPowerAdvisor) + .setName(std::string("Injected display for ") + + test_info->test_case_name() + "." + test_info->name()) + .build(); auto compositionDisplay = compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), diff --git a/services/surfaceflinger/tests/unittests/DisplayIdGeneratorTest.cpp b/services/surfaceflinger/tests/unittests/DisplayIdGeneratorTest.cpp index 77a3e1449f..8d4a023615 100644 --- a/services/surfaceflinger/tests/unittests/DisplayIdGeneratorTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayIdGeneratorTest.cpp @@ -14,76 +14,68 @@ * limitations under the License. */ -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wextra" - #include <gtest/gtest.h> +#include <ui/DisplayId.h> +#include <algorithm> +#include <iterator> #include <vector> -#include <ui/DisplayId.h> #include "DisplayIdGenerator.h" namespace android { -template <typename T> -void testNextId(DisplayIdGenerator<T>& generator) { - constexpr int kNumIds = 5; - std::vector<T> ids; - for (int i = 0; i < kNumIds; i++) { - const auto id = generator.nextId(); - ASSERT_TRUE(id); - ids.push_back(*id); - } +template <typename Id> +void testGenerateId() { + DisplayIdGenerator<Id> generator; + + std::vector<std::optional<Id>> ids; + std::generate_n(std::back_inserter(ids), 10, [&] { return generator.generateId(); }); // All IDs should be different. - for (size_t i = 0; i < kNumIds; i++) { - for (size_t j = i + 1; j < kNumIds; j++) { - EXPECT_NE(ids[i], ids[j]); + for (auto it = ids.begin(); it != ids.end(); ++it) { + EXPECT_TRUE(*it); + + for (auto dup = it + 1; dup != ids.end(); ++dup) { + EXPECT_NE(*it, *dup); } } } -TEST(DisplayIdGeneratorTest, nextIdGpuVirtual) { - RandomDisplayIdGenerator<GpuVirtualDisplayId> generator; - testNextId(generator); +TEST(DisplayIdGeneratorTest, generateGpuVirtualDisplayId) { + testGenerateId<GpuVirtualDisplayId>(); } -TEST(DisplayIdGeneratorTest, nextIdHalVirtual) { - RandomDisplayIdGenerator<HalVirtualDisplayId> generator; - testNextId(generator); +TEST(DisplayIdGeneratorTest, generateHalVirtualDisplayId) { + testGenerateId<HalVirtualDisplayId>(); } -TEST(DisplayIdGeneratorTest, markUnused) { +TEST(DisplayIdGeneratorTest, releaseId) { constexpr size_t kMaxIdsCount = 5; - RandomDisplayIdGenerator<GpuVirtualDisplayId> generator(kMaxIdsCount); + DisplayIdGenerator<GpuVirtualDisplayId> generator(kMaxIdsCount); - const auto id = generator.nextId(); + const auto id = generator.generateId(); EXPECT_TRUE(id); - for (int i = 1; i < kMaxIdsCount; i++) { - EXPECT_TRUE(generator.nextId()); + for (size_t i = 1; i < kMaxIdsCount; i++) { + EXPECT_TRUE(generator.generateId()); } - EXPECT_FALSE(generator.nextId()); + EXPECT_FALSE(generator.generateId()); - generator.markUnused(*id); - EXPECT_TRUE(generator.nextId()); + generator.releaseId(*id); + EXPECT_TRUE(generator.generateId()); } TEST(DisplayIdGeneratorTest, maxIdsCount) { constexpr size_t kMaxIdsCount = 5; - RandomDisplayIdGenerator<GpuVirtualDisplayId> generator(kMaxIdsCount); + DisplayIdGenerator<GpuVirtualDisplayId> generator(kMaxIdsCount); - for (int i = 0; i < kMaxIdsCount; i++) { - EXPECT_TRUE(generator.nextId()); + for (size_t i = 0; i < kMaxIdsCount; i++) { + EXPECT_TRUE(generator.generateId()); } - EXPECT_FALSE(generator.nextId()); + EXPECT_FALSE(generator.generateId()); } } // namespace android - -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic pop // ignored "-Wextra"
\ No newline at end of file diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp index a3e810871c..60b0f5334c 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp @@ -41,9 +41,6 @@ DisplayTransactionTest::DisplayTransactionTest() { mFlinger.mutableUseColorManagement() = false; mFlinger.mutableDisplayColorSetting() = DisplayColorSetting::kUnmanaged; - // Default to using HWC virtual displays - mFlinger.mutableUseHwcVirtualDisplays() = true; - mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) { ADD_FAILURE() << "Unexpected request to create a buffer queue."; }); @@ -85,10 +82,17 @@ void DisplayTransactionTest::injectMockScheduler() { } void DisplayTransactionTest::injectMockComposer(int virtualDisplayCount) { + if (mComposer) { + // If reinjecting, disable first to prevent the enable below from being a no-op. + mFlinger.enableHalVirtualDisplays(false); + } + mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); + EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); + mFlinger.enableHalVirtualDisplays(true); + Mock::VerifyAndClear(mComposer); } @@ -118,7 +122,7 @@ void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() { sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay( std::function<void(FakeDisplayDeviceInjector&)> injectExtra) { - constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID(777); + constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(255u); constexpr int DEFAULT_DISPLAY_WIDTH = 1080; constexpr int DEFAULT_DISPLAY_HEIGHT = 1920; constexpr HWDisplayId DEFAULT_DISPLAY_HWC_DISPLAY_ID = 0; @@ -135,18 +139,21 @@ sp<DisplayDevice> DisplayTransactionTest::injectDefaultInternalDisplay( EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)); EXPECT_CALL(*mNativeWindow, perform(NATIVE_WINDOW_API_DISCONNECT)).Times(AnyNumber()); - auto compositionDisplay = compositionengine::impl:: - createDisplay(mFlinger.getCompositionEngine(), - compositionengine::DisplayCreationArgsBuilder() - .setPhysical( - {DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal}) - .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) - .setPowerAdvisor(&mPowerAdvisor) - .build()); - - auto injector = FakeDisplayDeviceInjector(mFlinger, compositionDisplay, - ui::DisplayConnectionType::Internal, - DEFAULT_DISPLAY_HWC_DISPLAY_ID, true /* isPrimary */); + constexpr auto kConnectionType = ui::DisplayConnectionType::Internal; + constexpr bool kIsPrimary = true; + + auto compositionDisplay = + compositionengine::impl::createDisplay(mFlinger.getCompositionEngine(), + compositionengine::DisplayCreationArgsBuilder() + .setId(DEFAULT_DISPLAY_ID) + .setConnectionType(kConnectionType) + .setPixels({DEFAULT_DISPLAY_WIDTH, + DEFAULT_DISPLAY_HEIGHT}) + .setPowerAdvisor(&mPowerAdvisor) + .build()); + + auto injector = FakeDisplayDeviceInjector(mFlinger, compositionDisplay, kConnectionType, + DEFAULT_DISPLAY_HWC_DISPLAY_ID, kIsPrimary); injector.setNativeWindow(mNativeWindow); if (injectExtra) { diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h b/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h index d68fff6345..6ce281d403 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h @@ -263,40 +263,23 @@ struct DisplayVariant { static auto makeFakeExistingDisplayInjector(DisplayTransactionTest* test) { auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder(); - if (auto displayId = PhysicalDisplayId::tryCast(DISPLAY_ID::get())) { - ceDisplayArgs.setPhysical({*displayId, ui::DisplayConnectionType::Internal}); - } else { - // We turn off the use of HwcVirtualDisplays, to prevent Composition Engine - // from calling into HWComposer. This way all virtual displays will get - // a GpuVirtualDisplayId, even if we are in the HwcVirtualDisplayVariant. - // In this case we later override it by calling display.setDisplayIdForTesting(). - ceDisplayArgs.setUseHwcVirtualDisplays(false); - - GpuVirtualDisplayId desiredDisplayId = GpuVirtualDisplayId::tryCast(DISPLAY_ID::get()) - .value_or(GpuVirtualDisplayId(0)); - - ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) - .WillByDefault(Return(desiredDisplayId)); + ceDisplayArgs.setId(DISPLAY_ID::get()) + .setPixels({WIDTH, HEIGHT}) + .setPowerAdvisor(&test->mPowerAdvisor); - auto& generator = test->mFlinger.gpuVirtualDisplayIdGenerator(); - ceDisplayArgs.setGpuVirtualDisplayIdGenerator(generator); + const auto connectionType = CONNECTION_TYPE::value; + if (connectionType) { + ceDisplayArgs.setConnectionType(*connectionType); } - ceDisplayArgs.setPixels({WIDTH, HEIGHT}).setPowerAdvisor(&test->mPowerAdvisor); auto compositionDisplay = compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), ceDisplayArgs.build()); - if (HalVirtualDisplayId::tryCast(DISPLAY_ID::get())) { - // CompositionEngine has assigned a placeholder GpuVirtualDisplayId and we need to - // override it with the correct HalVirtualDisplayId. - compositionDisplay->setDisplayIdForTesting(DISPLAY_ID::get()); - } - auto injector = TestableSurfaceFlinger::FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay, - CONNECTION_TYPE::value, + connectionType, HWC_DISPLAY_ID_OPT::value, static_cast<bool>(PRIMARY)); @@ -404,8 +387,8 @@ struct HwcDisplayVariant { ::testing::UnitTest::GetInstance()->current_test_info(); auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() - .setPhysical({DisplayVariant::DISPLAY_ID::get(), - PhysicalDisplay::CONNECTION_TYPE}) + .setId(DisplayVariant::DISPLAY_ID::get()) + .setConnectionType(PhysicalDisplay::CONNECTION_TYPE) .setPixels({DisplayVariant::WIDTH, DisplayVariant::HEIGHT}) .setIsSecure(static_cast<bool>(DisplayVariant::SECURE)) .setPowerAdvisor(&test->mPowerAdvisor) @@ -558,17 +541,13 @@ struct NonHwcVirtualDisplayVariant const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) - .WillByDefault(Return(Base::DISPLAY_ID::get())); - auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() + .setId(Base::DISPLAY_ID::get()) .setPixels({Base::WIDTH, Base::HEIGHT}) .setIsSecure(static_cast<bool>(Base::SECURE)) .setPowerAdvisor(&test->mPowerAdvisor) .setName(std::string("Injected display for ") + test_info->test_case_name() + "." + test_info->name()) - .setGpuVirtualDisplayIdGenerator( - test->mFlinger.gpuVirtualDisplayIdGenerator()) .build(); return compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), @@ -610,35 +589,22 @@ struct HwcVirtualDisplayVariant const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); - // In order to prevent compostition engine calling into HWComposer, we - // 1. turn off the use of HWC virtual displays, - // 2. provide a GpuVirtualDisplayIdGenerator which always returns some fake ID - // 3. override the ID by calling setDisplayIdForTesting() - - ON_CALL(test->mFlinger.gpuVirtualDisplayIdGenerator(), nextId()) - .WillByDefault(Return(GpuVirtualDisplayId(0))); - + const auto displayId = Base::DISPLAY_ID::get(); auto ceDisplayArgs = compositionengine::DisplayCreationArgsBuilder() - .setUseHwcVirtualDisplays(false) + .setId(displayId) .setPixels({Base::WIDTH, Base::HEIGHT}) .setIsSecure(static_cast<bool>(Base::SECURE)) .setPowerAdvisor(&test->mPowerAdvisor) .setName(std::string("Injected display for ") + test_info->test_case_name() + "." + test_info->name()) - .setGpuVirtualDisplayIdGenerator( - test->mFlinger.gpuVirtualDisplayIdGenerator()) .build(); auto compositionDisplay = compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), ceDisplayArgs); - compositionDisplay->setDisplayIdForTesting(Base::DISPLAY_ID::get()); // Insert display data so that the HWC thinks it created the virtual display. - if (const auto displayId = Base::DISPLAY_ID::get(); - HalVirtualDisplayId::tryCast(displayId)) { - test->mFlinger.mutableHwcDisplayData().try_emplace(displayId); - } + test->mFlinger.mutableHwcDisplayData().try_emplace(displayId); return compositionDisplay; } @@ -649,8 +615,8 @@ struct HwcVirtualDisplayVariant } static void setupHwcVirtualDisplayCreationCallExpectations(DisplayTransactionTest* test) { - EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _)) - .WillOnce(DoAll(SetArgPointee<3>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); + EXPECT_CALL(*test->mComposer, createVirtualDisplay(Base::WIDTH, Base::HEIGHT, _, _, _)) + .WillOnce(DoAll(SetArgPointee<4>(Self::HWC_DISPLAY_ID), Return(Error::NONE))); EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE)); } }; diff --git a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp index b4a1481e9c..62acc6b549 100644 --- a/services/surfaceflinger/tests/unittests/EventThreadTest.cpp +++ b/services/surfaceflinger/tests/unittests/EventThreadTest.cpp @@ -41,10 +41,13 @@ 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 = PhysicalDisplayId::fromPort(111u); +constexpr PhysicalDisplayId EXTERNAL_DISPLAY_ID = PhysicalDisplayId::fromPort(222u); +constexpr PhysicalDisplayId DISPLAY_ID_64BIT = + PhysicalDisplayId::fromEdid(0xffu, 0xffffu, 0xffff'ffffu); + constexpr std::chrono::duration VSYNC_PERIOD(16ms); + class MockVSyncSource : public VSyncSource { public: const char* getName() const override { return "test"; } diff --git a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp index dec0ff5df2..010c675574 100644 --- a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp +++ b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp @@ -76,11 +76,9 @@ protected: static constexpr int32_t PRIORITY_UNSET = -1; void setupScheduler(); - void setupComposer(uint32_t virtualDisplayCount); sp<BufferStateLayer> createBufferStateLayer(LayerMetadata metadata); TestableSurfaceFlinger mFlinger; - Hwc2::mock::Composer* mComposer = nullptr; mock::FrameTimeline mFrameTimeline = mock::FrameTimeline(std::make_shared<impl::TimeStats>(), 0); @@ -103,7 +101,8 @@ FpsReporterTest::FpsReporterTest() { ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); - setupComposer(0); + mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); + mFpsListener = new TestableFpsListener(); } @@ -145,19 +144,11 @@ void FpsReporterTest::setupScheduler() { std::move(eventThread), std::move(sfEventThread)); } -void FpsReporterTest::setupComposer(uint32_t virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); -} - namespace { TEST_F(FpsReporterTest, callsListeners) { mParent = createBufferStateLayer(); - const constexpr int32_t kTaskId = 12; + constexpr int32_t kTaskId = 12; LayerMetadata targetMetadata; targetMetadata.setInt32(METADATA_TASK_ID, kTaskId); mTarget = createBufferStateLayer(targetMetadata); diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp index cbf8cc21bd..655baf8a77 100644 --- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp +++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp @@ -58,28 +58,26 @@ using ::testing::SetArgPointee; using ::testing::StrictMock; struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> { - MOCK_METHOD3(onHotplugReceived, void(int32_t sequenceId, hal::HWDisplayId, hal::Connection)); - MOCK_METHOD2(onRefreshReceived, void(int32_t sequenceId, hal::HWDisplayId)); - MOCK_METHOD4(onVsyncReceived, - void(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp, - std::optional<hal::VsyncPeriodNanos>)); - MOCK_METHOD3(onVsyncPeriodTimingChangedReceived, - void(int32_t sequenceId, hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&)); - MOCK_METHOD2(onSeamlessPossible, void(int32_t sequenceId, hal::HWDisplayId)); + MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection)); + MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId)); + MOCK_METHOD3(onComposerHalVsync, + void(hal::HWDisplayId, int64_t timestamp, std::optional<hal::VsyncPeriodNanos>)); + MOCK_METHOD2(onComposerHalVsyncPeriodTimingChanged, + void(hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&)); + MOCK_METHOD1(onComposerHalSeamlessPossible, void(hal::HWDisplayId)); }; -struct HWComposerSetConfigurationTest : testing::Test { +struct HWComposerSetCallbackTest : testing::Test { Hwc2::mock::Composer* mHal = new StrictMock<Hwc2::mock::Composer>(); MockHWC2ComposerCallback mCallback; }; -TEST_F(HWComposerSetConfigurationTest, loadsLayerMetadataSupport) { +TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) { const std::string kMetadata1Name = "com.example.metadata.1"; constexpr bool kMetadata1Mandatory = false; const std::string kMetadata2Name = "com.example.metadata.2"; constexpr bool kMetadata2Mandatory = true; - EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0)); EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{})); EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_)) .WillOnce(DoAll(SetArgPointee<0>(std::vector<hal::LayerGenericMetadataKey>{ @@ -91,7 +89,7 @@ TEST_F(HWComposerSetConfigurationTest, loadsLayerMetadataSupport) { EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false)); impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)}; - hwc.setConfiguration(&mCallback, 123); + hwc.setCallback(&mCallback); const auto& supported = hwc.getSupportedLayerGenericMetadata(); EXPECT_EQ(2u, supported.size()); @@ -101,8 +99,7 @@ TEST_F(HWComposerSetConfigurationTest, loadsLayerMetadataSupport) { EXPECT_EQ(kMetadata2Mandatory, supported.find(kMetadata2Name)->second); } -TEST_F(HWComposerSetConfigurationTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) { - EXPECT_CALL(*mHal, getMaxVirtualDisplayCount()).WillOnce(Return(0)); +TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) { EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<hal::Capability>{})); EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_)) .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED)); @@ -110,7 +107,7 @@ TEST_F(HWComposerSetConfigurationTest, handlesUnsupportedCallToGetLayerGenericMe EXPECT_CALL(*mHal, isVsyncPeriodSwitchSupported()).WillOnce(Return(false)); impl::HWComposer hwc{std::unique_ptr<Hwc2::Composer>(mHal)}; - hwc.setConfiguration(&mCallback, 123); + hwc.setCallback(&mCallback); const auto& supported = hwc.getSupportedLayerGenericMetadata(); EXPECT_EQ(0u, supported.size()); diff --git a/services/surfaceflinger/tests/unittests/OneShotTimerTest.cpp b/services/surfaceflinger/tests/unittests/OneShotTimerTest.cpp index 691676420c..597e5e71a2 100644 --- a/services/surfaceflinger/tests/unittests/OneShotTimerTest.cpp +++ b/services/surfaceflinger/tests/unittests/OneShotTimerTest.cpp @@ -72,7 +72,8 @@ TEST_F(OneShotTimerTest, startStopTest) { mIdleTimer->stop(); } -TEST_F(OneShotTimerTest, resetTest) { +// TODO(b/186417847) This test is flaky. Reenable once fixed. +TEST_F(OneShotTimerTest, DISABLED_resetTest) { fake::FakeClock* clock = new fake::FakeClock(); mIdleTimer = std::make_unique<scheduler::OneShotTimer>("TestTimer", 1ms, mResetTimerCallback.getInvocable(), @@ -94,7 +95,8 @@ TEST_F(OneShotTimerTest, resetTest) { EXPECT_FALSE(mResetTimerCallback.waitForUnexpectedCall().has_value()); } -TEST_F(OneShotTimerTest, resetBackToBackTest) { +// TODO(b/186417847) This test is flaky. Reenable once fixed. +TEST_F(OneShotTimerTest, DISABLED_resetBackToBackTest) { fake::FakeClock* clock = new fake::FakeClock(); mIdleTimer = std::make_unique<scheduler::OneShotTimer>("TestTimer", 1ms, mResetTimerCallback.getInvocable(), @@ -144,7 +146,8 @@ TEST_F(OneShotTimerTest, startNotCalledTest) { EXPECT_FALSE(mResetTimerCallback.waitForUnexpectedCall().has_value()); } -TEST_F(OneShotTimerTest, idleTimerIdlesTest) { +// TODO(b/186417847) This test is flaky. Reenable once fixed. +TEST_F(OneShotTimerTest, DISABLED_idleTimerIdlesTest) { fake::FakeClock* clock = new fake::FakeClock(); mIdleTimer = std::make_unique<scheduler::OneShotTimer>("TestTimer", 1ms, mResetTimerCallback.getInvocable(), @@ -169,7 +172,8 @@ TEST_F(OneShotTimerTest, idleTimerIdlesTest) { EXPECT_FALSE(mResetTimerCallback.waitForUnexpectedCall().has_value()); } -TEST_F(OneShotTimerTest, timeoutCallbackExecutionTest) { +// TODO(b/186417847) This test is flaky. Reenable once fixed. +TEST_F(OneShotTimerTest, DISABLED_timeoutCallbackExecutionTest) { fake::FakeClock* clock = new fake::FakeClock(); mIdleTimer = std::make_unique<scheduler::OneShotTimer>("TestTimer", 1ms, mResetTimerCallback.getInvocable(), diff --git a/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp index 9c6ad06e1d..fd3e564cd9 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp @@ -60,7 +60,6 @@ protected: static constexpr int32_t PRIORITY_UNSET = -1; void setupScheduler(); - void setupComposer(uint32_t virtualDisplayCount); sp<BufferQueueLayer> createBufferQueueLayer(); sp<BufferStateLayer> createBufferStateLayer(); sp<EffectLayer> createEffectLayer(); @@ -69,7 +68,6 @@ protected: void commitTransaction(Layer* layer); TestableSurfaceFlinger mFlinger; - Hwc2::mock::Composer* mComposer = nullptr; sp<Client> mClient; sp<Layer> mParent; @@ -83,7 +81,7 @@ RefreshRateSelectionTest::RefreshRateSelectionTest() { ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); - setupComposer(0); + mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); } RefreshRateSelectionTest::~RefreshRateSelectionTest() { @@ -147,14 +145,6 @@ void RefreshRateSelectionTest::setupScheduler() { std::move(eventThread), std::move(sfEventThread)); } -void RefreshRateSelectionTest::setupComposer(uint32_t virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); -} - namespace { /* ------------------------------------------------------------------------ * Test cases diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index 38e503fc81..7a6ae5bbc2 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -34,7 +34,7 @@ using testing::Return; namespace android { namespace { -constexpr PhysicalDisplayId PHYSICAL_DISPLAY_ID(999); +constexpr PhysicalDisplayId PHYSICAL_DISPLAY_ID = PhysicalDisplayId::fromPort(255u); class SchedulerTest : public testing::Test { protected: diff --git a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp index c088ddc971..46ef75091e 100644 --- a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp +++ b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp @@ -118,14 +118,12 @@ protected: SetFrameRateTest(); void setupScheduler(); - void setupComposer(uint32_t virtualDisplayCount); void addChild(sp<Layer> layer, sp<Layer> child); void removeChild(sp<Layer> layer, sp<Layer> child); void commitTransaction(); TestableSurfaceFlinger mFlinger; - Hwc2::mock::Composer* mComposer = nullptr; mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); std::vector<sp<Layer>> mLayers; @@ -139,10 +137,11 @@ SetFrameRateTest::SetFrameRateTest() { mFlinger.mutableUseFrameRateApi() = true; setupScheduler(); - setupComposer(0); + mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); mFlinger.mutableEventQueue().reset(mMessageQueue); } + void SetFrameRateTest::addChild(sp<Layer> layer, sp<Layer> child) { layer.get()->addChild(child.get()); } @@ -184,14 +183,6 @@ void SetFrameRateTest::setupScheduler() { /*hasMultipleModes*/ true); } -void SetFrameRateTest::setupComposer(uint32_t virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); -} - namespace { /* ------------------------------------------------------------------------ * Test cases diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_OnHotplugReceivedTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp index 42f4cf31ba..bd89397ef6 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_OnHotplugReceivedTest.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_HotplugTest.cpp @@ -22,19 +22,15 @@ namespace android { namespace { -class OnHotplugReceivedTest : public DisplayTransactionTest {}; +class HotplugTest : public DisplayTransactionTest {}; -TEST_F(OnHotplugReceivedTest, hotplugEnqueuesEventsForDisplayTransaction) { - constexpr int currentSequenceId = 123; +TEST_F(HotplugTest, enqueuesEventsForDisplayTransaction) { constexpr HWDisplayId hwcDisplayId1 = 456; constexpr HWDisplayId hwcDisplayId2 = 654; // -------------------------------------------------------------------- // Preconditions - // Set the current sequence id for accepted events - mFlinger.mutableComposerSequenceId() = currentSequenceId; - // Set the main thread id so that the current thread does not appear to be // the main thread. mFlinger.mutableMainThreadId() = std::thread::id(); @@ -50,8 +46,8 @@ TEST_F(OnHotplugReceivedTest, hotplugEnqueuesEventsForDisplayTransaction) { // Invocation // Simulate two hotplug events (a connect and a disconnect) - mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId1, Connection::CONNECTED); - mFlinger.onHotplugReceived(currentSequenceId, hwcDisplayId2, Connection::DISCONNECTED); + mFlinger.onComposerHalHotplug(hwcDisplayId1, Connection::CONNECTED); + mFlinger.onComposerHalHotplug(hwcDisplayId2, Connection::DISCONNECTED); // -------------------------------------------------------------------- // Postconditions @@ -68,52 +64,14 @@ TEST_F(OnHotplugReceivedTest, hotplugEnqueuesEventsForDisplayTransaction) { EXPECT_EQ(Connection::DISCONNECTED, pendingEvents[1].connection); } -TEST_F(OnHotplugReceivedTest, hotplugDiscardsUnexpectedEvents) { - constexpr int currentSequenceId = 123; - constexpr int otherSequenceId = 321; - constexpr HWDisplayId displayId = 456; - - // -------------------------------------------------------------------- - // Preconditions - - // Set the current sequence id for accepted events - mFlinger.mutableComposerSequenceId() = currentSequenceId; - - // Set the main thread id so that the current thread does not appear to be - // the main thread. - mFlinger.mutableMainThreadId() = std::thread::id(); - - // -------------------------------------------------------------------- - // Call Expectations - - // We do not expect any calls to invalidate(). - EXPECT_CALL(*mMessageQueue, invalidate()).Times(0); - - // -------------------------------------------------------------------- - // Invocation - - // Call with an unexpected sequence id - mFlinger.onHotplugReceived(otherSequenceId, displayId, Connection::INVALID); - - // -------------------------------------------------------------------- - // Postconditions - - // The display transaction needed flag should not be set - EXPECT_FALSE(hasTransactionFlagSet(eDisplayTransactionNeeded)); - - // There should be no pending events - EXPECT_TRUE(mFlinger.mutablePendingHotplugEvents().empty()); -} - -TEST_F(OnHotplugReceivedTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread) { - constexpr int currentSequenceId = 123; +TEST_F(HotplugTest, processesEnqueuedEventsIfCalledOnMainThread) { constexpr HWDisplayId displayId1 = 456; // -------------------------------------------------------------------- // Note: // -------------------------------------------------------------------- // This test case is a bit tricky. We want to verify that - // onHotplugReceived() calls processDisplayHotplugEventsLocked(), but we + // onComposerHalHotplug() calls processDisplayHotplugEventsLocked(), but we // don't really want to provide coverage for everything the later function // does as there are specific tests for it. // -------------------------------------------------------------------- @@ -121,9 +79,6 @@ TEST_F(OnHotplugReceivedTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread // -------------------------------------------------------------------- // Preconditions - // Set the current sequence id for accepted events - mFlinger.mutableComposerSequenceId() = currentSequenceId; - // Set the main thread id so that the current thread does appear to be the // main thread. mFlinger.mutableMainThreadId() = std::this_thread::get_id(); @@ -139,9 +94,9 @@ TEST_F(OnHotplugReceivedTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread // Invocation // Simulate a disconnect on a display id that is not connected. This should - // be enqueued by onHotplugReceived(), and dequeued by + // be enqueued by onComposerHalHotplug(), and dequeued by // processDisplayHotplugEventsLocked(), but then ignored as invalid. - mFlinger.onHotplugReceived(currentSequenceId, displayId1, Connection::DISCONNECTED); + mFlinger.onComposerHalHotplug(displayId1, Connection::DISCONNECTED); // -------------------------------------------------------------------- // Postconditions @@ -155,4 +110,4 @@ TEST_F(OnHotplugReceivedTest, hotplugProcessesEnqueuedEventsIfCalledOnMainThread } } // namespace -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index d004b9d9eb..82eb3bfc18 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -42,7 +42,6 @@ #include "SurfaceInterceptor.h" #include "TestableScheduler.h" #include "mock/DisplayHardware/MockComposer.h" -#include "mock/MockDisplayIdGenerator.h" #include "mock/MockFrameTimeline.h" #include "mock/MockFrameTracer.h" @@ -185,9 +184,6 @@ public: SurfaceFlinger* flinger() { return mFlinger.get(); } TestableScheduler* scheduler() { return mScheduler; } - mock::DisplayIdGenerator<GpuVirtualDisplayId>& gpuVirtualDisplayIdGenerator() { - return mGpuVirtualDisplayIdGenerator; - } // Extend this as needed for accessing SurfaceFlinger private (and public) // functions. @@ -308,6 +304,8 @@ public: return mFlinger->destroyDisplay(displayToken); } + void enableHalVirtualDisplays(bool enable) { mFlinger->enableHalVirtualDisplays(enable); } + auto setupNewDisplayDeviceInternal( const wp<IBinder>& displayToken, std::shared_ptr<compositionengine::Display> compositionDisplay, @@ -323,9 +321,8 @@ public: return mFlinger->handleTransactionLocked(transactionFlags); } - auto onHotplugReceived(int32_t sequenceId, hal::HWDisplayId display, - hal::Connection connection) { - return mFlinger->onHotplugReceived(sequenceId, display, connection); + void onComposerHalHotplug(hal::HWDisplayId hwcDisplayId, hal::Connection connection) { + mFlinger->onComposerHalHotplug(hwcDisplayId, connection); } auto setDisplayStateLocked(const DisplayState& s) { @@ -436,11 +433,9 @@ public: auto& mutablePhysicalDisplayTokens() { return mFlinger->mPhysicalDisplayTokens; } auto& mutableTexturePool() { return mFlinger->mTexturePool; } auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; } - auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; } auto& mutablePowerAdvisor() { return mFlinger->mPowerAdvisor; } auto& mutableDebugDisableHWC() { return mFlinger->mDebugDisableHWC; } - auto& mutableComposerSequenceId() { return mFlinger->getBE().mComposerSequenceId; } auto& mutableHwcDisplayData() { return getHwComposer().mDisplayData; } auto& mutableHwcPhysicalDisplayIdMap() { return getHwComposer().mPhysicalDisplayIdMap; } auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; } @@ -775,7 +770,6 @@ private: surfaceflinger::test::Factory mFactory; sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization); TestableScheduler* mScheduler = nullptr; - mock::DisplayIdGenerator<GpuVirtualDisplayId> mGpuVirtualDisplayIdGenerator; }; } // namespace android diff --git a/services/surfaceflinger/tests/unittests/TransactionFrameTracerTest.cpp b/services/surfaceflinger/tests/unittests/TransactionFrameTracerTest.cpp index 25001d3890..546bc4a17b 100644 --- a/services/surfaceflinger/tests/unittests/TransactionFrameTracerTest.cpp +++ b/services/surfaceflinger/tests/unittests/TransactionFrameTracerTest.cpp @@ -45,7 +45,7 @@ public: ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); - setupComposer(0); + mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); } ~TransactionFrameTracerTest() { @@ -91,17 +91,9 @@ public: std::move(eventThread), std::move(sfEventThread)); } - void setupComposer(uint32_t virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); - } - TestableSurfaceFlinger mFlinger; - Hwc2::mock::Composer* mComposer = nullptr; renderengine::mock::RenderEngine mRenderEngine; + FenceToFenceTimeMap fenceFactory; client_cache_t mClientCache; diff --git a/services/surfaceflinger/tests/unittests/TransactionSurfaceFrameTest.cpp b/services/surfaceflinger/tests/unittests/TransactionSurfaceFrameTest.cpp index b7917aa00e..c1123cd6e8 100644 --- a/services/surfaceflinger/tests/unittests/TransactionSurfaceFrameTest.cpp +++ b/services/surfaceflinger/tests/unittests/TransactionSurfaceFrameTest.cpp @@ -45,7 +45,7 @@ public: ::testing::UnitTest::GetInstance()->current_test_info(); ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); setupScheduler(); - setupComposer(0); + mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); } ~TransactionSurfaceFrameTest() { @@ -91,17 +91,9 @@ public: std::move(eventThread), std::move(sfEventThread)); } - void setupComposer(uint32_t virtualDisplayCount) { - mComposer = new Hwc2::mock::Composer(); - EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); - mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); - - Mock::VerifyAndClear(mComposer); - } - TestableSurfaceFlinger mFlinger; - Hwc2::mock::Composer* mComposer = nullptr; renderengine::mock::RenderEngine mRenderEngine; + FenceToFenceTimeMap fenceFactory; client_cache_t mClientCache; diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h index 1ba3c0f56e..cb3bd73920 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h @@ -54,7 +54,8 @@ public: MOCK_METHOD0(resetCommands, void()); MOCK_METHOD0(executeCommands, Error()); MOCK_METHOD0(getMaxVirtualDisplayCount, uint32_t()); - MOCK_METHOD4(createVirtualDisplay, Error(uint32_t, uint32_t, PixelFormat*, Display*)); + MOCK_METHOD5(createVirtualDisplay, + Error(uint32_t, uint32_t, PixelFormat*, std::optional<Display>, Display*)); MOCK_METHOD1(destroyVirtualDisplay, Error(Display)); MOCK_METHOD1(acceptDisplayChanges, Error(Display)); MOCK_METHOD2(createLayer, Error(Display, Layer* outLayer)); diff --git a/services/surfaceflinger/tests/unittests/mock/MockDisplayIdGenerator.h b/services/surfaceflinger/tests/unittests/mock/MockDisplayIdGenerator.h deleted file mode 100644 index cfc37ea8d9..0000000000 --- a/services/surfaceflinger/tests/unittests/mock/MockDisplayIdGenerator.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 <gmock/gmock.h> - -#include "DisplayIdGenerator.h" - -namespace android::mock { - -template <typename T> -class DisplayIdGenerator : public android::DisplayIdGenerator<T> { -public: - // Explicit default instantiation is recommended. - DisplayIdGenerator() = default; - virtual ~DisplayIdGenerator() = default; - - MOCK_METHOD0(nextId, std::optional<T>()); - MOCK_METHOD1(markUnused, void(T)); -}; - -} // namespace android::mock |