Skip to content

Commit 0f98975

Browse files
committed
metal: allow filtering default properties
1 parent 23a2608 commit 0f98975

2 files changed

Lines changed: 53 additions & 39 deletions

File tree

src/backends/metal/transaction.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,32 +827,41 @@ impl MetalDeviceTransactionWithDrmState {
827827
test: bool,
828828
reset_default_properties: bool,
829829
) -> Result<MetalDeviceTransactionWithChange, BackendConnectorTransactionError> {
830-
fn for_each_changed_default_property(
830+
fn for_each_changed_default_property<T>(
831831
props: &BHashMap<DrmProperty, u64>,
832-
defaults: &[DefaultProperty],
833-
mut f: impl FnMut(u64, &DefaultProperty),
832+
defaults: &[DefaultProperty<T>],
833+
filter: impl Fn(&T) -> bool,
834+
mut f: impl FnMut(u64, &DefaultProperty<T>),
834835
) {
835836
for dp in defaults {
836-
let old = props.get(&dp.prop).copied().unwrap_or_default();
837-
let new = dp.value;
838-
if old != new {
839-
f(old, dp);
837+
if filter(&dp.t) {
838+
let old = props.get(&dp.prop).copied().unwrap_or_default();
839+
let new = dp.value;
840+
if old != new {
841+
f(old, dp);
842+
}
840843
}
841844
}
842845
}
843846
macro_rules! need_reset_default_properties {
844-
($props:expr, $defaults:expr $(,)?) => {{
847+
($props:expr, $defaults:expr $(,)?) => {{ need_reset_default_properties!($props, $defaults, |_: &()| true) }};
848+
($props:expr, $defaults:expr, $filter:expr $(,)?) => {{
845849
let mut changed = false;
846850
if reset_default_properties {
847-
for_each_changed_default_property($props, $defaults, |_, _| changed = true);
851+
for_each_changed_default_property($props, $defaults, $filter, |_, _| {
852+
changed = true
853+
});
848854
}
849855
changed
850856
}};
851857
}
852858
macro_rules! reset_default_properties {
853859
($c:expr, $props:expr, $defaults:expr $(,)?) => {{
860+
reset_default_properties!($c, $props, $defaults, |_: &()| true);
861+
}};
862+
($c:expr, $props:expr, $defaults:expr, $filter:expr $(,)?) => {{
854863
if reset_default_properties {
855-
for_each_changed_default_property($props, $defaults, |old, dp| {
864+
for_each_changed_default_property($props, $defaults, $filter, |old, dp| {
856865
log::log!(LEVEL, " changing {} from {old} to {}", dp.name, dp.value);
857866
$c.change(dp.prop, dp.value);
858867
});

src/backends/metal/video.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,11 @@ pub struct PersistentDisplayData {
367367
}
368368

369369
#[derive(Debug)]
370-
pub struct DefaultProperty {
370+
pub struct DefaultProperty<T = ()> {
371371
pub name: &'static str,
372372
pub prop: DrmProperty,
373373
pub value: u64,
374+
pub t: T,
374375
}
375376

376377
#[derive(Debug)]
@@ -1022,12 +1023,15 @@ enum DefaultValue {
10221023
RangeMax,
10231024
}
10241025

1025-
fn create_default_properties(
1026+
fn create_default_properties<T>(
10261027
props: &CollectedProperties,
1027-
defaults: &[(&'static str, DefaultValue)],
1028-
) -> Vec<DefaultProperty> {
1028+
defaults: &[(&'static str, DefaultValue, T)],
1029+
) -> Vec<DefaultProperty<T>>
1030+
where
1031+
T: Copy,
1032+
{
10291033
let mut res = vec![];
1030-
'outer: for &(name, def) in defaults {
1034+
'outer: for &(name, def, t) in defaults {
10311035
if let Some((definition, _)) = props.props.get(name.as_bytes().as_bstr()) {
10321036
let value = match def {
10331037
DefaultValue::Fixed(v) => v,
@@ -1067,6 +1071,7 @@ fn create_default_properties(
10671071
name,
10681072
prop: definition.id,
10691073
value,
1074+
t,
10701075
});
10711076
}
10721077
}
@@ -1368,14 +1373,14 @@ fn create_connector_display_data(
13681373
let default_properties = create_default_properties(
13691374
&props,
13701375
&[
1371-
("Broadcast RGB", DefaultValue::Enum("Automatic")),
1372-
("HDR_SOURCE_METADATA", DefaultValue::Fixed(0)),
1373-
("Output format", DefaultValue::Enum("Default")),
1374-
("WRITEBACK_FB_ID", DefaultValue::Fixed(0)),
1375-
("WRITEBACK_OUT_FENCE_PTR", DefaultValue::Fixed(0)),
1376-
("content type", DefaultValue::Enum("No Data")),
1377-
("dither", DefaultValue::Enum("off")),
1378-
("max bpc", DefaultValue::RangeMax),
1376+
("Broadcast RGB", DefaultValue::Enum("Automatic"), ()),
1377+
("HDR_SOURCE_METADATA", DefaultValue::Fixed(0), ()),
1378+
("Output format", DefaultValue::Enum("Default"), ()),
1379+
("WRITEBACK_FB_ID", DefaultValue::Fixed(0), ()),
1380+
("WRITEBACK_OUT_FENCE_PTR", DefaultValue::Fixed(0), ()),
1381+
("content type", DefaultValue::Enum("No Data"), ()),
1382+
("dither", DefaultValue::Enum("off"), ()),
1383+
("max bpc", DefaultValue::RangeMax, ()),
13791384
],
13801385
);
13811386
let hdr_metadata_prop = props
@@ -1484,10 +1489,10 @@ fn create_crtc(
14841489
let default_properties = create_default_properties(
14851490
&props,
14861491
&[
1487-
("AMD_CRTC_REGAMMA_TF", DefaultValue::Enum("Default")),
1488-
("CTM", DefaultValue::Fixed(0)),
1489-
("DEGAMMA_LUT", DefaultValue::Fixed(0)),
1490-
("OUT_FENCE_PTR", DefaultValue::Fixed(0)),
1492+
("AMD_CRTC_REGAMMA_TF", DefaultValue::Enum("Default"), ()),
1493+
("CTM", DefaultValue::Fixed(0), ()),
1494+
("DEGAMMA_LUT", DefaultValue::Fixed(0), ()),
1495+
("OUT_FENCE_PTR", DefaultValue::Fixed(0), ()),
14911496
],
14921497
);
14931498
let mode_id = props.get("MODE_ID")?.map(|v| DrmBlob(v as u32));
@@ -1604,18 +1609,18 @@ fn create_plane(plane: DrmPlane, master: &Rc<DrmMaster>) -> Result<MetalPlane, D
16041609
let default_properties = create_default_properties(
16051610
&props,
16061611
&[
1607-
("AMD_PLANE_BLEND_LUT", DefaultValue::Fixed(0)),
1608-
("AMD_PLANE_BLEND_TF", DefaultValue::Enum("Default")),
1609-
("AMD_PLANE_CTM", DefaultValue::Fixed(0)),
1610-
("AMD_PLANE_DEGAMMA_LUT", DefaultValue::Fixed(0)),
1611-
("AMD_PLANE_HDR_MULT", DefaultValue::Fixed(0)),
1612-
("AMD_PLANE_LUT3D", DefaultValue::Fixed(0)),
1613-
("AMD_PLANE_SHAPER_LUT", DefaultValue::Fixed(0)),
1614-
("AMD_PLANE_SHAPER_TF", DefaultValue::Enum("Default")),
1615-
("alpha", DefaultValue::RangeMax),
1616-
("pixel blend mode", DefaultValue::Enum("Pre-multiplied")),
1617-
("rotation", DefaultValue::Bitmask(&["rotate-0"])),
1618-
("COLOR_PIPELINE", DefaultValue::Enum("Bypass")),
1612+
("AMD_PLANE_BLEND_LUT", DefaultValue::Fixed(0), ()),
1613+
("AMD_PLANE_BLEND_TF", DefaultValue::Enum("Default"), ()),
1614+
("AMD_PLANE_CTM", DefaultValue::Fixed(0), ()),
1615+
("AMD_PLANE_DEGAMMA_LUT", DefaultValue::Fixed(0), ()),
1616+
("AMD_PLANE_HDR_MULT", DefaultValue::Fixed(0), ()),
1617+
("AMD_PLANE_LUT3D", DefaultValue::Fixed(0), ()),
1618+
("AMD_PLANE_SHAPER_LUT", DefaultValue::Fixed(0), ()),
1619+
("AMD_PLANE_SHAPER_TF", DefaultValue::Enum("Default"), ()),
1620+
("alpha", DefaultValue::RangeMax, ()),
1621+
("pixel blend mode", DefaultValue::Enum("Pre-multiplied"), ()),
1622+
("rotation", DefaultValue::Bitmask(&["rotate-0"]), ()),
1623+
("COLOR_PIPELINE", DefaultValue::Enum("Bypass"), ()),
16191624
],
16201625
);
16211626
let in_fence_fd = props.get("IN_FENCE_FD")?;

0 commit comments

Comments
 (0)