-
Notifications
You must be signed in to change notification settings - Fork 90
Introduce a display subsystem for GPU output #319
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
mtjhrc
wants to merge
5
commits into
containers:main
Choose a base branch
from
mtjhrc:gtk-display
base: main
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
87ae2a4
utils: Introduce pollable_channel()
mtjhrc 3255a04
gpu: Fix GetDisplayInfo command decoding
mtjhrc 382d7a0
devices, virtio/gpu: Introduce a display subsystem
mtjhrc 0f5aecd
display: Introduce GTK display backend
mtjhrc 102c12f
examples/chroot_vm: Add --display parameter for attaching displays
mtjhrc 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,116 @@ | ||
mod worker; | ||
|
||
use crate::display::gtk::worker::gtk_display_main_loop; | ||
use crate::display::{check_scanout_id, DisplayBackend, DisplayBackendError, DisplayInfoList}; | ||
use crate::virtio::GpuResourceFormat; | ||
use gtk4::gdk; | ||
use std::thread; | ||
use utils::pollable_channel::{pollable_channel, PollableChannelSender}; | ||
|
||
enum DisplayEvent { | ||
ConfigureScanout { | ||
scanout_id: u32, | ||
width: i32, | ||
height: i32, | ||
format: gdk::MemoryFormat, | ||
}, | ||
DisableScanout { | ||
scanout_id: u32, | ||
}, | ||
UpdateScanout { | ||
scanout_id: u32, | ||
data: Vec<u8>, | ||
/// stride/pitch of row specified in bytes | ||
stride: u32, | ||
}, | ||
} | ||
|
||
pub struct DisplayBackendGtk { | ||
tx: PollableChannelSender<DisplayEvent>, | ||
displays: DisplayInfoList, | ||
} | ||
|
||
fn resource_format_into_gdk(format: GpuResourceFormat) -> gdk::MemoryFormat { | ||
match format { | ||
GpuResourceFormat::BGRA => gdk::MemoryFormat::B8g8r8a8, | ||
GpuResourceFormat::BGRX => gdk::MemoryFormat::B8g8r8x8, | ||
GpuResourceFormat::ARGB => gdk::MemoryFormat::A8r8g8b8, | ||
GpuResourceFormat::XRGB => gdk::MemoryFormat::X8r8g8b8, | ||
GpuResourceFormat::RGBA => gdk::MemoryFormat::R8g8b8a8, | ||
GpuResourceFormat::XBGR => gdk::MemoryFormat::X8b8g8r8, | ||
GpuResourceFormat::ABGR => gdk::MemoryFormat::A8b8g8r8, | ||
GpuResourceFormat::RGBX => gdk::MemoryFormat::R8g8b8x8, | ||
} | ||
} | ||
|
||
impl DisplayBackendGtk { | ||
pub fn new(displays: DisplayInfoList) -> DisplayBackendGtk { | ||
let (tx, rx) = pollable_channel().unwrap(); | ||
let displays_clone = displays.clone(); | ||
thread::Builder::new() | ||
.name("gtk display".to_string()) | ||
.spawn(move || { | ||
gtk_display_main_loop(rx, displays_clone); | ||
}) | ||
.unwrap(); | ||
|
||
Self { displays, tx } | ||
} | ||
} | ||
|
||
impl DisplayBackend for DisplayBackendGtk { | ||
fn displays(&self) -> &DisplayInfoList { | ||
&self.displays | ||
} | ||
|
||
fn configure_scanout( | ||
&self, | ||
scanout_id: u32, | ||
width: u32, | ||
height: u32, | ||
format: GpuResourceFormat, | ||
) -> Result<(), DisplayBackendError> { | ||
check_scanout_id(self, scanout_id)?; | ||
let Ok(width) = width.try_into() else { | ||
warn!("Display width out of range"); | ||
return Err(DisplayBackendError::InvalidParameter); | ||
}; | ||
|
||
let Ok(height) = height.try_into() else { | ||
warn!("Display width out of range"); | ||
return Err(DisplayBackendError::InvalidParameter); | ||
}; | ||
|
||
let format = resource_format_into_gdk(format); | ||
|
||
self.tx.send(DisplayEvent::ConfigureScanout { | ||
scanout_id, | ||
width, | ||
height, | ||
format, | ||
})?; | ||
Ok(()) | ||
} | ||
|
||
fn disable_scanout(&self, scanout_id: u32) -> Result<(), DisplayBackendError> { | ||
check_scanout_id(self, scanout_id)?; | ||
self.tx.send(DisplayEvent::DisableScanout { scanout_id })?; | ||
Ok(()) | ||
} | ||
|
||
fn update_scanout( | ||
&self, | ||
scanout_id: u32, | ||
data: Vec<u8>, | ||
stride: u32, | ||
) -> Result<(), DisplayBackendError> { | ||
check_scanout_id(self, scanout_id)?; | ||
|
||
self.tx.send(DisplayEvent::UpdateScanout { | ||
scanout_id, | ||
data, | ||
stride, | ||
})?; | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.
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.
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.
it is already pulled by gtk4, no need for a specific dep.