2010-09-28 14:17:46 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2011-05-09 21:45:33 +00:00
|
|
|
* Copyright (C) 2010, 2011 Intel Corporation.
|
2010-09-28 14:17:46 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
* Authors:
|
|
|
|
* Matthew Allum
|
|
|
|
* Robert Bragg
|
|
|
|
* Kristian Høgsberg
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-01-10 16:40:59 +00:00
|
|
|
#include <sys/mman.h>
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-10-21 10:29:09 +00:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
2011-05-09 21:45:33 +00:00
|
|
|
#include "clutter-main.h"
|
2010-10-21 10:29:09 +00:00
|
|
|
#include "clutter-stage-private.h"
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
#include "wayland/clutter-backend-wayland.h"
|
2013-01-30 00:49:38 +00:00
|
|
|
#include "wayland/clutter-backend-wayland-priv.h"
|
2011-05-09 21:45:33 +00:00
|
|
|
#include "wayland/clutter-device-manager-wayland.h"
|
|
|
|
#include "wayland/clutter-event-wayland.h"
|
|
|
|
#include "wayland/clutter-stage-wayland.h"
|
|
|
|
#include "cogl/clutter-stage-cogl.h"
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
#include <wayland-client.h>
|
2012-10-08 12:25:36 +00:00
|
|
|
#include <wayland-cursor.h>
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-01-10 16:40:59 +00:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2011-05-09 21:45:33 +00:00
|
|
|
#include <cogl/cogl.h>
|
2012-03-20 13:50:42 +00:00
|
|
|
#include <cogl/cogl-wayland-client.h>
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
#define clutter_backend_wayland_get_type _clutter_backend_wayland_get_type
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBackendWayland, clutter_backend_wayland, CLUTTER_TYPE_BACKEND);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-01-10 16:40:59 +00:00
|
|
|
static void clutter_backend_wayland_load_cursor (ClutterBackendWayland *backend_wayland);
|
|
|
|
|
2010-09-28 14:17:46 +00:00
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_backend_wayland_dispose (GObject *gobject)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (gobject);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
if (backend_wayland->device_manager)
|
|
|
|
{
|
|
|
|
g_object_unref (backend_wayland->device_manager);
|
|
|
|
backend_wayland->device_manager = NULL;
|
|
|
|
}
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-01-10 16:40:59 +00:00
|
|
|
if (backend_wayland->cursor_buffer)
|
|
|
|
{
|
|
|
|
wl_buffer_destroy (backend_wayland->cursor_buffer);
|
|
|
|
backend_wayland->cursor_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-08 12:25:36 +00:00
|
|
|
if (backend_wayland->cursor_theme)
|
|
|
|
{
|
|
|
|
wl_cursor_theme_destroy (backend_wayland->cursor_theme);
|
|
|
|
backend_wayland->cursor_theme = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
G_OBJECT_CLASS (clutter_backend_wayland_parent_class)->dispose (gobject);
|
|
|
|
}
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2010-09-29 21:10:44 +00:00
|
|
|
|
2012-01-20 18:22:50 +00:00
|
|
|
static void
|
|
|
|
output_handle_mode (void *data,
|
|
|
|
struct wl_output *wl_output,
|
|
|
|
uint32_t flags,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int refresh)
|
|
|
|
{
|
|
|
|
ClutterBackendWayland *backend_wayland = data;
|
|
|
|
|
|
|
|
if (flags & WL_OUTPUT_MODE_CURRENT)
|
|
|
|
{
|
|
|
|
backend_wayland->output_width = width;
|
|
|
|
backend_wayland->output_height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
output_handle_geometry (void *data,
|
|
|
|
struct wl_output *wl_output,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int physical_width,
|
|
|
|
int physical_height,
|
|
|
|
int subpixel,
|
|
|
|
const char *make,
|
2012-08-23 23:16:25 +00:00
|
|
|
const char *model,
|
|
|
|
int32_t transform)
|
2012-01-20 18:22:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wl_output_listener wayland_output_listener = {
|
|
|
|
output_handle_geometry,
|
|
|
|
output_handle_mode,
|
|
|
|
};
|
|
|
|
|
2010-09-28 14:17:46 +00:00
|
|
|
|
|
|
|
static void
|
2012-10-12 17:54:25 +00:00
|
|
|
registry_handle_global (void *data,
|
|
|
|
struct wl_registry *registry,
|
|
|
|
uint32_t id,
|
|
|
|
const char *interface,
|
|
|
|
uint32_t version)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterBackendWayland *backend_wayland = data;
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
if (strcmp (interface, "wl_compositor") == 0)
|
|
|
|
backend_wayland->wayland_compositor =
|
2012-10-12 17:54:25 +00:00
|
|
|
wl_registry_bind (registry, id, &wl_compositor_interface, 1);
|
2012-08-23 23:16:25 +00:00
|
|
|
else if (strcmp (interface, "wl_seat") == 0)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
ClutterDeviceManager *device_manager = backend_wayland->device_manager;
|
|
|
|
_clutter_device_manager_wayland_add_input_group (device_manager, id);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
2011-05-09 21:45:33 +00:00
|
|
|
else if (strcmp (interface, "wl_shell") == 0)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
backend_wayland->wayland_shell =
|
2012-10-12 17:54:25 +00:00
|
|
|
wl_registry_bind (registry, id, &wl_shell_interface, 1);
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
2011-05-09 21:45:33 +00:00
|
|
|
else if (strcmp (interface, "wl_shm") == 0)
|
2012-01-20 18:22:50 +00:00
|
|
|
{
|
|
|
|
backend_wayland->wayland_shm =
|
2012-10-12 17:54:25 +00:00
|
|
|
wl_registry_bind (registry, id, &wl_shm_interface, 1);
|
2012-01-20 18:22:50 +00:00
|
|
|
}
|
|
|
|
else if (strcmp (interface, "wl_output") == 0)
|
|
|
|
{
|
|
|
|
/* FIXME: Support multiple outputs */
|
|
|
|
backend_wayland->wayland_output =
|
2012-10-12 17:54:25 +00:00
|
|
|
wl_registry_bind (registry, id, &wl_output_interface, 1);
|
2012-01-20 18:22:50 +00:00
|
|
|
wl_output_add_listener (backend_wayland->wayland_output,
|
|
|
|
&wayland_output_listener,
|
|
|
|
backend_wayland);
|
|
|
|
}
|
2011-02-08 15:45:39 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 17:54:25 +00:00
|
|
|
static const struct wl_registry_listener wayland_registry_listener = {
|
|
|
|
registry_handle_global,
|
|
|
|
};
|
|
|
|
|
2011-01-31 05:05:28 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_backend_wayland_post_parse (ClutterBackend *backend,
|
2011-05-09 21:45:33 +00:00
|
|
|
GError **error)
|
2011-01-31 05:05:28 +00:00
|
|
|
{
|
|
|
|
ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);
|
|
|
|
|
|
|
|
/* TODO: expose environment variable/commandline option for this... */
|
|
|
|
backend_wayland->wayland_display = wl_display_connect (NULL);
|
|
|
|
if (!backend_wayland->wayland_display)
|
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
2011-05-09 21:45:33 +00:00
|
|
|
CLUTTER_INIT_ERROR_BACKEND,
|
|
|
|
"Failed to open Wayland display socket");
|
2011-01-31 05:05:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-12 17:54:25 +00:00
|
|
|
backend_wayland->wayland_registry =
|
|
|
|
wl_display_get_registry (backend_wayland->wayland_display);
|
|
|
|
|
2011-01-31 05:05:28 +00:00
|
|
|
backend_wayland->wayland_source =
|
|
|
|
_clutter_event_source_wayland_new (backend_wayland->wayland_display);
|
|
|
|
g_source_attach (backend_wayland->wayland_source, NULL);
|
|
|
|
|
2012-09-18 00:49:00 +00:00
|
|
|
g_object_set (clutter_settings_get_default (), "font-dpi", 96 * 1024, NULL);
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
/* XXX: We require the device manager to exist as soon as we connect to the
|
|
|
|
* compositor and setup an event handler because we will immediately be
|
|
|
|
* notified of the available input devices which need to be associated with
|
|
|
|
* the device-manager.
|
|
|
|
*
|
|
|
|
* FIXME: At some point we could perhaps just collapse the
|
|
|
|
* _clutter_backend_post_parse(), and _clutter_backend_init_events()
|
|
|
|
* functions into one called something like _clutter_backend_init() which
|
|
|
|
* would allow the real backend to manage the precise order of
|
|
|
|
* initialization.
|
|
|
|
*/
|
|
|
|
backend_wayland->device_manager =
|
|
|
|
_clutter_device_manager_wayland_new (backend);
|
|
|
|
|
2011-01-31 05:05:28 +00:00
|
|
|
/* Set up listener so we'll catch all events. */
|
2012-10-12 17:54:25 +00:00
|
|
|
wl_registry_add_listener (backend_wayland->wayland_registry,
|
|
|
|
&wayland_registry_listener,
|
|
|
|
backend_wayland);
|
2011-01-31 05:05:28 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
/* Wait until we have been notified about the compositor and shell objects */
|
|
|
|
while (!(backend_wayland->wayland_compositor &&
|
|
|
|
backend_wayland->wayland_shell))
|
|
|
|
wl_display_roundtrip (backend_wayland->wayland_display);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-01-10 16:40:59 +00:00
|
|
|
/* We need the shm object before we can create the cursor */
|
|
|
|
clutter_backend_wayland_load_cursor (backend_wayland);
|
|
|
|
|
2010-09-28 14:17:46 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
static CoglRenderer *
|
|
|
|
clutter_backend_wayland_get_renderer (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend);
|
2011-05-09 21:45:33 +00:00
|
|
|
CoglRenderer *renderer;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Creating a new wayland renderer");
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
renderer = cogl_renderer_new ();
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2012-02-29 16:35:48 +00:00
|
|
|
cogl_renderer_set_winsys_id (renderer, COGL_WINSYS_ID_EGL_WAYLAND);
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
cogl_wayland_renderer_set_foreign_display (renderer,
|
|
|
|
backend_wayland->wayland_display);
|
|
|
|
cogl_wayland_renderer_set_foreign_compositor (renderer,
|
|
|
|
backend_wayland->wayland_compositor);
|
|
|
|
cogl_wayland_renderer_set_foreign_shell (renderer,
|
|
|
|
backend_wayland->wayland_shell);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
return renderer;
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
static CoglDisplay *
|
|
|
|
clutter_backend_wayland_get_display (ClutterBackend *backend,
|
|
|
|
CoglRenderer *renderer,
|
|
|
|
CoglSwapChain *swap_chain,
|
|
|
|
GError **error)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
2011-05-09 21:45:33 +00:00
|
|
|
CoglOnscreenTemplate *onscreen_template = NULL;
|
|
|
|
CoglDisplay *display;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
onscreen_template = cogl_onscreen_template_new (swap_chain);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
/* XXX: I have some doubts that this is a good design.
|
|
|
|
* Conceptually should we be able to check an onscreen_template
|
|
|
|
* without more details about the CoglDisplay configuration?
|
|
|
|
*/
|
|
|
|
if (!cogl_renderer_check_onscreen_template (renderer,
|
|
|
|
onscreen_template,
|
|
|
|
error))
|
|
|
|
goto error;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
display = cogl_display_new (renderer, onscreen_template);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
return display;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
error:
|
|
|
|
if (onscreen_template)
|
|
|
|
cogl_object_unref (onscreen_template);
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
return NULL;
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_backend_wayland_class_init (ClutterBackendWaylandClass *klass)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
gobject_class->dispose = clutter_backend_wayland_dispose;
|
2010-09-28 14:17:46 +00:00
|
|
|
|
2011-11-04 18:27:08 +00:00
|
|
|
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_WAYLAND;
|
|
|
|
|
2011-05-09 21:45:33 +00:00
|
|
|
backend_class->post_parse = clutter_backend_wayland_post_parse;
|
|
|
|
backend_class->get_renderer = clutter_backend_wayland_get_renderer;
|
|
|
|
backend_class->get_display = clutter_backend_wayland_get_display;
|
2010-09-28 14:17:46 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 16:40:59 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_wayland_load_cursor (ClutterBackendWayland *backend_wayland)
|
|
|
|
{
|
2012-10-08 12:25:36 +00:00
|
|
|
struct wl_cursor *cursor;
|
2012-01-10 16:40:59 +00:00
|
|
|
|
2012-10-08 12:25:36 +00:00
|
|
|
backend_wayland->cursor_theme =
|
|
|
|
wl_cursor_theme_load (NULL, /* default */
|
|
|
|
32,
|
|
|
|
backend_wayland->wayland_shm);
|
2012-01-10 16:40:59 +00:00
|
|
|
|
2012-10-08 12:25:36 +00:00
|
|
|
cursor = wl_cursor_theme_get_cursor (backend_wayland->cursor_theme,
|
|
|
|
"left_ptr");
|
2012-01-10 16:40:59 +00:00
|
|
|
|
2012-10-08 12:25:36 +00:00
|
|
|
backend_wayland->cursor_buffer =
|
|
|
|
wl_cursor_image_get_buffer (cursor->images[0]);
|
2012-01-10 16:40:59 +00:00
|
|
|
|
|
|
|
if (backend_wayland->cursor_buffer)
|
|
|
|
{
|
2012-10-08 12:25:36 +00:00
|
|
|
backend_wayland->cursor_x = cursor->images[0]->hotspot_x;
|
|
|
|
backend_wayland->cursor_y = cursor->images[0]->hotspot_y;
|
2012-01-10 16:40:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:16:25 +00:00
|
|
|
backend_wayland->cursor_surface =
|
|
|
|
wl_compositor_create_surface (backend_wayland->wayland_compositor);
|
2012-01-10 16:40:59 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 14:17:46 +00:00
|
|
|
static void
|
2011-05-09 21:45:33 +00:00
|
|
|
clutter_backend_wayland_init (ClutterBackendWayland *backend_wayland)
|
2010-09-28 14:17:46 +00:00
|
|
|
{
|
|
|
|
}
|