~ubuntu-branches/ubuntu/precise/clutter-1.0/precise

« back to all changes in this revision

Viewing changes to clutter/sdl/clutter-backend-sdl.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef HAVE_CONFIG_H
2
 
#include "config.h"
3
 
#endif
4
 
 
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"
10
 
 
11
 
static ClutterBackendSDL *backend_singleton = NULL;
12
 
 
13
 
 
14
 
G_DEFINE_TYPE (ClutterBackendSDL, clutter_backend_sdl, CLUTTER_TYPE_BACKEND);
15
 
 
16
 
static gboolean
17
 
clutter_backend_sdl_pre_parse (ClutterBackend  *backend,
18
 
                               GError         **error)
19
 
{
20
 
  return TRUE;
21
 
}
22
 
 
23
 
static gboolean
24
 
clutter_backend_sdl_post_parse (ClutterBackend  *backend,
25
 
                                GError         **error)
26
 
{
27
 
  int err;
28
 
 
29
 
  if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
30
 
    {
31
 
      g_set_error (error, CLUTTER_INIT_ERROR,
32
 
                   CLUTTER_INIT_ERROR_BACKEND,
33
 
                   "Unable to Initialize SDL");
34
 
      return FALSE;
35
 
    }
36
 
 
37
 
#if defined(WIN32)
38
 
  err = SDL_GL_LoadLibrary ("opengl32.dll");
39
 
#elif defined(__linux__) || defined(__FreeBSD__)
40
 
  err = SDL_GL_LoadLibrary ("libGL.so");
41
 
#else
42
 
#error Your platform is not supported
43
 
  err = 1;
44
 
#endif
45
 
 
46
 
  if (err != 0)
47
 
    {
48
 
      g_set_error (error, CLUTTER_INIT_ERROR,
49
 
                   CLUTTER_INIT_ERROR_BACKEND,
50
 
                   "%s", SDL_GetError ());
51
 
      return FALSE;
52
 
    }
53
 
 
54
 
  CLUTTER_NOTE (BACKEND, "SDL successfully initialized");
55
 
 
56
 
  return TRUE;
57
 
}
58
 
 
59
 
static void
60
 
clutter_backend_sdl_ensure_context (ClutterBackend *backend,
61
 
                                    ClutterStage   *stage)
62
 
{
63
 
  /* no context to ensure */
64
 
}
65
 
 
66
 
static void
67
 
clutter_backend_sdl_redraw (ClutterBackend *backend,
68
 
                            ClutterStage   *stage)
69
 
{
70
 
  clutter_actor_paint (CLUTTER_ACTOR (stage));
71
 
  cogl_flush ();
72
 
 
73
 
  SDL_GL_SwapBuffers();
74
 
}
75
 
 
76
 
static ClutterActor *
77
 
clutter_backend_sdl_create_stage (ClutterBackend  *backend,
78
 
                                  ClutterStage    *wrapper,
79
 
                                  GError         **error)
80
 
{
81
 
  ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (backend);
82
 
  ClutterStageSDL *stage_sdl;
83
 
  ClutterActor *stage;
84
 
 
85
 
  if (backend_sdl->stage)
86
 
    {
87
 
      g_warning ("The SDL backend does not support multiple stages");
88
 
      return CLUTTER_ACTOR (backend_sdl->stage);
89
 
    }
90
 
 
91
 
  stage = g_object_new (CLUTTER_TYPE_STAGE_SDL, NULL);
92
 
 
93
 
  /* copy backend data into the stage */
94
 
  stage_sdl = CLUTTER_STAGE_SDL (stage);
95
 
  stage_sdl->wrapper = wrapper;
96
 
 
97
 
  backend_sdl->stage = stage_sdl;
98
 
 
99
 
  return stage;
100
 
}
101
 
 
102
 
static void
103
 
clutter_backend_sdl_init_events (ClutterBackend *backend)
104
 
{
105
 
  _clutter_events_init (backend);
106
 
}
107
 
 
108
 
static void
109
 
clutter_backend_sdl_finalize (GObject *gobject)
110
 
{
111
 
  SDL_Quit();
112
 
 
113
 
  if (backend_singleton)
114
 
    backend_singleton = NULL;
115
 
 
116
 
  G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->finalize (gobject);
117
 
}
118
 
 
119
 
static void
120
 
clutter_backend_sdl_dispose (GObject *gobject)
121
 
{
122
 
  ClutterBackendSDL *backend_sdl = CLUTTER_BACKEND_SDL (gobject);
123
 
 
124
 
  _clutter_events_uninit (CLUTTER_BACKEND (backend_sdl));
125
 
 
126
 
  if (backend_sdl->stage)
127
 
    {
128
 
      clutter_actor_destroy (CLUTTER_ACTOR (backend_sdl->stage));
129
 
      backend_sdl->stage = NULL;
130
 
    }
131
 
 
132
 
  if (backend_sdl->timer)
133
 
    {
134
 
      g_timer_destroy (backend_sdl->timer);
135
 
      backend_sdl->timer = NULL;
136
 
    }
137
 
 
138
 
  G_OBJECT_CLASS (clutter_backend_sdl_parent_class)->dispose (gobject);
139
 
}
140
 
 
141
 
static GObject *
142
 
clutter_backend_sdl_constructor (GType                  gtype,
143
 
                                 guint                  n_params,
144
 
                                 GObjectConstructParam *params)
145
 
{
146
 
  GObjectClass *parent_class;
147
 
  GObject *retval;
148
 
 
149
 
  if (!backend_singleton)
150
 
    {
151
 
      parent_class = G_OBJECT_CLASS (clutter_backend_sdl_parent_class);
152
 
      retval = parent_class->constructor (gtype, n_params, params);
153
 
 
154
 
      backend_singleton = CLUTTER_BACKEND_SDL (retval);
155
 
 
156
 
      return retval;
157
 
    }
158
 
 
159
 
  g_warning ("Attempting to create a new backend object. This should "
160
 
             "never happen, so we return the singleton instance.");
161
 
  
162
 
  return g_object_ref (backend_singleton);
163
 
}
164
 
 
165
 
static ClutterFeatureFlags
166
 
clutter_backend_sdl_get_features (ClutterBackend *backend)
167
 
{
168
 
  return CLUTTER_FEATURE_STAGE_CURSOR;
169
 
}
170
 
 
171
 
static void
172
 
clutter_backend_sdl_class_init (ClutterBackendSDLClass *klass)
173
 
{
174
 
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
175
 
  ClutterBackendClass *backend_class = CLUTTER_BACKEND_CLASS (klass);
176
 
 
177
 
  gobject_class->constructor = clutter_backend_sdl_constructor;
178
 
  gobject_class->dispose = clutter_backend_sdl_dispose;
179
 
  gobject_class->finalize = clutter_backend_sdl_finalize;
180
 
 
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;
188
 
}
189
 
 
190
 
static void
191
 
clutter_backend_sdl_init (ClutterBackendSDL *backend_sdl)
192
 
{
193
 
  ClutterBackend *backend = CLUTTER_BACKEND (backend_sdl);
194
 
 
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);
198
 
 
199
 
  backend_sdl->timer = g_timer_new ();
200
 
}
201
 
 
202
 
GType
203
 
_clutter_backend_impl_get_type (void)
204
 
{
205
 
  return clutter_backend_sdl_get_type ();
206
 
}
207