driver/graphics: Implement Debug for a bunch of things
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::ffi::c_char;
|
||||
use std::fmt::Debug;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::mem;
|
||||
@@ -22,8 +23,8 @@ use crate::objects::{DrmConnector, DrmObjectId, DrmObjects};
|
||||
|
||||
pub mod objects;
|
||||
|
||||
pub trait GraphicsAdapter: Sized {
|
||||
type Connector;
|
||||
pub trait GraphicsAdapter: Sized + Debug {
|
||||
type Connector: Debug;
|
||||
|
||||
type Framebuffer: Framebuffer;
|
||||
type Cursor: CursorFramebuffer;
|
||||
|
||||
@@ -5,6 +5,7 @@ use syscall::{Error, Result, EINVAL};
|
||||
|
||||
use crate::GraphicsAdapter;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrmObjects<T: GraphicsAdapter> {
|
||||
next_id: DrmObjectId,
|
||||
objects: HashMap<DrmObjectId, DrmObject<T>>,
|
||||
@@ -122,22 +123,25 @@ impl<T: GraphicsAdapter> DrmObjects<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct DrmObjectId(pub(crate) u32);
|
||||
|
||||
impl DrmObjectId {
|
||||
pub const INVALID: DrmObjectId = DrmObjectId(0);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DrmObject<T: GraphicsAdapter> {
|
||||
kind: DrmObjectKind<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DrmObjectKind<T: GraphicsAdapter> {
|
||||
Connector(DrmConnector<T>),
|
||||
Encoder(DrmEncoder),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrmConnector<T: GraphicsAdapter> {
|
||||
pub modes: Vec<drm_mode_modeinfo>,
|
||||
pub encoder_id: DrmObjectId,
|
||||
@@ -150,7 +154,7 @@ pub struct DrmConnector<T: GraphicsAdapter> {
|
||||
pub driver_data: T::Connector,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
pub enum DrmConnectorStatus {
|
||||
Disconnected = 0,
|
||||
@@ -158,7 +162,7 @@ pub enum DrmConnectorStatus {
|
||||
Unknown = 2,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
pub enum DrmSubpixelOrder {
|
||||
Unknown = 0,
|
||||
@@ -170,6 +174,7 @@ pub enum DrmSubpixelOrder {
|
||||
}
|
||||
|
||||
// FIXME can we represent connector and encoder using a single struct?
|
||||
#[derive(Debug)]
|
||||
pub struct DrmEncoder {
|
||||
pub crtc_id: DrmObjectId,
|
||||
pub possible_crtcs: u32,
|
||||
|
||||
@@ -5,7 +5,7 @@ use common::{
|
||||
use embedded_hal::prelude::*;
|
||||
use pcid_interface::{PciFunction, PciFunctionHandle};
|
||||
use range_alloc::RangeAllocator;
|
||||
use std::{collections::VecDeque, mem, sync::Arc, time::Duration};
|
||||
use std::{collections::VecDeque, fmt, mem, sync::Arc, time::Duration};
|
||||
use syscall::error::{Error, Result, EIO, ENODEV, ERANGE};
|
||||
|
||||
mod aux;
|
||||
@@ -172,6 +172,19 @@ pub struct Device {
|
||||
transcoders: Vec<Transcoder>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Device {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Device")
|
||||
.field("kind", &self.kind)
|
||||
.field("alloc_buffers", &self.alloc_buffers)
|
||||
.field("alloc_surfaces", &self.alloc_surfaces)
|
||||
.field("gttmm", &self.gttmm)
|
||||
.field("gm", &self.gm)
|
||||
.field("ref_freq", &self.ref_freq)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn new(pcid_handle: &mut PciFunctionHandle, func: &PciFunction) -> Result<Self> {
|
||||
let kind = match (func.full_device_id.vendor_id, func.full_device_id.device_id) {
|
||||
|
||||
@@ -14,6 +14,7 @@ use syscall::{error::EINVAL, PAGE_SIZE};
|
||||
|
||||
use super::Device;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Connector {
|
||||
framebuffer_id: usize,
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ use graphics_ipc::v1::Damage;
|
||||
use graphics_ipc::v2::ipc::{DRM_CAP_DUMB_BUFFER, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT};
|
||||
use syscall::{EINVAL, PAGE_SIZE};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FbAdapter {
|
||||
pub framebuffers: Vec<FrameBuffer>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Connector {
|
||||
width: u32,
|
||||
height: u32,
|
||||
@@ -108,6 +110,7 @@ impl GraphicsAdapter for FbAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FrameBuffer {
|
||||
pub onscreen: *mut [u32],
|
||||
pub phys: usize,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use common::{dma::Dma, sgl};
|
||||
@@ -27,6 +28,7 @@ impl Into<GpuRect> for Damage {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct VirtGpuConnector {
|
||||
display_id: u32,
|
||||
}
|
||||
@@ -88,6 +90,14 @@ pub struct VirtGpuAdapter<'a> {
|
||||
displays: Vec<Display>,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for VirtGpuAdapter<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("VirtGpuAdapter")
|
||||
.field("displays", &self.displays)
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtGpuAdapter<'_> {
|
||||
pub async fn update_displays(&mut self) -> Result<(), Error> {
|
||||
let display_info = self.get_display_info().await?;
|
||||
|
||||
Reference in New Issue
Block a user