64
55
stage_egl->egl_surface = EGL_NO_SURFACE;
67
XSync (stage_x11->xdpy, False);
58
XSync (backend_x11->xdpy, False);
69
60
clutter_x11_untrap_x_errors ();
75
clutter_stage_egl_realize (ClutterActor *actor)
64
_clutter_stage_egl_try_realize (ClutterStageWindow *stage_window, int *retry_cookie)
77
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (actor);
78
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (actor);
66
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (stage_window);
67
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
68
ClutterBackend *backend;
79
69
ClutterBackendEGL *backend_egl;
80
70
ClutterBackendX11 *backend_x11;
82
72
EGLint config_count;
84
gboolean is_offscreen = FALSE;
86
CLUTTER_NOTE (BACKEND, "Realizing main stage");
88
g_object_get (stage_x11->wrapper, "offscreen", &is_offscreen, NULL);
90
backend_egl = CLUTTER_BACKEND_EGL (clutter_get_default_backend ());
91
backend_x11 = CLUTTER_BACKEND_X11 (clutter_get_default_backend ());
93
if (G_LIKELY (!is_offscreen))
97
EGLConfig *all_configs;
99
EGLint cfg_attribs[] = {
100
EGL_BUFFER_SIZE, EGL_DONT_CARE,
76
EGLConfig *all_configs;
77
EGLint cfg_attribs[] = {
78
/* NB: This must be the first attribute, since we may
79
* try and fallback to no stencil buffer */
86
EGL_BUFFER_SIZE, EGL_DONT_CARE,
105
88
#ifdef HAVE_COGL_GLES2
106
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
89
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
107
90
#else /* HAVE_COGL_GLES2 */
108
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
91
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
109
92
#endif /* HAVE_COGL_GLES2 */
114
status = eglGetConfigs (backend_egl->edpy,
119
eglGetConfigs (clutter_eglx_display (), NULL, 0, &num_configs);
121
all_configs = g_malloc (num_configs * sizeof (EGLConfig));
122
eglGetConfigs (clutter_eglx_display (),
127
for (c = 0; c < num_configs; ++c)
129
EGLint red = -1, green = -1, blue = -1, alpha = -1, stencil = -1;
131
eglGetConfigAttrib (clutter_eglx_display (),
134
eglGetConfigAttrib (clutter_eglx_display (),
136
EGL_GREEN_SIZE, &green);
137
eglGetConfigAttrib (clutter_eglx_display (),
139
EGL_BLUE_SIZE, &blue);
140
eglGetConfigAttrib (clutter_eglx_display (),
142
EGL_ALPHA_SIZE, &alpha);
143
eglGetConfigAttrib (clutter_eglx_display (),
145
EGL_STENCIL_SIZE, &stencil);
146
CLUTTER_NOTE (BACKEND, "EGLConfig == R:%d G:%d B:%d A:%d S:%d \n",
147
red, green, blue, alpha, stencil);
150
g_free (all_configs);
152
if (status != EGL_TRUE)
154
g_critical ("eglGetConfigs failed");
158
status = eglChooseConfig (backend_egl->edpy,
161
G_N_ELEMENTS (configs),
164
if (status != EGL_TRUE)
166
g_critical ("eglChooseConfig failed");
170
if (stage_x11->xwin == None)
172
XCreateSimpleWindow (stage_x11->xdpy,
173
stage_x11->xwin_root,
175
stage_x11->xwin_width,
176
stage_x11->xwin_height,
178
WhitePixel (stage_x11->xdpy,
179
stage_x11->xscreen));
181
if (clutter_x11_has_event_retrieval ())
183
if (clutter_x11_has_xinput ())
185
XSelectInput (stage_x11->xdpy, stage_x11->xwin,
186
StructureNotifyMask |
189
EnterWindowMask | LeaveWindowMask |
192
_clutter_x11_select_events (stage_x11->xwin);
98
/* Here we can change the attributes depending on the fallback count... */
100
/* Some GLES hardware can't support a stencil buffer: */
101
if (*retry_cookie == 1)
103
g_warning ("Trying with stencil buffer disabled...");
104
cfg_attribs[1 /* EGL_STENCIL_SIZE */] = 0;
107
/* XXX: at this point we only have one fallback */
109
backend = clutter_get_default_backend ();
110
backend_egl = CLUTTER_BACKEND_EGL (backend);
111
backend_x11 = CLUTTER_BACKEND_X11 (backend);
113
edpy = clutter_eglx_display ();
115
eglGetConfigs (edpy, NULL, 0, &num_configs);
117
all_configs = g_malloc (num_configs * sizeof (EGLConfig));
118
eglGetConfigs (clutter_eglx_display (),
123
for (i = 0; i < num_configs; ++i)
125
EGLint red = -1, green = -1, blue = -1, alpha = -1, stencil = -1;
127
eglGetConfigAttrib (edpy,
130
eglGetConfigAttrib (edpy,
132
EGL_GREEN_SIZE, &green);
133
eglGetConfigAttrib (edpy,
135
EGL_BLUE_SIZE, &blue);
136
eglGetConfigAttrib (edpy,
138
EGL_ALPHA_SIZE, &alpha);
139
eglGetConfigAttrib (edpy,
141
EGL_STENCIL_SIZE, &stencil);
142
CLUTTER_NOTE (BACKEND, "EGLConfig == R:%d G:%d B:%d A:%d S:%d \n",
143
red, green, blue, alpha, stencil);
146
g_free (all_configs);
148
status = eglChooseConfig (edpy,
152
if (status != EGL_TRUE)
154
g_warning ("eglChooseConfig failed");
158
if (stage_x11->xwin == None)
160
XCreateSimpleWindow (backend_x11->xdpy,
161
backend_x11->xwin_root,
163
stage_x11->xwin_width,
164
stage_x11->xwin_height,
166
WhitePixel (backend_x11->xdpy,
167
backend_x11->xscreen_num));
169
if (clutter_x11_has_event_retrieval ())
171
if (clutter_x11_has_xinput ())
173
XSelectInput (backend_x11->xdpy, stage_x11->xwin,
174
StructureNotifyMask |
177
EnterWindowMask | LeaveWindowMask |
180
_clutter_x11_select_events (stage_x11->xwin);
196
XSelectInput (stage_x11->xdpy, stage_x11->xwin,
197
StructureNotifyMask |
201
KeyPressMask | KeyReleaseMask |
202
ButtonPressMask | ButtonReleaseMask |
203
EnterWindowMask | LeaveWindowMask |
207
/* FIXME, do these in a clutterstage_x11_realise? */
208
clutter_stage_x11_fix_window_size (stage_x11, -1, -1);
209
clutter_stage_x11_set_wm_protocols (stage_x11);
211
if (stage_egl->egl_surface != EGL_NO_SURFACE)
213
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
214
stage_egl->egl_surface = EGL_NO_SURFACE;
217
stage_egl->egl_surface =
218
eglCreateWindowSurface (backend_egl->edpy,
220
(NativeWindowType) stage_x11->xwin,
223
if (stage_egl->egl_surface == EGL_NO_SURFACE)
225
g_critical ("Unable to create an EGL surface");
229
if (G_UNLIKELY (backend_egl->egl_context == None))
184
XSelectInput (backend_x11->xdpy, stage_x11->xwin,
185
StructureNotifyMask |
189
KeyPressMask | KeyReleaseMask |
190
ButtonPressMask | ButtonReleaseMask |
191
EnterWindowMask | LeaveWindowMask |
195
clutter_stage_x11_fix_window_size (stage_x11, -1, -1);
196
clutter_stage_x11_set_wm_protocols (stage_x11);
198
if (stage_egl->egl_surface != EGL_NO_SURFACE)
200
eglDestroySurface (edpy, stage_egl->egl_surface);
201
stage_egl->egl_surface = EGL_NO_SURFACE;
204
stage_egl->egl_surface =
205
eglCreateWindowSurface (edpy,
207
(NativeWindowType) stage_x11->xwin,
210
if (stage_egl->egl_surface == EGL_NO_SURFACE)
212
g_warning ("Unable to create an EGL surface");
216
if (G_UNLIKELY (backend_egl->egl_context == None))
231
218
#ifdef HAVE_COGL_GLES2
232
static const EGLint attribs[3]
233
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
219
static const EGLint attribs[3]
220
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
235
backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
222
backend_egl->egl_context = eglCreateContext (edpy,
240
/* Seems some GLES implementations 1.x do not like attribs... */
241
backend_egl->egl_context = eglCreateContext (backend_egl->edpy,
227
/* Seems some GLES implementations 1.x do not like attribs... */
228
backend_egl->egl_context = eglCreateContext (edpy,
246
if (backend_egl->egl_context == EGL_NO_CONTEXT)
248
g_critical ("Unable to create a suitable EGL context");
251
backend_egl->egl_config = configs[0];
252
CLUTTER_NOTE (GL, "Created EGL Context");
233
if (backend_egl->egl_context == EGL_NO_CONTEXT)
235
g_warning ("Unable to create a suitable EGL context");
257
g_critical ("EGLX Backend does not support offscreen rendering");
261
/* we need to chain up to the X11 stage implementation in order to
262
* set the window state in case we set it before realizing the stage
264
CLUTTER_ACTOR_CLASS (clutter_stage_egl_parent_class)->realize (actor);
239
backend_egl->egl_config = config;
240
CLUTTER_NOTE (GL, "Created EGL Context");
268
CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REALIZED);
248
if (stage_egl->egl_surface != EGL_NO_SURFACE)
250
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
251
stage_egl->egl_surface = EGL_NO_SURFACE;
253
if (stage_x11->xwin != None)
255
XDestroyWindow (backend_x11->xdpy, stage_x11->xwin);
256
stage_x11->xwin = None;
259
/* NB: We currently only support a single fallback option */
260
if (*retry_cookie == 0)
261
*retry_cookie = 1; /* tell the caller to try again */
263
*retry_cookie = 0; /* tell caller not to try again! */
269
clutter_stage_egl_realize (ClutterStageWindow *stage_window)
271
int retry_cookie = 0;
273
CLUTTER_NOTE (BACKEND, "Realizing main stage");
277
/* _clutter_stage_egl_try_realize supports fallbacks, and the number of
278
* fallbacks already tried is tracked in the retry_cookie, so what we are
279
* doing here is re-trying until we get told there are no more fallback
281
if (_clutter_stage_egl_try_realize (stage_window, &retry_cookie))
283
gboolean ret = clutter_stage_egl_parent_iface->realize (stage_window);
285
CLUTTER_NOTE (BACKEND, "Successfully realized stage");
289
if (retry_cookie == 0)
290
return FALSE; /* we've been told not to try again! */
292
g_warning ("%s: Trying fallback", G_STRFUNC);
295
g_return_val_if_reached (FALSE);
272
299
clutter_stage_egl_dispose (GObject *gobject)
274
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (gobject);
275
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (gobject);
277
301
G_OBJECT_CLASS (clutter_stage_egl_parent_class)->dispose (gobject);
281
305
clutter_stage_window_iface_init (ClutterStageWindowIface *iface)
307
clutter_stage_egl_parent_iface = g_type_interface_peek_parent (iface);
309
iface->realize = clutter_stage_egl_realize;
310
iface->unrealize = clutter_stage_egl_unrealize;
283
312
/* the rest is inherited from ClutterStageX11 */