logical-monitor: Make scale a float

To support fractional scaling, the logical monitor scale must be stored
as a float. No other functional changes is part of this commit.

https://bugzilla.gnome.org/show_bug.cgi?id=765011
This commit is contained in:
Jonas Ådahl 2017-05-25 16:12:51 +08:00
parent c2e49f1bb5
commit b64c69e4bc
21 changed files with 95 additions and 66 deletions

View File

@ -107,7 +107,7 @@ MetaLogicalMonitor *
meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
MetaRectangle *layout,
int scale,
float scale,
int monitor_number)
{
MetaLogicalMonitor *logical_monitor;
@ -175,7 +175,7 @@ meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor)
logical_monitor->is_primary = TRUE;
}
int
float
meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor)
{
return logical_monitor->scale;

View File

@ -40,7 +40,7 @@ struct _MetaLogicalMonitor
gboolean is_primary;
gboolean is_presentation; /* XXX: not yet used */
gboolean in_fullscreen;
int scale;
float scale;
MetaMonitorTransform transform;
/* The primary or first output for this monitor, 0 if we can't figure out.
@ -68,7 +68,7 @@ MetaLogicalMonitor * meta_logical_monitor_new (MetaMonitorManager *monitor
MetaLogicalMonitor * meta_logical_monitor_new_derived (MetaMonitorManager *monitor_manager,
MetaMonitor *monitor,
MetaRectangle *layout,
int scale,
float scale,
int monitor_number);
void meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
@ -78,7 +78,7 @@ gboolean meta_logical_monitor_is_primary (MetaLogicalMonitor *logical_monitor);
void meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor);
int meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor);
float meta_logical_monitor_get_scale (MetaLogicalMonitor *logical_monitor);
GList * meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor);

View File

@ -488,7 +488,7 @@ create_preferred_logical_monitor_config (MetaMonitorManager *monitor_ma
{
MetaMonitorMode *mode;
int width, height;
int scale;
float scale;
MetaMonitorConfig *monitor_config;
MetaLogicalMonitorConfig *logical_monitor_config;
@ -949,10 +949,10 @@ meta_verify_logical_monitor_config (MetaLogicalMonitorConfig *logical_monitor
int expected_mode_width = 0;
int expected_mode_height = 0;
if (logical_monitor_config->scale < 1)
if (logical_monitor_config->scale < 1.0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid logical monitor config scale %d",
"Invalid logical monitor config scale %g",
logical_monitor_config->scale);
return FALSE;
}

View File

@ -41,7 +41,7 @@ typedef struct _MetaLogicalMonitorConfig
MetaRectangle layout;
GList *monitor_configs;
MetaMonitorTransform transform;
int scale;
float scale;
gboolean is_primary;
gboolean is_presentation;
} MetaLogicalMonitorConfig;

View File

@ -828,14 +828,14 @@ handle_text (GMarkupParseContext *context,
case STATE_LOGICAL_MONITOR_SCALE:
{
if (!read_int (text, text_len,
&parser->current_logical_monitor_config->scale, error))
if (!read_float (text, text_len,
&parser->current_logical_monitor_config->scale, error))
return;
if (parser->current_logical_monitor_config->scale <= 0)
if (parser->current_logical_monitor_config->scale < 1.0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Logical monitor scale '%d' invalid",
"Logical monitor scale '%g' invalid",
parser->current_logical_monitor_config->scale);
return;
}
@ -1074,7 +1074,7 @@ append_logical_monitor_xml (GString *buffer,
logical_monitor_config->layout.x);
g_string_append_printf (buffer, " <y>%d</y>\n",
logical_monitor_config->layout.y);
g_string_append_printf (buffer, " <scale>%d</scale>\n",
g_string_append_printf (buffer, " <scale>%g</scale>\n",
logical_monitor_config->scale);
if (logical_monitor_config->is_primary)
g_string_append (buffer, " <primary>yes</primary>\n");

View File

@ -59,7 +59,7 @@ struct _MetaMonitorManagerDummyClass
typedef struct _MetaOutputDummy
{
int scale;
float scale;
} MetaOutputDummy;
G_DEFINE_TYPE (MetaMonitorManagerDummy, meta_monitor_manager_dummy, META_TYPE_MONITOR_MANAGER);
@ -74,7 +74,7 @@ static void
append_monitor (GArray *modes,
GArray *crtcs,
GArray *outputs,
int scale)
float scale)
{
MetaCrtcMode modes_decl[] = {
{
@ -242,11 +242,25 @@ meta_output_dummy_notify_destroy (MetaOutput *output)
g_clear_pointer (&output->driver_private, g_free);
}
static gboolean
is_scale_supported (float scale)
{
unsigned int i;
for (i = 0; i < G_N_ELEMENTS (supported_scales_dummy); i++)
{
if (scale == supported_scales_dummy[i])
return TRUE;
}
return FALSE;
}
static void
meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager)
{
unsigned int num_monitors = 1;
int *monitor_scales = NULL;
float *monitor_scales = NULL;
const char *num_monitors_str;
const char *monitor_scales_str;
const char *tiled_monitors_str;
@ -298,9 +312,9 @@ meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager)
}
}
monitor_scales = g_newa (int, num_monitors);
monitor_scales = g_newa (typeof (*monitor_scales), num_monitors);
for (i = 0; i < num_monitors; i++)
monitor_scales[i] = 1;
monitor_scales[i] = 1.0;
monitor_scales_str = getenv ("MUTTER_DEBUG_DUMMY_MONITOR_SCALES");
if (monitor_scales_str)
@ -313,11 +327,11 @@ meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager)
"of monitors (defaults to 1).\n");
for (i = 0; i < num_monitors && scales_str_list[i]; i++)
{
int scale = g_ascii_strtoll (scales_str_list[i], NULL, 10);
if (scale == 1 || scale == 2)
float scale = g_ascii_strtod (scales_str_list[i], NULL);
if (is_scale_supported (scale))
monitor_scales[i] = scale;
else
meta_warning ("Invalid dummy monitor scale");
meta_warning ("Invalid dummy monitor scale\n");
}
g_strfreev (scales_str_list);
}
@ -592,7 +606,7 @@ meta_monitor_manager_dummy_is_transform_handled (MetaMonitorManager *manager,
return manager_dummy->is_transform_handled;
}
static int
static float
meta_monitor_manager_dummy_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)

View File

@ -390,9 +390,9 @@ struct _MetaMonitorManagerClass
MetaCrtc *,
MetaMonitorTransform);
int (*calculate_monitor_mode_scale) (MetaMonitorManager *,
MetaMonitor *,
MetaMonitorMode *);
float (*calculate_monitor_mode_scale) (MetaMonitorManager *,
MetaMonitor *,
MetaMonitorMode *);
void (*get_supported_scales) (MetaMonitorManager *,
float **,
@ -504,7 +504,7 @@ void meta_monitor_manager_lid_is_closed_changed (MetaMonitorManage
gboolean meta_monitor_manager_is_headless (MetaMonitorManager *manager);
int meta_monitor_manager_calculate_monitor_mode_scale (MetaMonitorManager *manager,
float meta_monitor_manager_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode);

View File

@ -184,7 +184,7 @@ derive_monitor_layout (MetaMonitor *monitor,
meta_monitor_derive_dimensions (monitor, &layout->width, &layout->height);
}
static int
static float
derive_configured_global_scale (MetaMonitorManager *manager)
{
MetaMonitorsConfig *config;
@ -192,14 +192,14 @@ derive_configured_global_scale (MetaMonitorManager *manager)
config = meta_monitor_config_manager_get_current (manager->config_manager);
if (!config)
return 1;
return 1.0;
logical_monitor_config = config->logical_monitor_configs->data;
return logical_monitor_config->scale;
}
static int
static float
calculate_monitor_scale (MetaMonitorManager *manager,
MetaMonitor *monitor)
{
@ -211,19 +211,19 @@ calculate_monitor_scale (MetaMonitorManager *manager,
monitor_mode);
}
static int
static float
derive_calculated_global_scale (MetaMonitorManager *manager)
{
MetaMonitor *primary_monitor;
primary_monitor = meta_monitor_manager_get_primary_monitor (manager);
if (!primary_monitor)
return 1;
return 1.0;
return calculate_monitor_scale (manager, primary_monitor);
}
static int
static float
derive_scale_from_config (MetaMonitorManager *manager,
MetaRectangle *layout)
{
@ -240,7 +240,7 @@ derive_scale_from_config (MetaMonitorManager *manager,
}
g_warning ("Missing logical monitor, using scale 1");
return 1;
return 1.0;
}
static void
@ -253,7 +253,7 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager
MetaLogicalMonitor *primary_logical_monitor = NULL;
gboolean use_configured_scale;
gboolean use_global_scale;
int global_scale = 0;
float global_scale = 0.0;
MetaMonitorManagerCapability capabilities;
monitor_number = 0;
@ -291,7 +291,7 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager
}
else
{
int scale;
float scale;
if (use_global_scale)
scale = global_scale;
@ -393,7 +393,7 @@ meta_monitor_manager_is_headless (MetaMonitorManager *manager)
return !manager->monitors;
}
int
float
meta_monitor_manager_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)
@ -1894,6 +1894,14 @@ derive_logical_monitor_size (GList *monitor_configs,
switch (layout_mode)
{
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
if (fmodf (width, scale) != 0.0 || fmodf (height, scale) != 0.0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Scale %g not valid for resolution %dx%d",
scale, width, height);
return FALSE;
}
width /= scale;
height /= scale;
break;
@ -1967,7 +1975,7 @@ create_logical_monitor_config_from_variant (MetaMonitorManager *manager
.height = height
},
.transform = transform,
.scale = (int) scale,
.scale = scale,
.is_primary = is_primary,
.monitor_configs = monitor_configs
};

View File

@ -1261,7 +1261,7 @@ meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
/* From http://en.wikipedia.org/wiki/4K_resolution#Resolutions_of_common_formats */
#define SMALLEST_4K_WIDTH 3656
static int
static float
calculate_scale (MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)
{
@ -1269,7 +1269,7 @@ calculate_scale (MetaMonitor *monitor,
int width_mm, height_mm;
int scale;
scale = 1;
scale = 1.0;
meta_monitor_mode_get_resolution (monitor_mode,
&resolution_width,
@ -1314,14 +1314,14 @@ calculate_scale (MetaMonitor *monitor,
* pick higher ratio than 2 automatically.
*/
if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
scale = 2;
scale = 2.0;
}
out:
return scale;
}
int
float
meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)
{

View File

@ -160,8 +160,8 @@ void meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
int *out_x,
int *out_y);
int meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
MetaMonitorMode *monitor_mode);
float meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
MetaMonitorMode *monitor_mode);
MetaMonitorModeSpec * meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode);

View File

@ -69,7 +69,7 @@ calculate_ui_scaling_factor (MetaSettings *settings)
meta_backend_get_monitor_manager (settings->backend);
GList *logical_monitors;
GList *l;
int max_scale = 1;
float max_scale = 1.0;
logical_monitors =
meta_monitor_manager_get_logical_monitors (monitor_manager);
@ -81,7 +81,9 @@ calculate_ui_scaling_factor (MetaSettings *settings)
max_scale);
}
return max_scale;
g_warn_if_fail (fmodf (max_scale, 1.0) == 0.0);
return (int) max_scale;
}
static int

View File

@ -239,13 +239,13 @@ update_monitor_crtc_cursor (MetaMonitor *monitor,
MetaCursorRendererNativePrivate *priv =
meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
MetaRectangle scaled_crtc_rect;
int scale;
float scale;
int crtc_x, crtc_y;
if (meta_is_stage_views_scaled ())
scale = meta_logical_monitor_get_scale (data->in_logical_monitor);
else
scale = 1;
scale = 1.0;
meta_monitor_calculate_crtc_pos (monitor, monitor_mode,
monitor_crtc_mode->output,

View File

@ -1838,7 +1838,7 @@ meta_monitor_manager_kms_is_transform_handled (MetaMonitorManager *manager,
return FALSE;
}
static int
static float
meta_monitor_manager_kms_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)

View File

@ -1707,7 +1707,7 @@ meta_renderer_native_create_view (MetaRenderer *renderer,
MetaMonitorTransform view_transform;
CoglOnscreen *onscreen = NULL;
CoglOffscreen *offscreen = NULL;
int scale;
float scale;
int width, height;
MetaRendererView *view;
GError *error = NULL;
@ -1715,9 +1715,9 @@ meta_renderer_native_create_view (MetaRenderer *renderer,
view_transform = calculate_view_transform (monitor_manager, logical_monitor);
if (meta_is_stage_views_scaled ())
scale = logical_monitor->scale;
scale = meta_logical_monitor_get_scale (logical_monitor);
else
scale = 1;
scale = 1.0;
width = logical_monitor->rect.width * scale;
height = logical_monitor->rect.height * scale;
@ -1743,7 +1743,7 @@ meta_renderer_native_create_view (MetaRenderer *renderer,
view = g_object_new (META_TYPE_RENDERER_VIEW,
"layout", &logical_monitor->rect,
"scale", (float) scale,
"scale", scale,
"framebuffer", onscreen,
"offscreen", offscreen,
"logical-monitor", logical_monitor,

View File

@ -1791,7 +1791,7 @@ meta_monitor_manager_xrandr_is_transform_handled (MetaMonitorManager *manager,
return TRUE;
}
static int
static float
meta_monitor_manager_xrandr_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)

View File

@ -173,7 +173,7 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
MetaMonitorTransform view_transform;
int view_scale;
float view_scale;
int width, height;
CoglOffscreen *fake_onscreen;
CoglOffscreen *offscreen;
@ -183,7 +183,7 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
if (meta_is_stage_views_scaled ())
view_scale = logical_monitor->scale;
else
view_scale = 1;
view_scale = 1.0;
if (meta_monitor_transform_is_rotated (view_transform))
{
@ -210,7 +210,7 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
"framebuffer", COGL_FRAMEBUFFER (fake_onscreen),
"offscreen", COGL_FRAMEBUFFER (offscreen),
"transform", view_transform,
"scale", (float) view_scale,
"scale", view_scale,
"logical-monitor", logical_monitor,
NULL);
}

View File

@ -400,7 +400,7 @@ meta_monitor_manager_test_is_transform_handled (MetaMonitorManager *manager,
return manager_test->handles_transforms;
}
static int
static float
meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)

View File

@ -34,7 +34,7 @@ typedef struct _MetaMonitorTestSetup
typedef struct _MetaOutputTest
{
int scale;
float scale;
} MetaOutputTest;
#define META_TYPE_MONITOR_MANAGER_TEST (meta_monitor_manager_test_get_type ())

View File

@ -205,7 +205,7 @@ send_output_events (struct wl_resource *resource,
{
int scale;
scale = meta_logical_monitor_get_scale (logical_monitor);
scale = (int) meta_logical_monitor_get_scale (logical_monitor);
if (need_all_events ||
old_scale != scale)
{
@ -273,7 +273,7 @@ meta_wayland_output_set_logical_monitor (MetaWaylandOutput *wayland_output,
if (current_mode == preferred_mode)
wayland_output->mode_flags |= WL_OUTPUT_MODE_PREFERRED;
wayland_output->scale = meta_logical_monitor_get_scale (logical_monitor);
wayland_output->scale = (int) meta_logical_monitor_get_scale (logical_monitor);
wayland_output->refresh_rate = meta_monitor_mode_get_refresh_rate (current_mode);
}

View File

@ -104,7 +104,7 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
const MetaLogicalMonitor *logical_monitor;
MetaLogicalMonitor *logical_monitor;
logical_monitor =
meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
@ -115,7 +115,8 @@ cursor_sprite_prepare_at (MetaCursorSprite *cursor_sprite,
if (meta_is_stage_views_scaled ())
texture_scale = 1.0 / surface->scale;
else
texture_scale = (float) logical_monitor->scale / surface->scale;
texture_scale = (meta_logical_monitor_get_scale (logical_monitor) /
surface->scale);
meta_cursor_sprite_set_texture_scale (cursor_sprite, texture_scale);
}

View File

@ -70,7 +70,7 @@ get_window_geometry_scale_for_logical_monitor (MetaLogicalMonitor *logical_monit
if (meta_is_stage_views_scaled ())
return 1;
else
return logical_monitor->scale;
return meta_logical_monitor_get_scale (logical_monitor);
}
static void
@ -359,6 +359,7 @@ meta_window_wayland_update_main_monitor (MetaWindow *window)
MetaLogicalMonitor *from;
MetaLogicalMonitor *to;
MetaLogicalMonitor *scaled_new;
float from_scale, to_scale;
float scale;
MetaRectangle rect;
@ -383,9 +384,12 @@ meta_window_wayland_update_main_monitor (MetaWindow *window)
if (from == to)
return;
from_scale = meta_logical_monitor_get_scale (from);
to_scale = meta_logical_monitor_get_scale (to);
/* If we are setting the first output, unsetting the output, or the new has
* the same scale as the old no need to do any further checking. */
if (from == NULL || to == NULL || from->scale == to->scale)
if (from == NULL || to == NULL || from_scale == to_scale)
{
window->monitor = to;
return;
@ -400,7 +404,7 @@ meta_window_wayland_update_main_monitor (MetaWindow *window)
/* To avoid a window alternating between two main monitors because scaling
* changes the main monitor, wait until both the current and the new scale
* will result in the same main monitor. */
scale = (float)to->scale / from->scale;
scale = to_scale / from_scale;
rect = window->rect;
scale_rect_size (&rect, scale);
scaled_new =