5
#include "clutter-backend-sdl.h"
6
#include "clutter-stage-sdl.h"
7
#include "../clutter-private.h"
8
#include "../clutter-main.h"
9
#include "../clutter-debug.h"
11
static ClutterBackendSDL *backend_singleton = NULL;
14
G_DEFINE_TYPE (ClutterBackendSDL, clutter_backend_sdl, CLUTTER_TYPE_BACKEND);
17
clutter_backend_sdl_pre_parse (ClutterBackend *backend,
24
clutter_backend_sdl_post_parse (ClutterBackend *backend,
29
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
31
g_set_error (error, CLUTTER_INIT_ERROR,
32
CLUTTER_INIT_ERROR_BACKEND,
33
"Unable to Initialize SDL");
38
err = SDL_GL_LoadLibrary ("opengl32.dll");
39
#elif defined(__linux__) || defined(__FreeBSD__)
40
err = SDL_GL_LoadLibrary ("libGL.so");
42
#error Your platform is not supported
48
g_set_error (error, CLUTTER_INIT_ERROR,
49
CLUTTER_INIT_ERROR_BACKEND,
50
"%s", SDL_GetError ());
54
CLUTTER_NOTE (BACKEND, "SDL successfully initialized");
60
clutter_backend_sdl_ensure_context (ClutterBackend *backend,
63
/* no context to ensure */
67
clutter_backend_sdl_redraw (ClutterBackend *backend,
70
clutter_actor_paint (CLUTTER_ACTOR (stage));
77
clutter_backend_sdl_create_stage (ClutterBackend *backend,
78
ClutterStage *wrapper,
81
ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend);
82
ClutterStageSDL *stage_sdl;
85
if (backend_sdl->stage)
87
g_warning ("The SDL backend does not support multiple stages");
88
return CLUTTER_ACTOR (backend_sdl->stage);
91
stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL);
93
/* copy backend data into the stage */
94
stage_sdl = CLUTTER_STAGE_SDL (stage);
95
stage_sdl->wrapper = wrapper;
97
backend_sdl->stage = stage_sdl;
103
clutter_backend_sdl_init_events (ClutterBackend *backend)
105
_clutter_events_init (backend);
109
clutter_backend_sdl_finalize (GObject *gobject)
113
if (backend_singleton)
114
backend_singleton = NULL;
116
G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->finalize (gobject);
120
clutter_backend_sdl_dispose (GObject *gobject)
122
ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (gobject);
124
_clutter_events_uninit (CLUTTER_BACKEND (backend_sdl));
126
if (backend_sdl->stage)
128
clutter_actor_destroy (CLUTTER_ACTOR (backend_sdl->stage));
129
backend_sdl->stage = NULL;
132
if (backend_sdl->timer)
134
g_timer_destroy (backend_sdl->timer);
135
backend_sdl->timer = NULL;
138
G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->dispose (gobject);
142
clutter_backend_sdl_constructor (GType gtype,
144
GObjectConstructParam *params)
146
GObjectClass *parent_class;
149
if (!backend_singleton)
151
parent_class = G_OBJECT_CLASS (clutter_backend_sdl_parent_class);
152
retval = parent_class->constructor (gtype, n_params, params);
154
backend_singleton = CLUTTER_BACKEND_SDL (retval);
159
g_warning ("Attempting to create a new backend object. This should "
160
"never happen, so we return the singleton instance.");
162
return g_object_ref (backend_singleton);
165
static ClutterFeatureFlags
166
clutter_backend_sdl_get_features (ClutterBackend *backend)
168
return CLUTTER_FEATURE_STAGE_CURSOR;
172
clutter_backend_sdl_class_init (ClutterBackendSDLClass *klass)
174
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
175
ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
177
gobject_class->constructor = clutter_backend_sdl_constructor;
178
gobject_class->dispose = clutter_backend_sdl_dispose;
179
gobject_class->finalize = clutter_backend_sdl_finalize;
181
backend_class->pre_parse = clutter_backend_sdl_pre_parse;
182
backend_class->post_parse = clutter_backend_sdl_post_parse;
183
backend_class->init_events = clutter_backend_sdl_init_events;
184
backend_class->create_stage = clutter_backend_sdl_create_stage;
185
backend_class->ensure_context = clutter_backend_sdl_ensure_context;
186
backend_class->redraw = clutter_backend_sdl_redraw;
187
backend_class->get_features = clutter_backend_sdl_get_features;
191
clutter_backend_sdl_init (ClutterBackendSDL *backend_sdl)
193
ClutterBackend *backend = CLUTTER_BACKEND (backend_sdl);
195
clutter_backend_set_resolution (backend, 96.0);
196
clutter_backend_set_double_click_time (backend, 250);
197
clutter_backend_set_double_click_distance (backend, 5);
199
backend_sdl->timer = g_timer_new ();
203
_clutter_backend_impl_get_type (void)
205
return clutter_backend_sdl_get_type ();