From 2ce1563b5f6dbf6f530c1b33b1b31576dbda49b3 Mon Sep 17 00:00:00 2001 From: MaxsTechReview Date: Thu, 26 Nov 2026 21:55:32 -0500 Subject: [PATCH] fix(display): clients pacing on presentation feedback draw at the frame limit, not the panel rate (#3311) Report the frame limit's interval as the refresh in presentation feedback --- app/src/main/cpp/waylandcomp/src/compositor.c | 10 ++- tools/tests/test_feedback_refresh.py | 72 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tools/tests/test_feedback_refresh.py diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 3641760ed1..98b5746037 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -1198,6 +1198,14 @@ static uint32_t nominal_refresh_ns(void) { return (uint32_t)(1000000000000LL / (int64_t)mhz); } +static uint32_t feedback_refresh_ns(void) { + const int limit = g_fps_limit; + const uint32_t panel = nominal_refresh_ns(); + if (limit <= 0 || g_release_unpaced) return panel; + const uint32_t paced = (uint32_t)(1000000000LL / limit); + return paced > panel ? paced : panel; +} + static int64_t presented_ns(int64_t render_ns) { int64_t tick = g_tick_vsync_ns; int64_t refresh = (int64_t)nominal_refresh_ns(); @@ -1216,7 +1224,7 @@ static void feedback_present_all(struct wl_list *list, int64_t t) { uint32_t nsec = (uint32_t)(t % 1000000000LL); wl_resource_for_each_safe(fb, tmp, list) { wp_presentation_feedback_send_presented(fb, (uint32_t)(sec >> 32), (uint32_t)sec, nsec, - nominal_refresh_ns(), 0, 0, + feedback_refresh_ns(), 0, 0, WP_PRESENTATION_FEEDBACK_KIND_VSYNC); wl_resource_destroy(fb); g_pace.presented++; diff --git a/tools/tests/test_feedback_refresh.py b/tools/tests/test_feedback_refresh.py new file mode 100644 index 0000000000..0f4f772824 --- /dev/null +++ b/tools/tests/test_feedback_refresh.py @@ -0,0 +1,72 @@ +import shutil +import subprocess +import tempfile +import unittest +from pathlib import Path + +from test_output_refresh import SOURCE, extract_function + + +PROBE = r''' +#include +#include +#include +#include + +static atomic_int g_output_refresh_mhz; +static volatile int g_fps_limit; +static volatile int g_release_unpaced; + +%s +%s + +int main(int argc, char **argv) { + atomic_store(&g_output_refresh_mhz, atoi(argv[1])); + g_fps_limit = atoi(argv[2]); + g_release_unpaced = atoi(argv[3]); + printf("%%u\n", feedback_refresh_ns()); + return 0; +} +''' + + +@unittest.skipUnless(shutil.which('cc'), 'needs a C compiler') +class FeedbackRefreshTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + source = SOURCE.read_text() + cls.tmp = tempfile.TemporaryDirectory() + probe = Path(cls.tmp.name) / 'probe.c' + probe.write_text(PROBE % (extract_function(source, 'nominal_refresh_ns'), + extract_function(source, 'feedback_refresh_ns'))) + cls.binary = Path(cls.tmp.name) / 'probe' + subprocess.run(['cc', '-std=c11', '-Wall', '-Werror', str(probe), '-o', str(cls.binary)], check=True) + + @classmethod + def tearDownClass(cls): + cls.tmp.cleanup() + + def refresh(self, mhz, limit, unpaced=0): + out = subprocess.run([str(self.binary), str(mhz), str(limit), str(unpaced)], + check=True, capture_output=True, text=True).stdout + return int(out) + + def test_no_limit_reports_the_panel_refresh(self): + self.assertEqual(self.refresh(120000, 0), 8333333) + self.assertEqual(self.refresh(60000, 0), 16666666) + + def test_limit_below_the_panel_reports_the_limit_interval(self): + self.assertEqual(self.refresh(120000, 60), 16666666) + self.assertEqual(self.refresh(120000, 30), 33333333) + self.assertEqual(self.refresh(90000, 45), 22222222) + + def test_limit_at_or_above_the_panel_keeps_the_panel_refresh(self): + self.assertEqual(self.refresh(60000, 60), 16666666) + self.assertEqual(self.refresh(60000, 144), 16666666) + + def test_unpaced_sessions_keep_the_panel_refresh(self): + self.assertEqual(self.refresh(120000, 60, unpaced=1), 8333333) + + +if __name__ == '__main__': + unittest.main()