2016-12-13 02:53:38 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Red Hat
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/meta-monitor.h"
|
|
|
|
|
2016-12-13 10:58:22 +00:00
|
|
|
#include "backends/meta-backend-private.h"
|
2017-03-28 04:35:19 +00:00
|
|
|
#include "backends/meta-crtc.h"
|
2017-07-10 10:19:32 +00:00
|
|
|
#include "backends/meta-gpu.h"
|
2016-12-13 02:53:38 +00:00
|
|
|
#include "backends/meta-monitor-manager-private.h"
|
2017-04-21 09:28:22 +00:00
|
|
|
#include "backends/meta-settings-private.h"
|
2017-03-24 09:35:51 +00:00
|
|
|
#include "backends/meta-output.h"
|
2020-01-14 21:34:44 +00:00
|
|
|
#include "core/boxes-private.h"
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2017-08-09 16:41:13 +00:00
|
|
|
#define SCALE_FACTORS_PER_INTEGER 4
|
2017-06-09 03:18:14 +00:00
|
|
|
#define SCALE_FACTORS_STEPS (1.0 / (float) SCALE_FACTORS_PER_INTEGER)
|
2017-08-09 16:41:13 +00:00
|
|
|
#define MINIMUM_SCALE_FACTOR 1.0f
|
2017-06-06 03:27:58 +00:00
|
|
|
#define MAXIMUM_SCALE_FACTOR 4.0f
|
2019-08-12 08:52:48 +00:00
|
|
|
#define MINIMUM_LOGICAL_AREA (800 * 480)
|
2017-09-14 10:42:47 +00:00
|
|
|
#define MAXIMUM_REFRESH_RATE_DIFF 0.001
|
2017-06-06 03:27:58 +00:00
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
typedef struct _MetaMonitorMode
|
|
|
|
{
|
2019-08-12 08:54:18 +00:00
|
|
|
MetaMonitor *monitor;
|
2017-06-14 04:04:09 +00:00
|
|
|
char *id;
|
2016-12-17 14:29:33 +00:00
|
|
|
MetaMonitorModeSpec spec;
|
2016-12-14 09:22:07 +00:00
|
|
|
MetaMonitorCrtcMode *crtc_modes;
|
|
|
|
} MetaMonitorMode;
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
typedef struct _MetaMonitorModeTiled
|
|
|
|
{
|
|
|
|
MetaMonitorMode parent;
|
|
|
|
|
|
|
|
gboolean is_tiled;
|
|
|
|
} MetaMonitorModeTiled;
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
typedef struct _MetaMonitorPrivate
|
|
|
|
{
|
2021-01-26 13:49:25 +00:00
|
|
|
MetaBackend *backend;
|
2017-05-11 09:24:53 +00:00
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
GList *outputs;
|
2016-12-14 09:22:07 +00:00
|
|
|
GList *modes;
|
2017-06-14 04:04:09 +00:00
|
|
|
GHashTable *mode_ids;
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2016-12-17 14:32:05 +00:00
|
|
|
MetaMonitorMode *preferred_mode;
|
2016-12-22 07:22:13 +00:00
|
|
|
MetaMonitorMode *current_mode;
|
2016-12-17 14:32:05 +00:00
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitorSpec *spec;
|
|
|
|
|
2020-01-16 09:10:42 +00:00
|
|
|
MetaLogicalMonitor *logical_monitor;
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
/*
|
|
|
|
* The primary or first output for this monitor, 0 if we can't figure out.
|
|
|
|
* It can be matched to a winsys_id of a MetaOutput.
|
|
|
|
*
|
|
|
|
* This is used as an opaque token on reconfiguration when switching from
|
2020-08-26 09:49:50 +00:00
|
|
|
* clone to extended, to decide on what output the windows should go next
|
2016-12-13 02:53:38 +00:00
|
|
|
* (it's an attempt to keep windows on the same monitor, and preferably on
|
|
|
|
* the primary one).
|
|
|
|
*/
|
2018-10-17 14:55:18 +00:00
|
|
|
uint64_t winsys_id;
|
2019-06-26 09:24:19 +00:00
|
|
|
|
|
|
|
char *display_name;
|
2016-12-13 02:53:38 +00:00
|
|
|
} MetaMonitorPrivate;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (MetaMonitor, meta_monitor, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
struct _MetaMonitorNormal
|
|
|
|
{
|
|
|
|
MetaMonitor parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorNormal, meta_monitor_normal, META_TYPE_MONITOR)
|
|
|
|
|
|
|
|
struct _MetaMonitorTiled
|
|
|
|
{
|
|
|
|
MetaMonitor parent;
|
|
|
|
|
2019-01-11 14:35:42 +00:00
|
|
|
MetaMonitorManager *monitor_manager;
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
uint32_t tile_group_id;
|
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
/* The tile (0, 0) output. */
|
|
|
|
MetaOutput *origin_output;
|
|
|
|
|
|
|
|
/* The output enabled even when a non-tiled mode is used. */
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaOutput *main_output;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorTiled, meta_monitor_tiled, META_TYPE_MONITOR)
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_mode_free (MetaMonitorMode *mode);
|
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitorSpec *
|
|
|
|
meta_monitor_spec_clone (MetaMonitorSpec *monitor_spec)
|
|
|
|
{
|
|
|
|
MetaMonitorSpec *new_monitor_spec;
|
|
|
|
|
|
|
|
new_monitor_spec = g_new0 (MetaMonitorSpec, 1);
|
|
|
|
*new_monitor_spec = (MetaMonitorSpec) {
|
|
|
|
.connector = g_strdup (monitor_spec->connector),
|
|
|
|
.vendor = g_strdup (monitor_spec->vendor),
|
|
|
|
.product = g_strdup (monitor_spec->product),
|
|
|
|
.serial = g_strdup (monitor_spec->serial),
|
|
|
|
};
|
|
|
|
|
|
|
|
return new_monitor_spec;
|
|
|
|
}
|
|
|
|
|
2021-02-05 16:21:55 +00:00
|
|
|
guint
|
|
|
|
meta_monitor_spec_hash (gconstpointer key)
|
|
|
|
{
|
|
|
|
const MetaMonitorSpec *monitor_spec = key;
|
|
|
|
|
|
|
|
return (g_str_hash (monitor_spec->connector) +
|
|
|
|
g_str_hash (monitor_spec->vendor) +
|
|
|
|
g_str_hash (monitor_spec->product) +
|
|
|
|
g_str_hash (monitor_spec->serial));
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_spec_equals (MetaMonitorSpec *monitor_spec,
|
|
|
|
MetaMonitorSpec *other_monitor_spec)
|
|
|
|
{
|
|
|
|
return (g_str_equal (monitor_spec->connector, other_monitor_spec->connector) &&
|
|
|
|
g_str_equal (monitor_spec->vendor, other_monitor_spec->vendor) &&
|
|
|
|
g_str_equal (monitor_spec->product, other_monitor_spec->product) &&
|
|
|
|
g_str_equal (monitor_spec->serial, other_monitor_spec->serial));
|
|
|
|
}
|
|
|
|
|
2017-01-12 08:13:48 +00:00
|
|
|
int
|
|
|
|
meta_monitor_spec_compare (MetaMonitorSpec *monitor_spec_a,
|
|
|
|
MetaMonitorSpec *monitor_spec_b)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = strcmp (monitor_spec_a->connector, monitor_spec_b->connector);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = strcmp (monitor_spec_a->vendor, monitor_spec_b->vendor);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = strcmp (monitor_spec_a->product, monitor_spec_b->product);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return strcmp (monitor_spec_a->serial, monitor_spec_b->serial);
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
void
|
|
|
|
meta_monitor_spec_free (MetaMonitorSpec *monitor_spec)
|
|
|
|
{
|
|
|
|
g_free (monitor_spec->connector);
|
|
|
|
g_free (monitor_spec->vendor);
|
|
|
|
g_free (monitor_spec->product);
|
|
|
|
g_free (monitor_spec->serial);
|
|
|
|
g_free (monitor_spec);
|
|
|
|
}
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
static const MetaOutputInfo *
|
|
|
|
meta_monitor_get_main_output_info (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
|
|
|
return meta_output_get_info (output);
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
static void
|
2017-04-28 07:31:03 +00:00
|
|
|
meta_monitor_generate_spec (MetaMonitor *monitor)
|
2016-12-17 14:34:26 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitorSpec *monitor_spec;
|
2021-10-28 13:25:58 +00:00
|
|
|
const char *vendor;
|
|
|
|
const char *product;
|
|
|
|
const char *serial;
|
|
|
|
|
|
|
|
vendor = output_info->vendor;
|
|
|
|
product = output_info->product;
|
|
|
|
serial = output_info->serial;
|
2016-12-17 14:34:26 +00:00
|
|
|
|
|
|
|
monitor_spec = g_new0 (MetaMonitorSpec, 1);
|
|
|
|
*monitor_spec = (MetaMonitorSpec) {
|
2020-02-26 08:45:07 +00:00
|
|
|
.connector = g_strdup (output_info->name),
|
2021-10-28 13:25:58 +00:00
|
|
|
.vendor = g_strdup (vendor ? vendor : "unknown"),
|
|
|
|
.product = g_strdup (product ? product : "unknown"),
|
|
|
|
.serial = g_strdup (serial ? serial : "unknown"),
|
2016-12-17 14:34:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
priv->spec = monitor_spec;
|
|
|
|
}
|
|
|
|
|
2019-06-26 09:24:19 +00:00
|
|
|
static const double known_diagonals[] = {
|
|
|
|
12.1,
|
|
|
|
13.3,
|
|
|
|
15.6
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *
|
|
|
|
diagonal_to_str (double d)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++)
|
|
|
|
{
|
|
|
|
double delta;
|
|
|
|
|
|
|
|
delta = fabs(known_diagonals[i] - d);
|
|
|
|
if (delta < 0.1)
|
|
|
|
return g_strdup_printf ("%0.1lf\"", known_diagonals[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_strdup_printf ("%d\"", (int) (d + 0.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2021-10-28 14:08:25 +00:00
|
|
|
meta_monitor_make_display_name (MetaMonitor *monitor)
|
2019-06-26 09:24:19 +00:00
|
|
|
{
|
2021-10-28 14:08:25 +00:00
|
|
|
MetaBackend *backend = meta_monitor_get_backend (monitor);
|
2019-06-26 09:24:19 +00:00
|
|
|
g_autofree char *inches = NULL;
|
|
|
|
g_autofree char *vendor_name = NULL;
|
|
|
|
const char *vendor = NULL;
|
|
|
|
const char *product_name = NULL;
|
|
|
|
int width_mm;
|
|
|
|
int height_mm;
|
|
|
|
|
|
|
|
meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
|
|
|
|
|
|
|
|
if (meta_monitor_is_laptop_panel (monitor))
|
|
|
|
return g_strdup (_("Built-in display"));
|
|
|
|
|
|
|
|
if (width_mm > 0 && height_mm > 0)
|
|
|
|
{
|
|
|
|
if (!meta_monitor_has_aspect_as_size (monitor))
|
|
|
|
{
|
|
|
|
double d = sqrt (width_mm * width_mm +
|
|
|
|
height_mm * height_mm);
|
|
|
|
inches = diagonal_to_str (d / 25.4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
product_name = meta_monitor_get_product (monitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vendor = meta_monitor_get_vendor (monitor);
|
2021-10-28 13:25:58 +00:00
|
|
|
if (vendor)
|
2019-06-26 09:24:19 +00:00
|
|
|
{
|
2021-10-28 14:08:25 +00:00
|
|
|
vendor_name = meta_backend_get_vendor_name (backend, vendor);
|
2019-06-26 09:24:19 +00:00
|
|
|
|
|
|
|
if (!vendor_name)
|
|
|
|
vendor_name = g_strdup (vendor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (inches != NULL)
|
|
|
|
vendor_name = g_strdup (_("Unknown"));
|
|
|
|
else
|
|
|
|
vendor_name = g_strdup (_("Unknown Display"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inches != NULL)
|
|
|
|
{
|
|
|
|
/**/
|
|
|
|
return g_strdup_printf (C_("This is a monitor vendor name, followed by a "
|
|
|
|
"size in inches, like 'Dell 15\"'",
|
|
|
|
"%s %s"),
|
|
|
|
vendor_name, inches);
|
|
|
|
}
|
|
|
|
else if (product_name != NULL)
|
|
|
|
{
|
|
|
|
return g_strdup_printf (C_("This is a monitor vendor name followed by "
|
|
|
|
"product/model name where size in inches "
|
|
|
|
"could not be calculated, e.g. Dell U2414H",
|
|
|
|
"%s %s"),
|
|
|
|
vendor_name, product_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return g_strdup (vendor_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 13:49:25 +00:00
|
|
|
MetaBackend *
|
|
|
|
meta_monitor_get_backend (MetaMonitor *monitor)
|
2017-07-24 09:16:38 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
2021-01-26 13:49:25 +00:00
|
|
|
return priv->backend;
|
2017-07-24 09:16:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
GList *
|
|
|
|
meta_monitor_get_outputs (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return priv->outputs;
|
|
|
|
}
|
|
|
|
|
2016-12-13 03:03:22 +00:00
|
|
|
MetaOutput *
|
2016-12-13 02:53:38 +00:00
|
|
|
meta_monitor_get_main_output (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
return META_MONITOR_GET_CLASS (monitor)->get_main_output (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_monitor_is_active (MetaMonitor *monitor)
|
|
|
|
{
|
monitor: Use current monitor mode to check whether active
For historical reasons meta_monitor_is_active() checked whether it is
active by checking whether the main output have a CRTC assigned and
whether that CRTC has a current mode. At a later point, the MetaMonitor
got its own mode abstraction (MetaMonitorMode), but
meta_monitor_is_active() was never updated to use this.
An issue with checking the main output's CRTC state is that, if there is
some CRTC mode combination that for some reason isn't properly detected
by the MetaMonitorMode abstraction (e.g. some tiling configuration not
yet handled), meta_monitor_is_active() would return TRUE, even though no
(abstracted) mode was set. This would cause confusion here and there,
leading to NULL pointer dereferences due to the assumption that if a
monitor is active, it has an active mode.
Instead, change meta_monitor_is_active() to directly check the current
monitor mode, and log a warning if the main output still happen to have
a CRTC with a mode assigned to it. This way, when an not undrestood CRTC
mode combination is encountered, instead of dereferencing NULL pointers,
simply assume the monitor is not active, which means that it will not be
managed or rendered by mutter at all.
https://gitlab.gnome.org/GNOME/mutter/issues/130
2018-07-31 11:18:51 +00:00
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
monitor: Use current monitor mode to check whether active
For historical reasons meta_monitor_is_active() checked whether it is
active by checking whether the main output have a CRTC assigned and
whether that CRTC has a current mode. At a later point, the MetaMonitor
got its own mode abstraction (MetaMonitorMode), but
meta_monitor_is_active() was never updated to use this.
An issue with checking the main output's CRTC state is that, if there is
some CRTC mode combination that for some reason isn't properly detected
by the MetaMonitorMode abstraction (e.g. some tiling configuration not
yet handled), meta_monitor_is_active() would return TRUE, even though no
(abstracted) mode was set. This would cause confusion here and there,
leading to NULL pointer dereferences due to the assumption that if a
monitor is active, it has an active mode.
Instead, change meta_monitor_is_active() to directly check the current
monitor mode, and log a warning if the main output still happen to have
a CRTC with a mode assigned to it. This way, when an not undrestood CRTC
mode combination is encountered, instead of dereferencing NULL pointers,
simply assume the monitor is not active, which means that it will not be
managed or rendered by mutter at all.
https://gitlab.gnome.org/GNOME/mutter/issues/130
2018-07-31 11:18:51 +00:00
|
|
|
return !!priv->current_mode;
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 03:03:22 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_is_primary (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
2020-02-25 17:37:21 +00:00
|
|
|
return meta_output_is_primary (output);
|
2016-12-13 03:03:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-23 09:59:43 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_supports_underscanning (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2017-01-23 09:59:43 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->supports_underscanning;
|
2017-01-23 09:59:43 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 10:42:36 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_supports_color_transform (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
|
|
|
|
|
|
|
return output_info->supports_color_transform;
|
|
|
|
}
|
|
|
|
|
2017-01-17 02:59:24 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_is_underscanning (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
2020-02-25 17:37:21 +00:00
|
|
|
return meta_output_is_underscanning (output);
|
2017-01-17 02:59:24 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 10:45:46 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_get_max_bpc (MetaMonitor *monitor,
|
|
|
|
unsigned int *max_bpc)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
|
|
|
return meta_output_get_max_bpc (output, max_bpc);
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:37:57 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_is_laptop_panel (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-17 14:37:57 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
switch (output_info->connector_type)
|
2016-12-17 14:37:57 +00:00
|
|
|
{
|
|
|
|
case META_CONNECTOR_TYPE_eDP:
|
|
|
|
case META_CONNECTOR_TYPE_LVDS:
|
|
|
|
case META_CONNECTOR_TYPE_DSI:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 20:57:31 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_is_virtual (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
|
|
|
|
|
|
|
return output_info->is_virtual;
|
|
|
|
}
|
|
|
|
|
2017-06-21 09:58:46 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_is_same_as (MetaMonitor *monitor,
|
|
|
|
MetaMonitor *other_monitor)
|
|
|
|
{
|
2021-10-28 13:27:49 +00:00
|
|
|
const MetaMonitorSpec *spec = meta_monitor_get_spec (monitor);
|
|
|
|
const MetaMonitorSpec *other_spec = meta_monitor_get_spec (other_monitor);
|
|
|
|
|
|
|
|
if ((g_strcmp0 (spec->vendor, "unknown") == 0 ||
|
|
|
|
g_strcmp0 (spec->product, "unknown") == 0 ||
|
|
|
|
g_strcmp0 (spec->serial, "unknown") == 0) &&
|
|
|
|
(g_strcmp0 (other_spec->vendor, "unknown") == 0 ||
|
|
|
|
g_strcmp0 (other_spec->product, "unknown") == 0 ||
|
|
|
|
g_strcmp0 (other_spec->serial, "unknown") == 0))
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaMonitorPrivate *other_priv =
|
|
|
|
meta_monitor_get_instance_private (other_monitor);
|
|
|
|
|
|
|
|
return priv->winsys_id == other_priv->winsys_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0 (spec->vendor, other_spec->vendor) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (g_strcmp0 (spec->product, other_spec->product) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (g_strcmp0 (spec->serial, other_spec->serial) != 0)
|
|
|
|
return FALSE;
|
2017-06-21 09:58:46 +00:00
|
|
|
|
2021-10-28 13:27:49 +00:00
|
|
|
return TRUE;
|
2017-06-21 09:58:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
void
|
2017-03-07 04:34:38 +00:00
|
|
|
meta_monitor_get_current_resolution (MetaMonitor *monitor,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
2017-03-07 04:34:38 +00:00
|
|
|
MetaMonitorMode *mode = meta_monitor_get_current_mode (monitor);
|
|
|
|
|
|
|
|
*width = mode->spec.width;
|
|
|
|
*height = mode->spec.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-12 07:42:20 +00:00
|
|
|
meta_monitor_derive_layout (MetaMonitor *monitor,
|
|
|
|
MetaRectangle *layout)
|
2017-03-07 04:34:38 +00:00
|
|
|
{
|
2017-07-12 07:42:20 +00:00
|
|
|
META_MONITOR_GET_CLASS (monitor)->derive_layout (monitor, layout);
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_monitor_get_physical_dimensions (MetaMonitor *monitor,
|
|
|
|
int *width_mm,
|
|
|
|
int *height_mm)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
*width_mm = output_info->width_mm;
|
|
|
|
*height_mm = output_info->height_mm;
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 07:16:48 +00:00
|
|
|
CoglSubpixelOrder
|
|
|
|
meta_monitor_get_subpixel_order (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-22 07:16:48 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->subpixel_order;
|
2016-12-22 07:16:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 05:14:43 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_connector (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2017-04-06 05:14:43 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->name;
|
2017-04-06 05:14:43 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 07:20:57 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_vendor (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-22 07:20:57 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->vendor;
|
2016-12-22 07:20:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 10:58:22 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_product (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-13 10:58:22 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->product;
|
2016-12-13 10:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 07:20:57 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_serial (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2016-12-22 07:20:57 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->serial;
|
2016-12-22 07:20:57 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:26:31 +00:00
|
|
|
const MetaEdidInfo *
|
|
|
|
meta_monitor_get_edid_info (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
|
|
|
|
|
|
|
return output_info->edid_info;
|
|
|
|
}
|
|
|
|
|
2021-10-26 09:27:56 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_edid_checksum_md5 (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
|
|
|
|
|
|
|
return output_info->edid_checksum_md5;
|
|
|
|
}
|
|
|
|
|
2017-01-20 07:07:12 +00:00
|
|
|
MetaConnectorType
|
|
|
|
meta_monitor_get_connector_type (MetaMonitor *monitor)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2017-01-20 07:07:12 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
return output_info->connector_type;
|
2017-01-20 07:07:12 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 10:43:58 +00:00
|
|
|
MetaMonitorTransform
|
|
|
|
meta_monitor_logical_to_crtc_transform (MetaMonitor *monitor,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
MetaOutput *output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
2020-01-14 21:21:38 +00:00
|
|
|
return meta_output_logical_to_crtc_transform (output, transform);
|
2017-10-24 10:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaMonitorTransform
|
|
|
|
meta_monitor_crtc_to_logical_transform (MetaMonitor *monitor,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
MetaOutput *output = meta_monitor_get_main_output (monitor);
|
|
|
|
|
2020-02-18 10:45:26 +00:00
|
|
|
return meta_output_crtc_to_logical_transform (output, transform);
|
2017-10-24 10:43:58 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (object);
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
if (priv->outputs)
|
|
|
|
{
|
2021-01-27 22:16:05 +00:00
|
|
|
g_list_foreach (priv->outputs, (GFunc) meta_output_unset_monitor, NULL);
|
2017-11-03 10:27:57 +00:00
|
|
|
g_list_free_full (priv->outputs, g_object_unref);
|
|
|
|
priv->outputs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (object);
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
g_hash_table_destroy (priv->mode_ids);
|
2016-12-14 09:22:07 +00:00
|
|
|
g_list_free_full (priv->modes, (GDestroyNotify) meta_monitor_mode_free);
|
2016-12-17 14:34:26 +00:00
|
|
|
meta_monitor_spec_free (priv->spec);
|
2019-06-26 09:24:19 +00:00
|
|
|
g_free (priv->display_name);
|
2017-09-11 03:12:03 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_parent_class)->finalize (object);
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_init (MetaMonitor *monitor)
|
|
|
|
{
|
2017-06-14 04:04:09 +00:00
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
priv->mode_ids = g_hash_table_new (g_str_hash, g_str_equal);
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_class_init (MetaMonitorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
object_class->dispose = meta_monitor_dispose;
|
2016-12-13 02:53:38 +00:00
|
|
|
object_class->finalize = meta_monitor_finalize;
|
|
|
|
}
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
static char *
|
|
|
|
generate_mode_id (MetaMonitorModeSpec *monitor_mode_spec)
|
|
|
|
{
|
2017-06-14 06:41:13 +00:00
|
|
|
gboolean is_interlaced;
|
2023-03-06 23:17:25 +00:00
|
|
|
char rate_str[G_ASCII_DTOSTR_BUF_SIZE];
|
2017-06-14 04:04:09 +00:00
|
|
|
|
2017-06-14 06:41:13 +00:00
|
|
|
is_interlaced = !!(monitor_mode_spec->flags & META_CRTC_MODE_FLAG_INTERLACE);
|
2023-03-06 23:17:25 +00:00
|
|
|
g_ascii_formatd (rate_str, sizeof (rate_str),
|
|
|
|
"%.3f", monitor_mode_spec->refresh_rate);
|
2017-06-14 04:04:09 +00:00
|
|
|
|
2023-03-06 23:17:25 +00:00
|
|
|
return g_strdup_printf ("%dx%d%s@%s",
|
2017-06-14 04:04:09 +00:00
|
|
|
monitor_mode_spec->width,
|
|
|
|
monitor_mode_spec->height,
|
2017-06-14 06:41:13 +00:00
|
|
|
is_interlaced ? "i" : "",
|
2023-03-06 23:17:25 +00:00
|
|
|
rate_str);
|
2017-06-14 04:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_monitor_add_mode (MetaMonitor *monitor,
|
2017-10-18 15:22:01 +00:00
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
gboolean replace)
|
2017-06-14 04:04:09 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
2017-10-18 15:22:01 +00:00
|
|
|
MetaMonitorMode *existing_mode;
|
2017-06-14 04:04:09 +00:00
|
|
|
|
2017-10-18 15:22:01 +00:00
|
|
|
existing_mode = g_hash_table_lookup (priv->mode_ids,
|
|
|
|
meta_monitor_mode_get_id (monitor_mode));
|
|
|
|
if (existing_mode && !replace)
|
2017-06-14 04:04:09 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-10-18 15:22:01 +00:00
|
|
|
if (existing_mode)
|
|
|
|
priv->modes = g_list_remove (priv->modes, existing_mode);
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
priv->modes = g_list_append (priv->modes, monitor_mode);
|
2017-10-18 15:22:01 +00:00
|
|
|
g_hash_table_replace (priv->mode_ids, monitor_mode->id, monitor_mode);
|
2017-06-14 04:04:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-24 10:43:58 +00:00
|
|
|
static MetaMonitorModeSpec
|
|
|
|
meta_monitor_create_spec (MetaMonitor *monitor,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
MetaCrtcMode *crtc_mode)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info =
|
|
|
|
meta_crtc_mode_get_info (crtc_mode);
|
2017-10-24 10:43:58 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (meta_monitor_transform_is_rotated (output_info->panel_orientation_transform))
|
2017-10-24 10:43:58 +00:00
|
|
|
{
|
|
|
|
int temp = width;
|
|
|
|
width = height;
|
|
|
|
height = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (MetaMonitorModeSpec) {
|
|
|
|
.width = width,
|
|
|
|
.height = height,
|
2020-02-26 23:08:58 +00:00
|
|
|
.refresh_rate = crtc_mode_info->refresh_rate,
|
|
|
|
.flags = crtc_mode_info->flags & HANDLED_CRTC_MODE_FLAGS
|
2017-10-24 10:43:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-26 09:45:17 +00:00
|
|
|
/**
|
|
|
|
* meta_monitor_get_gamma_lut_size:
|
|
|
|
* @monitor: The MetaMonitor instance to retrieve the size from.
|
|
|
|
*
|
|
|
|
* Get the size of the look-up tables (LUTs) for the monitor.
|
|
|
|
*
|
|
|
|
* Retrieve the size of the LUT used to implement the encoding or decoding
|
|
|
|
* transfer functions ("gamma", "degamma") for the CRTC or CRTCs that backs
|
|
|
|
* this monitor.
|
|
|
|
*
|
|
|
|
* Returns: The number of look-up table entries possible for the monitor. It is
|
|
|
|
* assumed that each CRTC of a monitor has identical gamma LUT sizes.
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
meta_monitor_get_gamma_lut_size (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
MetaCrtc *crtc;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2021-12-03 16:34:34 +00:00
|
|
|
return meta_crtc_get_gamma_lut_size (crtc);
|
2021-10-26 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 09:46:37 +00:00
|
|
|
static gboolean
|
|
|
|
set_gamma_lut (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode,
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
|
|
|
{
|
2021-12-03 16:34:34 +00:00
|
|
|
const MetaGammaLut *lut = user_data;
|
2021-10-26 09:46:37 +00:00
|
|
|
MetaCrtc *crtc;
|
|
|
|
|
|
|
|
crtc = meta_output_get_assigned_crtc (monitor_crtc_mode->output);
|
|
|
|
|
2021-12-03 16:34:34 +00:00
|
|
|
meta_crtc_set_gamma_lut (crtc, lut);
|
2021-10-26 09:46:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_monitor_set_gamma_lut:
|
|
|
|
*
|
|
|
|
* Set a new gamma look-up table (LUT) for the given monitor's CRTCs.
|
|
|
|
*/
|
|
|
|
void
|
2021-12-03 16:34:34 +00:00
|
|
|
meta_monitor_set_gamma_lut (MetaMonitor *monitor,
|
|
|
|
const MetaGammaLut *lut)
|
2021-10-26 09:46:37 +00:00
|
|
|
{
|
|
|
|
MetaMonitorMode *current_mode;
|
|
|
|
|
|
|
|
current_mode = meta_monitor_get_current_mode (monitor);
|
|
|
|
g_return_if_fail (current_mode);
|
|
|
|
|
|
|
|
meta_monitor_mode_foreach_crtc (monitor,
|
|
|
|
current_mode,
|
|
|
|
set_gamma_lut,
|
2021-12-03 16:34:34 +00:00
|
|
|
(gpointer) lut,
|
2021-10-26 09:46:37 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_normal_generate_modes (MetaMonitorNormal *monitor_normal)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_normal);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaOutput *output;
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info;
|
2020-02-26 23:08:58 +00:00
|
|
|
MetaCrtcMode *preferred_mode;
|
2017-10-18 15:22:01 +00:00
|
|
|
MetaCrtcModeFlag preferred_mode_flags;
|
2016-12-14 09:22:07 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
2020-02-26 08:45:07 +00:00
|
|
|
output_info = meta_output_get_info (output);
|
2020-02-26 23:08:58 +00:00
|
|
|
preferred_mode = output_info->preferred_mode;
|
|
|
|
preferred_mode_flags = meta_crtc_mode_get_info (preferred_mode)->flags;
|
2017-10-18 15:22:01 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
for (i = 0; i < output_info->n_modes; i++)
|
2016-12-14 09:22:07 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
MetaCrtcMode *crtc_mode = output_info->modes[i];
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info =
|
|
|
|
meta_crtc_mode_get_info (crtc_mode);
|
2017-11-03 10:25:30 +00:00
|
|
|
MetaCrtc *crtc;
|
2016-12-14 09:22:07 +00:00
|
|
|
MetaMonitorMode *mode;
|
2017-10-18 15:22:01 +00:00
|
|
|
gboolean replace;
|
2016-12-14 09:22:07 +00:00
|
|
|
|
|
|
|
mode = g_new0 (MetaMonitorMode, 1);
|
2019-08-12 08:54:18 +00:00
|
|
|
mode->monitor = monitor;
|
2017-10-24 10:43:58 +00:00
|
|
|
mode->spec = meta_monitor_create_spec (monitor,
|
2020-02-26 23:08:58 +00:00
|
|
|
crtc_mode_info->width,
|
|
|
|
crtc_mode_info->height,
|
2017-10-24 10:43:58 +00:00
|
|
|
crtc_mode);
|
2017-06-14 04:04:09 +00:00
|
|
|
mode->id = generate_mode_id (&mode->spec);
|
2016-12-14 09:22:07 +00:00
|
|
|
mode->crtc_modes = g_new (MetaMonitorCrtcMode, 1);
|
|
|
|
mode->crtc_modes[0] = (MetaMonitorCrtcMode) {
|
|
|
|
.output = output,
|
|
|
|
.crtc_mode = crtc_mode
|
|
|
|
};
|
|
|
|
|
2017-10-18 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* We don't distinguish between all available mode flags, just the ones
|
|
|
|
* that are configurable. We still need to pick some mode though, so
|
|
|
|
* prefer ones that has the same set of flags as the preferred mode;
|
|
|
|
* otherwise take the first one in the list. This guarantees that the
|
|
|
|
* preferred mode is always added.
|
|
|
|
*/
|
2020-02-26 23:08:58 +00:00
|
|
|
replace = crtc_mode_info->flags == preferred_mode_flags;
|
2017-10-18 15:22:01 +00:00
|
|
|
|
|
|
|
if (!meta_monitor_add_mode (monitor, mode, replace))
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
g_assert (crtc_mode != output_info->preferred_mode);
|
2017-10-18 15:22:01 +00:00
|
|
|
meta_monitor_mode_free (mode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (crtc_mode == output_info->preferred_mode)
|
2016-12-17 14:32:05 +00:00
|
|
|
monitor_priv->preferred_mode = mode;
|
2017-11-03 10:25:30 +00:00
|
|
|
|
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2020-02-26 09:37:53 +00:00
|
|
|
if (crtc)
|
|
|
|
{
|
|
|
|
const MetaCrtcConfig *crtc_config;
|
|
|
|
|
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
|
|
|
if (crtc_config && crtc_mode == crtc_config->mode)
|
|
|
|
monitor_priv->current_mode = mode;
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorNormal *
|
2021-01-26 13:49:25 +00:00
|
|
|
meta_monitor_normal_new (MetaMonitorManager *monitor_manager,
|
2019-06-26 09:24:19 +00:00
|
|
|
MetaOutput *output)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
|
|
|
MetaMonitorNormal *monitor_normal;
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitor *monitor;
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorPrivate *monitor_priv;
|
|
|
|
|
|
|
|
monitor_normal = g_object_new (META_TYPE_MONITOR_NORMAL, NULL);
|
2016-12-17 14:34:26 +00:00
|
|
|
monitor = META_MONITOR (monitor_normal);
|
|
|
|
monitor_priv = meta_monitor_get_instance_private (monitor);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2021-01-26 13:49:25 +00:00
|
|
|
monitor_priv->backend = meta_monitor_manager_get_backend (monitor_manager);
|
2017-05-11 09:24:53 +00:00
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
monitor_priv->outputs = g_list_append (NULL, g_object_ref (output));
|
2020-10-08 15:34:57 +00:00
|
|
|
meta_output_set_monitor (output, monitor);
|
|
|
|
|
2020-02-25 15:13:52 +00:00
|
|
|
monitor_priv->winsys_id = meta_output_get_id (output);
|
2017-04-28 07:34:27 +00:00
|
|
|
meta_monitor_generate_spec (monitor);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
meta_monitor_normal_generate_modes (monitor_normal);
|
|
|
|
|
2021-10-28 14:08:25 +00:00
|
|
|
monitor_priv->display_name = meta_monitor_make_display_name (monitor);
|
2019-06-26 09:24:19 +00:00
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
return monitor_normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaOutput *
|
|
|
|
meta_monitor_normal_get_main_output (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return monitor_priv->outputs->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-12 07:42:20 +00:00
|
|
|
meta_monitor_normal_derive_layout (MetaMonitor *monitor,
|
|
|
|
MetaRectangle *layout)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
|
|
|
MetaOutput *output;
|
2017-11-03 10:25:30 +00:00
|
|
|
MetaCrtc *crtc;
|
2020-02-26 09:37:53 +00:00
|
|
|
const MetaCrtcConfig *crtc_config;
|
2016-12-13 02:53:38 +00:00
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
2017-11-03 10:25:30 +00:00
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2020-02-26 09:37:53 +00:00
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
2020-01-14 21:34:44 +00:00
|
|
|
|
|
|
|
g_return_if_fail (crtc_config);
|
|
|
|
|
|
|
|
meta_rectangle_from_graphene_rect (&crtc_config->layout,
|
|
|
|
META_ROUNDING_STRATEGY_ROUND,
|
|
|
|
layout);
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 03:55:10 +00:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_normal_get_suggested_position (MetaMonitor *monitor,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info =
|
|
|
|
meta_monitor_get_main_output_info (monitor);
|
2017-05-01 03:55:10 +00:00
|
|
|
|
2020-02-26 15:44:28 +00:00
|
|
|
if (!output_info->hotplug_mode_update)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (output_info->suggested_x < 0 && output_info->suggested_y < 0)
|
2017-05-01 03:55:10 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-03-27 04:08:39 +00:00
|
|
|
if (x)
|
|
|
|
*x = output_info->suggested_x;
|
|
|
|
|
|
|
|
if (y)
|
|
|
|
*y = output_info->suggested_y;
|
2017-05-01 03:55:10 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
static void
|
2019-03-08 18:13:00 +00:00
|
|
|
meta_monitor_normal_calculate_crtc_pos (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaOutput *output,
|
|
|
|
MetaMonitorTransform crtc_transform,
|
|
|
|
int *out_x,
|
|
|
|
int *out_y)
|
2017-03-17 09:21:10 +00:00
|
|
|
{
|
|
|
|
*out_x = 0;
|
|
|
|
*out_y = 0;
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_normal_init (MetaMonitorNormal *monitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_normal_class_init (MetaMonitorNormalClass *klass)
|
|
|
|
{
|
|
|
|
MetaMonitorClass *monitor_class = META_MONITOR_CLASS (klass);
|
|
|
|
|
|
|
|
monitor_class->get_main_output = meta_monitor_normal_get_main_output;
|
2017-07-12 07:42:20 +00:00
|
|
|
monitor_class->derive_layout = meta_monitor_normal_derive_layout;
|
2017-03-17 09:21:10 +00:00
|
|
|
monitor_class->calculate_crtc_pos = meta_monitor_normal_calculate_crtc_pos;
|
2017-05-01 03:55:10 +00:00
|
|
|
monitor_class->get_suggested_position = meta_monitor_normal_get_suggested_position;
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 10:58:22 +00:00
|
|
|
uint32_t
|
|
|
|
meta_monitor_tiled_get_tile_group_id (MetaMonitorTiled *monitor_tiled)
|
|
|
|
{
|
|
|
|
return monitor_tiled->tile_group_id;
|
|
|
|
}
|
|
|
|
|
2017-01-09 07:35:03 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_get_suggested_position (MetaMonitor *monitor,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
2017-05-01 03:55:10 +00:00
|
|
|
return META_MONITOR_GET_CLASS (monitor)->get_suggested_position (monitor,
|
|
|
|
x, y);
|
2017-01-09 07:35:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
static void
|
2017-07-10 10:19:32 +00:00
|
|
|
add_tiled_monitor_outputs (MetaGpu *gpu,
|
|
|
|
MetaMonitorTiled *monitor_tiled)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (META_MONITOR (monitor_tiled));
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *outputs;
|
|
|
|
GList *l;
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
outputs = meta_gpu_get_outputs (gpu);
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = outputs; l; l = l->next)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
|
|
|
const MetaOutputInfo *origin_output_info;
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (output_info->tile_info.group_id != monitor_tiled->tile_group_id)
|
2016-12-13 02:53:38 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
origin_output_info = meta_output_get_info (monitor_tiled->origin_output);
|
|
|
|
g_warn_if_fail (output_info->subpixel_order ==
|
|
|
|
origin_output_info->subpixel_order);
|
2016-12-22 07:16:48 +00:00
|
|
|
|
2017-11-03 10:27:57 +00:00
|
|
|
monitor_priv->outputs = g_list_append (monitor_priv->outputs,
|
|
|
|
g_object_ref (output));
|
2020-10-08 15:34:57 +00:00
|
|
|
|
|
|
|
meta_output_set_monitor (output, META_MONITOR (monitor_tiled));
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
static void
|
2017-03-17 09:21:10 +00:00
|
|
|
calculate_tile_coordinate (MetaMonitor *monitor,
|
|
|
|
MetaOutput *output,
|
2017-03-21 06:17:18 +00:00
|
|
|
MetaMonitorTransform crtc_transform,
|
2017-03-17 09:21:10 +00:00
|
|
|
int *out_x,
|
|
|
|
int *out_y)
|
2016-12-14 09:22:07 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2016-12-14 09:22:07 +00:00
|
|
|
GList *l;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
for (l = monitor_priv->outputs; l; l = l->next)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *other_output_info = meta_output_get_info (l->data);
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2017-03-21 06:17:18 +00:00
|
|
|
switch (crtc_transform)
|
|
|
|
{
|
|
|
|
case META_MONITOR_TRANSFORM_NORMAL:
|
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED:
|
2020-02-26 08:45:07 +00:00
|
|
|
if ((other_output_info->tile_info.loc_v_tile ==
|
|
|
|
output_info->tile_info.loc_v_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_h_tile <
|
|
|
|
output_info->tile_info.loc_h_tile))
|
|
|
|
x += other_output_info->tile_info.tile_w;
|
|
|
|
if ((other_output_info->tile_info.loc_h_tile ==
|
|
|
|
output_info->tile_info.loc_h_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_v_tile <
|
|
|
|
output_info->tile_info.loc_v_tile))
|
|
|
|
y += other_output_info->tile_info.tile_h;
|
2017-03-21 06:17:18 +00:00
|
|
|
break;
|
|
|
|
case META_MONITOR_TRANSFORM_180:
|
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_180:
|
2020-02-26 08:45:07 +00:00
|
|
|
if ((other_output_info->tile_info.loc_v_tile ==
|
|
|
|
output_info->tile_info.loc_v_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_h_tile >
|
|
|
|
output_info->tile_info.loc_h_tile))
|
|
|
|
x += other_output_info->tile_info.tile_w;
|
|
|
|
if ((other_output_info->tile_info.loc_h_tile ==
|
|
|
|
output_info->tile_info.loc_h_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_v_tile >
|
|
|
|
output_info->tile_info.loc_v_tile))
|
|
|
|
y += other_output_info->tile_info.tile_h;
|
2017-03-21 06:17:18 +00:00
|
|
|
break;
|
|
|
|
case META_MONITOR_TRANSFORM_270:
|
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_270:
|
2020-02-26 08:45:07 +00:00
|
|
|
if ((other_output_info->tile_info.loc_v_tile ==
|
|
|
|
output_info->tile_info.loc_v_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_h_tile >
|
|
|
|
output_info->tile_info.loc_h_tile))
|
|
|
|
y += other_output_info->tile_info.tile_w;
|
|
|
|
if ((other_output_info->tile_info.loc_h_tile ==
|
|
|
|
output_info->tile_info.loc_h_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_v_tile >
|
|
|
|
output_info->tile_info.loc_v_tile))
|
|
|
|
x += other_output_info->tile_info.tile_h;
|
2017-03-21 06:17:18 +00:00
|
|
|
break;
|
|
|
|
case META_MONITOR_TRANSFORM_90:
|
|
|
|
case META_MONITOR_TRANSFORM_FLIPPED_90:
|
2020-02-26 08:45:07 +00:00
|
|
|
if ((other_output_info->tile_info.loc_v_tile ==
|
|
|
|
output_info->tile_info.loc_v_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_h_tile <
|
|
|
|
output_info->tile_info.loc_h_tile))
|
|
|
|
y += other_output_info->tile_info.tile_w;
|
|
|
|
if ((other_output_info->tile_info.loc_h_tile ==
|
|
|
|
output_info->tile_info.loc_h_tile) &&
|
|
|
|
(other_output_info->tile_info.loc_v_tile <
|
|
|
|
output_info->tile_info.loc_v_tile))
|
|
|
|
x += other_output_info->tile_info.tile_h;
|
2017-03-21 06:17:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_x = x;
|
|
|
|
*out_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_tiled_calculate_tiled_size (MetaMonitor *monitor,
|
|
|
|
int *out_width,
|
|
|
|
int *out_height)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
for (l = monitor_priv->outputs; l; l = l->next)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (l->data);
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (output_info->tile_info.loc_v_tile == 0)
|
|
|
|
width += output_info->tile_info.tile_w;
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
if (output_info->tile_info.loc_h_tile == 0)
|
|
|
|
height += output_info->tile_info.tile_h;
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_width = width;
|
|
|
|
*out_height = height;
|
|
|
|
}
|
|
|
|
|
2017-03-06 05:09:56 +00:00
|
|
|
static gboolean
|
|
|
|
is_monitor_mode_assigned (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (l = priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
|
2017-11-03 10:25:30 +00:00
|
|
|
MetaCrtc *crtc;
|
2020-02-26 09:37:53 +00:00
|
|
|
const MetaCrtcConfig *crtc_config;
|
2017-03-06 05:09:56 +00:00
|
|
|
|
2017-11-03 10:25:30 +00:00
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
2020-02-26 09:37:53 +00:00
|
|
|
crtc_config = crtc ? meta_crtc_get_config (crtc) : NULL;
|
|
|
|
|
2017-03-06 05:09:56 +00:00
|
|
|
if (monitor_crtc_mode->crtc_mode &&
|
2020-02-26 09:37:53 +00:00
|
|
|
(!crtc || !crtc_config ||
|
|
|
|
crtc_config->mode != monitor_crtc_mode->crtc_mode))
|
2017-03-06 05:09:56 +00:00
|
|
|
return FALSE;
|
2017-11-03 10:25:30 +00:00
|
|
|
else if (!monitor_crtc_mode->crtc_mode && crtc)
|
2017-03-06 05:09:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:36:51 +00:00
|
|
|
static gboolean
|
|
|
|
is_crtc_mode_tiled (MetaOutput *output,
|
|
|
|
MetaCrtcMode *crtc_mode)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
|
2020-02-26 08:45:07 +00:00
|
|
|
|
2020-02-26 23:08:58 +00:00
|
|
|
return (crtc_mode_info->width == (int) output_info->tile_info.tile_w &&
|
|
|
|
crtc_mode_info->height == (int) output_info->tile_info.tile_h);
|
2017-04-28 07:36:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
static MetaCrtcMode *
|
2017-06-14 06:41:13 +00:00
|
|
|
find_tiled_crtc_mode (MetaOutput *output,
|
|
|
|
MetaCrtcMode *reference_crtc_mode)
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *reference_crtc_mode_info =
|
|
|
|
meta_crtc_mode_get_info (reference_crtc_mode);
|
2017-05-01 04:01:41 +00:00
|
|
|
MetaCrtcMode *crtc_mode;
|
|
|
|
unsigned int i;
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
crtc_mode = output_info->preferred_mode;
|
2017-05-01 04:01:41 +00:00
|
|
|
if (is_crtc_mode_tiled (output, crtc_mode))
|
|
|
|
return crtc_mode;
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
for (i = 0; i < output_info->n_modes; i++)
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info;
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
crtc_mode = output_info->modes[i];
|
2020-02-26 23:08:58 +00:00
|
|
|
crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
|
2017-05-01 04:01:41 +00:00
|
|
|
|
|
|
|
if (!is_crtc_mode_tiled (output, crtc_mode))
|
|
|
|
continue;
|
|
|
|
|
2020-02-26 23:08:58 +00:00
|
|
|
if (crtc_mode_info->refresh_rate != reference_crtc_mode_info->refresh_rate)
|
2017-06-14 06:41:13 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-26 23:08:58 +00:00
|
|
|
if (crtc_mode_info->flags != reference_crtc_mode_info->flags)
|
2017-05-01 04:01:41 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return crtc_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-06 05:09:56 +00:00
|
|
|
static MetaMonitorMode *
|
2017-05-01 04:01:41 +00:00
|
|
|
create_tiled_monitor_mode (MetaMonitorTiled *monitor_tiled,
|
2017-06-14 06:41:13 +00:00
|
|
|
MetaCrtcMode *reference_crtc_mode,
|
2017-05-01 04:01:41 +00:00
|
|
|
gboolean *out_is_preferred)
|
2016-12-14 09:22:07 +00:00
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
2017-03-17 09:21:10 +00:00
|
|
|
MetaMonitorModeTiled *mode;
|
2017-06-14 04:04:09 +00:00
|
|
|
int width, height;
|
2016-12-14 09:22:07 +00:00
|
|
|
GList *l;
|
2017-05-01 04:01:41 +00:00
|
|
|
unsigned int i;
|
|
|
|
gboolean is_preferred = TRUE;
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
mode = g_new0 (MetaMonitorModeTiled, 1);
|
|
|
|
mode->is_tiled = TRUE;
|
2017-06-14 04:04:09 +00:00
|
|
|
meta_monitor_tiled_calculate_tiled_size (monitor, &width, &height);
|
2019-08-12 08:54:18 +00:00
|
|
|
mode->parent.monitor = monitor;
|
2017-10-24 10:43:58 +00:00
|
|
|
mode->parent.spec =
|
|
|
|
meta_monitor_create_spec (monitor, width, height, reference_crtc_mode);
|
2017-06-14 04:04:09 +00:00
|
|
|
mode->parent.id = generate_mode_id (&mode->parent.spec);
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
mode->parent.crtc_modes = g_new0 (MetaMonitorCrtcMode,
|
|
|
|
g_list_length (monitor_priv->outputs));
|
2016-12-14 09:22:07 +00:00
|
|
|
for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2017-05-01 04:01:41 +00:00
|
|
|
MetaCrtcMode *tiled_crtc_mode;
|
|
|
|
|
2017-06-14 06:41:13 +00:00
|
|
|
tiled_crtc_mode = find_tiled_crtc_mode (output, reference_crtc_mode);
|
2017-05-01 04:01:41 +00:00
|
|
|
if (!tiled_crtc_mode)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
g_warning ("No tiled mode found on %s", meta_output_get_name (output));
|
2017-05-01 04:01:41 +00:00
|
|
|
meta_monitor_mode_free ((MetaMonitorMode *) mode);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
|
2016-12-14 09:22:07 +00:00
|
|
|
.output = output,
|
2017-05-01 04:01:41 +00:00
|
|
|
.crtc_mode = tiled_crtc_mode
|
2016-12-14 09:22:07 +00:00
|
|
|
};
|
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
is_preferred = (is_preferred &&
|
|
|
|
tiled_crtc_mode == output_info->preferred_mode);
|
2017-03-06 05:09:56 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
*out_is_preferred = is_preferred;
|
|
|
|
|
|
|
|
return (MetaMonitorMode *) mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
generate_tiled_monitor_modes (MetaMonitorTiled *monitor_tiled)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaOutput *main_output;
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *main_output_info;
|
2017-05-01 04:01:41 +00:00
|
|
|
GList *tiled_modes = NULL;
|
|
|
|
unsigned int i;
|
2017-06-14 04:04:09 +00:00
|
|
|
MetaMonitorMode *best_mode = NULL;
|
|
|
|
GList *l;
|
2017-05-01 04:01:41 +00:00
|
|
|
|
|
|
|
main_output = meta_monitor_get_main_output (META_MONITOR (monitor_tiled));
|
2020-02-26 08:45:07 +00:00
|
|
|
main_output_info = meta_output_get_info (main_output);
|
2017-05-01 04:01:41 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
for (i = 0; i < main_output_info->n_modes; i++)
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
MetaCrtcMode *reference_crtc_mode = main_output_info->modes[i];
|
2017-05-01 04:01:41 +00:00
|
|
|
MetaMonitorMode *mode;
|
|
|
|
gboolean is_preferred;
|
|
|
|
|
2017-06-14 06:41:13 +00:00
|
|
|
if (!is_crtc_mode_tiled (main_output, reference_crtc_mode))
|
2017-05-01 04:01:41 +00:00
|
|
|
continue;
|
|
|
|
|
2017-06-14 06:41:13 +00:00
|
|
|
mode = create_tiled_monitor_mode (monitor_tiled, reference_crtc_mode,
|
2017-05-01 04:01:41 +00:00
|
|
|
&is_preferred);
|
|
|
|
if (!mode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tiled_modes = g_list_append (tiled_modes, mode);
|
|
|
|
|
|
|
|
if (is_monitor_mode_assigned (monitor, mode))
|
|
|
|
monitor_priv->current_mode = mode;
|
|
|
|
|
|
|
|
if (is_preferred)
|
|
|
|
monitor_priv->preferred_mode = mode;
|
|
|
|
}
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
while ((l = tiled_modes))
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2017-06-14 04:04:09 +00:00
|
|
|
MetaMonitorMode *mode = l->data;
|
|
|
|
|
|
|
|
tiled_modes = g_list_remove_link (tiled_modes, l);
|
2017-05-01 04:01:41 +00:00
|
|
|
|
2017-10-18 15:22:01 +00:00
|
|
|
if (!meta_monitor_add_mode (monitor, mode, FALSE))
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2017-06-14 04:04:09 +00:00
|
|
|
meta_monitor_mode_free (mode);
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-01 04:01:41 +00:00
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
if (!monitor_priv->preferred_mode)
|
|
|
|
{
|
2017-05-01 04:01:41 +00:00
|
|
|
if (!best_mode ||
|
|
|
|
mode->spec.refresh_rate > best_mode->spec.refresh_rate)
|
|
|
|
best_mode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
if (best_mode)
|
|
|
|
monitor_priv->preferred_mode = best_mode;
|
2017-03-06 05:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static MetaMonitorMode *
|
|
|
|
create_untiled_monitor_mode (MetaMonitorTiled *monitor_tiled,
|
|
|
|
MetaOutput *main_output,
|
|
|
|
MetaCrtcMode *crtc_mode)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
2017-03-17 09:21:10 +00:00
|
|
|
MetaMonitorModeTiled *mode;
|
2020-02-26 23:08:58 +00:00
|
|
|
const MetaCrtcModeInfo *crtc_mode_info;
|
2017-03-06 05:09:56 +00:00
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
2017-04-28 07:36:51 +00:00
|
|
|
if (is_crtc_mode_tiled (main_output, crtc_mode))
|
2017-03-06 05:09:56 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
mode = g_new0 (MetaMonitorModeTiled, 1);
|
|
|
|
mode->is_tiled = FALSE;
|
2019-08-12 08:54:18 +00:00
|
|
|
mode->parent.monitor = monitor;
|
2020-02-26 23:08:58 +00:00
|
|
|
|
|
|
|
crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
|
2017-10-24 10:43:58 +00:00
|
|
|
mode->parent.spec = meta_monitor_create_spec (monitor,
|
2020-02-26 23:08:58 +00:00
|
|
|
crtc_mode_info->width,
|
|
|
|
crtc_mode_info->height,
|
2017-10-24 10:43:58 +00:00
|
|
|
crtc_mode);
|
2017-06-14 04:04:09 +00:00
|
|
|
mode->parent.id = generate_mode_id (&mode->parent.spec);
|
2017-03-17 09:21:10 +00:00
|
|
|
mode->parent.crtc_modes = g_new0 (MetaMonitorCrtcMode,
|
2017-06-14 04:23:53 +00:00
|
|
|
g_list_length (monitor_priv->outputs));
|
2017-03-06 05:09:56 +00:00
|
|
|
|
|
|
|
for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
2016-12-22 07:22:13 +00:00
|
|
|
|
2017-03-06 05:09:56 +00:00
|
|
|
if (output == main_output)
|
|
|
|
{
|
2017-03-17 09:21:10 +00:00
|
|
|
mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
|
2017-03-06 05:09:56 +00:00
|
|
|
.output = output,
|
|
|
|
.crtc_mode = crtc_mode
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-17 09:21:10 +00:00
|
|
|
mode->parent.crtc_modes[i] = (MetaMonitorCrtcMode) {
|
2017-03-06 05:09:56 +00:00
|
|
|
.output = output,
|
|
|
|
.crtc_mode = NULL
|
|
|
|
};
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
return &mode->parent;
|
2017-03-06 05:09:56 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
static int
|
|
|
|
count_untiled_crtc_modes (MetaOutput *output)
|
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2017-05-01 04:01:41 +00:00
|
|
|
int count;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
count = 0;
|
2020-02-26 08:45:07 +00:00
|
|
|
for (i = 0; i < output_info->n_modes; i++)
|
2017-05-01 04:01:41 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
MetaCrtcMode *crtc_mode = output_info->modes[i];
|
2017-05-01 04:01:41 +00:00
|
|
|
|
|
|
|
if (!is_crtc_mode_tiled (output, crtc_mode))
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaOutput *
|
|
|
|
find_untiled_output (MetaMonitorTiled *monitor_tiled)
|
2017-03-06 05:09:56 +00:00
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
2017-05-01 04:01:41 +00:00
|
|
|
MetaOutput *best_output;
|
|
|
|
int best_untiled_crtc_mode_count;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
best_output = monitor_tiled->origin_output;
|
|
|
|
best_untiled_crtc_mode_count =
|
|
|
|
count_untiled_crtc_modes (monitor_tiled->origin_output);
|
|
|
|
|
|
|
|
for (l = monitor_priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
int untiled_crtc_mode_count;
|
|
|
|
|
|
|
|
if (output == monitor_tiled->origin_output)
|
|
|
|
continue;
|
2017-03-06 05:09:56 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
untiled_crtc_mode_count = count_untiled_crtc_modes (output);
|
|
|
|
if (untiled_crtc_mode_count > best_untiled_crtc_mode_count)
|
|
|
|
{
|
|
|
|
best_untiled_crtc_mode_count = untiled_crtc_mode_count;
|
|
|
|
best_output = output;
|
|
|
|
}
|
|
|
|
}
|
2017-03-06 05:09:56 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
return best_output;
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
static void
|
|
|
|
generate_untiled_monitor_modes (MetaMonitorTiled *monitor_tiled)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaOutput *main_output;
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *main_output_info;
|
2017-05-01 04:01:41 +00:00
|
|
|
unsigned int i;
|
2016-12-22 07:22:13 +00:00
|
|
|
|
2017-03-06 05:09:56 +00:00
|
|
|
main_output = meta_monitor_get_main_output (monitor);
|
2020-02-26 08:45:07 +00:00
|
|
|
main_output_info = meta_output_get_info (main_output);
|
2017-05-01 04:01:41 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
for (i = 0; i < main_output_info->n_modes; i++)
|
2017-03-06 05:09:56 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
MetaCrtcMode *crtc_mode = main_output_info->modes[i];
|
2017-05-01 04:01:41 +00:00
|
|
|
MetaMonitorMode *mode;
|
2017-03-06 05:09:56 +00:00
|
|
|
|
|
|
|
mode = create_untiled_monitor_mode (monitor_tiled,
|
|
|
|
main_output,
|
|
|
|
crtc_mode);
|
2017-05-01 04:01:41 +00:00
|
|
|
if (!mode)
|
|
|
|
continue;
|
|
|
|
|
2017-10-18 15:22:01 +00:00
|
|
|
if (!meta_monitor_add_mode (monitor, mode, FALSE))
|
2017-06-14 04:04:09 +00:00
|
|
|
{
|
|
|
|
meta_monitor_mode_free (mode);
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-01 04:01:41 +00:00
|
|
|
|
|
|
|
if (is_monitor_mode_assigned (monitor, mode))
|
2017-03-06 05:09:56 +00:00
|
|
|
{
|
2017-05-01 04:01:41 +00:00
|
|
|
g_assert (!monitor_priv->current_mode);
|
|
|
|
monitor_priv->current_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!monitor_priv->preferred_mode &&
|
2020-02-26 08:45:07 +00:00
|
|
|
crtc_mode == main_output_info->preferred_mode)
|
2017-05-01 04:01:41 +00:00
|
|
|
monitor_priv->preferred_mode = mode;
|
|
|
|
}
|
|
|
|
}
|
2017-03-06 05:09:56 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
static MetaMonitorMode *
|
|
|
|
find_best_mode (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaMonitorMode *best_mode = NULL;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = monitor_priv->modes; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitorMode *mode = l->data;
|
|
|
|
int area, best_area;
|
|
|
|
|
|
|
|
if (!best_mode)
|
|
|
|
{
|
|
|
|
best_mode = mode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
area = mode->spec.width * mode->spec.height;
|
|
|
|
best_area = best_mode->spec.width * best_mode->spec.height;
|
|
|
|
if (area > best_area)
|
|
|
|
{
|
|
|
|
best_mode = mode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode->spec.refresh_rate > best_mode->spec.refresh_rate)
|
|
|
|
{
|
|
|
|
best_mode = mode;
|
|
|
|
continue;
|
2017-03-06 05:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-01 04:01:41 +00:00
|
|
|
|
|
|
|
return best_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_tiled_generate_modes (MetaMonitorTiled *monitor_tiled)
|
|
|
|
{
|
|
|
|
MetaMonitor *monitor = META_MONITOR (monitor_tiled);
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tiled monitors may look a bit different from each other, depending on the
|
|
|
|
* monitor itself, the driver, etc.
|
|
|
|
*
|
|
|
|
* On some, the tiled modes will be the preferred CRTC modes, and running
|
|
|
|
* untiled is done by only enabling (0, 0) tile. In this case, things are
|
|
|
|
* pretty straight forward.
|
|
|
|
*
|
|
|
|
* Other times a monitor may have some bogus mode preferred on the main tile,
|
|
|
|
* and an untiled mode preferred on the non-main tile, and there seems to be
|
|
|
|
* no guarantee that the (0, 0) tile is the one that should drive the
|
|
|
|
* non-tiled mode.
|
|
|
|
*
|
|
|
|
* To handle both these cases, the following hueristics are implemented:
|
|
|
|
*
|
|
|
|
* 1) Find all the tiled CRTC modes of the (0, 0) tile, and create tiled
|
|
|
|
* monitor modes for all tiles based on these.
|
|
|
|
* 2) If there is any tiled monitor mode combination where all CRTC modes
|
|
|
|
* are the preferred ones, that one is marked as preferred.
|
|
|
|
* 3) If there is no preferred mode determined so far, assume the tiled
|
|
|
|
* monitor mode with the highest refresh rate is preferred.
|
|
|
|
* 4) Find the tile with highest number of untiled CRTC modes available,
|
|
|
|
* assume this is the one driving the monitor in untiled mode, and
|
|
|
|
* create monitor modes for all untiled CRTC modes of that tile. If
|
|
|
|
* there is still no preferred mode, set any untiled mode as preferred
|
|
|
|
* if the CRTC mode is marked as such.
|
|
|
|
* 5) If at this point there is still no preferred mode, just pick the one
|
|
|
|
* with the highest number of pixels and highest refresh rate.
|
|
|
|
*
|
|
|
|
* Note that this ignores the preference if the preference is a non-tiled
|
|
|
|
* mode. This seems to be the case on some systems, where the user tends to
|
|
|
|
* manually set up the tiled mode anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
generate_tiled_monitor_modes (monitor_tiled);
|
|
|
|
|
|
|
|
if (!monitor_priv->preferred_mode)
|
|
|
|
g_warning ("Tiled monitor on %s didn't have any tiled modes",
|
|
|
|
monitor_priv->spec->connector);
|
|
|
|
|
|
|
|
generate_untiled_monitor_modes (monitor_tiled);
|
|
|
|
|
|
|
|
if (!monitor_priv->preferred_mode)
|
|
|
|
{
|
|
|
|
g_warning ("Tiled monitor on %s didn't have a valid preferred mode",
|
|
|
|
monitor_priv->spec->connector);
|
|
|
|
monitor_priv->preferred_mode = find_best_mode (monitor);
|
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorTiled *
|
2021-01-26 13:49:25 +00:00
|
|
|
meta_monitor_tiled_new (MetaMonitorManager *monitor_manager,
|
2019-01-11 14:35:42 +00:00
|
|
|
MetaOutput *output)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
2020-02-26 08:45:07 +00:00
|
|
|
const MetaOutputInfo *output_info = meta_output_get_info (output);
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorTiled *monitor_tiled;
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitor *monitor;
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorPrivate *monitor_priv;
|
|
|
|
|
|
|
|
monitor_tiled = g_object_new (META_TYPE_MONITOR_TILED, NULL);
|
2016-12-17 14:34:26 +00:00
|
|
|
monitor = META_MONITOR (monitor_tiled);
|
|
|
|
monitor_priv = meta_monitor_get_instance_private (monitor);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2021-01-26 13:49:25 +00:00
|
|
|
monitor_priv->backend = meta_monitor_manager_get_backend (monitor_manager);
|
2017-05-11 09:24:53 +00:00
|
|
|
|
2020-02-26 08:45:07 +00:00
|
|
|
monitor_tiled->tile_group_id = output_info->tile_info.group_id;
|
2020-02-25 15:13:52 +00:00
|
|
|
monitor_priv->winsys_id = meta_output_get_id (output);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
monitor_tiled->origin_output = output;
|
2021-01-26 13:49:25 +00:00
|
|
|
add_tiled_monitor_outputs (meta_output_get_gpu (output), monitor_tiled);
|
2016-12-13 02:53:38 +00:00
|
|
|
|
2017-05-01 04:01:41 +00:00
|
|
|
monitor_tiled->main_output = find_untiled_output (monitor_tiled);
|
|
|
|
|
2017-04-28 07:34:27 +00:00
|
|
|
meta_monitor_generate_spec (monitor);
|
|
|
|
|
2019-01-11 14:35:42 +00:00
|
|
|
monitor_tiled->monitor_manager = monitor_manager;
|
2016-12-13 10:58:22 +00:00
|
|
|
meta_monitor_manager_tiled_monitor_added (monitor_manager,
|
|
|
|
META_MONITOR (monitor_tiled));
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
meta_monitor_tiled_generate_modes (monitor_tiled);
|
|
|
|
|
2021-10-28 14:08:25 +00:00
|
|
|
monitor_priv->display_name = meta_monitor_make_display_name (monitor);
|
2019-06-26 09:24:19 +00:00
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
return monitor_tiled;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaOutput *
|
|
|
|
meta_monitor_tiled_get_main_output (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (monitor);
|
|
|
|
|
|
|
|
return monitor_tiled->main_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-24 07:54:54 +00:00
|
|
|
meta_monitor_tiled_derive_layout (MetaMonitor *monitor,
|
|
|
|
MetaRectangle *layout)
|
2016-12-13 02:53:38 +00:00
|
|
|
{
|
2017-03-07 04:34:38 +00:00
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
2020-01-14 21:34:44 +00:00
|
|
|
float min_x, min_y, max_x, max_y;
|
2017-03-07 04:34:38 +00:00
|
|
|
|
2020-01-14 21:34:44 +00:00
|
|
|
min_x = FLT_MAX;
|
|
|
|
min_y = FLT_MAX;
|
|
|
|
max_x = 0.0;
|
|
|
|
max_y = 0.0;
|
2017-03-07 04:34:38 +00:00
|
|
|
for (l = monitor_priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
2017-11-03 10:25:30 +00:00
|
|
|
MetaCrtc *crtc;
|
2020-02-26 09:37:53 +00:00
|
|
|
const MetaCrtcConfig *crtc_config;
|
|
|
|
const graphene_rect_t *crtc_layout;
|
2017-03-07 04:34:38 +00:00
|
|
|
|
2017-11-03 10:25:30 +00:00
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
|
|
|
if (!crtc)
|
2017-03-07 04:34:38 +00:00
|
|
|
continue;
|
|
|
|
|
2020-02-26 09:37:53 +00:00
|
|
|
crtc_config = meta_crtc_get_config (crtc);
|
2020-01-14 21:34:44 +00:00
|
|
|
g_return_if_fail (crtc_config);
|
|
|
|
|
|
|
|
crtc_layout = &crtc_config->layout;
|
|
|
|
|
|
|
|
min_x = MIN (crtc_layout->origin.x, min_x);
|
|
|
|
min_y = MIN (crtc_layout->origin.y, min_y);
|
|
|
|
max_x = MAX (crtc_layout->origin.x + crtc_layout->size.width, max_x);
|
|
|
|
max_y = MAX (crtc_layout->origin.y + crtc_layout->size.height, max_y);
|
2017-03-07 04:34:38 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 07:42:20 +00:00
|
|
|
*layout = (MetaRectangle) {
|
2020-01-14 21:34:44 +00:00
|
|
|
.x = roundf (min_x),
|
|
|
|
.y = roundf (min_y),
|
|
|
|
.width = roundf (max_x - min_x),
|
|
|
|
.height = roundf (max_y - min_y)
|
2017-07-12 07:42:20 +00:00
|
|
|
};
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 03:55:10 +00:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_tiled_get_suggested_position (MetaMonitor *monitor,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
static void
|
2019-03-08 18:13:00 +00:00
|
|
|
meta_monitor_tiled_calculate_crtc_pos (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaOutput *output,
|
|
|
|
MetaMonitorTransform crtc_transform,
|
|
|
|
int *out_x,
|
|
|
|
int *out_y)
|
2017-03-17 09:21:10 +00:00
|
|
|
{
|
|
|
|
MetaMonitorModeTiled *mode_tiled = (MetaMonitorModeTiled *) monitor_mode;
|
|
|
|
|
|
|
|
if (mode_tiled->is_tiled)
|
|
|
|
{
|
2017-03-21 06:17:18 +00:00
|
|
|
calculate_tile_coordinate (monitor, output, crtc_transform,
|
2017-03-17 09:21:10 +00:00
|
|
|
out_x, out_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*out_x = 0;
|
|
|
|
*out_y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 10:58:22 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_tiled_finalize (GObject *object)
|
|
|
|
{
|
2019-01-11 14:35:42 +00:00
|
|
|
MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (object);
|
2016-12-13 10:58:22 +00:00
|
|
|
|
2019-01-11 14:35:42 +00:00
|
|
|
meta_monitor_manager_tiled_monitor_removed (monitor_tiled->monitor_manager,
|
|
|
|
META_MONITOR (monitor_tiled));
|
2017-09-11 03:12:03 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_tiled_parent_class)->finalize (object);
|
2016-12-13 10:58:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_tiled_init (MetaMonitorTiled *monitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_tiled_class_init (MetaMonitorTiledClass *klass)
|
|
|
|
{
|
2016-12-13 10:58:22 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2016-12-13 02:53:38 +00:00
|
|
|
MetaMonitorClass *monitor_class = META_MONITOR_CLASS (klass);
|
|
|
|
|
2016-12-13 10:58:22 +00:00
|
|
|
object_class->finalize = meta_monitor_tiled_finalize;
|
|
|
|
|
2016-12-13 02:53:38 +00:00
|
|
|
monitor_class->get_main_output = meta_monitor_tiled_get_main_output;
|
2017-10-24 07:54:54 +00:00
|
|
|
monitor_class->derive_layout = meta_monitor_tiled_derive_layout;
|
2017-03-17 09:21:10 +00:00
|
|
|
monitor_class->calculate_crtc_pos = meta_monitor_tiled_calculate_crtc_pos;
|
2017-05-01 03:55:10 +00:00
|
|
|
monitor_class->get_suggested_position = meta_monitor_tiled_get_suggested_position;
|
2016-12-13 02:53:38 +00:00
|
|
|
}
|
2016-12-14 09:22:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_mode_free (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2017-06-14 04:04:09 +00:00
|
|
|
g_free (monitor_mode->id);
|
2016-12-14 09:22:07 +00:00
|
|
|
g_free (monitor_mode->crtc_modes);
|
|
|
|
g_free (monitor_mode);
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:34:26 +00:00
|
|
|
MetaMonitorSpec *
|
|
|
|
meta_monitor_get_spec (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return priv->spec;
|
|
|
|
}
|
|
|
|
|
2017-01-09 06:31:18 +00:00
|
|
|
MetaLogicalMonitor *
|
|
|
|
meta_monitor_get_logical_monitor (MetaMonitor *monitor)
|
|
|
|
{
|
2020-01-16 09:10:42 +00:00
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
2017-01-09 06:31:18 +00:00
|
|
|
|
2020-01-16 09:10:42 +00:00
|
|
|
return priv->logical_monitor;
|
2017-01-09 06:31:18 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
MetaMonitorMode *
|
|
|
|
meta_monitor_get_mode_from_id (MetaMonitor *monitor,
|
|
|
|
const char *monitor_mode_id)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return g_hash_table_lookup (priv->mode_ids, monitor_mode_id);
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:25:22 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_mode_spec_has_similar_size (MetaMonitorModeSpec *monitor_mode_spec,
|
|
|
|
MetaMonitorModeSpec *other_monitor_mode_spec)
|
|
|
|
{
|
|
|
|
const float target_ratio = 1.0;
|
|
|
|
/* The a size difference of 15% means e.g. 4K modes matches other 4K modes,
|
|
|
|
* FHD (2K) modes other FHD modes, and HD modes other HD modes, but not each
|
|
|
|
* other.
|
|
|
|
*/
|
|
|
|
const float epsilon = 0.15;
|
|
|
|
|
|
|
|
return G_APPROX_VALUE (((float) monitor_mode_spec->width /
|
|
|
|
other_monitor_mode_spec->width) *
|
|
|
|
((float) monitor_mode_spec->height /
|
|
|
|
other_monitor_mode_spec->height),
|
|
|
|
target_ratio, epsilon);
|
|
|
|
}
|
|
|
|
|
2016-12-21 05:03:35 +00:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_mode_spec_equals (MetaMonitorModeSpec *monitor_mode_spec,
|
|
|
|
MetaMonitorModeSpec *other_monitor_mode_spec)
|
|
|
|
{
|
|
|
|
return (monitor_mode_spec->width == other_monitor_mode_spec->width &&
|
|
|
|
monitor_mode_spec->height == other_monitor_mode_spec->height &&
|
2017-09-14 10:42:47 +00:00
|
|
|
ABS (monitor_mode_spec->refresh_rate -
|
|
|
|
other_monitor_mode_spec->refresh_rate) < MAXIMUM_REFRESH_RATE_DIFF &&
|
2017-06-14 06:41:13 +00:00
|
|
|
monitor_mode_spec->flags == other_monitor_mode_spec->flags);
|
2016-12-21 05:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaMonitorMode *
|
|
|
|
meta_monitor_get_mode_from_spec (MetaMonitor *monitor,
|
|
|
|
MetaMonitorModeSpec *monitor_mode_spec)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = priv->modes; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitorMode *monitor_mode = l->data;
|
|
|
|
|
|
|
|
if (meta_monitor_mode_spec_equals (monitor_mode_spec,
|
|
|
|
&monitor_mode->spec))
|
|
|
|
return monitor_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:32:05 +00:00
|
|
|
MetaMonitorMode *
|
|
|
|
meta_monitor_get_preferred_mode (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return priv->preferred_mode;
|
|
|
|
}
|
|
|
|
|
2016-12-22 07:22:13 +00:00
|
|
|
MetaMonitorMode *
|
|
|
|
meta_monitor_get_current_mode (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return priv->current_mode;
|
|
|
|
}
|
|
|
|
|
monitor: Use current monitor mode to check whether active
For historical reasons meta_monitor_is_active() checked whether it is
active by checking whether the main output have a CRTC assigned and
whether that CRTC has a current mode. At a later point, the MetaMonitor
got its own mode abstraction (MetaMonitorMode), but
meta_monitor_is_active() was never updated to use this.
An issue with checking the main output's CRTC state is that, if there is
some CRTC mode combination that for some reason isn't properly detected
by the MetaMonitorMode abstraction (e.g. some tiling configuration not
yet handled), meta_monitor_is_active() would return TRUE, even though no
(abstracted) mode was set. This would cause confusion here and there,
leading to NULL pointer dereferences due to the assumption that if a
monitor is active, it has an active mode.
Instead, change meta_monitor_is_active() to directly check the current
monitor mode, and log a warning if the main output still happen to have
a CRTC with a mode assigned to it. This way, when an not undrestood CRTC
mode combination is encountered, instead of dereferencing NULL pointers,
simply assume the monitor is not active, which means that it will not be
managed or rendered by mutter at all.
https://gitlab.gnome.org/GNOME/mutter/issues/130
2018-07-31 11:18:51 +00:00
|
|
|
static gboolean
|
|
|
|
is_current_mode_known (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
MetaCrtc *crtc;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
crtc = meta_output_get_assigned_crtc (output);
|
|
|
|
|
2020-02-26 09:37:53 +00:00
|
|
|
return (meta_monitor_is_active (monitor) ==
|
|
|
|
(crtc && meta_crtc_get_config (crtc)));
|
monitor: Use current monitor mode to check whether active
For historical reasons meta_monitor_is_active() checked whether it is
active by checking whether the main output have a CRTC assigned and
whether that CRTC has a current mode. At a later point, the MetaMonitor
got its own mode abstraction (MetaMonitorMode), but
meta_monitor_is_active() was never updated to use this.
An issue with checking the main output's CRTC state is that, if there is
some CRTC mode combination that for some reason isn't properly detected
by the MetaMonitorMode abstraction (e.g. some tiling configuration not
yet handled), meta_monitor_is_active() would return TRUE, even though no
(abstracted) mode was set. This would cause confusion here and there,
leading to NULL pointer dereferences due to the assumption that if a
monitor is active, it has an active mode.
Instead, change meta_monitor_is_active() to directly check the current
monitor mode, and log a warning if the main output still happen to have
a CRTC with a mode assigned to it. This way, when an not undrestood CRTC
mode combination is encountered, instead of dereferencing NULL pointers,
simply assume the monitor is not active, which means that it will not be
managed or rendered by mutter at all.
https://gitlab.gnome.org/GNOME/mutter/issues/130
2018-07-31 11:18:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 07:22:13 +00:00
|
|
|
void
|
|
|
|
meta_monitor_derive_current_mode (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
MetaMonitorMode *current_mode = NULL;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = priv->modes; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaMonitorMode *mode = l->data;
|
|
|
|
|
|
|
|
if (is_monitor_mode_assigned (monitor, mode))
|
|
|
|
{
|
|
|
|
current_mode = mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->current_mode = current_mode;
|
monitor: Use current monitor mode to check whether active
For historical reasons meta_monitor_is_active() checked whether it is
active by checking whether the main output have a CRTC assigned and
whether that CRTC has a current mode. At a later point, the MetaMonitor
got its own mode abstraction (MetaMonitorMode), but
meta_monitor_is_active() was never updated to use this.
An issue with checking the main output's CRTC state is that, if there is
some CRTC mode combination that for some reason isn't properly detected
by the MetaMonitorMode abstraction (e.g. some tiling configuration not
yet handled), meta_monitor_is_active() would return TRUE, even though no
(abstracted) mode was set. This would cause confusion here and there,
leading to NULL pointer dereferences due to the assumption that if a
monitor is active, it has an active mode.
Instead, change meta_monitor_is_active() to directly check the current
monitor mode, and log a warning if the main output still happen to have
a CRTC with a mode assigned to it. This way, when an not undrestood CRTC
mode combination is encountered, instead of dereferencing NULL pointers,
simply assume the monitor is not active, which means that it will not be
managed or rendered by mutter at all.
https://gitlab.gnome.org/GNOME/mutter/issues/130
2018-07-31 11:18:51 +00:00
|
|
|
|
|
|
|
g_warn_if_fail (is_current_mode_known (monitor));
|
2016-12-22 07:22:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 06:31:18 +00:00
|
|
|
void
|
|
|
|
meta_monitor_set_current_mode (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
priv->current_mode = mode;
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
GList *
|
|
|
|
meta_monitor_get_modes (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return priv->modes;
|
|
|
|
}
|
|
|
|
|
2017-03-17 09:21:10 +00:00
|
|
|
void
|
2019-03-08 18:13:00 +00:00
|
|
|
meta_monitor_calculate_crtc_pos (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaOutput *output,
|
|
|
|
MetaMonitorTransform crtc_transform,
|
|
|
|
int *out_x,
|
|
|
|
int *out_y)
|
2017-03-17 09:21:10 +00:00
|
|
|
{
|
|
|
|
META_MONITOR_GET_CLASS (monitor)->calculate_crtc_pos (monitor,
|
|
|
|
monitor_mode,
|
|
|
|
output,
|
2017-03-21 06:17:18 +00:00
|
|
|
crtc_transform,
|
2017-03-17 09:21:10 +00:00
|
|
|
out_x,
|
|
|
|
out_y);
|
|
|
|
}
|
|
|
|
|
2017-04-21 09:28:22 +00:00
|
|
|
/*
|
2022-10-07 05:46:04 +00:00
|
|
|
* We choose a default scale factor such that the UI is as big
|
|
|
|
* as it would be on a display with this DPI without scaling.
|
|
|
|
*
|
|
|
|
* Through experiementing, a value of 135 has been found to best
|
|
|
|
* line up with the UI size chosen as default by other operating
|
|
|
|
* systems (macOS, Android, iOS, Windows) and the community-decided
|
|
|
|
* "known-good" scale factors for GNOME for various mobile devices
|
|
|
|
* such as phones, tablets, and laptops
|
2017-04-21 09:28:22 +00:00
|
|
|
*/
|
2022-10-07 05:46:04 +00:00
|
|
|
#define UI_SCALE_MOBILE_TARGET_DPI 135
|
2017-04-21 09:28:22 +00:00
|
|
|
|
2022-10-07 05:46:04 +00:00
|
|
|
/*
|
|
|
|
* People tend to sit further away from larger stationary displays
|
|
|
|
* than they do from mobile displays, so a UI of an identical size to
|
|
|
|
* a mobile device has a smaller angular size and thus seems to be too
|
|
|
|
* small.
|
|
|
|
*
|
|
|
|
* The largest mainstream laptops have screens ~17in, and HiDPI external
|
|
|
|
* monitors start at ~23in, so 20in is a good boundary point
|
|
|
|
*/
|
|
|
|
#define UI_SCALE_LARGE_TARGET_DPI 110
|
|
|
|
#define UI_SCALE_LARGE_MIN_SIZE_INCHES 20
|
2017-04-21 09:28:22 +00:00
|
|
|
|
2017-05-25 08:12:51 +00:00
|
|
|
static float
|
2017-06-10 14:10:57 +00:00
|
|
|
calculate_scale (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaMonitorScalesConstraint constraints)
|
2017-04-21 09:28:22 +00:00
|
|
|
{
|
2022-10-07 05:46:04 +00:00
|
|
|
int width_px, height_px, width_mm, height_mm;
|
|
|
|
float diag_inches;
|
|
|
|
g_autofree float *scales = NULL;
|
|
|
|
int n_scales;
|
|
|
|
float best_scale, best_dpi;
|
|
|
|
int target_dpi;
|
2023-03-02 10:16:38 +00:00
|
|
|
const float scale_epsilon = 0.2;
|
2017-04-21 09:28:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Somebody encoded the aspect ratio (16/9 or 16/10) instead of the physical
|
2022-10-07 05:46:04 +00:00
|
|
|
* size. We'll be unable to select an appropriate scale factor.
|
2017-04-21 09:28:22 +00:00
|
|
|
*/
|
2018-09-24 07:48:37 +00:00
|
|
|
if (meta_monitor_has_aspect_as_size (monitor))
|
2022-10-07 05:46:04 +00:00
|
|
|
return 1.0;
|
2017-04-21 09:28:22 +00:00
|
|
|
|
2022-10-07 05:46:04 +00:00
|
|
|
/* Compute display's diagonal size in inches */
|
|
|
|
meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
|
|
|
|
if (width_mm == 0 || height_mm == 0)
|
|
|
|
return 1.0;
|
|
|
|
diag_inches = sqrtf (width_mm * width_mm + height_mm * height_mm) / 25.4;
|
|
|
|
|
|
|
|
/* Pick the appropriate target DPI based on screen size */
|
|
|
|
if (diag_inches < UI_SCALE_LARGE_MIN_SIZE_INCHES)
|
|
|
|
target_dpi = UI_SCALE_MOBILE_TARGET_DPI;
|
|
|
|
else
|
|
|
|
target_dpi = UI_SCALE_LARGE_TARGET_DPI;
|
|
|
|
|
|
|
|
meta_monitor_mode_get_resolution (monitor_mode, &width_px, &height_px);
|
|
|
|
|
|
|
|
/* We'll only be considering the supported scale factors */
|
|
|
|
scales = meta_monitor_calculate_supported_scales (monitor, monitor_mode,
|
2023-03-02 10:16:38 +00:00
|
|
|
META_MONITOR_SCALES_CONSTRAINT_NONE,
|
|
|
|
&n_scales);
|
2022-10-07 05:46:04 +00:00
|
|
|
best_scale = scales[0];
|
|
|
|
for (int i = 0; i < n_scales; i++)
|
2017-04-21 09:28:22 +00:00
|
|
|
{
|
2022-10-07 05:46:04 +00:00
|
|
|
float width_scaled, height_scaled, diag_scaled, dpi;
|
2017-04-21 09:28:22 +00:00
|
|
|
|
2022-10-07 05:46:04 +00:00
|
|
|
/*
|
|
|
|
* Compute the logical resolution of the display for this
|
|
|
|
* scale factor
|
|
|
|
*/
|
|
|
|
width_scaled = (float) width_px / scales[i];
|
|
|
|
height_scaled = (float) height_px / scales[i];
|
|
|
|
|
|
|
|
/* Compute the number of logical pixels across the display's diagonal */
|
|
|
|
diag_scaled = sqrtf (width_scaled * width_scaled +
|
|
|
|
height_scaled * height_scaled);
|
2017-04-21 09:28:22 +00:00
|
|
|
|
|
|
|
/*
|
2022-10-07 05:46:04 +00:00
|
|
|
* Computes the display's logical DPI - the number of logical pixels
|
|
|
|
* per inch on the display's diagonal
|
2017-04-21 09:28:22 +00:00
|
|
|
*/
|
2022-10-07 05:46:04 +00:00
|
|
|
dpi = diag_scaled / diag_inches;
|
|
|
|
|
|
|
|
/* Pick the scale factor whose logical DPI is closest to the optimal value */
|
|
|
|
if (i == 0 || fabsf (dpi - target_dpi) < fabsf (best_dpi - target_dpi))
|
|
|
|
{
|
|
|
|
best_scale = scales[i];
|
|
|
|
best_dpi = dpi;
|
|
|
|
}
|
2017-04-21 09:28:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 10:16:38 +00:00
|
|
|
if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC)
|
|
|
|
{
|
|
|
|
best_scale = floorf (MIN (scales[n_scales - 1],
|
|
|
|
best_scale + 0.25 + scale_epsilon));
|
|
|
|
}
|
|
|
|
|
2022-10-07 05:46:04 +00:00
|
|
|
return best_scale;
|
2017-04-21 09:28:22 +00:00
|
|
|
}
|
|
|
|
|
2017-05-25 08:12:51 +00:00
|
|
|
float
|
2017-06-10 14:10:57 +00:00
|
|
|
meta_monitor_calculate_mode_scale (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaMonitorScalesConstraint constraints)
|
2017-04-21 09:28:22 +00:00
|
|
|
{
|
2022-05-27 17:35:01 +00:00
|
|
|
MetaBackend *backend = meta_monitor_get_backend (monitor);
|
2017-04-21 09:28:22 +00:00
|
|
|
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;
|
|
|
|
|
2017-06-10 14:10:57 +00:00
|
|
|
return calculate_scale (monitor, monitor_mode, constraints);
|
2017-04-21 09:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-16 16:09:40 +00:00
|
|
|
static gboolean
|
2019-08-12 08:52:20 +00:00
|
|
|
is_logical_size_large_enough (int width,
|
|
|
|
int height)
|
2018-07-16 16:09:40 +00:00
|
|
|
{
|
2019-08-12 08:52:48 +00:00
|
|
|
return width * height >= MINIMUM_LOGICAL_AREA;
|
2018-07-16 16:09:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 03:35:51 +00:00
|
|
|
static gboolean
|
|
|
|
is_scale_valid_for_size (float width,
|
|
|
|
float height,
|
|
|
|
float scale)
|
|
|
|
{
|
|
|
|
if (scale < MINIMUM_SCALE_FACTOR || scale > MAXIMUM_SCALE_FACTOR)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return is_logical_size_large_enough (floorf (width / scale),
|
|
|
|
floorf (height / scale));
|
|
|
|
}
|
|
|
|
|
2018-07-16 16:09:40 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_mode_should_be_advertised (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2019-08-12 08:54:18 +00:00
|
|
|
MetaMonitorMode *preferred_mode;
|
|
|
|
|
2018-07-16 16:09:40 +00:00
|
|
|
g_return_val_if_fail (monitor_mode != NULL, FALSE);
|
|
|
|
|
2019-08-12 08:54:18 +00:00
|
|
|
preferred_mode = meta_monitor_get_preferred_mode (monitor_mode->monitor);
|
|
|
|
if (monitor_mode->spec.width == preferred_mode->spec.width &&
|
|
|
|
monitor_mode->spec.height == preferred_mode->spec.height)
|
|
|
|
return TRUE;
|
|
|
|
|
2018-07-16 16:09:40 +00:00
|
|
|
return is_logical_size_large_enough (monitor_mode->spec.width,
|
|
|
|
monitor_mode->spec.height);
|
|
|
|
}
|
|
|
|
|
2017-06-06 03:27:58 +00:00
|
|
|
static float
|
|
|
|
get_closest_scale_factor_for_resolution (float width,
|
|
|
|
float height,
|
2021-05-28 17:45:42 +00:00
|
|
|
float scale,
|
|
|
|
float threshold)
|
2017-06-06 03:27:58 +00:00
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
float scaled_h;
|
|
|
|
float scaled_w;
|
|
|
|
float best_scale;
|
|
|
|
int base_scaled_w;
|
|
|
|
gboolean found_one;
|
|
|
|
|
|
|
|
best_scale = 0;
|
|
|
|
|
2018-11-24 03:35:51 +00:00
|
|
|
if (!is_scale_valid_for_size (width, height, scale))
|
2021-05-28 17:07:21 +00:00
|
|
|
return best_scale;
|
2017-06-06 03:27:58 +00:00
|
|
|
|
2018-11-24 03:35:51 +00:00
|
|
|
if (fmodf (width, scale) == 0.0 && fmodf (height, scale) == 0.0)
|
2017-06-06 03:27:58 +00:00
|
|
|
return scale;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
found_one = FALSE;
|
2018-11-24 03:35:51 +00:00
|
|
|
base_scaled_w = floorf (width / scale);
|
2017-06-06 03:27:58 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
for (j = 0; j < 2; j++)
|
|
|
|
{
|
|
|
|
float current_scale;
|
|
|
|
int offset = i * (j ? 1 : -1);
|
|
|
|
|
|
|
|
scaled_w = base_scaled_w + offset;
|
|
|
|
current_scale = width / scaled_w;
|
|
|
|
scaled_h = height / current_scale;
|
|
|
|
|
2021-05-28 17:45:42 +00:00
|
|
|
if (current_scale >= scale + threshold ||
|
|
|
|
current_scale <= scale - threshold ||
|
2017-06-06 03:27:58 +00:00
|
|
|
current_scale < MINIMUM_SCALE_FACTOR ||
|
|
|
|
current_scale > MAXIMUM_SCALE_FACTOR)
|
|
|
|
{
|
2021-05-28 17:07:21 +00:00
|
|
|
return best_scale;
|
2017-06-06 03:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (floorf (scaled_h) == scaled_h)
|
|
|
|
{
|
|
|
|
found_one = TRUE;
|
|
|
|
|
|
|
|
if (fabsf (current_scale - scale) < fabsf (best_scale - scale))
|
|
|
|
best_scale = current_scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2019-03-05 00:26:35 +00:00
|
|
|
while (!found_one);
|
2017-06-06 03:27:58 +00:00
|
|
|
|
|
|
|
return best_scale;
|
|
|
|
}
|
|
|
|
|
2017-06-05 07:59:47 +00:00
|
|
|
float *
|
2019-03-08 18:03:57 +00:00
|
|
|
meta_monitor_calculate_supported_scales (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
MetaMonitorScalesConstraint constraints,
|
|
|
|
int *n_supported_scales)
|
2017-06-05 07:59:47 +00:00
|
|
|
{
|
2017-06-06 03:27:58 +00:00
|
|
|
unsigned int i, j;
|
2017-06-05 07:59:47 +00:00
|
|
|
int width, height;
|
|
|
|
GArray *supported_scales;
|
|
|
|
|
|
|
|
supported_scales = g_array_new (FALSE, FALSE, sizeof (float));
|
|
|
|
|
2017-06-06 03:27:58 +00:00
|
|
|
meta_monitor_mode_get_resolution (monitor_mode, &width, &height);
|
2017-06-05 07:59:47 +00:00
|
|
|
|
2017-06-06 03:27:58 +00:00
|
|
|
for (i = floorf (MINIMUM_SCALE_FACTOR);
|
|
|
|
i <= ceilf (MAXIMUM_SCALE_FACTOR);
|
|
|
|
i++)
|
|
|
|
{
|
2021-05-28 17:19:36 +00:00
|
|
|
if (constraints & META_MONITOR_SCALES_CONSTRAINT_NO_FRAC)
|
2017-06-06 03:27:58 +00:00
|
|
|
{
|
2021-05-28 17:19:36 +00:00
|
|
|
if (is_scale_valid_for_size (width, height, i))
|
2017-06-06 03:27:58 +00:00
|
|
|
{
|
2021-05-28 17:19:36 +00:00
|
|
|
float scale = i;
|
|
|
|
g_array_append_val (supported_scales, scale);
|
2018-11-24 03:35:51 +00:00
|
|
|
}
|
2021-05-28 17:19:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-28 17:45:42 +00:00
|
|
|
float max_bound;
|
|
|
|
|
|
|
|
if (i == floorf (MINIMUM_SCALE_FACTOR) ||
|
|
|
|
i == ceilf (MAXIMUM_SCALE_FACTOR))
|
|
|
|
max_bound = SCALE_FACTORS_STEPS;
|
|
|
|
else
|
|
|
|
max_bound = SCALE_FACTORS_STEPS / 2.0;
|
|
|
|
|
2021-05-28 17:19:36 +00:00
|
|
|
for (j = 0; j < SCALE_FACTORS_PER_INTEGER; j++)
|
2018-11-24 03:35:51 +00:00
|
|
|
{
|
2021-05-28 17:19:36 +00:00
|
|
|
float scale;
|
|
|
|
float scale_value = i + j * SCALE_FACTORS_STEPS;
|
|
|
|
|
|
|
|
scale = get_closest_scale_factor_for_resolution (width, height,
|
2021-05-28 17:45:42 +00:00
|
|
|
scale_value,
|
|
|
|
max_bound);
|
2021-05-28 17:19:36 +00:00
|
|
|
if (scale > 0.0)
|
|
|
|
g_array_append_val (supported_scales, scale);
|
|
|
|
}
|
2017-06-06 03:27:58 +00:00
|
|
|
}
|
2017-06-05 07:59:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-11 06:12:29 +00:00
|
|
|
if (supported_scales->len == 0)
|
|
|
|
{
|
|
|
|
float fallback_scale;
|
|
|
|
|
|
|
|
fallback_scale = 1.0;
|
|
|
|
g_array_append_val (supported_scales, fallback_scale);
|
|
|
|
}
|
|
|
|
|
2017-06-05 07:59:47 +00:00
|
|
|
*n_supported_scales = supported_scales->len;
|
|
|
|
return (float *) g_array_free (supported_scales, FALSE);
|
|
|
|
}
|
|
|
|
|
2016-12-17 14:29:33 +00:00
|
|
|
MetaMonitorModeSpec *
|
|
|
|
meta_monitor_mode_get_spec (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
|
|
|
return &monitor_mode->spec;
|
|
|
|
}
|
|
|
|
|
2017-06-14 04:04:09 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_mode_get_id (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
|
|
|
return monitor_mode->id;
|
|
|
|
}
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
void
|
|
|
|
meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
2016-12-17 14:29:33 +00:00
|
|
|
*width = monitor_mode->spec.width;
|
|
|
|
*height = monitor_mode->spec.height;
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
meta_monitor_mode_get_refresh_rate (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2016-12-17 14:29:33 +00:00
|
|
|
return monitor_mode->spec.refresh_rate;
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 06:41:13 +00:00
|
|
|
MetaCrtcModeFlag
|
|
|
|
meta_monitor_mode_get_flags (MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
|
|
|
return monitor_mode->spec.flags;
|
|
|
|
}
|
|
|
|
|
2016-12-20 15:23:27 +00:00
|
|
|
gboolean
|
2019-03-08 18:17:40 +00:00
|
|
|
meta_monitor_mode_foreach_crtc (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode,
|
|
|
|
MetaMonitorModeFunc func,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2016-12-14 09:22:07 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
2017-08-18 06:04:02 +00:00
|
|
|
for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
|
|
|
|
|
|
|
|
if (!monitor_crtc_mode->crtc_mode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!func (monitor, mode, monitor_crtc_mode, user_data, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-03-08 18:17:40 +00:00
|
|
|
meta_monitor_mode_foreach_output (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode,
|
|
|
|
MetaMonitorModeFunc func,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2017-08-18 06:04:02 +00:00
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
2016-12-14 09:22:07 +00:00
|
|
|
for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
|
|
|
|
|
2016-12-20 15:23:27 +00:00
|
|
|
if (!func (monitor, mode, monitor_crtc_mode, user_data, error))
|
|
|
|
return FALSE;
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
2016-12-20 15:23:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-12-14 09:22:07 +00:00
|
|
|
}
|
2019-06-26 09:24:19 +00:00
|
|
|
|
2020-10-09 23:02:28 +00:00
|
|
|
MetaMonitorCrtcMode *
|
|
|
|
meta_monitor_get_crtc_mode_for_output (MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *mode,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (l = monitor_priv->outputs, i = 0; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
MetaMonitorCrtcMode *monitor_crtc_mode = &mode->crtc_modes[i];
|
|
|
|
|
|
|
|
if (monitor_crtc_mode->output == output)
|
|
|
|
return monitor_crtc_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warn_if_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-26 09:24:19 +00:00
|
|
|
const char *
|
|
|
|
meta_monitor_get_display_name (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *monitor_priv =
|
|
|
|
meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
return monitor_priv->display_name;
|
|
|
|
}
|
2020-01-16 09:10:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_monitor_set_logical_monitor (MetaMonitor *monitor,
|
|
|
|
MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
priv->logical_monitor = logical_monitor;
|
|
|
|
}
|
2021-03-22 00:02:19 +00:00
|
|
|
|
|
|
|
static MetaOutput *
|
|
|
|
maybe_get_privacy_screen_output (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
|
|
|
|
if (priv->outputs && priv->outputs->next)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return meta_monitor_get_main_output (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaPrivacyScreenState
|
|
|
|
meta_monitor_get_privacy_screen_state (MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = maybe_get_privacy_screen_output (monitor);
|
|
|
|
|
|
|
|
if (!output)
|
|
|
|
return META_PRIVACY_SCREEN_UNAVAILABLE;
|
|
|
|
|
|
|
|
return meta_output_get_privacy_screen_state (output);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_monitor_set_privacy_screen_enabled (MetaMonitor *monitor,
|
|
|
|
gboolean enabled,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
output = maybe_get_privacy_screen_output (monitor);
|
|
|
|
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"The privacy screen is not supported by this output");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return meta_output_set_privacy_screen_enabled (output, enabled, error);
|
|
|
|
}
|
2023-03-02 00:35:10 +00:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_monitor_set_color_space (MetaMonitor *monitor,
|
|
|
|
MetaOutputColorspace color_space,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
if (!meta_output_is_color_space_supported (output, color_space))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"The color space is not supported by this monitor");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
meta_output_set_color_space (output, color_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_monitor_set_hdr_metadata (MetaMonitor *monitor,
|
|
|
|
MetaOutputHdrMetadata *metadata,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
2023-03-02 18:49:36 +00:00
|
|
|
if (!meta_output_is_hdr_metadata_supported (output, metadata->eotf))
|
2023-03-02 00:35:10 +00:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
"HDR metadata is not supported by this monitor");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = priv->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
meta_output_set_hdr_metadata (output, metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|