Struct linux_drm::modeset::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 42)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
fn display_demo(card: &mut Card) -> Result<(), Error> {
    let mut outputs = prepare_outputs(&card)?;
    let mut req = linux_drm::modeset::AtomicRequest::new();

    for output in &mut outputs {
        println!("preparing output {output:#?}");
        let conn = card.connector_state(output.conn_id)?;

        let mode = &output.mode;
        let mode_name = String::from_utf8_lossy(&mode.name);
        println!(
            "{:?} connector uses {mode_name} ({}x{}@{}Hz)",
            conn.connector_type, mode.hdisplay, mode.vdisplay, mode.vrefresh,
        );

        let rows = output.db.height() as usize;
        let pitch = output.db.pitch() as usize;
        let data = output.db.buffer_mut();
        for i in 0..rows {
            if (i % 8) > 3 {
                let row = &mut data[(i * pitch)..(i * pitch) + pitch];
                row.fill(0xff);
            }
        }

        println!(
            "configuring CRTC {} for framebuffer {} and mode {mode_name} on connector {}",
            output.crtc_id,
            output.db.framebuffer_id(),
            conn.id
        );

        req.set_property(
            ObjectId::Connector(output.conn_id),
            output.conn_prop_ids.crtc_id,
            output.crtc_id as u64,
        );
        req.set_property(
            ObjectId::Crtc(output.crtc_id),
            output.crtc_prop_ids.active,
            1_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.fb_id,
            output.db.framebuffer_id() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_id,
            output.crtc_id as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_x,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_y,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_w,
            output.db.width() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_h,
            output.db.height() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_x,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_y,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_w,
            (output.db.width() as u64) << 16,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_h,
            (output.db.height() as u64) << 16,
        );
    }

    println!("atomic commit {req:#?}");
    card.atomic_commit(
        req,
        AtomicCommitFlags::ALLOW_MODESET | AtomicCommitFlags::PAGE_FLIP_EVENT,
        0,
    )?;

    let mut evt_buf = vec![0_u8; 1024];
    loop {
        println!("waiting for events (send SIGINT to exit)");
        for evt in card.read_events(&mut evt_buf)? {
            println!("event {evt:?}");
            match evt {
                DrmEvent::Generic(GenericDrmEvent::FlipComplete(_)) => {
                    // In a real program this would be a time place to draw the next frame
                    // for the reported crtc.
                }
                _ => {
                    // Ignore any unrecognized event types.
                }
            }
        }
    }
}
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: ObjectId, prop_id: u32, value: u64)

Examples found in repository?
examples/modesetting-atomic.rs (lines 72-76)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
fn display_demo(card: &mut Card) -> Result<(), Error> {
    let mut outputs = prepare_outputs(&card)?;
    let mut req = linux_drm::modeset::AtomicRequest::new();

    for output in &mut outputs {
        println!("preparing output {output:#?}");
        let conn = card.connector_state(output.conn_id)?;

        let mode = &output.mode;
        let mode_name = String::from_utf8_lossy(&mode.name);
        println!(
            "{:?} connector uses {mode_name} ({}x{}@{}Hz)",
            conn.connector_type, mode.hdisplay, mode.vdisplay, mode.vrefresh,
        );

        let rows = output.db.height() as usize;
        let pitch = output.db.pitch() as usize;
        let data = output.db.buffer_mut();
        for i in 0..rows {
            if (i % 8) > 3 {
                let row = &mut data[(i * pitch)..(i * pitch) + pitch];
                row.fill(0xff);
            }
        }

        println!(
            "configuring CRTC {} for framebuffer {} and mode {mode_name} on connector {}",
            output.crtc_id,
            output.db.framebuffer_id(),
            conn.id
        );

        req.set_property(
            ObjectId::Connector(output.conn_id),
            output.conn_prop_ids.crtc_id,
            output.crtc_id as u64,
        );
        req.set_property(
            ObjectId::Crtc(output.crtc_id),
            output.crtc_prop_ids.active,
            1_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.fb_id,
            output.db.framebuffer_id() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_id,
            output.crtc_id as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_x,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_y,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_w,
            output.db.width() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.crtc_h,
            output.db.height() as u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_x,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_y,
            0_u64,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_w,
            (output.db.width() as u64) << 16,
        );
        req.set_property(
            ObjectId::Plane(output.plane_id),
            output.plane_prop_ids.src_h,
            (output.db.height() as u64) << 16,
        );
    }

    println!("atomic commit {req:#?}");
    card.atomic_commit(
        req,
        AtomicCommitFlags::ALLOW_MODESET | AtomicCommitFlags::PAGE_FLIP_EVENT,
        0,
    )?;

    let mut evt_buf = vec![0_u8; 1024];
    loop {
        println!("waiting for events (send SIGINT to exit)");
        for evt in card.read_events(&mut evt_buf)? {
            println!("event {evt:?}");
            match evt {
                DrmEvent::Generic(GenericDrmEvent::FlipComplete(_)) => {
                    // In a real program this would be a time place to draw the next frame
                    // for the reported crtc.
                }
                _ => {
                    // Ignore any unrecognized event types.
                }
            }
        }
    }
}

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.