Skip to content

fix(kms): run modesetting after the surface is resized #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(kms_platform)]
mod imple {
use drm::control::{connector, Device as CtrlDevice, Event, ModeTypeFlags, PlaneType};
use drm::Device;
use drm::{ClientCapability, Device};

use raw_window_handle::{DisplayHandle, DrmDisplayHandle, DrmWindowHandle, WindowHandle};
use softbuffer::{Context, Surface};
Expand All @@ -16,6 +16,7 @@ mod imple {
pub(super) fn entry() -> Result<(), Box<dyn std::error::Error>> {
// Open a new device.
let device = Card::find()?;
device.set_client_capability(ClientCapability::UniversalPlanes, true)?;

// Create the softbuffer context.
let context = unsafe {
Expand Down
23 changes: 23 additions & 0 deletions src/backends/kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ impl<D: HasDisplayHandle + ?Sized, W: HasWindowHandle> SurfaceInterface<D, W> fo
let front_buffer = SharedBuffer::new(&self.display, width, height)?;
let back_buffer = SharedBuffer::new(&self.display, width, height)?;

// Iterate over all modes of all the connectors,
// and pick one that is compatible with the size given by the user.
let mode = self
.connectors
.iter()
.flat_map(|con| self.display.get_modes(*con).unwrap())
.find(|mode| {
mode.size().0 as u32 == u32::from(width)
&& mode.size().1 as u32 == u32::from(height)
})
.swbuf_err("No mode found")?;

// When changing the display resolution, we need to modeset
self.display
.set_crtc(
self.crtc.handle(),
Some(front_buffer.fb),
(0, 0),
&self.connectors,
Some(mode),
)
.swbuf_err("Failed to modeset")?;

self.buffer = Some(Buffers {
first_is_front: true,
buffers: [front_buffer, back_buffer],
Expand Down