0

Fix Headless browser_tests failures with CADisplayLink enabled

Use base::MessagePumpType::NS_RUNLOOP instead of
base::MessagePumpType::DEFAULT for Headless main_thread_task_executor
on the CrGpuMain thread. CADisplayLink will not work without
NS_RUNLOOP.

Regressions are reported in CL5894417: Revert "Enable CADisplayLink in fieldtrial_testing_config." | https://chromium-review.googlesource.com/c/chromium/src/+/5894417

Bug: 345275139
Change-Id: I3821bb336ce9b86b5e41441211a303ac4402662f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5898112
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Commit-Queue: Maggie Chen <magchen@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1362633}
This commit is contained in:
Maggie Chen
2024-10-01 20:08:37 +00:00
committed by Chromium LUCI CQ
parent bc2d4cb64a
commit b539c3b14f
2 changed files with 16 additions and 0 deletions
content/gpu
ui/display/mac

@ -267,9 +267,17 @@ int GpuMain(MainFunctionParams parameters) {
std::unique_ptr<base::SingleThreadTaskExecutor> main_thread_task_executor;
std::unique_ptr<ui::PlatformEventSource> event_source;
if (command_line.HasSwitch(switches::kHeadless)) {
#if BUILDFLAG(IS_MAC)
// CADisplayLink (Mac HW VSync) callback only works with NS_RUNLOOP.
main_thread_task_executor =
std::make_unique<base::SingleThreadTaskExecutor>(
base::MessagePumpType::NS_RUNLOOP);
main_thread_task_executor->SetWorkBatchSize(2);
#else
main_thread_task_executor =
std::make_unique<base::SingleThreadTaskExecutor>(
base::MessagePumpType::DEFAULT);
#endif
} else {
#if BUILDFLAG(IS_WIN)
// The GpuMain thread should not be pumping Windows messages because no UI
@ -291,6 +299,8 @@ int GpuMain(MainFunctionParams parameters) {
// Cross-process CoreAnimation requires a CFRunLoop to function at all, and
// requires a NSRunLoop to not starve under heavy load. See:
// https://crbug.com/312462#c51 and https://crbug.com/783298
// CADisplayLink (Mac HW VSync) callback only works with NS_RUNLOOP. DEFAULT
// type does not support NSObject.
main_thread_task_executor =
std::make_unique<base::SingleThreadTaskExecutor>(
base::MessagePumpType::NS_RUNLOOP);

@ -253,6 +253,12 @@ scoped_refptr<DisplayLinkMac> CADisplayLinkMac::GetForDisplayOnCurrentThread(
.maximum = refresh_rate,
.preferred = refresh_rate};
// This display link interface requires the task executor of the current
// thread (CrGpuMain or VizCompositorThread) to run with
// MessagePumpType::NS_RUNLOOP. CADisplayLinkTarget and display_link are
// NSObject, and MessagePumpType::DEFAULT does not support system work.
// There will be no callbacks (CADisplayLinkTarget::step()) at all if
// MessagePumpType NS_RUNLOOP is not chosen during thread initialization.
[objc_state->display_link addToRunLoop:NSRunLoop.currentRunLoop
forMode:NSDefaultRunLoopMode];