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

Commit 4c2f8a62 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Add test for synced_resolution_switch

Bug: 355427258
Flag: com.android.graphics.surfaceflinger.flags.synced_resolution_switch
Test: DisplayModeSwitchingTest.changeResolutionSynced
Change-Id: I3e4eeea1d8cfa47714ac3e42da182e0210b49b2b
parent f863ba4d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -114,7 +114,11 @@ public:
    // Test instances

    TestableSurfaceFlinger mFlinger;

    sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
    sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
            sp<compositionengine::mock::DisplaySurface>::make();

    sp<GraphicBuffer> mBuffer =
            sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888,
                                    GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN);
@@ -294,6 +298,7 @@ struct DisplayVariant {

        injector.setSecure(static_cast<bool>(SECURE));
        injector.setNativeWindow(test->mNativeWindow);
        injector.setDisplaySurface(test->mDisplaySurface);

        // Creating a DisplayDevice requires getting default dimensions from the
        // native window along with some other initial setup.
+47 −1
Original line number Diff line number Diff line
@@ -171,16 +171,22 @@ protected:
    static constexpr DisplayModeId kModeId90{1};
    static constexpr DisplayModeId kModeId120{2};
    static constexpr DisplayModeId kModeId90_4K{3};
    static constexpr DisplayModeId kModeId60_8K{4};

    static inline const DisplayModePtr kMode60 = createDisplayMode(kModeId60, 60_Hz, 0);
    static inline const DisplayModePtr kMode90 = createDisplayMode(kModeId90, 90_Hz, 1);
    static inline const DisplayModePtr kMode120 = createDisplayMode(kModeId120, 120_Hz, 2);

    static constexpr ui::Size kResolution4K{3840, 2160};
    static constexpr ui::Size kResolution8K{7680, 4320};

    static inline const DisplayModePtr kMode90_4K =
            createDisplayMode(kModeId90_4K, 90_Hz, 3, kResolution4K);
    static inline const DisplayModePtr kMode60_8K =
            createDisplayMode(kModeId60_8K, 60_Hz, 4, kResolution8K);

    static inline const DisplayModes kModes = makeModes(kMode60, kMode90, kMode120, kMode90_4K);
    static inline const DisplayModes kModes =
            makeModes(kMode60, kMode90, kMode120, kMode90_4K, kMode60_8K);
};

void DisplayModeSwitchingTest::setupScheduler(
@@ -326,6 +332,8 @@ TEST_F(DisplayModeSwitchingTest, twoConsecutiveSetDesiredDisplayModeSpecs) {
}

TEST_F(DisplayModeSwitchingTest, changeResolutionWithoutRefreshRequired) {
    SET_FLAG_FOR_TEST(flags::synced_resolution_switch, false);

    EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));

    EXPECT_EQ(NO_ERROR,
@@ -360,6 +368,44 @@ TEST_F(DisplayModeSwitchingTest, changeResolutionWithoutRefreshRequired) {
    EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId90_4K));
}

TEST_F(DisplayModeSwitchingTest, changeResolutionSynced) {
    SET_FLAG_FOR_TEST(flags::synced_resolution_switch, true);

    EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));

    // PrimaryDisplayVariant has a 4K size, so switch to 8K.
    EXPECT_EQ(NO_ERROR,
              mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
                                                  mock::createDisplayModeSpecs(kModeId60_8K,
                                                                               60_Hz)));

    EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));

    // The mode should not be set until the commit that resizes the display.
    mFlinger.commit();
    EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));
    mFlinger.commit();
    EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));

    // Set the display size to match the resolution.
    DisplayState state;
    state.what = DisplayState::eDisplaySizeChanged;
    state.token = mDisplay->getDisplayToken().promote();
    state.width = static_cast<uint32_t>(kResolution8K.width);
    state.height = static_cast<uint32_t>(kResolution8K.height);

    // The next commit should set the mode and resize the framebuffer.
    const VsyncPeriodChangeTimeline timeline{.refreshRequired = false};
    EXPECT_CALL(*mDisplaySurface, resizeBuffers(kResolution8K));
    EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId60_8K);

    constexpr bool kModeset = true;
    mFlinger.setDisplayStateLocked(state);
    mFlinger.configureAndCommit(kModeset);

    EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60_8K));
}

TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
    SET_FLAG_FOR_TEST(flags::connected_display, true);

+6 −3
Original line number Diff line number Diff line
@@ -337,9 +337,9 @@ public:
        mFlinger->configure();
    }

    void configureAndCommit() {
    void configureAndCommit(bool modeset = false) {
        configure();
        commitTransactionsLocked(eDisplayTransactionNeeded);
        commitTransactionsLocked(eDisplayTransactionNeeded, modeset);
    }

    void commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime,
@@ -429,11 +429,14 @@ public:
                                                       dispSurface, producer);
    }

    void commitTransactionsLocked(uint32_t transactionFlags) {
    void commitTransactionsLocked(uint32_t transactionFlags, bool modeset = false) {
        Mutex::Autolock lock(mFlinger->mStateLock);
        ftl::FakeGuard guard(kMainThreadContext);
        mFlinger->processDisplayChangesLocked();
        mFlinger->commitTransactionsLocked(transactionFlags);
        if (modeset) {
            mFlinger->initiateDisplayModeChanges();
        }
    }

    void onComposerHalHotplugEvent(hal::HWDisplayId hwcDisplayId, DisplayHotplugEvent event) {