mirror of
https://github.com/brl/mutter.git
synced 2025-08-02 22:54:44 +00:00
backends: Split out CRTC/output management to MetaGpu
In order to eventually support multilpe GPUs with their own connectors, split out related meta data management (i.e. outputs, CRTCs and CRTC modes) into a new MetaGpu GObject. The Xrandr backend always assumes there is always only a single "GPU" as the GPU is abstracted by the X server; only the native backend (aside from the test backend) will eventually see more than one GPU. The Xrandr backend still moves some management to MetaGpuXrandr, in order to behave more similarly to the KMS counterparts. https://bugzilla.gnome.org/show_bug.cgi?id=785381
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "backends/native/meta-crtc-kms.h"
|
||||
|
||||
#include "backends/meta-backend-private.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
#define ALL_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
|
||||
#define ALL_TRANSFORMS_MASK ((1 << ALL_TRANSFORMS) - 1)
|
||||
@@ -57,13 +57,12 @@ void
|
||||
meta_crtc_kms_apply_transform (MetaCrtc *crtc)
|
||||
{
|
||||
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
||||
MetaMonitorManager *monitor_manager = meta_crtc_get_monitor_manager (crtc);
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
int kms_fd;
|
||||
MetaMonitorTransform hw_transform;
|
||||
|
||||
kms_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
if (crtc_kms->all_hw_transforms & (1 << crtc->transform))
|
||||
hw_transform = crtc->transform;
|
||||
@@ -91,15 +90,14 @@ meta_crtc_kms_set_underscan (MetaCrtc *crtc,
|
||||
gboolean is_underscanning)
|
||||
{
|
||||
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
||||
MetaMonitorManager *monitor_manager = meta_crtc_get_monitor_manager (crtc);
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
int kms_fd;
|
||||
|
||||
if (!crtc_kms->underscan_prop_id)
|
||||
return;
|
||||
|
||||
kms_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
if (is_underscanning)
|
||||
{
|
||||
@@ -136,17 +134,16 @@ meta_crtc_kms_set_underscan (MetaCrtc *crtc,
|
||||
}
|
||||
|
||||
static int
|
||||
find_property_index (MetaMonitorManager *monitor_manager,
|
||||
find_property_index (MetaGpu *gpu,
|
||||
drmModeObjectPropertiesPtr props,
|
||||
const char *prop_name,
|
||||
drmModePropertyPtr *out_prop)
|
||||
{
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
int kms_fd;
|
||||
unsigned int i;
|
||||
|
||||
kms_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
for (i = 0; i < props->count_props; i++)
|
||||
{
|
||||
@@ -197,13 +194,13 @@ parse_transforms (MetaCrtc *crtc,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_primary_plane (MetaMonitorManager *monitor_manager,
|
||||
is_primary_plane (MetaGpu *gpu,
|
||||
drmModeObjectPropertiesPtr props)
|
||||
{
|
||||
drmModePropertyPtr prop;
|
||||
int idx;
|
||||
|
||||
idx = find_property_index (monitor_manager, props, "type", &prop);
|
||||
idx = find_property_index (gpu, props, "type", &prop);
|
||||
if (idx < 0)
|
||||
return FALSE;
|
||||
|
||||
@@ -212,19 +209,18 @@ is_primary_plane (MetaMonitorManager *monitor_manager,
|
||||
}
|
||||
|
||||
static void
|
||||
init_crtc_rotations (MetaCrtc *crtc,
|
||||
MetaMonitorManager *monitor_manager)
|
||||
init_crtc_rotations (MetaCrtc *crtc,
|
||||
MetaGpu *gpu)
|
||||
{
|
||||
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
int kms_fd;
|
||||
drmModeObjectPropertiesPtr props;
|
||||
drmModePlaneRes *planes;
|
||||
drmModePlane *drm_plane;
|
||||
unsigned int i;
|
||||
|
||||
kms_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
planes = drmModeGetPlaneResources (kms_fd);
|
||||
if (planes == NULL)
|
||||
@@ -245,12 +241,12 @@ init_crtc_rotations (MetaCrtc *crtc,
|
||||
drm_plane->plane_id,
|
||||
DRM_MODE_OBJECT_PLANE);
|
||||
|
||||
if (props && is_primary_plane (monitor_manager, props))
|
||||
if (props && is_primary_plane (gpu, props))
|
||||
{
|
||||
int rotation_idx;
|
||||
|
||||
crtc_kms->primary_plane_id = drm_plane->plane_id;
|
||||
rotation_idx = find_property_index (monitor_manager, props,
|
||||
rotation_idx = find_property_index (gpu, props,
|
||||
"rotation", &prop);
|
||||
if (rotation_idx >= 0)
|
||||
{
|
||||
@@ -273,15 +269,15 @@ init_crtc_rotations (MetaCrtc *crtc,
|
||||
}
|
||||
|
||||
static void
|
||||
find_crtc_properties (MetaCrtc *crtc,
|
||||
MetaMonitorManagerKms *monitor_manager_kms)
|
||||
find_crtc_properties (MetaCrtc *crtc,
|
||||
MetaGpuKms *gpu_kms)
|
||||
{
|
||||
MetaCrtcKms *crtc_kms = crtc->driver_private;
|
||||
int kms_fd;
|
||||
drmModeObjectPropertiesPtr props;
|
||||
unsigned int i;
|
||||
|
||||
kms_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
props = drmModeObjectGetProperties (kms_fd, crtc->crtc_id,
|
||||
DRM_MODE_OBJECT_CRTC);
|
||||
if (!props)
|
||||
@@ -314,18 +310,17 @@ meta_crtc_destroy_notify (MetaCrtc *crtc)
|
||||
}
|
||||
|
||||
MetaCrtc *
|
||||
meta_create_kms_crtc (MetaMonitorManager *monitor_manager,
|
||||
drmModeCrtc *drm_crtc,
|
||||
unsigned int crtc_index)
|
||||
meta_create_kms_crtc (MetaGpuKms *gpu_kms,
|
||||
drmModeCrtc *drm_crtc,
|
||||
unsigned int crtc_index)
|
||||
{
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
MetaCrtc *crtc;
|
||||
MetaCrtcKms *crtc_kms;
|
||||
|
||||
crtc = g_object_new (META_TYPE_CRTC, NULL);
|
||||
|
||||
crtc->monitor_manager = monitor_manager;
|
||||
crtc->gpu = gpu;
|
||||
crtc->crtc_id = drm_crtc->crtc_id;
|
||||
crtc->rect.x = drm_crtc->x;
|
||||
crtc->rect.y = drm_crtc->y;
|
||||
@@ -340,7 +335,7 @@ meta_create_kms_crtc (MetaMonitorManager *monitor_manager,
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = monitor_manager->modes; l; l = l->next)
|
||||
for (l = meta_gpu_get_modes (gpu); l; l = l->next)
|
||||
{
|
||||
MetaCrtcMode *mode = l->data;
|
||||
|
||||
@@ -358,8 +353,8 @@ meta_create_kms_crtc (MetaMonitorManager *monitor_manager,
|
||||
crtc->driver_private = crtc_kms;
|
||||
crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify;
|
||||
|
||||
find_crtc_properties (crtc, monitor_manager_kms);
|
||||
init_crtc_rotations (crtc, monitor_manager);
|
||||
find_crtc_properties (crtc, gpu_kms);
|
||||
init_crtc_rotations (crtc, gpu);
|
||||
|
||||
return crtc;
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "backends/meta-crtc.h"
|
||||
#include "backends/meta-gpu.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
gboolean meta_crtc_kms_is_transform_handled (MetaCrtc *crtc,
|
||||
MetaMonitorTransform transform);
|
||||
@@ -35,8 +37,8 @@ void meta_crtc_kms_apply_transform (MetaCrtc *crtc);
|
||||
void meta_crtc_kms_set_underscan (MetaCrtc *crtc,
|
||||
gboolean is_underscanning);
|
||||
|
||||
MetaCrtc * meta_create_kms_crtc (MetaMonitorManager *monitor_manager,
|
||||
drmModeCrtc *drm_crtc,
|
||||
unsigned int crtc_index);
|
||||
MetaCrtc * meta_create_kms_crtc (MetaGpuKms *gpu_kms,
|
||||
drmModeCrtc *drm_crtc,
|
||||
unsigned int crtc_index);
|
||||
|
||||
#endif /* META_CRTC_KMS_H */
|
||||
|
@@ -488,6 +488,7 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
|
||||
{
|
||||
MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
|
||||
MetaCursorRendererNativePrivate *priv = meta_cursor_renderer_native_get_instance_private (native);
|
||||
GList *gpus;
|
||||
CoglTexture *texture;
|
||||
|
||||
if (priv->hw_cursor_broken)
|
||||
@@ -496,6 +497,10 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
|
||||
if (!cursor_sprite)
|
||||
return FALSE;
|
||||
|
||||
gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
|
||||
if (g_list_length (gpus) != 1)
|
||||
return FALSE;
|
||||
|
||||
if (cursor_over_transformed_logical_monitor (renderer, cursor_sprite))
|
||||
return FALSE;
|
||||
|
||||
@@ -853,24 +858,26 @@ on_monitors_changed (MetaMonitorManager *monitors,
|
||||
}
|
||||
|
||||
static void
|
||||
init_hw_cursor_support (MetaCursorRendererNative *cursor_renderer_native,
|
||||
MetaBackend *backend)
|
||||
init_hw_cursor_support (MetaCursorRendererNative *cursor_renderer_native)
|
||||
{
|
||||
MetaRendererNative *renderer_native =
|
||||
META_RENDERER_NATIVE (meta_backend_get_renderer (backend));
|
||||
MetaCursorRendererNativePrivate *priv =
|
||||
meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (priv->monitor_manager);
|
||||
GList *gpus;
|
||||
MetaGpuKms *gpu_kms;
|
||||
uint64_t width, height;
|
||||
struct gbm_device *gbm_device;
|
||||
|
||||
gbm_device = meta_renderer_native_get_gbm (renderer_native);
|
||||
gpus = meta_monitor_manager_get_gpus (priv->monitor_manager);
|
||||
if (g_list_length (gpus) != 1)
|
||||
return;
|
||||
|
||||
gpu_kms = META_GPU_KMS (gpus->data);
|
||||
gbm_device = meta_gbm_device_from_gpu (gpu_kms);
|
||||
if (!gbm_device)
|
||||
return;
|
||||
|
||||
priv->gbm = gbm_device;
|
||||
priv->drm_fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
priv->drm_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
if (drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_WIDTH, &width) == 0 &&
|
||||
drmGetCap (priv->drm_fd, DRM_CAP_CURSOR_HEIGHT, &height) == 0)
|
||||
@@ -905,7 +912,7 @@ meta_cursor_renderer_native_new (MetaBackend *backend)
|
||||
priv->monitor_manager = monitor_manager;
|
||||
priv->hw_state_invalidated = TRUE;
|
||||
|
||||
init_hw_cursor_support (cursor_renderer_native, backend);
|
||||
init_hw_cursor_support (cursor_renderer_native);
|
||||
|
||||
return cursor_renderer_native;
|
||||
}
|
||||
|
759
src/backends/native/meta-gpu-kms.c
Normal file
759
src/backends/native/meta-gpu-kms.c
Normal file
@@ -0,0 +1,759 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
#include <drm.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "backends/meta-crtc.h"
|
||||
#include "backends/meta-monitor-manager-private.h"
|
||||
#include "backends/meta-output.h"
|
||||
#include "backends/native/meta-backend-native.h"
|
||||
#include "backends/native/meta-crtc-kms.h"
|
||||
#include "backends/native/meta-launcher.h"
|
||||
#include "backends/native/meta-output-kms.h"
|
||||
#include "backends/native/meta-default-modes.h"
|
||||
|
||||
typedef struct _MetaKmsSource
|
||||
{
|
||||
GSource source;
|
||||
|
||||
gpointer fd_tag;
|
||||
MetaGpuKms *gpu_kms;
|
||||
} MetaKmsSource;
|
||||
|
||||
struct _MetaGpuKms
|
||||
{
|
||||
MetaGpu parent;
|
||||
|
||||
int fd;
|
||||
char *file_path;
|
||||
GSource *source;
|
||||
|
||||
drmModeConnector **connectors;
|
||||
unsigned int n_connectors;
|
||||
|
||||
int max_buffer_width;
|
||||
int max_buffer_height;
|
||||
|
||||
gboolean page_flips_not_supported;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaGpuKms, meta_gpu_kms, META_TYPE_GPU)
|
||||
|
||||
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_gpu_kms_wait_for_flip (kms_source->gpu_kms);
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static GSourceFuncs kms_event_funcs = {
|
||||
NULL,
|
||||
kms_event_check,
|
||||
kms_event_dispatch
|
||||
};
|
||||
|
||||
static void
|
||||
get_crtc_drm_connectors (MetaGpu *gpu,
|
||||
MetaCrtc *crtc,
|
||||
uint32_t **connectors,
|
||||
unsigned int *n_connectors)
|
||||
{
|
||||
GArray *connectors_array = g_array_new (FALSE, FALSE, sizeof (uint32_t));
|
||||
GList *l;
|
||||
|
||||
for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->crtc == crtc)
|
||||
g_array_append_val (connectors_array, output->winsys_id);
|
||||
}
|
||||
|
||||
*n_connectors = connectors_array->len;
|
||||
*connectors = (uint32_t *) g_array_free (connectors_array, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_gpu_kms_apply_crtc_mode (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id)
|
||||
{
|
||||
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
||||
int kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
uint32_t *connectors;
|
||||
unsigned int n_connectors;
|
||||
drmModeModeInfo *mode;
|
||||
|
||||
get_crtc_drm_connectors (gpu, crtc, &connectors, &n_connectors);
|
||||
|
||||
if (connectors)
|
||||
mode = crtc->current_mode->driver_private;
|
||||
else
|
||||
mode = NULL;
|
||||
|
||||
if (drmModeSetCrtc (kms_fd,
|
||||
crtc->crtc_id,
|
||||
fb_id,
|
||||
x, y,
|
||||
connectors, n_connectors,
|
||||
mode) != 0)
|
||||
{
|
||||
g_warning ("Failed to set CRTC mode %s: %m", crtc->current_mode->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free (connectors);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
|
||||
GList *l;
|
||||
gboolean connected_crtc_found;
|
||||
|
||||
if (monitor_manager->power_save_mode != META_POWER_SAVE_ON)
|
||||
return FALSE;
|
||||
|
||||
connected_crtc_found = FALSE;
|
||||
for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->crtc == crtc)
|
||||
{
|
||||
connected_crtc_found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected_crtc_found)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id,
|
||||
GClosure *flip_closure,
|
||||
gboolean *fb_in_use)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
|
||||
uint32_t *connectors;
|
||||
unsigned int n_connectors;
|
||||
int ret = -1;
|
||||
|
||||
g_assert (meta_crtc_get_gpu (crtc) == gpu);
|
||||
g_assert (monitor_manager->power_save_mode == META_POWER_SAVE_ON);
|
||||
|
||||
get_crtc_drm_connectors (gpu, crtc, &connectors, &n_connectors);
|
||||
g_assert (n_connectors > 0);
|
||||
|
||||
if (!gpu_kms->page_flips_not_supported)
|
||||
{
|
||||
int kms_fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
ret = drmModePageFlip (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));
|
||||
gpu_kms->page_flips_not_supported = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpu_kms->page_flips_not_supported)
|
||||
{
|
||||
if (meta_gpu_kms_apply_crtc_mode (gpu_kms, crtc, x, y, fb_id))
|
||||
{
|
||||
*fb_in_use = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
return FALSE;
|
||||
|
||||
*fb_in_use = TRUE;
|
||||
g_closure_ref (flip_closure);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
page_flip_handler (int fd,
|
||||
unsigned int frame,
|
||||
unsigned int sec,
|
||||
unsigned int usec,
|
||||
void *user_data)
|
||||
{
|
||||
GClosure *flip_closure = user_data;
|
||||
|
||||
invoke_flip_closure (flip_closure);
|
||||
}
|
||||
|
||||
void
|
||||
meta_gpu_kms_wait_for_flip (MetaGpuKms *gpu_kms)
|
||||
{
|
||||
drmEventContext evctx;
|
||||
|
||||
if (gpu_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 (gpu_kms->fd, &evctx);
|
||||
}
|
||||
|
||||
void
|
||||
meta_gpu_kms_get_max_buffer_size (MetaGpuKms *gpu_kms,
|
||||
int *max_width,
|
||||
int *max_height)
|
||||
{
|
||||
*max_width = gpu_kms->max_buffer_width;
|
||||
*max_height = gpu_kms->max_buffer_height;
|
||||
}
|
||||
|
||||
int
|
||||
meta_gpu_kms_get_fd (MetaGpuKms *gpu_kms)
|
||||
{
|
||||
return gpu_kms->fd;
|
||||
}
|
||||
|
||||
const char *
|
||||
meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms)
|
||||
{
|
||||
return gpu_kms->file_path;
|
||||
}
|
||||
|
||||
void
|
||||
meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
|
||||
uint64_t state)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = meta_gpu_get_outputs (META_GPU (gpu_kms)); l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
meta_output_kms_set_power_save_mode (output, state);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_resources (MetaGpuKms *gpu_kms)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < gpu_kms->n_connectors; i++)
|
||||
drmModeFreeConnector (gpu_kms->connectors[i]);
|
||||
|
||||
g_free (gpu_kms->connectors);
|
||||
}
|
||||
|
||||
static int
|
||||
compare_outputs (gconstpointer one,
|
||||
gconstpointer two)
|
||||
{
|
||||
const MetaOutput *o_one = one, *o_two = two;
|
||||
|
||||
return strcmp (o_one->name, o_two->name);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_crtc_mode_destroy_notify (MetaCrtcMode *mode)
|
||||
{
|
||||
g_slice_free (drmModeModeInfo, mode->driver_private);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_drm_mode_equal (const drmModeModeInfo *one,
|
||||
const drmModeModeInfo *two)
|
||||
{
|
||||
return (one->clock == two->clock &&
|
||||
one->hdisplay == two->hdisplay &&
|
||||
one->hsync_start == two->hsync_start &&
|
||||
one->hsync_end == two->hsync_end &&
|
||||
one->htotal == two->htotal &&
|
||||
one->hskew == two->hskew &&
|
||||
one->vdisplay == two->vdisplay &&
|
||||
one->vsync_start == two->vsync_start &&
|
||||
one->vsync_end == two->vsync_end &&
|
||||
one->vtotal == two->vtotal &&
|
||||
one->vscan == two->vscan &&
|
||||
one->vrefresh == two->vrefresh &&
|
||||
one->flags == two->flags &&
|
||||
one->type == two->type &&
|
||||
strncmp (one->name, 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;
|
||||
}
|
||||
|
||||
MetaCrtcMode *
|
||||
meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
|
||||
const drmModeModeInfo *drm_mode)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
GList *l;
|
||||
|
||||
for (l = meta_gpu_get_modes (gpu); l; l = l->next)
|
||||
{
|
||||
MetaCrtcMode *mode = l->data;
|
||||
|
||||
if (meta_drm_mode_equal (drm_mode, mode->driver_private))
|
||||
return mode;
|
||||
}
|
||||
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
float
|
||||
meta_calculate_drm_mode_refresh_rate (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;
|
||||
}
|
||||
|
||||
static MetaCrtcMode *
|
||||
create_mode (const drmModeModeInfo *drm_mode,
|
||||
long mode_id)
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
|
||||
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;
|
||||
mode->refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
|
||||
mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode);
|
||||
mode->driver_notify = (GDestroyNotify) meta_crtc_mode_destroy_notify;
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
static MetaOutput *
|
||||
find_output_by_id (GList *outputs,
|
||||
glong id)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = outputs; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->winsys_id == id)
|
||||
return output;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_output_clones (MetaGpu *gpu)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = meta_gpu_get_outputs (gpu); l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
GList *k;
|
||||
|
||||
for (k = meta_gpu_get_outputs (gpu); k; k = k->next)
|
||||
{
|
||||
MetaOutput *other_output = k->data;
|
||||
|
||||
if (other_output == output)
|
||||
continue;
|
||||
|
||||
if (meta_output_kms_can_clone (output, other_output))
|
||||
{
|
||||
output->n_possible_clones++;
|
||||
output->possible_clones = g_renew (MetaOutput *,
|
||||
output->possible_clones,
|
||||
output->n_possible_clones);
|
||||
output->possible_clones[output->n_possible_clones - 1] =
|
||||
other_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_connectors (MetaGpuKms *gpu_kms,
|
||||
drmModeRes *resources)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
gpu_kms->n_connectors = resources->count_connectors;
|
||||
gpu_kms->connectors = g_new (drmModeConnector *, gpu_kms->n_connectors);
|
||||
for (i = 0; i < gpu_kms->n_connectors; i++)
|
||||
{
|
||||
drmModeConnector *drm_connector;
|
||||
|
||||
drm_connector = drmModeGetConnector (gpu_kms->fd,
|
||||
resources->connectors[i]);
|
||||
gpu_kms->connectors[i] = drm_connector;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_modes (MetaGpuKms *gpu_kms,
|
||||
drmModeRes *resources)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
GHashTable *modes_table;
|
||||
GList *modes;
|
||||
GHashTableIter iter;
|
||||
drmModeModeInfo *drm_mode;
|
||||
unsigned int i;
|
||||
long mode_id;
|
||||
|
||||
/*
|
||||
* Gather all modes on all connected connectors.
|
||||
*/
|
||||
modes_table = g_hash_table_new (drm_mode_hash, (GEqualFunc) meta_drm_mode_equal);
|
||||
for (i = 0; i < gpu_kms->n_connectors; i++)
|
||||
{
|
||||
drmModeConnector *drm_connector;
|
||||
|
||||
drm_connector = gpu_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_table, &drm_connector->modes[j]);
|
||||
}
|
||||
}
|
||||
|
||||
modes = NULL;
|
||||
|
||||
g_hash_table_iter_init (&iter, modes_table);
|
||||
mode_id = 0;
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &drm_mode))
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = create_mode (drm_mode, (long) mode_id);
|
||||
modes = g_list_append (modes, mode);
|
||||
|
||||
mode_id++;
|
||||
}
|
||||
|
||||
g_hash_table_destroy (modes_table);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = create_mode (&meta_default_drm_mode_infos[i], (long) mode_id);
|
||||
modes = g_list_append (modes, mode);
|
||||
|
||||
mode_id++;
|
||||
}
|
||||
|
||||
meta_gpu_take_modes (gpu, modes);
|
||||
}
|
||||
|
||||
static void
|
||||
init_crtcs (MetaGpuKms *gpu_kms,
|
||||
MetaKmsResources *resources)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
GList *crtcs;
|
||||
unsigned int i;
|
||||
|
||||
crtcs = NULL;
|
||||
|
||||
for (i = 0; i < (unsigned int) resources->resources->count_crtcs; i++)
|
||||
{
|
||||
drmModeCrtc *drm_crtc;
|
||||
MetaCrtc *crtc;
|
||||
|
||||
drm_crtc = drmModeGetCrtc (gpu_kms->fd,
|
||||
resources->resources->crtcs[i]);
|
||||
|
||||
crtc = meta_create_kms_crtc (gpu_kms, drm_crtc, i);
|
||||
|
||||
drmModeFreeCrtc (drm_crtc);
|
||||
|
||||
crtcs = g_list_append (crtcs, crtc);
|
||||
}
|
||||
|
||||
meta_gpu_take_crtcs (gpu, crtcs);
|
||||
}
|
||||
|
||||
static void
|
||||
init_outputs (MetaGpuKms *gpu_kms,
|
||||
MetaKmsResources *resources)
|
||||
{
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
GList *old_outputs;
|
||||
GList *outputs;
|
||||
unsigned int i;
|
||||
|
||||
old_outputs = meta_gpu_get_outputs (gpu);
|
||||
|
||||
outputs = NULL;
|
||||
|
||||
for (i = 0; i < gpu_kms->n_connectors; i++)
|
||||
{
|
||||
drmModeConnector *connector;
|
||||
|
||||
connector = gpu_kms->connectors[i];
|
||||
|
||||
if (connector && connector->connection == DRM_MODE_CONNECTED)
|
||||
{
|
||||
MetaOutput *output;
|
||||
MetaOutput *old_output;
|
||||
|
||||
old_output = find_output_by_id (old_outputs, connector->connector_id);
|
||||
output = meta_create_kms_output (gpu_kms, connector, resources,
|
||||
old_output);
|
||||
outputs = g_list_prepend (outputs, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Sort the outputs for easier handling in MetaMonitorConfig */
|
||||
outputs = g_list_sort (outputs, compare_outputs);
|
||||
meta_gpu_take_outputs (gpu, outputs);
|
||||
|
||||
setup_output_clones (gpu);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_gpu_kms_read_current (MetaGpu *gpu,
|
||||
GError **error)
|
||||
{
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_gpu_get_monitor_manager (gpu);
|
||||
MetaKmsResources resources;
|
||||
|
||||
meta_kms_resources_init (&resources, gpu_kms->fd);
|
||||
|
||||
gpu_kms->max_buffer_width = resources.resources->max_width;
|
||||
gpu_kms->max_buffer_height = resources.resources->max_height;
|
||||
|
||||
monitor_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 (gpu_kms);
|
||||
|
||||
init_connectors (gpu_kms, resources.resources);
|
||||
init_modes (gpu_kms, resources.resources);
|
||||
init_crtcs (gpu_kms, &resources);
|
||||
init_outputs (gpu_kms, &resources);
|
||||
|
||||
meta_kms_resources_release (&resources);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
MetaGpuKms *
|
||||
meta_gpu_kms_new (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
const char *kms_file_path,
|
||||
GError **error)
|
||||
{
|
||||
MetaMonitorManager *monitor_manager =
|
||||
META_MONITOR_MANAGER (monitor_manager_kms);
|
||||
MetaBackend *backend = meta_monitor_manager_get_backend (monitor_manager);
|
||||
MetaLauncher *launcher =
|
||||
meta_backend_native_get_launcher (META_BACKEND_NATIVE (backend));
|
||||
GSource *source;
|
||||
MetaKmsSource *kms_source;
|
||||
MetaGpuKms *gpu_kms;
|
||||
int kms_fd;
|
||||
|
||||
kms_fd = meta_launcher_open_restricted (launcher, kms_file_path, error);
|
||||
if (kms_fd == -1)
|
||||
return FALSE;
|
||||
|
||||
gpu_kms = g_object_new (META_TYPE_GPU_KMS,
|
||||
"monitor-manager", monitor_manager_kms,
|
||||
NULL);
|
||||
|
||||
gpu_kms->fd = kms_fd;
|
||||
gpu_kms->file_path = g_strdup (kms_file_path);
|
||||
|
||||
drmSetClientCap (gpu_kms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
|
||||
|
||||
source = g_source_new (&kms_event_funcs, sizeof (MetaKmsSource));
|
||||
kms_source = (MetaKmsSource *) source;
|
||||
kms_source->fd_tag = g_source_add_unix_fd (source,
|
||||
gpu_kms->fd,
|
||||
G_IO_IN | G_IO_ERR);
|
||||
kms_source->gpu_kms = gpu_kms;
|
||||
|
||||
gpu_kms->source = source;
|
||||
g_source_attach (gpu_kms->source, NULL);
|
||||
|
||||
return gpu_kms;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_gpu_kms_finalize (GObject *object)
|
||||
{
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (object);
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_gpu_get_monitor_manager (META_GPU (gpu_kms));
|
||||
MetaBackend *backend = meta_monitor_manager_get_backend (monitor_manager);
|
||||
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
||||
MetaLauncher *launcher = meta_backend_native_get_launcher (backend_native);
|
||||
|
||||
if (gpu_kms->fd != -1)
|
||||
meta_launcher_close_restricted (launcher, gpu_kms->fd);
|
||||
g_clear_pointer (&gpu_kms->file_path, g_free);
|
||||
|
||||
g_source_destroy (gpu_kms->source);
|
||||
|
||||
free_resources (gpu_kms);
|
||||
|
||||
G_OBJECT_CLASS (meta_gpu_kms_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_gpu_kms_init (MetaGpuKms *gpu_kms)
|
||||
{
|
||||
gpu_kms->fd = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_gpu_kms_class_init (MetaGpuKmsClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
MetaGpuClass *gpu_class = META_GPU_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_gpu_kms_finalize;
|
||||
|
||||
gpu_class->read_current = meta_gpu_kms_read_current;
|
||||
}
|
86
src/backends/native/meta-gpu-kms.h
Normal file
86
src/backends/native/meta-gpu-kms.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef META_GPU_KMS_H
|
||||
#define META_GPU_KMS_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "backends/meta-gpu.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
|
||||
#define META_TYPE_GPU_KMS (meta_gpu_kms_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaGpuKms, meta_gpu_kms, META, GPU_KMS, MetaGpu)
|
||||
|
||||
typedef struct _MetaKmsResources
|
||||
{
|
||||
drmModeRes *resources;
|
||||
drmModeEncoder **encoders;
|
||||
unsigned int n_encoders;
|
||||
} MetaKmsResources;
|
||||
|
||||
typedef void (*MetaKmsFlipCallback) (void *user_data);
|
||||
|
||||
MetaGpuKms * meta_gpu_kms_new (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
const char *kms_file_path,
|
||||
GError **error);
|
||||
|
||||
gboolean meta_gpu_kms_apply_crtc_mode (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id);
|
||||
|
||||
gboolean meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc);
|
||||
|
||||
gboolean meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id,
|
||||
GClosure *flip_closure,
|
||||
gboolean *fb_in_use);
|
||||
|
||||
void meta_gpu_kms_wait_for_flip (MetaGpuKms *gpu_kms);
|
||||
|
||||
int meta_gpu_kms_get_fd (MetaGpuKms *gpu_kms);
|
||||
|
||||
const char * meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms);
|
||||
|
||||
void meta_gpu_kms_get_max_buffer_size (MetaGpuKms *gpu_kms,
|
||||
int *max_width,
|
||||
int *max_height);
|
||||
|
||||
void meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
|
||||
uint64_t state);
|
||||
|
||||
MetaCrtcMode * meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
|
||||
const drmModeModeInfo *drm_mode);
|
||||
|
||||
gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
|
||||
const drmModeModeInfo *two);
|
||||
|
||||
float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode);
|
||||
|
||||
#endif /* META_GPU_KMS_H */
|
@@ -32,6 +32,7 @@
|
||||
#include "meta-backend-private.h"
|
||||
#include "meta-renderer-native.h"
|
||||
#include "meta-crtc-kms.h"
|
||||
#include "meta-gpu-kms.h"
|
||||
#include "meta-output-kms.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -49,8 +50,6 @@
|
||||
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "meta-default-modes.h"
|
||||
|
||||
#define DRM_CARD_UDEV_DEVICE_TYPE "drm_minor"
|
||||
|
||||
typedef struct
|
||||
@@ -65,20 +64,10 @@ struct _MetaMonitorManagerKms
|
||||
{
|
||||
MetaMonitorManager parent_instance;
|
||||
|
||||
int fd;
|
||||
char *file_path;
|
||||
MetaKmsSource *source;
|
||||
|
||||
drmModeConnector **connectors;
|
||||
unsigned int n_connectors;
|
||||
MetaGpuKms *primary_gpu;
|
||||
|
||||
GUdevClient *udev;
|
||||
guint uevent_handler_id;
|
||||
|
||||
gboolean page_flips_not_supported;
|
||||
|
||||
int max_buffer_width;
|
||||
int max_buffer_height;
|
||||
};
|
||||
|
||||
struct _MetaMonitorManagerKmsClass
|
||||
@@ -94,378 +83,6 @@ G_DEFINE_TYPE_WITH_CODE (MetaMonitorManagerKms, meta_monitor_manager_kms,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
initable_iface_init))
|
||||
|
||||
int
|
||||
meta_monitor_manager_kms_get_fd (MetaMonitorManagerKms *manager_kms)
|
||||
{
|
||||
return manager_kms->fd;
|
||||
}
|
||||
|
||||
const char *
|
||||
meta_monitor_manager_kms_get_file_path (MetaMonitorManagerKms *manager_kms)
|
||||
{
|
||||
return manager_kms->file_path;
|
||||
}
|
||||
|
||||
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
|
||||
compare_outputs (gconstpointer one,
|
||||
gconstpointer two)
|
||||
{
|
||||
const MetaOutput *o_one = one, *o_two = two;
|
||||
|
||||
return strcmp (o_one->name, o_two->name);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_monitor_mode_destroy_notify (MetaCrtcMode *mode)
|
||||
{
|
||||
g_slice_free (drmModeModeInfo, mode->driver_private);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_drm_mode_equal (const drmModeModeInfo *one,
|
||||
const drmModeModeInfo *two)
|
||||
{
|
||||
return (one->clock == two->clock &&
|
||||
one->hdisplay == two->hdisplay &&
|
||||
one->hsync_start == two->hsync_start &&
|
||||
one->hsync_end == two->hsync_end &&
|
||||
one->htotal == two->htotal &&
|
||||
one->hskew == two->hskew &&
|
||||
one->vdisplay == two->vdisplay &&
|
||||
one->vsync_start == two->vsync_start &&
|
||||
one->vsync_end == two->vsync_end &&
|
||||
one->vtotal == two->vtotal &&
|
||||
one->vscan == two->vscan &&
|
||||
one->vrefresh == two->vrefresh &&
|
||||
one->flags == two->flags &&
|
||||
one->type == two->type &&
|
||||
strncmp (one->name, 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;
|
||||
}
|
||||
|
||||
MetaCrtcMode *
|
||||
meta_monitor_manager_kms_get_mode_from_drm_mode (MetaMonitorManagerKms *manager_kms,
|
||||
const drmModeModeInfo *drm_mode)
|
||||
{
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
GList *l;
|
||||
|
||||
for (l = manager->modes; l; l = l->next)
|
||||
{
|
||||
MetaCrtcMode *mode = l->data;
|
||||
|
||||
if (meta_drm_mode_equal (drm_mode, mode->driver_private))
|
||||
return mode;
|
||||
}
|
||||
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
float
|
||||
meta_calculate_drm_mode_refresh_rate (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;
|
||||
}
|
||||
|
||||
static MetaCrtcMode *
|
||||
create_mode (const drmModeModeInfo *drm_mode,
|
||||
long mode_id)
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = g_object_new (META_TYPE_CRTC_MODE, NULL);
|
||||
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;
|
||||
mode->refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
|
||||
mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode);
|
||||
mode->driver_notify = (GDestroyNotify) meta_monitor_mode_destroy_notify;
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
static MetaOutput *
|
||||
find_output_by_id (GList *outputs,
|
||||
glong id)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = outputs; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->winsys_id == id)
|
||||
return output;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_output_clones (MetaMonitorManager *manager)
|
||||
{
|
||||
GList *l;
|
||||
|
||||
for (l = manager->outputs; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
GList *k;
|
||||
|
||||
for (k = manager->outputs; k; k = k->next)
|
||||
{
|
||||
MetaOutput *other_output = k->data;
|
||||
|
||||
if (other_output == output)
|
||||
continue;
|
||||
|
||||
if (meta_output_kms_can_clone (output, other_output))
|
||||
{
|
||||
output->n_possible_clones++;
|
||||
output->possible_clones = g_renew (MetaOutput *,
|
||||
output->possible_clones,
|
||||
output->n_possible_clones);
|
||||
output->possible_clones[output->n_possible_clones - 1] =
|
||||
other_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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, (GEqualFunc) meta_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]);
|
||||
}
|
||||
}
|
||||
|
||||
manager->modes = NULL;
|
||||
|
||||
g_hash_table_iter_init (&iter, modes);
|
||||
mode_id = 0;
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &drm_mode))
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = create_mode (drm_mode, (long) mode_id);
|
||||
manager->modes = g_list_append (manager->modes, mode);
|
||||
|
||||
mode_id++;
|
||||
}
|
||||
|
||||
g_hash_table_destroy (modes);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
||||
{
|
||||
MetaCrtcMode *mode;
|
||||
|
||||
mode = create_mode (&meta_default_drm_mode_infos[i], (long) mode_id);
|
||||
manager->modes = g_list_append (manager->modes, mode);
|
||||
|
||||
mode_id++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_crtcs (MetaMonitorManager *manager,
|
||||
MetaKmsResources *resources)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
||||
unsigned int i;
|
||||
|
||||
manager->crtcs = NULL;
|
||||
|
||||
for (i = 0; i < (unsigned int) resources->resources->count_crtcs; i++)
|
||||
{
|
||||
drmModeCrtc *drm_crtc;
|
||||
MetaCrtc *crtc;
|
||||
|
||||
drm_crtc = drmModeGetCrtc (manager_kms->fd,
|
||||
resources->resources->crtcs[i]);
|
||||
|
||||
crtc = meta_create_kms_crtc (manager, drm_crtc, i);
|
||||
|
||||
drmModeFreeCrtc (drm_crtc);
|
||||
|
||||
manager->crtcs = g_list_append (manager->crtcs, crtc);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_outputs (MetaMonitorManager *manager,
|
||||
MetaKmsResources *resources)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
||||
GList *old_outputs;
|
||||
unsigned int i;
|
||||
|
||||
old_outputs = manager->outputs;
|
||||
|
||||
manager->outputs = NULL;
|
||||
|
||||
for (i = 0; i < manager_kms->n_connectors; i++)
|
||||
{
|
||||
drmModeConnector *connector;
|
||||
|
||||
connector = manager_kms->connectors[i];
|
||||
|
||||
if (connector && connector->connection == DRM_MODE_CONNECTED)
|
||||
{
|
||||
MetaOutput *output;
|
||||
MetaOutput *old_output;
|
||||
|
||||
old_output = find_output_by_id (old_outputs, connector->connector_id);
|
||||
output = meta_create_kms_output (manager, connector, resources, old_output);
|
||||
manager->outputs = g_list_prepend (manager->outputs, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Sort the outputs for easier handling in MetaMonitorConfig */
|
||||
manager->outputs = g_list_sort (manager->outputs, compare_outputs);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_monitor_manager_kms_read_current (MetaMonitorManager *manager)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
||||
MetaKmsResources resources;
|
||||
|
||||
meta_kms_resources_init (&resources, manager_kms->fd);
|
||||
|
||||
manager_kms->max_buffer_width = resources.resources->max_width;
|
||||
manager_kms->max_buffer_height = resources.resources->max_height;
|
||||
|
||||
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.resources);
|
||||
init_modes (manager, resources.resources);
|
||||
init_crtcs (manager, &resources);
|
||||
init_outputs (manager, &resources);
|
||||
|
||||
meta_kms_resources_release (&resources);
|
||||
}
|
||||
|
||||
static GBytes *
|
||||
meta_monitor_manager_kms_read_edid (MetaMonitorManager *manager,
|
||||
MetaOutput *output)
|
||||
@@ -497,11 +114,11 @@ meta_monitor_manager_kms_set_power_save_mode (MetaMonitorManager *manager,
|
||||
return;
|
||||
}
|
||||
|
||||
for (l = manager->outputs; l; l = l->next)
|
||||
for (l = manager->gpus; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
MetaGpuKms *gpu_kms = l->data;
|
||||
|
||||
meta_output_kms_set_power_save_mode (output, state);
|
||||
meta_gpu_kms_set_power_save_mode (gpu_kms, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,23 +196,29 @@ apply_crtc_assignments (MetaMonitorManager *manager,
|
||||
}
|
||||
/* Disable CRTCs not mentioned in the list (they have is_dirty == FALSE,
|
||||
because they weren't seen in the first loop) */
|
||||
for (l = manager->crtcs; l; l = l->next)
|
||||
for (l = manager->gpus; l; l = l->next)
|
||||
{
|
||||
MetaCrtc *crtc = l->data;
|
||||
MetaGpu *gpu = l->data;
|
||||
GList *k;
|
||||
|
||||
crtc->logical_monitor = NULL;
|
||||
|
||||
if (crtc->is_dirty)
|
||||
for (k = meta_gpu_get_crtcs (gpu); k; k = k->next)
|
||||
{
|
||||
crtc->is_dirty = FALSE;
|
||||
continue;
|
||||
}
|
||||
MetaCrtc *crtc = k->data;
|
||||
|
||||
crtc->rect.x = 0;
|
||||
crtc->rect.y = 0;
|
||||
crtc->rect.width = 0;
|
||||
crtc->rect.height = 0;
|
||||
crtc->current_mode = NULL;
|
||||
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++)
|
||||
@@ -611,18 +234,24 @@ apply_crtc_assignments (MetaMonitorManager *manager,
|
||||
}
|
||||
|
||||
/* Disable outputs not mentioned in the list */
|
||||
for (l = manager->outputs; l; l = l->next)
|
||||
for (l = manager->gpus; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
MetaGpu *gpu = l->data;
|
||||
GList *k;
|
||||
|
||||
if (output->is_dirty)
|
||||
for (k = meta_gpu_get_outputs (gpu); k; k = k->next)
|
||||
{
|
||||
output->is_dirty = FALSE;
|
||||
continue;
|
||||
}
|
||||
MetaOutput *output = k->data;
|
||||
|
||||
output->crtc = NULL;
|
||||
output->is_primary = FALSE;
|
||||
if (output->is_dirty)
|
||||
{
|
||||
output->is_dirty = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
output->crtc = NULL;
|
||||
output->is_primary = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -707,17 +336,18 @@ meta_monitor_manager_kms_get_crtc_gamma (MetaMonitorManager *manager,
|
||||
unsigned short **green,
|
||||
unsigned short **blue)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
||||
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
||||
int kms_fd = meta_gpu_kms_get_fd (META_GPU_KMS (gpu));
|
||||
drmModeCrtc *kms_crtc;
|
||||
|
||||
kms_crtc = drmModeGetCrtc (manager_kms->fd, crtc->crtc_id);
|
||||
kms_crtc = drmModeGetCrtc (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);
|
||||
drmModeCrtcGetGamma (kms_fd, crtc->crtc_id, *size, *red, *green, *blue);
|
||||
|
||||
drmModeFreeCrtc (kms_crtc);
|
||||
}
|
||||
@@ -730,9 +360,10 @@ meta_monitor_manager_kms_set_crtc_gamma (MetaMonitorManager *manager,
|
||||
unsigned short *green,
|
||||
unsigned short *blue)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager);
|
||||
MetaGpu *gpu = meta_crtc_get_gpu (crtc);
|
||||
int kms_fd = meta_gpu_kms_get_fd (META_GPU_KMS (gpu));
|
||||
|
||||
drmModeCrtcSetGamma (manager_kms->fd, crtc->crtc_id, size, red, green, blue);
|
||||
drmModeCrtcSetGamma (kms_fd, crtc->crtc_id, size, red, green, blue);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -757,32 +388,6 @@ on_uevent (GUdevClient *client,
|
||||
handle_hotplug_event (manager);
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
static void
|
||||
meta_monitor_manager_kms_connect_uevent_handler (MetaMonitorManagerKms *manager_kms)
|
||||
{
|
||||
@@ -815,182 +420,6 @@ meta_monitor_manager_kms_resume (MetaMonitorManagerKms *manager_kms)
|
||||
handle_hotplug_event (manager);
|
||||
}
|
||||
|
||||
static void
|
||||
get_crtc_connectors (MetaMonitorManager *manager,
|
||||
MetaCrtc *crtc,
|
||||
uint32_t **connectors,
|
||||
unsigned int *n_connectors)
|
||||
{
|
||||
GArray *connectors_array = g_array_new (FALSE, FALSE, sizeof (uint32_t));
|
||||
GList *l;
|
||||
|
||||
for (l = manager->outputs; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->crtc == crtc)
|
||||
g_array_append_val (connectors_array, output->winsys_id);
|
||||
}
|
||||
|
||||
*n_connectors = connectors_array->len;
|
||||
*connectors = (uint32_t *) g_array_free (connectors_array, FALSE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_monitor_manager_kms_apply_crtc_mode (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id)
|
||||
{
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
uint32_t *connectors;
|
||||
unsigned int n_connectors;
|
||||
drmModeModeInfo *mode;
|
||||
|
||||
get_crtc_connectors (manager, crtc, &connectors, &n_connectors);
|
||||
|
||||
if (connectors)
|
||||
mode = crtc->current_mode->driver_private;
|
||||
else
|
||||
mode = NULL;
|
||||
|
||||
if (drmModeSetCrtc (manager_kms->fd,
|
||||
crtc->crtc_id,
|
||||
fb_id,
|
||||
x, y,
|
||||
connectors, n_connectors,
|
||||
mode) != 0)
|
||||
{
|
||||
g_warning ("Failed to set CRTC mode %s: %m", crtc->current_mode->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_free (connectors);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_monitor_manager_kms_is_crtc_active (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc)
|
||||
{
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
GList *l;
|
||||
gboolean connected_crtc_found;
|
||||
|
||||
if (manager->power_save_mode != META_POWER_SAVE_ON)
|
||||
return FALSE;
|
||||
|
||||
connected_crtc_found = FALSE;
|
||||
for (l = manager->outputs; l; l = l->next)
|
||||
{
|
||||
MetaOutput *output = l->data;
|
||||
|
||||
if (output->crtc == crtc)
|
||||
{
|
||||
connected_crtc_found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!connected_crtc_found)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
meta_monitor_manager_kms_flip_crtc (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id,
|
||||
GClosure *flip_closure,
|
||||
gboolean *fb_in_use)
|
||||
{
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
uint32_t *connectors;
|
||||
unsigned int n_connectors;
|
||||
int ret = -1;
|
||||
|
||||
g_assert (manager->power_save_mode == META_POWER_SAVE_ON);
|
||||
|
||||
get_crtc_connectors (manager, crtc, &connectors, &n_connectors);
|
||||
g_assert (n_connectors > 0);
|
||||
|
||||
if (!manager_kms->page_flips_not_supported)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (manager_kms->page_flips_not_supported)
|
||||
{
|
||||
if (meta_monitor_manager_kms_apply_crtc_mode (manager_kms,
|
||||
crtc,
|
||||
x, y,
|
||||
fb_id))
|
||||
{
|
||||
*fb_in_use = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
return FALSE;
|
||||
|
||||
*fb_in_use = TRUE;
|
||||
g_closure_ref (flip_closure);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
page_flip_handler (int fd,
|
||||
unsigned int frame,
|
||||
unsigned int sec,
|
||||
unsigned int usec,
|
||||
void *data)
|
||||
{
|
||||
GClosure *flip_closure = data;
|
||||
|
||||
invoke_flip_closure (flip_closure);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_monitor_manager_kms_is_transform_handled (MetaMonitorManager *manager,
|
||||
MetaCrtc *crtc,
|
||||
@@ -1046,16 +475,8 @@ meta_monitor_manager_kms_get_capabilities (MetaMonitorManager *manager)
|
||||
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER))
|
||||
capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
|
||||
|
||||
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
|
||||
}
|
||||
if (meta_renderer_native_supports_mirroring (renderer_native))
|
||||
capabilities |= META_MONITOR_MANAGER_CAPABILITY_MIRRORING;
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
@@ -1070,8 +491,8 @@ meta_monitor_manager_kms_get_max_screen_size (MetaMonitorManager *manager,
|
||||
if (meta_is_stage_views_enabled ())
|
||||
return FALSE;
|
||||
|
||||
*max_width = manager_kms->max_buffer_width;
|
||||
*max_height = manager_kms->max_buffer_height;
|
||||
meta_gpu_kms_get_max_buffer_size (manager_kms->primary_gpu,
|
||||
max_width, max_height);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1093,6 +514,12 @@ meta_monitor_manager_kms_get_default_layout_mode (MetaMonitorManager *manager)
|
||||
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
|
||||
}
|
||||
|
||||
MetaGpuKms *
|
||||
meta_monitor_manager_kms_get_primary_gpu (MetaMonitorManagerKms *manager_kms)
|
||||
{
|
||||
return manager_kms->primary_gpu;
|
||||
}
|
||||
|
||||
static guint
|
||||
count_devices_with_connectors (const char *seat_id,
|
||||
GList *devices)
|
||||
@@ -1256,64 +683,34 @@ out:
|
||||
}
|
||||
|
||||
static gboolean
|
||||
open_primary_gpu (MetaMonitorManagerKms *manager_kms,
|
||||
int *fd_out,
|
||||
char **kms_file_path_out,
|
||||
GError **error)
|
||||
meta_monitor_manager_kms_initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
|
||||
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
||||
MetaLauncher *launcher = meta_backend_native_get_launcher (backend_native);
|
||||
g_autofree char *path = NULL;
|
||||
int fd;
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (initable);
|
||||
const char *subsystems[2] = { "drm", NULL };
|
||||
g_autofree char *primary_gpu_path;
|
||||
|
||||
path = get_primary_gpu_path (manager_kms);
|
||||
if (!path)
|
||||
manager_kms->udev = g_udev_client_new (subsystems);
|
||||
|
||||
primary_gpu_path = get_primary_gpu_path (manager_kms);
|
||||
if (!primary_gpu_path)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Could not find drm kms device");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fd = meta_launcher_open_restricted (launcher, path, error);
|
||||
if (fd == -1)
|
||||
manager_kms->primary_gpu = meta_gpu_kms_new (manager_kms,
|
||||
primary_gpu_path,
|
||||
error);
|
||||
if (!manager_kms->primary_gpu)
|
||||
return FALSE;
|
||||
|
||||
*fd_out = fd;
|
||||
*kms_file_path_out = g_steal_pointer (&path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
meta_monitor_manager_kms_initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (initable);
|
||||
GSource *source;
|
||||
const char *subsystems[2] = { "drm", NULL };
|
||||
|
||||
manager_kms->udev = g_udev_client_new (subsystems);
|
||||
|
||||
if (!open_primary_gpu (manager_kms,
|
||||
&manager_kms->fd,
|
||||
&manager_kms->file_path,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
drmSetClientCap (manager_kms->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
|
||||
|
||||
meta_monitor_manager_kms_connect_uevent_handler (manager_kms);
|
||||
|
||||
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);
|
||||
meta_monitor_manager_add_gpu (META_MONITOR_MANAGER (manager_kms),
|
||||
META_GPU (manager_kms->primary_gpu));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1334,29 +731,9 @@ meta_monitor_manager_kms_dispose (GObject *object)
|
||||
G_OBJECT_CLASS (meta_monitor_manager_kms_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_monitor_manager_kms_finalize (GObject *object)
|
||||
{
|
||||
MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (object);
|
||||
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_kms);
|
||||
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
|
||||
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
|
||||
MetaLauncher *launcher = meta_backend_native_get_launcher (backend_native);
|
||||
|
||||
if (manager_kms->fd != -1)
|
||||
meta_launcher_close_restricted (launcher, manager_kms->fd);
|
||||
g_clear_pointer (&manager_kms->file_path, g_free);
|
||||
|
||||
free_resources (manager_kms);
|
||||
g_source_destroy ((GSource *) manager_kms->source);
|
||||
|
||||
G_OBJECT_CLASS (meta_monitor_manager_kms_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_monitor_manager_kms_init (MetaMonitorManagerKms *manager_kms)
|
||||
{
|
||||
manager_kms->fd = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1366,9 +743,7 @@ meta_monitor_manager_kms_class_init (MetaMonitorManagerKmsClass *klass)
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = meta_monitor_manager_kms_dispose;
|
||||
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;
|
||||
manager_class->ensure_initial_config = meta_monitor_manager_kms_ensure_initial_config;
|
||||
manager_class->apply_monitors_config = meta_monitor_manager_kms_apply_monitors_config;
|
||||
|
@@ -28,53 +28,17 @@
|
||||
|
||||
#include "meta-monitor-manager-private.h"
|
||||
|
||||
typedef struct _MetaGpuKms MetaGpuKms;
|
||||
|
||||
#define META_TYPE_MONITOR_MANAGER_KMS (meta_monitor_manager_kms_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaMonitorManagerKms, meta_monitor_manager_kms,
|
||||
META, MONITOR_MANAGER_KMS,
|
||||
MetaMonitorManager)
|
||||
|
||||
typedef struct _MetaKmsResources
|
||||
{
|
||||
drmModeRes *resources;
|
||||
drmModeEncoder **encoders;
|
||||
unsigned int n_encoders;
|
||||
} MetaKmsResources;
|
||||
|
||||
typedef void (*MetaKmsFlipCallback) (void *user_data);
|
||||
|
||||
int meta_monitor_manager_kms_get_fd (MetaMonitorManagerKms *manager_kms);
|
||||
|
||||
const char * meta_monitor_manager_kms_get_file_path (MetaMonitorManagerKms *manager_kms);
|
||||
|
||||
gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
|
||||
const drmModeModeInfo *two);
|
||||
|
||||
MetaCrtcMode * meta_monitor_manager_kms_get_mode_from_drm_mode (MetaMonitorManagerKms *manager_kms,
|
||||
const drmModeModeInfo *drm_mode);
|
||||
|
||||
gboolean meta_monitor_manager_kms_apply_crtc_mode (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id);
|
||||
|
||||
gboolean meta_monitor_manager_kms_is_crtc_active (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc);
|
||||
|
||||
gboolean meta_monitor_manager_kms_flip_crtc (MetaMonitorManagerKms *manager_kms,
|
||||
MetaCrtc *crtc,
|
||||
int x,
|
||||
int y,
|
||||
uint32_t fb_id,
|
||||
GClosure *flip_closure,
|
||||
gboolean *fb_in_use);
|
||||
|
||||
void meta_monitor_manager_kms_wait_for_flip (MetaMonitorManagerKms *manager_kms);
|
||||
MetaGpuKms * meta_monitor_manager_kms_get_primary_gpu (MetaMonitorManagerKms *manager_kms);
|
||||
|
||||
void meta_monitor_manager_kms_pause (MetaMonitorManagerKms *manager_kms);
|
||||
|
||||
void meta_monitor_manager_kms_resume (MetaMonitorManagerKms *manager_kms);
|
||||
|
||||
float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode);
|
||||
|
||||
#endif /* META_MONITOR_MANAGER_KMS_H */
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include "backends/meta-crtc.h"
|
||||
#include "backends/native/meta-crtc-kms.h"
|
||||
#include "backends/native/meta-default-modes.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
|
||||
#define SYNC_TOLERANCE 0.01 /* 1 percent */
|
||||
|
||||
@@ -77,16 +76,14 @@ meta_output_kms_set_power_save_mode (MetaOutput *output,
|
||||
uint64_t state)
|
||||
{
|
||||
MetaOutputKms *output_kms = output->driver_private;
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_output_get_monitor_manager (output);
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = meta_output_get_gpu (output);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
|
||||
if (output_kms->dpms_prop_id != 0)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
if (drmModeObjectSetProperty (fd, output->winsys_id,
|
||||
DRM_MODE_OBJECT_CONNECTOR,
|
||||
output_kms->dpms_prop_id, state) < 0)
|
||||
@@ -113,14 +110,14 @@ meta_output_kms_can_clone (MetaOutput *output,
|
||||
}
|
||||
|
||||
static drmModePropertyBlobPtr
|
||||
read_edid_blob (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
uint32_t edid_blob_id,
|
||||
GError **error)
|
||||
read_edid_blob (MetaGpuKms *gpu_kms,
|
||||
uint32_t edid_blob_id,
|
||||
GError **error)
|
||||
{
|
||||
int fd;
|
||||
drmModePropertyBlobPtr edid_blob = NULL;
|
||||
|
||||
fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
edid_blob = drmModeGetPropertyBlob (fd, edid_blob_id);
|
||||
if (!edid_blob)
|
||||
{
|
||||
@@ -133,16 +130,16 @@ read_edid_blob (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
}
|
||||
|
||||
static GBytes *
|
||||
read_output_edid (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
MetaOutput *output,
|
||||
GError **error)
|
||||
read_output_edid (MetaGpuKms *gpu_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 (monitor_manager_kms, output_kms->edid_blob_id, error);
|
||||
edid_blob = read_edid_blob (gpu_kms, output_kms->edid_blob_id, error);
|
||||
if (!edid_blob)
|
||||
return NULL;
|
||||
|
||||
@@ -159,8 +156,8 @@ read_output_edid (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
output_get_tile_info (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
MetaOutput *output)
|
||||
output_get_tile_info (MetaGpuKms *gpu_kms,
|
||||
MetaOutput *output)
|
||||
{
|
||||
MetaOutputKms *output_kms = output->driver_private;
|
||||
int fd;
|
||||
@@ -169,7 +166,7 @@ output_get_tile_info (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
if (output_kms->tile_blob_id == 0)
|
||||
return FALSE;
|
||||
|
||||
fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
tile_blob = drmModeGetPropertyBlob (fd, output_kms->tile_blob_id);
|
||||
if (!tile_blob)
|
||||
{
|
||||
@@ -211,17 +208,15 @@ GBytes *
|
||||
meta_output_kms_read_edid (MetaOutput *output)
|
||||
{
|
||||
MetaOutputKms *output_kms = output->driver_private;
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_output_get_monitor_manager (output);
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = meta_output_get_gpu (output);
|
||||
MetaGpuKms *gpu_kms = META_GPU_KMS (gpu);
|
||||
GError *error = NULL;
|
||||
GBytes *edid;
|
||||
|
||||
if (output_kms->edid_blob_id == 0)
|
||||
return NULL;
|
||||
|
||||
edid = read_output_edid (monitor_manager_kms, output, &error);
|
||||
edid = read_output_edid (gpu_kms, output, &error);
|
||||
if (!edid)
|
||||
{
|
||||
g_warning ("Failed to read EDID from '%s': %s",
|
||||
@@ -234,14 +229,14 @@ meta_output_kms_read_edid (MetaOutput *output)
|
||||
}
|
||||
|
||||
static void
|
||||
find_connector_properties (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
MetaOutputKms *output_kms)
|
||||
find_connector_properties (MetaGpuKms *gpu_kms,
|
||||
MetaOutputKms *output_kms)
|
||||
{
|
||||
drmModeConnector *connector = output_kms->connector;
|
||||
int fd;
|
||||
int i;
|
||||
|
||||
fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
output_kms->hotplug_mode_update = 0;
|
||||
output_kms->suggested_x = -1;
|
||||
@@ -327,8 +322,8 @@ meta_output_destroy_notify (MetaOutput *output)
|
||||
}
|
||||
|
||||
static void
|
||||
add_common_modes (MetaOutput *output,
|
||||
MetaMonitorManagerKms *monitor_manager_kms)
|
||||
add_common_modes (MetaOutput *output,
|
||||
MetaGpuKms *gpu_kms)
|
||||
{
|
||||
GPtrArray *array;
|
||||
unsigned i;
|
||||
@@ -365,8 +360,8 @@ add_common_modes (MetaOutput *output,
|
||||
refresh_rate > max_refresh_rate)
|
||||
continue;
|
||||
|
||||
crtc_mode = meta_monitor_manager_kms_get_mode_from_drm_mode (monitor_manager_kms,
|
||||
drm_mode);
|
||||
crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms,
|
||||
drm_mode);
|
||||
g_ptr_array_add (array, crtc_mode);
|
||||
}
|
||||
|
||||
@@ -397,8 +392,8 @@ compare_modes (const void *one,
|
||||
}
|
||||
|
||||
static void
|
||||
init_output_modes (MetaOutput *output,
|
||||
MetaMonitorManagerKms *monitor_manager_kms)
|
||||
init_output_modes (MetaOutput *output,
|
||||
MetaGpuKms *gpu_kms)
|
||||
{
|
||||
MetaOutputKms *output_kms = output->driver_private;
|
||||
unsigned int i;
|
||||
@@ -412,9 +407,7 @@ init_output_modes (MetaOutput *output,
|
||||
MetaCrtcMode *crtc_mode;
|
||||
|
||||
drm_mode = &output_kms->connector->modes[i];
|
||||
crtc_mode =
|
||||
meta_monitor_manager_kms_get_mode_from_drm_mode (monitor_manager_kms,
|
||||
drm_mode);
|
||||
crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms, drm_mode);
|
||||
output->modes[i] = crtc_mode;
|
||||
if (output_kms->connector->modes[i].type & DRM_MODE_TYPE_PREFERRED)
|
||||
output->preferred_mode = output->modes[i];
|
||||
@@ -425,13 +418,12 @@ init_output_modes (MetaOutput *output,
|
||||
}
|
||||
|
||||
MetaOutput *
|
||||
meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
drmModeConnector *connector,
|
||||
MetaKmsResources *resources,
|
||||
MetaOutput *old_output)
|
||||
meta_create_kms_output (MetaGpuKms *gpu_kms,
|
||||
drmModeConnector *connector,
|
||||
MetaKmsResources *resources,
|
||||
MetaOutput *old_output)
|
||||
{
|
||||
MetaMonitorManagerKms *monitor_manager_kms =
|
||||
META_MONITOR_MANAGER_KMS (monitor_manager);
|
||||
MetaGpu *gpu = META_GPU (gpu_kms);
|
||||
MetaOutput *output;
|
||||
MetaOutputKms *output_kms;
|
||||
GArray *crtcs;
|
||||
@@ -447,7 +439,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
output->driver_private = output_kms;
|
||||
output->driver_notify = (GDestroyNotify) meta_output_destroy_notify;
|
||||
|
||||
output->monitor_manager = monitor_manager;
|
||||
output->gpu = gpu;
|
||||
output->winsys_id = connector->connector_id;
|
||||
output->name = make_output_name (connector);
|
||||
output->width_mm = connector->mmWidth;
|
||||
@@ -477,16 +469,16 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
}
|
||||
|
||||
output_kms->connector = connector;
|
||||
find_connector_properties (monitor_manager_kms, output_kms);
|
||||
find_connector_properties (gpu_kms, output_kms);
|
||||
|
||||
init_output_modes (output, monitor_manager_kms);
|
||||
init_output_modes (output, gpu_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 (output, monitor_manager_kms);
|
||||
add_common_modes (output, gpu_kms);
|
||||
|
||||
qsort (output->modes, output->n_modes,
|
||||
sizeof (MetaCrtcMode *), compare_modes);
|
||||
@@ -494,7 +486,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
output_kms->n_encoders = connector->count_encoders;
|
||||
output_kms->encoders = g_new0 (drmModeEncoderPtr, output_kms->n_encoders);
|
||||
|
||||
fd = meta_monitor_manager_kms_get_fd (monitor_manager_kms);
|
||||
fd = meta_gpu_kms_get_fd (gpu_kms);
|
||||
|
||||
crtc_mask = ~(unsigned int) 0;
|
||||
for (i = 0; i < output_kms->n_encoders; i++)
|
||||
@@ -516,7 +508,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
|
||||
crtcs = g_array_new (FALSE, FALSE, sizeof (MetaCrtc*));
|
||||
|
||||
for (l = monitor_manager->crtcs, i = 0; l; l = l->next, i++)
|
||||
for (l = meta_gpu_get_crtcs (gpu), i = 0; l; l = l->next, i++)
|
||||
{
|
||||
if (crtc_mask & (1 << i))
|
||||
{
|
||||
@@ -531,7 +523,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
|
||||
if (output_kms->current_encoder && output_kms->current_encoder->crtc_id != 0)
|
||||
{
|
||||
for (l = monitor_manager->crtcs; l; l = l->next)
|
||||
for (l = meta_gpu_get_crtcs (gpu); l; l = l->next)
|
||||
{
|
||||
MetaCrtc *crtc = l->data;
|
||||
|
||||
@@ -566,7 +558,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
edid = read_output_edid (monitor_manager_kms, output, &error);
|
||||
edid = read_output_edid (gpu_kms, output, &error);
|
||||
if (!edid)
|
||||
{
|
||||
g_warning ("Failed to read EDID blob from %s: %s",
|
||||
@@ -585,7 +577,7 @@ meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
/* MetaConnectorType matches DRM's connector types */
|
||||
output->connector_type = (MetaConnectorType) connector->connector_type;
|
||||
|
||||
output_get_tile_info (monitor_manager_kms, output);
|
||||
output_get_tile_info (gpu_kms, output);
|
||||
|
||||
/* FIXME: backlight is a very driver specific thing unfortunately,
|
||||
every DDX does its own thing, and the dumb KMS API does not include it.
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#define META_OUTPUT_KMS_H
|
||||
|
||||
#include "backends/meta-output.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
|
||||
void meta_output_kms_set_underscan (MetaOutput *output);
|
||||
|
||||
@@ -35,9 +35,9 @@ gboolean meta_output_kms_can_clone (MetaOutput *output,
|
||||
|
||||
GBytes * meta_output_kms_read_edid (MetaOutput *output);
|
||||
|
||||
MetaOutput * meta_create_kms_output (MetaMonitorManager *monitor_manager,
|
||||
drmModeConnector *connector,
|
||||
MetaKmsResources *resources,
|
||||
MetaOutput *old_output);
|
||||
MetaOutput * meta_create_kms_output (MetaGpuKms *gpu_kms,
|
||||
drmModeConnector *connector,
|
||||
MetaKmsResources *resources,
|
||||
MetaOutput *old_output);
|
||||
|
||||
#endif /* META_OUTPUT_KMS_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -25,10 +25,12 @@
|
||||
#ifndef META_RENDERER_NATIVE_H
|
||||
#define META_RENDERER_NATIVE_H
|
||||
|
||||
#include <gbm.h>
|
||||
#include <glib-object.h>
|
||||
#include <xf86drmMode.h>
|
||||
|
||||
#include "backends/meta-renderer.h"
|
||||
#include "backends/native/meta-gpu-kms.h"
|
||||
#include "backends/native/meta-monitor-manager-kms.h"
|
||||
|
||||
#define META_TYPE_RENDERER_NATIVE (meta_renderer_native_get_type ())
|
||||
@@ -47,9 +49,9 @@ typedef enum _MetaRendererNativeMode
|
||||
MetaRendererNative * meta_renderer_native_new (MetaMonitorManagerKms *monitor_manager_kms,
|
||||
GError **error);
|
||||
|
||||
MetaRendererNativeMode meta_renderer_native_get_mode (MetaRendererNative *renderer_native);
|
||||
struct gbm_device * meta_gbm_device_from_gpu (MetaGpuKms *gpu_kms);
|
||||
|
||||
struct gbm_device * meta_renderer_native_get_gbm (MetaRendererNative *renderer_native);
|
||||
gboolean meta_renderer_native_supports_mirroring (MetaRendererNative *renderer_native);
|
||||
|
||||
void meta_renderer_native_queue_modes_reset (MetaRendererNative *renderer_native);
|
||||
|
||||
|
Reference in New Issue
Block a user