From 6ac86b939b65f288c7ff8f34bda1bb1eafb087e9 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 23 Apr 2008 17:20:59 +0000 Subject: [PATCH] 2008-04-23 Emmanuele Bassi * 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. --- ChangeLog | 10 ++ clutter/eglnative/clutter-backend-egl.c | 161 ++++++++++++++----- clutter/eglnative/clutter-backend-egl.h | 6 +- clutter/eglnative/clutter-event-egl.c | 2 + clutter/eglnative/clutter-stage-egl.c | 198 ++++++++++++------------ clutter/eglnative/clutter-stage-egl.h | 8 +- clutter/eglx/clutter-backend-egl.c | 4 + 7 files changed, 243 insertions(+), 146 deletions(-) diff --git a/ChangeLog b/ChangeLog index 172bc61e4..714abc594 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-04-23 Emmanuele Bassi + + * 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 * tests/test-script.json: Remove the explicit "visible" diff --git a/clutter/eglnative/clutter-backend-egl.c b/clutter/eglnative/clutter-backend-egl.c index 3cc10788b..577100e67 100644 --- a/clutter/eglnative/clutter-backend-egl.c +++ b/clutter/eglnative/clutter-backend-egl.c @@ -27,11 +27,11 @@ clutter_backend_egl_post_parse (ClutterBackend *backend, ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL(backend); EGLBoolean status; - backend_egl->edpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + backend_egl->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY); - status = eglInitialize(backend_egl->edpy, - &backend_egl->egl_version_major, - &backend_egl->egl_version_minor); + status = eglInitialize (backend_egl->edpy, + &backend_egl->egl_version_major, + &backend_egl->egl_version_minor); if (status != EGL_TRUE) { @@ -48,33 +48,111 @@ clutter_backend_egl_post_parse (ClutterBackend *backend, return TRUE; } -static gboolean -clutter_backend_egl_init_stage (ClutterBackend *backend, - GError **error) +static void +clutter_backend_egl_ensure_context (ClutterBackend *backend, + ClutterStage *stage) { ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend); - if (!backend_egl->stage) + if (stage == NULL) { - ClutterActor *stage; + 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; - stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL); + impl = _clutter_stage_get_window (stage); + g_assert (impl != NULL); - g_object_set_data (G_OBJECT (stage), "clutter-backend", backend); + stage_egl = CLUTTER_STAGE_EGL (impl); - backend_egl->stage = g_object_ref_sink (stage); + 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; + + 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_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); + clutter_actor_realize (backend_egl->stage); + if (!CLUTTER_ACTOR_IS_REALIZED (backend_egl->stage)) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_INTERNAL, "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 @@ -89,23 +167,6 @@ static const GOptionEntry entries[] = { 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 * clutter_backend_egl_get_stage (ClutterBackend *backend) { @@ -130,12 +191,10 @@ clutter_backend_egl_dispose (GObject *gobject) _clutter_events_uninit (CLUTTER_BACKEND (backend_egl)); - if (backend_egl->stage) + if (backend_egl->egl_context) { - CLUTTER_UNSET_PRIVATE_FLAGS (backend_egl->stage, - CLUTTER_ACTOR_IS_TOPLEVEL); - clutter_actor_destroy (backend_egl->stage); - backend_egl->stage = NULL; + eglDestroyContext (backend_egl->edpy, backend_egl->egl_context); + backend_egl->egl_context = NULL; } if (backend_egl->edpy) @@ -174,6 +233,22 @@ clutter_backend_egl_constructor (GType gtype, static ClutterFeatureFlags 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; } @@ -187,13 +262,13 @@ clutter_backend_egl_class_init (ClutterBackendEGLClass *klass) gobject_class->dispose = clutter_backend_egl_dispose; gobject_class->finalize = clutter_backend_egl_finalize; - backend_class->pre_parse = clutter_backend_egl_pre_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->get_stage = clutter_backend_egl_get_stage; - backend_class->redraw = clutter_backend_egl_redraw; - backend_class->get_features = clutter_backend_egl_get_features; + backend_class->pre_parse = clutter_backend_egl_pre_parse; + backend_class->post_parse = clutter_backend_egl_post_parse; + backend_class->init_events = clutter_backend_egl_init_events; + 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->get_features = clutter_backend_egl_get_features; } static void diff --git a/clutter/eglnative/clutter-backend-egl.h b/clutter/eglnative/clutter-backend-egl.h index 5b0cbdc2e..806ecf339 100644 --- a/clutter/eglnative/clutter-backend-egl.h +++ b/clutter/eglnative/clutter-backend-egl.h @@ -46,7 +46,11 @@ struct _ClutterBackendEGL /* EGL Specific */ 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 */ ClutterActor *stage; diff --git a/clutter/eglnative/clutter-event-egl.c b/clutter/eglnative/clutter-event-egl.c index 7fda04a41..e09bb9385 100644 --- a/clutter/eglnative/clutter-event-egl.c +++ b/clutter/eglnative/clutter-event-egl.c @@ -215,6 +215,8 @@ clutter_event_dispatch (GSource *source, event = clutter_event_new (CLUTTER_NOTHING); + event->any.stage = clutter_stage_get_default (); + last_x = event->button.x = tsevent.x; last_y = event->button.y = tsevent.y; diff --git a/clutter/eglnative/clutter-stage-egl.c b/clutter/eglnative/clutter-stage-egl.c index 5854a1ac5..042c3a480 100644 --- a/clutter/eglnative/clutter-stage-egl.c +++ b/clutter/eglnative/clutter-stage-egl.c @@ -2,6 +2,7 @@ #include "config.h" #endif +#include "clutter-backend-egl.h" #include "clutter-stage-egl.h" #include "clutter-egl.h" @@ -14,64 +15,63 @@ #include "../clutter-private.h" #include "../clutter-debug.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 clutter_stage_egl_show (ClutterActor *actor) { - ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); - - CLUTTER_ACTOR_SET_FLAGS (stage_egl, CLUTTER_ACTOR_MAPPED); + CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->show (actor); } static void clutter_stage_egl_hide (ClutterActor *actor) { - ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); - - CLUTTER_ACTOR_UNSET_FLAGS (stage_egl, CLUTTER_ACTOR_MAPPED); + CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->hide (actor); } static void clutter_stage_egl_unrealize (ClutterActor *actor) { ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor); - gboolean was_offscreen; 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) - eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface); - stage_egl->egl_surface = NULL; + { + eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface); + stage_egl->egl_surface = EGL_NO_SURFACE; + } - if (stage_egl->egl_context) - 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; + clutter_stage_ensure_current (stage_egl->wrapper); } static void 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]; EGLint config_count; EGLBoolean status; ClutterPerspective perspective; - - gboolean is_offscreen; + gboolean is_offscreen; 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)) { @@ -84,67 +84,81 @@ clutter_stage_egl_realize (ClutterActor *actor) EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; - - status = eglGetConfigs (clutter_egl_display(), + + status = eglGetConfigs (backend_egl->edpy, configs, 2, &config_count); - + if (status != EGL_TRUE) - g_warning ("eglGetConfigs"); - - status = eglChooseConfig (clutter_egl_display(), - cfg_attribs, - configs, - sizeof configs / sizeof configs[0], + g_warning ("eglGetConfigs failed"); + + status = eglChooseConfig (backend_egl->edpy, + cfg_attribs, + configs, + G_N_ELEMENTS (configs), &config_count); if (status != EGL_TRUE) - g_warning ("eglChooseConfig"); + g_warning ("eglChooseConfig failed"); - if (stage_egl->egl_context) - eglDestroyContext (clutter_egl_display(), stage_egl->egl_context); + if (stage_egl->egl_surface != EGL_NO_SURFACE) + { + eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface); + stage_egl->egl_surface = EGL_NO_SURFACE; + } - if (stage_egl->egl_surface) - eglDestroySurface (clutter_egl_display(), stage_egl->egl_surface); + stage_egl->egl_surface = + eglCreateWindowSurface (backend_egl->edpy, + configs[0], + NULL, + NULL); - stage_egl->egl_surface - = eglCreateWindowSurface (clutter_egl_display(), - configs[0], - NULL, - NULL); + if (stage_egl->egl_surface == EGL_NO_SURFACE) + { + g_critical ("Unable to create an EGL surface"); - eglQuerySurface (clutter_egl_display(), + CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED); + return; + } + + eglQuerySurface (backend_egl->edpy, stage_egl->egl_surface, EGL_WIDTH, &stage_egl->surface_width); - eglQuerySurface (clutter_egl_display(), + eglQuerySurface (backend_egl->edpy, stage_egl->egl_surface, EGL_HEIGHT, &stage_egl->surface_height); - if (stage_egl->egl_surface == EGL_NO_SURFACE) - g_warning ("eglCreateWindowSurface"); - - CLUTTER_NOTE (BACKEND, "surface is %ix%i", - stage_egl->surface_width, stage_egl->surface_height); + CLUTTER_NOTE (BACKEND, "EGL surface is %ix%i", + stage_egl->surface_width, + stage_egl->surface_height); - stage_egl->egl_context = eglCreateContext (clutter_egl_display(), - configs[0], - EGL_NO_CONTEXT, - NULL); + if (G_UNLIKELY (backend_egl->egl_context == None)) + { + CLUTTER_NOTE (GL, "Creating EGL Context"); - if (stage_egl->egl_context == EGL_NO_CONTEXT) - g_warning ("eglCreateContext"); - - status = eglMakeCurrent (clutter_egl_display(), - stage_egl->egl_surface, - stage_egl->egl_surface, - stage_egl->egl_context); + backend_egl->egl_context = eglCreateContext (backend_egl->edpy, + configs[0], + EGL_NO_CONTEXT, + NULL); - if (status != EGL_TRUE) - g_warning ("eglMakeCurrent"); + 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; + } + } + + /* this will make sure to set the current context */ + 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 { @@ -153,18 +167,12 @@ clutter_stage_egl_realize (ClutterActor *actor) return; } - clutter_stage_get_perspectivex (CLUTTER_STAGE (actor), &perspective); - cogl_setup_viewport (clutter_actor_get_width (actor), - clutter_actor_get_height (actor), - perspective.fovy, - perspective.aspect, - perspective.z_near, - perspective.z_far); + CLUTTER_SET_PRIVATE_FLAGS (stage_egl->wrapper, CLUTTER_ACTOR_SYNC_MATRICES); } static void -clutter_stage_egl_query_coords (ClutterActor *self, - ClutterActorBox *box) +clutter_stage_egl_query_coords (ClutterActor *self, + ClutterActorBox *box) { ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (self); @@ -174,8 +182,8 @@ clutter_stage_egl_query_coords (ClutterActor *self, } static void -clutter_stage_egl_request_coords (ClutterActor *self, - ClutterActorBox *box) +clutter_stage_egl_request_coords (ClutterActor *self, + ClutterActorBox *box) { ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (self); @@ -184,26 +192,9 @@ clutter_stage_egl_request_coords (ClutterActor *self, box->y1 = 0; box->x2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_width); box->y2 = CLUTTER_UNITS_FROM_INT (stage_egl->surface_height); -} -static void -clutter_stage_egl_set_fullscreen (ClutterStage *stage, - 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; + CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->request_coords (self, + box); } static void @@ -224,21 +215,30 @@ clutter_stage_egl_class_init (ClutterStageEGLClass *klass) ClutterStageClass *stage_class = CLUTTER_STAGE_CLASS (klass); gobject_class->dispose = clutter_stage_egl_dispose; - + 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->request_coords = clutter_stage_egl_request_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 clutter_stage_egl_init (ClutterStageEGL *stage) { - ; } - - diff --git a/clutter/eglnative/clutter-stage-egl.h b/clutter/eglnative/clutter-stage-egl.h index 4b4491f34..1144c8a89 100644 --- a/clutter/eglnative/clutter-stage-egl.h +++ b/clutter/eglnative/clutter-stage-egl.h @@ -18,19 +18,21 @@ typedef struct _ClutterStageEGLClass ClutterStageEGLClass; struct _ClutterStageEGL { - ClutterStage parent_instance; + ClutterActor parent_instance; /* from the backend */ gint surface_width; gint surface_height; EGLSurface egl_surface; - EGLContext egl_context; + + /* the stage wrapper */ + ClutterStage *wrapper; }; struct _ClutterStageEGLClass { - ClutterStageClass parent_class; + ClutterActorClass parent_class; }; GType clutter_stage_egl_get_type (void) G_GNUC_CONST; diff --git a/clutter/eglx/clutter-backend-egl.c b/clutter/eglx/clutter-backend-egl.c index eb567a9df..63ef6a6ee 100644 --- a/clutter/eglx/clutter-backend-egl.c +++ b/clutter/eglx/clutter-backend-egl.c @@ -281,7 +281,11 @@ clutter_backend_egl_class_init (ClutterBackendEGLClass *klass) static void 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