2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-07-06 09:56:01 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
#include "clutter-stage-egl.h"
|
|
|
|
#include "clutter-egl.h"
|
2008-04-25 09:37:36 -04:00
|
|
|
#include "clutter-backend-egl.h"
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
#include "../clutter-main.h"
|
|
|
|
#include "../clutter-feature.h"
|
|
|
|
#include "../clutter-color.h"
|
|
|
|
#include "../clutter-util.h"
|
|
|
|
#include "../clutter-event.h"
|
|
|
|
#include "../clutter-enum-types.h"
|
|
|
|
#include "../clutter-private.h"
|
|
|
|
#include "../clutter-debug.h"
|
|
|
|
#include "../clutter-units.h"
|
2008-04-23 13:20:59 -04:00
|
|
|
#include "../clutter-stage.h"
|
|
|
|
#include "../clutter-stage-window.h"
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (ClutterStageEGL,
|
|
|
|
clutter_stage_egl,
|
|
|
|
CLUTTER_TYPE_ACTOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW,
|
|
|
|
clutter_stage_window_iface_init));
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_show (ClutterActor *actor)
|
|
|
|
{
|
2008-05-13 12:09:42 -04:00
|
|
|
CLUTTER_ACTOR_SET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_hide (ClutterActor *actor)
|
|
|
|
{
|
2008-05-13 12:09:42 -04:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_MAPPED);
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_unrealize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
|
|
|
|
|
|
|
|
CLUTTER_MARK();
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->unrealize (actor);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
if (stage_egl->egl_surface)
|
2008-04-23 13:20:59 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
eglDestroySurface (clutter_egl_display (), stage_egl->egl_surface);
|
2008-04-23 13:20:59 -04:00
|
|
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_realize (ClutterActor *actor)
|
|
|
|
{
|
2008-04-23 13:20:59 -04:00
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
|
|
|
|
ClutterBackendEGL *backend_egl;
|
2007-07-06 09:56:01 -04:00
|
|
|
EGLConfig configs[2];
|
|
|
|
EGLint config_count;
|
|
|
|
EGLBoolean status;
|
2008-04-23 13:20:59 -04:00
|
|
|
gboolean is_offscreen;
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
g_object_get (stage_egl->wrapper, "offscreen", &is_offscreen, NULL);
|
|
|
|
|
|
|
|
backend_egl = CLUTTER_BACKEND_EGL (clutter_get_default_backend ());
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
if (G_LIKELY (!is_offscreen))
|
|
|
|
{
|
2008-06-06 10:21:22 -04:00
|
|
|
EGLint cfg_attribs[] = { EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
|
|
|
EGL_RED_SIZE, 5,
|
|
|
|
EGL_GREEN_SIZE, 6,
|
|
|
|
EGL_BLUE_SIZE, 5,
|
|
|
|
EGL_DEPTH_SIZE, 16,
|
|
|
|
EGL_ALPHA_SIZE, EGL_DONT_CARE,
|
2008-06-24 06:39:12 -04:00
|
|
|
EGL_STENCIL_SIZE, 2,
|
2008-06-06 10:21:22 -04:00
|
|
|
#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 */
|
2007-07-06 09:56:01 -04:00
|
|
|
EGL_NONE };
|
2008-04-23 13:20:59 -04:00
|
|
|
|
2008-06-25 09:52:17 -04:00
|
|
|
ClutterUnit widthu, heightu;
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
status = eglGetConfigs (backend_egl->edpy,
|
2007-07-06 09:56:01 -04:00
|
|
|
configs,
|
|
|
|
2,
|
|
|
|
&config_count);
|
2008-04-23 13:20:59 -04:00
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
if (status != EGL_TRUE)
|
2008-04-28 05:33:38 -04:00
|
|
|
{
|
|
|
|
g_critical ("eglGetConfigs failed");
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-23 13:20:59 -04:00
|
|
|
|
|
|
|
status = eglChooseConfig (backend_egl->edpy,
|
|
|
|
cfg_attribs,
|
|
|
|
configs,
|
|
|
|
G_N_ELEMENTS (configs),
|
2007-07-06 09:56:01 -04:00
|
|
|
&config_count);
|
|
|
|
|
|
|
|
if (status != EGL_TRUE)
|
2008-04-28 05:33:38 -04:00
|
|
|
{
|
|
|
|
g_critical ("eglChooseConfig failed");
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-23 13:20:59 -04:00
|
|
|
|
2008-06-24 06:39:12 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "Got %i configs", config_count);
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
|
|
|
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (backend_egl->egl_context)
|
|
|
|
{
|
|
|
|
eglDestroyContext (backend_egl->edpy, backend_egl->egl_context);
|
|
|
|
backend_egl->egl_context = NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
stage_egl->egl_surface =
|
|
|
|
eglCreateWindowSurface (backend_egl->edpy,
|
|
|
|
configs[0],
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
|
|
|
{
|
|
|
|
g_critical ("Unable to create an EGL surface");
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
eglQuerySurface (backend_egl->edpy,
|
2007-07-06 09:56:01 -04:00
|
|
|
stage_egl->egl_surface,
|
|
|
|
EGL_WIDTH,
|
|
|
|
&stage_egl->surface_width);
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
eglQuerySurface (backend_egl->edpy,
|
2007-07-06 09:56:01 -04:00
|
|
|
stage_egl->egl_surface,
|
|
|
|
EGL_HEIGHT,
|
|
|
|
&stage_egl->surface_height);
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
CLUTTER_NOTE (BACKEND, "EGL surface is %ix%i",
|
|
|
|
stage_egl->surface_width,
|
|
|
|
stage_egl->surface_height);
|
|
|
|
|
2008-06-25 09:52:17 -04:00
|
|
|
widthu = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_width);
|
|
|
|
heightu = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_height);
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Setting minimum and natural width and height "
|
|
|
|
"to the EGL surface width and height");
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (stage_egl),
|
|
|
|
"min-width", widthu,
|
|
|
|
"min-width-set", TRUE,
|
|
|
|
"natural-width", widthu,
|
|
|
|
"natural-width-set", TRUE,
|
|
|
|
"min-height", heightu,
|
|
|
|
"min-height-set", TRUE,
|
|
|
|
"natural-height", heightu,
|
|
|
|
"natural-height-set", TRUE,
|
|
|
|
NULL);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
if (G_UNLIKELY (backend_egl->egl_context == NULL))
|
2008-04-23 13:20:59 -04:00
|
|
|
{
|
2008-06-06 10:21:22 -04:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
2008-06-25 07:17:43 -04:00
|
|
|
static const EGLint attribs[3]
|
|
|
|
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
2008-04-23 13:20:59 -04:00
|
|
|
|
|
|
|
backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
|
2008-06-06 10:21:22 -04:00
|
|
|
configs[0],
|
2008-04-23 13:20:59 -04:00
|
|
|
EGL_NO_CONTEXT,
|
2008-06-06 10:21:22 -04:00
|
|
|
attribs);
|
2008-06-25 07:17:43 -04:00
|
|
|
#else
|
|
|
|
/* Seems some GLES implementations 1.x do not like attribs... */
|
|
|
|
backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
|
|
|
|
configs[0],
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
NULL);
|
|
|
|
#endif
|
2008-04-23 13:20:59 -04:00
|
|
|
|
|
|
|
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-06-25 07:17:43 -04:00
|
|
|
|
|
|
|
CLUTTER_NOTE (GL, "Created EGL Context");
|
2008-04-23 13:20:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CLUTTER_NOTE (BACKEND, "Marking stage as realized and setting context");
|
|
|
|
CLUTTER_ACTOR_SET_FLAGS (stage_egl, CLUTTER_ACTOR_REALIZED);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-04-28 05:33:38 -04:00
|
|
|
/* eglnative can have only one stage */
|
2008-04-25 09:37:36 -04:00
|
|
|
status = eglMakeCurrent (backend_egl->edpy,
|
|
|
|
stage_egl->egl_surface,
|
|
|
|
stage_egl->egl_surface,
|
|
|
|
backend_egl->egl_context);
|
|
|
|
|
|
|
|
if (status != EGL_TRUE)
|
2008-04-28 05:33:38 -04:00
|
|
|
{
|
|
|
|
g_critical ("eglMakeCurrent failed");
|
|
|
|
|
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-28 05:33:38 -04:00
|
|
|
g_warning ("EGL Backend does not yet support offscreen rendering\n");
|
2008-02-07 07:55:51 -05:00
|
|
|
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
|
|
|
|
return;
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-11 06:19:02 -04:00
|
|
|
clutter_stage_egl_get_preferred_width (ClutterActor *self,
|
|
|
|
ClutterUnit for_height,
|
|
|
|
ClutterUnit *min_width_p,
|
|
|
|
ClutterUnit *natural_width_p)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (self);
|
|
|
|
|
2008-06-11 06:19:02 -04:00
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_width);
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_width);
|
|
|
|
}
|
|
|
|
|
2007-07-06 09:56:01 -04:00
|
|
|
static void
|
2008-06-11 06:19:02 -04:00
|
|
|
clutter_stage_egl_get_preferred_height (ClutterActor *self,
|
|
|
|
ClutterUnit for_width,
|
|
|
|
ClutterUnit *min_height_p,
|
|
|
|
ClutterUnit *natural_height_p)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (self);
|
|
|
|
|
2008-06-11 06:19:02 -04:00
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_height);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-06-11 06:19:02 -04:00
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = CLUTTER_UNITS_FROM_DEVICE (stage_egl->surface_height);
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_dispose (GObject *gobject)
|
|
|
|
{
|
|
|
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (gobject);
|
|
|
|
|
|
|
|
clutter_actor_unrealize (CLUTTER_ACTOR (stage_egl));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (clutter_stage_egl_parent_class)->dispose (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clutter_stage_egl_class_init (ClutterStageEGLClass *klass)
|
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2007-07-06 09:56:01 -04:00
|
|
|
|
|
|
|
gobject_class->dispose = clutter_stage_egl_dispose;
|
2008-04-23 13:20:59 -04:00
|
|
|
|
2008-06-11 06:19:02 -04:00
|
|
|
actor_class->show = clutter_stage_egl_show;
|
|
|
|
actor_class->hide = clutter_stage_egl_hide;
|
|
|
|
actor_class->realize = clutter_stage_egl_realize;
|
|
|
|
actor_class->unrealize = clutter_stage_egl_unrealize;
|
|
|
|
actor_class->get_preferred_width = clutter_stage_egl_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = clutter_stage_egl_get_preferred_height;
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-04-23 13:20:59 -04:00
|
|
|
clutter_stage_egl_set_fullscreen (ClutterStageWindow *stage_window,
|
|
|
|
gboolean fullscreen)
|
2007-07-06 09:56:01 -04:00
|
|
|
{
|
2008-04-23 13:20:59 -04:00
|
|
|
g_warning ("Stage of type `%s' do not support ClutterStage::set_fullscreen",
|
|
|
|
G_OBJECT_TYPE_NAME (stage_window));
|
2007-07-06 09:56:01 -04:00
|
|
|
}
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
static ClutterActor *
|
|
|
|
clutter_stage_egl_get_wrapper (ClutterStageWindow *stage_window)
|
|
|
|
{
|
|
|
|
return CLUTTER_ACTOR (CLUTTER_STAGE_EGL (stage_window)->wrapper);
|
|
|
|
}
|
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
static void
|
|
|
|
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
|
|
|
|
{
|
|
|
|
iface->set_fullscreen = clutter_stage_egl_set_fullscreen;
|
2008-04-25 09:37:36 -04:00
|
|
|
iface->set_title = NULL;
|
|
|
|
iface->get_wrapper = clutter_stage_egl_get_wrapper;
|
2008-04-23 13:20:59 -04:00
|
|
|
}
|
2007-07-06 09:56:01 -04:00
|
|
|
|
2008-04-23 13:20:59 -04:00
|
|
|
static void
|
|
|
|
clutter_stage_egl_init (ClutterStageEGL *stage)
|
|
|
|
{
|
|
|
|
}
|