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

Commit 36efc341 authored by Su Hong Koo's avatar Su Hong Koo Committed by Android (Google) Code Review
Browse files

Merge changes I7e33c132,Iac4b00fe into main

* changes:
  SF: Extend synthetic vsync and thread optimizations to external displays
  SF: Avoid redundant pacesetter setting in SF::setPhysicalDisplayPowerMode
parents 00a4d4d3 b042537b
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -5784,7 +5784,8 @@ void SurfaceFlinger::setPhysicalDisplayPowerMode(const sp<DisplayDevice>& displa
    const bool shouldApplyOptimizationPolicy =
    const bool shouldApplyOptimizationPolicy =
            FlagManager::getInstance().disable_synthetic_vsync_for_performance() &&
            FlagManager::getInstance().disable_synthetic_vsync_for_performance() &&
            FlagManager::getInstance().correct_virtual_display_power_state();
            FlagManager::getInstance().correct_virtual_display_power_state();
    if (isInternalDisplay && shouldApplyOptimizationPolicy) {
    if ((isInternalDisplay || FlagManager::getInstance().pacesetter_selection()) &&
        shouldApplyOptimizationPolicy) {
        applyOptimizationPolicy(__func__);
        applyOptimizationPolicy(__func__);
    }
    }


@@ -5896,7 +5897,8 @@ void SurfaceFlinger::setPhysicalDisplayPowerMode(const sp<DisplayDevice>& displa
    }
    }


    mScheduler->setDisplayPowerMode(displayId, mode);
    mScheduler->setDisplayPowerMode(displayId, mode);
    if (FlagManager::getInstance().pacesetter_selection()) {
    if (FlagManager::getInstance().pacesetter_selection() &&
        mScheduler->getPacesetterDisplayId() != mFrontInternalDisplayId) {
        // TODO: b/389983418 - Update pacesetter designation inside
        // TODO: b/389983418 - Update pacesetter designation inside
        // Scheduler::setDisplayPowerMode().
        // Scheduler::setDisplayPowerMode().
        mScheduler->setPacesetterDisplay(mFrontInternalDisplayId);
        mScheduler->setPacesetterDisplay(mFrontInternalDisplayId);
+53 −72
Original line number Original line Diff line number Diff line
@@ -68,56 +68,6 @@ struct DozeNotSupportedVariant {
    }
    }
};
};


struct EventThreadBaseSupportedVariant {
    static void setupVsyncNoCallExpectations(DisplayTransactionTest* test) {
        // Expect no change to hardware nor synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, _)).Times(0);
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(_)).Times(0);
    }
};

struct EventThreadNotSupportedVariant : public EventThreadBaseSupportedVariant {
    static void setupEnableVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, true)).Times(1);
        setupDisableSyntheticVsyncCallExpectations(test);
    }

    static void setupDisableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(_)).Times(0);
    }

    static void setupDisableVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, false)).Times(1);
        setupEnableSyntheticVsyncCallExpectations(test);
    }

    static void setupEnableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(_)).Times(0);
    }
};

struct EventThreadIsSupportedVariant : public EventThreadBaseSupportedVariant {
    static void setupEnableVsyncCallExpectations(DisplayTransactionTest* test) {
        // Expect to enable hardware VSYNC and disable synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, true)).Times(1);
        setupDisableSyntheticVsyncCallExpectations(test);
    }

    static void setupDisableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(false)).Times(1);
    }

    static void setupDisableVsyncCallExpectations(DisplayTransactionTest* test) {
        // Expect to disable hardware VSYNC and enable synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, false)).Times(1);
        setupEnableSyntheticVsyncCallExpectations(test);
    }

    static void setupEnableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(true)).Times(1);
    }
};

struct DispSyncIsSupportedVariant {
struct DispSyncIsSupportedVariant {
    static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
    static void setupResetModelCallExpectations(DisplayTransactionTest* test) {
        auto vsyncSchedule = test->mFlinger.scheduler()->getVsyncSchedule();
        auto vsyncSchedule = test->mFlinger.scheduler()->getVsyncSchedule();
@@ -153,7 +103,7 @@ struct TransitionOffToOnVariant : public TransitionVariantCommon<PowerMode::OFF,
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::setupRepaintEverythingCallExpectations(test);
        Case::setupRepaintEverythingCallExpectations(test);
    }
    }
@@ -168,7 +118,7 @@ struct TransitionOffToDozeSuspendVariant
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
        Case::EventThread::setupEnableSyntheticVsyncCallExpectations(test);
        Case::setupEnableSyntheticVsyncCallExpectations(test);
        Case::setupRepaintEverythingCallExpectations(test);
        Case::setupRepaintEverythingCallExpectations(test);
    }
    }


@@ -180,7 +130,7 @@ struct TransitionOffToDozeSuspendVariant
struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
struct TransitionOnToOffVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::OFF> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupDisableVsyncCallExpectations(test);
        Case::setupDisableVsyncCallExpectations(test);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
    }
    }


@@ -193,7 +143,7 @@ struct TransitionDozeSuspendToOffVariant
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::OFF> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupEnableSyntheticVsyncCallExpectations(test);
        Case::setupEnableSyntheticVsyncCallExpectations(test);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::OFF);
    }
    }


@@ -205,7 +155,7 @@ struct TransitionDozeSuspendToOffVariant
struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
struct TransitionOnToDozeVariant : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
    }
    }
};
};
@@ -214,7 +164,7 @@ struct TransitionDozeSuspendToDozeVariant
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::DOZE> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE);
    }
    }
@@ -223,7 +173,7 @@ struct TransitionDozeSuspendToDozeVariant
struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
struct TransitionDozeToOnVariant : public TransitionVariantCommon<PowerMode::DOZE, PowerMode::ON> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
    }
    }
};
};
@@ -232,7 +182,7 @@ struct TransitionDozeSuspendToOnVariant
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
      : public TransitionVariantCommon<PowerMode::DOZE_SUSPEND, PowerMode::ON> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupEnableVsyncCallExpectations(test);
        Case::setupEnableVsyncCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::DispSync::setupResetModelCallExpectations(test);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
        Case::setupComposerCallExpectations(test, IComposerClient::PowerMode::ON);
    }
    }
@@ -242,7 +192,7 @@ struct TransitionOnToDozeSuspendVariant
      : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
      : public TransitionVariantCommon<PowerMode::ON, PowerMode::DOZE_SUSPEND> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupDisableVsyncCallExpectations(test);
        Case::setupDisableVsyncCallExpectations(test);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
        Case::setupComposerCallExpectations(test, Case::Doze::ACTUAL_POWER_MODE_FOR_DOZE_SUSPEND);
    }
    }
};
};
@@ -251,7 +201,7 @@ struct TransitionOnToUnknownVariant
      : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
      : public TransitionVariantCommon<PowerMode::ON, static_cast<PowerMode>(POWER_MODE_LEET)> {
    template <typename Case>
    template <typename Case>
    static void setupCallExpectations(DisplayTransactionTest* test) {
    static void setupCallExpectations(DisplayTransactionTest* test) {
        Case::EventThread::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupDisableSyntheticVsyncCallExpectations(test);
        Case::setupNoComposerPowerModeCallExpectations(test);
        Case::setupNoComposerPowerModeCallExpectations(test);
    }
    }
};
};
@@ -264,12 +214,11 @@ struct TransitionOnToUnknownVariant
// display type, and the other for another display type.
// display type, and the other for another display type.
// --------------------------------------------------------------------
// --------------------------------------------------------------------


template <typename DisplayVariant, typename DozeVariant, typename EventThreadVariant,
template <typename DisplayVariant, typename DozeVariant, typename DispSyncVariant,
          typename DispSyncVariant, typename TransitionVariant>
          typename TransitionVariant>
struct DisplayPowerCase {
struct DisplayPowerCase {
    using Display = DisplayVariant;
    using Display = DisplayVariant;
    using Doze = DozeVariant;
    using Doze = DozeVariant;
    using EventThread = EventThreadVariant;
    using DispSync = DispSyncVariant;
    using DispSync = DispSyncVariant;
    using Transition = TransitionVariant;
    using Transition = TransitionVariant;


@@ -308,19 +257,41 @@ struct DisplayPowerCase {
    static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
    static void setupNoComposerPowerModeCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
        EXPECT_CALL(*test->mComposer, setPowerMode(Display::HWC_DISPLAY_ID, _)).Times(0);
    }
    }

    static void setupVsyncNoCallExpectations(DisplayTransactionTest* test) {
        // Expect no change to hardware nor synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, _)).Times(0);
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(_)).Times(0);
    }

    static void setupEnableVsyncCallExpectations(DisplayTransactionTest* test) {
        // Expect to enable hardware VSYNC and disable synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, true)).Times(1);
        setupDisableSyntheticVsyncCallExpectations(test);
    }

    static void setupDisableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(false)).Times(1);
    }

    static void setupDisableVsyncCallExpectations(DisplayTransactionTest* test) {
        // Expect to disable hardware VSYNC and enable synthetic VSYNC.
        EXPECT_CALL(test->mFlinger.scheduler()->mockRequestHardwareVsync, Call(_, false)).Times(1);
        setupEnableSyntheticVsyncCallExpectations(test);
    }

    static void setupEnableSyntheticVsyncCallExpectations(DisplayTransactionTest* test) {
        EXPECT_CALL(*test->mEventThread, enableSyntheticVsync(true)).Times(1);
    }
};
};


// A sample configuration for the primary display.
// A sample configuration for the primary display. We emulate doze support.
// In addition to having event thread support, we emulate doze support.
template <typename TransitionVariant>
template <typename TransitionVariant>
using PrimaryDisplayPowerCase =
using PrimaryDisplayPowerCase =
        DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
        DisplayPowerCase<PrimaryDisplayVariant, DozeIsSupportedVariant<PrimaryDisplayVariant>,
                         EventThreadIsSupportedVariant, DispSyncIsSupportedVariant,
                         DispSyncIsSupportedVariant, TransitionVariant>;
                         TransitionVariant>;


// A sample configuration for the external display.
// A sample configuration for the external display. We emulate not having doze support.
// In addition to not having event thread support, we emulate not having doze
// support.
// TODO (b/267483230): ExternalDisplay supports the features tracked in
// TODO (b/267483230): ExternalDisplay supports the features tracked in
// DispSyncIsSupportedVariant, but is the follower, so the
// DispSyncIsSupportedVariant, but is the follower, so the
// expectations set by DispSyncIsSupportedVariant don't match (wrong schedule).
// expectations set by DispSyncIsSupportedVariant don't match (wrong schedule).
@@ -329,11 +300,13 @@ using PrimaryDisplayPowerCase =
template <typename TransitionVariant>
template <typename TransitionVariant>
using ExternalDisplayPowerCase =
using ExternalDisplayPowerCase =
        DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
        DisplayPowerCase<ExternalDisplayVariant, DozeNotSupportedVariant<ExternalDisplayVariant>,
                         EventThreadNotSupportedVariant, DispSyncNotSupportedVariant,
                         DispSyncNotSupportedVariant, TransitionVariant>;
                         TransitionVariant>;


class SetPhysicalDisplayPowerModeTest : public DisplayTransactionTest {
class SetPhysicalDisplayPowerModeTest : public DisplayTransactionTest {
public:
public:
    static constexpr bool kWithMockScheduler = false;
    SetPhysicalDisplayPowerModeTest() : DisplayTransactionTest(kWithMockScheduler) {}

    template <typename Case>
    template <typename Case>
    void transitionDisplayCommon();
    void transitionDisplayCommon();
};
};
@@ -355,6 +328,14 @@ void SetPhysicalDisplayPowerModeTest::transitionDisplayCommon() {
    SET_FLAG_FOR_TEST(android::companion::virtualdevice::flags::correct_virtual_display_power_state,
    SET_FLAG_FOR_TEST(android::companion::virtualdevice::flags::correct_virtual_display_power_state,
                      true);
                      true);
    SET_FLAG_FOR_TEST(flags::disable_synthetic_vsync_for_performance, true);
    SET_FLAG_FOR_TEST(flags::disable_synthetic_vsync_for_performance, true);
    SET_FLAG_FOR_TEST(flags::pacesetter_selection, true);

    const auto displayIdOpt = asPhysicalDisplayId(Case::Display::DISPLAY_ID::get());
    ASSERT_TRUE(displayIdOpt);
    injectMockScheduler(*displayIdOpt);
    // TODO: b/389983418 - Remove once the Scheduler is no longer dependent on front internal
    // display.
    mFlinger.mutableFrontInternalDisplayId() = *displayIdOpt;


    Case::Doze::setupComposerCallExpectations(this);
    Case::Doze::setupComposerCallExpectations(this);
    auto display =
    auto display =