From 7c3cf35eec1abdd5c6734f5c2e9932e3e3d8d16d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 25 Apr 2008 12:17:01 +0000 Subject: [PATCH] 2008-04-25 Emmanuele Bassi * clutter/sdl/clutter-stage-sdl.[ch]: Port the SDL stage to the new stage implementation API. * clutter/sdl/clutter-backend-sdl.[ch]: Port the SDL backend to the new backend API. * clutter/sdl/clutter-event-sdl.c: (clutter_event_dispatch): Assign the default stage as the origin of the event. --- ChangeLog | 12 +++ clutter/sdl/clutter-backend-sdl.c | 122 ++++++++++++++---------------- clutter/sdl/clutter-backend-sdl.h | 5 +- clutter/sdl/clutter-event-sdl.c | 6 +- clutter/sdl/clutter-stage-sdl.c | 108 ++++++++++++++++---------- clutter/sdl/clutter-stage-sdl.h | 6 +- 6 files changed, 148 insertions(+), 111 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47de40a60..111cef009 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-04-25 Emmanuele Bassi + + * clutter/sdl/clutter-stage-sdl.[ch]: Port the SDL stage to + the new stage implementation API. + + * clutter/sdl/clutter-backend-sdl.[ch]: Port the SDL backend + to the new backend API. + + * clutter/sdl/clutter-event-sdl.c: + (clutter_event_dispatch): Assign the default stage as the + origin of the event. + 2008-04-24 Emmanuele Bassi * configure.ac: Add the --with-json configure switch to diff --git a/clutter/sdl/clutter-backend-sdl.c b/clutter/sdl/clutter-backend-sdl.c index f06256803..edacba060 100644 --- a/clutter/sdl/clutter-backend-sdl.c +++ b/clutter/sdl/clutter-backend-sdl.c @@ -24,9 +24,9 @@ static gboolean clutter_backend_sdl_post_parse (ClutterBackend *backend, GError **error) { - int err; + int err; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) + if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, @@ -35,97 +35,94 @@ clutter_backend_sdl_post_parse (ClutterBackend *backend, } #if defined(WIN32) - err = SDL_GL_LoadLibrary("opengl32.dll"); + err = SDL_GL_LoadLibrary ("opengl32.dll"); #elif defined(__linux__) || defined(__FreeBSD__) - err = SDL_GL_LoadLibrary("libGL.so"); + err = SDL_GL_LoadLibrary ("libGL.so"); #else #error Your platform is not supported err = 1; #endif + if (err != 0) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, - SDL_GetError()); + SDL_GetError ()); return FALSE; } + CLUTTER_NOTE (BACKEND, "SDL successfully initialized"); + return TRUE; } -static gboolean -clutter_backend_sdl_init_stage (ClutterBackend *backend, - GError **error) +static void +clutter_backend_sdl_ensure_context (ClutterBackend *backend, + ClutterStage *stage) +{ + /* no context to ensure */ +} + +static void +clutter_backend_sdl_redraw (ClutterBackend *backend, + ClutterStage *stage) +{ + clutter_actor_paint (CLUTTER_ACTOR (stage)); + + SDL_GL_SwapBuffers(); +} + +static ClutterActor * +clutter_backend_sdl_create_stage (ClutterBackend *backend, + ClutterStage *wrapper, + GError **error) { ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend); + ClutterStageSDL *stage_sdl; + ClutterActor *stage; - if (!backend_sdl->stage) + if (backend_sdl->stage) { - ClutterStageSDL *stage_sdl; - ClutterActor *stage; - - stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL); - - /* copy backend data into the stage */ - stage_sdl = CLUTTER_STAGE_SDL (stage); - - g_object_set_data (G_OBJECT (stage), "clutter-backend", backend); - - backend_sdl->stage = g_object_ref_sink (stage); + g_warning ("The SDL backend does not support multiple stages"); + return CLUTTER_ACTOR (backend_sdl->stage); } - clutter_actor_realize (backend_sdl->stage); + stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL); - if (!CLUTTER_ACTOR_IS_REALIZED (backend_sdl->stage)) + /* copy backend data into the stage */ + stage_sdl = CLUTTER_STAGE_SDL (stage); + stage_sdl->wrapper = wrapper; + + _clutter_stage_set_window (wrapper, CLUTTER_STAGE_WINDOW (stage)); + + g_object_set_data (G_OBJECT (stage), "clutter-backend", backend); + + clutter_actor_realize (stage); + + if (!CLUTTER_ACTOR_IS_REALIZED (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_sdl->stage = stage_sdl; + + return stage; } static void clutter_backend_sdl_init_events (ClutterBackend *backend) { _clutter_events_init (backend); - } -static const GOptionEntry entries[] = -{ - { NULL } -}; - - static void clutter_backend_sdl_add_options (ClutterBackend *backend, GOptionGroup *group) { - g_option_group_add_entries (group, entries); -} - -static ClutterActor * -clutter_backend_sdl_get_stage (ClutterBackend *backend) -{ - ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend); - - return backend_sdl->stage; -} - -static void -clutter_backend_sdl_redraw (ClutterBackend *backend) -{ - ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend); - ClutterStageSDL *stage_sdl; - - stage_sdl = CLUTTER_STAGE_SDL(backend_sdl->stage); - - clutter_actor_paint (CLUTTER_ACTOR(stage_sdl)); - - SDL_GL_SwapBuffers(); } static void @@ -148,9 +145,7 @@ clutter_backend_sdl_dispose (GObject *gobject) if (backend_sdl->stage) { - CLUTTER_UNSET_PRIVATE_FLAGS (backend_sdl->stage, - CLUTTER_ACTOR_IS_TOPLEVEL); - clutter_actor_destroy (backend_sdl->stage); + clutter_actor_destroy (CLUTTER_ACTOR (backend_sdl->stage)); backend_sdl->stage = NULL; } @@ -197,14 +192,13 @@ clutter_backend_sdl_class_init (ClutterBackendSDLClass *klass) gobject_class->dispose = clutter_backend_sdl_dispose; gobject_class->finalize = clutter_backend_sdl_finalize; - backend_class->pre_parse = clutter_backend_sdl_pre_parse; - backend_class->post_parse = clutter_backend_sdl_post_parse; - backend_class->init_stage = clutter_backend_sdl_init_stage; - backend_class->init_events = clutter_backend_sdl_init_events; - backend_class->get_stage = clutter_backend_sdl_get_stage; - backend_class->add_options = clutter_backend_sdl_add_options; - backend_class->redraw = clutter_backend_sdl_redraw; - backend_class->get_features = clutter_backend_sdl_get_features; + backend_class->pre_parse = clutter_backend_sdl_pre_parse; + backend_class->post_parse = clutter_backend_sdl_post_parse; + backend_class->init_events = clutter_backend_sdl_init_events; + backend_class->create_stage = clutter_backend_sdl_create_stage; + backend_class->ensure_context = clutter_backend_sdl_ensure_context; + backend_class->redraw = clutter_backend_sdl_redraw; + backend_class->get_features = clutter_backend_sdl_get_features; } static void diff --git a/clutter/sdl/clutter-backend-sdl.h b/clutter/sdl/clutter-backend-sdl.h index 49b0e12e9..a76cc4100 100644 --- a/clutter/sdl/clutter-backend-sdl.h +++ b/clutter/sdl/clutter-backend-sdl.h @@ -22,9 +22,10 @@ #ifndef __CLUTTER_BACKEND_SDL_H__ #define __CLUTTER_BACKEND_SDL_H__ +#include #include #include -#include +#include "clutter-stage-sdl.h" G_BEGIN_DECLS @@ -43,7 +44,7 @@ struct _ClutterBackendSDL ClutterBackend parent_instance; /* main stage singleton */ - ClutterActor *stage; + ClutterStageSDL *stage; /* event source */ GSource *event_source; diff --git a/clutter/sdl/clutter-event-sdl.c b/clutter/sdl/clutter-event-sdl.c index 7605e758f..b3edfa32a 100644 --- a/clutter/sdl/clutter-event-sdl.c +++ b/clutter/sdl/clutter-event-sdl.c @@ -327,15 +327,15 @@ clutter_event_dispatch (GSource *source, { event = clutter_event_new (CLUTTER_NOTHING); + event->any.stage = clutter_stage_get_default (); + if (event_translate (backend, event, &sdl_event)) { /* push directly here to avoid copy of queue_put */ g_queue_push_head (clutter_context->events_queue, event); } else - { - clutter_event_free (event); - } + clutter_event_free (event); } } diff --git a/clutter/sdl/clutter-stage-sdl.c b/clutter/sdl/clutter-stage-sdl.c index 48a94964e..5d867d867 100644 --- a/clutter/sdl/clutter-stage-sdl.c +++ b/clutter/sdl/clutter-stage-sdl.c @@ -14,10 +14,17 @@ #include "../clutter-private.h" #include "../clutter-debug.h" #include "../clutter-units.h" +#include "../clutter-stage-window.h" #include "cogl.h" -G_DEFINE_TYPE (ClutterStageSDL, clutter_stage_sdl, CLUTTER_TYPE_STAGE); +static void clutter_stage_window_iface_init (ClutterStageWindowIface *iface); + +G_DEFINE_TYPE_WITH_CODE (ClutterStageSDL, + clutter_stage_sdl, + CLUTTER_TYPE_ACTOR, + G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_STAGE_WINDOW, + clutter_stage_window_iface_init)); static void clutter_stage_sdl_show (ClutterActor *actor) @@ -46,45 +53,58 @@ static void clutter_stage_sdl_realize (ClutterActor *actor) { ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (actor); - gboolean is_offscreen, is_fullscreen; - ClutterPerspective perspective; CLUTTER_NOTE (BACKEND, "Realizing main stage"); - g_object_get (actor, "offscreen", &is_offscreen, NULL); - g_object_get (actor, "fullscreen", &is_fullscreen, NULL); + is_offscreen = is_fullscreen = FALSE; + g_object_get (stage_sdl->wrapper, + "offscreen", &is_offscreen, + "fullscreen", &is_fullscreen, + NULL); if (G_LIKELY (!is_offscreen)) { gint flags = SDL_OPENGL; - if (is_fullscreen) flags |= SDL_FULLSCREEN; + if (is_fullscreen) + flags |= SDL_FULLSCREEN; - SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0); + SDL_GL_SetAttribute (SDL_GL_ACCUM_RED_SIZE, 0); + SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); + SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); + SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); - if (SDL_SetVideoMode(stage_sdl->win_width, - stage_sdl->win_height, - 0, flags) == NULL) + if (SDL_SetVideoMode (stage_sdl->win_width, + stage_sdl->win_height, + 0, flags) == NULL) { CLUTTER_NOTE (BACKEND, "SDL appears not to handle this mode - %s", SDL_GetError()); - CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED); + + CLUTTER_ACTOR_UNSET_FLAGS (stage_sdl, CLUTTER_ACTOR_REALIZED); + CLUTTER_ACTOR_UNSET_FLAGS (stage_sdl->wrapper, + CLUTTER_ACTOR_REALIZED); return; } + else + { + CLUTTER_ACTOR_SET_FLAGS (stage_sdl, CLUTTER_ACTOR_REALIZED); + CLUTTER_ACTOR_SET_FLAGS (stage_sdl->wrapper, CLUTTER_ACTOR_REALIZED); + clutter_stage_ensure_current (stage_sdl->wrapper); + } } else { /* FIXME */ g_warning("SDL Backend does not yet support offscreen rendering\n"); + CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED); return; } - CLUTTER_SET_PRIVATE_FLAGS(actor, CLUTTER_ACTOR_SYNC_MATRICES); + CLUTTER_NOTE (BACKEND, "SDL stage realized"); + CLUTTER_SET_PRIVATE_FLAGS (stage_sdl->wrapper, CLUTTER_ACTOR_SYNC_MATRICES); } static void @@ -126,18 +146,22 @@ clutter_stage_sdl_request_coords (ClutterActor *self, stage_sdl->win_width = new_width; stage_sdl->win_height = new_height; - CLUTTER_SET_PRIVATE_FLAGS(self, CLUTTER_ACTOR_SYNC_MATRICES); + CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_ACTOR_SYNC_MATRICES); } + + CLUTTER_ACTOR_CLASS (clutter_stage_sdl_parent_class)->request_coords (self, + box); } static void -clutter_stage_sdl_set_fullscreen (ClutterStage *stage, - gboolean fullscreen) +clutter_stage_sdl_set_fullscreen (ClutterStageWindow *stage_window, + gboolean fullscreen) { - ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage); + ClutterStageSDL *stage_sdl = CLUTTER_STAGE_SDL (stage_window); int flags = SDL_OPENGL; - if (fullscreen) flags |= SDL_FULLSCREEN; + if (fullscreen) + flags |= SDL_FULLSCREEN; SDL_SetVideoMode(stage_sdl->win_width, stage_sdl->win_height, @@ -145,28 +169,29 @@ clutter_stage_sdl_set_fullscreen (ClutterStage *stage, } static void -clutter_stage_sdl_set_cursor_visible (ClutterStage *stage, - gboolean show_cursor) +clutter_stage_sdl_set_cursor_visible (ClutterStageWindow *stage_window, + gboolean show_cursor) { - SDL_ShowCursor(show_cursor); + SDL_ShowCursor (show_cursor); } -static GdkPixbuf* -clutter_stage_sdl_draw_to_pixbuf (ClutterStage *stage, - GdkPixbuf *dest, - gint x, - gint y, - gint width, - gint height) +static GdkPixbuf * +clutter_stage_sdl_draw_to_pixbuf (ClutterStageWindow *stage_window, + GdkPixbuf *dest, + 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)); + g_warning ("Stage of type `%s' do not support " + "ClutterStageWindow::draw_to_pixbuf", + G_OBJECT_TYPE_NAME (stage_window)); return NULL; } static void -clutter_stage_sdl_set_title (ClutterStage *stage, - const gchar *title) +clutter_stage_sdl_set_title (ClutterStageWindow *stage_window, + const gchar *title) { SDL_WM_SetCaption (title, NULL); } @@ -186,7 +211,6 @@ clutter_stage_sdl_class_init (ClutterStageSDLClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - ClutterStageClass *stage_class = CLUTTER_STAGE_CLASS (klass); gobject_class->dispose = clutter_stage_sdl_dispose; @@ -196,11 +220,15 @@ clutter_stage_sdl_class_init (ClutterStageSDLClass *klass) actor_class->unrealize = clutter_stage_sdl_unrealize; actor_class->request_coords = clutter_stage_sdl_request_coords; actor_class->query_coords = clutter_stage_sdl_query_coords; - - stage_class->set_fullscreen = clutter_stage_sdl_set_fullscreen; - stage_class->set_cursor_visible = clutter_stage_sdl_set_cursor_visible; - stage_class->draw_to_pixbuf = clutter_stage_sdl_draw_to_pixbuf; - stage_class->set_title = clutter_stage_sdl_set_title; +} + +static void +clutter_stage_window_iface_init (ClutterStageWindowIface *iface) +{ + iface->set_fullscreen = clutter_stage_sdl_set_fullscreen; + iface->set_cursor_visible = clutter_stage_sdl_set_cursor_visible; + iface->set_title = clutter_stage_sdl_set_title; + iface->draw_to_pixbuf = clutter_stage_sdl_draw_to_pixbuf; } static void diff --git a/clutter/sdl/clutter-stage-sdl.h b/clutter/sdl/clutter-stage-sdl.h index 94fda29a7..d986e1b59 100644 --- a/clutter/sdl/clutter-stage-sdl.h +++ b/clutter/sdl/clutter-stage-sdl.h @@ -16,15 +16,17 @@ typedef struct _ClutterStageSDLClass ClutterStageSDLClass; struct _ClutterStageSDL { - ClutterStage parent_instance; + ClutterActor parent_instance; gint win_width; gint win_height; + + ClutterStage *wrapper; }; struct _ClutterStageSDLClass { - ClutterStageClass parent_class; + ClutterActorClass parent_class; }; GType clutter_stage_sdl_get_type (void) G_GNUC_CONST;