2008-04-23 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/eglnative/clutter-backend-egl.[ch]:
	* clutter/eglnative/clutter-stage-egl.[ch]:
	* clutter/eglnative/clutter-event-egl.c: Port to the new stage
	and backend APIs. *WARNING* untested and not compiled.

	* clutter/eglx/clutter-backend-egl.c:
	(clutter_backend_egl_init): Set some defaults.
This commit is contained in:
Emmanuele Bassi 2008-04-23 17:20:59 +00:00
parent f7d9c5eaa1
commit 6ac86b939b
7 changed files with 243 additions and 146 deletions

View File

@ -1,3 +1,13 @@
2008-04-23 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/eglnative/clutter-backend-egl.[ch]:
* clutter/eglnative/clutter-stage-egl.[ch]:
* clutter/eglnative/clutter-event-egl.c: Port to the new stage
and backend APIs. *WARNING* untested and not compiled.
* clutter/eglx/clutter-backend-egl.c:
(clutter_backend_egl_init): Set some defaults.
2008-04-23 Emmanuele Bassi <ebassi@openedhand.com> 2008-04-23 Emmanuele Bassi <ebassi@openedhand.com>
* tests/test-script.json: Remove the explicit "visible" * tests/test-script.json: Remove the explicit "visible"

View File

@ -27,9 +27,9 @@ clutter_backend_egl_post_parse (ClutterBackend *backend,
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL(backend); ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL(backend);
EGLBoolean status; EGLBoolean status;
backend_egl->edpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); backend_egl->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);
status = eglInitialize(backend_egl->edpy, status = eglInitialize (backend_egl->edpy,
&backend_egl->egl_version_major, &backend_egl->egl_version_major,
&backend_egl->egl_version_minor); &backend_egl->egl_version_minor);
@ -48,33 +48,111 @@ clutter_backend_egl_post_parse (ClutterBackend *backend,
return TRUE; return TRUE;
} }
static gboolean static void
clutter_backend_egl_init_stage (ClutterBackend *backend, clutter_backend_egl_ensure_context (ClutterBackend *backend,
GError **error) ClutterStage *stage)
{ {
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend); ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
if (!backend_egl->stage) if (stage == NULL)
{ {
CLUTTER_NOTE (BACKEND, "Clearing EGL context");
eglMakeCurrent (backend_egl->edpy,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT);
}
else
{
ClutterStageWindow *impl;
ClutterStageEGL *stage_egl;
impl = _clutter_stage_get_window (stage);
g_assert (impl != NULL);
stage_egl = CLUTTER_STAGE_EGL (impl);
if (!backend_egl->egl_context)
return;
if (stage_egl->egl_surface == EGL_NO_SURFACE)
eglMakeCurrent (backend_egl->edpy,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT);
else
eglMakeCurrent (backend_egl->edpy,
stage_egl->egl_surface,
stage_egl->egl_surface,
backend_egl->egl_context);
}
}
static void
clutter_backend_egl_redraw (ClutterBackend *backend,
ClutterStage *stage)
{
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
ClutterStageEGL *stage_egl;
ClutterStageWindow *impl;
impl = _clutter_stage_get_window (stage);
if (!impl)
return;
g_assert (CLUTTER_IS_STAGE_EGL (impl));
stage_egl = CLUTTER_STAGE_EGL (impl);
clutter_actor_paint (CLUTTER_ACTOR (stage_egl));
/* Why this paint is done in backend as likely GL windowing system
* specific calls, like swapping buffers.
*/
/* clutter_feature_wait_for_vblank (); */
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
}
static ClutterActor *
clutter_backend_egl_create_stage (ClutterBackend *backend,
ClutterStage *wrapper,
GError **error)
{
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
ClutterStageEGL *stage_egl;
ClutterActor *stage; ClutterActor *stage;
if (backend_egl->stage)
{
g_warning ("The EGL native backend does not support multiple stages");
return backend_egl->stage;
}
stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL); stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL);
stage_egl = CLUTTER_STAGE_EGL (stage);
stage_egl->edpy = backend_egl->edpy
stage_egl->backend = backend_egl;
stage_egl->wrapper = wrapper;
_clutter_stage_set_window (wrapper, CLUTTER_STAGE_WINDOW (stage));
g_object_set_data (G_OBJECT (stage), "clutter-backend", backend); g_object_set_data (G_OBJECT (stage), "clutter-backend", backend);
backend_egl->stage = g_object_ref_sink (stage);
}
clutter_actor_realize (backend_egl->stage); clutter_actor_realize (backend_egl->stage);
if (!CLUTTER_ACTOR_IS_REALIZED (backend_egl->stage)) if (!CLUTTER_ACTOR_IS_REALIZED (backend_egl->stage))
{ {
g_set_error (error, CLUTTER_INIT_ERROR, g_set_error (error, CLUTTER_INIT_ERROR,
CLUTTER_INIT_ERROR_INTERNAL, CLUTTER_INIT_ERROR_INTERNAL,
"Unable to realize the main stage"); "Unable to realize the main stage");
return FALSE; g_object_unref (stage);
return NULL;
} }
return TRUE; backend_egl->stage = stage_egl;
return stage;
} }
static void static void
@ -89,23 +167,6 @@ static const GOptionEntry entries[] =
{ NULL } { NULL }
}; };
static void
clutter_backend_egl_redraw (ClutterBackend *backend)
{
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
ClutterStageEGL *stage_egl;
stage_egl = CLUTTER_STAGE_EGL(backend_egl->stage);
clutter_actor_paint (CLUTTER_ACTOR(stage_egl));
/* Why this paint is done in backend as likely GL windowing system
* specific calls, like swapping buffers.
*/
/* clutter_feature_wait_for_vblank (); */
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
}
static ClutterActor * static ClutterActor *
clutter_backend_egl_get_stage (ClutterBackend *backend) clutter_backend_egl_get_stage (ClutterBackend *backend)
{ {
@ -130,12 +191,10 @@ clutter_backend_egl_dispose (GObject *gobject)
_clutter_events_uninit (CLUTTER_BACKEND (backend_egl)); _clutter_events_uninit (CLUTTER_BACKEND (backend_egl));
if (backend_egl->stage) if (backend_egl->egl_context)
{ {
CLUTTER_UNSET_PRIVATE_FLAGS (backend_egl->stage, eglDestroyContext (backend_egl->edpy, backend_egl->egl_context);
CLUTTER_ACTOR_IS_TOPLEVEL); backend_egl->egl_context = NULL;
clutter_actor_destroy (backend_egl->stage);
backend_egl->stage = NULL;
} }
if (backend_egl->edpy) if (backend_egl->edpy)
@ -174,6 +233,22 @@ clutter_backend_egl_constructor (GType gtype,
static ClutterFeatureFlags static ClutterFeatureFlags
clutter_backend_egl_get_features (ClutterBackend *backend) clutter_backend_egl_get_features (ClutterBackend *backend)
{ {
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
CLUTTER_NOTE (BACKEND, "Checking features\n"
"GL_VENDOR: %s\n"
"GL_RENDERER: %s\n"
"GL_VERSION: %s\n"
"EGL_VENDOR: %s\n"
"EGL_VERSION: %s\n"
"EGL_EXTENSIONS: %s\n",
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));
return CLUTTER_FEATURE_STAGE_STATIC; return CLUTTER_FEATURE_STAGE_STATIC;
} }
@ -189,9 +264,9 @@ clutter_backend_egl_class_init (ClutterBackendEGLClass *klass)
backend_class->pre_parse = clutter_backend_egl_pre_parse; backend_class->pre_parse = clutter_backend_egl_pre_parse;
backend_class->post_parse = clutter_backend_egl_post_parse; backend_class->post_parse = clutter_backend_egl_post_parse;
backend_class->init_stage = clutter_backend_egl_init_stage;
backend_class->init_events = clutter_backend_egl_init_events; backend_class->init_events = clutter_backend_egl_init_events;
backend_class->get_stage = clutter_backend_egl_get_stage; backend_class->create_stage = clutter_backend_egl_init_stage;
backend_class->ensure_context = clutter_backend_egl_ensure_context;
backend_class->redraw = clutter_backend_egl_redraw; backend_class->redraw = clutter_backend_egl_redraw;
backend_class->get_features = clutter_backend_egl_get_features; backend_class->get_features = clutter_backend_egl_get_features;
} }

View File

@ -46,7 +46,11 @@ struct _ClutterBackendEGL
/* EGL Specific */ /* EGL Specific */
EGLDisplay edpy; EGLDisplay edpy;
gint egl_version_major, egl_version_minor; EGLSurface egl_surface;
EGLContext egl_context;
gint egl_version_major;
gint egl_version_minor;
/* main stage singleton */ /* main stage singleton */
ClutterActor *stage; ClutterActor *stage;

View File

@ -215,6 +215,8 @@ clutter_event_dispatch (GSource *source,
event = clutter_event_new (CLUTTER_NOTHING); event = clutter_event_new (CLUTTER_NOTHING);
event->any.stage = clutter_stage_get_default ();
last_x = event->button.x = tsevent.x; last_x = event->button.x = tsevent.x;
last_y = event->button.y = tsevent.y; last_y = event->button.y = tsevent.y;

View File

@ -2,6 +2,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include "clutter-backend-egl.h"
#include "clutter-stage-egl.h" #include "clutter-stage-egl.h"
#include "clutter-egl.h" #include "clutter-egl.h"
@ -14,64 +15,63 @@
#include "../clutter-private.h" #include "../clutter-private.h"
#include "../clutter-debug.h" #include "../clutter-debug.h"
#include "../clutter-units.h" #include "../clutter-units.h"
#include "../clutter-stage.h"
#include "../clutter-stage-window.h"
G_DEFINE_TYPE (ClutterStageEGL, clutter_stage_egl, CLUTTER_TYPE_STAGE); 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));
static void static void
clutter_stage_egl_show (ClutterActor *actor) clutter_stage_egl_show (ClutterActor *actor)
{ {
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->show (actor);
CLUTTER_ACTOR_SET_FLAGS (stage_egl, CLUTTER_ACTOR_MAPPED);
} }
static void static void
clutter_stage_egl_hide (ClutterActor *actor) clutter_stage_egl_hide (ClutterActor *actor)
{ {
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->hide (actor);
CLUTTER_ACTOR_UNSET_FLAGS (stage_egl, CLUTTER_ACTOR_MAPPED);
} }
static void static void
clutter_stage_egl_unrealize (ClutterActor *actor) clutter_stage_egl_unrealize (ClutterActor *actor)
{ {
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
gboolean was_offscreen;
CLUTTER_MARK(); CLUTTER_MARK();
g_object_get (actor, "offscreen", &was_offscreen, NULL); CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->unrealize (actor);
if (stage_egl->egl_surface) if (stage_egl->egl_surface)
{
eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface); eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface);
stage_egl->egl_surface = NULL; stage_egl->egl_surface = EGL_NO_SURFACE;
}
if (stage_egl->egl_context) clutter_stage_ensure_current (stage_egl->wrapper);
eglDestroyContext (clutter_egl_display(), stage_egl->egl_context);
stage_egl->egl_context = NULL;
eglMakeCurrent (clutter_egl_display(),
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
stage_egl->egl_context = EGL_NO_CONTEXT;
} }
static void static void
clutter_stage_egl_realize (ClutterActor *actor) clutter_stage_egl_realize (ClutterActor *actor)
{ {
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
ClutterBackendEGL *backend_egl;
EGLConfig configs[2]; EGLConfig configs[2];
EGLint config_count; EGLint config_count;
EGLBoolean status; EGLBoolean status;
ClutterPerspective perspective; ClutterPerspective perspective;
gboolean is_offscreen; gboolean is_offscreen;
CLUTTER_NOTE (BACKEND, "Realizing main stage"); CLUTTER_NOTE (BACKEND, "Realizing main stage");
g_object_get (actor, "offscreen", &is_offscreen, NULL); g_object_get (stage_egl->wrapper, "offscreen", &is_offscreen, NULL);
backend_egl = CLUTTER_BACKEND_EGL (clutter_get_default_backend ());
if (G_LIKELY (!is_offscreen)) if (G_LIKELY (!is_offscreen))
{ {
@ -85,66 +85,80 @@ clutter_stage_egl_realize (ClutterActor *actor)
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE }; EGL_NONE };
status = eglGetConfigs (clutter_egl_display(), status = eglGetConfigs (backend_egl->edpy,
configs, configs,
2, 2,
&config_count); &config_count);
if (status != EGL_TRUE) if (status != EGL_TRUE)
g_warning ("eglGetConfigs"); g_warning ("eglGetConfigs failed");
status = eglChooseConfig (clutter_egl_display(), status = eglChooseConfig (backend_egl->edpy,
cfg_attribs, cfg_attribs,
configs, configs,
sizeof configs / sizeof configs[0], G_N_ELEMENTS (configs),
&config_count); &config_count);
if (status != EGL_TRUE) if (status != EGL_TRUE)
g_warning ("eglChooseConfig"); g_warning ("eglChooseConfig failed");
if (stage_egl->egl_context) if (stage_egl->egl_surface != EGL_NO_SURFACE)
eglDestroyContext (clutter_egl_display(), stage_egl->egl_context); {
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
stage_egl->egl_surface = EGL_NO_SURFACE;
}
if (stage_egl->egl_surface) stage_egl->egl_surface =
eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface); eglCreateWindowSurface (backend_egl->edpy,
stage_egl->egl_surface
= eglCreateWindowSurface (clutter_egl_display(),
configs[0], configs[0],
NULL, NULL,
NULL); NULL);
eglQuerySurface (clutter_egl_display(), if (stage_egl->egl_surface == EGL_NO_SURFACE)
{
g_critical ("Unable to create an EGL surface");
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
return;
}
eglQuerySurface (backend_egl->edpy,
stage_egl->egl_surface, stage_egl->egl_surface,
EGL_WIDTH, EGL_WIDTH,
&stage_egl->surface_width); &stage_egl->surface_width);
eglQuerySurface (clutter_egl_display(), eglQuerySurface (backend_egl->edpy,
stage_egl->egl_surface, stage_egl->egl_surface,
EGL_HEIGHT, EGL_HEIGHT,
&stage_egl->surface_height); &stage_egl->surface_height);
if (stage_egl->egl_surface == EGL_NO_SURFACE) CLUTTER_NOTE (BACKEND, "EGL surface is %ix%i",
g_warning ("eglCreateWindowSurface"); stage_egl->surface_width,
stage_egl->surface_height);
CLUTTER_NOTE (BACKEND, "surface is %ix%i", if (G_UNLIKELY (backend_egl->egl_context == None))
stage_egl->surface_width, stage_egl->surface_height); {
CLUTTER_NOTE (GL, "Creating EGL Context");
stage_egl->egl_context = eglCreateContext (clutter_egl_display(), backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
configs[0], configs[0],
EGL_NO_CONTEXT, EGL_NO_CONTEXT,
NULL); NULL);
if (stage_egl->egl_context == EGL_NO_CONTEXT) if (backend_egl->egl_context == EGL_NO_CONTEXT)
g_warning ("eglCreateContext"); {
g_critical ("Unable to create a suitable EGL context");
status = eglMakeCurrent (clutter_egl_display(), CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
stage_egl->egl_surface, return;
stage_egl->egl_surface, }
stage_egl->egl_context); }
if (status != EGL_TRUE) /* this will make sure to set the current context */
g_warning ("eglMakeCurrent"); CLUTTER_NOTE (BACKEND, "Marking stage as realized and setting context");
CLUTTER_ACTOR_SET_FLAGS (stage_egl->wrapper, CLUTTER_ACTOR_REALIZED);
CLUTTER_ACTOR_SET_FLAGS (stage_egl, CLUTTER_ACTOR_REALIZED);
clutter_stage_ensure_current (stage_egl->wrapper);
} }
else else
{ {
@ -153,13 +167,7 @@ clutter_stage_egl_realize (ClutterActor *actor)
return; return;
} }
clutter_stage_get_perspectivex (CLUTTER_STAGE (actor), &perspective); CLUTTER_SET_PRIVATE_FLAGS (stage_egl->wrapper, CLUTTER_ACTOR_SYNC_MATRICES);
cogl_setup_viewport (clutter_actor_get_width (actor),
clutter_actor_get_height (actor),
perspective.fovy,
perspective.aspect,
perspective.z_near,
perspective.z_far);
} }
static void static void
@ -184,26 +192,9 @@ clutter_stage_egl_request_coords (ClutterActor *self,
box->y1 = 0; box->y1 = 0;
box->x2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_width); box->x2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_width);
box->y2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_height); box->y2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_height);
}
static void CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->request_coords (self,
clutter_stage_egl_set_fullscreen (ClutterStage *stage, box);
gboolean fullscreen)
{
g_warning ("Stage of type `%s' do not support ClutterStage::set_fullscreen",
G_OBJECT_TYPE_NAME (stage));
}
static GdkPixbuf*
clutter_stage_egl_draw_to_pixbuf (ClutterStage *stage,
gint x,
gint y,
gint width,
gint height)
{
g_warning ("Stage of type `%s' do not support ClutterStage::draw_to_pixbuf",
G_OBJECT_TYPE_NAME (stage));
return NULL;
} }
static void static void
@ -231,14 +222,23 @@ clutter_stage_egl_class_init (ClutterStageEGLClass *klass)
actor_class->unrealize = clutter_stage_egl_unrealize; actor_class->unrealize = clutter_stage_egl_unrealize;
actor_class->request_coords = clutter_stage_egl_request_coords; actor_class->request_coords = clutter_stage_egl_request_coords;
actor_class->query_coords = clutter_stage_egl_query_coords; actor_class->query_coords = clutter_stage_egl_query_coords;
stage_class->set_fullscreen = clutter_stage_egl_set_fullscreen; }
stage_class->draw_to_pixbuf = clutter_stage_egl_draw_to_pixbuf;
static void
clutter_stage_egl_set_fullscreen (ClutterStageWindow *stage_window,
gboolean fullscreen)
{
g_warning ("Stage of type `%s' do not support ClutterStage::set_fullscreen",
G_OBJECT_TYPE_NAME (stage_window));
}
static void
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
{
iface->set_fullscreen = clutter_stage_egl_set_fullscreen;
} }
static void static void
clutter_stage_egl_init (ClutterStageEGL *stage) clutter_stage_egl_init (ClutterStageEGL *stage)
{ {
;
} }

View File

@ -18,19 +18,21 @@ typedef struct _ClutterStageEGLClass ClutterStageEGLClass;
struct _ClutterStageEGL struct _ClutterStageEGL
{ {
ClutterStage parent_instance; ClutterActor parent_instance;
/* from the backend */ /* from the backend */
gint surface_width; gint surface_width;
gint surface_height; gint surface_height;
EGLSurface egl_surface; EGLSurface egl_surface;
EGLContext egl_context;
/* the stage wrapper */
ClutterStage *wrapper;
}; };
struct _ClutterStageEGLClass struct _ClutterStageEGLClass
{ {
ClutterStageClass parent_class; ClutterActorClass parent_class;
}; };
GType clutter_stage_egl_get_type (void) G_GNUC_CONST; GType clutter_stage_egl_get_type (void) G_GNUC_CONST;

View File

@ -281,7 +281,11 @@ clutter_backend_egl_class_init (ClutterBackendEGLClass *klass)
static void static void
clutter_backend_egl_init (ClutterBackendEGL *backend_egl) clutter_backend_egl_init (ClutterBackendEGL *backend_egl)
{ {
ClutterBackend *backend = CLUTTER_BACKEND (backend_egl);
clutter_backend_set_resolution (backend, 96.0);
clutter_backend_set_double_click_time (backend, 250);
clutter_backend_set_double_click_distance (backend, 5);
} }
GType GType