-
Notifications
You must be signed in to change notification settings - Fork 1.1k
wayland: add and implement EventLoopExtDrm #4300
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
mahkoh
wants to merge
1
commit into
rust-windowing:master
Choose a base branch
from
mahkoh:jorth/main-gpu-device
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use libc::dev_t; | ||
| use sctk::globals::GlobalData; | ||
| use wayland_client::globals::{BindError, GlobalList}; | ||
| use wayland_client::{delegate_dispatch, Connection, Dispatch, QueueHandle}; | ||
| use wayland_protocols::wp::linux_dmabuf::zv1::client::zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1; | ||
| use wayland_protocols::wp::linux_dmabuf::zv1::client::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1; | ||
| use wayland_protocols::wp::linux_dmabuf::zv1::client::{ | ||
| zwp_linux_dmabuf_feedback_v1, zwp_linux_dmabuf_v1, | ||
| }; | ||
|
|
||
| use crate::state::WinitState; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct LinuxDmabufManager { | ||
| _manager: ZwpLinuxDmabufV1, | ||
| feedback: LinuxDmabufFeedback, | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct LinuxDmabufFeedback { | ||
| _feedback: ZwpLinuxDmabufFeedbackV1, | ||
| device: Option<dev_t>, | ||
| pending_device: Option<dev_t>, | ||
| } | ||
|
|
||
| impl LinuxDmabufManager { | ||
| pub fn new( | ||
| globals: &GlobalList, | ||
| queue_handle: &QueueHandle<WinitState>, | ||
| ) -> Result<Self, BindError> { | ||
| let manager: ZwpLinuxDmabufV1 = globals.bind(queue_handle, 4..=5, GlobalData)?; | ||
| let feedback = manager.get_default_feedback(queue_handle, GlobalData); | ||
| let feedback = | ||
| LinuxDmabufFeedback { _feedback: feedback, device: None, pending_device: None }; | ||
| Ok(Self { _manager: manager, feedback }) | ||
| } | ||
|
|
||
| pub fn device(&self) -> Option<dev_t> { | ||
| self.feedback.device | ||
| } | ||
| } | ||
|
|
||
| impl Dispatch<ZwpLinuxDmabufV1, GlobalData, WinitState> for LinuxDmabufManager { | ||
| fn event( | ||
| _state: &mut WinitState, | ||
| _proxy: &ZwpLinuxDmabufV1, | ||
| _event: zwp_linux_dmabuf_v1::Event, | ||
| _data: &GlobalData, | ||
| _conn: &Connection, | ||
| _qhandle: &QueueHandle<WinitState>, | ||
| ) { | ||
| // nothing | ||
| } | ||
| } | ||
|
|
||
| impl Dispatch<ZwpLinuxDmabufFeedbackV1, GlobalData, WinitState> for LinuxDmabufManager { | ||
| fn event( | ||
| state: &mut WinitState, | ||
| _proxy: &ZwpLinuxDmabufFeedbackV1, | ||
| event: zwp_linux_dmabuf_feedback_v1::Event, | ||
| _data: &GlobalData, | ||
| _conn: &Connection, | ||
| _qhandle: &QueueHandle<WinitState>, | ||
| ) { | ||
| use zwp_linux_dmabuf_feedback_v1::Event; | ||
| match event { | ||
| Event::Done => { | ||
| let manager = state.linux_dmabuf_manager.as_mut().unwrap(); | ||
| if let Some(device) = manager.feedback.pending_device.take() { | ||
| manager.feedback.device = Some(device); | ||
| } | ||
| }, | ||
| Event::MainDevice { device } => { | ||
| let dev = dev_t::from_ne_bytes(device.try_into().unwrap()); | ||
| state.linux_dmabuf_manager.as_mut().unwrap().feedback.pending_device = Some(dev); | ||
| }, | ||
| _ => {}, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| delegate_dispatch!(WinitState: [ZwpLinuxDmabufV1: GlobalData] => LinuxDmabufManager); | ||
| delegate_dispatch!(WinitState: [ZwpLinuxDmabufFeedbackV1: GlobalData] => LinuxDmabufManager); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use libc::dev_t; | ||
|
|
||
| use crate::event_loop::EventLoop; | ||
|
|
||
| /// Additional methods on [`EventLoop`] that are specific to platforms using the Linux | ||
| /// Direct Rendering Manager (DRM). | ||
| pub trait EventLoopExtDrm { | ||
| /// Returns the device that the system prefers to use. | ||
| /// | ||
| /// The EGL EGL_EXT_device_drm and Vulkan VK_EXT_physical_device_drm extensions can be | ||
| /// used to select a matching device for accelerated rendering. | ||
| /// | ||
| /// This function returns `None` if the device is unknown. | ||
| fn main_drm_device(&self) -> Option<dev_t>; | ||
| } | ||
|
|
||
| impl EventLoopExtDrm for EventLoop { | ||
| fn main_drm_device(&self) -> Option<dev_t> { | ||
| self.event_loop.main_drm_device() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't care enough about X to implement this. But it is possible by using the
Dri3Openrequest to get a DRM fd and then calling stat on it.