Verified Commit fdad6ddc authored by Sebastian Krzyszkowiak's avatar Sebastian Krzyszkowiak Committed by Sebastian Krzyszkowiak

wayland: Switch to wlr-gamma-control protocol

parent 382c2b1e
Pipeline #64074 failed with stages
in 18 minutes and 19 seconds
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="gamma_control">
<copyright>
Copyright © 2015 Giulio camuffo
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="gamma_control_manager" version="1">
<request name="destroy" type="destructor"/>
<request name="get_gamma_control">
<arg name="id" type="new_id" interface="gamma_control"/>
<arg name="output" type="object" interface="wl_output"/>
</request>
</interface>
<interface name="gamma_control" version="1">
<enum name="error">
<entry name="invalid_gamma" value="0"/>
</enum>
<request name="destroy" type="destructor"/>
<request name="set_gamma">
<arg name="red" type="array"/>
<arg name="green" type="array"/>
<arg name="blue" type="array"/>
</request>
<request name="reset_gamma"/>
<event name="gamma_size">
<arg name="size" type="uint"/>
</event>
</interface>
</protocol>
......@@ -11,11 +11,11 @@ gen_scanner_client_code = generator(wl_scanner,
wl_protos = [
'/'.join([wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml']),
'/'.join([wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml']),
'gamma-control.xml',
'idle.xml',
'wlr-screencopy-unstable-v1.xml',
'phosh-private.xml',
'wlr-foreign-toplevel-management-unstable-v1.xml',
'wlr-gamma-control-unstable-v1.xml',
'wlr-input-inhibitor-unstable-v1.xml',
'wlr-layer-shell-unstable-v1.xml',
'wlr-output-management-unstable-v1.xml',
......
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_gamma_control_unstable_v1">
<copyright>
Copyright © 2015 Giulio camuffo
Copyright © 2018 Simon Ser
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<description summary="manage gamma tables of outputs">
This protocol allows a privileged client to set the gamma tables for
outputs.
Warning! The protocol described in this file is experimental and
backward incompatible changes may be made. Backward compatible changes
may be added together with the corresponding interface version bump.
Backward incompatible changes are done by bumping the version number in
the protocol and interface names and resetting the interface version.
Once the protocol is to be declared stable, the 'z' prefix and the
version number in the protocol and interface names are removed and the
interface version number is reset.
</description>
<interface name="zwlr_gamma_control_manager_v1" version="1">
<description summary="manager to create per-output gamma controls">
This interface is a manager that allows creating per-output gamma
controls.
</description>
<request name="get_gamma_control">
<description summary="get a gamma control for an output">
Create a gamma control that can be used to adjust gamma tables for the
provided output.
</description>
<arg name="id" type="new_id" interface="zwlr_gamma_control_v1"/>
<arg name="output" type="object" interface="wl_output"/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the manager">
All objects created by the manager will still remain valid, until their
appropriate destroy request has been called.
</description>
</request>
</interface>
<interface name="zwlr_gamma_control_v1" version="1">
<description summary="adjust gamma tables for an output">
This interface allows a client to adjust gamma tables for a particular
output.
The client will receive the gamma size, and will then be able to set gamma
tables. At any time the compositor can send a failed event indicating that
this object is no longer valid.
There can only be at most one gamma control object per output, which
has exclusive access to this particular output. When the gamma control
object is destroyed, the gamma table is restored to its original value.
</description>
<event name="gamma_size">
<description summary="size of gamma ramps">
Advertise the size of each gamma ramp.
This event is sent immediately when the gamma control object is created.
</description>
<arg name="size" type="uint" summary="number of elements in a ramp"/>
</event>
<enum name="error">
<entry name="invalid_gamma" value="1" summary="invalid gamma tables"/>
</enum>
<request name="set_gamma">
<description summary="set the gamma table">
Set the gamma table. The file descriptor can be memory-mapped to provide
the raw gamma table, which contains successive gamma ramps for the red,
green and blue channels. Each gamma ramp is an array of 16-byte unsigned
integers which has the same length as the gamma size.
The file descriptor data must have the same length as three times the
gamma size.
</description>
<arg name="fd" type="fd" summary="gamma table file descriptor"/>
</request>
<event name="failed">
<description summary="object no longer valid">
This event indicates that the gamma control is no longer valid. This
can happen for a number of reasons, including:
- The output doesn't support gamma tables
- Setting the gamma tables failed
- Another client already has exclusive gamma control for this output
- The compositor has transferred gamma control to another client
Upon receiving this event, the client should destroy this object.
</description>
</event>
<request name="destroy" type="destructor">
<description summary="destroy this control">
Destroys the gamma control object. If the object is still valid, this
restores the original gamma tables.
</description>
</request>
</interface>
</protocol>
......@@ -14,12 +14,15 @@
#include "monitor/head.h"
#include "monitor/monitor.h"
#include "gamma-control-client-protocol.h"
#include "wlr-gamma-control-unstable-v1-client-protocol.h"
#include "phosh-wayland.h"
#include "shell.h"
#include <gdk/gdkwayland.h>
#include <sys/mman.h>
#include <errno.h>
/**
* SECTION:monitor-manager
* @short_description: The singleton that manages available monitors
......@@ -316,52 +319,6 @@ phosh_monitor_manager_handle_change_backlight (
}
struct get_wl_gamma_callback_data {
PhoshDisplayDbusDisplayConfig *skeleton;
GDBusMethodInvocation *invocation;
};
static void handle_wl_gamma_size(void *data, struct gamma_control *gamma_control,
uint32_t size) {
struct get_wl_gamma_callback_data *gamma_callback_data = data;
GBytes *red_bytes, *green_bytes, *blue_bytes;
GVariant *red_v, *green_v, *blue_v;
/* All known clients using libgnome-desktop's
gnome_rr_crtc_get_gamma only do so to get the size of the gamma
table. So don't bother getting the real table since this is not
supported by wlroots: https://github.com/swaywm/wlroots/pull/1059.
Return an empty table instead.
*/
size *= sizeof(unsigned short);
red_bytes = g_bytes_new_take (g_malloc0 (size), size);
green_bytes = g_bytes_new_take (g_malloc0 (size), size);
blue_bytes = g_bytes_new_take (g_malloc0 (size), size);
red_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), red_bytes, TRUE);
green_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), green_bytes, TRUE);
blue_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), blue_bytes, TRUE);
phosh_display_dbus_display_config_complete_get_crtc_gamma (
gamma_callback_data->skeleton,
gamma_callback_data->invocation,
red_v, green_v, blue_v);
g_bytes_unref (red_bytes);
g_bytes_unref (green_bytes);
g_bytes_unref (blue_bytes);
g_free (gamma_callback_data);
gamma_control_destroy (gamma_control);
}
static const struct
gamma_control_listener gamma_control_listener = {
.gamma_size = handle_wl_gamma_size,
};
static gboolean
phosh_monitor_manager_handle_get_crtc_gamma (
PhoshDisplayDbusDisplayConfig *skeleton,
......@@ -371,9 +328,9 @@ phosh_monitor_manager_handle_get_crtc_gamma (
{
PhoshMonitorManager *self = PHOSH_MONITOR_MANAGER (skeleton);
PhoshMonitor *monitor;
struct gamma_control *gamma_control;
struct gamma_control_manager *gamma_control_manager;
struct get_wl_gamma_callback_data *data;;
guint32 size;
GBytes *red_bytes, *green_bytes, *blue_bytes;
GVariant *red_v, *green_v, *blue_v;
g_debug ("DBus call %s for crtc %d, serial %d", __func__, crtc_id, serial);
......@@ -391,24 +348,37 @@ phosh_monitor_manager_handle_get_crtc_gamma (
return TRUE;
}
gamma_control_manager = phosh_wayland_get_gamma_control_manager (
phosh_wayland_get_default ());
if (gamma_control_manager == NULL) {
monitor = g_ptr_array_index (self->monitors, crtc_id);
if (!monitor->gamma_control) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
"gamma control not supported");
return TRUE;
}
data = g_new0 (struct get_wl_gamma_callback_data, 1);
data->skeleton = skeleton;
data->invocation = invocation;
/* All known clients using libgnome-desktop's
gnome_rr_crtc_get_gamma only do so to get the size of the gamma
table. So don't bother getting the real table since this is not
supported by wlroots: https://github.com/swaywm/wlroots/pull/1059.
Return an empty table instead.
*/
size = monitor->gamma_size;
red_bytes = g_bytes_new_take (g_malloc0 (size), size);
green_bytes = g_bytes_new_take (g_malloc0 (size), size);
blue_bytes = g_bytes_new_take (g_malloc0 (size), size);
red_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), red_bytes, TRUE);
green_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), green_bytes, TRUE);
blue_v = g_variant_new_from_bytes (G_VARIANT_TYPE ("aq"), blue_bytes, TRUE);
monitor = g_ptr_array_index (self->monitors, crtc_id);
gamma_control = gamma_control_manager_get_gamma_control (
gamma_control_manager,
monitor->wl_output);
gamma_control_add_listener (gamma_control, &gamma_control_listener, data);
phosh_display_dbus_display_config_complete_get_crtc_gamma (
skeleton, invocation,
red_v, green_v, blue_v);
g_bytes_unref (red_bytes);
g_bytes_unref (green_bytes);
g_bytes_unref (blue_bytes);
return TRUE;
}
......@@ -426,12 +396,13 @@ phosh_monitor_manager_handle_set_crtc_gamma (
{
PhoshMonitorManager *self = PHOSH_MONITOR_MANAGER (skeleton);
PhoshMonitor *monitor;
unsigned short *red, *green, *blue;
guint16 *red, *green, *blue;
GBytes *red_bytes, *green_bytes, *blue_bytes;
gsize size, dummy;
struct gamma_control_manager *gamma_control_manager;
struct gamma_control *gamma_control;
struct wl_array wl_red, wl_green, wl_blue;
gsize size;
gint fd, ret;
gchar *filename;
guint16 *data;
GError *err = NULL;
g_debug ("DBus call %s for crtc %d, serial %d", __func__, crtc_id, serial);
if (serial != self->serial) {
......@@ -448,17 +419,15 @@ phosh_monitor_manager_handle_set_crtc_gamma (
return TRUE;
}
gamma_control_manager = phosh_wayland_get_gamma_control_manager (
phosh_wayland_get_default ());
if (!gamma_control_manager) {
monitor = g_ptr_array_index (self->monitors, crtc_id);
if (!monitor->gamma_control) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
"gamma control not supported");
return TRUE;
}
monitor = g_ptr_array_index (self->monitors, crtc_id);
red_bytes = g_variant_get_data_as_bytes (red_v);
green_bytes = g_variant_get_data_as_bytes (green_v);
blue_bytes = g_variant_get_data_as_bytes (blue_v);
......@@ -467,40 +436,59 @@ phosh_monitor_manager_handle_set_crtc_gamma (
if (size != g_bytes_get_size (blue_bytes) || size != g_bytes_get_size (green_bytes)) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
"gamma for each color must have same size");
"gamma for each channel must have same size");
goto err;
}
red = (unsigned short*) g_bytes_get_data (red_bytes, &dummy);
green = (unsigned short*) g_bytes_get_data (green_bytes, &dummy);
blue = (unsigned short*) g_bytes_get_data (blue_bytes, &dummy);
red = (guint16*) g_bytes_get_data (red_bytes, NULL);
green = (guint16*) g_bytes_get_data (green_bytes, NULL);
blue = (guint16*) g_bytes_get_data (blue_bytes, NULL);
if (!red || !green || !blue) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_NOT_SUPPORTED,
"could not extract gamma values");
goto err;
}
wl_array_init (&wl_red);
wl_array_init (&wl_green);
wl_array_init (&wl_blue);
fd = g_file_open_tmp("phosh-XXXXXX", &filename, &err);
wl_array_add (&wl_red, size);
wl_array_add (&wl_green, size);
wl_array_add (&wl_blue, size);
do {
errno = 0;
ret = ftruncate(fd, size * 3);
} while (errno == EINTR);
if (ret < 0) {
close(fd);
fd = -1;
}
memcpy(wl_red.data, red, size);
memcpy(wl_green.data, green, size);
memcpy(wl_blue.data, blue, size);
if (fd < 0 || err) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_IO_ERROR,
"could not create temporary file for gamma ramps data");
goto err;
}
unlink(filename);
gamma_control = gamma_control_manager_get_gamma_control (
gamma_control_manager,
monitor->wl_output);
gamma_control_set_gamma(gamma_control, &wl_red, &wl_green, &wl_blue);
gamma_control_destroy (gamma_control);
data = mmap(NULL, size * 3, PROT_WRITE, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_IO_ERROR,
"could not memory map temporary file for gamma ramps data");
goto err;
}
for (gsize i=0; i < size / sizeof(guint16); i++) {
data[i] = red[i];
data[i + size] = green[i];
data[i + 2 * size] = blue[i];
}
munmap(data, size * 3);
zwlr_gamma_control_v1_set_gamma (monitor->gamma_control, fd);
phosh_display_dbus_display_config_complete_set_crtc_gamma (
skeleton,
invocation);
wl_array_release (&wl_red);
wl_array_release (&wl_green);
wl_array_release (&wl_blue);
err:
g_bytes_unref (red_bytes);
g_bytes_unref (green_bytes);
......
......@@ -272,6 +272,26 @@ static const struct zwlr_output_power_v1_listener wlr_output_power_listener_v1 =
};
static void handle_wl_gamma_size(void *data, struct zwlr_gamma_control_v1 *gamma_control,
uint32_t size) {
PhoshMonitor *self = PHOSH_MONITOR (data);
self->gamma_size = size;
}
static void handle_wl_gamma_failed(void *data, struct zwlr_gamma_control_v1 *gamma_control) {
PhoshMonitor *self = PHOSH_MONITOR (data);
g_warning ("wl_gamma failed!");
zwlr_gamma_control_v1_destroy (gamma_control);
self->gamma_control = NULL;
}
static const struct
zwlr_gamma_control_v1_listener gamma_control_listener = {
.gamma_size = handle_wl_gamma_size,
.failed = handle_wl_gamma_failed,
};
static void
phosh_monitor_set_property (GObject *object,
guint property_id,
......@@ -327,6 +347,7 @@ phosh_monitor_dispose (GObject *object)
g_clear_pointer (&self->name, g_free);
g_clear_pointer (&self->xdg_output, zxdg_output_v1_destroy);
g_clear_pointer (&self->wlr_output_power, zwlr_output_power_v1_destroy);
g_clear_pointer (&self->gamma_control, zwlr_gamma_control_v1_destroy);
G_OBJECT_CLASS (phosh_monitor_parent_class)->dispose (object);
}
......@@ -356,6 +377,12 @@ phosh_monitor_constructed (GObject *object)
g_return_if_fail (self->wlr_output_power);
zwlr_output_power_v1_add_listener(self->wlr_output_power, &wlr_output_power_listener_v1, self);
}
self->gamma_control =
zwlr_gamma_control_manager_v1_get_gamma_control (phosh_wayland_get_zwlr_gamma_control_manager_v1 (phosh_wayland_get_default ()),
self->wl_output);
g_return_if_fail (self->gamma_control);
zwlr_gamma_control_v1_add_listener (self->gamma_control, &gamma_control_listener, self);
}
......
......@@ -139,6 +139,9 @@ struct _PhoshMonitor {
gboolean wl_output_done;
gboolean xdg_output_done;
struct zwlr_gamma_control_v1 *gamma_control;
guint32 gamma_size;
};
G_DECLARE_FINAL_TYPE (PhoshMonitor, phosh_monitor, PHOSH, MONITOR, GObject)
......
......@@ -35,7 +35,6 @@ static GParamSpec *props[PHOSH_WAYLAND_PROP_LAST_PROP];
struct _PhoshWayland {
GObject parent;
struct gamma_control_manager *gamma_control_manager;
struct org_kde_kwin_idle *idle_manager;
struct phosh_private *phosh_private;
struct wl_display *display;
......@@ -43,6 +42,7 @@ struct _PhoshWayland {
struct wl_seat *wl_seat;
struct xdg_wm_base *xdg_wm_base;
struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1;
struct zwlr_gamma_control_manager_v1 *zwlr_gamma_control_manager_v1;
struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
struct zwlr_layer_shell_v1 *layer_shell;
struct zwlr_output_manager_v1 *zwlr_output_manager_v1;
......@@ -112,11 +112,11 @@ registry_handle_global (void *data,
name,
&xdg_wm_base_interface,
1);
} else if (!strcmp(interface, gamma_control_manager_interface.name)) {
self->gamma_control_manager = wl_registry_bind(
} else if (!strcmp(interface, zwlr_gamma_control_manager_v1_interface.name)) {
self->zwlr_gamma_control_manager_v1 = wl_registry_bind(
registry,
name,
&gamma_control_manager_interface,
&zwlr_gamma_control_manager_v1_interface,
1);
} else if (!strcmp (interface, zxdg_output_manager_v1_interface.name)) {
self->zxdg_output_manager_v1 = wl_registry_bind(
......@@ -340,12 +340,12 @@ phosh_wayland_get_zwlr_layer_shell_v1 (PhoshWayland *self)
}
struct gamma_control_manager*
phosh_wayland_get_gamma_control_manager (PhoshWayland *self)
struct zwlr_gamma_control_manager_v1*
phosh_wayland_get_zwlr_gamma_control_manager_v1 (PhoshWayland *self)
{
g_return_val_if_fail (PHOSH_IS_WAYLAND (self), NULL);
return self->gamma_control_manager;
return self->zwlr_gamma_control_manager_v1;
}
......
......@@ -7,13 +7,13 @@
*/
#pragma once
#include "gamma-control-client-protocol.h"
#include "idle-client-protocol.h"
#include "wlr-screencopy-unstable-v1-client-protocol.h"
#include "phosh-private-client-protocol.h"
#include "wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"
#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "wlr-gamma-control-unstable-v1-client-protocol.h"
#include "wlr-output-management-unstable-v1-client-protocol.h"
#include "wlr-output-power-management-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
......@@ -47,7 +47,6 @@ PhoshWayland *phosh_wayland_get_default (void);
GHashTable *phosh_wayland_get_wl_outputs (PhoshWayland *self);
gboolean phosh_wayland_has_wl_output (PhoshWayland *self,
struct wl_output *wl_output);
struct gamma_control_manager *phosh_wayland_get_gamma_control_manager (PhoshWayland *self);
struct org_kde_kwin_idle *phosh_wayland_get_org_kde_kwin_idle (PhoshWayland *self);
struct phosh_private *phosh_wayland_get_phosh_private (PhoshWayland *self);
struct wl_seat *phosh_wayland_get_wl_seat (PhoshWayland *self);
......@@ -56,6 +55,7 @@ struct xdg_wm_base *phosh_wayland_get_xdg_wm_base (PhoshWaylan
struct zwlr_foreign_toplevel_manager_v1 *phosh_wayland_get_zwlr_foreign_toplevel_manager_v1 (PhoshWayland *self);
struct zwlr_input_inhibit_manager_v1 *phosh_wayland_get_zwlr_input_inhibit_manager_v1 (PhoshWayland *self);
struct zwlr_layer_shell_v1 *phosh_wayland_get_zwlr_layer_shell_v1 (PhoshWayland *self);
struct zwlr_gamma_control_manager_v1 *phosh_wayland_get_zwlr_gamma_control_manager_v1 (PhoshWayland *self);
struct zwlr_output_manager_v1 *phosh_wayland_get_zwlr_output_manager_v1 (PhoshWayland *self);
struct zwlr_output_power_manager_v1 *phosh_wayland_get_zwlr_output_power_manager_v1 (PhoshWayland *self);
struct zxdg_output_manager_v1 *phosh_wayland_get_zxdg_output_manager_v1 (PhoshWayland *self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment