mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
monitor-manager/kms: Move scale calculation to MetaMonitor
The scale calculation doesn't really have anything to do with KMS, and eventually we'll want to have mutter calculate the monitor scale for non-KMS backends too, so move the scale calculation to MetaMonitor. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
parent
0bc312a54b
commit
3b097c7e77
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "backends/meta-backend-private.h"
|
#include "backends/meta-backend-private.h"
|
||||||
#include "backends/meta-monitor-manager-private.h"
|
#include "backends/meta-monitor-manager-private.h"
|
||||||
|
#include "backends/meta-settings-private.h"
|
||||||
|
|
||||||
typedef struct _MetaMonitorMode
|
typedef struct _MetaMonitorMode
|
||||||
{
|
{
|
||||||
@ -976,6 +977,94 @@ meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
|
|||||||
out_y);
|
out_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The minimum resolution at which we turn on a window-scale of 2 */
|
||||||
|
#define HIDPI_LIMIT 192
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The minimum screen height at which we turn on a window-scale of 2;
|
||||||
|
* below this there just isn't enough vertical real estate for GNOME
|
||||||
|
* apps to work, and it's better to just be tiny
|
||||||
|
*/
|
||||||
|
#define HIDPI_MIN_HEIGHT 1200
|
||||||
|
|
||||||
|
/* From http://en.wikipedia.org/wiki/4K_resolution#Resolutions_of_common_formats */
|
||||||
|
#define SMALLEST_4K_WIDTH 3656
|
||||||
|
|
||||||
|
static int
|
||||||
|
calculate_scale (MetaMonitor *monitor,
|
||||||
|
MetaMonitorMode *monitor_mode)
|
||||||
|
{
|
||||||
|
int resolution_width, resolution_height;
|
||||||
|
int width_mm, height_mm;
|
||||||
|
int scale;
|
||||||
|
|
||||||
|
scale = 1;
|
||||||
|
|
||||||
|
meta_monitor_mode_get_resolution (monitor_mode,
|
||||||
|
&resolution_width,
|
||||||
|
&resolution_height);
|
||||||
|
|
||||||
|
if (resolution_height < HIDPI_MIN_HEIGHT)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* 4K TV */
|
||||||
|
switch (meta_monitor_get_connector_type (monitor))
|
||||||
|
{
|
||||||
|
case META_CONNECTOR_TYPE_HDMIA:
|
||||||
|
case META_CONNECTOR_TYPE_HDMIB:
|
||||||
|
if (resolution_width >= SMALLEST_4K_WIDTH)
|
||||||
|
goto out;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Somebody encoded the aspect ratio (16/9 or 16/10) instead of the physical
|
||||||
|
* size.
|
||||||
|
*/
|
||||||
|
if ((width_mm == 160 && height_mm == 90) ||
|
||||||
|
(width_mm == 160 && height_mm == 100) ||
|
||||||
|
(width_mm == 16 && height_mm == 9) ||
|
||||||
|
(width_mm == 16 && height_mm == 10))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (width_mm > 0 && height_mm > 0)
|
||||||
|
{
|
||||||
|
double dpi_x, dpi_y;
|
||||||
|
|
||||||
|
dpi_x = (double) resolution_width / (width_mm / 25.4);
|
||||||
|
dpi_y = (double) resolution_height / (height_mm / 25.4);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We don't completely trust these values so both must be high, and never
|
||||||
|
* pick higher ratio than 2 automatically.
|
||||||
|
*/
|
||||||
|
if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
|
||||||
|
scale = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
|
||||||
|
MetaMonitorMode *monitor_mode)
|
||||||
|
{
|
||||||
|
MetaBackend *backend = meta_get_backend ();
|
||||||
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
||||||
|
int global_scaling_factor;
|
||||||
|
|
||||||
|
if (meta_settings_get_global_scaling_factor (settings,
|
||||||
|
&global_scaling_factor))
|
||||||
|
return global_scaling_factor;
|
||||||
|
|
||||||
|
return calculate_scale (monitor, monitor_mode);
|
||||||
|
}
|
||||||
|
|
||||||
MetaMonitorModeSpec *
|
MetaMonitorModeSpec *
|
||||||
meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode)
|
meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode)
|
||||||
{
|
{
|
||||||
|
@ -156,6 +156,9 @@ void meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
|
|||||||
int *out_x,
|
int *out_x,
|
||||||
int *out_y);
|
int *out_y);
|
||||||
|
|
||||||
|
int meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
|
||||||
|
MetaMonitorMode *monitor_mode);
|
||||||
|
|
||||||
MetaMonitorModeSpec * meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode);
|
MetaMonitorModeSpec * meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode);
|
||||||
|
|
||||||
void meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode,
|
void meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode,
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "meta-monitor-config-manager.h"
|
#include "meta-monitor-config-manager.h"
|
||||||
#include "meta-backend-private.h"
|
#include "meta-backend-private.h"
|
||||||
#include "meta-renderer-native.h"
|
#include "meta-renderer-native.h"
|
||||||
#include "backends/meta-input-settings-private.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -1829,90 +1828,12 @@ meta_monitor_manager_kms_is_transform_handled (MetaMonitorManager *manager,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The minimum resolution at which we turn on a window-scale of 2 */
|
|
||||||
#define HIDPI_LIMIT 192
|
|
||||||
|
|
||||||
/* The minimum screen height at which we turn on a window-scale of 2;
|
|
||||||
* below this there just isn't enough vertical real estate for GNOME
|
|
||||||
* apps to work, and it's better to just be tiny */
|
|
||||||
#define HIDPI_MIN_HEIGHT 1200
|
|
||||||
|
|
||||||
/* From http://en.wikipedia.org/wiki/4K_resolution#Resolutions_of_common_formats */
|
|
||||||
#define SMALLEST_4K_WIDTH 3656
|
|
||||||
|
|
||||||
static int
|
|
||||||
compute_scale (MetaMonitor *monitor,
|
|
||||||
MetaMonitorMode *monitor_mode)
|
|
||||||
{
|
|
||||||
int resolution_width, resolution_height;
|
|
||||||
int width_mm, height_mm;
|
|
||||||
int scale;
|
|
||||||
|
|
||||||
scale = 1;
|
|
||||||
|
|
||||||
meta_monitor_mode_get_resolution (monitor_mode,
|
|
||||||
&resolution_width,
|
|
||||||
&resolution_height);
|
|
||||||
|
|
||||||
if (resolution_height < HIDPI_MIN_HEIGHT)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* 4K TV */
|
|
||||||
switch (meta_monitor_get_connector_type (monitor))
|
|
||||||
{
|
|
||||||
case META_CONNECTOR_TYPE_HDMIA:
|
|
||||||
case META_CONNECTOR_TYPE_HDMIB:
|
|
||||||
if (resolution_width >= SMALLEST_4K_WIDTH)
|
|
||||||
goto out;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Somebody encoded the aspect ratio (16/9 or 16/10) instead of the physical
|
|
||||||
* size.
|
|
||||||
*/
|
|
||||||
if ((width_mm == 160 && height_mm == 90) ||
|
|
||||||
(width_mm == 160 && height_mm == 100) ||
|
|
||||||
(width_mm == 16 && height_mm == 9) ||
|
|
||||||
(width_mm == 16 && height_mm == 10))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (width_mm > 0 && height_mm > 0)
|
|
||||||
{
|
|
||||||
double dpi_x, dpi_y;
|
|
||||||
|
|
||||||
dpi_x = (double) resolution_width / (width_mm / 25.4);
|
|
||||||
dpi_y = (double) resolution_height / (height_mm / 25.4);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We don't completely trust these values so both must be high, and never
|
|
||||||
* pick higher ratio than 2 automatically.
|
|
||||||
*/
|
|
||||||
if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
|
|
||||||
scale = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
return scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
meta_monitor_manager_kms_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
meta_monitor_manager_kms_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
||||||
MetaMonitor *monitor,
|
MetaMonitor *monitor,
|
||||||
MetaMonitorMode *monitor_mode)
|
MetaMonitorMode *monitor_mode)
|
||||||
{
|
{
|
||||||
MetaBackend *backend = meta_get_backend ();
|
return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
|
||||||
MetaSettings *settings = meta_backend_get_settings (backend);
|
|
||||||
int global_scale;
|
|
||||||
|
|
||||||
if (meta_settings_get_global_scaling_factor (settings, &global_scale))
|
|
||||||
return global_scale;
|
|
||||||
else
|
|
||||||
return compute_scale (monitor, monitor_mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user