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

Commit d6fbb8ab authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Test coverage for resetDisplayState

Add unit tests to cover SurfaceFlinger::resetDisplayState()

Test: libsurfaceflinger_unittest passes on Pixel XL
Bug: 74827900
Change-Id: Id0f2187612fb0f45f60e0caae91d2b36cdd0fdd9
parent a482f995
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -900,6 +900,55 @@ TEST_F(DisplayTransactionTest, destroyDisplayHandlesUnknownDisplay) {
    mFlinger.destroyDisplay(displayToken);
}

/* ------------------------------------------------------------------------
 * SurfaceFlinger::resetDisplayState
 */

TEST_F(DisplayTransactionTest, resetDisplayStateClearsState) {
    using Case = NonHwcVirtualDisplayCase;

    // --------------------------------------------------------------------
    // Preconditions

    // vsync is enabled and available
    mFlinger.mutablePrimaryHWVsyncEnabled() = true;
    mFlinger.mutableHWVsyncAvailable() = true;

    // A display exists
    auto existing = Case::Display::makeFakeExistingDisplayInjector(this);
    existing.inject();

    // --------------------------------------------------------------------
    // Call Expectations

    // The call disable vsyncs
    EXPECT_CALL(*mEventControlThread, setVsyncEnabled(false)).Times(1);

    // The call clears the current render engine surface
    EXPECT_CALL(*mRenderEngine, resetCurrentSurface());

    // --------------------------------------------------------------------
    // Invocation

    mFlinger.resetDisplayState();

    // --------------------------------------------------------------------
    // Postconditions

    // vsyncs should be off and not available.
    EXPECT_FALSE(mFlinger.mutablePrimaryHWVsyncEnabled());
    EXPECT_FALSE(mFlinger.mutableHWVsyncAvailable());

    // The display should have been removed from the display map.
    EXPECT_FALSE(hasDisplayDevice(existing.token()));

    // The display should still exist in the current state
    EXPECT_TRUE(hasCurrentDisplayState(existing.token()));

    // The display should have been removed from the drawing state
    EXPECT_FALSE(hasDrawingDisplayState(existing.token()));
}

/* ------------------------------------------------------------------------
 * SurfaceFlinger::setupNewDisplayDeviceInternal
 */
+4 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public:

    auto destroyDisplay(const sp<IBinder>& display) { return mFlinger->destroyDisplay(display); }

    auto resetDisplayState() { return mFlinger->resetDisplayState(); }

    auto setupNewDisplayDeviceInternal(const wp<IBinder>& display, int hwcId,
                                       const DisplayDeviceState& state,
                                       const sp<DisplaySurface>& dispSurface,
@@ -98,9 +100,11 @@ public:
    auto& mutableEventControlThread() { return mFlinger->mEventControlThread; }
    auto& mutableEventQueue() { return mFlinger->mEventQueue; }
    auto& mutableEventThread() { return mFlinger->mEventThread; }
    auto& mutableHWVsyncAvailable() { return mFlinger->mHWVsyncAvailable; }
    auto& mutableInterceptor() { return mFlinger->mInterceptor; }
    auto& mutableMainThreadId() { return mFlinger->mMainThreadId; }
    auto& mutablePendingHotplugEvents() { return mFlinger->mPendingHotplugEvents; }
    auto& mutablePrimaryHWVsyncEnabled() { return mFlinger->mPrimaryHWVsyncEnabled; }
    auto& mutableTransactionFlags() { return mFlinger->mTransactionFlags; }
    auto& mutableUseHwcVirtualDisplays() { return mFlinger->mUseHwcVirtualDisplays; }