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
|
|
|
|
2009-10-05 09:58:08 -04:00
|
|
|
static ClutterStageWindowIface *clutter_stage_egl_parent_iface = NULL;
|
|
|
|
|
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
|
2009-10-05 09:58:08 -04:00
|
|
|
clutter_stage_egl_unrealize (ClutterStageWindow *stage_window)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2009-08-03 09:50:10 -04:00
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2009-10-05 09:58:08 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (stage_window);
|
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2009-10-05 09:58:08 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Unrealizing stage");
|
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
|
|
|
|
2009-07-31 13:34:51 -04:00
|
|
|
if (!stage_x11->is_foreign_xwin && stage_x11->xwin != None)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2009-08-03 09:50:10 -04:00
|
|
|
XDestroyWindow (backend_x11->xdpy, stage_x11->xwin);
|
2009-07-31 13:34:51 -04:00
|
|
|
stage_x11->xwin = None;
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
else
|
2009-07-31 13:34:51 -04:00
|
|
|
stage_x11->xwin = None;
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
2008-04-04 11:02:11 -04:00
|
|
|
{
|
|
|
|
eglDestroySurface (clutter_eglx_display (), stage_egl->egl_surface);
|
|
|
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
2009-08-03 09:50:10 -04:00
|
|
|
XSync (backend_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
|
|
|
}
|
|
|
|
|
2009-10-05 09:58:08 -04:00
|
|
|
static gboolean
|
2010-03-25 22:37:26 -04:00
|
|
|
clutter_stage_egl_realize (ClutterStageWindow *stage_window)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2009-10-05 09:58:08 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (stage_window);
|
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
|
|
|
ClutterBackend *backend;
|
2008-04-04 11:02:11 -04:00
|
|
|
ClutterBackendEGL *backend_egl;
|
2008-06-23 05:55:42 -04:00
|
|
|
ClutterBackendX11 *backend_x11;
|
2010-03-25 22:37:26 -04:00
|
|
|
EGLDisplay edpy;
|
2009-08-20 06:54:41 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
2008-04-04 11:02:11 -04:00
|
|
|
|
2009-10-05 09:58:08 -04:00
|
|
|
backend = clutter_get_default_backend ();
|
|
|
|
backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
2009-07-31 13:34:51 -04:00
|
|
|
edpy = clutter_eglx_display ();
|
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
if (stage_x11->xwin == None)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes xattr;
|
|
|
|
unsigned long mask;
|
|
|
|
XVisualInfo *xvisinfo;
|
|
|
|
gfloat width, height;
|
2009-07-31 13:34:51 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
CLUTTER_NOTE (MISC, "Creating stage X window");
|
2009-07-31 13:34:51 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
xvisinfo = clutter_backend_x11_get_visual_info (backend_x11);
|
|
|
|
if (xvisinfo == NULL)
|
|
|
|
{
|
|
|
|
g_critical ("Unable to find suitable GL visual.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-06-23 09:09:08 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
/* window attributes */
|
|
|
|
xattr.background_pixel = WhitePixel (backend_x11->xdpy,
|
|
|
|
backend_x11->xscreen_num);
|
|
|
|
xattr.border_pixel = 0;
|
|
|
|
xattr.colormap = XCreateColormap (backend_x11->xdpy,
|
|
|
|
backend_x11->xwin_root,
|
|
|
|
xvisinfo->visual,
|
|
|
|
AllocNone);
|
|
|
|
mask = CWBorderPixel | CWColormap;
|
|
|
|
|
|
|
|
/* Call get_size - this will either get the geometry size (which
|
|
|
|
* before we create the window is set to 640x480), or if a size
|
|
|
|
* is set, it will get that. This lets you set a size on the
|
|
|
|
* stage before it's realized.
|
|
|
|
*/
|
|
|
|
clutter_actor_get_size (CLUTTER_ACTOR (stage_x11->wrapper),
|
|
|
|
&width,
|
|
|
|
&height);
|
|
|
|
stage_x11->xwin_width = (gint)width;
|
|
|
|
stage_x11->xwin_height = (gint)height;
|
|
|
|
|
|
|
|
stage_x11->xwin = XCreateWindow (backend_x11->xdpy,
|
|
|
|
backend_x11->xwin_root,
|
|
|
|
0, 0,
|
|
|
|
stage_x11->xwin_width,
|
|
|
|
stage_x11->xwin_height,
|
|
|
|
0,
|
|
|
|
xvisinfo->depth,
|
|
|
|
InputOutput,
|
|
|
|
xvisinfo->visual,
|
|
|
|
mask, &xattr);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Stage [%p], window: 0x%x, size: %dx%d",
|
|
|
|
stage_window,
|
|
|
|
(unsigned int) stage_x11->xwin,
|
|
|
|
stage_x11->xwin_width,
|
|
|
|
stage_x11->xwin_height);
|
|
|
|
|
|
|
|
XFree (xvisinfo);
|
|
|
|
}
|
2007-10-12 04:17:00 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
2009-07-31 13:34:51 -04:00
|
|
|
{
|
2010-03-25 22:37:26 -04:00
|
|
|
stage_egl->egl_surface =
|
|
|
|
eglCreateWindowSurface (edpy,
|
|
|
|
backend_egl->egl_config,
|
2010-05-18 12:25:25 -04:00
|
|
|
(NativeWindowType) stage_x11->xwin,
|
2010-03-25 22:37:26 -04:00
|
|
|
NULL);
|
2009-07-31 13:34:51 -04:00
|
|
|
}
|
2008-04-04 11:02:11 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
|
|
|
g_warning ("Unable to create an EGL surface");
|
2009-07-31 13:34:51 -04:00
|
|
|
|
|
|
|
if (clutter_x11_has_event_retrieval ())
|
|
|
|
{
|
|
|
|
if (clutter_x11_has_xinput ())
|
2008-06-23 05:55:42 -04:00
|
|
|
{
|
2009-08-03 09:50:10 -04:00
|
|
|
XSelectInput (backend_x11->xdpy, stage_x11->xwin,
|
2009-07-31 13:34:51 -04:00
|
|
|
StructureNotifyMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
PropertyChangeMask);
|
|
|
|
#ifdef USE_XINPUT
|
|
|
|
_clutter_x11_select_events (stage_x11->xwin);
|
2008-06-23 05:55:42 -04:00
|
|
|
#endif
|
|
|
|
}
|
2009-07-31 13:34:51 -04:00
|
|
|
else
|
2009-08-03 09:50:10 -04:00
|
|
|
XSelectInput (backend_x11->xdpy, stage_x11->xwin,
|
2009-07-31 13:34:51 -04:00
|
|
|
StructureNotifyMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
PointerMotionMask |
|
|
|
|
KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
PropertyChangeMask);
|
|
|
|
}
|
2008-04-04 11:02:11 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
/* no user resize... */
|
|
|
|
clutter_stage_x11_fix_window_size (stage_x11,
|
|
|
|
stage_x11->xwin_width,
|
|
|
|
stage_x11->xwin_height);
|
2009-07-31 13:34:51 -04:00
|
|
|
clutter_stage_x11_set_wm_protocols (stage_x11);
|
2008-04-14 13:01:14 -04:00
|
|
|
|
2010-03-25 22:37:26 -04:00
|
|
|
return clutter_stage_egl_parent_iface->realize (stage_window);
|
2009-08-20 06:54:41 -04:00
|
|
|
}
|
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
static void
|
|
|
|
clutter_stage_egl_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (clutter_stage_egl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
static void
|
|
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
|
|
{
|
2009-10-05 09:58:08 -04:00
|
|
|
clutter_stage_egl_parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->realize = clutter_stage_egl_realize;
|
|
|
|
iface->unrealize = clutter_stage_egl_unrealize;
|
|
|
|
|
2008-04-04 11:02:11 -04:00
|
|
|
/* 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);
|
2007-03-22 14:21:59 -04:00
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
gobject_class->dispose = clutter_stage_egl_dispose;
|
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
|
|
|
{
|
2010-03-25 22:37:26 -04:00
|
|
|
stage->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clutter_stage_egl_redraw (ClutterStageEGL *stage_egl,
|
|
|
|
ClutterStage *stage)
|
|
|
|
{
|
|
|
|
ClutterBackend *backend = clutter_get_default_backend ();
|
|
|
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
|
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_egl);
|
|
|
|
ClutterStageWindow *impl;
|
|
|
|
|
|
|
|
impl = _clutter_stage_get_window (stage);
|
|
|
|
if (impl == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_assert (CLUTTER_IS_STAGE_EGL (impl));
|
|
|
|
stage_egl = CLUTTER_STAGE_EGL (impl);
|
|
|
|
|
|
|
|
clutter_actor_paint (CLUTTER_ACTOR (stage_x11->wrapper));
|
|
|
|
cogl_flush ();
|
|
|
|
|
|
|
|
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|