summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2014-03-11 16:51:24 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2014-03-13 17:14:28 -0400
commit64be6cf4f0908f88dd9e2627c509b04c5a5ef41e (patch)
treeed74f0d2eeecc3417dba5d7b5a79f34ef2eaa2d6
parenta9d8107c3d60f57efe57b293f5197eb8397a3cf0 (diff)
downloadmutter-64be6cf4f0908f88dd9e2627c509b04c5a5ef41e.tar.gz
weston-launch: Pass the DRM device to Cogl
Open the device from weston-launch, and pass it to Cogl/Clutter. This is a preliminary cleanup for our login1 integration.
-rw-r--r--src/wayland/meta-wayland.c11
-rw-r--r--src/wayland/meta-weston-launch.c48
-rw-r--r--src/wayland/meta-weston-launch.h4
-rw-r--r--src/wayland/weston-launch.c84
-rw-r--r--src/wayland/weston-launch.h5
5 files changed, 36 insertions, 116 deletions
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 8cbe6cf4a..a13a920ae 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -653,17 +653,6 @@ meta_wayland_init (void)
if (clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
g_error ("Failed to initialize Clutter");
-#if defined(CLUTTER_WINDOWING_EGL)
- if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
- {
- ClutterBackend *backend = clutter_get_default_backend ();
- CoglContext *cogl_context = clutter_backend_get_cogl_context (backend);
- CoglRenderer *cogl_renderer = cogl_display_get_renderer (cogl_context_get_display (cogl_context));
- int drm_fd = cogl_kms_renderer_get_kms_fd (cogl_renderer);
- meta_launcher_set_drm_fd (compositor->launcher, drm_fd, NULL);
- }
-#endif
-
meta_monitor_manager_initialize ();
monitors = meta_monitor_manager_get ();
g_signal_connect (monitors, "monitors-changed",
diff --git a/src/wayland/meta-weston-launch.c b/src/wayland/meta-weston-launch.c
index 7d04493c2..6ef5c6908 100644
--- a/src/wayland/meta-weston-launch.c
+++ b/src/wayland/meta-weston-launch.c
@@ -23,6 +23,7 @@
#include <gio/gunixfdmessage.h>
#include <clutter/clutter.h>
+#include <clutter/egl/clutter-egl.h>
#include <clutter/evdev/clutter-evdev.h>
#include <glib.h>
@@ -156,36 +157,11 @@ send_message_to_wl (MetaLauncher *self,
return TRUE;
}
-gboolean
-meta_launcher_set_drm_fd (MetaLauncher *self,
- int drm_fd,
- GError **error)
-{
- struct weston_launcher_message message;
- GSocketControlMessage *cmsg;
- gboolean ok;
-
- message.opcode = WESTON_LAUNCHER_DRM_SET_FD;
-
- cmsg = g_unix_fd_message_new ();
- if (g_unix_fd_message_append_fd (G_UNIX_FD_MESSAGE (cmsg),
- drm_fd, error) == FALSE)
- {
- g_object_unref (cmsg);
- return FALSE;
- }
-
- ok = send_message_to_wl (self, &message, sizeof message, cmsg, NULL, error);
-
- g_object_unref (cmsg);
- return ok;
-}
-
static int
-meta_launcher_open_input_device (MetaLauncher *self,
- const char *name,
- int flags,
- GError **error)
+meta_launcher_open_device (MetaLauncher *self,
+ const char *name,
+ int flags,
+ GError **error)
{
struct weston_launcher_open *message;
GSocketControlMessage *cmsg;
@@ -261,7 +237,7 @@ on_evdev_device_open (const char *path,
{
MetaLauncher *launcher = user_data;
- return meta_launcher_open_input_device (launcher, path, flags, error);
+ return meta_launcher_open_device (launcher, path, flags, error);
}
static void
@@ -391,6 +367,18 @@ meta_launcher_new (void)
on_evdev_device_close,
self);
+#if defined(CLUTTER_WINDOWING_EGL)
+ if (clutter_check_windowing_backend (CLUTTER_WINDOWING_EGL))
+ {
+ GError *error = NULL;
+ int fd = meta_launcher_open_device (self, "/dev/dri/card0", O_RDWR, &error);
+ if (error)
+ g_error ("Failed to open /dev/dri/card0: %s", error->message);
+
+ clutter_egl_set_kms_fd (fd);
+ }
+#endif
+
return self;
}
diff --git a/src/wayland/meta-weston-launch.h b/src/wayland/meta-weston-launch.h
index 7fdd03c23..b70faf88e 100644
--- a/src/wayland/meta-weston-launch.h
+++ b/src/wayland/meta-weston-launch.h
@@ -31,8 +31,4 @@ void meta_launcher_free (MetaLauncher *self);
gboolean meta_launcher_activate_vt (MetaLauncher *self,
signed char vt,
GError **error);
-
-gboolean meta_launcher_set_drm_fd (MetaLauncher *self,
- int drm_fd,
- GError **error);
#endif
diff --git a/src/wayland/weston-launch.c b/src/wayland/weston-launch.c
index 240cfef16..ae713ed23 100644
--- a/src/wayland/weston-launch.c
+++ b/src/wayland/weston-launch.c
@@ -166,69 +166,6 @@ setenv_fd(const char *env, int fd)
}
static int
-handle_setdrmfd(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
-{
- struct weston_launcher_reply reply;
- struct cmsghdr *cmsg;
- union cmsg_data *data;
- struct stat s;
-
- reply.header.opcode = WESTON_LAUNCHER_DRM_SET_FD;
- reply.ret = -1;
-
- if (wl->drm_fd != -1) {
- error(0, 0, "DRM FD already set");
- reply.ret = -EINVAL;
- goto out;
- }
-
- cmsg = CMSG_FIRSTHDR(msg);
- if (!cmsg ||
- cmsg->cmsg_level != SOL_SOCKET ||
- cmsg->cmsg_type != SCM_RIGHTS) {
- error(0, 0, "invalid control message");
- reply.ret = -EINVAL;
- goto out;
- }
-
- data = (union cmsg_data *) CMSG_DATA(cmsg);
- if (data->fd < 0) {
- error(0, 0, "missing drm fd in socket request");
- reply.ret = -EINVAL;
- goto out;
- }
-
- if (fstat(data->fd, &s) < 0) {
- reply.ret = -errno;
- goto out;
- }
-
- if (major(s.st_rdev) != DRM_MAJOR) {
- fprintf(stderr, "FD is not for DRM\n");
- reply.ret = -EPERM;
- goto out;
- }
-
- wl->drm_fd = data->fd;
- reply.ret = drmSetMaster(data->fd);
- if (reply.ret < 0)
- reply.ret = -errno;
-
- if (wl->verbose)
- fprintf(stderr, "mutter-launch: set drm FD, ret: %d, fd: %d\n",
- reply.ret, data->fd);
-
-out:
- do {
- len = send(wl->sock[0], &reply, sizeof reply, 0);
- } while (len < 0 && errno == EINTR);
- if (len < 0)
- return -1;
-
- return 0;
-}
-
-static int
handle_confirm_vt_switch(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
{
struct weston_launcher_reply reply;
@@ -323,6 +260,7 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
struct iovec iov;
struct weston_launcher_open *message;
union cmsg_data *data;
+ int dev_major;
reply.header.opcode = WESTON_LAUNCHER_OPEN;
reply.ret = -1;
@@ -339,13 +277,22 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
goto err0;
}
- if (major(s.st_rdev) != INPUT_MAJOR) {
- fprintf(stderr, "Device %s is not an input device\n",
+ dev_major = major(s.st_rdev);
+
+ if (dev_major != INPUT_MAJOR ||
+ dev_major != DRM_MAJOR) {
+ fprintf(stderr, "Device %s is not an input or DRM device\n",
message->path);
reply.ret = -EPERM;
goto err0;
}
+ if (dev_major == DRM_MAJOR && wl->drm_fd != -1) {
+ fprintf(stderr, "Already have a DRM device open\n");
+ reply.ret = -EPERM;
+ goto err0;
+ }
+
fd = open(message->path, message->flags);
if (fd < 0) {
fprintf(stderr, "Error opening device %s: %m\n",
@@ -354,6 +301,10 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len)
goto err0;
}
+ if (dev_major == DRM_MAJOR) {
+ wl->drm_fd = fd;
+ }
+
err0:
memset(&nmsg, 0, sizeof nmsg);
nmsg.msg_iov = &iov;
@@ -419,9 +370,6 @@ handle_socket_msg(struct weston_launch *wl)
case WESTON_LAUNCHER_OPEN:
ret = handle_open(wl, &msg, len);
break;
- case WESTON_LAUNCHER_DRM_SET_FD:
- ret = handle_setdrmfd(wl, &msg, len);
- break;
case WESTON_LAUNCHER_CONFIRM_VT_SWITCH:
ret = handle_confirm_vt_switch(wl, &msg, len);
break;
diff --git a/src/wayland/weston-launch.h b/src/wayland/weston-launch.h
index 968dd7416..1e716c5ac 100644
--- a/src/wayland/weston-launch.h
+++ b/src/wayland/weston-launch.h
@@ -31,9 +31,8 @@ enum weston_launcher_message_type {
enum weston_launcher_opcode {
WESTON_LAUNCHER_OPEN = (1 << 1 | WESTON_LAUNCHER_REQUEST),
- WESTON_LAUNCHER_DRM_SET_FD = (2 << 1 | WESTON_LAUNCHER_REQUEST),
- WESTON_LAUNCHER_ACTIVATE_VT = (3 << 1 | WESTON_LAUNCHER_REQUEST),
- WESTON_LAUNCHER_CONFIRM_VT_SWITCH = (4 << 1 | WESTON_LAUNCHER_REQUEST),
+ WESTON_LAUNCHER_ACTIVATE_VT = (2 << 1 | WESTON_LAUNCHER_REQUEST),
+ WESTON_LAUNCHER_CONFIRM_VT_SWITCH = (3 << 1 | WESTON_LAUNCHER_REQUEST),
};
enum weston_launcher_server_opcode {