Struct AtomicRequest

Source
pub struct AtomicRequest { /* private fields */ }
Expand description

An atomic modesetting commit request.

Implementations§

Source§

impl AtomicRequest

Source

pub fn new() -> Self

Examples found in repository?
examples/modesetting-atomic.rs (line 62)
60fn display_demo(card: &mut Card) -> Result<(), Error> {
61    let mut outputs = prepare_outputs(&card)?;
62    let mut req = linux_drm::modeset::AtomicRequest::new();
63
64    for output in &mut outputs {
65        println!("preparing output {output:#?}");
66        let conn = card.connector_state(output.conn_id)?;
67
68        let mode = &output.mode;
69        let mode_name = String::from_utf8_lossy(&mode.name);
70        println!(
71            "{:?} connector uses {mode_name} ({}x{}@{}Hz)",
72            conn.connector_type, mode.hdisplay, mode.vdisplay, mode.vrefresh,
73        );
74
75        let rows = output.db.height() as usize;
76        let pitch = output.db.pitch() as usize;
77        let data = output.db.buffer_mut();
78        for i in 0..rows {
79            if (i % 8) > 3 {
80                let row = &mut data[(i * pitch)..(i * pitch) + pitch];
81                row.fill(0xff);
82            }
83        }
84
85        println!(
86            "configuring CRTC {:?} for framebuffer {:?} and mode {mode_name} on connector {:?}",
87            output.crtc_id,
88            output.db.framebuffer_id(),
89            conn.id
90        );
91
92        req.set_property(
93            ObjectId::Connector(output.conn_id),
94            output.conn_prop_ids.crtc_id,
95            output.crtc_id,
96        );
97        req.set_property(
98            ObjectId::Crtc(output.crtc_id),
99            output.crtc_prop_ids.active,
100            true,
101        );
102        req.set_property(
103            ObjectId::Plane(output.plane_id),
104            output.plane_prop_ids.fb_id,
105            output.db.framebuffer_id(),
106        );
107        req.set_property(
108            ObjectId::Plane(output.plane_id),
109            output.plane_prop_ids.crtc_id,
110            output.crtc_id,
111        );
112        req.set_property(
113            ObjectId::Plane(output.plane_id),
114            output.plane_prop_ids.crtc_x,
115            0,
116        );
117        req.set_property(
118            ObjectId::Plane(output.plane_id),
119            output.plane_prop_ids.crtc_y,
120            0,
121        );
122        req.set_property(
123            ObjectId::Plane(output.plane_id),
124            output.plane_prop_ids.crtc_w,
125            output.db.width(),
126        );
127        req.set_property(
128            ObjectId::Plane(output.plane_id),
129            output.plane_prop_ids.crtc_h,
130            output.db.height(),
131        );
132        req.set_property(
133            ObjectId::Plane(output.plane_id),
134            output.plane_prop_ids.src_x,
135            0,
136        );
137        req.set_property(
138            ObjectId::Plane(output.plane_id),
139            output.plane_prop_ids.src_y,
140            0,
141        );
142        req.set_property(
143            ObjectId::Plane(output.plane_id),
144            output.plane_prop_ids.src_w,
145            (output.db.width() as u64) << 16,
146        );
147        req.set_property(
148            ObjectId::Plane(output.plane_id),
149            output.plane_prop_ids.src_h,
150            (output.db.height() as u64) << 16,
151        );
152    }
153
154    println!("atomic commit {req:#?}");
155    card.atomic_commit(
156        &req,
157        AtomicCommitFlags::ALLOW_MODESET | AtomicCommitFlags::PAGE_FLIP_EVENT,
158        0,
159    )?;
160
161    let mut evt_buf = vec![0_u8; 1024];
162    loop {
163        println!("waiting for events (send SIGINT to exit)");
164        for evt in card.read_events(&mut evt_buf)? {
165            println!("event {evt:?}");
166            match evt {
167                DrmEvent::Generic(GenericDrmEvent::FlipComplete(_)) => {
168                    // In a real program this would be a time place to draw the next frame
169                    // for the reported crtc.
170                }
171                _ => {
172                    // Ignore any unrecognized event types.
173                }
174            }
175        }
176    }
177}
Source

pub fn reset(&mut self)

Clear any previously-set properties, returning the object to empty.

This function does, however, retain any allocated capacity for property-set requests for existing objects, so callers can avoid making lots of dynamic memory allocations on every change by retaining and reusing a single request object. This optimization will only be productive if the object is reused to set a similar set of properties on a similar set of objects.

Source

pub fn set_property( &mut self, obj_id: impl Into<ObjectId>, prop_id: PropertyId, value: impl IntoRawPropertyValue, )

Examples found in repository?
examples/modesetting-atomic.rs (lines 92-96)
60fn display_demo(card: &mut Card) -> Result<(), Error> {
61    let mut outputs = prepare_outputs(&card)?;
62    let mut req = linux_drm::modeset::AtomicRequest::new();
63
64    for output in &mut outputs {
65        println!("preparing output {output:#?}");
66        let conn = card.connector_state(output.conn_id)?;
67
68        let mode = &output.mode;
69        let mode_name = String::from_utf8_lossy(&mode.name);
70        println!(
71            "{:?} connector uses {mode_name} ({}x{}@{}Hz)",
72            conn.connector_type, mode.hdisplay, mode.vdisplay, mode.vrefresh,
73        );
74
75        let rows = output.db.height() as usize;
76        let pitch = output.db.pitch() as usize;
77        let data = output.db.buffer_mut();
78        for i in 0..rows {
79            if (i % 8) > 3 {
80                let row = &mut data[(i * pitch)..(i * pitch) + pitch];
81                row.fill(0xff);
82            }
83        }
84
85        println!(
86            "configuring CRTC {:?} for framebuffer {:?} and mode {mode_name} on connector {:?}",
87            output.crtc_id,
88            output.db.framebuffer_id(),
89            conn.id
90        );
91
92        req.set_property(
93            ObjectId::Connector(output.conn_id),
94            output.conn_prop_ids.crtc_id,
95            output.crtc_id,
96        );
97        req.set_property(
98            ObjectId::Crtc(output.crtc_id),
99            output.crtc_prop_ids.active,
100            true,
101        );
102        req.set_property(
103            ObjectId::Plane(output.plane_id),
104            output.plane_prop_ids.fb_id,
105            output.db.framebuffer_id(),
106        );
107        req.set_property(
108            ObjectId::Plane(output.plane_id),
109            output.plane_prop_ids.crtc_id,
110            output.crtc_id,
111        );
112        req.set_property(
113            ObjectId::Plane(output.plane_id),
114            output.plane_prop_ids.crtc_x,
115            0,
116        );
117        req.set_property(
118            ObjectId::Plane(output.plane_id),
119            output.plane_prop_ids.crtc_y,
120            0,
121        );
122        req.set_property(
123            ObjectId::Plane(output.plane_id),
124            output.plane_prop_ids.crtc_w,
125            output.db.width(),
126        );
127        req.set_property(
128            ObjectId::Plane(output.plane_id),
129            output.plane_prop_ids.crtc_h,
130            output.db.height(),
131        );
132        req.set_property(
133            ObjectId::Plane(output.plane_id),
134            output.plane_prop_ids.src_x,
135            0,
136        );
137        req.set_property(
138            ObjectId::Plane(output.plane_id),
139            output.plane_prop_ids.src_y,
140            0,
141        );
142        req.set_property(
143            ObjectId::Plane(output.plane_id),
144            output.plane_prop_ids.src_w,
145            (output.db.width() as u64) << 16,
146        );
147        req.set_property(
148            ObjectId::Plane(output.plane_id),
149            output.plane_prop_ids.src_h,
150            (output.db.height() as u64) << 16,
151        );
152    }
153
154    println!("atomic commit {req:#?}");
155    card.atomic_commit(
156        &req,
157        AtomicCommitFlags::ALLOW_MODESET | AtomicCommitFlags::PAGE_FLIP_EVENT,
158        0,
159    )?;
160
161    let mut evt_buf = vec![0_u8; 1024];
162    loop {
163        println!("waiting for events (send SIGINT to exit)");
164        for evt in card.read_events(&mut evt_buf)? {
165            println!("event {evt:?}");
166            match evt {
167                DrmEvent::Generic(GenericDrmEvent::FlipComplete(_)) => {
168                    // In a real program this would be a time place to draw the next frame
169                    // for the reported crtc.
170                }
171                _ => {
172                    // Ignore any unrecognized event types.
173                }
174            }
175        }
176    }
177}

Trait Implementations§

Source§

impl Debug for AtomicRequest

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.