1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
34//! Common video device-related definitions.
56#![forbid(unsafe_code)]
78use inspect::Inspect;
9use mesh::MeshPayload;
10use mesh::payload::Protobuf;
11use vm_resource::CanResolveTo;
12use vm_resource::ResourceId;
13use vm_resource::kind::FramebufferHandleKind;
1415impl CanResolveTo<ResolvedFramebuffer> for FramebufferHandleKind {
16type Input<'a> = ();
17}
1819/// A resolved framebuffer.
20pub struct ResolvedFramebuffer(pub Box<dyn FramebufferControl>);
2122impl<T: 'static + FramebufferControl> From<T> for ResolvedFramebuffer {
23fn from(value: T) -> Self {
24Self(Box::new(value))
25 }
26}
2728/// A handle to the global shared framebuffer that has been mapped with the VM.
29#[derive(MeshPayload)]
30pub struct SharedFramebufferHandle;
3132impl ResourceId<FramebufferHandleKind> for SharedFramebufferHandle {
33const ID: &'static str = "shared";
34}
3536/// The framebuffer memory format.
37#[derive(Debug, Copy, Clone, Protobuf, PartialEq, Eq, Inspect)]
38#[mesh(package = "framebuffer")]
39pub struct FramebufferFormat {
40/// Width in pixels.
41#[mesh(1)]
42pub width: usize,
43/// Height in pixels.
44#[mesh(2)]
45pub height: usize,
46/// Bytes per scanline.
47#[mesh(3)]
48pub bytes_per_line: usize,
49/// Starting offset.
50#[mesh(4)]
51pub offset: usize,
52}
5354/// Functions necessary to control the framebuffer from a video device.
55///
56/// This trait needs to be async so that an implementation of these functions can be async.
57///
58/// For example, the GET request needed to map the framebuffer from Underhill is async since
59/// the video device needs to wait for a response from the host to send an ack to the guest.
60#[async_trait::async_trait]
61pub trait FramebufferControl: Send {
62/// Maps the framebuffer to the guest at the specified GPA.
63async fn map(&mut self, gpa: u64);
64/// Unmaps the framebuffer from the guest.
65async fn unmap(&mut self);
66/// Updates the framebuffer format.
67async fn set_format(&mut self, format: FramebufferFormat);
68}