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

And some more improvements

parent bad65346
Pipeline #69334 failed with stages
in 49 seconds
......@@ -106,6 +106,11 @@ meta_logical_monitor_new (MetaMonitorManager *monitor_manager,
logical_monitor->in_fullscreen = -1;
logical_monitor->rect = logical_monitor_config->layout;
g_print("XRANDR: Built monitor %dx%d %dx%d @ %f\n",
logical_monitor->rect.x, logical_monitor->rect.y,
logical_monitor->rect.width,logical_monitor->rect.height,
logical_monitor->scale);
logical_monitor->is_presentation = TRUE;
g_list_foreach (monitor_configs, (GFunc) add_monitor_from_config,
&(AddMonitorFromConfigData) {
......
......@@ -373,7 +373,9 @@ gboolean meta_monitor_manager_is_scale_supported (MetaMonitorManager
MetaMonitorMode *monitor_mode,
float scale);
float meta_monitor_manager_get_maximum_scale (MetaMonitorManager *manager);
float meta_monitor_manager_get_maximum_monitor_scale (MetaMonitorManager *manager);
float meta_monitor_manager_get_maximum_crtc_scale (MetaMonitorManager *manager);
gboolean meta_monitor_manager_disable_scale_for_monitor (MetaMonitorManager *manager,
MetaLogicalMonitor *monitor);
......
......@@ -201,19 +201,20 @@ meta_monitor_manager_rebuild_logical_monitors (MetaMonitorManager *manager,
}
float
meta_monitor_manager_get_maximum_scale (MetaMonitorManager *manager)
meta_monitor_manager_get_maximum_crtc_scale (MetaMonitorManager *manager)
{
GList *l;
float scale;
scale = 1.0f;
/* Use config if available, otherwise or */
for (l = manager->monitors; l != NULL; l = l->next)
{
MetaMonitor *monitor = l->data;
MetaOutput *output = meta_monitor_get_main_output (monitor);
MetaCrtc *crtc = meta_output_get_assigned_crtc (output);
if (crtc)
g_print(" XRANDR: CRTC %d scale %f\n",crtc->crtc_id,crtc->scale);
if (crtc)
scale = MAX (scale, crtc->scale);
}
......@@ -221,6 +222,36 @@ meta_monitor_manager_get_maximum_scale (MetaMonitorManager *manager)
return scale;
}
float
meta_monitor_manager_get_maximum_monitor_scale (MetaMonitorManager *manager)
{
GList *l;
float scale;
scale = 1.0f;
/* Use config if available, otherwise or */
for (l = manager->monitors; l != NULL; l = l->next)
{
MetaMonitor *monitor = l->data;
MetaOutput *output = meta_monitor_get_main_output (monitor);
MetaCrtc *crtc = meta_output_get_assigned_crtc (output);
if (crtc)
g_print(" XRANDR: CRTC %d scale %f\n",crtc->crtc_id,crtc->scale);
// if (crtc)
// scale = MAX (scale, crtc->scale);
}
for (l = manager->logical_monitors; l != NULL; l = l->next)
{
MetaLogicalMonitor *logical_monitor = l->data;
g_print(" XRANDR: Monitor %d scale %f\n",logical_monitor->number,logical_monitor->scale);
scale = MAX (scale, logical_monitor->scale);
}
return scale;
}
static float
derive_configured_global_scale (MetaMonitorManager *manager,
MetaMonitorsConfig *config)
......@@ -331,12 +362,32 @@ derive_scale_from_config (MetaMonitorManager *manager,
return 1.0;
}
static float
derive_crtc_maximum_scale (MetaMonitorManager *manager)
{
GList *l;
float scale = 1.0f;
for (l = manager->monitors; l != NULL; l = l->next)
{
MetaMonitor *monitor = l->data;
MetaOutput *output = meta_monitor_get_main_output (monitor);
MetaCrtc *crtc = meta_output_get_assigned_crtc (output);
if (crtc)
scale = MAX (scale, crtc->scale);
}
return scale;
}
static gboolean
derive_scale_from_crtc (MetaMonitorManager *manager,
MetaMonitor *monitor,
float *scale)
{
MetaMonitorMode *monitor_mode;
float crtc_scale;
float threshold = FLT_EPSILON;
MetaOutput *output = meta_monitor_get_main_output (monitor);
MetaCrtc *crtc = meta_output_get_assigned_crtc (output);
......@@ -346,23 +397,31 @@ derive_scale_from_crtc (MetaMonitorManager *manager,
if (!crtc)
return FALSE;
crtc_scale = crtc->scale;
monitor_mode = meta_monitor_get_current_mode (monitor);
/* Due to inverse scaling applied to the output the result could not match
* exactly, so we apply a more relaxed threshold in this case. */
if (meta_monitor_manager_get_capabilities (manager) &
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING)
{
threshold = 0.01f;
// if (manager->layout_mode == META_LOGICAL_MONITOR_LAYOUT_MODE_GLOBAL_UI_LOGICAL)
// crtc_scale *= derive_crtc_maximum_scale (manager);
}
if (meta_monitor_manager_is_scale_supported_with_threshold (manager,
manager->layout_mode,
monitor,
monitor_mode,
crtc->scale,
crtc_scale,
threshold,
scale))
{
g_print("XRANDR: Derived CRT scale is %f\n",*scale);
return TRUE;
}
return FALSE;
// monitor_mode = meta_monitor_get_current_mode (monitor);
// constraints = meta_monitor_manager_get
......@@ -408,8 +467,8 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manag
meta_monitor_derive_layout (monitor, &layout);
logical_monitor = logical_monitor_from_layout (manager, logical_monitors,
&layout);
g_print("XRANDR. Deriving monitor, is it logical %p, layout %dx%d\n",logical_monitor,
layout.width,layout.height);
g_print("XRANDR. Deriving monitor, is it logical %p, layout %dx%d. We have config %p\n",logical_monitor,
layout.width,layout.height, config);
// layout.width *= 0.75;
// layout.height *= 0.75;
if (logical_monitor)
......
......@@ -1563,8 +1563,8 @@ meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
&global_scaling_factor))
return global_scaling_factor;
if (g_strcmp0 (meta_monitor_get_connector (monitor), "Virtual1") == 0)
return 1.5;
// if (g_strcmp0 (meta_monitor_get_connector (monitor), "Virtual1") == 0)
// return 1.5;
return calculate_scale (monitor, monitor_mode, constraints);
}
......@@ -1660,6 +1660,7 @@ meta_monitor_calculate_supported_scales (MetaMonitor *monitor,
MetaMonitorScalesConstraint constraints,
int *n_supported_scales)
{
/* Check for mode 1636x936 1 1.33333 1.33333 2 4) */
unsigned int i, j;
int width, height;
GArray *supported_scales;
......
......@@ -95,8 +95,8 @@ calculate_ui_scaling_factor (MetaSettings *settings)
{
if (!monitor_manager)
return 1;
g_print("XRANDR: Maximum scale is %f\n", (meta_monitor_manager_get_maximum_scale (monitor_manager)));
return ceilf (meta_monitor_manager_get_maximum_scale (monitor_manager));
g_print("XRANDR: Maximum scale is %f\n", (meta_monitor_manager_get_maximum_crtc_scale (monitor_manager)));
return ceilf (meta_monitor_manager_get_maximum_crtc_scale (monitor_manager));
// return 2;
}
......@@ -131,6 +131,8 @@ update_ui_scaling_factor (MetaSettings *settings)
if (settings->ui_scaling_factor != ui_scaling_factor)
{
g_print("XRANDR: UI SCALING FACTOR CHANGEDD!!! update_ui_scale_factor: %d (was %d)\n",
ui_scaling_factor, settings->ui_scaling_factor);
settings->ui_scaling_factor = ui_scaling_factor;
return TRUE;
}
......
......@@ -356,15 +356,15 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr,
meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations);
crtc->scale = meta_monitor_scale_from_transformation (transform_attributes);
g_print("XRANDR: %s: ID: %d: %dx%d + %dx%d\n", G_STRFUNC, crtc->crtc_id, crtc->rect.width,crtc->rect.height,
crtc->rect.x, crtc->rect.y);
g_print("XRANDR: %s (%p): ID: %d: %dx%d + %dx%d @ %f\n", G_STRFUNC, crtc, crtc->crtc_id, crtc->rect.width,crtc->rect.height,
crtc->rect.x, crtc->rect.y, crtc->scale);
g_print(" XRANDR: Transform attributes are %p\n",transform_attributes);
g_print(" XRANDR: current scale is %f\n",crtc->scale);
if (meta_settings_get_x11_scale_mode (settings) == META_X11_SCALE_MODE_UI_DOWN) {
crtc->scale *= meta_settings_get_ui_scaling_factor (settings);
g_print("XRANDR: Scale multiplied per UI is %f\n",crtc->scale);
}
// g_print(" XRANDR: current scale is %f\n",crtc->scale);
// if (meta_settings_get_x11_scale_mode (settings) == META_X11_SCALE_MODE_UI_DOWN) {
// crtc->scale *= meta_settings_get_ui_scaling_factor (settings);
// g_print("XRANDR: Scale multiplied per UI is %f\n",crtc->scale);
// }
modes = meta_gpu_get_modes (crtc->gpu);
for (i = 0; i < (unsigned int) resources->nmode; i++)
......
......@@ -92,6 +92,62 @@ get_xmode_name (XRRModeInfo *xmode)
return g_strdup_printf ("%dx%d", width, height);
}
/* Set the Output scaling as output property!!!!!!!! */
static int
get_current_dpi_scale (MetaMonitorManagerXrandr *manager_xrandr,
MetaGpuXrandr *gpu_xrandr)
{
Atom actual;
int result, format;
unsigned long n, left;
g_autofree unsigned char *data = NULL;
g_auto(GStrv) resources = NULL;
Display *dpy;
int i;
// return 1;
if (gpu_xrandr->resources->timestamp ==
meta_monitor_manager_xrandr_get_config_timestamp (manager_xrandr))
{
MetaMonitorManager *monitor_manager = META_MONITOR_MANAGER (manager_xrandr);
MetaBackend *backend = meta_monitor_manager_get_backend (monitor_manager);
MetaSettings *settings = meta_backend_get_settings (backend);
return meta_settings_get_ui_scaling_factor (settings);
}
dpy = meta_monitor_manager_xrandr_get_xdisplay (manager_xrandr);
result = XGetWindowProperty (dpy, DefaultRootWindow (dpy),
XA_RESOURCE_MANAGER, 0L, 65536, False,
XA_STRING, &actual, &format,
&n, &left, &data);
if (result != Success || !data || actual != XA_STRING)
return 1;
resources = g_strsplit ((char *) data, "\n", -1);
for (i = 0; resources && resources[i]; ++i)
{
if (g_str_has_prefix (resources[i], "Xft.dpi:"))
{
g_auto(GStrv) res = g_strsplit (resources[i], "\t", 2);
if (res && res[0] && res[1])
{
guint64 dpi;
dpi = g_ascii_strtoull (res[1], NULL, 10);
if (dpi > 0 && dpi < 96 * 10)
return MAX (1, roundf ((float) dpi / 96.0f));
}
}
}
return 1;
}
static gboolean
meta_gpu_xrandr_read_current (MetaGpu *gpu,
GError **error)
......@@ -113,6 +169,7 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu,
GList *modes = NULL;
GList *crtcs = NULL;
gboolean has_transform;
int dpi_scale = 1;
if (gpu_xrandr->resources)
XRRFreeScreenResources (gpu_xrandr->resources);
......@@ -195,6 +252,14 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu,
has_transform = !!(meta_monitor_manager_get_capabilities (monitor_manager) &
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING);
if (has_transform &&
meta_monitor_manager_get_default_layout_mode (monitor_manager) ==
META_LOGICAL_MONITOR_LAYOUT_MODE_GLOBAL_UI_LOGICAL)
dpi_scale = get_current_dpi_scale (monitor_manager_xrandr, gpu_xrandr);
g_print("XRANDR: get_current_dpi_scale: %d\n",dpi_scale);
for (i = 0; i < (unsigned)resources->ncrtc; i++)
{
XRRCrtcInfo *xrandr_crtc;
......@@ -212,6 +277,7 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu,
crtc = meta_create_xrandr_crtc (gpu_xrandr,
xrandr_crtc, crtc_id, resources,
transform_attributes);
crtc->scale *= dpi_scale;
XFree (transform_attributes);
XRRFreeCrtcInfo (xrandr_crtc);
......
......@@ -108,6 +108,12 @@ meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *manager_xran
return manager_xrandr->xdisplay;
}
uint32_t
meta_monitor_manager_xrandr_get_config_timestamp (MetaMonitorManagerXrandr *manager_xrandr)
{
return manager_xrandr->last_xrandr_set_timestamp;
}
static GBytes *
meta_monitor_manager_xrandr_read_edid (MetaMonitorManager *manager,
MetaOutput *output)
......@@ -285,7 +291,7 @@ is_crtc_assignment_changed (MetaMonitorManager *monitor_manager,
if ((meta_monitor_manager_get_capabilities (monitor_manager) &
META_MONITOR_MANAGER_CAPABILITY_NATIVE_OUTPUT_SCALING))
{
if (crtc->scale != crtc_info->scale)
if (fabs (crtc->scale - crtc_info->scale) > 0.01)
return TRUE;
}
......@@ -442,20 +448,22 @@ apply_crtc_assignments (MetaMonitorManager *manager,
if (crtc_info->mode == NULL)
continue;
scale = crtc_info->scale;
scale = crtc->scale;
if (scale_mode == META_X11_SCALE_MODE_UI_DOWN)
scale = crtc_info->scale / ceilf (max_scale);
scale = ceilf (max_scale) / crtc_info->scale;
/* do the scaling only on scale down */
if (meta_monitor_transform_is_rotated (crtc_info->transform))
{
width = MAX (width, crtc_info->x + crtc_info->mode->height);
height = MAX (height, crtc_info->y + crtc_info->mode->width);
width = MAX (width, crtc_info->x + roundf (crtc_info->mode->height * scale));
height = MAX (height, crtc_info->y + roundf (crtc_info->mode->width * scale));
}
else
{
width = MAX (width, crtc_info->x + crtc_info->mode->width);
height = MAX (height, crtc_info->y + crtc_info->mode->height);
width = MAX (width, crtc_info->x + roundf (crtc_info->mode->width * scale));
height = MAX (height, crtc_info->y + roundf (crtc_info->mode->height * scale));
}
avg_screen_scale += scale / (float) valid_crtcs;
......@@ -525,7 +533,7 @@ apply_crtc_assignments (MetaMonitorManager *manager,
crtc->scale = 1.0f;
}
g_print("1 meta_monitor_manager_xrandr_update_screen_size %dx%d %f\n",
g_print("XRANDR 1 meta_monitor_manager_xrandr_update_screen_size %dx%d %f\n",
width, height, avg_screen_scale);
meta_monitor_manager_xrandr_update_screen_size (manager_xrandr, width, height,
avg_screen_scale);
......@@ -682,15 +690,26 @@ meta_monitor_manager_xrandr_rebuild_derived (MetaMonitorManager *manager,
MetaMonitorManagerXrandr *manager_xrandr =
META_MONITOR_MANAGER_XRANDR(manager);
meta_monitor_manager_rebuild_derived (manager, config);
// if (meta_monitor_manager_get_default_layout_mode (manager) !=
// META_LOGICAL_MONITOR_LAYOUT_MODE_GLOBAL_UI_LOGICAL)
// else
// meta_monitor_manager_rebuild (manager, config);
/* Compute the new size of the screen (framebuffer) */
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
MetaSettings *settings = meta_backend_get_settings (backend);
MetaX11ScaleMode scale_mode = meta_settings_get_x11_scale_mode (settings);
int screen_width = 0;
int screen_height = 0;
unsigned n_crtcs = 0;
float average_scale = 0;
float max_scale = 1;
GList *l;
if (scale_mode == META_X11_SCALE_MODE_UI_DOWN)
max_scale = ceilf (meta_monitor_manager_get_maximum_crtc_scale (manager));
for (l = meta_gpu_get_crtcs (manager_xrandr->gpu); l; l = l->next)
{
float scale;
......@@ -702,21 +721,26 @@ meta_monitor_manager_xrandr_rebuild_derived (MetaMonitorManager *manager,
/* When scaling up we should not reduce the screen size, or X will fail
* miserabily, while we must do it when scaling down, in order to increase
* the available screen area we can use. */
scale = crtc->scale > 1.0f ? crtc->scale : 1.0f;
scale = MAX (1.0f, crtc->scale);
if (scale_mode == META_X11_SCALE_MODE_UI_DOWN)
scale = max_scale / scale;
g_print(" XRANDR: Updating screen size by crtc %dx%d | %dx%d @ %f\n",crtc->rect.x,crtc->rect.y,
crtc->rect.width,crtc->rect.height,crtc->scale);
if (meta_monitor_transform_is_rotated (crtc->transform))
{
// screen_width = MAX (screen_width, crtc->rect.x + crtc->current_mode->height);
// screen_height = MAX (screen_height, crtc->rect.y + crtc->current_mode->width);
screen_width = MAX (screen_width, roundf ((crtc->rect.x + crtc->rect.height) * scale));
screen_height = MAX (screen_height, roundf ((crtc->rect.y + crtc->rect.width) * scale));
screen_width = MAX (screen_width, roundf (crtc->rect.x + (crtc->rect.height) * scale));
screen_height = MAX (screen_height, roundf (crtc->rect.y + (crtc->rect.width) * scale));
}
else
{
// screen_width = MAX (screen_width, crtc->rect.x + crtc->current_mode->width);
// screen_height = MAX (screen_height, crtc->rect.y + crtc->current_mode->height);
screen_width = MAX (screen_width, roundf ((crtc->rect.x + crtc->rect.width) * scale));
screen_height = MAX (screen_height, roundf ((crtc->rect.y + crtc->rect.height) * scale));
screen_width = MAX (screen_width, roundf (crtc->rect.x + (crtc->rect.width) * scale));
screen_height = MAX (screen_height, roundf (crtc->rect.y + (crtc->rect.height) * scale));
}
++n_crtcs;
......@@ -733,6 +757,17 @@ meta_monitor_manager_xrandr_rebuild_derived (MetaMonitorManager *manager,
meta_monitor_manager_xrandr_update_screen_size (manager_xrandr,
screen_width, screen_height,
average_scale);
g_print("XRANDR: screen width updated to %dx%d\n",manager->screen_width,
manager->screen_height);
meta_monitor_manager_rebuild_derived (manager, config);
// meta_monitor_manager_rebuild_derived (manager, config);
// if (meta_monitor_manager_get_default_layout_mode (manager) ==
// META_LOGICAL_MONITOR_LAYOUT_MODE_GLOBAL_UI_LOGICAL)
// meta_monitor_manager_rebuild_derived (manager, config);
}
static gboolean
......@@ -783,14 +818,17 @@ meta_monitor_manager_xrandr_apply_monitors_config (MetaMonitorManager *mana
crtc_infos->len,
(MetaOutputInfo **) output_infos->pdata,
output_infos->len);
// if (meta_monitor_manager_get_default_layout_mode (manager) ==
// META_LOGICAL_MONITOR_LAYOUT_MODE_GLOBAL_UI_LOGICAL)
// meta_monitor_manager_rebuild (manager, config);
meta_settings_update_ui_scaling_factor (settings);
}
else
{
g_print("XRANDR: REBUILD DERIVED, changed assignments\n");
meta_monitor_manager_xrandr_rebuild_derived (manager, config);
}
meta_settings_update_ui_scaling_factor (settings);
}
g_ptr_array_free (crtc_infos, TRUE);
......
......@@ -36,6 +36,8 @@ Display * meta_monitor_manager_xrandr_get_xdisplay (MetaMonitorManagerXrandr *ma
gboolean meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManagerXrandr *manager,
XEvent *event);
uint32_t meta_monitor_manager_xrandr_get_config_timestamp (MetaMonitorManagerXrandr *manager);
// void meta_monitor_manager_xrandr_update_screen_size (MetaMonitorManagerXrandr *manager,
// int width,
// int height);
......
......@@ -30,6 +30,8 @@
void meta_output_xrandr_apply_mode (MetaOutput *output);
// void meta_output_xrandr_set_ui_scale
void meta_output_xrandr_change_backlight (MetaOutput *output,
int value);
......
......@@ -1456,6 +1456,8 @@ find_highest_logical_monitor_scale (MetaBackend *backend,
GList *l;
float highest_scale = 0.0;
return 1;
cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
cursor_sprite);
......
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