2013-07-30 05:36:18 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2013-07-30 05:36:18 -04:00
|
|
|
* Copyright (C) 2013 Red Hat Inc.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2013-07-30 05:36:18 -04: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 09:34:02 -04:00
|
|
|
*
|
2013-07-30 05:36:18 -04: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-30 20:25:31 -04:00
|
|
|
#include "meta-monitor-manager-kms.h"
|
2017-01-09 01:31:18 -05:00
|
|
|
#include "meta-monitor-config-manager.h"
|
2017-03-28 00:35:19 -04:00
|
|
|
#include "meta-crtc.h"
|
2017-03-24 05:35:51 -04:00
|
|
|
#include "meta-output.h"
|
2016-05-09 07:51:29 -04:00
|
|
|
#include "meta-backend-private.h"
|
|
|
|
#include "meta-renderer-native.h"
|
2017-07-04 00:11:44 -04:00
|
|
|
#include "meta-output-kms.h"
|
2014-03-30 20:25:31 -04:00
|
|
|
|
2013-07-30 05:36:18 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2016-05-12 02:55:06 -04:00
|
|
|
#include <drm.h>
|
2013-07-30 05:36:18 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <meta/main.h>
|
|
|
|
#include <meta/errors.h>
|
|
|
|
|
2014-10-12 16:05:31 -04:00
|
|
|
#include <gudev/gudev.h>
|
|
|
|
|
2015-02-14 15:03:38 -05:00
|
|
|
#include "meta-default-modes.h"
|
|
|
|
|
2015-12-18 06:16:59 -05:00
|
|
|
#define ALL_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
|
2016-07-31 21:51:36 -04:00
|
|
|
#define ALL_TRANSFORMS_MASK ((1 << ALL_TRANSFORMS) - 1)
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-12-21 03:04:23 -05:00
|
|
|
typedef struct
|
|
|
|
{
|
2015-04-27 20:42:10 -04:00
|
|
|
uint32_t underscan_prop_id;
|
|
|
|
uint32_t underscan_hborder_prop_id;
|
|
|
|
uint32_t underscan_vborder_prop_id;
|
2015-12-18 06:16:59 -05:00
|
|
|
uint32_t primary_plane_id;
|
|
|
|
uint32_t rotation_prop_id;
|
|
|
|
uint32_t rotation_map[ALL_TRANSFORMS];
|
2016-07-31 17:41:26 -04:00
|
|
|
uint32_t all_hw_transforms;
|
2016-12-07 23:15:28 -05:00
|
|
|
} MetaCrtcKms;
|
2015-04-27 20:42:10 -04:00
|
|
|
|
2016-05-12 02:55:06 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
gpointer fd_tag;
|
|
|
|
MetaMonitorManagerKms *manager_kms;
|
|
|
|
} MetaKmsSource;
|
|
|
|
|
2013-07-30 05:36:18 -04:00
|
|
|
struct _MetaMonitorManagerKms
|
|
|
|
{
|
|
|
|
MetaMonitorManager parent_instance;
|
|
|
|
|
|
|
|
int fd;
|
2016-05-12 02:55:06 -04:00
|
|
|
MetaKmsSource *source;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
|
|
|
drmModeConnector **connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
|
2014-10-12 16:05:31 -04:00
|
|
|
GUdevClient *udev;
|
2017-03-10 02:11:56 -05:00
|
|
|
guint uevent_handler_id;
|
2015-02-22 14:21:37 -05:00
|
|
|
|
2016-05-12 02:55:06 -04:00
|
|
|
gboolean page_flips_not_supported;
|
2017-02-15 03:06:46 -05:00
|
|
|
|
|
|
|
int max_buffer_width;
|
|
|
|
int max_buffer_height;
|
2013-07-30 05:36:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaMonitorManagerKmsClass
|
|
|
|
{
|
|
|
|
MetaMonitorManagerClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorManagerKms, meta_monitor_manager_kms, META_TYPE_MONITOR_MANAGER);
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
int
|
|
|
|
meta_monitor_manager_kms_get_fd (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
|
|
|
return manager_kms->fd;
|
|
|
|
}
|
|
|
|
|
2013-07-30 05:36:18 -04:00
|
|
|
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 05:35:51 -04:00
|
|
|
compare_outputs (gconstpointer one,
|
|
|
|
gconstpointer two)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
|
|
|
const MetaOutput *o_one = one, *o_two = two;
|
|
|
|
|
|
|
|
return strcmp (o_one->name, o_two->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-09 02:49:54 -05:00
|
|
|
meta_monitor_mode_destroy_notify (MetaCrtcMode *mode)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2016-12-09 02:49:54 -05:00
|
|
|
g_slice_free (drmModeModeInfo, mode->driver_private);
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
|
2015-04-27 20:42:10 -04:00
|
|
|
static void
|
2016-12-07 23:15:28 -05:00
|
|
|
meta_crtc_destroy_notify (MetaCrtc *crtc)
|
2015-04-27 20:42:10 -04:00
|
|
|
{
|
|
|
|
g_free (crtc->driver_private);
|
|
|
|
}
|
|
|
|
|
2013-07-30 05:36:18 -04: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;
|
|
|
|
}
|
|
|
|
|
2015-04-27 20:42:10 -04:00
|
|
|
static void
|
|
|
|
find_crtc_properties (MetaMonitorManagerKms *manager_kms,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *meta_crtc)
|
2015-04-27 20:42:10 -04:00
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcKms *crtc_kms;
|
2015-04-27 20:42:10 -04: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 10:52:20 -04:00
|
|
|
if (!props)
|
|
|
|
return;
|
|
|
|
|
2015-04-27 20:42:10 -04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaCrtcMode *
|
|
|
|
meta_monitor_manager_kms_get_mode_from_drm_mode (MetaMonitorManagerKms *manager_kms,
|
|
|
|
const drmModeModeInfo *drm_mode)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
2017-03-28 04:52:15 -04:00
|
|
|
GList *l;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-03-28 04:52:15 -04:00
|
|
|
for (l = manager->modes; l; l = l->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-28 04:52:15 -04:00
|
|
|
MetaCrtcMode *mode = l->data;
|
|
|
|
|
|
|
|
if (drm_mode_equal (drm_mode, mode->driver_private))
|
|
|
|
return mode;
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
float
|
|
|
|
meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode)
|
2015-02-14 15:03:38 -05:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-28 04:52:15 -04:00
|
|
|
static MetaCrtcMode *
|
|
|
|
create_mode (const drmModeModeInfo *drm_mode,
|
|
|
|
long mode_id)
|
2016-08-01 05:25:52 -04:00
|
|
|
{
|
2017-03-28 04:52:15 -04:00
|
|
|
MetaCrtcMode *mode;
|
|
|
|
|
|
|
|
mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
|
2016-08-01 05:25:52 -04: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;
|
2017-07-04 00:11:44 -04:00
|
|
|
mode->refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
|
2016-08-01 05:25:52 -04:00
|
|
|
mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode);
|
2017-07-04 00:11:44 -04:00
|
|
|
mode->driver_notify = (GDestroyNotify) meta_monitor_mode_destroy_notify;
|
2017-03-28 04:52:15 -04:00
|
|
|
|
|
|
|
return mode;
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
|
|
|
|
2013-07-30 05:36:18 -04:00
|
|
|
static MetaOutput *
|
2017-03-24 05:35:51 -04:00
|
|
|
find_output_by_id (GList *outputs,
|
|
|
|
glong id)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaOutput *output = l->data;
|
|
|
|
|
|
|
|
if (output->winsys_id == id)
|
|
|
|
return output;
|
|
|
|
}
|
2013-07-30 05:36:18 -04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-18 06:16:59 -05: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-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc)
|
2015-12-18 06:16:59 -05:00
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2015-12-18 06:16:59 -05: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 17:41:26 -04:00
|
|
|
crtc_kms->all_hw_transforms |= 1 << cur;
|
2015-12-18 06:16:59 -05: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-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2015-12-18 06:16:59 -05:00
|
|
|
unsigned int idx)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
drmModeObjectPropertiesPtr props;
|
|
|
|
drmModePlaneRes *planes;
|
|
|
|
drmModePlane *drm_plane;
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcKms *crtc_kms;
|
2015-12-18 06:16:59 -05: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 13:35:12 -05:00
|
|
|
|
2016-07-31 17:41:26 -04:00
|
|
|
crtc->all_transforms |= crtc_kms->all_hw_transforms;
|
|
|
|
|
2016-01-07 13:35:12 -05:00
|
|
|
drmModeFreePlaneResources (planes);
|
2015-12-18 06:16:59 -05:00
|
|
|
}
|
|
|
|
|
2017-03-28 00:35:19 -04:00
|
|
|
static MetaCrtc *
|
|
|
|
create_crtc (MetaMonitorManager *manager,
|
|
|
|
drmModeCrtc *drm_crtc)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-28 00:35:19 -04:00
|
|
|
MetaCrtc *crtc;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-03-28 00:35:19 -04:00
|
|
|
crtc = g_object_new (META_TYPE_CRTC, NULL);
|
|
|
|
|
2017-07-04 03:58:44 -04:00
|
|
|
crtc->monitor_manager = manager;
|
2016-08-01 05:25:52 -04: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-07-31 21:51:36 -04:00
|
|
|
crtc->all_transforms = meta_is_stage_views_enabled () ?
|
|
|
|
ALL_TRANSFORMS_MASK : META_MONITOR_TRANSFORM_NORMAL;
|
2016-08-01 05:25:52 -04:00
|
|
|
|
|
|
|
if (drm_crtc->mode_valid)
|
|
|
|
{
|
2017-03-28 04:52:15 -04:00
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = manager->modes; l; l = l->next)
|
2016-08-01 05:25:52 -04:00
|
|
|
{
|
2017-03-28 04:52:15 -04:00
|
|
|
MetaCrtcMode *mode = l->data;
|
|
|
|
|
|
|
|
if (drm_mode_equal (&drm_crtc->mode, mode->driver_private))
|
2016-08-01 05:25:52 -04:00
|
|
|
{
|
2017-03-28 04:52:15 -04:00
|
|
|
crtc->current_mode = mode;
|
2016-08-01 05:25:52 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-12-07 23:15:28 -05:00
|
|
|
crtc->driver_private = g_new0 (MetaCrtcKms, 1);
|
2016-08-01 05:25:52 -04:00
|
|
|
crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify;
|
2017-03-28 00:35:19 -04:00
|
|
|
|
|
|
|
return crtc;
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-08-01 05:25:52 -04:00
|
|
|
static void
|
2017-07-04 00:11:44 -04:00
|
|
|
setup_output_clones (MetaMonitorManager *manager)
|
2016-08-01 05:25:52 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
|
|
|
GList *k;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
for (k = manager->outputs; k; k = k->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaOutput *other_output = k->data;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
if (other_output == output)
|
2013-07-30 05:36:18 -04:00
|
|
|
continue;
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
if (meta_output_kms_can_clone (output, other_output))
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2016-08-01 05:25:52 -04:00
|
|
|
output->n_possible_clones++;
|
|
|
|
output->possible_clones = g_renew (MetaOutput *,
|
|
|
|
output->possible_clones,
|
|
|
|
output->n_possible_clones);
|
2017-07-04 00:11:44 -04:00
|
|
|
output->possible_clones[output->n_possible_clones - 1] =
|
|
|
|
other_output;
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-08-01 05:25:52 -04: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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 04:52:15 -04:00
|
|
|
manager->modes = NULL;
|
2016-08-01 05:25:52 -04: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 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2016-08-01 05:25:52 -04:00
|
|
|
|
2017-03-28 04:52:15 -04:00
|
|
|
mode = create_mode (drm_mode, (long) mode_id);
|
|
|
|
manager->modes = g_list_append (manager->modes, mode);
|
2016-08-01 05:25:52 -04:00
|
|
|
|
|
|
|
mode_id++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_destroy (modes);
|
2015-02-14 15:03:38 -05:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
|
|
|
{
|
2016-12-09 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2015-02-14 15:03:38 -05:00
|
|
|
|
2017-03-28 04:52:15 -04:00
|
|
|
mode = create_mode (&meta_default_drm_mode_infos[i], (long) mode_id);
|
|
|
|
manager->modes = g_list_append (manager->modes, mode);
|
2015-02-14 15:03:38 -05:00
|
|
|
|
|
|
|
mode_id++;
|
|
|
|
}
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_crtcs (MetaMonitorManager *manager,
|
|
|
|
drmModeRes *resources)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
|
|
|
unsigned int i;
|
|
|
|
|
2017-03-28 00:35:19 -04:00
|
|
|
manager->crtcs = NULL;
|
2016-08-01 05:25:52 -04:00
|
|
|
|
|
|
|
for (i = 0; i < (unsigned)resources->count_crtcs; i++)
|
|
|
|
{
|
|
|
|
drmModeCrtc *drm_crtc;
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc;
|
2016-08-01 05:25:52 -04:00
|
|
|
|
|
|
|
drm_crtc = drmModeGetCrtc (manager_kms->fd, resources->crtcs[i]);
|
|
|
|
|
2017-03-28 00:35:19 -04:00
|
|
|
crtc = create_crtc (manager, drm_crtc);
|
2016-08-01 05:25:52 -04:00
|
|
|
find_crtc_properties (manager_kms, crtc);
|
|
|
|
init_crtc_rotations (manager, crtc, i);
|
|
|
|
|
|
|
|
drmModeFreeCrtc (drm_crtc);
|
2017-03-28 00:35:19 -04:00
|
|
|
|
|
|
|
manager->crtcs = g_list_append (manager->crtcs, crtc);
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_outputs (MetaMonitorManager *manager,
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaKmsResources *resources)
|
2016-08-01 05:25:52 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *old_outputs;
|
2016-08-01 05:25:52 -04:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
old_outputs = manager->outputs;
|
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
manager->outputs = NULL;
|
2016-08-01 05:25:52 -04: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 05:35:51 -04:00
|
|
|
MetaOutput *output;
|
2016-08-01 05:25:52 -04:00
|
|
|
MetaOutput *old_output;
|
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
old_output = find_output_by_id (old_outputs, connector->connector_id);
|
2017-07-04 00:11:44 -04:00
|
|
|
output = meta_create_kms_output (manager, connector, resources, old_output);
|
2017-03-24 05:35:51 -04:00
|
|
|
manager->outputs = g_list_prepend (manager->outputs, output);
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Sort the outputs for easier handling in MetaMonitorConfig */
|
2017-03-24 05:35:51 -04:00
|
|
|
manager->outputs = g_list_sort (manager->outputs, compare_outputs);
|
2016-08-01 05:25:52 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
setup_output_clones (manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_kms_resources_init (MetaKmsResources *resources,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
drmModeRes *drm_resources;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
drm_resources = drmModeGetResources (fd);
|
|
|
|
resources->resources = drm_resources;
|
|
|
|
|
|
|
|
resources->n_encoders = (unsigned int) drm_resources->count_encoders;
|
|
|
|
resources->encoders = g_new (drmModeEncoder *, resources->n_encoders);
|
|
|
|
for (i = 0; i < resources->n_encoders; i++)
|
|
|
|
resources->encoders[i] = drmModeGetEncoder (fd, drm_resources->encoders[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_kms_resources_release (MetaKmsResources *resources)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < resources->n_encoders; i++)
|
|
|
|
drmModeFreeEncoder (resources->encoders[i]);
|
|
|
|
g_free (resources->encoders);
|
|
|
|
|
|
|
|
drmModeFreeResources (resources->resources);
|
2016-08-01 05:25:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_read_current (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2017-07-04 00:11:44 -04:00
|
|
|
MetaKmsResources resources;
|
2016-08-01 05:25:52 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
meta_kms_resources_init (&resources, manager_kms->fd);
|
2016-08-01 05:25:52 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
manager_kms->max_buffer_width = resources.resources->max_width;
|
|
|
|
manager_kms->max_buffer_height = resources.resources->max_height;
|
2016-08-01 05:25:52 -04: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);
|
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
init_connectors (manager, resources.resources);
|
|
|
|
init_modes (manager, resources.resources);
|
|
|
|
init_crtcs (manager, resources.resources);
|
|
|
|
init_outputs (manager, &resources);
|
2016-08-01 05:25:52 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
meta_kms_resources_release (&resources);
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GBytes *
|
|
|
|
meta_monitor_manager_kms_read_edid (MetaMonitorManager *manager,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
2017-07-04 00:11:44 -04:00
|
|
|
return meta_output_kms_read_edid (output);
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_set_power_save_mode (MetaMonitorManager *manager,
|
|
|
|
MetaPowerSave mode)
|
|
|
|
{
|
|
|
|
uint64_t state;
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2013-07-30 05:36:18 -04: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 18:43:12 -05:00
|
|
|
state = DRM_MODE_DPMS_OFF;
|
2013-07-30 05:36:18 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2017-07-04 00:11:44 -04:00
|
|
|
meta_output_kms_set_power_save_mode (output, state);
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 20:42:10 -04:00
|
|
|
static void
|
|
|
|
set_underscan (MetaMonitorManagerKms *manager_kms,
|
|
|
|
MetaOutput *output)
|
|
|
|
{
|
|
|
|
if (!output->crtc)
|
|
|
|
return;
|
|
|
|
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc = output->crtc;
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2015-04-27 20:42:10 -04: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 00:27:21 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_ensure_initial_config (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-01-09 01:31:18 -05:00
|
|
|
MetaMonitorsConfig *config;
|
2017-01-06 00:27:21 -05:00
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
config = meta_monitor_manager_ensure_configured (manager);
|
|
|
|
|
2017-03-24 03:36:12 -04:00
|
|
|
meta_monitor_manager_update_logical_state (manager, config);
|
2017-01-06 00:27:21 -05:00
|
|
|
}
|
|
|
|
|
2013-07-30 05:36:18 -04:00
|
|
|
static void
|
2017-01-09 01:31:18 -05:00
|
|
|
apply_crtc_assignments (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2015-04-27 20:42:10 -04:00
|
|
|
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
2013-07-30 05:36:18 -04:00
|
|
|
unsigned i;
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2016-07-31 17:41:26 -04:00
|
|
|
MetaMonitorTransform hw_transform;
|
2013-07-30 05:36:18 -04: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 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2016-05-12 02:55:06 -04:00
|
|
|
unsigned int j;
|
2013-07-30 05:36:18 -04: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 03:16:16 -04: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 05:36:18 -04:00
|
|
|
}
|
2015-12-18 06:16:59 -05:00
|
|
|
|
2016-07-31 17:41:26 -04:00
|
|
|
if (crtc_kms->all_hw_transforms & (1 << crtc->transform))
|
|
|
|
hw_transform = crtc->transform;
|
|
|
|
else
|
|
|
|
hw_transform = META_MONITOR_TRANSFORM_NORMAL;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-10-07 10:52:43 -04: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 16:28:58 -04:00
|
|
|
g_warning ("Failed to apply DRM plane transform %d: %m", hw_transform);
|
2016-10-07 10:52:43 -04: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 17:41:26 -04:00
|
|
|
}
|
2013-07-30 05:36:18 -04: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 00:35:19 -04:00
|
|
|
for (l = manager->crtcs; l; l = l->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-28 00:35:19 -04:00
|
|
|
MetaCrtc *crtc = l->data;
|
2013-07-30 05:36:18 -04: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-27 20:42:10 -04:00
|
|
|
output->is_underscanning = output_info->is_underscanning;
|
|
|
|
|
|
|
|
set_underscan (manager_kms, output);
|
2013-07-30 05:36:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable outputs not mentioned in the list */
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2013-07-30 05:36:18 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
|
|
|
if (output->is_dirty)
|
|
|
|
{
|
|
|
|
output->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->is_primary = FALSE;
|
|
|
|
}
|
2017-01-09 01:31:18 -05: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 05:36:18 -04:00
|
|
|
|
|
|
|
manager->screen_width = screen_width;
|
|
|
|
manager->screen_height = screen_height;
|
2017-01-09 01:31:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2017-02-14 06:54:04 -05:00
|
|
|
meta_monitor_manager_kms_apply_monitors_config (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config,
|
|
|
|
MetaMonitorsConfigMethod method,
|
|
|
|
GError **error)
|
2017-01-09 01:31:18 -05:00
|
|
|
{
|
|
|
|
GPtrArray *crtc_infos;
|
|
|
|
GPtrArray *output_infos;
|
|
|
|
|
2017-01-12 00:47:54 -05:00
|
|
|
if (!config)
|
|
|
|
{
|
2017-04-12 02:15:33 -04:00
|
|
|
manager->screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH;
|
|
|
|
manager->screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT;
|
2017-01-20 01:50:11 -05:00
|
|
|
meta_monitor_manager_rebuild (manager, NULL);
|
2017-01-12 00:47:54 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
if (!meta_monitor_config_manager_assign (manager, config,
|
|
|
|
&crtc_infos, &output_infos,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 06:54:04 -05: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 01:31:18 -05: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 05:36:18 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_get_crtc_gamma (MetaMonitorManager *manager,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2013-07-30 05:36:18 -04: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-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2013-07-30 05:36:18 -04: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 03:00:29 -05:00
|
|
|
static void
|
|
|
|
handle_hotplug_event (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
meta_monitor_manager_read_current_state (manager);
|
|
|
|
meta_monitor_manager_on_hotplug (manager);
|
|
|
|
}
|
|
|
|
|
2014-10-12 16:05:31 -04: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 03:00:29 -05:00
|
|
|
handle_hotplug_event (manager);
|
2014-10-12 16:05:31 -04:00
|
|
|
}
|
|
|
|
|
2016-05-12 02:55:06 -04: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 02:11:56 -05: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 03:29:11 -05: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 05:36:18 -04:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_kms_init (MetaMonitorManagerKms *manager_kms)
|
|
|
|
{
|
2016-05-09 07:51:29 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
|
2016-05-12 02:55:06 -04:00
|
|
|
GSource *source;
|
2013-07-30 05:36:18 -04:00
|
|
|
|
2016-05-09 07:51:29 -04:00
|
|
|
manager_kms->fd = meta_renderer_native_get_kms_fd (renderer_native);
|
2014-10-12 16:05:31 -04:00
|
|
|
|
2015-12-18 06:16:59 -05:00
|
|
|
drmSetClientCap (manager_kms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
|
|
|
|
|
2014-10-12 16:05:31 -04:00
|
|
|
const char *subsystems[2] = { "drm", NULL };
|
|
|
|
manager_kms->udev = g_udev_client_new (subsystems);
|
2017-03-10 02:11:56 -05:00
|
|
|
meta_monitor_manager_kms_connect_uevent_handler (manager_kms);
|
2015-02-22 14:21:37 -05:00
|
|
|
|
2016-05-12 02:55:06 -04: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 16:05:31 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 04:26:34 -04:00
|
|
|
static void
|
|
|
|
get_crtc_connectors (MetaMonitorManager *manager,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2016-05-11 04:26:34 -04:00
|
|
|
uint32_t **connectors,
|
|
|
|
unsigned int *n_connectors)
|
|
|
|
{
|
2016-10-14 12:23:24 -04:00
|
|
|
GArray *connectors_array = g_array_new (FALSE, FALSE, sizeof (uint32_t));
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2016-05-11 04:26:34 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
2016-05-11 04:26:34 -04:00
|
|
|
|
|
|
|
if (output->crtc == crtc)
|
2016-10-14 12:23:24 -04:00
|
|
|
g_array_append_val (connectors_array, output->winsys_id);
|
2016-05-11 04:26:34 -04:00
|
|
|
}
|
|
|
|
|
2016-10-14 12:23:24 -04:00
|
|
|
*n_connectors = connectors_array->len;
|
|
|
|
*connectors = (uint32_t *) g_array_free (connectors_array, FALSE);
|
2016-05-11 04:26:34 -04:00
|
|
|
}
|
|
|
|
|
2016-11-17 07:17:15 -05:00
|
|
|
gboolean
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_monitor_manager_kms_apply_crtc_mode (MetaMonitorManagerKms *manager_kms,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2016-06-08 05:05:31 -04:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
uint32_t fb_id)
|
2016-05-11 04:26:34 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
2016-06-08 05:05:31 -04:00
|
|
|
uint32_t *connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
drmModeModeInfo *mode;
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
get_crtc_connectors (manager, crtc, &connectors, &n_connectors);
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
if (connectors)
|
|
|
|
mode = crtc->current_mode->driver_private;
|
|
|
|
else
|
|
|
|
mode = NULL;
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
if (drmModeSetCrtc (manager_kms->fd,
|
|
|
|
crtc->crtc_id,
|
|
|
|
fb_id,
|
|
|
|
x, y,
|
|
|
|
connectors, n_connectors,
|
|
|
|
mode) != 0)
|
2016-11-17 07:17:15 -05:00
|
|
|
{
|
|
|
|
g_warning ("Failed to set CRTC mode %s: %m", crtc->current_mode->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
g_free (connectors);
|
2016-11-17 07:17:15 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2016-06-08 05:05:31 -04:00
|
|
|
}
|
2016-05-11 04:26:34 -04:00
|
|
|
|
2016-06-08 05:05:31 -04: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 04:26:34 -04:00
|
|
|
}
|
|
|
|
|
2016-05-12 02:55:06 -04:00
|
|
|
gboolean
|
2016-06-08 05:05:31 -04:00
|
|
|
meta_monitor_manager_kms_is_crtc_active (MetaMonitorManagerKms *manager_kms,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc)
|
2016-05-12 02:55:06 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
2017-03-24 05:35:51 -04:00
|
|
|
GList *l;
|
2016-06-08 05:05:31 -04:00
|
|
|
gboolean connected_crtc_found;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
|
|
|
if (manager->power_save_mode != META_POWER_SAVE_ON)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
connected_crtc_found = FALSE;
|
2017-03-24 05:35:51 -04:00
|
|
|
for (l = manager->outputs; l; l = l->next)
|
2016-05-12 02:55:06 -04:00
|
|
|
{
|
2017-03-24 05:35:51 -04:00
|
|
|
MetaOutput *output = l->data;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
if (output->crtc == crtc)
|
|
|
|
{
|
|
|
|
connected_crtc_found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
if (!connected_crtc_found)
|
|
|
|
return FALSE;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
gboolean
|
|
|
|
meta_monitor_manager_kms_flip_crtc (MetaMonitorManagerKms *manager_kms,
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc,
|
2016-06-08 05:05:31 -04:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
uint32_t fb_id,
|
2016-11-17 07:17:15 -05:00
|
|
|
GClosure *flip_closure,
|
|
|
|
gboolean *fb_in_use)
|
2016-06-08 05:05:31 -04:00
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
|
|
|
uint32_t *connectors;
|
|
|
|
unsigned int n_connectors;
|
|
|
|
int ret = -1;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04: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 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
if (!manager_kms->page_flips_not_supported)
|
|
|
|
{
|
2016-05-12 02:55:06 -04: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 05:05:31 -04:00
|
|
|
if (manager_kms->page_flips_not_supported)
|
2016-11-17 07:17:15 -05: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 05:05:31 -04:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-17 07:17:15 -05:00
|
|
|
*fb_in_use = TRUE;
|
2016-06-08 05:05:31 -04:00
|
|
|
g_closure_ref (flip_closure);
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
return TRUE;
|
2016-05-12 02:55:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_flip_handler (int fd,
|
|
|
|
unsigned int frame,
|
|
|
|
unsigned int sec,
|
|
|
|
unsigned int usec,
|
|
|
|
void *data)
|
|
|
|
{
|
2016-06-08 05:05:31 -04:00
|
|
|
GClosure *flip_closure = data;
|
2016-05-12 02:55:06 -04:00
|
|
|
|
2016-06-08 05:05:31 -04:00
|
|
|
invoke_flip_closure (flip_closure);
|
2016-05-12 02:55:06 -04: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 03:05:00 -05: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 10:21:46 -04:00
|
|
|
if ((1 << transform) & crtc_kms->all_hw_transforms)
|
2017-03-08 03:05:00 -05:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-05-25 04:12:51 -04:00
|
|
|
static float
|
2017-01-20 02:07:12 -05:00
|
|
|
meta_monitor_manager_kms_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
2017-04-21 05:28:22 -04:00
|
|
|
return meta_monitor_calculate_mode_scale (monitor, monitor_mode);
|
2017-01-20 02:07:12 -05:00
|
|
|
}
|
|
|
|
|
2017-06-05 03:59:47 -04: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 04:14:32 -05:00
|
|
|
{
|
2017-06-05 03:59:47 -04:00
|
|
|
MetaMonitorScalesConstraint constraints =
|
|
|
|
META_MONITOR_SCALES_CONSTRAINT_NONE;
|
|
|
|
|
2017-05-25 05:20:59 -04:00
|
|
|
switch (layout_mode)
|
|
|
|
{
|
|
|
|
case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL:
|
|
|
|
break;
|
|
|
|
case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL:
|
2017-06-05 03:59:47 -04:00
|
|
|
constraints |= META_MONITOR_SCALES_CONSTRAINT_NO_FRAC;
|
2017-05-25 05:20:59 -04:00
|
|
|
break;
|
|
|
|
}
|
2017-06-05 03:59:47 -04:00
|
|
|
|
|
|
|
return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
|
|
|
|
constraints,
|
|
|
|
n_supported_scales);
|
2017-01-26 04:14:32 -05:00
|
|
|
}
|
|
|
|
|
2017-02-07 03:01:40 -05:00
|
|
|
static MetaMonitorManagerCapability
|
|
|
|
meta_monitor_manager_kms_get_capabilities (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_get_backend ();
|
2017-04-21 04:40:51 -04:00
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
2017-02-07 03:01:40 -05: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 04:40:51 -04:00
|
|
|
if (meta_settings_is_experimental_feature_enabled (
|
|
|
|
settings,
|
2017-02-24 05:10:52 -05:00
|
|
|
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
|
|
|
|
capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
|
|
|
|
|
2017-02-07 03:01:40 -05: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 03:06:46 -05: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 05:10:52 -05:00
|
|
|
static MetaLogicalMonitorLayoutMode
|
|
|
|
meta_monitor_manager_kms_get_default_layout_mode (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-04-21 04:40:51 -04:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaSettings *settings = meta_backend_get_settings (backend);
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
if (!meta_is_stage_views_enabled ())
|
|
|
|
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
|
|
|
|
|
2017-04-21 04:40:51 -04:00
|
|
|
if (meta_settings_is_experimental_feature_enabled (
|
|
|
|
settings,
|
2017-02-24 05:10:52 -05: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 16:05:31 -04: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 05:36:18 -04: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 02:55:06 -04:00
|
|
|
g_source_destroy ((GSource *) manager_kms->source);
|
2013-07-30 05:36:18 -04: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 16:05:31 -04:00
|
|
|
object_class->dispose = meta_monitor_manager_kms_dispose;
|
2013-07-30 05:36:18 -04: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 00:27:21 -05:00
|
|
|
manager_class->ensure_initial_config = meta_monitor_manager_kms_ensure_initial_config;
|
2017-01-09 01:31:18 -05:00
|
|
|
manager_class->apply_monitors_config = meta_monitor_manager_kms_apply_monitors_config;
|
2013-07-30 05:36:18 -04: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 03:05:00 -05:00
|
|
|
manager_class->is_transform_handled = meta_monitor_manager_kms_is_transform_handled;
|
2017-01-20 02:07:12 -05:00
|
|
|
manager_class->calculate_monitor_mode_scale = meta_monitor_manager_kms_calculate_monitor_mode_scale;
|
2017-06-05 03:59:47 -04:00
|
|
|
manager_class->calculate_supported_scales = meta_monitor_manager_kms_calculate_supported_scales;
|
2017-02-07 03:01:40 -05:00
|
|
|
manager_class->get_capabilities = meta_monitor_manager_kms_get_capabilities;
|
2017-02-15 03:06:46 -05:00
|
|
|
manager_class->get_max_screen_size = meta_monitor_manager_kms_get_max_screen_size;
|
2017-02-24 05:10:52 -05:00
|
|
|
manager_class->get_default_layout_mode = meta_monitor_manager_kms_get_default_layout_mode;
|
2016-07-31 17:41:26 -04:00
|
|
|
}
|