2017-07-04 08:04:39 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2017 Red Hat
|
2018-11-16 15:06:36 +00:00
|
|
|
* Copyright (C) 2018 DisplayLink (UK) Ltd.
|
2017-07-04 08:04:39 +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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/native/meta-crtc-kms.h"
|
|
|
|
|
|
|
|
#include "backends/meta-backend-private.h"
|
2017-07-10 10:19:32 +00:00
|
|
|
#include "backends/native/meta-gpu-kms.h"
|
2019-03-09 17:23:28 +00:00
|
|
|
#include "backends/native/meta-kms-device.h"
|
|
|
|
#include "backends/native/meta-kms-plane.h"
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2019-03-08 17:57:35 +00:00
|
|
|
#define ALL_TRANSFORMS_MASK ((1 << META_MONITOR_N_TRANSFORMS) - 1)
|
2017-07-04 08:04:39 +00:00
|
|
|
|
|
|
|
typedef struct _MetaCrtcKms
|
|
|
|
{
|
2019-01-29 17:33:00 +00:00
|
|
|
MetaKmsCrtc *kms_crtc;
|
|
|
|
|
2017-07-04 08:04:39 +00:00
|
|
|
uint32_t rotation_prop_id;
|
2019-03-08 17:57:35 +00:00
|
|
|
uint32_t rotation_map[META_MONITOR_N_TRANSFORMS];
|
2019-03-09 17:23:28 +00:00
|
|
|
|
|
|
|
MetaKmsPlane *primary_plane;
|
2017-07-04 08:04:39 +00:00
|
|
|
} MetaCrtcKms;
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
meta_crtc_kms_is_transform_handled (MetaCrtc *crtc,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
if (!crtc_kms->primary_plane)
|
2017-07-04 08:04:39 +00:00
|
|
|
return FALSE;
|
2019-03-09 17:23:28 +00:00
|
|
|
|
|
|
|
return meta_kms_plane_is_transform_handled (crtc_kms->primary_plane,
|
|
|
|
transform);
|
2017-07-04 08:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_crtc_kms_apply_transform (MetaCrtc *crtc)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2017-07-10 10:19:32 +00:00
|
|
|
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
2017-07-04 08:04:39 +00:00
|
|
|
int kms_fd;
|
|
|
|
MetaMonitorTransform hw_transform;
|
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
hw_transform = crtc->transform;
|
|
|
|
if (!meta_crtc_kms_is_transform_handled (crtc, hw_transform))
|
2017-07-04 08:04:39 +00:00
|
|
|
hw_transform = META_MONITOR_TRANSFORM_NORMAL;
|
2019-03-09 17:23:28 +00:00
|
|
|
if (!meta_crtc_kms_is_transform_handled (crtc, hw_transform))
|
2017-07-24 07:09:38 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-04 08:04:39 +00:00
|
|
|
if (drmModeObjectSetProperty (kms_fd,
|
2019-03-09 17:23:28 +00:00
|
|
|
meta_kms_plane_get_id (crtc_kms->primary_plane),
|
2017-07-04 08:04:39 +00:00
|
|
|
DRM_MODE_OBJECT_PLANE,
|
|
|
|
crtc_kms->rotation_prop_id,
|
|
|
|
crtc_kms->rotation_map[hw_transform]) != 0)
|
2019-03-09 17:23:28 +00:00
|
|
|
g_warning ("Failed to apply DRM plane transform %d: %m", hw_transform);
|
2017-07-04 08:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-10 10:19:32 +00:00
|
|
|
find_property_index (MetaGpu *gpu,
|
2017-07-04 08:04:39 +00:00
|
|
|
drmModeObjectPropertiesPtr props,
|
|
|
|
const char *prop_name,
|
|
|
|
drmModePropertyPtr *out_prop)
|
|
|
|
{
|
2017-07-10 10:19:32 +00:00
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
2017-07-04 08:04:39 +00:00
|
|
|
int kms_fd;
|
|
|
|
unsigned int i;
|
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2017-07-04 08:04:39 +00:00
|
|
|
|
|
|
|
for (i = 0; i < props->count_props; i++)
|
|
|
|
{
|
|
|
|
drmModePropertyPtr prop;
|
|
|
|
|
|
|
|
prop = drmModeGetProperty (kms_fd, props->props[i]);
|
|
|
|
if (!prop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp (prop->name, prop_name) == 0)
|
|
|
|
{
|
|
|
|
*out_prop = prop;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
drmModeFreeProperty (prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-03-09 14:55:24 +00:00
|
|
|
MetaKmsCrtc *
|
|
|
|
meta_crtc_kms_get_kms_crtc (MetaCrtc *crtc)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
|
|
|
return crtc_kms->kms_crtc;
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:12:32 +00:00
|
|
|
/**
|
|
|
|
* meta_crtc_kms_get_modifiers:
|
|
|
|
* @crtc: a #MetaCrtc object that has to be a #MetaCrtcKms
|
|
|
|
* @format: a DRM pixel format
|
|
|
|
*
|
|
|
|
* Returns a pointer to a #GArray containing all the supported
|
|
|
|
* modifiers for the given DRM pixel format on the CRTC's primary
|
|
|
|
* plane. The array element type is uint64_t.
|
|
|
|
*
|
|
|
|
* The caller must not modify or destroy the array or its contents.
|
|
|
|
*
|
|
|
|
* Returns NULL if the modifiers are not known or the format is not
|
|
|
|
* supported.
|
|
|
|
*/
|
2017-08-03 14:42:50 +00:00
|
|
|
GArray *
|
|
|
|
meta_crtc_kms_get_modifiers (MetaCrtc *crtc,
|
|
|
|
uint32_t format)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
return meta_kms_plane_get_modifiers_for_format (crtc_kms->primary_plane,
|
|
|
|
format);
|
2017-08-03 14:42:50 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 13:15:27 +00:00
|
|
|
/**
|
|
|
|
* meta_crtc_kms_copy_drm_format_list:
|
|
|
|
* @crtc: a #MetaCrtc object that has to be a #MetaCrtcKms
|
|
|
|
*
|
|
|
|
* Returns a new #GArray that the caller must destroy. The array
|
|
|
|
* contains all the DRM pixel formats the CRTC supports on
|
|
|
|
* its primary plane. The array element type is uint32_t.
|
|
|
|
*/
|
|
|
|
GArray *
|
|
|
|
meta_crtc_kms_copy_drm_format_list (MetaCrtc *crtc)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
return meta_kms_plane_copy_drm_format_list (crtc_kms->primary_plane);
|
2018-11-21 13:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_crtc_kms_supports_format:
|
|
|
|
* @crtc: a #MetaCrtc object that has to be a #MetaCrtcKms
|
|
|
|
* @drm_format: a DRM pixel format
|
|
|
|
*
|
|
|
|
* Returns true if the CRTC supports the format on its primary plane.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
meta_crtc_kms_supports_format (MetaCrtc *crtc,
|
|
|
|
uint32_t drm_format)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
return meta_kms_plane_is_format_supported (crtc_kms->primary_plane,
|
|
|
|
drm_format);
|
2017-08-03 12:42:15 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 08:04:39 +00:00
|
|
|
static void
|
|
|
|
parse_transforms (MetaCrtc *crtc,
|
|
|
|
drmModePropertyPtr prop)
|
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < prop->count_enums; i++)
|
|
|
|
{
|
|
|
|
int transform = -1;
|
|
|
|
|
|
|
|
if (strcmp (prop->enums[i].name, "rotate-0") == 0)
|
|
|
|
transform = META_MONITOR_TRANSFORM_NORMAL;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-90") == 0)
|
|
|
|
transform = META_MONITOR_TRANSFORM_90;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-180") == 0)
|
|
|
|
transform = META_MONITOR_TRANSFORM_180;
|
|
|
|
else if (strcmp (prop->enums[i].name, "rotate-270") == 0)
|
|
|
|
transform = META_MONITOR_TRANSFORM_270;
|
|
|
|
|
|
|
|
if (transform != -1)
|
2019-03-09 17:23:28 +00:00
|
|
|
crtc_kms->rotation_map[transform] = 1 << prop->enums[i].value;
|
2017-07-04 08:04:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-10 10:19:32 +00:00
|
|
|
init_crtc_rotations (MetaCrtc *crtc,
|
|
|
|
MetaGpu *gpu)
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
|
|
|
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
2017-07-10 10:19:32 +00:00
|
|
|
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
2017-07-04 08:04:39 +00:00
|
|
|
int kms_fd;
|
2019-03-09 17:23:28 +00:00
|
|
|
uint32_t primary_plane_id;
|
2017-07-04 08:04:39 +00:00
|
|
|
drmModePlane *drm_plane;
|
2019-03-09 17:23:28 +00:00
|
|
|
drmModeObjectPropertiesPtr props;
|
|
|
|
drmModePropertyPtr prop;
|
|
|
|
int rotation_idx;
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
2019-03-09 17:23:28 +00:00
|
|
|
primary_plane_id = meta_kms_plane_get_id (crtc_kms->primary_plane);
|
|
|
|
drm_plane = drmModeGetPlane (kms_fd, primary_plane_id);
|
|
|
|
props = drmModeObjectGetProperties (kms_fd,
|
|
|
|
primary_plane_id,
|
|
|
|
DRM_MODE_OBJECT_PLANE);
|
|
|
|
|
|
|
|
rotation_idx = find_property_index (gpu, props,
|
|
|
|
"rotation", &prop);
|
|
|
|
if (rotation_idx >= 0)
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
2019-03-09 17:23:28 +00:00
|
|
|
crtc_kms->rotation_prop_id = props->props[rotation_idx];
|
|
|
|
parse_transforms (crtc, prop);
|
|
|
|
drmModeFreeProperty (prop);
|
2017-07-04 08:04:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
drmModeFreeObjectProperties (props);
|
|
|
|
drmModeFreePlane (drm_plane);
|
2017-07-04 08:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_crtc_destroy_notify (MetaCrtc *crtc)
|
|
|
|
{
|
|
|
|
g_free (crtc->driver_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaCrtc *
|
2019-03-08 18:19:18 +00:00
|
|
|
meta_create_kms_crtc (MetaGpuKms *gpu_kms,
|
|
|
|
MetaKmsCrtc *kms_crtc)
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
2017-07-10 10:19:32 +00:00
|
|
|
MetaGpu *gpu = META_GPU (gpu_kms);
|
2019-03-09 17:23:28 +00:00
|
|
|
MetaKmsDevice *kms_device;
|
2017-07-04 08:04:39 +00:00
|
|
|
MetaCrtc *crtc;
|
|
|
|
MetaCrtcKms *crtc_kms;
|
2019-03-09 17:23:28 +00:00
|
|
|
MetaKmsPlane *primary_plane;
|
2019-03-08 18:19:18 +00:00
|
|
|
const MetaKmsCrtcState *crtc_state;
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2019-03-09 17:23:28 +00:00
|
|
|
kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
|
|
|
|
primary_plane = meta_kms_device_get_primary_plane_for (kms_device,
|
|
|
|
kms_crtc);
|
2019-03-08 18:19:18 +00:00
|
|
|
crtc_state = meta_kms_crtc_get_current_state (kms_crtc);
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2019-03-08 18:19:18 +00:00
|
|
|
crtc = g_object_new (META_TYPE_CRTC, NULL);
|
2017-07-10 10:19:32 +00:00
|
|
|
crtc->gpu = gpu;
|
2019-01-29 17:33:00 +00:00
|
|
|
crtc->crtc_id = meta_kms_crtc_get_id (kms_crtc);
|
2019-03-08 18:19:18 +00:00
|
|
|
crtc->rect = crtc_state->rect;
|
2017-07-04 08:04:39 +00:00
|
|
|
crtc->is_dirty = FALSE;
|
|
|
|
crtc->transform = META_MONITOR_TRANSFORM_NORMAL;
|
2018-12-04 13:55:05 +00:00
|
|
|
crtc->all_transforms = ALL_TRANSFORMS_MASK;
|
2017-07-04 08:04:39 +00:00
|
|
|
|
2019-03-08 18:19:18 +00:00
|
|
|
if (crtc_state->is_drm_mode_valid)
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
for (l = meta_gpu_get_modes (gpu); l; l = l->next)
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
|
|
|
MetaCrtcMode *mode = l->data;
|
|
|
|
|
2019-03-08 18:19:18 +00:00
|
|
|
if (meta_drm_mode_equal (&crtc_state->drm_mode, mode->driver_private))
|
2017-07-04 08:04:39 +00:00
|
|
|
{
|
|
|
|
crtc->current_mode = mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc_kms = g_new0 (MetaCrtcKms, 1);
|
2019-01-29 17:33:00 +00:00
|
|
|
crtc_kms->kms_crtc = kms_crtc;
|
2019-03-09 17:23:28 +00:00
|
|
|
crtc_kms->primary_plane = primary_plane;
|
2018-11-16 15:06:36 +00:00
|
|
|
|
2017-07-04 08:04:39 +00:00
|
|
|
crtc->driver_private = crtc_kms;
|
|
|
|
crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify;
|
|
|
|
|
2017-07-10 10:19:32 +00:00
|
|
|
init_crtc_rotations (crtc, gpu);
|
2017-07-04 08:04:39 +00:00
|
|
|
|
|
|
|
return crtc;
|
|
|
|
}
|