Introduce virtual monitors
Virtual monitors are monitors that isn't backed by any monitor like
hardware. It would typically be backed by e.g. a remote desktop service,
or a network display.
It is currently only supported by the native backend, and whether the
X11 backend will ever see virtual monitors is an open question. This
rest of this commit message describes how it works under the native
backend.
Each virutal monitor consists of virtualized mode setting components:
* A virtual CRTC mode (MetaCrtcModeVirtual)
* A virtual CRTC (MetaCrtcVirtual)
* A virtual connector (MetaOutputVirtual)
In difference to the corresponding mode setting objects that represents
KMS objects, the virtual ones isn't directly tied to a MetaGpu, other
than the CoglFramebuffer being part of the GPU context of the primary
GPU, which is the case for all monitors no matter what GPU they are
connected to. Part of the reason for this is that a MetaGpu in practice
represents a mode setting device, and its CRTCs and outputs, are all
backed by real mode setting objects, while a virtual monitor is only
backed by a framebuffer that is tied to the primary GPU. Maybe this will
be reevaluated in the future, but since a virtual monitor is not tied to
any GPU currently, so is the case for the virtual mode setting objects.
The native rendering backend, including the cursor renderer, is adapted
to handle the situation where a CRTC does not have a GPU associated with
it; this in practice means that it e.g. will not try to upload HW cursor
buffers when the cursor is only on a virtual monitor. The same applies
to the native renderer, which is made to avoid creating
MetaOnscreenNative for views that are backed by virtual CRTCs, as well
as to avoid trying to mode set on such views.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698>
2021-01-26 10:49:28 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* 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-virtual-monitor.h"
|
|
|
|
|
|
|
|
#include "backends/meta-crtc.h"
|
|
|
|
#include "backends/meta-crtc-mode.h"
|
|
|
|
#include "backends/meta-output.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DESTROY,
|
|
|
|
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[N_SIGNALS] = { 0 };
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_CRTC,
|
|
|
|
PROP_CRTC_MODE,
|
|
|
|
PROP_OUTPUT,
|
|
|
|
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *obj_props[N_PROPS];
|
|
|
|
|
|
|
|
typedef struct _MetaVirtualMonitorPrivate
|
|
|
|
{
|
|
|
|
MetaCrtc *crtc;
|
|
|
|
MetaCrtcMode *crtc_mode;
|
|
|
|
MetaOutput *output;
|
|
|
|
|
|
|
|
gboolean is_destroyed;
|
|
|
|
} MetaVirtualMonitorPrivate;
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaVirtualMonitor, meta_virtual_monitor,
|
|
|
|
G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
MetaVirtualMonitorInfo *
|
|
|
|
meta_virtual_monitor_info_new (int width,
|
|
|
|
int height,
|
|
|
|
float refresh_rate,
|
|
|
|
const char *vendor,
|
|
|
|
const char *product,
|
|
|
|
const char *serial)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitorInfo *info;
|
|
|
|
|
|
|
|
info = g_new0 (MetaVirtualMonitorInfo, 1);
|
2021-12-01 17:24:33 -05:00
|
|
|
info->mode_info = (MetaVirtualModeInfo) {
|
|
|
|
.width = width,
|
|
|
|
.height = height,
|
|
|
|
.refresh_rate = refresh_rate,
|
|
|
|
};
|
Introduce virtual monitors
Virtual monitors are monitors that isn't backed by any monitor like
hardware. It would typically be backed by e.g. a remote desktop service,
or a network display.
It is currently only supported by the native backend, and whether the
X11 backend will ever see virtual monitors is an open question. This
rest of this commit message describes how it works under the native
backend.
Each virutal monitor consists of virtualized mode setting components:
* A virtual CRTC mode (MetaCrtcModeVirtual)
* A virtual CRTC (MetaCrtcVirtual)
* A virtual connector (MetaOutputVirtual)
In difference to the corresponding mode setting objects that represents
KMS objects, the virtual ones isn't directly tied to a MetaGpu, other
than the CoglFramebuffer being part of the GPU context of the primary
GPU, which is the case for all monitors no matter what GPU they are
connected to. Part of the reason for this is that a MetaGpu in practice
represents a mode setting device, and its CRTCs and outputs, are all
backed by real mode setting objects, while a virtual monitor is only
backed by a framebuffer that is tied to the primary GPU. Maybe this will
be reevaluated in the future, but since a virtual monitor is not tied to
any GPU currently, so is the case for the virtual mode setting objects.
The native rendering backend, including the cursor renderer, is adapted
to handle the situation where a CRTC does not have a GPU associated with
it; this in practice means that it e.g. will not try to upload HW cursor
buffers when the cursor is only on a virtual monitor. The same applies
to the native renderer, which is made to avoid creating
MetaOnscreenNative for views that are backed by virtual CRTCs, as well
as to avoid trying to mode set on such views.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698>
2021-01-26 10:49:28 -05:00
|
|
|
info->vendor = g_strdup (vendor);
|
|
|
|
info->product = g_strdup (product);
|
|
|
|
info->serial = g_strdup (serial);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_virtual_monitor_info_free (MetaVirtualMonitorInfo *info)
|
|
|
|
{
|
|
|
|
g_free (info->vendor);
|
|
|
|
g_free (info->product);
|
|
|
|
g_free (info->serial);
|
|
|
|
g_free (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaCrtc *
|
|
|
|
meta_virtual_monitor_get_crtc (MetaVirtualMonitor *virtual_monitor)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
return priv->crtc;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaCrtcMode *
|
|
|
|
meta_virtual_monitor_get_crtc_mode (MetaVirtualMonitor *virtual_monitor)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
return priv->crtc_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaOutput *
|
|
|
|
meta_virtual_monitor_get_output (MetaVirtualMonitor *virtual_monitor)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
return priv->output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_virtual_monitor_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_CRTC:
|
|
|
|
priv->crtc = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
case PROP_CRTC_MODE:
|
|
|
|
priv->crtc_mode = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT:
|
|
|
|
priv->output = g_value_get_object (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_virtual_monitor_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_CRTC:
|
|
|
|
g_value_set_object (value, priv->crtc);
|
|
|
|
break;
|
|
|
|
case PROP_CRTC_MODE:
|
|
|
|
g_value_set_object (value, priv->crtc_mode);
|
|
|
|
break;
|
|
|
|
case PROP_OUTPUT:
|
|
|
|
g_value_set_object (value, priv->output);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_virtual_monitor_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MetaVirtualMonitor *virtual_monitor = META_VIRTUAL_MONITOR (object);
|
|
|
|
MetaVirtualMonitorPrivate *priv =
|
|
|
|
meta_virtual_monitor_get_instance_private (virtual_monitor);
|
|
|
|
|
|
|
|
if (!priv->is_destroyed)
|
|
|
|
{
|
|
|
|
g_signal_emit (virtual_monitor, signals[DESTROY], 0);
|
|
|
|
priv->is_destroyed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_object (&priv->crtc);
|
|
|
|
g_clear_object (&priv->crtc_mode);
|
|
|
|
g_clear_object (&priv->output);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_virtual_monitor_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_virtual_monitor_init (MetaVirtualMonitor *virtual_monitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_virtual_monitor_class_init (MetaVirtualMonitorClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->set_property = meta_virtual_monitor_set_property;
|
|
|
|
object_class->get_property = meta_virtual_monitor_get_property;
|
|
|
|
object_class->dispose = meta_virtual_monitor_dispose;
|
|
|
|
|
|
|
|
obj_props[PROP_CRTC] =
|
|
|
|
g_param_spec_object ("crtc",
|
|
|
|
"crtc",
|
|
|
|
"The virtual CRTC",
|
|
|
|
META_TYPE_CRTC,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
obj_props[PROP_CRTC_MODE] =
|
|
|
|
g_param_spec_object ("crtc-mode",
|
|
|
|
"crtc-mode",
|
|
|
|
"The virtual CRTC mode",
|
|
|
|
META_TYPE_CRTC_MODE,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
obj_props[PROP_OUTPUT] =
|
|
|
|
g_param_spec_object ("output",
|
|
|
|
"output",
|
|
|
|
"The virtual output",
|
|
|
|
META_TYPE_OUTPUT,
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
|
|
|
|
|
|
|
signals[DESTROY] =
|
|
|
|
g_signal_new ("destroy",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|