monitor-config: Handle fractional scale precision loss

When calculating sizes given some size and a fractional logical monitor
scale with precision loss, round the result of the floating point
calculation to the closest integer, as otherwise we might end up with
result smaller by 1 if there was a loss of precision when calculating
the scale.

https://bugzilla.gnome.org/show_bug.cgi?id=765011
This commit is contained in:
Jonas Ådahl 2017-06-09 15:51:14 +08:00
parent 197401fbf8
commit 41eea5a942
3 changed files with 8 additions and 6 deletions

View File

@ -981,8 +981,10 @@ meta_verify_logical_monitor_config (MetaLogicalMonitorConfig *logical_monitor
switch (layout_mode)
{
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
expected_mode_width *= logical_monitor_config->scale;
expected_mode_height *= logical_monitor_config->scale;
expected_mode_width = roundf (expected_mode_width *
logical_monitor_config->scale);
expected_mode_height = roundf (expected_mode_height *
logical_monitor_config->scale);
break;
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
break;

View File

@ -453,8 +453,8 @@ derive_logical_monitor_layout (MetaLogicalMonitorConfig *logical_monitor_conf
switch (layout_mode)
{
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
width /= logical_monitor_config->scale;
height /= logical_monitor_config->scale;
width = roundf (width / logical_monitor_config->scale);
height = roundf (height / logical_monitor_config->scale);
break;
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
break;

View File

@ -1968,8 +1968,8 @@ derive_logical_monitor_size (MetaMonitorConfig *monitor_config,
switch (layout_mode)
{
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
width /= scale;
height /= scale;
width = roundf (width / scale);
height = roundf (height / scale);
break;
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
break;