Skip to content

Commit 6cb3a27

Browse files
committed
Move the modifier from add_planar_framebuffer to PlanarBuffer
The modifier is a property of the buffer, so let’s put it where it belongs. This adds a validation that the flags correspond to the modifier. Another option would be to remove the flag and instead rely on whether the modifier is set or not to set it for the kernel, but I’m not sure this actually improves anything.
1 parent 3607a37 commit 6cb3a27

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/buffer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub trait PlanarBuffer {
109109
fn size(&self) -> (u32, u32);
110110
/// The format of the buffer.
111111
fn format(&self) -> DrmFourcc;
112+
/// The modifier of the buffer.
113+
fn modifier(&self) -> Option<DrmModifier>;
112114
/// The pitches of the buffer.
113115
fn pitches(&self) -> [u32; 4];
114116
/// The handles to the buffer.

src/control/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,21 +309,29 @@ pub trait Device: super::Device {
309309
fn add_planar_framebuffer<B>(
310310
&self,
311311
planar_buffer: &B,
312-
modifiers: &[Option<DrmModifier>; 4],
313312
flags: FbCmd2Flags,
314313
) -> Result<framebuffer::Handle, SystemError>
315314
where
316315
B: buffer::PlanarBuffer + ?Sized,
317316
{
317+
let modifier = planar_buffer.modifier();
318+
let has_modifier = flags.contains(FbCmd2Flags::MODIFIERS);
319+
assert!((has_modifier && modifier.is_some()) || (!has_modifier && modifier.is_none()));
320+
let modifier = if let Some(modifier) = modifier {
321+
u64::from(modifier)
322+
} else {
323+
0
324+
};
325+
318326
let (w, h) = planar_buffer.size();
319327
let opt_handles = planar_buffer.handles();
320328

321329
let handles = bytemuck::cast(opt_handles);
322330
let mods = [
323-
modifiers[0].map(Into::<u64>::into).unwrap_or(0),
324-
modifiers[1].map(Into::<u64>::into).unwrap_or(0),
325-
modifiers[2].map(Into::<u64>::into).unwrap_or(0),
326-
modifiers[3].map(Into::<u64>::into).unwrap_or(0),
331+
opt_handles[0].map_or(0, |_| modifier),
332+
opt_handles[1].map_or(0, |_| modifier),
333+
opt_handles[2].map_or(0, |_| modifier),
334+
opt_handles[3].map_or(0, |_| modifier),
327335
];
328336

329337
let info = ffi::mode::add_fb2(

0 commit comments

Comments
 (0)