2013-07-30 09:36:18 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2014-05-02 13:34:02 +00:00
|
|
|
/*
|
2013-07-30 09:36:18 +00:00
|
|
|
* Copyright (C) 2013 Red Hat Inc.
|
2014-05-02 13:34:02 +00:00
|
|
|
*
|
2013-07-30 09:36:18 +00:00
|
|
|
* 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.
|
2014-05-02 13:34:02 +00:00
|
|
|
*
|
2013-07-30 09:36:18 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Author: Giovanni Campagna <gcampagn@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2014-03-31 00:25:31 +00:00
|
|
|
#include "meta-monitor-manager-kms.h"
|
2017-01-09 06:31:18 +00:00
|
|
|
#include "meta-monitor-config-manager.h"
|
2017-03-28 04:35:19 +00:00
|
|
|
#include "meta-crtc.h"
|
2017-03-24 09:35:51 +00:00
|
|
|
#include "meta-output.h"
|
2016-05-09 11:51:29 +00:00
|
|
|
#include "meta-backend-private.h"
|
|
|
|
#include "meta-renderer-native.h"
|
2014-03-31 00:25:31 +00:00
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
#include <drm.h>
|
2013-07-30 09:36:18 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
|
|
|
#include <meta/main.h>
|
|
|
|
#include <meta/errors.h>
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
#include <gudev/gudev.h>
|
|
|
|
|
2015-02-14 20:03:38 +00:00
|
|
|
#include "meta-default-modes.h"
|
|
|
|
|
2015-12-18 11:16:59 +00:00
|
|
|
#define ALL_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
|
2016-08-01 01:51:36 +00:00
|
|
|
#define ALL_TRANSFORMS_MASK ((1 << ALL_TRANSFORMS) - 1)
|
2015-02-14 20:03:38 +00:00
|
|
|
#define SYNC_TOLERANCE 0.01 /* 1 percent */
|
2015-12-18 11:16:59 +00:00
|
|
|
|
2016-12-21 08:04:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-07-30 09:36:18 +00:00
|
|
|
drmModeConnector *connector;
|
|
|
|
|
|
|
|
unsigned n_encoders;
|
|
|
|
drmModeEncoderPtr *encoders;
|
|
|
|
drmModeEncoderPtr current_encoder;
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
/*
|
|
|
|
* Bitmasks of encoder position in the resources array (used during clone
|
|
|
|
* setup).
|
|
|
|
*/
|
2013-07-30 09:36:18 +00:00
|
|
|
uint32_t encoder_mask;
|
|
|
|
uint32_t enc_clone_mask;
|
|
|
|
|
|
|
|
uint32_t dpms_prop_id;
|
|
|
|
uint32_t edid_blob_id;
|
2015-03-31 00:41:51 +00:00
|
|
|
uint32_t tile_blob_id;
|
2015-06-03 19:50:28 +00:00
|
|
|
|
|
|
|
int suggested_x;
|
|
|
|
int suggested_y;
|
|
|
|
uint32_t hotplug_mode_update;
|
2015-02-14 20:03:38 +00:00
|
|
|
|
|
|
|
gboolean has_scaling;
|
2013-07-30 09:36:18 +00:00
|
|
|
} MetaOutputKms;
|
|
|
|
|
2016-12-21 08:04:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-04-28 00:42:10 +00:00
|
|
|
uint32_t underscan_prop_id;
|
|
|
|
uint32_t underscan_hborder_prop_id;
|
|
|
|
uint32_t underscan_vborder_prop_id;
|
2015-12-18 11:16:59 +00:00
|
|
|
uint32_t primary_plane_id;
|
|
|
|
uint32_t rotation_prop_id;
|
|
|
|
uint32_t rotation_map[ALL_TRANSFORMS];
|
2016-07-31 21:41:26 +00:00
|
|
|
uint32_t all_hw_transforms;
|
2016-12-08 04:15:28 +00:00
|
|
|
} MetaCrtcKms;
|
2015-04-28 00:42:10 +00:00
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
gpointer fd_tag;
|
|
|
|
MetaMonitorManagerKms *manager_kms;
|
|
|
|
} MetaKmsSource;
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
struct _MetaMonitorManagerKms
|
|
|
|
{
|
|
|
|
MetaMonitorManager parent_instance;
|
|
|
|
|
|
|
|
int fd;
|
2016-05-12 06:55:06 +00:00
|
|
|
MetaKmsSource *source;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
drmModeConnector **connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
GUdevClient *udev;
|
2017-03-10 07:11:56 +00:00
|
|
|
guint uevent_handler_id;
|
2015-02-22 19:21:37 +00:00
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
gboolean page_flips_not_supported;
|
2017-02-15 08:06:46 +00:00
|
|
|
|
|
|
|
int max_buffer_width;
|
|
|
|
int max_buffer_height;
|
2013-07-30 09:36:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaMonitorManagerKmsClass
|
|
|
|
{
|
|
|
|
MetaMonitorManagerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorManagerKms, meta_monitor_manager_kms, META_TYPE_MONITOR_MANAGER);
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_resources (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < manager_kms->n_connectors; i++)
|
|
|
|
drmModeFreeConnector (manager_kms->connectors[i]);
|
|
|
|
|
|
|
|
g_free (manager_kms->connectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-03-24 09:35:51 +00:00
|
|
|
compare_outputs (gconstpointer one,
|
|
|
|
gconstpointer two)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
|
|
|
const MetaOutput *o_one = one, *o_two = two;
|
|
|
|
|
|
|
|
return strcmp (o_one->name, o_two->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
make_output_name (drmModeConnector *connector)
|
|
|
|
{
|
|
|
|
static const char * const connector_type_names[] = {
|
2016-08-24 12:38:30 +00:00
|
|
|
"None",
|
|
|
|
"VGA",
|
|
|
|
"DVI-I",
|
|
|
|
"DVI-D",
|
|
|
|
"DVI-A",
|
|
|
|
"Composite",
|
|
|
|
"SVIDEO",
|
|
|
|
"LVDS",
|
|
|
|
"Component",
|
|
|
|
"DIN",
|
|
|
|
"DP",
|
|
|
|
"HDMI",
|
|
|
|
"HDMI-B",
|
|
|
|
"TV",
|
|
|
|
"eDP",
|
|
|
|
"Virtual",
|
|
|
|
"DSI",
|
2013-07-30 09:36:18 +00:00
|
|
|
};
|
|
|
|
|
2013-12-20 13:03:41 +00:00
|
|
|
if (connector->connector_type < G_N_ELEMENTS (connector_type_names))
|
2016-08-24 12:47:51 +00:00
|
|
|
return g_strdup_printf ("%s-%d",
|
|
|
|
connector_type_names[connector->connector_type],
|
|
|
|
connector->connector_type_id);
|
2013-07-30 09:36:18 +00:00
|
|
|
else
|
2016-08-24 12:47:51 +00:00
|
|
|
return g_strdup_printf ("Unknown%d-%d",
|
|
|
|
connector->connector_type,
|
|
|
|
connector->connector_type_id);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_output_destroy_notify (MetaOutput *output)
|
|
|
|
{
|
|
|
|
MetaOutputKms *output_kms;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
output_kms = output->driver_private;
|
|
|
|
|
|
|
|
for (i = 0; i < output_kms->n_encoders; i++)
|
|
|
|
drmModeFreeEncoder (output_kms->encoders[i]);
|
|
|
|
g_free (output_kms->encoders);
|
|
|
|
|
|
|
|
g_slice_free (MetaOutputKms, output_kms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-09 07:49:54 +00:00
|
|
|
meta_monitor_mode_destroy_notify (MetaCrtcMode *mode)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2016-12-09 07:49:54 +00:00
|
|
|
g_slice_free (drmModeModeInfo, mode->driver_private);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 00:42:10 +00:00
|
|
|
static void
|
2016-12-08 04:15:28 +00:00
|
|
|
meta_crtc_destroy_notify (MetaCrtc *crtc)
|
2015-04-28 00:42:10 +00:00
|
|
|
{
|
|
|
|
g_free (crtc->driver_private);
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
static gboolean
|
|
|
|
drm_mode_equal (gconstpointer one,
|
|
|
|
gconstpointer two)
|
|
|
|
{
|
|
|
|
const drmModeModeInfo *m_one = one;
|
|
|
|
const drmModeModeInfo *m_two = two;
|
|
|
|
|
|
|
|
return m_one->clock == m_two->clock &&
|
|
|
|
m_one->hdisplay == m_two->hdisplay &&
|
|
|
|
m_one->hsync_start == m_two->hsync_start &&
|
|
|
|
m_one->hsync_end == m_two->hsync_end &&
|
|
|
|
m_one->htotal == m_two->htotal &&
|
|
|
|
m_one->hskew == m_two->hskew &&
|
|
|
|
m_one->vdisplay == m_two->vdisplay &&
|
|
|
|
m_one->vsync_start == m_two->vsync_start &&
|
|
|
|
m_one->vsync_end == m_two->vsync_end &&
|
|
|
|
m_one->vtotal == m_two->vtotal &&
|
|
|
|
m_one->vscan == m_two->vscan &&
|
|
|
|
m_one->vrefresh == m_two->vrefresh &&
|
|
|
|
m_one->flags == m_two->flags &&
|
|
|
|
m_one->type == m_two->type &&
|
|
|
|
strncmp (m_one->name, m_two->name, DRM_DISPLAY_MODE_LEN) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
drm_mode_hash (gconstpointer ptr)
|
|
|
|
{
|
|
|
|
const drmModeModeInfo *mode = ptr;
|
|
|
|
guint hash = 0;
|
|
|
|
|
|
|
|
/* We don't include the name in the hash because it's generally
|
|
|
|
derived from the other fields (hdisplay, vdisplay and flags)
|
|
|
|
*/
|
|
|
|
|
|
|
|
hash ^= mode->clock;
|
|
|
|
hash ^= mode->hdisplay ^ mode->hsync_start ^ mode->hsync_end;
|
|
|
|
hash ^= mode->vdisplay ^ mode->vsync_start ^ mode->vsync_end;
|
|
|
|
hash ^= mode->vrefresh;
|
|
|
|
hash ^= mode->flags ^ mode->type;
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-04-28 00:42:10 +00:00
|
|
|
find_connector_properties (MetaMonitorManagerKms *manager_kms,
|
|
|
|
MetaOutputKms *output_kms)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-06-03 19:50:28 +00:00
|
|
|
output_kms->hotplug_mode_update = 0;
|
|
|
|
output_kms->suggested_x = -1;
|
|
|
|
output_kms->suggested_y = -1;
|
2013-07-30 09:36:18 +00:00
|
|
|
for (i = 0; i < output_kms->connector->count_props; i++)
|
|
|
|
{
|
2015-04-28 00:42:10 +00:00
|
|
|
drmModePropertyPtr prop = drmModeGetProperty (manager_kms->fd, output_kms->connector->props[i]);
|
2013-07-30 09:36:18 +00:00
|
|
|
if (!prop)
|
|
|
|
continue;
|
|
|
|
|
2015-04-28 00:42:10 +00:00
|
|
|
if ((prop->flags & DRM_MODE_PROP_ENUM) && strcmp (prop->name, "DPMS") == 0)
|
2013-07-30 09:36:18 +00:00
|
|
|
output_kms->dpms_prop_id = prop->prop_id;
|
2015-04-28 00:42:10 +00:00
|
|
|
else if ((prop->flags & DRM_MODE_PROP_BLOB) && strcmp (prop->name, "EDID") == 0)
|
2013-07-30 09:36:18 +00:00
|
|
|
output_kms->edid_blob_id = output_kms->connector->prop_values[i];
|
2015-06-03 19:50:28 +00:00
|
|
|
else if ((prop->flags & DRM_MODE_PROP_BLOB) &&
|
2015-03-31 00:41:51 +00:00
|
|
|
strcmp (prop->name, "TILE") == 0)
|
|
|
|
output_kms->tile_blob_id = output_kms->connector->prop_values[i];
|
2015-06-03 19:50:28 +00:00
|
|
|
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
|
|
|
|
strcmp (prop->name, "suggested X") == 0)
|
|
|
|
output_kms->suggested_x = output_kms->connector->prop_values[i];
|
|
|
|
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
|
|
|
|
strcmp (prop->name, "suggested Y") == 0)
|
|
|
|
output_kms->suggested_y = output_kms->connector->prop_values[i];
|
|
|
|
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
|
|
|
|
strcmp (prop->name, "hotplug_mode_update") == 0)
|
|
|
|
output_kms->hotplug_mode_update = output_kms->connector->prop_values[i];
|
2015-02-14 20:03:38 +00:00
|
|
|
else if (strcmp (prop->name, "scaling mode") == 0)
|
|
|
|
output_kms->has_scaling = TRUE;
|
|
|
|
|
2014-12-15 22:15:46 +00:00
|
|
|
drmModeFreeProperty (prop);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 00:42:10 +00:00
|
|
|
static void
|
|
|
|
find_crtc_properties (MetaMonitorManagerKms *manager_kms,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *meta_crtc)
|
2015-04-28 00:42:10 +00:00
|
|
|
{
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtcKms *crtc_kms;
|
2015-04-28 00:42:10 +00:00
|
|
|
drmModeObjectPropertiesPtr props;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
crtc_kms = meta_crtc->driver_private;
|
|
|
|
|
|
|
|
props = drmModeObjectGetProperties (manager_kms->fd, meta_crtc->crtc_id, DRM_MODE_OBJECT_CRTC);
|
2015-04-28 14:52:20 +00:00
|
|
|
if (!props)
|
|
|
|
return;
|
|
|
|
|
2015-04-28 00:42:10 +00:00
|
|
|
for (i = 0; i < props->count_props; i++)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr prop = drmModeGetProperty (manager_kms->fd, props->props[i]);
|
|
|
|
if (!prop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((prop->flags & DRM_MODE_PROP_ENUM) && strcmp (prop->name, "underscan") == 0)
|
|
|
|
crtc_kms->underscan_prop_id = prop->prop_id;
|
|
|
|
else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan hborder") == 0)
|
|
|
|
crtc_kms->underscan_hborder_prop_id = prop->prop_id;
|
|
|
|
else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan vborder") == 0)
|
|
|
|
crtc_kms->underscan_vborder_prop_id = prop->prop_id;
|
|
|
|
|
|
|
|
drmModeFreeProperty (prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
static drmModePropertyBlobPtr
|
|
|
|
read_edid_blob (MetaMonitorManagerKms *manager_kms,
|
|
|
|
uint32_t edid_blob_id,
|
|
|
|
GError **error)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
|
|
|
drmModePropertyBlobPtr edid_blob = NULL;
|
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
edid_blob = drmModeGetPropertyBlob (manager_kms->fd, edid_blob_id);
|
2013-07-30 09:36:18 +00:00
|
|
|
if (!edid_blob)
|
|
|
|
{
|
2016-12-21 08:00:29 +00:00
|
|
|
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
|
2017-03-10 07:12:52 +00:00
|
|
|
"%s", strerror (errno));
|
2013-07-30 09:36:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
return edid_blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GBytes *
|
|
|
|
read_output_edid (MetaMonitorManagerKms *manager_kms,
|
|
|
|
MetaOutput *output,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
|
|
|
drmModePropertyBlobPtr edid_blob;
|
|
|
|
|
|
|
|
g_assert (output_kms->edid_blob_id != 0);
|
|
|
|
|
|
|
|
edid_blob = read_edid_blob (manager_kms, output_kms->edid_blob_id, error);
|
|
|
|
if (!edid_blob)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (edid_blob->length == 0)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2016-12-21 08:00:29 +00:00
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "EDID blob was empty");
|
2013-07-30 09:36:18 +00:00
|
|
|
drmModeFreePropertyBlob (edid_blob);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-12-21 08:00:29 +00:00
|
|
|
|
|
|
|
return g_bytes_new_with_free_func (edid_blob->data, edid_blob->length,
|
|
|
|
(GDestroyNotify) drmModeFreePropertyBlob,
|
|
|
|
edid_blob);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 00:41:51 +00:00
|
|
|
static gboolean
|
|
|
|
output_get_tile_info (MetaMonitorManagerKms *manager_kms,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
|
|
|
drmModePropertyBlobPtr tile_blob = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (output_kms->tile_blob_id == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
tile_blob = drmModeGetPropertyBlob (manager_kms->fd, output_kms->tile_blob_id);
|
|
|
|
if (!tile_blob)
|
|
|
|
{
|
|
|
|
meta_warning ("Failed to read TILE of output %s: %s\n", output->name, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile_blob->length > 0)
|
|
|
|
{
|
|
|
|
ret = sscanf ((char *)tile_blob->data, "%d:%d:%d:%d:%d:%d:%d:%d",
|
|
|
|
&output->tile_info.group_id,
|
|
|
|
&output->tile_info.flags,
|
|
|
|
&output->tile_info.max_h_tiles,
|
|
|
|
&output->tile_info.max_v_tiles,
|
|
|
|
&output->tile_info.loc_h_tile,
|
|
|
|
&output->tile_info.loc_v_tile,
|
|
|
|
&output->tile_info.tile_w,
|
|
|
|
&output->tile_info.tile_h);
|
2016-11-24 09:27:08 +00:00
|
|
|
drmModeFreePropertyBlob (tile_blob);
|
2015-03-31 00:41:51 +00:00
|
|
|
|
|
|
|
if (ret != 8)
|
2016-11-24 09:27:08 +00:00
|
|
|
{
|
|
|
|
meta_warning ("Couldn't understand output tile property blob\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-03-31 00:41:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drmModeFreePropertyBlob (tile_blob);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 07:49:54 +00:00
|
|
|
static MetaCrtcMode *
|
2017-03-28 08:44:57 +00:00
|
|
|
mode_from_drm_mode (MetaMonitorManager *manager,
|
|
|
|
const drmModeModeInfo *drm_mode)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
|
|
|
unsigned k;
|
|
|
|
|
|
|
|
for (k = 0; k < manager->n_modes; k++)
|
|
|
|
{
|
|
|
|
if (drm_mode_equal (drm_mode, manager->modes[k].driver_private))
|
|
|
|
return &manager->modes[k];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:03:38 +00:00
|
|
|
static float
|
|
|
|
drm_mode_vrefresh (const drmModeModeInfo *mode)
|
|
|
|
{
|
|
|
|
float refresh = 0.0;
|
|
|
|
|
|
|
|
if (mode->htotal > 0 && mode->vtotal > 0)
|
|
|
|
{
|
|
|
|
/* Calculate refresh rate in milliHz first for extra precision. */
|
|
|
|
refresh = (mode->clock * 1000000LL) / mode->htotal;
|
|
|
|
refresh += (mode->vtotal / 2);
|
|
|
|
refresh /= mode->vtotal;
|
|
|
|
if (mode->vscan > 1)
|
|
|
|
refresh /= mode->vscan;
|
|
|
|
refresh /= 1000.0;
|
|
|
|
}
|
|
|
|
return refresh;
|
|
|
|
}
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
static void
|
2016-12-09 07:49:54 +00:00
|
|
|
init_mode (MetaCrtcMode *mode,
|
2015-02-14 20:03:38 +00:00
|
|
|
const drmModeModeInfo *drm_mode,
|
|
|
|
long mode_id)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
|
|
|
mode->mode_id = mode_id;
|
|
|
|
mode->name = g_strndup (drm_mode->name, DRM_DISPLAY_MODE_LEN);
|
|
|
|
mode->width = drm_mode->hdisplay;
|
|
|
|
mode->height = drm_mode->vdisplay;
|
|
|
|
mode->flags = drm_mode->flags;
|
2015-02-14 20:03:38 +00:00
|
|
|
mode->refresh_rate = drm_mode_vrefresh (drm_mode);
|
2016-08-01 09:25:52 +00:00
|
|
|
mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode);
|
|
|
|
mode->driver_notify = (GDestroyNotify)meta_monitor_mode_destroy_notify;
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:03:38 +00:00
|
|
|
static int
|
|
|
|
compare_modes (const void *one,
|
|
|
|
const void *two)
|
|
|
|
{
|
2016-12-09 07:49:54 +00:00
|
|
|
MetaCrtcMode *a = *(MetaCrtcMode **) one;
|
|
|
|
MetaCrtcMode *b = *(MetaCrtcMode **) two;
|
2015-02-14 20:03:38 +00:00
|
|
|
|
|
|
|
if (a->width != b->width)
|
|
|
|
return a->width > b->width ? -1 : 1;
|
|
|
|
if (a->height != b->height)
|
|
|
|
return a->height > b->height ? -1 : 1;
|
|
|
|
if (a->refresh_rate != b->refresh_rate)
|
|
|
|
return a->refresh_rate > b->refresh_rate ? -1 : 1;
|
|
|
|
|
|
|
|
return g_strcmp0 (b->name, a->name);
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
static MetaOutput *
|
2017-03-24 09:35:51 +00:00
|
|
|
find_output_by_id (GList *outputs,
|
|
|
|
glong id)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
if (output->winsys_id == id)
|
|
|
|
return output;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-18 11:16:59 +00:00
|
|
|
static int
|
|
|
|
find_property_index (MetaMonitorManager *manager,
|
|
|
|
drmModeObjectPropertiesPtr props,
|
|
|
|
const gchar *prop_name,
|
|
|
|
drmModePropertyPtr *found)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < props->count_props; i++)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr prop;
|
|
|
|
|
|
|
|
prop = drmModeGetProperty (manager_kms->fd, props->props[i]);
|
|
|
|
if (!prop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp (prop->name, prop_name) == 0)
|
|
|
|
{
|
|
|
|
*found = prop;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
drmModeFreeProperty (prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_transforms (MetaMonitorManager *manager,
|
|
|
|
drmModePropertyPtr prop,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc)
|
2015-12-18 11:16:59 +00:00
|
|
|
{
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2015-12-18 11:16:59 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < prop->count_enums; i++)
|
|
|
|
{
|
|
|
|
int cur = -1;
|
|
|
|
|
|
|
|
if (strcmp (prop->enums[i].name, "rotate-0") == 0)
|
|
|
|
cur = META_MONITOR_TRANSFORM_NORMAL;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-90") == 0)
|
|
|
|
cur = META_MONITOR_TRANSFORM_90;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-180") == 0)
|
|
|
|
cur = META_MONITOR_TRANSFORM_180;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-270") == 0)
|
|
|
|
cur = META_MONITOR_TRANSFORM_270;
|
|
|
|
|
|
|
|
if (cur != -1)
|
|
|
|
{
|
2016-07-31 21:41:26 +00:00
|
|
|
crtc_kms->all_hw_transforms |= 1 << cur;
|
2015-12-18 11:16:59 +00:00
|
|
|
crtc_kms->rotation_map[cur] = 1 << prop->enums[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_primary_plane (MetaMonitorManager *manager,
|
|
|
|
drmModeObjectPropertiesPtr props)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr prop;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = find_property_index (manager, props, "type", &prop);
|
|
|
|
if (idx < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
drmModeFreeProperty (prop);
|
|
|
|
return props->prop_values[idx] == DRM_PLANE_TYPE_PRIMARY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_crtc_rotations (MetaMonitorManager *manager,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2015-12-18 11:16:59 +00:00
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
drmModeObjectPropertiesPtr props;
|
|
|
|
drmModePlaneRes *planes;
|
|
|
|
drmModePlane *drm_plane;
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtcKms *crtc_kms;
|
2015-12-18 11:16:59 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
crtc_kms = crtc->driver_private;
|
|
|
|
|
|
|
|
planes = drmModeGetPlaneResources(manager_kms->fd);
|
|
|
|
if (planes == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < planes->count_planes; i++)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr prop;
|
|
|
|
|
|
|
|
drm_plane = drmModeGetPlane (manager_kms->fd, planes->planes[i]);
|
|
|
|
|
|
|
|
if (!drm_plane)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((drm_plane->possible_crtcs & (1 << idx)))
|
|
|
|
{
|
|
|
|
props = drmModeObjectGetProperties (manager_kms->fd,
|
|
|
|
drm_plane->plane_id,
|
|
|
|
DRM_MODE_OBJECT_PLANE);
|
|
|
|
|
|
|
|
if (props && is_primary_plane (manager, props))
|
|
|
|
{
|
|
|
|
int rotation_idx;
|
|
|
|
|
|
|
|
crtc_kms->primary_plane_id = drm_plane->plane_id;
|
|
|
|
rotation_idx = find_property_index (manager, props, "rotation", &prop);
|
|
|
|
|
|
|
|
if (rotation_idx >= 0)
|
|
|
|
{
|
|
|
|
crtc_kms->rotation_prop_id = props->props[rotation_idx];
|
|
|
|
parse_transforms (manager, prop, crtc);
|
|
|
|
drmModeFreeProperty (prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props)
|
|
|
|
drmModeFreeObjectProperties (props);
|
|
|
|
}
|
|
|
|
|
|
|
|
drmModeFreePlane (drm_plane);
|
|
|
|
}
|
2016-01-07 18:35:12 +00:00
|
|
|
|
2016-07-31 21:41:26 +00:00
|
|
|
crtc->all_transforms |= crtc_kms->all_hw_transforms;
|
|
|
|
|
2016-01-07 18:35:12 +00:00
|
|
|
drmModeFreePlaneResources (planes);
|
2015-12-18 11:16:59 +00:00
|
|
|
}
|
|
|
|
|
2015-02-14 20:03:38 +00:00
|
|
|
static void
|
|
|
|
add_common_modes (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2017-03-28 08:44:57 +00:00
|
|
|
const drmModeModeInfo *drm_mode;
|
2015-02-14 20:03:38 +00:00
|
|
|
GPtrArray *array;
|
|
|
|
unsigned i;
|
|
|
|
unsigned max_hdisplay = 0;
|
|
|
|
unsigned max_vdisplay = 0;
|
|
|
|
float max_vrefresh = 0.0;
|
|
|
|
|
|
|
|
for (i = 0; i < output->n_modes; i++)
|
|
|
|
{
|
2017-03-28 08:44:57 +00:00
|
|
|
drm_mode = output->modes[i]->driver_private;
|
|
|
|
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
|
|
|
|
max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay);
|
|
|
|
max_vrefresh = MAX (max_vrefresh, drm_mode_vrefresh (drm_mode));
|
2015-02-14 20:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
max_vrefresh = MAX (max_vrefresh, 60.0);
|
|
|
|
max_vrefresh *= (1 + SYNC_TOLERANCE);
|
|
|
|
|
|
|
|
array = g_ptr_array_new ();
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
|
|
|
{
|
2017-03-28 08:44:57 +00:00
|
|
|
drm_mode = &meta_default_drm_mode_infos[i];
|
|
|
|
if (drm_mode->hdisplay > max_hdisplay ||
|
|
|
|
drm_mode->vdisplay > max_vdisplay ||
|
|
|
|
drm_mode_vrefresh (drm_mode) > max_vrefresh)
|
2015-02-14 20:03:38 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-28 08:44:57 +00:00
|
|
|
g_ptr_array_add (array, mode_from_drm_mode (manager, drm_mode));
|
2015-02-14 20:03:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 07:49:54 +00:00
|
|
|
output->modes = g_renew (MetaCrtcMode *, output->modes,
|
|
|
|
output->n_modes + array->len);
|
|
|
|
memcpy (output->modes + output->n_modes, array->pdata,
|
|
|
|
array->len * sizeof (MetaCrtcMode *));
|
2015-02-14 20:03:38 +00:00
|
|
|
output->n_modes += array->len;
|
|
|
|
|
|
|
|
g_ptr_array_free (array, TRUE);
|
|
|
|
}
|
|
|
|
|
2017-03-28 04:35:19 +00:00
|
|
|
static MetaCrtc *
|
|
|
|
create_crtc (MetaMonitorManager *manager,
|
|
|
|
drmModeCrtc *drm_crtc)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
MetaCrtc *crtc;
|
2016-08-01 09:25:52 +00:00
|
|
|
unsigned int i;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-28 04:35:19 +00:00
|
|
|
crtc = g_object_new (META_TYPE_CRTC, NULL);
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
crtc->crtc_id = drm_crtc->crtc_id;
|
|
|
|
crtc->rect.x = drm_crtc->x;
|
|
|
|
crtc->rect.y = drm_crtc->y;
|
|
|
|
crtc->rect.width = drm_crtc->width;
|
|
|
|
crtc->rect.height = drm_crtc->height;
|
|
|
|
crtc->is_dirty = FALSE;
|
|
|
|
crtc->transform = META_MONITOR_TRANSFORM_NORMAL;
|
2016-08-01 01:51:36 +00:00
|
|
|
crtc->all_transforms = meta_is_stage_views_enabled () ?
|
|
|
|
ALL_TRANSFORMS_MASK : META_MONITOR_TRANSFORM_NORMAL;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
if (drm_crtc->mode_valid)
|
|
|
|
{
|
|
|
|
for (i = 0; i < manager->n_modes; i++)
|
|
|
|
{
|
|
|
|
if (drm_mode_equal (&drm_crtc->mode, manager->modes[i].driver_private))
|
|
|
|
{
|
|
|
|
crtc->current_mode = &manager->modes[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-12-08 04:15:28 +00:00
|
|
|
crtc->driver_private = g_new0 (MetaCrtcKms, 1);
|
2016-08-01 09:25:52 +00:00
|
|
|
crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify;
|
2017-03-28 04:35:19 +00:00
|
|
|
|
|
|
|
return crtc;
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
static MetaOutput *
|
|
|
|
create_output (MetaMonitorManager *manager,
|
|
|
|
drmModeConnector *connector,
|
|
|
|
MetaOutput *old_output)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output;
|
2016-08-01 09:25:52 +00:00
|
|
|
MetaOutputKms *output_kms;
|
|
|
|
GArray *crtcs;
|
|
|
|
GBytes *edid;
|
2017-03-28 04:35:19 +00:00
|
|
|
GList *l;
|
2016-08-01 09:25:52 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int crtc_mask;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
output = g_object_new (META_TYPE_OUTPUT, NULL);
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output_kms = g_slice_new0 (MetaOutputKms);
|
|
|
|
output->driver_private = output_kms;
|
|
|
|
output->driver_notify = (GDestroyNotify)meta_output_destroy_notify;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output->winsys_id = connector->connector_id;
|
|
|
|
output->name = make_output_name (connector);
|
|
|
|
output->width_mm = connector->mmWidth;
|
|
|
|
output->height_mm = connector->mmHeight;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
switch (connector->subpixel)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2016-08-01 09:25:52 +00:00
|
|
|
case DRM_MODE_SUBPIXEL_NONE:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_NONE;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_RGB;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_BGR;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SUBPIXEL_UNKNOWN:
|
|
|
|
default:
|
|
|
|
output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output->preferred_mode = NULL;
|
|
|
|
output->n_modes = connector->count_modes;
|
2016-12-09 07:49:54 +00:00
|
|
|
output->modes = g_new0 (MetaCrtcMode *, output->n_modes);
|
2016-08-01 09:25:52 +00:00
|
|
|
for (i = 0; i < output->n_modes; i++) {
|
2017-03-28 08:44:57 +00:00
|
|
|
output->modes[i] = mode_from_drm_mode (manager, &connector->modes[i]);
|
2016-08-01 09:25:52 +00:00
|
|
|
if (connector->modes[i].type & DRM_MODE_TYPE_PREFERRED)
|
|
|
|
output->preferred_mode = output->modes[i];
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
if (!output->preferred_mode)
|
|
|
|
output->preferred_mode = output->modes[0];
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output_kms->connector = connector;
|
2015-02-14 20:03:38 +00:00
|
|
|
find_connector_properties (manager_kms, output_kms);
|
|
|
|
|
|
|
|
/* FIXME: MSC feature bit? */
|
|
|
|
/* Presume that if the output supports scaling, then we have
|
|
|
|
* a panel fitter capable of adjusting any mode to suit.
|
|
|
|
*/
|
|
|
|
if (output_kms->has_scaling)
|
|
|
|
add_common_modes (manager, output);
|
|
|
|
|
2016-12-09 07:49:54 +00:00
|
|
|
qsort (output->modes, output->n_modes, sizeof (MetaCrtcMode *), compare_modes);
|
2015-02-14 20:03:38 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output_kms->n_encoders = connector->count_encoders;
|
|
|
|
output_kms->encoders = g_new0 (drmModeEncoderPtr, output_kms->n_encoders);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
crtc_mask = ~(unsigned int) 0;
|
|
|
|
for (i = 0; i < output_kms->n_encoders; i++)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2016-08-01 09:25:52 +00:00
|
|
|
output_kms->encoders[i] = drmModeGetEncoder (manager_kms->fd,
|
|
|
|
connector->encoders[i]);
|
|
|
|
if (!output_kms->encoders[i])
|
|
|
|
continue;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
/* We only list CRTCs as supported if they are supported by all encoders
|
|
|
|
for this connectors.
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
This is what xf86-video-modesetting does (see drmmode_output_init())
|
|
|
|
*/
|
|
|
|
crtc_mask &= output_kms->encoders[i]->possible_crtcs;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
if (output_kms->encoders[i]->encoder_id == connector->encoder_id)
|
|
|
|
output_kms->current_encoder = output_kms->encoders[i];
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-12-08 04:15:28 +00:00
|
|
|
crtcs = g_array_new (FALSE, FALSE, sizeof (MetaCrtc*));
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-28 04:35:19 +00:00
|
|
|
for (l = manager->crtcs, i = 0; l; l = l->next, i++)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
|
|
|
if (crtc_mask & (1 << i))
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
MetaCrtc *crtc = l->data;
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
g_array_append_val (crtcs, crtc);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output->n_possible_crtcs = crtcs->len;
|
|
|
|
output->possible_crtcs = (void*)g_array_free (crtcs, FALSE);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
if (output_kms->current_encoder && output_kms->current_encoder->crtc_id != 0)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
for (l = manager->crtcs; l; l = l->next)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
MetaCrtc *crtc = l->data;
|
|
|
|
|
|
|
|
if (crtc->crtc_id == output_kms->current_encoder->crtc_id)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
output->crtc = crtc;
|
2013-07-30 09:36:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output->crtc = NULL;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
if (old_output)
|
|
|
|
{
|
|
|
|
output->is_primary = old_output->is_primary;
|
|
|
|
output->is_presentation = old_output->is_presentation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output->is_primary = FALSE;
|
|
|
|
output->is_presentation = FALSE;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output->suggested_x = output_kms->suggested_x;
|
|
|
|
output->suggested_y = output_kms->suggested_y;
|
|
|
|
output->hotplug_mode_update = output_kms->hotplug_mode_update;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
if (output_kms->edid_blob_id != 0)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
edid = read_output_edid (manager_kms, output, &error);
|
|
|
|
if (!edid)
|
|
|
|
{
|
2017-03-10 07:12:52 +00:00
|
|
|
g_warning ("Failed to read EDID blob from %s: %s",
|
|
|
|
output->name, error->message);
|
2016-12-21 08:00:29 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edid = NULL;
|
|
|
|
}
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
meta_output_parse_edid (output, edid);
|
|
|
|
g_bytes_unref (edid);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
/* MetaConnectorType matches DRM's connector types */
|
|
|
|
output->connector_type = (MetaConnectorType) connector->connector_type;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
output_get_tile_info (manager_kms, output);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
/* FIXME: backlight is a very driver specific thing unfortunately,
|
|
|
|
every DDX does its own thing, and the dumb KMS API does not include it.
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
For example, xf86-video-intel has a list of paths to probe in /sys/class/backlight
|
|
|
|
(one for each major HW maker, and then some).
|
|
|
|
We can't do the same because we're not root.
|
|
|
|
It might be best to leave backlight out of the story and rely on the setuid
|
|
|
|
helper in gnome-settings-daemon.
|
|
|
|
*/
|
|
|
|
output->backlight_min = 0;
|
|
|
|
output->backlight_max = 0;
|
|
|
|
output->backlight = -1;
|
2017-03-24 09:35:51 +00:00
|
|
|
|
|
|
|
return output;
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
static void
|
|
|
|
detect_and_setup_output_clones (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
drmModeEncoder **encoders;
|
|
|
|
unsigned int i, n_encoders;
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
n_encoders = (unsigned int) resources->count_encoders;
|
|
|
|
encoders = g_new (drmModeEncoder *, n_encoders);
|
|
|
|
for (i = 0; i < n_encoders; i++)
|
|
|
|
encoders[i] = drmModeGetEncoder (manager_kms->fd, resources->encoders[i]);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
/*
|
|
|
|
* Setup encoder position mask and encoder clone mask.
|
|
|
|
*/
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
2016-08-01 09:25:52 +00:00
|
|
|
unsigned int j;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
output_kms->enc_clone_mask = 0xff;
|
|
|
|
output_kms->encoder_mask = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < output_kms->n_encoders; j++)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
for (k = 0; k < n_encoders; k++)
|
|
|
|
{
|
2015-03-02 16:38:41 +00:00
|
|
|
if (output_kms->encoders[j] && encoders[k] &&
|
|
|
|
output_kms->encoders[j]->encoder_id == encoders[k]->encoder_id)
|
2016-08-01 09:25:52 +00:00
|
|
|
{
|
2013-07-30 09:36:18 +00:00
|
|
|
output_kms->encoder_mask |= (1 << k);
|
2016-08-01 09:25:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
output_kms->enc_clone_mask &= output_kms->encoders[j]->possible_clones;
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
for (i = 0; i < (unsigned)resources->count_encoders; i++)
|
|
|
|
drmModeFreeEncoder (encoders[i]);
|
|
|
|
g_free (encoders);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup MetaOutput <-> MetaOutput clone associations.
|
|
|
|
*/
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
|
|
|
GList *k;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
if (output_kms->enc_clone_mask == 0)
|
|
|
|
continue;
|
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
for (k = manager->outputs; k; k = k->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *clone = k->data;
|
|
|
|
MetaOutputKms *clone_kms = clone->driver_private;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
if (clone == output)
|
2013-07-30 09:36:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (clone_kms->encoder_mask == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (clone_kms->encoder_mask == output_kms->enc_clone_mask)
|
|
|
|
{
|
2016-08-01 09:25:52 +00:00
|
|
|
output->n_possible_clones++;
|
|
|
|
output->possible_clones = g_renew (MetaOutput *,
|
|
|
|
output->possible_clones,
|
|
|
|
output->n_possible_clones);
|
2017-03-24 09:35:51 +00:00
|
|
|
output->possible_clones[output->n_possible_clones - 1] = clone;
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-08-01 09:25:52 +00:00
|
|
|
static void
|
|
|
|
init_connectors (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
manager_kms->n_connectors = resources->count_connectors;
|
|
|
|
manager_kms->connectors = g_new (drmModeConnector *, manager_kms->n_connectors);
|
|
|
|
for (i = 0; i < manager_kms->n_connectors; i++)
|
|
|
|
{
|
|
|
|
drmModeConnector *drm_connector;
|
|
|
|
|
|
|
|
drm_connector = drmModeGetConnector (manager_kms->fd,
|
|
|
|
resources->connectors[i]);
|
|
|
|
manager_kms->connectors[i] = drm_connector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_modes (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
GHashTable *modes;
|
|
|
|
GHashTableIter iter;
|
|
|
|
drmModeModeInfo *drm_mode;
|
|
|
|
unsigned int i;
|
|
|
|
long mode_id;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gather all modes on all connected connectors.
|
|
|
|
*/
|
|
|
|
modes = g_hash_table_new (drm_mode_hash, drm_mode_equal);
|
|
|
|
for (i = 0; i < manager_kms->n_connectors; i++)
|
|
|
|
{
|
|
|
|
drmModeConnector *drm_connector;
|
|
|
|
|
|
|
|
drm_connector = manager_kms->connectors[i];
|
|
|
|
if (drm_connector && drm_connector->connection == DRM_MODE_CONNECTED)
|
|
|
|
{
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
for (j = 0; j < (unsigned int) drm_connector->count_modes; j++)
|
|
|
|
g_hash_table_add (modes, &drm_connector->modes[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:03:38 +00:00
|
|
|
manager->n_modes = g_hash_table_size (modes) + G_N_ELEMENTS (meta_default_drm_mode_infos);
|
2016-12-09 07:49:54 +00:00
|
|
|
manager->modes = g_new0 (MetaCrtcMode, manager->n_modes);
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, modes);
|
|
|
|
mode_id = 0;
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &drm_mode))
|
|
|
|
{
|
2016-12-09 07:49:54 +00:00
|
|
|
MetaCrtcMode *mode;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
mode = &manager->modes[mode_id];
|
|
|
|
init_mode (mode, drm_mode, (long) mode_id);
|
|
|
|
|
|
|
|
mode_id++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_destroy (modes);
|
2015-02-14 20:03:38 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
|
|
|
{
|
2016-12-09 07:49:54 +00:00
|
|
|
MetaCrtcMode *mode;
|
2015-02-14 20:03:38 +00:00
|
|
|
|
|
|
|
mode = &manager->modes[mode_id];
|
|
|
|
init_mode (mode, &meta_default_drm_mode_infos[i], (long) mode_id);
|
|
|
|
|
|
|
|
mode_id++;
|
|
|
|
}
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_crtcs (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
unsigned int i;
|
|
|
|
|
2017-03-28 04:35:19 +00:00
|
|
|
manager->crtcs = NULL;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < (unsigned)resources->count_crtcs; i++)
|
|
|
|
{
|
|
|
|
drmModeCrtc *drm_crtc;
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
drm_crtc = drmModeGetCrtc (manager_kms->fd, resources->crtcs[i]);
|
|
|
|
|
2017-03-28 04:35:19 +00:00
|
|
|
crtc = create_crtc (manager, drm_crtc);
|
2016-08-01 09:25:52 +00:00
|
|
|
find_crtc_properties (manager_kms, crtc);
|
|
|
|
init_crtc_rotations (manager, crtc, i);
|
|
|
|
|
|
|
|
drmModeFreeCrtc (drm_crtc);
|
2017-03-28 04:35:19 +00:00
|
|
|
|
|
|
|
manager->crtcs = g_list_append (manager->crtcs, crtc);
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_outputs (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *old_outputs;
|
2016-08-01 09:25:52 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
old_outputs = manager->outputs;
|
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
manager->outputs = NULL;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < manager_kms->n_connectors; i++)
|
|
|
|
{
|
|
|
|
drmModeConnector *connector;
|
|
|
|
|
|
|
|
connector = manager_kms->connectors[i];
|
|
|
|
|
|
|
|
if (connector && connector->connection == DRM_MODE_CONNECTED)
|
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output;
|
2016-08-01 09:25:52 +00:00
|
|
|
MetaOutput *old_output;
|
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
old_output = find_output_by_id (old_outputs, connector->connector_id);
|
|
|
|
output = create_output (manager, connector, old_output);
|
|
|
|
manager->outputs = g_list_prepend (manager->outputs, output);
|
2016-08-01 09:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Sort the outputs for easier handling in MetaMonitorConfig */
|
2017-03-24 09:35:51 +00:00
|
|
|
manager->outputs = g_list_sort (manager->outputs, compare_outputs);
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
detect_and_setup_output_clones (manager, resources);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_read_current (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
drmModeRes *resources;
|
|
|
|
|
2016-12-21 08:04:23 +00:00
|
|
|
resources = drmModeGetResources (manager_kms->fd);
|
2016-08-01 09:25:52 +00:00
|
|
|
|
2017-02-15 08:06:46 +00:00
|
|
|
manager_kms->max_buffer_width = resources->max_width;
|
|
|
|
manager_kms->max_buffer_height = resources->max_height;
|
2016-08-01 09:25:52 +00:00
|
|
|
|
|
|
|
manager->power_save_mode = META_POWER_SAVE_ON;
|
|
|
|
|
|
|
|
/* Note: we must not free the public structures (output, crtc, monitor
|
|
|
|
mode and monitor info) here, they must be kept alive until the API
|
|
|
|
users are done with them after we emit monitors-changed, and thus
|
|
|
|
are freed by the platform-independent layer. */
|
|
|
|
free_resources (manager_kms);
|
|
|
|
|
|
|
|
init_connectors (manager, resources);
|
|
|
|
init_modes (manager, resources);
|
|
|
|
init_crtcs (manager, resources);
|
|
|
|
init_outputs (manager, resources);
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
drmModeFreeResources (resources);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GBytes *
|
|
|
|
meta_monitor_manager_kms_read_edid (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2016-12-21 08:00:29 +00:00
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
2013-07-30 09:36:18 +00:00
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2016-12-21 08:00:29 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
GBytes *edid;
|
|
|
|
|
|
|
|
if (output_kms->edid_blob_id == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
edid = read_output_edid (manager_kms, output, &error);
|
|
|
|
if (!edid)
|
|
|
|
{
|
|
|
|
g_warning ("Failed to read EDID from '%s': %s",
|
|
|
|
output->name, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
return edid;
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_set_power_save_mode (MetaMonitorManager *manager,
|
|
|
|
MetaPowerSave mode)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
uint64_t state;
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case META_POWER_SAVE_ON:
|
|
|
|
state = DRM_MODE_DPMS_ON;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_STANDBY:
|
|
|
|
state = DRM_MODE_DPMS_STANDBY;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_SUSPEND:
|
|
|
|
state = DRM_MODE_DPMS_SUSPEND;
|
|
|
|
break;
|
|
|
|
case META_POWER_SAVE_OFF:
|
2014-03-03 23:43:12 +00:00
|
|
|
state = DRM_MODE_DPMS_OFF;
|
2013-07-30 09:36:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
|
|
|
MetaOutputKms *output_kms = output->driver_private;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
if (output_kms->dpms_prop_id != 0)
|
|
|
|
{
|
2016-12-21 08:04:23 +00:00
|
|
|
int ok = drmModeObjectSetProperty (manager_kms->fd, output->winsys_id,
|
2015-04-28 00:42:10 +00:00
|
|
|
DRM_MODE_OBJECT_CONNECTOR,
|
|
|
|
output_kms->dpms_prop_id, state);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
if (ok < 0)
|
|
|
|
meta_warning ("Failed to set power save mode for output %s: %s\n",
|
2016-12-21 08:04:23 +00:00
|
|
|
output->name, strerror (errno));
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 00:42:10 +00:00
|
|
|
static void
|
|
|
|
set_underscan (MetaMonitorManagerKms *manager_kms,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
if (!output->crtc)
|
|
|
|
return;
|
|
|
|
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc = output->crtc;
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2015-04-28 00:42:10 +00:00
|
|
|
if (!crtc_kms->underscan_prop_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (output->is_underscanning)
|
|
|
|
{
|
|
|
|
drmModeObjectSetProperty (manager_kms->fd, crtc->crtc_id,
|
|
|
|
DRM_MODE_OBJECT_CRTC,
|
|
|
|
crtc_kms->underscan_prop_id, (uint64_t) 1);
|
|
|
|
|
|
|
|
if (crtc_kms->underscan_hborder_prop_id)
|
|
|
|
{
|
|
|
|
uint64_t value = crtc->current_mode->width * 0.05;
|
|
|
|
drmModeObjectSetProperty (manager_kms->fd, crtc->crtc_id,
|
|
|
|
DRM_MODE_OBJECT_CRTC,
|
|
|
|
crtc_kms->underscan_hborder_prop_id, value);
|
|
|
|
}
|
|
|
|
if (crtc_kms->underscan_vborder_prop_id)
|
|
|
|
{
|
|
|
|
uint64_t value = crtc->current_mode->height * 0.05;
|
|
|
|
drmModeObjectSetProperty (manager_kms->fd, crtc->crtc_id,
|
|
|
|
DRM_MODE_OBJECT_CRTC,
|
|
|
|
crtc_kms->underscan_vborder_prop_id, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drmModeObjectSetProperty (manager_kms->fd, crtc->crtc_id,
|
|
|
|
DRM_MODE_OBJECT_CRTC,
|
|
|
|
crtc_kms->underscan_prop_id, (uint64_t) 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 05:27:21 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_ensure_initial_config (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-01-09 06:31:18 +00:00
|
|
|
MetaMonitorsConfig *config;
|
2017-01-06 05:27:21 +00:00
|
|
|
|
2017-01-09 06:31:18 +00:00
|
|
|
config = meta_monitor_manager_ensure_configured (manager);
|
|
|
|
|
2017-03-24 07:36:12 +00:00
|
|
|
meta_monitor_manager_update_logical_state (manager, config);
|
2017-01-06 05:27:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
static void
|
2017-01-09 06:31:18 +00:00
|
|
|
apply_crtc_assignments (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2015-04-28 00:42:10 +00:00
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2013-07-30 09:36:18 +00:00
|
|
|
unsigned i;
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2016-07-31 21:41:26 +00:00
|
|
|
MetaMonitorTransform hw_transform;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
crtc->is_dirty = TRUE;
|
|
|
|
|
|
|
|
if (crtc_info->mode == NULL)
|
|
|
|
{
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-09 07:49:54 +00:00
|
|
|
MetaCrtcMode *mode;
|
2016-05-12 06:55:06 +00:00
|
|
|
unsigned int j;
|
2013-07-30 09:36:18 +00:00
|
|
|
int width, height;
|
|
|
|
|
|
|
|
mode = crtc_info->mode;
|
|
|
|
|
|
|
|
if (meta_monitor_transform_is_rotated (crtc_info->transform))
|
|
|
|
{
|
|
|
|
width = mode->height;
|
|
|
|
height = mode->width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = mode->width;
|
|
|
|
height = mode->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->rect.x = crtc_info->x;
|
|
|
|
crtc->rect.y = crtc_info->y;
|
|
|
|
crtc->rect.width = width;
|
|
|
|
crtc->rect.height = height;
|
|
|
|
crtc->current_mode = mode;
|
|
|
|
crtc->transform = crtc_info->transform;
|
2016-08-03 07:16:16 +00:00
|
|
|
|
|
|
|
for (j = 0; j < crtc_info->outputs->len; j++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = g_ptr_array_index (crtc_info->outputs, j);
|
|
|
|
|
|
|
|
output->is_dirty = TRUE;
|
|
|
|
output->crtc = crtc;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
2015-12-18 11:16:59 +00:00
|
|
|
|
2016-07-31 21:41:26 +00:00
|
|
|
if (crtc_kms->all_hw_transforms & (1 << crtc->transform))
|
|
|
|
hw_transform = crtc->transform;
|
|
|
|
else
|
|
|
|
hw_transform = META_MONITOR_TRANSFORM_NORMAL;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-10-07 14:52:43 +00:00
|
|
|
if (drmModeObjectSetProperty (manager_kms->fd,
|
|
|
|
crtc_kms->primary_plane_id,
|
|
|
|
DRM_MODE_OBJECT_PLANE,
|
|
|
|
crtc_kms->rotation_prop_id,
|
|
|
|
crtc_kms->rotation_map[hw_transform]) != 0)
|
|
|
|
{
|
2016-10-08 20:28:58 +00:00
|
|
|
g_warning ("Failed to apply DRM plane transform %d: %m", hw_transform);
|
2016-10-07 14:52:43 +00:00
|
|
|
|
|
|
|
/* Blacklist this HW transform, we want to fallback to our
|
|
|
|
* fallbacks in this case.
|
|
|
|
*/
|
|
|
|
crtc_kms->all_hw_transforms &= ~(1 << hw_transform);
|
|
|
|
}
|
2016-07-31 21:41:26 +00:00
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
/* Disable CRTCs not mentioned in the list (they have is_dirty == FALSE,
|
|
|
|
because they weren't seen in the first loop) */
|
2017-03-28 04:35:19 +00:00
|
|
|
for (l = manager->crtcs; l; l = l->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-28 04:35:19 +00:00
|
|
|
MetaCrtc *crtc = l->data;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
crtc->logical_monitor = NULL;
|
|
|
|
|
|
|
|
if (crtc->is_dirty)
|
|
|
|
{
|
|
|
|
crtc->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutputInfo *output_info = outputs[i];
|
|
|
|
MetaOutput *output = output_info->output;
|
|
|
|
|
|
|
|
output->is_primary = output_info->is_primary;
|
|
|
|
output->is_presentation = output_info->is_presentation;
|
2015-04-28 00:42:10 +00:00
|
|
|
output->is_underscanning = output_info->is_underscanning;
|
|
|
|
|
|
|
|
set_underscan (manager_kms, output);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable outputs not mentioned in the list */
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 09:36:18 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
if (output->is_dirty)
|
|
|
|
{
|
|
|
|
output->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->is_primary = FALSE;
|
|
|
|
}
|
2017-01-09 06:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_screen_size (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
int screen_width = 0;
|
|
|
|
int screen_height = 0;
|
|
|
|
|
|
|
|
for (l = config->logical_monitor_configs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
|
|
|
|
int right_edge;
|
|
|
|
int bottom_edge;
|
|
|
|
|
|
|
|
right_edge = (logical_monitor_config->layout.width +
|
|
|
|
logical_monitor_config->layout.x);
|
|
|
|
if (right_edge > screen_width)
|
|
|
|
screen_width = right_edge;
|
|
|
|
|
|
|
|
bottom_edge = (logical_monitor_config->layout.height +
|
|
|
|
logical_monitor_config->layout.y);
|
|
|
|
if (bottom_edge > screen_height)
|
|
|
|
screen_height = bottom_edge;
|
|
|
|
}
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
manager->screen_width = screen_width;
|
|
|
|
manager->screen_height = screen_height;
|
2017-01-09 06:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-02-14 11:54:04 +00:00
|
|
|
meta_monitor_manager_kms_apply_monitors_config (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config,
|
|
|
|
MetaMonitorsConfigMethod method,
|
|
|
|
GError **error)
|
2017-01-09 06:31:18 +00:00
|
|
|
{
|
|
|
|
GPtrArray *crtc_infos;
|
|
|
|
GPtrArray *output_infos;
|
|
|
|
|
2017-01-12 05:47:54 +00:00
|
|
|
if (!config)
|
|
|
|
{
|
2017-04-12 06:15:33 +00:00
|
|
|
manager->screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH;
|
|
|
|
manager->screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT;
|
2017-01-20 06:50:11 +00:00
|
|
|
meta_monitor_manager_rebuild (manager, NULL);
|
2017-01-12 05:47:54 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-09 06:31:18 +00:00
|
|
|
if (!meta_monitor_config_manager_assign (manager, config,
|
|
|
|
&crtc_infos, &output_infos,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 11:54:04 +00:00
|
|
|
if (method == META_MONITORS_CONFIG_METHOD_VERIFY)
|
|
|
|
{
|
|
|
|
g_ptr_array_free (crtc_infos, TRUE);
|
|
|
|
g_ptr_array_free (output_infos, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-09 06:31:18 +00:00
|
|
|
apply_crtc_assignments (manager,
|
|
|
|
(MetaCrtcInfo **) crtc_infos->pdata,
|
|
|
|
crtc_infos->len,
|
|
|
|
(MetaOutputInfo **) output_infos->pdata,
|
|
|
|
output_infos->len);
|
|
|
|
|
|
|
|
g_ptr_array_free (crtc_infos, TRUE);
|
|
|
|
g_ptr_array_free (output_infos, TRUE);
|
|
|
|
|
|
|
|
update_screen_size (manager, config);
|
|
|
|
meta_monitor_manager_rebuild (manager, config);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_get_crtc_gamma (MetaMonitorManager *manager,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2013-07-30 09:36:18 +00:00
|
|
|
gsize *size,
|
|
|
|
unsigned short **red,
|
|
|
|
unsigned short **green,
|
|
|
|
unsigned short **blue)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
drmModeCrtc *kms_crtc;
|
|
|
|
|
|
|
|
kms_crtc = drmModeGetCrtc (manager_kms->fd, crtc->crtc_id);
|
|
|
|
|
|
|
|
*size = kms_crtc->gamma_size;
|
|
|
|
*red = g_new (unsigned short, *size);
|
|
|
|
*green = g_new (unsigned short, *size);
|
|
|
|
*blue = g_new (unsigned short, *size);
|
|
|
|
|
|
|
|
drmModeCrtcGetGamma (manager_kms->fd, crtc->crtc_id, *size, *red, *green, *blue);
|
|
|
|
|
|
|
|
drmModeFreeCrtc (kms_crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_set_crtc_gamma (MetaMonitorManager *manager,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2013-07-30 09:36:18 +00:00
|
|
|
gsize size,
|
|
|
|
unsigned short *red,
|
|
|
|
unsigned short *green,
|
|
|
|
unsigned short *blue)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
|
|
|
|
drmModeCrtcSetGamma (manager_kms->fd, crtc->crtc_id, size, red, green, blue);
|
|
|
|
}
|
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
static void
|
|
|
|
handle_hotplug_event (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
meta_monitor_manager_read_current_state (manager);
|
|
|
|
meta_monitor_manager_on_hotplug (manager);
|
|
|
|
}
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
static void
|
|
|
|
on_uevent (GUdevClient *client,
|
|
|
|
const char *action,
|
|
|
|
GUdevDevice *device,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (user_data);
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
|
|
|
|
|
|
|
if (!g_udev_device_get_property_as_boolean (device, "HOTPLUG"))
|
|
|
|
return;
|
|
|
|
|
2016-12-21 08:00:29 +00:00
|
|
|
handle_hotplug_event (manager);
|
2014-10-12 20:05:31 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
static gboolean
|
|
|
|
kms_event_check (GSource *source)
|
|
|
|
{
|
|
|
|
MetaKmsSource *kms_source = (MetaKmsSource *) source;
|
|
|
|
|
|
|
|
return g_source_query_unix_fd (source, kms_source->fd_tag) & G_IO_IN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
kms_event_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaKmsSource *kms_source = (MetaKmsSource *) source;
|
|
|
|
|
|
|
|
meta_monitor_manager_kms_wait_for_flip (kms_source->manager_kms);
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs kms_event_funcs = {
|
|
|
|
NULL,
|
|
|
|
kms_event_check,
|
|
|
|
kms_event_dispatch
|
|
|
|
};
|
|
|
|
|
2017-03-10 07:11:56 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_connect_uevent_handler (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
manager_kms->uevent_handler_id = g_signal_connect (manager_kms->udev,
|
|
|
|
"uevent",
|
|
|
|
G_CALLBACK (on_uevent),
|
|
|
|
manager_kms);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_disconnect_uevent_handler (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
g_signal_handler_disconnect (manager_kms->udev,
|
|
|
|
manager_kms->uevent_handler_id);
|
|
|
|
manager_kms->uevent_handler_id = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-10 08:29:11 +00:00
|
|
|
void
|
|
|
|
meta_monitor_manager_kms_pause (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
meta_monitor_manager_kms_disconnect_uevent_handler (manager_kms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_monitor_manager_kms_resume (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
|
|
|
|
|
|
|
meta_monitor_manager_kms_connect_uevent_handler (manager_kms);
|
|
|
|
handle_hotplug_event (manager);
|
|
|
|
}
|
|
|
|
|
2013-07-30 09:36:18 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_init (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
2016-05-09 11:51:29 +00:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
2016-05-12 06:55:06 +00:00
|
|
|
GSource *source;
|
2013-07-30 09:36:18 +00:00
|
|
|
|
2016-05-09 11:51:29 +00:00
|
|
|
manager_kms->fd = meta_renderer_native_get_kms_fd (renderer_native);
|
2014-10-12 20:05:31 +00:00
|
|
|
|
2015-12-18 11:16:59 +00:00
|
|
|
drmSetClientCap (manager_kms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
const char *subsystems[2] = { "drm", NULL };
|
|
|
|
manager_kms->udev = g_udev_client_new (subsystems);
|
2017-03-10 07:11:56 +00:00
|
|
|
meta_monitor_manager_kms_connect_uevent_handler (manager_kms);
|
2015-02-22 19:21:37 +00:00
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
source = g_source_new (&kms_event_funcs, sizeof (MetaKmsSource));
|
|
|
|
manager_kms->source = (MetaKmsSource *) source;
|
|
|
|
manager_kms->source->fd_tag = g_source_add_unix_fd (source,
|
|
|
|
manager_kms->fd,
|
|
|
|
G_IO_IN | G_IO_ERR);
|
|
|
|
manager_kms->source->manager_kms = manager_kms;
|
|
|
|
g_source_attach (source, NULL);
|
2014-10-12 20:05:31 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 08:26:34 +00:00
|
|
|
static void
|
|
|
|
get_crtc_connectors (MetaMonitorManager *manager,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2016-05-11 08:26:34 +00:00
|
|
|
uint32_t **connectors,
|
|
|
|
unsigned int *n_connectors)
|
|
|
|
{
|
2016-10-14 16:23:24 +00:00
|
|
|
GArray *connectors_array = g_array_new (FALSE, FALSE, sizeof (uint32_t));
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2016-05-11 08:26:34 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
2016-05-11 08:26:34 +00:00
|
|
|
|
|
|
|
if (output->crtc == crtc)
|
2016-10-14 16:23:24 +00:00
|
|
|
g_array_append_val (connectors_array, output->winsys_id);
|
2016-05-11 08:26:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 16:23:24 +00:00
|
|
|
*n_connectors = connectors_array->len;
|
|
|
|
*connectors = (uint32_t *) g_array_free (connectors_array, FALSE);
|
2016-05-11 08:26:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 12:17:15 +00:00
|
|
|
gboolean
|
2016-06-08 09:05:31 +00:00
|
|
|
meta_monitor_manager_kms_apply_crtc_mode (MetaMonitorManagerKms *manager_kms,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2016-06-08 09:05:31 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
uint32_t fb_id)
|
2016-05-11 08:26:34 +00:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
2016-06-08 09:05:31 +00:00
|
|
|
uint32_t *connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
drmModeModeInfo *mode;
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
get_crtc_connectors (manager, crtc, &connectors, &n_connectors);
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (connectors)
|
|
|
|
mode = crtc->current_mode->driver_private;
|
|
|
|
else
|
|
|
|
mode = NULL;
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (drmModeSetCrtc (manager_kms->fd,
|
|
|
|
crtc->crtc_id,
|
|
|
|
fb_id,
|
|
|
|
x, y,
|
|
|
|
connectors, n_connectors,
|
|
|
|
mode) != 0)
|
2016-11-17 12:17:15 +00:00
|
|
|
{
|
|
|
|
g_warning ("Failed to set CRTC mode %s: %m", crtc->current_mode->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
g_free (connectors);
|
2016-11-17 12:17:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-06-08 09:05:31 +00:00
|
|
|
}
|
2016-05-11 08:26:34 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
static void
|
|
|
|
invoke_flip_closure (GClosure *flip_closure)
|
|
|
|
{
|
|
|
|
GValue param = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (¶m, G_TYPE_POINTER);
|
|
|
|
g_value_set_pointer (¶m, flip_closure);
|
|
|
|
g_closure_invoke (flip_closure, NULL, 1, ¶m, NULL);
|
|
|
|
g_closure_unref (flip_closure);
|
2016-05-11 08:26:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 06:55:06 +00:00
|
|
|
gboolean
|
2016-06-08 09:05:31 +00:00
|
|
|
meta_monitor_manager_kms_is_crtc_active (MetaMonitorManagerKms *manager_kms,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc)
|
2016-05-12 06:55:06 +00:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
2017-03-24 09:35:51 +00:00
|
|
|
GList *l;
|
2016-06-08 09:05:31 +00:00
|
|
|
gboolean connected_crtc_found;
|
2016-05-12 06:55:06 +00:00
|
|
|
|
|
|
|
if (manager->power_save_mode != META_POWER_SAVE_ON)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
connected_crtc_found = FALSE;
|
2017-03-24 09:35:51 +00:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2016-05-12 06:55:06 +00:00
|
|
|
{
|
2017-03-24 09:35:51 +00:00
|
|
|
MetaOutput *output = l->data;
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (output->crtc == crtc)
|
|
|
|
{
|
|
|
|
connected_crtc_found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (!connected_crtc_found)
|
|
|
|
return FALSE;
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
gboolean
|
|
|
|
meta_monitor_manager_kms_flip_crtc (MetaMonitorManagerKms *manager_kms,
|
2016-12-08 04:15:28 +00:00
|
|
|
MetaCrtc *crtc,
|
2016-06-08 09:05:31 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
uint32_t fb_id,
|
2016-11-17 12:17:15 +00:00
|
|
|
GClosure *flip_closure,
|
|
|
|
gboolean *fb_in_use)
|
2016-06-08 09:05:31 +00:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
|
|
|
uint32_t *connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
int ret = -1;
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
g_assert (manager->power_save_mode == META_POWER_SAVE_ON);
|
|
|
|
|
|
|
|
get_crtc_connectors (manager, crtc, &connectors, &n_connectors);
|
|
|
|
g_assert (n_connectors > 0);
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (!manager_kms->page_flips_not_supported)
|
|
|
|
{
|
2016-05-12 06:55:06 +00:00
|
|
|
ret = drmModePageFlip (manager_kms->fd,
|
|
|
|
crtc->crtc_id,
|
|
|
|
fb_id,
|
|
|
|
DRM_MODE_PAGE_FLIP_EVENT,
|
|
|
|
flip_closure);
|
|
|
|
if (ret != 0 && ret != -EACCES)
|
|
|
|
{
|
|
|
|
g_warning ("Failed to flip: %s", strerror (-ret));
|
|
|
|
manager_kms->page_flips_not_supported = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
if (manager_kms->page_flips_not_supported)
|
2016-11-17 12:17:15 +00:00
|
|
|
{
|
|
|
|
if (meta_monitor_manager_kms_apply_crtc_mode (manager_kms,
|
|
|
|
crtc,
|
|
|
|
x, y,
|
|
|
|
fb_id))
|
|
|
|
{
|
|
|
|
*fb_in_use = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2016-06-08 09:05:31 +00:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-17 12:17:15 +00:00
|
|
|
*fb_in_use = TRUE;
|
2016-06-08 09:05:31 +00:00
|
|
|
g_closure_ref (flip_closure);
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
return TRUE;
|
2016-05-12 06:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_flip_handler (int fd,
|
|
|
|
unsigned int frame,
|
|
|
|
unsigned int sec,
|
|
|
|
unsigned int usec,
|
|
|
|
void *data)
|
|
|
|
{
|
2016-06-08 09:05:31 +00:00
|
|
|
GClosure *flip_closure = data;
|
2016-05-12 06:55:06 +00:00
|
|
|
|
2016-06-08 09:05:31 +00:00
|
|
|
invoke_flip_closure (flip_closure);
|
2016-05-12 06:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_monitor_manager_kms_wait_for_flip (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
drmEventContext evctx;
|
|
|
|
|
|
|
|
if (manager_kms->page_flips_not_supported)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset (&evctx, 0, sizeof evctx);
|
|
|
|
evctx.version = DRM_EVENT_CONTEXT_VERSION;
|
|
|
|
evctx.page_flip_handler = page_flip_handler;
|
|
|
|
drmHandleEvent (manager_kms->fd, &evctx);
|
|
|
|
}
|
|
|
|
|
2017-03-08 08:05:00 +00:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_kms_is_transform_handled (MetaMonitorManager *manager,
|
|
|
|
MetaCrtc *crtc,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
2017-09-17 14:21:46 +00:00
|
|
|
if ((1 << transform) & crtc_kms->all_hw_transforms)
|
2017-03-08 08:05:00 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-05-25 08:12:51 +00:00
|
|
|
static float
|
2017-01-20 07:07:12 +00:00
|
|
|
meta_monitor_manager_kms_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2017-04-21 09:28:22 +00:00
|
|
|
return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
|
2017-01-20 07:07:12 +00:00
|
|
|
}
|
|
|
|
|
2017-06-05 07:59:47 +00:00
|
|
|
static float *
|
|
|
|
meta_monitor_manager_kms_calculate_supported_scales (MetaMonitorManager *manager,
|
|
|
|
MetaLogicalMonitorLayoutMode layout_mode,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode,
|
|
|
|
int *n_supported_scales)
|
2017-01-26 09:14:32 +00:00
|
|
|
{
|
2017-06-05 07:59:47 +00:00
|
|
|
MetaMonitorScalesConstraint constraints =
|
|
|
|
META_MONITOR_SCALES_CONSTRAINT_NONE;
|
|
|
|
|
2017-05-25 09:20:59 +00:00
|
|
|
switch (layout_mode)
|
|
|
|
{
|
|
|
|
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
|
|
|
|
break;
|
|
|
|
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
|
2017-06-05 07:59:47 +00:00
|
|
|
constraints |= META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
|
2017-05-25 09:20:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-05 07:59:47 +00:00
|
|
|
|
|
|
|
return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
|
|
|
|
constraints,
|
|
|
|
n_supported_scales);
|
2017-01-26 09:14:32 +00:00
|
|
|
}
|
|
|
|
|
2017-02-07 08:01:40 +00:00
|
|
|
static MetaMonitorManagerCapability
|
|
|
|
meta_monitor_manager_kms_get_capabilities (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2017-04-21 08:40:51 +00:00
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
2017-02-07 08:01:40 +00:00
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
|
|
|
MetaMonitorManagerCapability capabilities =
|
|
|
|
META_MONITOR_MANAGER_CAPABILITY_NONE;
|
|
|
|
|
2017-04-21 08:40:51 +00:00
|
|
|
if (meta_settings_is_experimental_feature_enabled (
|
|
|
|
settings,
|
2017-02-24 10:10:52 +00:00
|
|
|
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
|
|
|
|
capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
|
|
|
|
|
2017-02-07 08:01:40 +00:00
|
|
|
switch (meta_renderer_native_get_mode (renderer_native))
|
|
|
|
{
|
|
|
|
case META_RENDERER_NATIVE_MODE_GBM:
|
|
|
|
capabilities |= META_MONITOR_MANAGER_CAPABILITY_MIRRORING;
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_EGL_DEVICE
|
|
|
|
case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
|
2017-02-15 08:06:46 +00:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_kms_get_max_screen_size (MetaMonitorManager *manager,
|
|
|
|
int *max_width,
|
|
|
|
int *max_height)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
|
|
|
|
if (meta_is_stage_views_enabled ())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*max_width = manager_kms->max_buffer_width;
|
|
|
|
*max_height = manager_kms->max_buffer_height;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-02-24 10:10:52 +00:00
|
|
|
static MetaLogicalMonitorLayoutMode
|
|
|
|
meta_monitor_manager_kms_get_default_layout_mode (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-04-21 08:40:51 +00:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
|
|
|
|
2017-02-24 10:10:52 +00:00
|
|
|
if (!meta_is_stage_views_enabled ())
|
|
|
|
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
|
|
|
|
|
2017-04-21 08:40:51 +00:00
|
|
|
if (meta_settings_is_experimental_feature_enabled (
|
|
|
|
settings,
|
2017-02-24 10:10:52 +00:00
|
|
|
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
|
|
|
|
return META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
|
|
|
|
else
|
|
|
|
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
|
|
|
|
}
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (object);
|
|
|
|
|
|
|
|
g_clear_object (&manager_kms->udev);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_manager_kms_parent_class)->dispose (object);
|
2013-07-30 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (object);
|
|
|
|
|
|
|
|
free_resources (manager_kms);
|
2016-05-12 06:55:06 +00:00
|
|
|
g_source_destroy ((GSource *) manager_kms->source);
|
2013-07-30 09:36:18 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (meta_monitor_manager_kms_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_class_init (MetaMonitorManagerKmsClass *klass)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2014-10-12 20:05:31 +00:00
|
|
|
object_class->dispose = meta_monitor_manager_kms_dispose;
|
2013-07-30 09:36:18 +00:00
|
|
|
object_class->finalize = meta_monitor_manager_kms_finalize;
|
|
|
|
|
|
|
|
manager_class->read_current = meta_monitor_manager_kms_read_current;
|
|
|
|
manager_class->read_edid = meta_monitor_manager_kms_read_edid;
|
2017-01-06 05:27:21 +00:00
|
|
|
manager_class->ensure_initial_config = meta_monitor_manager_kms_ensure_initial_config;
|
2017-01-09 06:31:18 +00:00
|
|
|
manager_class->apply_monitors_config = meta_monitor_manager_kms_apply_monitors_config;
|
2013-07-30 09:36:18 +00:00
|
|
|
manager_class->set_power_save_mode = meta_monitor_manager_kms_set_power_save_mode;
|
|
|
|
manager_class->get_crtc_gamma = meta_monitor_manager_kms_get_crtc_gamma;
|
|
|
|
manager_class->set_crtc_gamma = meta_monitor_manager_kms_set_crtc_gamma;
|
2017-03-08 08:05:00 +00:00
|
|
|
manager_class->is_transform_handled = meta_monitor_manager_kms_is_transform_handled;
|
2017-01-20 07:07:12 +00:00
|
|
|
manager_class->calculate_monitor_mode_scale = meta_monitor_manager_kms_calculate_monitor_mode_scale;
|
2017-06-05 07:59:47 +00:00
|
|
|
manager_class->calculate_supported_scales = meta_monitor_manager_kms_calculate_supported_scales;
|
2017-02-07 08:01:40 +00:00
|
|
|
manager_class->get_capabilities = meta_monitor_manager_kms_get_capabilities;
|
2017-02-15 08:06:46 +00:00
|
|
|
manager_class->get_max_screen_size = meta_monitor_manager_kms_get_max_screen_size;
|
2017-02-24 10:10:52 +00:00
|
|
|
manager_class->get_default_layout_mode = meta_monitor_manager_kms_get_default_layout_mode;
|
2016-07-31 21:41:26 +00:00
|
|
|
}
|