pub struct VirtioGpuDriver { /* private fields */ }Expand description
VirtIO GPU Driver
Manages a single virtio-gpu device including its control and cursor virtqueues, display configuration, and framebuffer resources.
Implementations§
Source§impl VirtioGpuDriver
impl VirtioGpuDriver
Sourcepub fn new(mmio_base: usize) -> Result<Self, KernelError>
pub fn new(mmio_base: usize) -> Result<Self, KernelError>
Create and initialize a new VirtIO GPU driver at the given MMIO base.
Sourcepub fn get_display_info(&mut self) -> Result<VirtioGpuDisplayOne, KernelError>
pub fn get_display_info(&mut self) -> Result<VirtioGpuDisplayOne, KernelError>
Query display information from the device.
Returns the first enabled display mode (scanout 0 is preferred).
Sourcepub fn create_resource_2d(
&mut self,
resource_id: u32,
format: u32,
width: u32,
height: u32,
) -> Result<(), KernelError>
pub fn create_resource_2d( &mut self, resource_id: u32, format: u32, width: u32, height: u32, ) -> Result<(), KernelError>
Create a 2D resource on the host.
Sourcepub fn resource_unref(&mut self, resource_id: u32) -> Result<(), KernelError>
pub fn resource_unref(&mut self, resource_id: u32) -> Result<(), KernelError>
Destroy a 2D resource on the host.
Sourcepub fn attach_backing(
&mut self,
resource_id: u32,
addr: u64,
length: u32,
) -> Result<(), KernelError>
pub fn attach_backing( &mut self, resource_id: u32, addr: u64, length: u32, ) -> Result<(), KernelError>
Attach backing store (guest memory) to a resource.
The command includes a VirtioGpuMemEntry that describes the physical address and length of the backing memory.
Sourcepub fn detach_backing(&mut self, resource_id: u32) -> Result<(), KernelError>
pub fn detach_backing(&mut self, resource_id: u32) -> Result<(), KernelError>
Detach backing store from a resource.
Sourcepub fn set_scanout(
&mut self,
scanout_id: u32,
resource_id: u32,
rect: VirtioGpuRect,
) -> Result<(), KernelError>
pub fn set_scanout( &mut self, scanout_id: u32, resource_id: u32, rect: VirtioGpuRect, ) -> Result<(), KernelError>
Set scanout: bind a resource (or region of it) to a display output.
Sourcepub fn transfer_to_host_2d(
&mut self,
resource_id: u32,
rect: VirtioGpuRect,
) -> Result<(), KernelError>
pub fn transfer_to_host_2d( &mut self, resource_id: u32, rect: VirtioGpuRect, ) -> Result<(), KernelError>
Transfer data from guest backing store to host resource.
Sourcepub fn resource_flush(
&mut self,
resource_id: u32,
rect: VirtioGpuRect,
) -> Result<(), KernelError>
pub fn resource_flush( &mut self, resource_id: u32, rect: VirtioGpuRect, ) -> Result<(), KernelError>
Flush a resource region to the display.
Sourcepub fn setup_framebuffer(&mut self) -> Result<(), KernelError>
pub fn setup_framebuffer(&mut self) -> Result<(), KernelError>
Set up the primary framebuffer: create a 2D resource, attach a backing pixel buffer, and bind it to scanout 0.
Sourcepub fn flush_framebuffer(&mut self) -> Result<(), KernelError>
pub fn flush_framebuffer(&mut self) -> Result<(), KernelError>
Flush the framebuffer to the display.
Transfers the entire backing buffer to the host and triggers a display refresh. Call this after modifying the framebuffer pixels.
Sourcepub fn flush_region(&mut self, rect: VirtioGpuRect) -> Result<(), KernelError>
pub fn flush_region(&mut self, rect: VirtioGpuRect) -> Result<(), KernelError>
Flush a sub-region of the framebuffer.
More efficient than flushing the entire framebuffer when only a small area has changed.
Sourcepub fn get_framebuffer_mut(&mut self) -> Option<&mut [u32]>
pub fn get_framebuffer_mut(&mut self) -> Option<&mut [u32]>
Get mutable access to the framebuffer pixel buffer.
Returns a slice of BGRX pixels. Modify the pixels, then call
flush_framebuffer() or flush_region() to push changes to the
display.
Sourcepub fn get_framebuffer(&self) -> Option<&[u32]>
pub fn get_framebuffer(&self) -> Option<&[u32]>
Get read-only access to the framebuffer pixel buffer.
Sourcepub fn supports_edid(&self) -> bool
pub fn supports_edid(&self) -> bool
Check if EDID is supported.
Sourcepub fn supports_virgl(&self) -> bool
pub fn supports_virgl(&self) -> bool
Check if 3D (VIRGL) is supported.
Sourcepub fn framebuffer_resource_id(&self) -> u32
pub fn framebuffer_resource_id(&self) -> u32
Get the framebuffer resource ID.
Sourcepub fn alloc_resource_id(&mut self) -> u32
pub fn alloc_resource_id(&mut self) -> u32
Allocate a new resource ID.
Sourcepub fn set_pixel(
&mut self,
x: u32,
y: u32,
color: u32,
) -> Result<(), KernelError>
pub fn set_pixel( &mut self, x: u32, y: u32, color: u32, ) -> Result<(), KernelError>
Set a pixel in the framebuffer (BGRX format).
Does NOT flush automatically – call flush_framebuffer() after
modifying pixels.
Sourcepub fn fill_rect(
&mut self,
x: u32,
y: u32,
w: u32,
h: u32,
color: u32,
) -> Result<(), KernelError>
pub fn fill_rect( &mut self, x: u32, y: u32, w: u32, h: u32, color: u32, ) -> Result<(), KernelError>
Fill a rectangle in the framebuffer with a solid color.
Does NOT flush automatically.
Sourcepub fn blit(
&mut self,
buffer: &[u32],
x: u32,
y: u32,
w: u32,
h: u32,
) -> Result<(), KernelError>
pub fn blit( &mut self, buffer: &[u32], x: u32, y: u32, w: u32, h: u32, ) -> Result<(), KernelError>
Blit a buffer of pixels into the framebuffer.
The buffer must contain w * h BGRX pixels. Does NOT flush
automatically.