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"
|
2008-04-14 15:10:22 +00:00
|
|
|
#include "../clutter-version.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
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
backend_egl->edpy =
|
2010-05-18 16:25:25 +00:00
|
|
|
eglGetDisplay ((NativeDisplayType) backend_x11->xdpy);
|
2007-08-02 09:58:18 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
status = eglInitialize (backend_egl->edpy,
|
|
|
|
&backend_egl->egl_version_major,
|
|
|
|
&backend_egl->egl_version_minor);
|
2007-04-28 00:37:11 +00:00
|
|
|
|
2008-09-22 16:36:27 +00:00
|
|
|
g_atexit (clutter_backend_at_exit);
|
|
|
|
|
2007-04-28 00:37:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
static gboolean
|
|
|
|
clutter_backend_egl_create_context (ClutterBackend *backend,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
ClutterBackendEGL *backend_egl;
|
|
|
|
ClutterBackendX11 *backend_x11;
|
|
|
|
EGLConfig config;
|
|
|
|
EGLint config_count = 0;
|
|
|
|
EGLBoolean status;
|
|
|
|
EGLint cfg_attribs[] = {
|
|
|
|
/* NB: This must be the first attribute, since we may
|
|
|
|
* try and fallback to no stencil buffer */
|
|
|
|
EGL_STENCIL_SIZE, 8,
|
|
|
|
|
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_BLUE_SIZE, 5,
|
|
|
|
|
|
|
|
EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
|
|
|
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
#else /* HAVE_COGL_GLES2 */
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
|
#endif /* HAVE_COGL_GLES2 */
|
|
|
|
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLDisplay edpy;
|
|
|
|
gint retry_cookie = 0;
|
2010-05-05 16:30:00 +00:00
|
|
|
XVisualInfo *xvisinfo;
|
|
|
|
XSetWindowAttributes attrs;
|
2010-03-26 02:37:26 +00:00
|
|
|
|
|
|
|
backend = clutter_get_default_backend ();
|
|
|
|
backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
|
|
|
|
if (backend_egl->egl_context != EGL_NO_CONTEXT)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
|
|
|
|
|
|
|
edpy = clutter_eglx_display ();
|
|
|
|
|
|
|
|
retry:
|
|
|
|
/* Here we can change the attributes depending on the fallback count... */
|
|
|
|
|
|
|
|
/* Some GLES hardware can't support a stencil buffer: */
|
|
|
|
if (retry_cookie == 1)
|
|
|
|
{
|
|
|
|
g_warning ("Trying with stencil buffer disabled...");
|
|
|
|
cfg_attribs[1 /* EGL_STENCIL_SIZE */] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: at this point we only have one fallback */
|
|
|
|
|
|
|
|
status = eglChooseConfig (edpy,
|
|
|
|
cfg_attribs,
|
|
|
|
&config, 1,
|
|
|
|
&config_count);
|
|
|
|
if (status != EGL_TRUE || config_count == 0)
|
|
|
|
{
|
|
|
|
g_warning ("eglChooseConfig failed");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (backend_egl->egl_context == EGL_NO_CONTEXT))
|
|
|
|
{
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
static const EGLint attribs[3]
|
|
|
|
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
|
|
|
|
|
|
|
backend_egl->egl_context = eglCreateContext (edpy,
|
|
|
|
config,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
attribs);
|
|
|
|
#else
|
|
|
|
/* Seems some GLES implementations 1.x do not like attribs... */
|
|
|
|
backend_egl->egl_context = eglCreateContext (edpy,
|
|
|
|
config,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
NULL);
|
|
|
|
#endif
|
|
|
|
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
g_warning ("Unable to create a suitable EGL context");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
backend_egl->egl_config = config;
|
|
|
|
CLUTTER_NOTE (GL, "Created EGL Context");
|
|
|
|
}
|
|
|
|
|
2010-05-05 16:30:00 +00:00
|
|
|
/* COGL assumes that there is always a GL context selected; in order
|
|
|
|
* to make sure that an EGL context exists and is made current, we use
|
|
|
|
* a dummy, offscreen override-redirect window to which we can always
|
|
|
|
* fall back if no stage is available */
|
|
|
|
|
|
|
|
xvisinfo = clutter_backend_x11_get_visual_info (backend_x11);
|
|
|
|
if (xvisinfo == NULL)
|
|
|
|
{
|
|
|
|
g_critical ("Unable to find suitable GL visual.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs.override_redirect = True;
|
|
|
|
attrs.colormap = XCreateColormap (backend_x11->xdpy,
|
|
|
|
backend_x11->xwin_root,
|
|
|
|
xvisinfo->visual,
|
|
|
|
AllocNone);
|
|
|
|
attrs.border_pixel = 0;
|
|
|
|
|
|
|
|
backend_egl->dummy_xwin = XCreateWindow (backend_x11->xdpy,
|
|
|
|
backend_x11->xwin_root,
|
|
|
|
-100, -100, 1, 1,
|
|
|
|
0,
|
|
|
|
xvisinfo->depth,
|
|
|
|
CopyFromParent,
|
|
|
|
xvisinfo->visual,
|
|
|
|
CWOverrideRedirect |
|
|
|
|
CWColormap |
|
|
|
|
CWBorderPixel,
|
|
|
|
&attrs);
|
|
|
|
|
|
|
|
XFree (xvisinfo);
|
|
|
|
|
|
|
|
backend_egl->dummy_surface =
|
|
|
|
eglCreateWindowSurface (edpy,
|
|
|
|
backend_egl->egl_config,
|
2010-05-18 16:25:25 +00:00
|
|
|
(NativeWindowType) backend_egl->dummy_xwin,
|
2010-05-05 16:30:00 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (backend_egl->dummy_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
g_critical ("Unable to create an EGL surface");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
eglMakeCurrent (edpy,
|
|
|
|
backend_egl->dummy_surface,
|
|
|
|
backend_egl->dummy_surface,
|
|
|
|
backend_egl->egl_context);
|
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
/* NB: We currently only support a single fallback option */
|
|
|
|
if (retry_cookie == 0)
|
|
|
|
{
|
|
|
|
retry_cookie = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:49:34 +00:00
|
|
|
static void
|
2008-04-04 15:02:11 +00:00
|
|
|
clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
|
|
|
ClutterStage *stage)
|
2007-05-28 18:49:34 +00:00
|
|
|
{
|
2010-03-26 02:37:26 +00:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
ClutterStageWindow *impl;
|
2007-05-28 18:49:34 +00:00
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
if (stage == NULL ||
|
|
|
|
(CLUTTER_PRIVATE_FLAGS (stage) & CLUTTER_ACTOR_IN_DESTRUCTION) ||
|
|
|
|
((impl = _clutter_stage_get_window (stage)) == NULL))
|
2008-04-04 15:02:11 +00:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (BACKEND, "Clearing EGL context");
|
|
|
|
eglMakeCurrent (backend_egl->edpy,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClutterStageEGL *stage_egl;
|
|
|
|
ClutterStageX11 *stage_x11;
|
|
|
|
|
|
|
|
g_assert (impl != NULL);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (MULTISTAGE, "Setting context for stage of type %s [%p]",
|
|
|
|
g_type_name (G_OBJECT_TYPE (impl)),
|
|
|
|
impl);
|
|
|
|
|
|
|
|
stage_egl = CLUTTER_STAGE_EGL (impl);
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
2008-04-10 19:58:47 +00:00
|
|
|
return;
|
2008-04-04 15:02:11 +00:00
|
|
|
|
2008-05-12 Emmanuele Bassi <ebassi@openedhand.com>
Rework the stage wrapper/implementation relation: remove
duplicated code and all the bookkeeping from the backends into
ClutterStage whenever possible, to reduce the amount of work a
backend must do (and possibly get wrong). Thanks to Tommi
Komulainen.
* clutter/clutter-main.c:
(clutter_init_with_args), (clutter_init): Realize the default
stage after creation. The default stage is special, because we
use it in the initialization sequence. This removes the burden
from the backends and reduces the things a backend can get
wrong.
* clutter/clutter-stage.c:
(clutter_stage_show): Make sure to realize the implementation if
it hasn't been realized yet.
(clutter_stage_realize): Set the REALIZED flag and call
clutter_stage_ensure_current() if the implementation was
successfully realized.
(clutter_stage_unrealized): Call clutter_stage_ensure_current()
on unrealize.
* clutter/glx/clutter-backend-glx.c:
(clutter_backend_glx_create_stage): Do not realize the stage anymore
when creating it, and let the normal realization sequence take
place.
(clutter_backend_glx_ensure_context): Trap for X11 errors.
* clutter/glx/clutter-stage-glx.c:
(clutter_stage_glx_realize): Chain up to the X11 implementation
so that we can set up the window state (title, cursor visibility)
when we actually have a X window. Also, do not call
clutter_stage_ensure_current(), and rely on the wrapper to do
it for us. This means we can drop setting the REALIZED flag on
the wrapper.
(clutter_stage_glx_unrealize): Do not call
clutter_stage_ensure_current() ourselves, and rely on the wrapper
to do it for us.
* clutter/x11/clutter-stage-x11.c:
(set_wm_title), (set_cursor_visible): Move the WM title and
cursor visibility code inside their own functions.
(clutter_stage_x11_realize): Set the window title and whether the
cursor is visible or not after realizing the stage.
(clutter_stage_x11_set_cursor_visible),
(clutter_stage_x11_set_title): Call set_wm_title() and
set_cursor_visible().
(clutter_stage_x11_finalize): Free the title string.
* clutter/x11/clutter-stage-x11.h: Save more of the stage state,
so that we can set it even when the stage hasn't been realized
yet.
* clutter/eglnative/clutter-backend-egl.c:
(clutter_backend_egl_create_stage):
* clutter/eglnative/clutter-stage-egl.c:
(clutter_stage_egl_unrealize),
(clutter_stage_egl_realize): Update the eglnative backend.
* clutter/eglx/clutter-backend-egl.c:
(clutter_backend_egl_ensure_context),
(clutter_backend_egl_create_stage):
* clutter/eglx/clutter-stage-egl.c:
(clutter_stage_egl_unrealize),
(clutter_stage_egl_realize): Update the eglx backend.
* clutter/sdl/clutter-backend-sdl.c:
(clutter_backend_sdl_create_stage):
* clutter/sdl/clutter-stage-sdl.c:
(clutter_stage_sdl_realize): Update the sdl backend.
* clutter/fruity/clutter-backend-fruity.c:
(clutter_backend_fruity_create_stage):
* clutter/sdl/clutter-stage-fruity.c:
(clutter_stage_fruity_realize): Update the fruity backend.
* tests/test-multistage.c (on_button_press): Bail out if
clutter_stage_new() returns NULL.
* HACKING.backends: Update backend writing documentation.
2008-05-12 15:26:37 +00:00
|
|
|
clutter_x11_trap_x_errors ();
|
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
/* we might get here inside the final dispose cycle, so we
|
|
|
|
* need to handle this gracefully
|
|
|
|
*/
|
|
|
|
if (stage_x11->xwin == None ||
|
|
|
|
stage_egl->egl_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (MULTISTAGE,
|
|
|
|
"Received a stale stage, clearing all context");
|
|
|
|
|
2010-05-05 16:30:00 +00:00
|
|
|
if (backend_egl->dummy_surface == EGL_NO_SURFACE)
|
|
|
|
eglMakeCurrent (backend_egl->edpy,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
else
|
|
|
|
eglMakeCurrent (backend_egl->edpy,
|
|
|
|
backend_egl->dummy_surface,
|
|
|
|
backend_egl->dummy_surface,
|
|
|
|
backend_egl->egl_context);
|
2008-04-04 15:02:11 +00:00
|
|
|
}
|
|
|
|
else
|
2010-03-26 02:37:26 +00:00
|
|
|
{
|
|
|
|
CLUTTER_NOTE (MULTISTAGE, "Setting real surface current");
|
|
|
|
eglMakeCurrent (backend_egl->edpy,
|
|
|
|
stage_egl->egl_surface,
|
|
|
|
stage_egl->egl_surface,
|
|
|
|
backend_egl->egl_context);
|
|
|
|
}
|
2008-05-12 Emmanuele Bassi <ebassi@openedhand.com>
Rework the stage wrapper/implementation relation: remove
duplicated code and all the bookkeeping from the backends into
ClutterStage whenever possible, to reduce the amount of work a
backend must do (and possibly get wrong). Thanks to Tommi
Komulainen.
* clutter/clutter-main.c:
(clutter_init_with_args), (clutter_init): Realize the default
stage after creation. The default stage is special, because we
use it in the initialization sequence. This removes the burden
from the backends and reduces the things a backend can get
wrong.
* clutter/clutter-stage.c:
(clutter_stage_show): Make sure to realize the implementation if
it hasn't been realized yet.
(clutter_stage_realize): Set the REALIZED flag and call
clutter_stage_ensure_current() if the implementation was
successfully realized.
(clutter_stage_unrealized): Call clutter_stage_ensure_current()
on unrealize.
* clutter/glx/clutter-backend-glx.c:
(clutter_backend_glx_create_stage): Do not realize the stage anymore
when creating it, and let the normal realization sequence take
place.
(clutter_backend_glx_ensure_context): Trap for X11 errors.
* clutter/glx/clutter-stage-glx.c:
(clutter_stage_glx_realize): Chain up to the X11 implementation
so that we can set up the window state (title, cursor visibility)
when we actually have a X window. Also, do not call
clutter_stage_ensure_current(), and rely on the wrapper to do
it for us. This means we can drop setting the REALIZED flag on
the wrapper.
(clutter_stage_glx_unrealize): Do not call
clutter_stage_ensure_current() ourselves, and rely on the wrapper
to do it for us.
* clutter/x11/clutter-stage-x11.c:
(set_wm_title), (set_cursor_visible): Move the WM title and
cursor visibility code inside their own functions.
(clutter_stage_x11_realize): Set the window title and whether the
cursor is visible or not after realizing the stage.
(clutter_stage_x11_set_cursor_visible),
(clutter_stage_x11_set_title): Call set_wm_title() and
set_cursor_visible().
(clutter_stage_x11_finalize): Free the title string.
* clutter/x11/clutter-stage-x11.h: Save more of the stage state,
so that we can set it even when the stage hasn't been realized
yet.
* clutter/eglnative/clutter-backend-egl.c:
(clutter_backend_egl_create_stage):
* clutter/eglnative/clutter-stage-egl.c:
(clutter_stage_egl_unrealize),
(clutter_stage_egl_realize): Update the eglnative backend.
* clutter/eglx/clutter-backend-egl.c:
(clutter_backend_egl_ensure_context),
(clutter_backend_egl_create_stage):
* clutter/eglx/clutter-stage-egl.c:
(clutter_stage_egl_unrealize),
(clutter_stage_egl_realize): Update the eglx backend.
* clutter/sdl/clutter-backend-sdl.c:
(clutter_backend_sdl_create_stage):
* clutter/sdl/clutter-stage-sdl.c:
(clutter_stage_sdl_realize): Update the sdl backend.
* clutter/fruity/clutter-backend-fruity.c:
(clutter_backend_fruity_create_stage):
* clutter/sdl/clutter-stage-fruity.c:
(clutter_stage_fruity_realize): Update the fruity backend.
* tests/test-multistage.c (on_button_press): Bail out if
clutter_stage_new() returns NULL.
* HACKING.backends: Update backend writing documentation.
2008-05-12 15:26:37 +00:00
|
|
|
|
|
|
|
if (clutter_x11_untrap_x_errors ())
|
|
|
|
g_critical ("Unable to make the stage window 0x%x the current "
|
|
|
|
"EGLX drawable",
|
|
|
|
(int) stage_x11->xwin);
|
2008-04-04 15:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-28 18:49:34 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
static void
|
|
|
|
clutter_backend_egl_redraw (ClutterBackend *backend,
|
|
|
|
ClutterStage *stage)
|
|
|
|
{
|
2008-04-14 15:10:22 +00:00
|
|
|
ClutterStageWindow *impl;
|
2008-04-04 15:02:11 +00:00
|
|
|
|
|
|
|
impl = _clutter_stage_get_window (stage);
|
|
|
|
if (!impl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_assert (CLUTTER_IS_STAGE_EGL (impl));
|
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
clutter_stage_egl_redraw (CLUTTER_STAGE_EGL (impl), stage);
|
2007-05-28 18:49:34 +00:00
|
|
|
}
|
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);
|
2010-05-05 16:30:00 +00:00
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (gobject);
|
|
|
|
|
2010-05-18 16:08:12 +00:00
|
|
|
/* We chain up before disposing our own resources so that
|
|
|
|
ClutterBackendX11 will destroy all of the stages before we
|
|
|
|
destroy the egl context. Otherwise the actors may try to make GL
|
|
|
|
calls during destruction which causes a crash */
|
|
|
|
G_OBJECT_CLASS (clutter_backend_egl_parent_class)->dispose (gobject);
|
|
|
|
|
2010-05-05 16:30:00 +00:00
|
|
|
if (backend_egl->dummy_surface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
eglDestroySurface (backend_egl->edpy, backend_egl->dummy_surface);
|
|
|
|
backend_egl->dummy_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backend_egl->dummy_xwin)
|
|
|
|
{
|
|
|
|
XDestroyWindow (backend_x11->xdpy, backend_egl->dummy_xwin);
|
|
|
|
backend_egl->dummy_xwin = None;
|
|
|
|
}
|
2007-11-18 23:24:55 +00:00
|
|
|
|
2008-04-04 15:02:11 +00:00
|
|
|
if (backend_egl->egl_context)
|
|
|
|
{
|
|
|
|
eglDestroyContext (backend_egl->edpy, backend_egl->egl_context);
|
|
|
|
backend_egl->egl_context = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-18 23:24:55 +00:00
|
|
|
if (backend_egl->edpy)
|
|
|
|
{
|
|
|
|
eglTerminate (backend_egl->edpy);
|
2008-04-14 15:10:22 +00:00
|
|
|
backend_egl->edpy = 0;
|
2007-11-18 23:24:55 +00:00
|
|
|
}
|
2007-03-27 21:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-04-04 13:20:02 +00:00
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
2010-03-26 02:37:26 +00:00
|
|
|
ClutterFeatureFlags flags;
|
|
|
|
|
|
|
|
flags = clutter_backend_x11_get_features (backend);
|
|
|
|
flags |= CLUTTER_FEATURE_STAGE_MULTIPLE;
|
2008-04-04 13:20:02 +00:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Checking features\n"
|
|
|
|
"GL_VENDOR: %s\n"
|
|
|
|
"GL_RENDERER: %s\n"
|
|
|
|
"GL_VERSION: %s\n"
|
2008-04-14 15:10:22 +00:00
|
|
|
"EGL_VENDOR: %s\n"
|
|
|
|
"EGL_VERSION: %s\n"
|
2008-04-04 13:20:02 +00:00
|
|
|
"EGL_EXTENSIONS: %s\n",
|
2008-04-04 15:02:11 +00:00
|
|
|
glGetString (GL_VENDOR),
|
|
|
|
glGetString (GL_RENDERER),
|
|
|
|
glGetString (GL_VERSION),
|
|
|
|
eglQueryString (backend_egl->edpy, EGL_VENDOR),
|
|
|
|
eglQueryString (backend_egl->edpy, EGL_VERSION),
|
|
|
|
eglQueryString (backend_egl->edpy, EGL_EXTENSIONS));
|
2008-04-04 13:20:02 +00:00
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
return flags;
|
2007-07-26 20:08:09 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 14:53:06 +00:00
|
|
|
static ClutterStageWindow *
|
2008-04-04 15:02:11 +00:00
|
|
|
clutter_backend_egl_create_stage (ClutterBackend *backend,
|
|
|
|
ClutterStage *wrapper,
|
|
|
|
GError **error)
|
2007-11-15 14:45:27 +00:00
|
|
|
{
|
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2008-04-10 19:58:47 +00:00
|
|
|
ClutterStageX11 *stage_x11;
|
2009-10-05 14:53:06 +00:00
|
|
|
ClutterStageWindow *stage;
|
2007-11-15 14:45:27 +00:00
|
|
|
|
2009-03-17 14:12:01 +00:00
|
|
|
CLUTTER_NOTE (BACKEND, "Creating stage of type '%s'",
|
2008-04-04 15:02:11 +00:00
|
|
|
g_type_name (CLUTTER_STAGE_TYPE));
|
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL);
|
2008-04-04 15:02:11 +00:00
|
|
|
|
|
|
|
/* copy backend data into the stage */
|
|
|
|
stage_x11 = CLUTTER_STAGE_X11 (stage);
|
|
|
|
stage_x11->wrapper = wrapper;
|
|
|
|
|
|
|
|
CLUTTER_NOTE (MISC, "EGLX stage created (display:%p, screen:%d, root:%u)",
|
2009-08-03 13:50:10 +00:00
|
|
|
backend_x11->xdpy,
|
|
|
|
backend_x11->xscreen_num,
|
|
|
|
(unsigned int) backend_x11->xwin_root);
|
2008-04-04 15:02:11 +00:00
|
|
|
|
|
|
|
return stage;
|
2007-11-15 14:45:27 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 13:18:37 +00:00
|
|
|
static XVisualInfo *
|
2009-07-31 17:34:51 +00:00
|
|
|
clutter_backend_egl_get_visual_info (ClutterBackendX11 *backend_x11)
|
2009-08-11 13:18:37 +00:00
|
|
|
{
|
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend_x11);
|
2009-08-20 10:53:37 +00:00
|
|
|
XVisualInfo visinfo_template;
|
2010-03-26 02:44:37 +00:00
|
|
|
int template_mask = 0;
|
|
|
|
XVisualInfo *visinfo = NULL;
|
2009-08-20 10:53:37 +00:00
|
|
|
int visinfos_count;
|
2010-03-26 02:44:37 +00:00
|
|
|
EGLint visualid, red_size, green_size, blue_size, alpha_size;
|
2009-08-20 10:53:37 +00:00
|
|
|
|
2010-03-26 02:37:26 +00:00
|
|
|
if (!clutter_backend_egl_create_context (CLUTTER_BACKEND (backend_x11), NULL))
|
|
|
|
return NULL;
|
|
|
|
|
2010-03-26 02:44:37 +00:00
|
|
|
visinfo_template.screen = backend_x11->xscreen_num;
|
|
|
|
template_mask |= VisualScreenMask;
|
|
|
|
|
2009-08-20 10:53:37 +00:00
|
|
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
|
|
|
EGL_NATIVE_VISUAL_ID, &visualid);
|
|
|
|
|
2010-03-26 02:44:37 +00:00
|
|
|
if (visualid != 0)
|
|
|
|
{
|
|
|
|
visinfo_template.visualid = visualid;
|
|
|
|
template_mask |= VisualIDMask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
|
|
|
|
* attribute, so attempt to find the closest match. */
|
|
|
|
|
|
|
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
|
|
|
EGL_RED_SIZE, &red_size);
|
|
|
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
|
|
|
EGL_GREEN_SIZE, &green_size);
|
|
|
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
|
|
|
EGL_BLUE_SIZE, &blue_size);
|
|
|
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
|
|
|
EGL_ALPHA_SIZE, &alpha_size);
|
|
|
|
|
|
|
|
visinfo_template.depth = red_size + green_size + blue_size + alpha_size;
|
|
|
|
template_mask |= VisualDepthMask;
|
|
|
|
}
|
|
|
|
|
2009-08-20 10:53:37 +00:00
|
|
|
visinfo = XGetVisualInfo (backend_x11->xdpy,
|
2010-03-26 02:44:37 +00:00
|
|
|
template_mask,
|
2009-08-20 10:53:37 +00:00
|
|
|
&visinfo_template,
|
|
|
|
&visinfos_count);
|
2009-08-11 13:18:37 +00:00
|
|
|
|
|
|
|
return visinfo;
|
|
|
|
}
|
|
|
|
|
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);
|
2009-08-11 13:18:37 +00:00
|
|
|
ClutterBackendX11Class *backendx11_class = CLUTTER_BACKEND_X11_CLASS (klass);
|
2007-03-22 18:21:59 +00:00
|
|
|
|
2007-03-27 21:09:11 +00:00
|
|
|
gobject_class->constructor = clutter_backend_egl_constructor;
|
2008-04-04 15:02:11 +00:00
|
|
|
gobject_class->dispose = clutter_backend_egl_dispose;
|
|
|
|
gobject_class->finalize = clutter_backend_egl_finalize;
|
|
|
|
|
|
|
|
backend_class->post_parse = clutter_backend_egl_post_parse;
|
|
|
|
backend_class->redraw = clutter_backend_egl_redraw;
|
|
|
|
backend_class->get_features = clutter_backend_egl_get_features;
|
|
|
|
backend_class->create_stage = clutter_backend_egl_create_stage;
|
|
|
|
backend_class->ensure_context = clutter_backend_egl_ensure_context;
|
2010-03-26 02:37:26 +00:00
|
|
|
backend_class->create_context = clutter_backend_egl_create_context;
|
2009-08-11 13:18:37 +00:00
|
|
|
backendx11_class->get_visual_info = clutter_backend_egl_get_visual_info;
|
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
|
|
|
{
|
2010-03-26 02:37:26 +00:00
|
|
|
backend_egl->egl_context = EGL_NO_CONTEXT;
|
2010-05-05 16:30:00 +00:00
|
|
|
backend_egl->dummy_surface = EGL_NO_SURFACE;
|
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
|
|
|
/**
|
2009-06-09 13:47:36 +00:00
|
|
|
* clutter_eglx_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
|
|
|
}
|