Commit ef32eb9
[MAPSAND-2265] Fix MapSurface.setMaximumFps not working on secondary displays (#10405)
### Summary
Fixes https://mapbox.atlassian.net/browse/MAPSAND-2265
- Fix `MapSurface.setMaximumFps` returning wrong FPS on secondary
displays (e.g. Android Auto)
- Use `Context.getDisplay()` on API 30+ instead of
`WindowManager.defaultDisplay`
- Change is confined to a single method in `MapSurface.kt`
### Problem
`MapSurface.surfaceCreated()` reads the screen refresh rate via
`WindowManager.defaultDisplay.refreshRate`, which always returns the
**primary display's** refresh rate. When `MapSurface` runs on a
secondary display (e.g. Android Auto at 60Hz) with a 120Hz primary
display, `setMaximumFps(30)` produces ~60fps instead of 30fps. The
`FpsManager` receives 120Hz as the screen rate, yielding a ratio of
30/120=0.25 instead of the correct 30/60=0.5.
### Solution
On API 30+ (`Build.VERSION_CODES.R`), use `Context.getDisplay()` to
obtain the display the surface is actually attached to, consistent with
how `MapView.onStart()` already uses `View.getDisplay()`. Fall back to
the deprecated `WindowManager.defaultDisplay` on older APIs.
### Key Changes
- **`MapSurface.kt` `surfaceCreated()`**:
`WindowManager.defaultDisplay.refreshRate` →
`Context.getDisplay().refreshRate` (API 30+)
### Note on reproduction
I was not able to reproduce the exact issue described in the ticket. My
test setup: phone with 120Hz display + Android Auto emulator supporting
60fps. Both `context.display.refreshRate` and
`(context.getSystemService(Context.WINDOW_SERVICE) as
WindowManager?)?.defaultDisplay?.refreshRate` returned 60, and the
Android Auto refresh rate can be correctly set to 30fps both before and
after the change. It might require a specific device/head unit
combination to reproduce the discrepancy.
### Validation
- [x] Manual test: `setMaximumFps(30)` on a 60Hz secondary display
produces ~30fps as expected
cc @mapbox/maps-android
GitOrigin-RevId: ab04871940ea3b605a7c0e6894a1975fb6f448ba1 parent a179e9d commit ef32eb9
2 files changed
Lines changed: 10 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
101 | 106 | | |
102 | 107 | | |
103 | 108 | | |
| |||
0 commit comments