Struct ObjectPropMeta

Source
pub struct ObjectPropMeta<'card> { /* private fields */ }

Implementations§

Source§

impl<'card> ObjectPropMeta<'card>

Source

pub fn property_id(&self) -> PropertyId

Examples found in repository?
examples/modesetting-atomic.rs (line 295)
293    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
294        match from.name() {
295            "CRTC_ID" => self.crtc_id = from.property_id(),
296            _ => {}
297        }
298    }
299}
300
301#[derive(Debug)]
302struct CrtcPropIds {
303    active: PropertyId,
304}
305
306impl CrtcPropIds {
307    pub fn new(crtc_id: CrtcId, card: &linux_drm::Card) -> Result<Self, Error> {
308        let mut ret: Self = unsafe { core::mem::zeroed() };
309        card.each_object_property_meta(linux_drm::modeset::ObjectId::Crtc(crtc_id), |meta, _| {
310            ret.populate_from(meta)
311        })?;
312        Ok(ret)
313    }
314
315    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
316        match from.name() {
317            "ACTIVE" => self.active = from.property_id(),
318            _ => {}
319        }
320    }
321}
322
323#[derive(Debug)]
324struct PlanePropIds {
325    typ: PropertyId,
326    fb_id: PropertyId,
327    crtc_id: PropertyId,
328    crtc_x: PropertyId,
329    crtc_y: PropertyId,
330    crtc_w: PropertyId,
331    crtc_h: PropertyId,
332    src_x: PropertyId,
333    src_y: PropertyId,
334    src_w: PropertyId,
335    src_h: PropertyId,
336}
337
338impl PlanePropIds {
339    pub fn new(plane_id: PlaneId, card: &linux_drm::Card) -> Result<Self, Error> {
340        let mut ret: Self = unsafe { core::mem::zeroed() };
341        card.each_object_property_meta(plane_id, |meta, _| ret.populate_from(meta))?;
342        Ok(ret)
343    }
344
345    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
346        let field: &mut PropertyId = match from.name() {
347            "type" => &mut self.typ,
348            "FB_ID" => &mut self.fb_id,
349            "CRTC_ID" => &mut self.crtc_id,
350            "CRTC_X" => &mut self.crtc_x,
351            "CRTC_Y" => &mut self.crtc_y,
352            "CRTC_W" => &mut self.crtc_w,
353            "CRTC_H" => &mut self.crtc_h,
354            "SRC_X" => &mut self.src_x,
355            "SRC_Y" => &mut self.src_y,
356            "SRC_W" => &mut self.src_w,
357            "SRC_H" => &mut self.src_h,
358            _ => return,
359        };
360        *field = from.property_id()
361    }
Source

pub fn name(&self) -> &str

Examples found in repository?
examples/modesetting-atomic.rs (line 294)
293    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
294        match from.name() {
295            "CRTC_ID" => self.crtc_id = from.property_id(),
296            _ => {}
297        }
298    }
299}
300
301#[derive(Debug)]
302struct CrtcPropIds {
303    active: PropertyId,
304}
305
306impl CrtcPropIds {
307    pub fn new(crtc_id: CrtcId, card: &linux_drm::Card) -> Result<Self, Error> {
308        let mut ret: Self = unsafe { core::mem::zeroed() };
309        card.each_object_property_meta(linux_drm::modeset::ObjectId::Crtc(crtc_id), |meta, _| {
310            ret.populate_from(meta)
311        })?;
312        Ok(ret)
313    }
314
315    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
316        match from.name() {
317            "ACTIVE" => self.active = from.property_id(),
318            _ => {}
319        }
320    }
321}
322
323#[derive(Debug)]
324struct PlanePropIds {
325    typ: PropertyId,
326    fb_id: PropertyId,
327    crtc_id: PropertyId,
328    crtc_x: PropertyId,
329    crtc_y: PropertyId,
330    crtc_w: PropertyId,
331    crtc_h: PropertyId,
332    src_x: PropertyId,
333    src_y: PropertyId,
334    src_w: PropertyId,
335    src_h: PropertyId,
336}
337
338impl PlanePropIds {
339    pub fn new(plane_id: PlaneId, card: &linux_drm::Card) -> Result<Self, Error> {
340        let mut ret: Self = unsafe { core::mem::zeroed() };
341        card.each_object_property_meta(plane_id, |meta, _| ret.populate_from(meta))?;
342        Ok(ret)
343    }
344
345    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
346        let field: &mut PropertyId = match from.name() {
347            "type" => &mut self.typ,
348            "FB_ID" => &mut self.fb_id,
349            "CRTC_ID" => &mut self.crtc_id,
350            "CRTC_X" => &mut self.crtc_x,
351            "CRTC_Y" => &mut self.crtc_y,
352            "CRTC_W" => &mut self.crtc_w,
353            "CRTC_H" => &mut self.crtc_h,
354            "SRC_X" => &mut self.src_x,
355            "SRC_Y" => &mut self.src_y,
356            "SRC_W" => &mut self.src_w,
357            "SRC_H" => &mut self.src_h,
358            _ => return,
359        };
360        *field = from.property_id()
361    }
More examples
Hide additional examples
examples/properties.rs (line 177)
164fn property_meta<'a, 'card>(
165    prop_id: PropertyId,
166    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
167    card: &Card,
168) -> Result<&'a PropertyMeta, Error> {
169    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
170        card.property_meta(prop_id)
171            .map(|meta| {
172                let mut enum_names = BTreeMap::new();
173                for member in meta.enum_members().unwrap() {
174                    enum_names.insert(member.value(), member.name().to_string());
175                }
176                PropertyMeta {
177                    name: meta.name().to_string(),
178                    typ: meta.property_type(),
179                    immutable: meta.is_immutable(),
180                    values: meta.values().unwrap(),
181                    enum_names,
182                }
183            })
184            .unwrap_or(PropertyMeta {
185                name: String::from("<unknown>"),
186                typ: PropertyType::Unknown,
187                immutable: true,
188                values: Vec::new(),
189                enum_names: BTreeMap::new(),
190            })
191    }))
192}
Source

pub fn property_type(&self) -> PropertyType

Examples found in repository?
examples/properties.rs (line 178)
164fn property_meta<'a, 'card>(
165    prop_id: PropertyId,
166    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
167    card: &Card,
168) -> Result<&'a PropertyMeta, Error> {
169    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
170        card.property_meta(prop_id)
171            .map(|meta| {
172                let mut enum_names = BTreeMap::new();
173                for member in meta.enum_members().unwrap() {
174                    enum_names.insert(member.value(), member.name().to_string());
175                }
176                PropertyMeta {
177                    name: meta.name().to_string(),
178                    typ: meta.property_type(),
179                    immutable: meta.is_immutable(),
180                    values: meta.values().unwrap(),
181                    enum_names,
182                }
183            })
184            .unwrap_or(PropertyMeta {
185                name: String::from("<unknown>"),
186                typ: PropertyType::Unknown,
187                immutable: true,
188                values: Vec::new(),
189                enum_names: BTreeMap::new(),
190            })
191    }))
192}
Source

pub fn is_immutable(&self) -> bool

Examples found in repository?
examples/properties.rs (line 179)
164fn property_meta<'a, 'card>(
165    prop_id: PropertyId,
166    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
167    card: &Card,
168) -> Result<&'a PropertyMeta, Error> {
169    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
170        card.property_meta(prop_id)
171            .map(|meta| {
172                let mut enum_names = BTreeMap::new();
173                for member in meta.enum_members().unwrap() {
174                    enum_names.insert(member.value(), member.name().to_string());
175                }
176                PropertyMeta {
177                    name: meta.name().to_string(),
178                    typ: meta.property_type(),
179                    immutable: meta.is_immutable(),
180                    values: meta.values().unwrap(),
181                    enum_names,
182                }
183            })
184            .unwrap_or(PropertyMeta {
185                name: String::from("<unknown>"),
186                typ: PropertyType::Unknown,
187                immutable: true,
188                values: Vec::new(),
189                enum_names: BTreeMap::new(),
190            })
191    }))
192}
Source

pub fn is_mutable(&self) -> bool

Source

pub fn range(&self) -> Result<(u64, u64), Error>

Get the minimum and maximum value for a range-typed property.

This is essentially the same as Self::values, except that because it’s guaranteed that a range property always has exactly two values this function can avoid making a dynamic memory allocation and can instead retrieve the values directly into a stack object and then return those values.

Source

pub fn values(&self) -> Result<Vec<u64>, Error>

Get a vector of describing the values that are acceptable for this property.

The meaning of the result depends on the property type:

  • For a range or signed range, the result always has length 2 and describes the minimum and maximum values respectively.

    You can avoid a dynamic memory allocation in this case by using Self::range instead.

  • For an enum or bitmask, the result describes the values of the valid enumeration members.

    For these it’s typically better to use Self::enum_members since that can also return the name associated with each value.

Examples found in repository?
examples/properties.rs (line 180)
164fn property_meta<'a, 'card>(
165    prop_id: PropertyId,
166    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
167    card: &Card,
168) -> Result<&'a PropertyMeta, Error> {
169    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
170        card.property_meta(prop_id)
171            .map(|meta| {
172                let mut enum_names = BTreeMap::new();
173                for member in meta.enum_members().unwrap() {
174                    enum_names.insert(member.value(), member.name().to_string());
175                }
176                PropertyMeta {
177                    name: meta.name().to_string(),
178                    typ: meta.property_type(),
179                    immutable: meta.is_immutable(),
180                    values: meta.values().unwrap(),
181                    enum_names,
182                }
183            })
184            .unwrap_or(PropertyMeta {
185                name: String::from("<unknown>"),
186                typ: PropertyType::Unknown,
187                immutable: true,
188                values: Vec::new(),
189                enum_names: BTreeMap::new(),
190            })
191    }))
192}
Source

pub fn enum_members(&self) -> Result<Vec<ObjectPropEnumMember>, Error>

Get a vector describing the valid values for an enum, or the bitfield values for a bitmask.

Examples found in repository?
examples/properties.rs (line 173)
164fn property_meta<'a, 'card>(
165    prop_id: PropertyId,
166    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
167    card: &Card,
168) -> Result<&'a PropertyMeta, Error> {
169    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
170        card.property_meta(prop_id)
171            .map(|meta| {
172                let mut enum_names = BTreeMap::new();
173                for member in meta.enum_members().unwrap() {
174                    enum_names.insert(member.value(), member.name().to_string());
175                }
176                PropertyMeta {
177                    name: meta.name().to_string(),
178                    typ: meta.property_type(),
179                    immutable: meta.is_immutable(),
180                    values: meta.values().unwrap(),
181                    enum_names,
182                }
183            })
184            .unwrap_or(PropertyMeta {
185                name: String::from("<unknown>"),
186                typ: PropertyType::Unknown,
187                immutable: true,
188                values: Vec::new(),
189                enum_names: BTreeMap::new(),
190            })
191    }))
192}

Trait Implementations§

Source§

impl<'card> Debug for ObjectPropMeta<'card>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'card> Freeze for ObjectPropMeta<'card>

§

impl<'card> RefUnwindSafe for ObjectPropMeta<'card>

§

impl<'card> Send for ObjectPropMeta<'card>

§

impl<'card> Sync for ObjectPropMeta<'card>

§

impl<'card> Unpin for ObjectPropMeta<'card>

§

impl<'card> UnwindSafe for ObjectPropMeta<'card>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.