Skip to content

fix: fullscreen surface oversized when --force-scale-factor is set (#329)#446

Closed
aki1770-del wants to merge 26 commits intosony:masterfrom
aki1770-del:fix/fullscreen-scale-factor-329
Closed

fix: fullscreen surface oversized when --force-scale-factor is set (#329)#446
aki1770-del wants to merge 26 commits intosony:masterfrom
aki1770-del:fix/fullscreen-scale-factor-329

Conversation

@aki1770-del
Copy link
Copy Markdown

Problem

When --fullscreen and --force-scale-factor=N are combined, the Wayland surface is created at native_width × N × native_height × N instead of the native display resolution. On an 800×480 display with --force-scale-factor=1.3, the surface becomes 1040×624, causing UI to extend off-screen (portions rendered outside the display area).

Reported in #329. Confirmed by two maintainers.

Root cause

wl_output_listener.mode stores native display pixels directly in view_properties_.width/height for the fullscreen case. The rest of the codebase treats view_properties_ as logical DIP and multiplies by current_scale_ to get physical dimensions — so CreateRenderSurface ends up at native_px × scale instead of native_px.

force_scale_factor is for adjusting the Flutter engine's device pixel ratio (DPR) so UI elements appear larger. It does not change the physical display resolution. The wl_surface_set_buffer_scale call receives the float value truncated to an integer (e.g. 1.3 → 1), so any surface buffer larger than native resolution is incorrect.

The xdg_toplevel_listener.configure callback already handles this correctly (next_width_dip = width / current_scale_). This fix makes wl_output_listener.mode consistent.

Fix

Two changes, both guarded by force_scale_factor so the auto-detected HiDPI path (wl_output.scale) is unchanged:

  1. wl_output_listener.mode: store display dimensions as logical DIP (width / current_scale_) when force_scale_factor is set, consistent with xdg_toplevel_listener.configure.

  2. CreateRenderSurface: use display_max_width_/height_ directly when force_scale_factor is set, avoiding floating-point rounding for non-integer scale values like 1.3.

Before / after

On an 800×480 display with --fullscreen --force-scale-factor=1.3:

Before After
Surface created at 1040×624 800×480
OnWindowSizeChanged reports 1040×624 px 800×480 px
Flutter DPR 1.3 1.3
Flutter DIP 800×480 615×369
UI element scale broken (off-screen) ✓ 1.3×

Non-force_scale_factor path: unchanged.

Fixes #329

lhoward and others added 26 commits December 18, 2025 16:51
The DRM backend failed to translate between view property dimensions (specified
in scaled pixels) and Flutter window mentrics (specified in physical pixels).

This patch fixes two issues: first, given the DRM backend (questionably)
overrides the dimensions specified by the application with the native window
dimensions but neglects to compensate for the current scaling factor.

Secondly, cursor and touch events are not correctly mapped from physical pixels
to scaled pixels.

Signed-off-by: Luke Howard <lukeh@padl.com>
These scripts are heavily based on what sony provided in [1],
with the container environment / cross compilation and some details
fixed up to allow rebuilding an older version more easily.

If these scripts live in the source repo further improvements can be
made to avoid cloning flutter-embedded-linux twice more, but they are
good enough for now, so let's start with what we have.

Link: sony/flutter-elinux#289 (comment) [1]
Build broke with gcc-15 due to `error: unknown type name 'uint8_t'`

Adding cstdint fixes that.
issues do not exist in flutter-elinux repo, so original sony links were kept

Also give thanks to sony for creating the fork
fix: add missing cstdint header
Fix DRM backend dimension scaling
flutter-elinux fork: update most URLs to github.com/flutter-elinux
When building with mesa 20 (debian bullseye) this define is missing,
so backport it.
Building with trixie requires a recent glibc/stdc++ environment
(GLIBC_2.38 / GLIBCXX_3.4.32), which might not be available on the
target environment.

Conversely, as far as libc/stdlib are concerned we are guarnateed to be
able to run an old binary on a newer system, so building on a system as
old as possible should address this particular issue.

Unfortunately libflutter*so also link against system libraries
(GL, X, wayland, fontconfig and many others), so if there is any so bump
or imcompatible ABI then this is still far from perfect:
future improvement should rebuild flutter-embedded-linux on demand for
the required target, from flutter-elinux's CMake configuration

The elinux embedded itself is not hard to build but libflutter_engine.so
will be more work, so settle with "back to the old state" level for now.
required if mutiple platforms are available, otherwise egl may call into
x11 and crash even if gbm is desired. tested on rk3588
Handle zwp_text_input_v1 and zwp_text_input_v3 purpose and hints based
on flutter's TextInputType settings.

This allows on-screen keyboards to adapt and e.g. display a number
keypad on number input.
release build got much bigger since flutter 3.32 (for debug it went from
83MB to 385MB)
This is apparently just because the lib is no longer stripped since [1]

This looks like a bug since we don't target android (tentative fix in
[2]), but until that lands just set --stripped manually.
Even if there is no C symbol dart stacktraces are available so most
people don't need these.

Link: flutter/flutter#161546 [1]
Link: flutter/flutter#181984 [2]
This allows compiling each individual file manually, so should fix any
problem with external projects using our includes in different orders.

Reported-by: Frede Hoey Braendstrup <frede@vokalo.io>
This was rebased manually but the code itself is verbatim.

Tested with squeekboard/niri using the text input v3 protocol.
includes: Add missing dependent headers
release: use old bullseye container for release build
release: strip flutter engine .so again
Previous commit typo'd the ifdef, which made it have no effect.

Since the define is identical the build didn't break for newer versions
and CI didn't complain, but bullseye wasn't fixed as it should have, so
address this.

Fixes: 3ac3f1a ("drm: add DRM_MODE_CONNECTOR_USB define for old releases")
Prevents crashes by clearing cursor_info_.pointer when the pointer
device (e.g., a mouse) disconnects and adding null check in
UpdateFlutterCursor.

Changes:
- Clear cursor_info_.pointer when WL_SEAT_CAPABILITY_POINTER is removed
- Add null check in UpdateFlutterCursor before accessing pointer

Fixes: 434d509 ("Multiple seats (sony#417)")
…e-dangling-ref

Fix cursor_info_.pointer dangling pointer on device disconnect (wayland)
Early fail if we are unable to create a render surface to avoid nullptr
dereference crashes further down the track.

Fixes: sony#14

Signed-off-by: Luke Howard <lukeh@padl.com>
Check CreateRenderSurface() return value
…ony#329)

When --fullscreen and --force-scale-factor=N are combined, the Wayland
surface was created at native_width*N x native_height*N instead of the
native display resolution. For example, a 800x480 display with
--force-scale-factor=1.3 produced a 1040x624 surface, causing UI to
render partially off-screen.

Root cause: wl_output_listener.mode stored the native display pixels
directly in view_properties_.width/height for the fullscreen case, but
the rest of the codebase treats view_properties_ as logical DIP. The
subsequent multiplication by current_scale_ in CreateRenderSurface then
over-scaled the surface dimensions.

force_scale_factor is intended to adjust the Flutter engine's device
pixel ratio (DPR) so that UI elements appear larger, not to increase
the surface buffer beyond the display's native resolution. The fix:

1. wl_output_listener.mode: when force_scale_factor is set, store the
   display dimensions as logical DIP (width / current_scale_), consistent
   with the xdg_toplevel_listener.configure callback which already does this.
2. CreateRenderSurface: when force_scale_factor is set and display_max
   dimensions are known, use display_max directly to avoid float rounding.

Signed-off-by: Akihiko Komada <aki1770@gmail.com>
@aki1770-del aki1770-del force-pushed the fix/fullscreen-scale-factor-329 branch from 43f0900 to dc6bbd1 Compare April 2, 2026 07:15
@aki1770-del
Copy link
Copy Markdown
Author

Repo has migrated to flutter-elinux/flutter-embedded-linux. Re-opening at https://github.com/flutter-elinux/flutter-embedded-linux.

@aki1770-del aki1770-del closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Add HighDPI support for Wayland" breaks fullscreen

8 participants