2010-06-17 21:26:12 +00:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
2011-05-08 23:27:10 +00:00
|
|
|
* Copyright (C) 2010,2011 Intel Corporation.
|
2010-06-17 21:26:12 +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
|
|
|
|
* Emmanuele Bassi
|
|
|
|
* Robert Bragg
|
|
|
|
* Neil Roberts
|
|
|
|
*/
|
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-07-06 13:56:01 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2010-03-01 11:38:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2010-06-17 21:26:12 +00:00
|
|
|
#include <unistd.h>
|
2010-03-01 11:38:41 +00:00
|
|
|
|
2010-03-03 15:31:01 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
#include "clutter-backend-cogl.h"
|
|
|
|
#include "clutter-stage-cogl.h"
|
2010-03-01 11:38:41 +00:00
|
|
|
|
2010-11-04 14:38:32 +00:00
|
|
|
#ifdef HAVE_EVDEV
|
|
|
|
#include "clutter-device-manager-evdev.h"
|
|
|
|
#endif
|
|
|
|
|
2010-10-21 10:29:09 +00:00
|
|
|
#include "clutter-debug.h"
|
|
|
|
#include "clutter-private.h"
|
|
|
|
#include "clutter-main.h"
|
|
|
|
#include "clutter-stage-private.h"
|
2011-05-08 23:27:10 +00:00
|
|
|
|
|
|
|
#ifdef COGL_HAS_EGL_SUPPORT
|
|
|
|
#include "clutter-egl.h"
|
|
|
|
#endif
|
2011-03-04 12:50:39 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
#include "clutter-cex100.h"
|
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
static ClutterBackendCogl *backend_singleton = NULL;
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
static gchar *clutter_vblank = NULL;
|
2010-03-01 11:38:41 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
/* FIXME: We should have CLUTTER_ define for this... */
|
2011-03-04 12:50:39 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
static gdl_plane_id_t gdl_plane = GDL_PLANE_ID_UPP_C;
|
|
|
|
static guint gdl_n_buffers = CLUTTER_CEX100_TRIPLE_BUFFERING;
|
|
|
|
#endif
|
2010-11-16 13:54:15 +00:00
|
|
|
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef COGL_HAS_X11_SUPPORT
|
2011-05-08 23:27:10 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBackendCogl, _clutter_backend_cogl, CLUTTER_TYPE_BACKEND_X11);
|
2010-06-17 21:26:12 +00:00
|
|
|
#else
|
2011-05-08 23:27:10 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBackendCogl, _clutter_backend_cogl, CLUTTER_TYPE_BACKEND);
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2008-09-22 16:36:27 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_at_exit (void)
|
|
|
|
{
|
|
|
|
if (backend_singleton)
|
|
|
|
g_object_run_dispose (G_OBJECT (backend_singleton));
|
|
|
|
}
|
|
|
|
|
Eliminate G_CONST_RETURN
The G_CONST_RETURN define in GLib is, and has always been, a bit fuzzy.
We always used it to conform to the platform, at least for public-facing
API.
At first I assumed it has something to do with brain-damaged compilers
or with weird platforms where const was not really supported; sadly,
it's something much, much worse: it's a define that can be toggled at
compile-time to remove const from the signature of public API. This is a
truly terrifying feature that I assume was added in the past century,
and whose inception clearly had something to do with massive doses of
absynthe and opium — because any other explanation would make the
existence of such a feature even worse than assuming drugs had anything
to do with it.
Anyway, and pleasing the gods, this dubious feature is being
removed/deprecated in GLib; see bug:
https://bugzilla.gnome.org/show_bug.cgi?id=644611
Before deprecation, though, we should just remove its usage from the
whole API. We should especially remove its usage from Cally's internals,
since there it never made sense in the first place.
2011-06-07 14:49:20 +00:00
|
|
|
const gchar*
|
2011-05-08 23:27:10 +00:00
|
|
|
_clutter_backend_cogl_get_vblank (void)
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
|
|
|
if (clutter_vblank && strcmp (clutter_vblank, "0") == 0)
|
|
|
|
return "none";
|
|
|
|
else
|
|
|
|
return clutter_vblank;
|
|
|
|
}
|
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
static gboolean
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_pre_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
2010-03-01 11:38:41 +00:00
|
|
|
const gchar *env_string;
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef COGL_HAS_X11_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
ClutterBackendClass *parent_class =
|
2011-05-08 23:27:10 +00:00
|
|
|
CLUTTER_BACKEND_CLASS (_clutter_backend_cogl_parent_class);
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (!parent_class->pre_parse (backend, error))
|
2010-06-17 21:26:12 +00:00
|
|
|
return FALSE;
|
|
|
|
#endif
|
2010-03-01 11:38:41 +00:00
|
|
|
|
2010-11-16 13:54:15 +00:00
|
|
|
env_string = g_getenv ("CLUTTER_VBLANK");
|
|
|
|
if (env_string)
|
|
|
|
{
|
2011-02-25 00:31:41 +00:00
|
|
|
clutter_vblank = g_strdup (env_string);
|
2010-11-16 13:54:15 +00:00
|
|
|
env_string = NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_post_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef COGL_HAS_X11_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
ClutterBackendClass *parent_class =
|
2011-05-08 23:27:10 +00:00
|
|
|
CLUTTER_BACKEND_CLASS (_clutter_backend_cogl_parent_class);
|
2007-07-09 21:59:01 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (!parent_class->post_parse (backend, error))
|
2010-06-17 21:26:12 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
return TRUE;
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2010-02-27 09:42:42 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
g_atexit (clutter_backend_at_exit);
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2010-02-27 09:42:42 +00:00
|
|
|
return TRUE;
|
2010-06-17 21:26:12 +00:00
|
|
|
}
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2010-11-30 16:22:49 +00:00
|
|
|
#ifndef COGL_HAS_XLIB_SUPPORT
|
2010-11-04 14:38:32 +00:00
|
|
|
static ClutterDeviceManager *
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_get_device_manager (ClutterBackend *backend)
|
2010-11-04 14:38:32 +00:00
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterBackendCogl *backend_cogl = CLUTTER_BACKEND_COGL (backend);
|
2010-11-04 14:38:32 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
if (G_UNLIKELY (backend_cogl->device_manager == NULL))
|
2010-11-04 14:38:32 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_EVDEV
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_cogl->device_manager =
|
2010-11-04 14:38:32 +00:00
|
|
|
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_EVDEV,
|
2011-05-08 23:27:10 +00:00
|
|
|
"backend", backend_cogl,
|
2010-11-04 14:38:32 +00:00
|
|
|
NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
return backend_cogl->device_manager;
|
2010-11-04 14:38:32 +00:00
|
|
|
}
|
2010-11-30 16:22:49 +00:00
|
|
|
#endif
|
2010-11-04 14:38:32 +00:00
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_init_events (ClutterBackend *backend)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
2010-11-04 14:38:32 +00:00
|
|
|
#ifdef HAVE_TSLIB
|
2010-06-17 21:26:12 +00:00
|
|
|
/* XXX: This should be renamed to _clutter_events_tslib_init */
|
2011-05-08 23:27:10 +00:00
|
|
|
_clutter_events_tslib_init (CLUTTER_BACKEND_COGL (backend));
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2010-11-04 14:38:32 +00:00
|
|
|
#ifdef HAVE_EVDEV
|
|
|
|
_clutter_events_evdev_init (CLUTTER_BACKEND (backend));
|
|
|
|
#endif
|
2010-12-07 23:32:47 +00:00
|
|
|
#ifdef COGL_HAS_X11_SUPPORT
|
|
|
|
/* Chain up to the X11 backend */
|
2011-05-08 23:27:10 +00:00
|
|
|
CLUTTER_BACKEND_CLASS (_clutter_backend_cogl_parent_class)->
|
2010-12-07 23:32:47 +00:00
|
|
|
init_events (backend);
|
|
|
|
#endif
|
2010-11-04 14:38:32 +00:00
|
|
|
}
|
2007-07-06 13:56:01 +00:00
|
|
|
|
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_finalize (GObject *gobject)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
|
|
|
if (backend_singleton)
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
G_OBJECT_CLASS (_clutter_backend_cogl_parent_class)->finalize (gobject);
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_dispose (GObject *gobject)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
2011-02-25 00:31:41 +00:00
|
|
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
|
|
|
#ifdef HAVE_TSLIB
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterBackendCogl *backend_cogl = CLUTTER_BACKEND_COGL (gobject);
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
/* We chain up before disposing our CoglContext so that we will
|
|
|
|
* destroy all of the stages first. Otherwise the actors may try to
|
|
|
|
* make Cogl calls during destruction which would cause a crash */
|
2011-05-08 23:27:10 +00:00
|
|
|
G_OBJECT_CLASS (_clutter_backend_cogl_parent_class)->dispose (gobject);
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (backend->cogl_context)
|
2010-03-01 11:38:41 +00:00
|
|
|
{
|
2011-02-25 00:31:41 +00:00
|
|
|
cogl_object_unref (backend->cogl_context);
|
|
|
|
backend->cogl_context = NULL;
|
2007-10-09 13:56:29 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef HAVE_TSLIB
|
2011-02-25 00:31:41 +00:00
|
|
|
/* XXX: This should be renamed to _clutter_events_tslib_uninit */
|
2011-05-08 23:27:10 +00:00
|
|
|
_clutter_events_egl_uninit (backend_cogl);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
if (backend_cogl->event_timer != NULL)
|
2008-05-15 14:31:43 +00:00
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
g_timer_destroy (backend_cogl->event_timer);
|
|
|
|
backend_cogl->event_timer = NULL;
|
2008-05-15 14:31:43 +00:00
|
|
|
}
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_constructor (GType gtype,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *retval;
|
|
|
|
|
|
|
|
if (!backend_singleton)
|
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
parent_class = G_OBJECT_CLASS (_clutter_backend_cogl_parent_class);
|
2007-07-06 13:56:01 +00:00
|
|
|
retval = parent_class->constructor (gtype, n_params, params);
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_singleton = CLUTTER_BACKEND_COGL (retval);
|
2007-07-06 13:56:01 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Attempting to create a new backend object. This should "
|
|
|
|
"never happen, so we return the singleton instance.");
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
return g_object_ref (backend_singleton);
|
|
|
|
}
|
|
|
|
|
2007-07-26 20:08:09 +00:00
|
|
|
static ClutterFeatureFlags
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_get_features (ClutterBackend *backend)
|
2007-07-26 20:08:09 +00:00
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterBackendCogl *backend_cogl = CLUTTER_BACKEND_COGL (backend);
|
2011-02-25 00:31:41 +00:00
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
ClutterBackendClass *parent_class;
|
|
|
|
#endif
|
|
|
|
ClutterFeatureFlags flags = 0;
|
2010-02-27 09:42:42 +00:00
|
|
|
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
2011-05-08 23:27:10 +00:00
|
|
|
parent_class = CLUTTER_BACKEND_CLASS (_clutter_backend_cogl_parent_class);
|
2011-01-20 15:39:28 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
flags = parent_class->get_features (backend);
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports multiple onscreen framebuffers");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_MULTIPLE;
|
|
|
|
}
|
2010-11-16 13:54:15 +00:00
|
|
|
else
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl only supports one onscreen framebuffer");
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_STATIC;
|
|
|
|
}
|
2010-11-16 13:54:15 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_THROTTLE))
|
2010-11-16 13:54:15 +00:00
|
|
|
{
|
2011-02-25 00:31:41 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swap buffers throttling");
|
|
|
|
flags |= CLUTTER_FEATURE_SYNC_TO_VBLANK;
|
2010-11-16 13:54:15 +00:00
|
|
|
}
|
2011-02-25 00:31:41 +00:00
|
|
|
else
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl doesn't support swap buffers throttling");
|
2010-11-16 13:54:15 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swap buffers complete events");
|
|
|
|
flags |= CLUTTER_FEATURE_SWAP_EVENTS;
|
|
|
|
}
|
2010-11-16 13:54:15 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION))
|
2010-11-16 13:54:15 +00:00
|
|
|
{
|
2011-02-25 00:31:41 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Cogl supports swapping buffer regions");
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_cogl->can_blit_sub_buffer = TRUE;
|
2010-11-16 13:54:15 +00:00
|
|
|
}
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
static XVisualInfo *
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_get_visual_info (ClutterBackendX11 *backend_x11)
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
|
|
|
return cogl_clutter_winsys_xlib_get_visual_info ();
|
|
|
|
}
|
2010-11-16 13:54:15 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
static gboolean
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_create_context (ClutterBackend *backend,
|
|
|
|
GError **error)
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
|
|
|
#endif
|
|
|
|
CoglSwapChain *swap_chain = NULL;
|
|
|
|
CoglOnscreenTemplate *onscreen_template = NULL;
|
2008-04-23 17:20:59 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (backend->cogl_context)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
backend->cogl_renderer = cogl_renderer_new ();
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
cogl_renderer_xlib_set_foreign_display (backend->cogl_renderer,
|
|
|
|
backend_x11->xdpy);
|
|
|
|
#endif
|
|
|
|
if (!cogl_renderer_connect (backend->cogl_renderer, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
swap_chain = cogl_swap_chain_new ();
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
cogl_swap_chain_set_has_alpha (swap_chain,
|
|
|
|
clutter_x11_get_use_argb_visual ());
|
|
|
|
#endif
|
|
|
|
|
2011-03-04 12:50:39 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
cogl_swap_chain_set_length (swap_chain, gdl_n_buffers);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
onscreen_template = cogl_onscreen_template_new (swap_chain);
|
|
|
|
cogl_object_unref (swap_chain);
|
|
|
|
|
|
|
|
/* 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 (backend->cogl_renderer,
|
|
|
|
onscreen_template,
|
|
|
|
error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
backend->cogl_display = cogl_display_new (backend->cogl_renderer,
|
|
|
|
onscreen_template);
|
|
|
|
|
2011-03-04 12:50:39 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
|
|
|
cogl_gdl_display_set_plane (backend->cogl_display, gdl_plane);
|
2011-02-25 00:31:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
cogl_object_unref (backend->cogl_renderer);
|
|
|
|
cogl_object_unref (onscreen_template);
|
|
|
|
|
|
|
|
if (!cogl_display_setup (backend->cogl_display, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
backend->cogl_context = cogl_context_new (backend->cogl_display, error);
|
|
|
|
if (!backend->cogl_context)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* XXX: eventually this should go away but a lot of Cogl code still
|
|
|
|
* depends on a global default context. */
|
|
|
|
cogl_set_default_context (backend->cogl_context);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (backend->cogl_display)
|
|
|
|
{
|
|
|
|
cogl_object_unref (backend->cogl_display);
|
|
|
|
backend->cogl_display = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onscreen_template)
|
|
|
|
cogl_object_unref (onscreen_template);
|
|
|
|
if (swap_chain)
|
|
|
|
cogl_object_unref (swap_chain);
|
|
|
|
|
|
|
|
if (backend->cogl_renderer)
|
|
|
|
{
|
|
|
|
cogl_object_unref (backend->cogl_renderer);
|
|
|
|
backend->cogl_renderer = NULL;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2007-07-26 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 21:26:12 +00:00
|
|
|
static ClutterStageWindow *
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_create_stage (ClutterBackend *backend,
|
|
|
|
ClutterStage *wrapper,
|
|
|
|
GError **error)
|
2010-06-17 21:26:12 +00:00
|
|
|
{
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2011-01-19 15:17:34 +00:00
|
|
|
ClutterEventTranslator *translator;
|
2010-06-17 21:26:12 +00:00
|
|
|
ClutterStageWindow *stage;
|
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_COGL, NULL);
|
2010-06-17 21:26:12 +00:00
|
|
|
|
|
|
|
/* copy backend data into the stage */
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (stage);
|
|
|
|
stage_x11->wrapper = wrapper;
|
2011-01-26 11:58:08 +00:00
|
|
|
stage_x11->backend = backend_x11;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-01-19 15:17:34 +00:00
|
|
|
translator = CLUTTER_EVENT_TRANSLATOR (stage_x11);
|
2011-02-09 12:20:56 +00:00
|
|
|
_clutter_backend_add_event_translator (backend, translator);
|
2011-01-19 15:17:34 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
CLUTTER_NOTE (MISC, "Cogl stage created (display:%p, screen:%d, root:%u)",
|
2010-06-17 21:26:12 +00:00
|
|
|
backend_x11->xdpy,
|
|
|
|
backend_x11->xscreen_num,
|
|
|
|
(unsigned int) backend_x11->xwin_root);
|
|
|
|
|
|
|
|
#else /* COGL_HAS_XLIB_SUPPORT */
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterBackendCogl *backend_cogl = CLUTTER_BACKEND_COGL (backend);
|
2010-06-17 21:26:12 +00:00
|
|
|
ClutterStageWindow *stage;
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterStageCogl *stage_cogl;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
if (G_UNLIKELY (backend_cogl->stage != NULL))
|
2010-06-17 21:26:12 +00:00
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
|
|
|
CLUTTER_INIT_ERROR_BACKEND,
|
2011-02-25 00:31:41 +00:00
|
|
|
"The Cogl backend does not support multiple "
|
|
|
|
"onscreen windows");
|
2011-05-08 23:27:10 +00:00
|
|
|
return backend_cogl->stage;
|
2010-06-17 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_COGL, NULL);
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
stage_cogl = CLUTTER_STAGE_COGL (stage);
|
|
|
|
stage_cogl->backend = backend_cogl;
|
|
|
|
stage_cogl->wrapper = wrapper;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_cogl->stage = stage;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
|
|
|
#endif /* COGL_HAS_XLIB_SUPPORT */
|
|
|
|
|
|
|
|
return stage;
|
|
|
|
}
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
clutter_backend_cogl_ensure_context (ClutterBackend *backend,
|
|
|
|
ClutterStage *stage)
|
2010-06-17 21:26:12 +00:00
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
ClutterStageCogl *stage_cogl;
|
|
|
|
|
|
|
|
/* ignore ensuring the context on an empty stage */
|
|
|
|
if (stage == NULL)
|
|
|
|
return;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
stage_cogl =
|
|
|
|
CLUTTER_STAGE_COGL (_clutter_stage_get_window (stage));
|
|
|
|
|
|
|
|
cogl_set_framebuffer (COGL_FRAMEBUFFER (stage_cogl->onscreen));
|
2010-06-17 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
_clutter_backend_cogl_class_init (ClutterBackendCoglClass *klass)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef COGL_HAS_X11_SUPPORT
|
|
|
|
ClutterBackendX11Class *backendx11_class = CLUTTER_BACKEND_X11_CLASS (klass);
|
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
gobject_class->constructor = clutter_backend_cogl_constructor;
|
|
|
|
gobject_class->dispose = clutter_backend_cogl_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_cogl_finalize;
|
2007-07-06 13:56:01 +00:00
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_class->pre_parse = clutter_backend_cogl_pre_parse;
|
|
|
|
backend_class->post_parse = clutter_backend_cogl_post_parse;
|
|
|
|
backend_class->get_features = clutter_backend_cogl_get_features;
|
2010-11-30 16:22:49 +00:00
|
|
|
#ifndef COGL_HAS_XLIB_SUPPORT
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_class->get_device_manager = clutter_backend_cogl_get_device_manager;
|
2010-11-30 16:22:49 +00:00
|
|
|
#endif
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_class->init_events = clutter_backend_cogl_init_events;
|
|
|
|
backend_class->create_stage = clutter_backend_cogl_create_stage;
|
|
|
|
backend_class->create_context = clutter_backend_cogl_create_context;
|
|
|
|
backend_class->ensure_context = clutter_backend_cogl_ensure_context;
|
2010-06-17 21:26:12 +00:00
|
|
|
|
|
|
|
#ifdef COGL_HAS_XLIB_SUPPORT
|
2011-05-08 23:27:10 +00:00
|
|
|
backendx11_class->get_visual_info = clutter_backend_cogl_get_visual_info;
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-08 23:27:10 +00:00
|
|
|
_clutter_backend_cogl_init (ClutterBackendCogl *backend_cogl)
|
2007-07-06 13:56:01 +00:00
|
|
|
{
|
2010-06-17 21:26:12 +00:00
|
|
|
#ifdef HAVE_TSLIB
|
2011-05-08 23:27:10 +00:00
|
|
|
backend_cogl->event_timer = g_timer_new ();
|
2010-06-17 21:26:12 +00:00
|
|
|
#endif
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
_clutter_backend_impl_get_type (void)
|
|
|
|
{
|
2011-05-08 23:27:10 +00:00
|
|
|
return _clutter_backend_cogl_get_type ();
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 23:27:10 +00:00
|
|
|
#ifdef COGL_HAS_EGL_SUPPORT
|
2010-06-17 21:26:12 +00:00
|
|
|
EGLDisplay
|
|
|
|
clutter_eglx_display (void)
|
|
|
|
{
|
2010-12-09 15:11:37 +00:00
|
|
|
return clutter_egl_get_egl_display ();
|
2010-06-17 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 13:56:01 +00:00
|
|
|
EGLDisplay
|
|
|
|
clutter_egl_display (void)
|
|
|
|
{
|
2010-12-09 15:11:37 +00:00
|
|
|
return clutter_egl_get_egl_display ();
|
2007-07-06 13:56:01 +00:00
|
|
|
}
|
2010-06-17 21:26:12 +00:00
|
|
|
|
2010-12-09 15:11:37 +00:00
|
|
|
EGLDisplay
|
|
|
|
clutter_egl_get_egl_display (void)
|
|
|
|
{
|
|
|
|
if (backend_singleton == NULL)
|
|
|
|
{
|
2010-12-09 15:42:19 +00:00
|
|
|
g_critical ("%s has been called before clutter_init()", G_STRFUNC);
|
2010-12-09 15:11:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
return cogl_context_egl_get_egl_display (backend_singleton->cogl_context);
|
|
|
|
}
|
2011-05-08 23:27:10 +00:00
|
|
|
#endif
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
/* FIXME we should have a CLUTTER_ define for this */
|
2011-03-04 12:50:39 +00:00
|
|
|
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
|
2011-02-25 00:31:41 +00:00
|
|
|
void
|
|
|
|
clutter_cex100_set_plane (gdl_plane_id_t plane)
|
|
|
|
{
|
|
|
|
g_return_if_fail (plane >= GDL_PLANE_ID_UPP_A && plane <= GDL_PLANE_ID_UPP_E);
|
|
|
|
|
|
|
|
gdl_plane = plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clutter_cex100_set_buffering_mode (ClutterCex100BufferingMode mode)
|
|
|
|
{
|
|
|
|
g_return_if_fail (mode == CLUTTER_CEX100_DOUBLE_BUFFERING ||
|
|
|
|
mode == CLUTTER_CEX100_TRIPLE_BUFFERING);
|
|
|
|
|
|
|
|
gdl_n_buffers = mode;
|
2010-12-09 15:11:37 +00:00
|
|
|
}
|
2011-02-25 00:31:41 +00:00
|
|
|
#endif
|