Skip to content

feat(linux/kms): turn the stream upright when the compositor rotates the screen - #6234

Draft
miguelangel-nubla wants to merge 1 commit into
SunshineStream:masterfrom
miguelangel-nubla:feat/kms-output-rotation
Draft

miguelangel-nubla wants to merge 1 commit into
SunshineStream:masterfrom
miguelangel-nubla:feat/kms-output-rotation

Conversation

@miguelangel-nubla

Copy link
Copy Markdown

Description

On Linux, a compositor can rotate a screen in two ways: with the plane's hardware rotation, or by drawing the desktop already turned into a normal landscape framebuffer. GNOME on amdgpu does the latter (here, a 4K TV mounted in portrait and set to "Rotate right"). KMS capture reads that framebuffer as it is, so the stream shows the desktop on its side.

The Wayland output transform says how the picture is turned, and Sunshine already keeps it (viewport.transform, from #6020). With this change, KMS capture uses it when the captured plane isn't rotated by the hardware:

  • The EGL conversion passes (egl::sws_t, used by VAAPI and the CUDA GL path) sample the capture turned back. A rotation uniform (quarter turns) is added to Scene.vert and ConvertUV.vert; the cursor pass, drawn onto the capture before the conversion, keeps its default of 0. The letterbox is sized for the upright picture.
  • The display reports the upright size (e.g. 2160x3840), so the client gets a portrait stream.
  • The display's own transform stays 0. The picture is already upright, so absolute input maps onto the logical (xdg-output) size as it is, without the point rotation fix(linux/wlr): map absolute mouse input on rotated outputs #6020 added for wlgrab's sideways capture.
  • Encoders that can't turn the picture (Vulkan, the RAM path) log a warning and stream the picture as captured, as before. Flipped transforms (4-7) are left alone, with a warning.
  • When the plane is rotated by the hardware, nothing changes: the framebuffer is already upright, and the existing panel-orientation handling applies.

The rule (transform and plane rotation to quarter turns) is a small free function, platf::kms::upright_quarter_turns(), so it can be unit tested without a GPU.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

  • New unit tests in tests/unit/platform/linux/test_kmsgrab_rotation.cpp (KmsGrabRotation.*) for upright_quarter_turns(): each transform turned back, reflection bits ignored, a hardware-rotated plane not turned, flipped and unknown transforms left alone.
  • Built on master (13ca613) with scripts/linux_build.sh (no CUDA) in an Ubuntu 26.04 amd64 container and ran test_sunshine under Xvfb: 1019 tests, 1012 passed, 7 skipped, 0 failed (before the new tests: 1013, 1006, 7, 0).
  • End to end, on real hardware: Ubuntu 24.04, GNOME 46 on Wayland, an AMD GPU (VAAPI), a 4K TV rotated right (output transform 3), Moonlight as the client. The same change on Sunshine 2026.1018.5342 (this PR is that commit ported onto master, where fix(linux/wlr): map absolute mouse input on rotated outputs #6020 already keeps the transform). Before: the stream is on its side. After: Sunshine logs Screen rotated by the compositor (output transform 3): turning the stream upright, 2160x3840, the stream is upright, and an absolute mouse lands where pointed. With the Vulkan encoder it logs the warning and streams as before.
  • Not tested: the CUDA GL path (no NVIDIA GPU here; it uses the same egl::sws_t conversion), and rotations other than 270 on real hardware.
  • clang-format (the version in uv.lock) reports no changes for the touched files.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

…the screen

A compositor that rotates a screen without the plane's hardware rotation
(GNOME on amdgpu, for one) scans out a framebuffer with the picture already
turned, and KMS captures it as it is: a portrait desktop streamed on its
side (SunshineStream#3203).

The Wayland output transform (viewport.transform, from wl_output) says how
the picture is turned. When the captured plane isn't rotated by the
hardware, the EGL conversion passes (VAAPI, CUDA) now sample the capture
turned back: a rotation uniform in Scene.vert and ConvertUV.vert, with the
letterbox sized for the upright picture. The display reports the upright
size, and its own transform stays 0: the stream is upright, so absolute
input maps onto the logical (xdg-output) size as it is, unlike wlgrab's
sideways capture (SunshineStream#6020).

Encoders that can't turn the picture (Vulkan, the RAM path) log a warning
and stream it as captured, as before. Flipped transforms are left alone.
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

1 participant