diff --git a/local/recipes/gpu/redox-drm/source/src/kms/property.rs b/local/recipes/gpu/redox-drm/source/src/kms/property.rs new file mode 100644 index 0000000000..51f9a78618 --- /dev/null +++ b/local/recipes/gpu/redox-drm/source/src/kms/property.rs @@ -0,0 +1,101 @@ +use std::fmt; + +#[derive(Clone, Debug)] +pub struct DrmProperty { + pub prop_id: u32, + pub name: String, + pub flags: u32, + pub prop_type: PropertyType, + pub object_id: u32, + pub object_type: ObjectType, +} + +#[derive(Clone, Debug)] +pub enum PropertyType { + Range { min: u64, max: u64, current: u64 }, + Enum { values: Vec<(u64, String)>, current: u64 }, + Blob { blob_id: u32 }, + Object { current: u32 }, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ObjectType { + Crtc, + Connector, + Plane, +} + +#[derive(Clone, Debug)] +pub struct PropertyRegistry { + properties: Vec, +} + +impl PropertyRegistry { + pub fn new() -> Self { + Self { properties: Vec::new() } + } + + pub fn register_range(&mut self, prop_id: u32, name: &str, flags: u32, + obj_id: u32, obj_type: ObjectType, + min: u64, max: u64, current: u64) { + self.properties.push(DrmProperty { + prop_id, name: name.to_string(), flags, + object_id: obj_id, object_type: obj_type, + prop_type: PropertyType::Range { min, max, current }, + }); + } + + pub fn register_enum(&mut self, prop_id: u32, name: &str, flags: u32, + obj_id: u32, obj_type: ObjectType, + values: Vec<(u64, String)>, current: u64) { + self.properties.push(DrmProperty { + prop_id, name: name.to_string(), flags, + object_id: obj_id, object_type: obj_type, + prop_type: PropertyType::Enum { values, current }, + }); + } + + pub fn register_blob(&mut self, prop_id: u32, name: &str, flags: u32, + obj_id: u32, obj_type: ObjectType) { + self.properties.push(DrmProperty { + prop_id, name: name.to_string(), flags, + object_id: obj_id, object_type: obj_type, + prop_type: PropertyType::Blob { blob_id: 0 }, + }); + } + + pub fn register_object(&mut self, prop_id: u32, name: &str, flags: u32, + obj_id: u32, obj_type: ObjectType, current: u32) { + self.properties.push(DrmProperty { + prop_id, name: name.to_string(), flags, + object_id: obj_id, object_type: obj_type, + prop_type: PropertyType::Object { current }, + }); + } + + pub fn properties_for_object(&self, obj_id: u32, obj_type: ObjectType) -> Vec<&DrmProperty> { + self.properties.iter() + .filter(|p| p.object_id == obj_id && p.object_type == obj_type) + .collect() + } + + pub fn property_count(&self, obj_id: u32, obj_type: ObjectType) -> usize { + self.properties.iter() + .filter(|p| p.object_id == obj_id && p.object_type == obj_type) + .count() + } + + pub fn find_property(&self, prop_id: u32) -> Option<&DrmProperty> { + self.properties.iter().find(|p| p.prop_id == prop_id) + } +} + +impl fmt::Display for ObjectType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ObjectType::Crtc => write!(f, "CRTC"), + ObjectType::Connector => write!(f, "Connector"), + ObjectType::Plane => write!(f, "Plane"), + } + } +}