Commit e8fcee80 authored by Marco Trevisan's avatar Marco Trevisan 🎺

x11, crtc: read current randr scaling when creating a new crtc

Since now we've this flag in the crtc, we can get the current scaling from X11
and save it in the crtc infos.
parent 068cf4c8
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "backends/x11/meta-crtc-xrandr.h" #include "backends/x11/meta-crtc-xrandr.h"
#include <X11/Xlib-xcb.h> #include <X11/Xlib-xcb.h>
#include <X11/extensions/Xrender.h>
#include <stdlib.h> #include <stdlib.h>
#include <xcb/randr.h> #include <xcb/randr.h>
...@@ -171,11 +172,36 @@ meta_monitor_transform_from_xrandr_all (Rotation rotation) ...@@ -171,11 +172,36 @@ meta_monitor_transform_from_xrandr_all (Rotation rotation)
return ret; return ret;
} }
static float
meta_monitor_scale_from_transformation (XRRCrtcTransformAttributes *transformation)
{
XTransform *xt;
float scale;
if (!transformation)
return 1.0f;
xt = &transformation->currentTransform;
if (xt->matrix[0][0] == xt->matrix[1][1])
scale = XFixedToDouble (xt->matrix[0][0]);
else
scale = XFixedToDouble (xt->matrix[0][0] + xt->matrix[1][1]) / 2.0;
/* Due to inverse scaling computation, the value here won't ever match
exactly the one we have set, thus we should associate it to the closest
one in all the valid scaling values for the given mode.
However at this level we can simply assume that we supports only 4
scaling levels for integer, and round to one of these. */
return roundf ((1.0f / scale) * 4.0f) / 4.0f;
}
MetaCrtc * MetaCrtc *
meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr,
XRRCrtcInfo *xrandr_crtc, XRRCrtcInfo *xrandr_crtc,
RRCrtc crtc_id, RRCrtc crtc_id,
XRRScreenResources *resources) XRRScreenResources *resources,
XRRCrtcTransformAttributes *transform_attributes)
{ {
MetaCrtc *crtc; MetaCrtc *crtc;
unsigned int i; unsigned int i;
...@@ -194,6 +220,7 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, ...@@ -194,6 +220,7 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr,
meta_monitor_transform_from_xrandr (xrandr_crtc->rotation); meta_monitor_transform_from_xrandr (xrandr_crtc->rotation);
crtc->all_transforms = crtc->all_transforms =
meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations); meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations);
crtc->scale = meta_monitor_scale_from_transformation (transform_attributes);
modes = meta_gpu_get_modes (crtc->gpu); modes = meta_gpu_get_modes (crtc->gpu);
for (i = 0; i < (unsigned int) resources->nmode; i++) for (i = 0; i < (unsigned int) resources->nmode; i++)
......
...@@ -39,9 +39,10 @@ gboolean meta_crtc_xrandr_set_config (MetaCrtc *crtc, ...@@ -39,9 +39,10 @@ gboolean meta_crtc_xrandr_set_config (MetaCrtc *crtc,
int n_outputs, int n_outputs,
xcb_timestamp_t *out_timestamp); xcb_timestamp_t *out_timestamp);
MetaCrtc * meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, MetaCrtc * meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr,
XRRCrtcInfo *xrandr_crtc, XRRCrtcInfo *xrandr_crtc,
RRCrtc crtc_id, RRCrtc crtc_id,
XRRScreenResources *resources); XRRScreenResources *resources,
XRRCrtcTransformAttributes *transform_attributes);
#endif /* META_CRTC_XRANDR_H */ #endif /* META_CRTC_XRANDR_H */
...@@ -102,6 +102,7 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu, ...@@ -102,6 +102,7 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu,
GList *outputs = NULL; GList *outputs = NULL;
GList *modes = NULL; GList *modes = NULL;
GList *crtcs = NULL; GList *crtcs = NULL;
gboolean has_transform;
if (gpu_xrandr->resources) if (gpu_xrandr->resources)
XRRFreeScreenResources (gpu_xrandr->resources); XRRFreeScreenResources (gpu_xrandr->resources);
...@@ -182,17 +183,26 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu, ...@@ -182,17 +183,26 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu,
} }
meta_gpu_take_modes (gpu, modes); meta_gpu_take_modes (gpu, modes);
has_transform = !!(meta_monitor_manager_get_capabilities (monitor_manager) &
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING);
for (i = 0; i < (unsigned)resources->ncrtc; i++) for (i = 0; i < (unsigned)resources->ncrtc; i++)
{ {
XRRCrtcInfo *xrandr_crtc; XRRCrtcInfo *xrandr_crtc;
XRRCrtcTransformAttributes *transform_attributes;
RRCrtc crtc_id; RRCrtc crtc_id;
MetaCrtc *crtc; MetaCrtc *crtc;
crtc_id = resources->crtcs[i]; crtc_id = resources->crtcs[i];
xrandr_crtc = XRRGetCrtcInfo (xdisplay, xrandr_crtc = XRRGetCrtcInfo (xdisplay,
resources, crtc_id); resources, crtc_id);
if (!has_transform ||
!XRRGetCrtcTransform (xdisplay, crtc_id, &transform_attributes))
transform_attributes = NULL;
crtc = meta_create_xrandr_crtc (gpu_xrandr, crtc = meta_create_xrandr_crtc (gpu_xrandr,
xrandr_crtc, crtc_id, resources); xrandr_crtc, crtc_id, resources,
transform_attributes);
XFree (transform_attributes);
XRRFreeCrtcInfo (xrandr_crtc); XRRFreeCrtcInfo (xrandr_crtc);
crtcs = g_list_append (crtcs, crtc); crtcs = g_list_append (crtcs, crtc);
......
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