Skip to content

Commit 1e9f87e

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "SF: Add test for synced_resolution_switch" into main
2 parents e5694ec + 4c2f8a6 commit 1e9f87e

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ class DisplayTransactionTest : public testing::Test {
114114
// Test instances
115115

116116
TestableSurfaceFlinger mFlinger;
117+
117118
sp<mock::NativeWindow> mNativeWindow = sp<mock::NativeWindow>::make();
119+
sp<compositionengine::mock::DisplaySurface> mDisplaySurface =
120+
sp<compositionengine::mock::DisplaySurface>::make();
121+
118122
sp<GraphicBuffer> mBuffer =
119123
sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_8888,
120124
GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN);
@@ -294,6 +298,7 @@ struct DisplayVariant {
294298

295299
injector.setSecure(static_cast<bool>(SECURE));
296300
injector.setNativeWindow(test->mNativeWindow);
301+
injector.setDisplaySurface(test->mDisplaySurface);
297302

298303
// Creating a DisplayDevice requires getting default dimensions from the
299304
// native window along with some other initial setup.

services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,22 @@ class DisplayModeSwitchingTest : public DisplayTransactionTest {
171171
static constexpr DisplayModeId kModeId90{1};
172172
static constexpr DisplayModeId kModeId120{2};
173173
static constexpr DisplayModeId kModeId90_4K{3};
174+
static constexpr DisplayModeId kModeId60_8K{4};
174175

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

179180
static constexpr ui::Size kResolution4K{3840, 2160};
181+
static constexpr ui::Size kResolution8K{7680, 4320};
182+
180183
static inline const DisplayModePtr kMode90_4K =
181184
createDisplayMode(kModeId90_4K, 90_Hz, 3, kResolution4K);
185+
static inline const DisplayModePtr kMode60_8K =
186+
createDisplayMode(kModeId60_8K, 60_Hz, 4, kResolution8K);
182187

183-
static inline const DisplayModes kModes = makeModes(kMode60, kMode90, kMode120, kMode90_4K);
188+
static inline const DisplayModes kModes =
189+
makeModes(kMode60, kMode90, kMode120, kMode90_4K, kMode60_8K);
184190
};
185191

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

328334
TEST_F(DisplayModeSwitchingTest, changeResolutionWithoutRefreshRequired) {
335+
SET_FLAG_FOR_TEST(flags::synced_resolution_switch, false);
336+
329337
EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
330338

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

371+
TEST_F(DisplayModeSwitchingTest, changeResolutionSynced) {
372+
SET_FLAG_FOR_TEST(flags::synced_resolution_switch, true);
373+
374+
EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
375+
376+
// PrimaryDisplayVariant has a 4K size, so switch to 8K.
377+
EXPECT_EQ(NO_ERROR,
378+
mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
379+
mock::createDisplayModeSpecs(kModeId60_8K,
380+
60_Hz)));
381+
382+
EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));
383+
384+
// The mode should not be set until the commit that resizes the display.
385+
mFlinger.commit();
386+
EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));
387+
mFlinger.commit();
388+
EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId60_8K));
389+
390+
// Set the display size to match the resolution.
391+
DisplayState state;
392+
state.what = DisplayState::eDisplaySizeChanged;
393+
state.token = mDisplay->getDisplayToken().promote();
394+
state.width = static_cast<uint32_t>(kResolution8K.width);
395+
state.height = static_cast<uint32_t>(kResolution8K.height);
396+
397+
// The next commit should set the mode and resize the framebuffer.
398+
const VsyncPeriodChangeTimeline timeline{.refreshRequired = false};
399+
EXPECT_CALL(*mDisplaySurface, resizeBuffers(kResolution8K));
400+
EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId60_8K);
401+
402+
constexpr bool kModeset = true;
403+
mFlinger.setDisplayStateLocked(state);
404+
mFlinger.configureAndCommit(kModeset);
405+
406+
EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60_8K));
407+
}
408+
363409
TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
364410
SET_FLAG_FOR_TEST(flags::connected_display, true);
365411

services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ class TestableSurfaceFlinger {
337337
mFlinger->configure();
338338
}
339339

340-
void configureAndCommit() {
340+
void configureAndCommit(bool modeset = false) {
341341
configure();
342-
commitTransactionsLocked(eDisplayTransactionNeeded);
342+
commitTransactionsLocked(eDisplayTransactionNeeded, modeset);
343343
}
344344

345345
void commit(TimePoint frameTime, VsyncId vsyncId, TimePoint expectedVsyncTime,
@@ -429,11 +429,14 @@ class TestableSurfaceFlinger {
429429
dispSurface, producer);
430430
}
431431

432-
void commitTransactionsLocked(uint32_t transactionFlags) {
432+
void commitTransactionsLocked(uint32_t transactionFlags, bool modeset = false) {
433433
Mutex::Autolock lock(mFlinger->mStateLock);
434434
ftl::FakeGuard guard(kMainThreadContext);
435435
mFlinger->processDisplayChangesLocked();
436436
mFlinger->commitTransactionsLocked(transactionFlags);
437+
if (modeset) {
438+
mFlinger->initiateDisplayModeChanges();
439+
}
437440
}
438441

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

0 commit comments

Comments
 (0)