Commit 6686d9b7 authored by Marco Trevisan's avatar Marco Trevisan 🎺

x11, crtc: add function to scale a single crtc using randr

Randr transformation can be used to scale a single crtc using various filters.
parent e8fcee80
......@@ -46,6 +46,7 @@
#include "backends/x11/meta-monitor-manager-xrandr.h"
#define ALL_TRANSFORMS ((1 << (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)) - 1)
#define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536))
gboolean
meta_crtc_xrandr_set_config (MetaCrtc *crtc,
......@@ -98,6 +99,62 @@ meta_crtc_xrandr_set_config (MetaCrtc *crtc,
*out_timestamp = reply->timestamp;
free (reply);
return TRUE;
}
gboolean
meta_crtc_xrandr_set_scale (MetaCrtc *crtc,
xcb_randr_crtc_t xrandr_crtc,
float scale)
{
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
MetaMonitorManagerXrandr *monitor_manager_xrandr =
META_MONITOR_MANAGER_XRANDR (monitor_manager);
Display *xdisplay;
const char *scale_filter;
xcb_connection_t *xcb_conn;
xcb_void_cookie_t transform_cookie;
xcb_generic_error_t *xcb_error = NULL;
xcb_render_transform_t transformation = {
DOUBLE_TO_FIXED (1), DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (0),
DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (1), DOUBLE_TO_FIXED (0),
DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (0), DOUBLE_TO_FIXED (1)
};
if (!(meta_monitor_manager_get_capabilities (monitor_manager) &
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING))
return FALSE;
xdisplay = meta_monitor_manager_xrandr_get_xdisplay (monitor_manager_xrandr);
xcb_conn = XGetXCBConnection (xdisplay);
if (scale != 1.0f)
{
scale_filter = FilterGood;
transformation.matrix11 = DOUBLE_TO_FIXED (1.0 / scale);
transformation.matrix22 = DOUBLE_TO_FIXED (1.0 / scale);
}
else
scale_filter = FilterFast;
transform_cookie = xcb_randr_set_crtc_transform (xcb_conn, xrandr_crtc,
transformation,
strlen (scale_filter),
scale_filter,
0, NULL);
xcb_error = xcb_request_check (xcb_conn, transform_cookie);
if (xcb_error)
{
g_warning ("Impossible to set scaling on crtc %u to %f, error id %u",
xrandr_crtc, scale, xcb_error->error_code);
g_clear_pointer (&xcb_error, free);
return FALSE;
}
return TRUE;
}
......
......@@ -39,6 +39,10 @@ gboolean meta_crtc_xrandr_set_config (MetaCrtc *crtc,
int n_outputs,
xcb_timestamp_t *out_timestamp);
gboolean meta_crtc_xrandr_set_scale (MetaCrtc *crtc,
xcb_randr_crtc_t xrandr_crtc,
float scale);
MetaCrtc * meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr,
XRRCrtcInfo *xrandr_crtc,
RRCrtc crtc_id,
......
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