2007-10-12 08:17:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-03-22 18:21:59 +00:00
|
|
|
#include "config.h"
|
2007-10-12 08:17:00 +00:00
|
|
|
#endif
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
#include "clutter-backend-egl.h"
|
|
|
|
#include "clutter-stage-egl.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-main.h"
|
2007-03-27 21:09:11 +00:00
|
|
|
#include "../clutter-debug.h"
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-05-31 12:35:36 +00:00
|
|
|
static ClutterBackendEGL *backend_singleton = NULL;
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
G_DEFINE_TYPE (ClutterBackendEGL, clutter_backend_egl, CLUTTER_TYPE_BACKEND_X11);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_backend_egl_post_parse (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
2007-05-31 12:35:36 +00:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-27 21:09:11 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
if (clutter_backend_x11_post_parse (backend, error))
|
2007-03-27 21:09:11 +00:00
|
|
|
{
|
2007-04-28 00:37:11 +00:00
|
|
|
EGLBoolean status;
|
2007-03-27 21:09:11 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
backend_egl->edpy = eglGetDisplay((NativeDisplayType)backend_x11->xdpy);
|
2007-08-02 09:58:18 +00:00
|
|
|
|
2007-10-12 08:17:00 +00:00
|
|
|
status = eglInitialize(backend_egl->edpy,
|
|
|
|
&backend_egl->egl_version_major,
|
2007-04-28 00:37:11 +00:00
|
|
|
&backend_egl->egl_version_minor);
|
|
|
|
|
|
|
|
if (status != EGL_TRUE)
|
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
|
|
|
CLUTTER_INIT_ERROR_BACKEND,
|
|
|
|
"Unable to Initialize EGL");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-27 21:09:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-28 00:37:11 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "EGL Reports version %i.%i",
|
2007-10-12 08:17:00 +00:00
|
|
|
backend_egl->egl_version_major,
|
2007-04-28 00:37:11 +00:00
|
|
|
backend_egl->egl_version_minor);
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:49:34 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_egl_redraw (ClutterBackend *backend)
|
|
|
|
{
|
2007-05-31 12:35:36 +00:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-05-31 12:35:36 +00:00
|
|
|
ClutterStageEGL *stage_egl;
|
2007-11-15 14:45:27 +00:00
|
|
|
ClutterStageX11 *stage_x11;
|
2007-05-28 18:49:34 +00:00
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
stage_x11 = CLUTTER_STAGE_X11(backend_x11->stage);
|
|
|
|
stage_egl = CLUTTER_STAGE_EGL(backend_x11->stage);
|
2007-05-28 18:49:34 +00:00
|
|
|
|
|
|
|
clutter_actor_paint (CLUTTER_ACTOR(stage_egl));
|
|
|
|
|
|
|
|
/* Why this paint is done in backend as likely GL windowing system
|
|
|
|
* specific calls, like swapping buffers.
|
|
|
|
*/
|
2007-11-15 14:45:27 +00:00
|
|
|
if (stage_x11->xwin)
|
2007-05-28 18:49:34 +00:00
|
|
|
{
|
|
|
|
/* clutter_feature_wait_for_vblank (); */
|
2007-06-29 11:54:31 +00:00
|
|
|
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
|
2007-05-28 18:49:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eglWaitGL ();
|
|
|
|
CLUTTER_GLERR ();
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 21:09:11 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_egl_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
if (backend_singleton)
|
|
|
|
backend_singleton = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_backend_egl_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_backend_egl_dispose (GObject *gobject)
|
|
|
|
{
|
2007-11-18 23:24:55 +00:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (gobject);
|
|
|
|
|
|
|
|
if (backend_egl->edpy)
|
|
|
|
{
|
|
|
|
eglTerminate (backend_egl->edpy);
|
|
|
|
backend_egl->edpy = NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-27 21:09:11 +00:00
|
|
|
G_OBJECT_CLASS (clutter_backend_egl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
clutter_backend_egl_constructor (GType gtype,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GObjectClass *parent_class;
|
|
|
|
GObject *retval;
|
|
|
|
|
|
|
|
if (!backend_singleton)
|
|
|
|
{
|
|
|
|
parent_class = G_OBJECT_CLASS (clutter_backend_egl_parent_class);
|
|
|
|
retval = parent_class->constructor (gtype, n_params, params);
|
|
|
|
|
|
|
|
backend_singleton = CLUTTER_BACKEND_EGL (retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_warning ("Attempting to create a new backend object. This should "
|
|
|
|
"never happen, so we return the singleton instance.");
|
2007-10-12 08:17:00 +00:00
|
|
|
|
2007-03-27 21:09:11 +00:00
|
|
|
return g_object_ref (backend_singleton);
|
|
|
|
}
|
|
|
|
|
2007-07-26 20:08:09 +00:00
|
|
|
static ClutterFeatureFlags
|
|
|
|
clutter_backend_egl_get_features (ClutterBackend *backend)
|
|
|
|
{
|
|
|
|
/* We can actually resize too */
|
|
|
|
return CLUTTER_FEATURE_STAGE_CURSOR;
|
|
|
|
}
|
|
|
|
|
2007-11-15 14:45:27 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_backend_egl_init_stage (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
|
|
|
|
|
|
|
if (!backend_x11->stage)
|
|
|
|
{
|
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
ClutterActor *stage;
|
|
|
|
|
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL);
|
|
|
|
|
|
|
|
/* copy backend data into the stage */
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (stage);
|
|
|
|
stage_x11->xdpy = backend_x11->xdpy;
|
|
|
|
stage_x11->xwin_root = backend_x11->xwin_root;
|
|
|
|
stage_x11->xscreen = backend_x11->xscreen_num;
|
|
|
|
stage_x11->backend = backend_x11;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (MISC, "X11 stage created (display:%p, screen:%d, root:%u)",
|
|
|
|
stage_x11->xdpy,
|
|
|
|
stage_x11->xscreen,
|
|
|
|
(unsigned int) stage_x11->xwin_root);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (stage), "clutter-backend", backend);
|
|
|
|
|
|
|
|
backend_x11->stage = g_object_ref_sink (stage);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_realize (backend_x11->stage);
|
|
|
|
|
|
|
|
if (!CLUTTER_ACTOR_IS_REALIZED (backend_x11->stage))
|
|
|
|
{
|
|
|
|
g_set_error (error, CLUTTER_INIT_ERROR,
|
|
|
|
CLUTTER_INIT_ERROR_INTERNAL,
|
|
|
|
"Unable to realize the main stage");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:21:59 +00:00
|
|
|
static void
|
2007-05-31 12:35:36 +00:00
|
|
|
clutter_backend_egl_class_init (ClutterBackendEGLClass *klass)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-03-27 21:09:11 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2007-03-22 18:21:59 +00:00
|
|
|
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
|
|
|
|
|
2007-03-27 21:09:11 +00:00
|
|
|
gobject_class->constructor = clutter_backend_egl_constructor;
|
|
|
|
gobject_class->dispose = clutter_backend_egl_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_egl_finalize;
|
|
|
|
|
2007-05-28 18:49:34 +00:00
|
|
|
backend_class->post_parse = clutter_backend_egl_post_parse;
|
|
|
|
backend_class->redraw = clutter_backend_egl_redraw;
|
2007-07-26 20:08:09 +00:00
|
|
|
backend_class->get_features = clutter_backend_egl_get_features;
|
2007-11-15 14:45:27 +00:00
|
|
|
backend_class->init_stage = clutter_backend_egl_init_stage;
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-05-31 12:35:36 +00:00
|
|
|
clutter_backend_egl_init (ClutterBackendEGL *backend_egl)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-11-15 14:45:27 +00:00
|
|
|
;
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
|
|
|
_clutter_backend_impl_get_type (void)
|
|
|
|
{
|
|
|
|
return clutter_backend_egl_get_type ();
|
|
|
|
}
|
2007-03-27 21:09:11 +00:00
|
|
|
|
2007-06-29 11:54:31 +00:00
|
|
|
/**
|
|
|
|
* clutter_egl_display
|
2007-10-12 08:17:00 +00:00
|
|
|
*
|
2007-06-29 11:54:31 +00:00
|
|
|
* Gets the current EGLDisplay.
|
|
|
|
*
|
|
|
|
* Return value: an EGLDisplay
|
|
|
|
*
|
|
|
|
* Since: 0.4
|
|
|
|
*/
|
2007-03-27 21:09:11 +00:00
|
|
|
EGLDisplay
|
2007-07-06 13:56:01 +00:00
|
|
|
clutter_eglx_display (void)
|
2007-03-27 21:09:11 +00:00
|
|
|
{
|
2007-06-29 11:54:31 +00:00
|
|
|
return backend_singleton->edpy;
|
2007-03-27 21:09:11 +00:00
|
|
|
}
|