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

* 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.
This commit is contained in:
Emmanuele Bassi 2008-04-25 12:17:01 +00:00
parent 76735c0374
commit 7c3cf35eec
6 changed files with 148 additions and 111 deletions

View File

@ -1,3 +1,15 @@
2008-04-25 Emmanuele Bassi <ebassi@openedhand.com>
* 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 <ebassi@openedhand.com>
* configure.ac: Add the --with-json configure switch to

View File

@ -42,6 +42,7 @@ clutter_backend_sdl_post_parse (ClutterBackend *backend,
#error Your platform is not supported
err = 1;
#endif
if (err != 0)
{
g_set_error (error, CLUTTER_INIT_ERROR,
@ -50,82 +51,78 @@ clutter_backend_sdl_post_parse (ClutterBackend *backend,
return FALSE;
}
CLUTTER_NOTE (BACKEND, "SDL successfully initialized");
return TRUE;
}
static gboolean
clutter_backend_sdl_init_stage (ClutterBackend *backend,
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);
if (!backend_sdl->stage)
{
ClutterStageSDL *stage_sdl;
ClutterActor *stage;
if (backend_sdl->stage)
{
g_warning ("The SDL backend does not support multiple stages");
return CLUTTER_ACTOR (backend_sdl->stage);
}
stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL);
/* 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);
backend_sdl->stage = g_object_ref_sink (stage);
}
clutter_actor_realize (stage);
clutter_actor_realize (backend_sdl->stage);
if (!CLUTTER_ACTOR_IS_REALIZED (backend_sdl->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;
}
@ -199,10 +194,9 @@ clutter_backend_sdl_class_init (ClutterBackendSDLClass *klass)
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->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;
}

View File

@ -22,9 +22,10 @@
#ifndef __CLUTTER_BACKEND_SDL_H__
#define __CLUTTER_BACKEND_SDL_H__
#include <SDL.h>
#include <glib-object.h>
#include <clutter/clutter-backend.h>
#include <SDL.h>
#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;

View File

@ -327,17 +327,17 @@ 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);
}
}
}
event = clutter_event_get ();

View File

@ -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,20 +53,22 @@ 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);
@ -72,19 +81,30 @@ clutter_stage_sdl_realize (ClutterActor *actor)
{
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
@ -128,16 +148,20 @@ clutter_stage_sdl_request_coords (ClutterActor *self,
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,
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,27 +169,28 @@ clutter_stage_sdl_set_fullscreen (ClutterStage *stage,
}
static void
clutter_stage_sdl_set_cursor_visible (ClutterStage *stage,
clutter_stage_sdl_set_cursor_visible (ClutterStageWindow *stage_window,
gboolean show_cursor)
{
SDL_ShowCursor (show_cursor);
}
static GdkPixbuf *
clutter_stage_sdl_draw_to_pixbuf (ClutterStage *stage,
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,
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

View File

@ -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;