2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-03-22 14:21:59 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
#include "clutter-backend-egl.h"
|
2007-03-22 14:21:59 -04:00
|
|
|
#include "clutter-stage-egl.h"
|
2007-07-06 10:08:03 -04:00
|
|
|
#include "clutter-eglx.h"
|
2007-03-27 17:09:11 -04:00
|
|
|
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
#include "../clutter-feature.h"
|
|
|
|
#include "../clutter-color.h"
|
|
|
|
#include "../clutter-util.h"
|
2007-03-22 14:21:59 -04:00
|
|
|
#include "../clutter-event.h"
|
2007-03-27 17:09:11 -04:00
|
|
|
#include "../clutter-enum-types.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
2007-05-22 05:31:40 -04:00
|
|
|
#include "../clutter-units.h"
|
2008-04-04 11:02:11 -04:00
|
|
|
#include "../clutter-container.h"
|
|
|
|
#include "../clutter-stage.h"
|
|
|
|
#include "../clutter-stage-window.h"
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterStageEGL,
|
|
|
|
clutter_stage_egl,
|
|
|
|
CLUTTER_TYPE_STAGE_X11,
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
|
|
|
clutter_stage_window_iface_init));
|
2007-03-27 17:09:11 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_unrealize (ClutterActor *actor)
|
|
|
|
{
|
2007-05-31 08:35:36 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
|
2007-11-15 09:45:27 -05:00
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (actor);
|
2007-03-27 17:09:11 -04:00
|
|
|
gboolean was_offscreen;
|
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
g_object_get (stage_x11->wrapper, "offscreen", &was_offscreen, NULL);
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->unrealize (actor);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-14 11:10:22 -04:00
|
|
|
clutter_x11_trap_x_errors ();
|
2008-02-07 07:55:51 -05:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
if (G_UNLIKELY (was_offscreen))
|
|
|
|
{
|
|
|
|
/* No support as yet for this */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-14 11:10:22 -04:00
|
|
|
if (!stage_x11->is_foreign_xwin && stage_x11->xwin != None)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2007-11-15 09:45:27 -05:00
|
|
|
XDestroyWindow (stage_x11->xdpy, stage_x11->xwin);
|
|
|
|
stage_x11->xwin = None;
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
else
|
2007-11-15 09:45:27 -05:00
|
|
|
stage_x11->xwin = None;
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stage_egl->egl_surface)
|
2008-04-04 11:02:11 -04:00
|
|
|
{
|
|
|
|
eglDestroySurface (clutter_eglx_display (), stage_egl->egl_surface);
|
|
|
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_stage_ensure_current (stage_x11->wrapper);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
/* XSync (stage_x11->xdpy, False); */
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
clutter_x11_untrap_x_errors ();
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
CLUTTER_MARK ();
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_realize (ClutterActor *actor)
|
|
|
|
{
|
2008-04-04 11:02:11 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
|
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (actor);
|
|
|
|
ClutterBackendEGL *backend_egl;
|
|
|
|
EGLConfig configs[2];
|
|
|
|
EGLint config_count;
|
|
|
|
EGLBoolean status;
|
|
|
|
gboolean is_offscreen = FALSE;
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2007-04-27 20:37:11 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
g_object_get (stage_x11->wrapper, "offscreen", &is_offscreen, NULL);
|
|
|
|
|
|
|
|
backend_egl = CLUTTER_BACKEND_EGL (clutter_get_default_backend ());
|
2007-03-27 17:09:11 -04:00
|
|
|
|
|
|
|
if (G_LIKELY (!is_offscreen))
|
|
|
|
{
|
2008-04-04 11:02:11 -04:00
|
|
|
EGLint cfg_attribs[] = {
|
|
|
|
EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_BLUE_SIZE, 5,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
status = eglGetConfigs (backend_egl->edpy,
|
2007-10-12 04:17:00 -04:00
|
|
|
configs,
|
|
|
|
2,
|
2007-03-27 17:09:11 -04:00
|
|
|
&config_count);
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
if (status != EGL_TRUE)
|
2008-04-04 11:02:11 -04:00
|
|
|
g_warning ("eglGetConfigs failed");
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
status = eglChooseConfig (backend_egl->edpy,
|
2007-10-12 04:17:00 -04:00
|
|
|
cfg_attribs,
|
|
|
|
configs,
|
2008-04-04 11:02:11 -04:00
|
|
|
G_N_ELEMENTS (configs),
|
2007-03-27 17:09:11 -04:00
|
|
|
&config_count);
|
2007-04-27 20:37:11 -04:00
|
|
|
|
|
|
|
if (status != EGL_TRUE)
|
2008-04-04 11:02:11 -04:00
|
|
|
g_warning ("eglChooseConfig failed");
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
if (stage_x11->xwin == None)
|
2008-04-04 11:02:11 -04:00
|
|
|
stage_x11->xwin =
|
|
|
|
XCreateSimpleWindow (stage_x11->xdpy,
|
|
|
|
stage_x11->xwin_root,
|
|
|
|
0, 0,
|
|
|
|
stage_x11->xwin_width,
|
|
|
|
stage_x11->xwin_height,
|
|
|
|
0, 0,
|
|
|
|
WhitePixel (stage_x11->xdpy,
|
|
|
|
stage_x11->xscreen));
|
|
|
|
|
|
|
|
XSelectInput (stage_x11->xdpy, stage_x11->xwin,
|
|
|
|
StructureNotifyMask
|
|
|
|
| ExposureMask
|
|
|
|
/* FIXME: we may want to eplicity enable MotionMask */
|
|
|
|
| PointerMotionMask
|
|
|
|
| KeyPressMask
|
|
|
|
| KeyReleaseMask
|
|
|
|
| ButtonPressMask
|
|
|
|
| ButtonReleaseMask
|
|
|
|
| PropertyChangeMask);
|
|
|
|
|
|
|
|
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
|
|
|
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage_egl->egl_surface =
|
|
|
|
eglCreateWindowSurface (backend_egl->edpy,
|
|
|
|
configs[0],
|
|
|
|
(NativeWindowType) stage_x11->xwin,
|
|
|
|
NULL);
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
2008-04-04 11:02:11 -04:00
|
|
|
{
|
|
|
|
g_critical ("Unable to create an EGL surface");
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (backend_egl->egl_context == None))
|
|
|
|
{
|
|
|
|
CLUTTER_NOTE (GL, "Creating EGL Context");
|
|
|
|
|
|
|
|
backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
|
|
|
|
configs[0],
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
g_critical ("Unable to create a suitable EGL context");
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-10 15:54:08 -04:00
|
|
|
/* this will make sure to set the current context */
|
|
|
|
CLUTTER_NOTE (BACKEND, "Marking stage as realized and setting context");
|
2008-04-04 11:02:11 -04:00
|
|
|
CLUTTER_ACTOR_SET_FLAGS (stage_x11->wrapper, CLUTTER_ACTOR_REALIZED);
|
2008-04-10 15:54:08 -04:00
|
|
|
CLUTTER_ACTOR_SET_FLAGS (stage_x11, CLUTTER_ACTOR_REALIZED);
|
2008-04-04 11:02:11 -04:00
|
|
|
clutter_stage_ensure_current (stage_x11->wrapper);
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-04 11:02:11 -04:00
|
|
|
g_warning("EGLX Backend does not support offscreen rendering");
|
2008-02-07 07:55:51 -05:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
CLUTTER_SET_PRIVATE_FLAGS (stage_x11->wrapper, CLUTTER_ACTOR_SYNC_MATRICES);
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_dispose (GObject *gobject)
|
|
|
|
{
|
2007-05-31 08:35:36 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (gobject);
|
2007-11-15 09:45:27 -05:00
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (gobject);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
if (stage_x11->xwin)
|
2007-03-27 17:09:11 -04:00
|
|
|
clutter_actor_unrealize (CLUTTER_ACTOR (stage_egl));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_stage_egl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
static GdkPixbuf *
|
|
|
|
clutter_stage_egl_draw_to_pixbuf (ClutterStageWindow *stage_window,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
2008-04-14 11:10:22 -04:00
|
|
|
ClutterStage *stage = CLUTTER_STAGE (stage_window);
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
g_warning ("Stages of type `%s' do not support "
|
|
|
|
"ClutterStageWindow::draw_to_pixbuf",
|
|
|
|
G_OBJECT_TYPE_NAME (stage));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
|
|
{
|
|
|
|
iface->draw_to_pixbuf = clutter_stage_egl_draw_to_pixbuf;
|
|
|
|
|
|
|
|
/* the rest is inherited from ClutterStageX11 */
|
|
|
|
}
|
|
|
|
|
2007-03-22 14:21:59 -04:00
|
|
|
static void
|
2007-05-31 08:35:36 -04:00
|
|
|
clutter_stage_egl_class_init (ClutterStageEGLClass *klass)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-03-27 17:09:11 -04:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
gobject_class->dispose = clutter_stage_egl_dispose;
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
actor_class->realize = clutter_stage_egl_realize;
|
|
|
|
actor_class->unrealize = clutter_stage_egl_unrealize;
|
2007-03-22 14:21:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-05-31 08:35:36 -04:00
|
|
|
clutter_stage_egl_init (ClutterStageEGL *stage)
|
2007-03-22 14:21:59 -04:00
|
|
|
{
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|