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 275)
273    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
274        match from.name() {
275            "CRTC_ID" => self.crtc_id = from.property_id(),
276            _ => {}
277        }
278    }
279}
280
281#[derive(Debug)]
282struct CrtcPropIds {
283    active: PropertyId,
284}
285
286impl CrtcPropIds {
287    pub fn new(crtc_id: CrtcId, card: &linux_drm::Card) -> Result<Self, Error> {
288        let mut ret: Self = unsafe { core::mem::zeroed() };
289        card.each_object_property_meta(linux_drm::modeset::ObjectId::Crtc(crtc_id), |meta, _| {
290            ret.populate_from(meta)
291        })?;
292        Ok(ret)
293    }
294
295    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
296        match from.name() {
297            "ACTIVE" => self.active = from.property_id(),
298            _ => {}
299        }
300    }
301}
302
303#[derive(Debug)]
304struct PlanePropIds {
305    typ: PropertyId,
306    fb_id: PropertyId,
307    crtc_id: PropertyId,
308    crtc_x: PropertyId,
309    crtc_y: PropertyId,
310    crtc_w: PropertyId,
311    crtc_h: PropertyId,
312    src_x: PropertyId,
313    src_y: PropertyId,
314    src_w: PropertyId,
315    src_h: PropertyId,
316}
317
318impl PlanePropIds {
319    pub fn new(plane_id: PlaneId, card: &linux_drm::Card) -> Result<Self, Error> {
320        let mut ret: Self = unsafe { core::mem::zeroed() };
321        card.each_object_property_meta(plane_id, |meta, _| ret.populate_from(meta))?;
322        Ok(ret)
323    }
324
325    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
326        let field: &mut PropertyId = match from.name() {
327            "type" => &mut self.typ,
328            "FB_ID" => &mut self.fb_id,
329            "CRTC_ID" => &mut self.crtc_id,
330            "CRTC_X" => &mut self.crtc_x,
331            "CRTC_Y" => &mut self.crtc_y,
332            "CRTC_W" => &mut self.crtc_w,
333            "CRTC_H" => &mut self.crtc_h,
334            "SRC_X" => &mut self.src_x,
335            "SRC_Y" => &mut self.src_y,
336            "SRC_W" => &mut self.src_w,
337            "SRC_H" => &mut self.src_h,
338            _ => return,
339        };
340        *field = from.property_id()
341    }
Source

pub fn name(&self) -> &str

Examples found in repository?
examples/modesetting-atomic.rs (line 274)
273    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
274        match from.name() {
275            "CRTC_ID" => self.crtc_id = from.property_id(),
276            _ => {}
277        }
278    }
279}
280
281#[derive(Debug)]
282struct CrtcPropIds {
283    active: PropertyId,
284}
285
286impl CrtcPropIds {
287    pub fn new(crtc_id: CrtcId, card: &linux_drm::Card) -> Result<Self, Error> {
288        let mut ret: Self = unsafe { core::mem::zeroed() };
289        card.each_object_property_meta(linux_drm::modeset::ObjectId::Crtc(crtc_id), |meta, _| {
290            ret.populate_from(meta)
291        })?;
292        Ok(ret)
293    }
294
295    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
296        match from.name() {
297            "ACTIVE" => self.active = from.property_id(),
298            _ => {}
299        }
300    }
301}
302
303#[derive(Debug)]
304struct PlanePropIds {
305    typ: PropertyId,
306    fb_id: PropertyId,
307    crtc_id: PropertyId,
308    crtc_x: PropertyId,
309    crtc_y: PropertyId,
310    crtc_w: PropertyId,
311    crtc_h: PropertyId,
312    src_x: PropertyId,
313    src_y: PropertyId,
314    src_w: PropertyId,
315    src_h: PropertyId,
316}
317
318impl PlanePropIds {
319    pub fn new(plane_id: PlaneId, card: &linux_drm::Card) -> Result<Self, Error> {
320        let mut ret: Self = unsafe { core::mem::zeroed() };
321        card.each_object_property_meta(plane_id, |meta, _| ret.populate_from(meta))?;
322        Ok(ret)
323    }
324
325    pub fn populate_from<'card>(&mut self, from: linux_drm::modeset::ObjectPropMeta<'card>) {
326        let field: &mut PropertyId = match from.name() {
327            "type" => &mut self.typ,
328            "FB_ID" => &mut self.fb_id,
329            "CRTC_ID" => &mut self.crtc_id,
330            "CRTC_X" => &mut self.crtc_x,
331            "CRTC_Y" => &mut self.crtc_y,
332            "CRTC_W" => &mut self.crtc_w,
333            "CRTC_H" => &mut self.crtc_h,
334            "SRC_X" => &mut self.src_x,
335            "SRC_Y" => &mut self.src_y,
336            "SRC_W" => &mut self.src_w,
337            "SRC_H" => &mut self.src_h,
338            _ => return,
339        };
340        *field = from.property_id()
341    }
More examples
Hide additional examples
examples/properties.rs (line 157)
144fn property_meta<'a, 'card>(
145    prop_id: PropertyId,
146    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
147    card: &Card,
148) -> Result<&'a PropertyMeta, Error> {
149    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
150        card.property_meta(prop_id)
151            .map(|meta| {
152                let mut enum_names = BTreeMap::new();
153                for member in meta.enum_members().unwrap() {
154                    enum_names.insert(member.value(), member.name().to_string());
155                }
156                PropertyMeta {
157                    name: meta.name().to_string(),
158                    typ: meta.property_type(),
159                    immutable: meta.is_immutable(),
160                    values: meta.values().unwrap(),
161                    enum_names,
162                }
163            })
164            .unwrap_or(PropertyMeta {
165                name: String::from("<unknown>"),
166                typ: PropertyType::Unknown,
167                immutable: true,
168                values: Vec::new(),
169                enum_names: BTreeMap::new(),
170            })
171    }))
172}
Source

pub fn property_type(&self) -> PropertyType

Examples found in repository?
examples/properties.rs (line 158)
144fn property_meta<'a, 'card>(
145    prop_id: PropertyId,
146    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
147    card: &Card,
148) -> Result<&'a PropertyMeta, Error> {
149    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
150        card.property_meta(prop_id)
151            .map(|meta| {
152                let mut enum_names = BTreeMap::new();
153                for member in meta.enum_members().unwrap() {
154                    enum_names.insert(member.value(), member.name().to_string());
155                }
156                PropertyMeta {
157                    name: meta.name().to_string(),
158                    typ: meta.property_type(),
159                    immutable: meta.is_immutable(),
160                    values: meta.values().unwrap(),
161                    enum_names,
162                }
163            })
164            .unwrap_or(PropertyMeta {
165                name: String::from("<unknown>"),
166                typ: PropertyType::Unknown,
167                immutable: true,
168                values: Vec::new(),
169                enum_names: BTreeMap::new(),
170            })
171    }))
172}
Source

pub fn is_immutable(&self) -> bool

Examples found in repository?
examples/properties.rs (line 159)
144fn property_meta<'a, 'card>(
145    prop_id: PropertyId,
146    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
147    card: &Card,
148) -> Result<&'a PropertyMeta, Error> {
149    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
150        card.property_meta(prop_id)
151            .map(|meta| {
152                let mut enum_names = BTreeMap::new();
153                for member in meta.enum_members().unwrap() {
154                    enum_names.insert(member.value(), member.name().to_string());
155                }
156                PropertyMeta {
157                    name: meta.name().to_string(),
158                    typ: meta.property_type(),
159                    immutable: meta.is_immutable(),
160                    values: meta.values().unwrap(),
161                    enum_names,
162                }
163            })
164            .unwrap_or(PropertyMeta {
165                name: String::from("<unknown>"),
166                typ: PropertyType::Unknown,
167                immutable: true,
168                values: Vec::new(),
169                enum_names: BTreeMap::new(),
170            })
171    }))
172}
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 160)
144fn property_meta<'a, 'card>(
145    prop_id: PropertyId,
146    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
147    card: &Card,
148) -> Result<&'a PropertyMeta, Error> {
149    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
150        card.property_meta(prop_id)
151            .map(|meta| {
152                let mut enum_names = BTreeMap::new();
153                for member in meta.enum_members().unwrap() {
154                    enum_names.insert(member.value(), member.name().to_string());
155                }
156                PropertyMeta {
157                    name: meta.name().to_string(),
158                    typ: meta.property_type(),
159                    immutable: meta.is_immutable(),
160                    values: meta.values().unwrap(),
161                    enum_names,
162                }
163            })
164            .unwrap_or(PropertyMeta {
165                name: String::from("<unknown>"),
166                typ: PropertyType::Unknown,
167                immutable: true,
168                values: Vec::new(),
169                enum_names: BTreeMap::new(),
170            })
171    }))
172}
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 153)
144fn property_meta<'a, 'card>(
145    prop_id: PropertyId,
146    prop_meta: &'a mut HashMap<u32, PropertyMeta>,
147    card: &Card,
148) -> Result<&'a PropertyMeta, Error> {
149    Ok(prop_meta.entry(prop_id.0).or_insert_with(|| {
150        card.property_meta(prop_id)
151            .map(|meta| {
152                let mut enum_names = BTreeMap::new();
153                for member in meta.enum_members().unwrap() {
154                    enum_names.insert(member.value(), member.name().to_string());
155                }
156                PropertyMeta {
157                    name: meta.name().to_string(),
158                    typ: meta.property_type(),
159                    immutable: meta.is_immutable(),
160                    values: meta.values().unwrap(),
161                    enum_names,
162                }
163            })
164            .unwrap_or(PropertyMeta {
165                name: String::from("<unknown>"),
166                typ: PropertyType::Unknown,
167                immutable: true,
168                values: Vec::new(),
169                enum_names: BTreeMap::new(),
170            })
171    }))
172}

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, 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.