1
0
Fork 0

core/debug-control: Allow changing the reference luminance of outputs

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3953>
This commit is contained in:
Sebastian Wick 2024-07-19 15:30:56 +02:00 committed by Marge Bot
parent 9b05e39816
commit 6fa61a088f
5 changed files with 72 additions and 5 deletions

View file

@ -8,6 +8,7 @@
<property name="ColorManagementProtocol" type="b" access="readwrite" />
<property name="EnableHDR" type="b" access="readwrite" />
<property name="ForceLinearBlending" type="b" access="readwrite" />
<property name="LuminancePercentage" type="u" access="readwrite" />
</interface>

View file

@ -671,18 +671,32 @@ update_color_state (MetaColorDevice *color_device)
MetaMonitor *monitor = color_device->monitor;
MetaBackend *backend =
meta_color_manager_get_backend (color_device->color_manager);
MetaContext *context = meta_backend_get_context (backend);
MetaDebugControl *debug_control = meta_context_get_debug_control (context);
ClutterContext *clutter_context = meta_backend_get_clutter_context (backend);
g_autoptr (ClutterColorState) color_state = NULL;
ClutterColorspace colorspace;
ClutterTransferFunction transfer_function;
float min_lum, max_lum, ref_lum;
float reference_luminance_factor;
UpdateResult result = 0;
colorspace = get_color_space_from_monitor (monitor);
transfer_function = get_transfer_function_from_monitor (monitor);
color_state = clutter_color_state_new (clutter_context,
colorspace,
transfer_function);
clutter_transfer_function_get_default_luminances (transfer_function,
&min_lum,
&max_lum,
&ref_lum);
reference_luminance_factor =
meta_debug_control_get_luminance_percentage (debug_control) / 100.0f;
ref_lum = ref_lum * reference_luminance_factor;
color_state = clutter_color_state_new_full (clutter_context,
colorspace,
transfer_function,
min_lum, max_lum, ref_lum);
if (!color_device->color_state ||
!clutter_color_state_equals (color_device->color_state, color_state))
@ -698,6 +712,9 @@ MetaColorDevice *
meta_color_device_new (MetaColorManager *color_manager,
MetaMonitor *monitor)
{
MetaBackend *backend = meta_color_manager_get_backend (color_manager);
MetaContext *context = meta_backend_get_context (backend);
MetaDebugControl *debug_control = meta_context_get_debug_control (context);
MetaColorDevice *color_device;
color_device = g_object_new (META_TYPE_COLOR_DEVICE, NULL);
@ -724,6 +741,11 @@ meta_color_device_new (MetaColorManager *color_manager,
color_device);
}
g_signal_connect_object (debug_control, "notify::luminance-percentage",
G_CALLBACK (meta_color_device_update),
color_device,
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
return color_device;
}

View file

@ -25,3 +25,5 @@ gboolean meta_debug_control_is_color_management_protocol_enabled (MetaDebugContr
gboolean meta_debug_control_is_linear_blending_forced (MetaDebugControl *debug_control);
gboolean meta_debug_control_is_hdr_enabled (MetaDebugControl *debug_control);
unsigned int meta_debug_control_get_luminance_percentage (MetaDebugControl *debug_control);

View file

@ -182,6 +182,8 @@ meta_debug_control_init (MetaDebugControl *debug_control)
g_strcmp0 (getenv ("MUTTER_DEBUG_FORCE_LINEAR_BLENDING"), "1") == 0;
meta_dbus_debug_control_set_force_linear_blending (dbus_debug_control,
force_linear_blending);
meta_dbus_debug_control_set_luminance_percentage (dbus_debug_control, 100);
}
gboolean
@ -211,6 +213,15 @@ meta_debug_control_is_hdr_enabled (MetaDebugControl *debug_control)
return meta_dbus_debug_control_get_enable_hdr (dbus_debug_control);
}
unsigned int
meta_debug_control_get_luminance_percentage (MetaDebugControl *debug_control)
{
MetaDBusDebugControl *dbus_debug_control =
META_DBUS_DEBUG_CONTROL (debug_control);
return meta_dbus_debug_control_get_luminance_percentage (dbus_debug_control);
}
void
meta_debug_control_set_exported (MetaDebugControl *debug_control,
gboolean exported)

View file

@ -15,6 +15,25 @@ def bool_to_string(value):
else:
return "false"
def string_to_bool(value):
if value == "true":
return True
if value == "false":
return False
raise BaseException(f"bad boolean value: {value}")
def value_to_string(value):
if isinstance(value, dbus.Boolean):
return bool_to_string(value)
return f"{value}"
def string_to_value(current, value):
if isinstance(current, dbus.Boolean):
return dbus.Boolean(string_to_bool(value), variant_level=1)
if isinstance(current, dbus.UInt32):
return dbus.UInt32(int(value), variant_level=1)
return value
def get_debug_control():
bus = dbus.SessionBus()
try:
@ -28,8 +47,9 @@ def get_debug_control():
def status():
debug_control = get_debug_control()
props = debug_control.GetAll(INTERFACE, dbus_interface=PROPS_IFACE)
for prop in props:
print(f"{prop}: {bool_to_string(props[prop])}")
for prop, value in props.items():
value = value_to_string (value)
print(f"{prop}: {value}")
def enable(prop):
debug_control = get_debug_control()
@ -48,6 +68,14 @@ def toggle(prop):
debug_control.Set(INTERFACE, prop, dbus.Boolean(not value, variant_level=1),
dbus_interface=PROPS_IFACE)
def set_value(kv):
debug_control = get_debug_control()
[prop, value] = kv
current = debug_control.Get(INTERFACE, prop, dbus_interface=PROPS_IFACE)
value = string_to_value (current, value)
debug_control.Set(INTERFACE, prop, value, dbus_interface=PROPS_IFACE)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get and set debug state')
@ -56,6 +84,7 @@ if __name__ == '__main__':
parser.add_argument('--enable', metavar='PROPERTY', type=str, nargs='?')
parser.add_argument('--disable', metavar='PROPERTY', type=str, nargs='?')
parser.add_argument('--toggle', metavar='PROPERTY', type=str, nargs='?')
parser.add_argument('--set', metavar='PROPERTY', type=str, nargs=2)
args = parser.parse_args()
if args.status:
@ -66,5 +95,7 @@ if __name__ == '__main__':
disable(args.disable)
elif args.toggle:
toggle(args.toggle)
elif args.set:
set_value(args.set)
else:
parser.print_usage()