mirror of
https://github.com/brl/mutter.git
synced 2025-02-17 05:44:08 +00:00
update backend to use lazy context/stage creation
http://bugzilla.openedhand.com/show_bug.cgi?id=2056
This commit is contained in:
parent
07880d8b74
commit
e2a990dfd5
@ -32,7 +32,7 @@ clutter_backend_egl_post_parse (ClutterBackend *backend,
|
|||||||
EGLBoolean status;
|
EGLBoolean status;
|
||||||
|
|
||||||
backend_egl->edpy =
|
backend_egl->edpy =
|
||||||
eglGetDisplay ((NativeDisplayType) backend_x11->xdpy);
|
eglGetDisplay ((EGLNativeDisplayType) backend_x11->xdpy);
|
||||||
|
|
||||||
status = eglInitialize (backend_egl->edpy,
|
status = eglInitialize (backend_egl->edpy,
|
||||||
&backend_egl->egl_version_major,
|
&backend_egl->egl_version_major,
|
||||||
@ -57,13 +57,120 @@ clutter_backend_egl_post_parse (ClutterBackend *backend,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
clutter_backend_egl_create_context (ClutterBackend *backend,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
ClutterBackendEGL *backend_egl;
|
||||||
|
ClutterBackendX11 *backend_x11;
|
||||||
|
EGLConfig config;
|
||||||
|
EGLint config_count = 0;
|
||||||
|
EGLBoolean status;
|
||||||
|
EGLint cfg_attribs[] = {
|
||||||
|
/* NB: This must be the first attribute, since we may
|
||||||
|
* try and fallback to no stencil buffer */
|
||||||
|
EGL_STENCIL_SIZE, 8,
|
||||||
|
|
||||||
|
EGL_RED_SIZE, 5,
|
||||||
|
EGL_GREEN_SIZE, 6,
|
||||||
|
EGL_BLUE_SIZE, 5,
|
||||||
|
|
||||||
|
EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
||||||
|
|
||||||
|
#ifdef HAVE_COGL_GLES2
|
||||||
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||||
|
#else /* HAVE_COGL_GLES2 */
|
||||||
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||||
|
#endif /* HAVE_COGL_GLES2 */
|
||||||
|
|
||||||
|
EGL_NONE
|
||||||
|
};
|
||||||
|
EGLDisplay edpy;
|
||||||
|
gint retry_cookie = 0;
|
||||||
|
|
||||||
|
backend = clutter_get_default_backend ();
|
||||||
|
backend_egl = CLUTTER_BACKEND_EGL (backend);
|
||||||
|
|
||||||
|
if (backend_egl->egl_context != EGL_NO_CONTEXT)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
||||||
|
|
||||||
|
edpy = clutter_eglx_display ();
|
||||||
|
|
||||||
|
retry:
|
||||||
|
/* Here we can change the attributes depending on the fallback count... */
|
||||||
|
|
||||||
|
/* Some GLES hardware can't support a stencil buffer: */
|
||||||
|
if (retry_cookie == 1)
|
||||||
|
{
|
||||||
|
g_warning ("Trying with stencil buffer disabled...");
|
||||||
|
cfg_attribs[1 /* EGL_STENCIL_SIZE */] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX: at this point we only have one fallback */
|
||||||
|
|
||||||
|
status = eglChooseConfig (edpy,
|
||||||
|
cfg_attribs,
|
||||||
|
&config, 1,
|
||||||
|
&config_count);
|
||||||
|
if (status != EGL_TRUE || config_count == 0)
|
||||||
|
{
|
||||||
|
g_warning ("eglChooseConfig failed");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (G_UNLIKELY (backend_egl->egl_context == EGL_NO_CONTEXT))
|
||||||
|
{
|
||||||
|
#ifdef HAVE_COGL_GLES2
|
||||||
|
static const EGLint attribs[3]
|
||||||
|
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
||||||
|
|
||||||
|
backend_egl->egl_context = eglCreateContext (edpy,
|
||||||
|
config,
|
||||||
|
EGL_NO_CONTEXT,
|
||||||
|
attribs);
|
||||||
|
#else
|
||||||
|
/* Seems some GLES implementations 1.x do not like attribs... */
|
||||||
|
backend_egl->egl_context = eglCreateContext (edpy,
|
||||||
|
config,
|
||||||
|
EGL_NO_CONTEXT,
|
||||||
|
NULL);
|
||||||
|
#endif
|
||||||
|
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
||||||
|
{
|
||||||
|
g_warning ("Unable to create a suitable EGL context");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
backend_egl->egl_config = config;
|
||||||
|
CLUTTER_NOTE (GL, "Created EGL Context");
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
|
||||||
|
/* NB: We currently only support a single fallback option */
|
||||||
|
if (retry_cookie == 0)
|
||||||
|
{
|
||||||
|
retry_cookie = 1;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
||||||
ClutterStage *stage)
|
ClutterStage *stage)
|
||||||
{
|
{
|
||||||
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
||||||
|
ClutterStageWindow *impl;
|
||||||
|
|
||||||
if (stage == NULL)
|
if (stage == NULL ||
|
||||||
|
(CLUTTER_PRIVATE_FLAGS (stage) & CLUTTER_ACTOR_IN_DESTRUCTION) ||
|
||||||
|
((impl = _clutter_stage_get_window (stage)) == NULL))
|
||||||
{
|
{
|
||||||
CLUTTER_NOTE (BACKEND, "Clearing EGL context");
|
CLUTTER_NOTE (BACKEND, "Clearing EGL context");
|
||||||
eglMakeCurrent (backend_egl->edpy,
|
eglMakeCurrent (backend_egl->edpy,
|
||||||
@ -73,11 +180,9 @@ clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ClutterStageWindow *impl;
|
|
||||||
ClutterStageEGL *stage_egl;
|
ClutterStageEGL *stage_egl;
|
||||||
ClutterStageX11 *stage_x11;
|
ClutterStageX11 *stage_x11;
|
||||||
|
|
||||||
impl = _clutter_stage_get_window (stage);
|
|
||||||
g_assert (impl != NULL);
|
g_assert (impl != NULL);
|
||||||
|
|
||||||
CLUTTER_NOTE (MULTISTAGE, "Setting context for stage of type %s [%p]",
|
CLUTTER_NOTE (MULTISTAGE, "Setting context for stage of type %s [%p]",
|
||||||
@ -87,7 +192,7 @@ clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
|||||||
stage_egl = CLUTTER_STAGE_EGL (impl);
|
stage_egl = CLUTTER_STAGE_EGL (impl);
|
||||||
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
||||||
|
|
||||||
if (!backend_egl->egl_context)
|
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clutter_x11_trap_x_errors ();
|
clutter_x11_trap_x_errors ();
|
||||||
@ -107,10 +212,13 @@ clutter_backend_egl_ensure_context (ClutterBackend *backend,
|
|||||||
EGL_NO_CONTEXT);
|
EGL_NO_CONTEXT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
eglMakeCurrent (backend_egl->edpy,
|
{
|
||||||
stage_egl->egl_surface,
|
CLUTTER_NOTE (MULTISTAGE, "Setting real surface current");
|
||||||
stage_egl->egl_surface,
|
eglMakeCurrent (backend_egl->edpy,
|
||||||
backend_egl->egl_context);
|
stage_egl->egl_surface,
|
||||||
|
stage_egl->egl_surface,
|
||||||
|
backend_egl->egl_context);
|
||||||
|
}
|
||||||
|
|
||||||
if (clutter_x11_untrap_x_errors ())
|
if (clutter_x11_untrap_x_errors ())
|
||||||
g_critical ("Unable to make the stage window 0x%x the current "
|
g_critical ("Unable to make the stage window 0x%x the current "
|
||||||
@ -123,9 +231,6 @@ static void
|
|||||||
clutter_backend_egl_redraw (ClutterBackend *backend,
|
clutter_backend_egl_redraw (ClutterBackend *backend,
|
||||||
ClutterStage *stage)
|
ClutterStage *stage)
|
||||||
{
|
{
|
||||||
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
|
||||||
ClutterStageEGL *stage_egl;
|
|
||||||
ClutterStageX11 *stage_x11;
|
|
||||||
ClutterStageWindow *impl;
|
ClutterStageWindow *impl;
|
||||||
|
|
||||||
impl = _clutter_stage_get_window (stage);
|
impl = _clutter_stage_get_window (stage);
|
||||||
@ -134,26 +239,7 @@ clutter_backend_egl_redraw (ClutterBackend *backend,
|
|||||||
|
|
||||||
g_assert (CLUTTER_IS_STAGE_EGL (impl));
|
g_assert (CLUTTER_IS_STAGE_EGL (impl));
|
||||||
|
|
||||||
stage_x11 = CLUTTER_STAGE_X11 (impl);
|
clutter_stage_egl_redraw (CLUTTER_STAGE_EGL (impl), stage);
|
||||||
stage_egl = CLUTTER_STAGE_EGL (impl);
|
|
||||||
|
|
||||||
/* this will cause the stage implementation to be painted as well */
|
|
||||||
clutter_actor_paint (CLUTTER_ACTOR (stage));
|
|
||||||
cogl_flush ();
|
|
||||||
|
|
||||||
/* Why this paint is done in backend as likely GL windowing system
|
|
||||||
* specific calls, like swapping buffers.
|
|
||||||
*/
|
|
||||||
if (stage_x11->xwin)
|
|
||||||
{
|
|
||||||
/* clutter_feature_wait_for_vblank (); */
|
|
||||||
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eglWaitGL ();
|
|
||||||
CLUTTER_GLERR ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -213,6 +299,10 @@ static ClutterFeatureFlags
|
|||||||
clutter_backend_egl_get_features (ClutterBackend *backend)
|
clutter_backend_egl_get_features (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
||||||
|
ClutterFeatureFlags flags;
|
||||||
|
|
||||||
|
flags = clutter_backend_x11_get_features (backend);
|
||||||
|
flags |= CLUTTER_FEATURE_STAGE_MULTIPLE;
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Checking features\n"
|
CLUTTER_NOTE (BACKEND, "Checking features\n"
|
||||||
"GL_VENDOR: %s\n"
|
"GL_VENDOR: %s\n"
|
||||||
@ -228,8 +318,7 @@ clutter_backend_egl_get_features (ClutterBackend *backend)
|
|||||||
eglQueryString (backend_egl->edpy, EGL_VERSION),
|
eglQueryString (backend_egl->edpy, EGL_VERSION),
|
||||||
eglQueryString (backend_egl->edpy, EGL_EXTENSIONS));
|
eglQueryString (backend_egl->edpy, EGL_EXTENSIONS));
|
||||||
|
|
||||||
/* We can actually resize too */
|
return flags;
|
||||||
return CLUTTER_FEATURE_STAGE_CURSOR|CLUTTER_FEATURE_STAGE_MULTIPLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ClutterStageWindow *
|
static ClutterStageWindow *
|
||||||
@ -244,7 +333,7 @@ clutter_backend_egl_create_stage (ClutterBackend *backend,
|
|||||||
CLUTTER_NOTE (BACKEND, "Creating stage of type '%s'",
|
CLUTTER_NOTE (BACKEND, "Creating stage of type '%s'",
|
||||||
g_type_name (CLUTTER_STAGE_TYPE));
|
g_type_name (CLUTTER_STAGE_TYPE));
|
||||||
|
|
||||||
stage = g_object_new (CLUTTER_STAGE_TYPE, NULL);
|
stage = g_object_new (CLUTTER_TYPE_STAGE_EGL, NULL);
|
||||||
|
|
||||||
/* copy backend data into the stage */
|
/* copy backend data into the stage */
|
||||||
stage_x11 = CLUTTER_STAGE_X11 (stage);
|
stage_x11 = CLUTTER_STAGE_X11 (stage);
|
||||||
@ -267,6 +356,9 @@ clutter_backend_egl_get_visual_info (ClutterBackendX11 *backend_x11)
|
|||||||
XVisualInfo *visinfo = None;
|
XVisualInfo *visinfo = None;
|
||||||
int visinfos_count;
|
int visinfos_count;
|
||||||
|
|
||||||
|
if (!clutter_backend_egl_create_context (CLUTTER_BACKEND (backend_x11), NULL))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
eglGetConfigAttrib (backend_egl->edpy, backend_egl->egl_config,
|
||||||
EGL_NATIVE_VISUAL_ID, &visualid);
|
EGL_NATIVE_VISUAL_ID, &visualid);
|
||||||
|
|
||||||
@ -298,17 +390,14 @@ clutter_backend_egl_class_init (ClutterBackendEGLClass *klass)
|
|||||||
backend_class->get_features = clutter_backend_egl_get_features;
|
backend_class->get_features = clutter_backend_egl_get_features;
|
||||||
backend_class->create_stage = clutter_backend_egl_create_stage;
|
backend_class->create_stage = clutter_backend_egl_create_stage;
|
||||||
backend_class->ensure_context = clutter_backend_egl_ensure_context;
|
backend_class->ensure_context = clutter_backend_egl_ensure_context;
|
||||||
|
backend_class->create_context = clutter_backend_egl_create_context;
|
||||||
backendx11_class->get_visual_info = clutter_backend_egl_get_visual_info;
|
backendx11_class->get_visual_info = clutter_backend_egl_get_visual_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_backend_egl_init (ClutterBackendEGL *backend_egl)
|
clutter_backend_egl_init (ClutterBackendEGL *backend_egl)
|
||||||
{
|
{
|
||||||
ClutterBackend *backend = CLUTTER_BACKEND (backend_egl);
|
backend_egl->egl_context = EGL_NO_CONTEXT;
|
||||||
|
|
||||||
clutter_backend_set_resolution (backend, 96.0);
|
|
||||||
clutter_backend_set_double_click_time (backend, 250);
|
|
||||||
clutter_backend_set_double_click_distance (backend, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GType
|
GType
|
||||||
|
@ -51,9 +51,8 @@ struct _ClutterBackendEGL
|
|||||||
|
|
||||||
/* EGL Specific */
|
/* EGL Specific */
|
||||||
EGLDisplay edpy;
|
EGLDisplay edpy;
|
||||||
EGLSurface egl_surface;
|
|
||||||
EGLContext egl_context;
|
EGLContext egl_context;
|
||||||
EGLConfig egl_config;
|
EGLConfig egl_config;
|
||||||
|
|
||||||
gint egl_version_major;
|
gint egl_version_major;
|
||||||
gint egl_version_minor;
|
gint egl_version_minor;
|
||||||
|
@ -49,7 +49,7 @@ clutter_stage_egl_unrealize (ClutterStageWindow *stage_window)
|
|||||||
else
|
else
|
||||||
stage_x11->xwin = None;
|
stage_x11->xwin = None;
|
||||||
|
|
||||||
if (stage_egl->egl_surface)
|
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
||||||
{
|
{
|
||||||
eglDestroySurface (clutter_eglx_display (), stage_egl->egl_surface);
|
eglDestroySurface (clutter_eglx_display (), stage_egl->egl_surface);
|
||||||
stage_egl->egl_surface = EGL_NO_SURFACE;
|
stage_egl->egl_surface = EGL_NO_SURFACE;
|
||||||
@ -61,50 +61,16 @@ clutter_stage_egl_unrealize (ClutterStageWindow *stage_window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_clutter_stage_egl_try_realize (ClutterStageWindow *stage_window, int *retry_cookie)
|
clutter_stage_egl_realize (ClutterStageWindow *stage_window)
|
||||||
{
|
{
|
||||||
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (stage_window);
|
ClutterStageEGL *stage_egl = CLUTTER_STAGE_EGL (stage_window);
|
||||||
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
|
||||||
ClutterBackend *backend;
|
ClutterBackend *backend;
|
||||||
ClutterBackendEGL *backend_egl;
|
ClutterBackendEGL *backend_egl;
|
||||||
ClutterBackendX11 *backend_x11;
|
ClutterBackendX11 *backend_x11;
|
||||||
EGLConfig config;
|
EGLDisplay edpy;
|
||||||
EGLint config_count;
|
|
||||||
EGLBoolean status;
|
|
||||||
int i;
|
|
||||||
int num_configs;
|
|
||||||
EGLConfig *all_configs;
|
|
||||||
EGLint cfg_attribs[] = {
|
|
||||||
/* NB: This must be the first attribute, since we may
|
|
||||||
* try and fallback to no stencil buffer */
|
|
||||||
EGL_STENCIL_SIZE, 8,
|
|
||||||
|
|
||||||
EGL_RED_SIZE, 5,
|
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
||||||
EGL_GREEN_SIZE, 6,
|
|
||||||
EGL_BLUE_SIZE, 5,
|
|
||||||
|
|
||||||
EGL_BUFFER_SIZE, EGL_DONT_CARE,
|
|
||||||
|
|
||||||
#ifdef HAVE_COGL_GLES2
|
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
||||||
#else /* HAVE_COGL_GLES2 */
|
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
||||||
#endif /* HAVE_COGL_GLES2 */
|
|
||||||
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
EGLDisplay edpy;
|
|
||||||
|
|
||||||
/* Here we can change the attributes depending on the fallback count... */
|
|
||||||
|
|
||||||
/* Some GLES hardware can't support a stencil buffer: */
|
|
||||||
if (*retry_cookie == 1)
|
|
||||||
{
|
|
||||||
g_warning ("Trying with stencil buffer disabled...");
|
|
||||||
cfg_attribs[1 /* EGL_STENCIL_SIZE */] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* XXX: at this point we only have one fallback */
|
|
||||||
|
|
||||||
backend = clutter_get_default_backend ();
|
backend = clutter_get_default_backend ();
|
||||||
backend_egl = CLUTTER_BACKEND_EGL (backend);
|
backend_egl = CLUTTER_BACKEND_EGL (backend);
|
||||||
@ -112,59 +78,74 @@ _clutter_stage_egl_try_realize (ClutterStageWindow *stage_window, int *retry_coo
|
|||||||
|
|
||||||
edpy = clutter_eglx_display ();
|
edpy = clutter_eglx_display ();
|
||||||
|
|
||||||
eglGetConfigs (edpy, NULL, 0, &num_configs);
|
|
||||||
|
|
||||||
all_configs = g_malloc (num_configs * sizeof (EGLConfig));
|
|
||||||
eglGetConfigs (clutter_eglx_display (),
|
|
||||||
all_configs,
|
|
||||||
num_configs,
|
|
||||||
&num_configs);
|
|
||||||
|
|
||||||
for (i = 0; i < num_configs; ++i)
|
|
||||||
{
|
|
||||||
EGLint red = -1, green = -1, blue = -1, alpha = -1, stencil = -1;
|
|
||||||
|
|
||||||
eglGetConfigAttrib (edpy,
|
|
||||||
all_configs[i],
|
|
||||||
EGL_RED_SIZE, &red);
|
|
||||||
eglGetConfigAttrib (edpy,
|
|
||||||
all_configs[i],
|
|
||||||
EGL_GREEN_SIZE, &green);
|
|
||||||
eglGetConfigAttrib (edpy,
|
|
||||||
all_configs[i],
|
|
||||||
EGL_BLUE_SIZE, &blue);
|
|
||||||
eglGetConfigAttrib (edpy,
|
|
||||||
all_configs[i],
|
|
||||||
EGL_ALPHA_SIZE, &alpha);
|
|
||||||
eglGetConfigAttrib (edpy,
|
|
||||||
all_configs[i],
|
|
||||||
EGL_STENCIL_SIZE, &stencil);
|
|
||||||
CLUTTER_NOTE (BACKEND, "EGLConfig == R:%d G:%d B:%d A:%d S:%d \n",
|
|
||||||
red, green, blue, alpha, stencil);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (all_configs);
|
|
||||||
|
|
||||||
status = eglChooseConfig (edpy,
|
|
||||||
cfg_attribs,
|
|
||||||
&config, 1,
|
|
||||||
&config_count);
|
|
||||||
if (status != EGL_TRUE)
|
|
||||||
{
|
|
||||||
g_warning ("eglChooseConfig failed");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stage_x11->xwin == None)
|
if (stage_x11->xwin == None)
|
||||||
stage_x11->xwin =
|
{
|
||||||
XCreateSimpleWindow (backend_x11->xdpy,
|
XSetWindowAttributes xattr;
|
||||||
backend_x11->xwin_root,
|
unsigned long mask;
|
||||||
0, 0,
|
XVisualInfo *xvisinfo;
|
||||||
stage_x11->xwin_width,
|
gfloat width, height;
|
||||||
stage_x11->xwin_height,
|
|
||||||
0, 0,
|
CLUTTER_NOTE (MISC, "Creating stage X window");
|
||||||
WhitePixel (backend_x11->xdpy,
|
|
||||||
backend_x11->xscreen_num));
|
xvisinfo = clutter_backend_x11_get_visual_info (backend_x11);
|
||||||
|
if (xvisinfo == NULL)
|
||||||
|
{
|
||||||
|
g_critical ("Unable to find suitable GL visual.");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* window attributes */
|
||||||
|
xattr.background_pixel = WhitePixel (backend_x11->xdpy,
|
||||||
|
backend_x11->xscreen_num);
|
||||||
|
xattr.border_pixel = 0;
|
||||||
|
xattr.colormap = XCreateColormap (backend_x11->xdpy,
|
||||||
|
backend_x11->xwin_root,
|
||||||
|
xvisinfo->visual,
|
||||||
|
AllocNone);
|
||||||
|
mask = CWBorderPixel | CWColormap;
|
||||||
|
|
||||||
|
/* Call get_size - this will either get the geometry size (which
|
||||||
|
* before we create the window is set to 640x480), or if a size
|
||||||
|
* is set, it will get that. This lets you set a size on the
|
||||||
|
* stage before it's realized.
|
||||||
|
*/
|
||||||
|
clutter_actor_get_size (CLUTTER_ACTOR (stage_x11->wrapper),
|
||||||
|
&width,
|
||||||
|
&height);
|
||||||
|
stage_x11->xwin_width = (gint)width;
|
||||||
|
stage_x11->xwin_height = (gint)height;
|
||||||
|
|
||||||
|
stage_x11->xwin = XCreateWindow (backend_x11->xdpy,
|
||||||
|
backend_x11->xwin_root,
|
||||||
|
0, 0,
|
||||||
|
stage_x11->xwin_width,
|
||||||
|
stage_x11->xwin_height,
|
||||||
|
0,
|
||||||
|
xvisinfo->depth,
|
||||||
|
InputOutput,
|
||||||
|
xvisinfo->visual,
|
||||||
|
mask, &xattr);
|
||||||
|
|
||||||
|
CLUTTER_NOTE (BACKEND, "Stage [%p], window: 0x%x, size: %dx%d",
|
||||||
|
stage_window,
|
||||||
|
(unsigned int) stage_x11->xwin,
|
||||||
|
stage_x11->xwin_width,
|
||||||
|
stage_x11->xwin_height);
|
||||||
|
|
||||||
|
XFree (xvisinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
||||||
|
{
|
||||||
|
stage_egl->egl_surface =
|
||||||
|
eglCreateWindowSurface (edpy,
|
||||||
|
backend_egl->egl_config,
|
||||||
|
(EGLNativeWindowType) stage_x11->xwin,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
||||||
|
g_warning ("Unable to create an EGL surface");
|
||||||
|
|
||||||
if (clutter_x11_has_event_retrieval ())
|
if (clutter_x11_has_event_retrieval ())
|
||||||
{
|
{
|
||||||
@ -192,107 +173,13 @@ _clutter_stage_egl_try_realize (ClutterStageWindow *stage_window, int *retry_coo
|
|||||||
PropertyChangeMask);
|
PropertyChangeMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
clutter_stage_x11_fix_window_size (stage_x11, -1, -1);
|
/* no user resize... */
|
||||||
|
clutter_stage_x11_fix_window_size (stage_x11,
|
||||||
|
stage_x11->xwin_width,
|
||||||
|
stage_x11->xwin_height);
|
||||||
clutter_stage_x11_set_wm_protocols (stage_x11);
|
clutter_stage_x11_set_wm_protocols (stage_x11);
|
||||||
|
|
||||||
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
return clutter_stage_egl_parent_iface->realize (stage_window);
|
||||||
{
|
|
||||||
eglDestroySurface (edpy, stage_egl->egl_surface);
|
|
||||||
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
stage_egl->egl_surface =
|
|
||||||
eglCreateWindowSurface (edpy,
|
|
||||||
config,
|
|
||||||
(NativeWindowType) stage_x11->xwin,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (stage_egl->egl_surface == EGL_NO_SURFACE)
|
|
||||||
{
|
|
||||||
g_warning ("Unable to create an EGL surface");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (G_UNLIKELY (backend_egl->egl_context == None))
|
|
||||||
{
|
|
||||||
#ifdef HAVE_COGL_GLES2
|
|
||||||
static const EGLint attribs[3]
|
|
||||||
= { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
|
|
||||||
|
|
||||||
backend_egl->egl_context = eglCreateContext (edpy,
|
|
||||||
config,
|
|
||||||
EGL_NO_CONTEXT,
|
|
||||||
attribs);
|
|
||||||
#else
|
|
||||||
/* Seems some GLES implementations 1.x do not like attribs... */
|
|
||||||
backend_egl->egl_context = eglCreateContext (edpy,
|
|
||||||
config,
|
|
||||||
EGL_NO_CONTEXT,
|
|
||||||
NULL);
|
|
||||||
#endif
|
|
||||||
if (backend_egl->egl_context == EGL_NO_CONTEXT)
|
|
||||||
{
|
|
||||||
g_warning ("Unable to create a suitable EGL context");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
backend_egl->egl_config = config;
|
|
||||||
CLUTTER_NOTE (GL, "Created EGL Context");
|
|
||||||
}
|
|
||||||
|
|
||||||
*retry_cookie = 0;
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
|
|
||||||
if (stage_egl->egl_surface != EGL_NO_SURFACE)
|
|
||||||
{
|
|
||||||
eglDestroySurface (backend_egl->edpy, stage_egl->egl_surface);
|
|
||||||
stage_egl->egl_surface = EGL_NO_SURFACE;
|
|
||||||
}
|
|
||||||
if (stage_x11->xwin != None)
|
|
||||||
{
|
|
||||||
XDestroyWindow (backend_x11->xdpy, stage_x11->xwin);
|
|
||||||
stage_x11->xwin = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NB: We currently only support a single fallback option */
|
|
||||||
if (*retry_cookie == 0)
|
|
||||||
*retry_cookie = 1; /* tell the caller to try again */
|
|
||||||
else
|
|
||||||
*retry_cookie = 0; /* tell caller not to try again! */
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
clutter_stage_egl_realize (ClutterStageWindow *stage_window)
|
|
||||||
{
|
|
||||||
int retry_cookie = 0;
|
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Realizing main stage");
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* _clutter_stage_egl_try_realize supports fallbacks, and the number of
|
|
||||||
* fallbacks already tried is tracked in the retry_cookie, so what we are
|
|
||||||
* doing here is re-trying until we get told there are no more fallback
|
|
||||||
* options... */
|
|
||||||
if (_clutter_stage_egl_try_realize (stage_window, &retry_cookie))
|
|
||||||
{
|
|
||||||
gboolean ret = clutter_stage_egl_parent_iface->realize (stage_window);
|
|
||||||
if (G_LIKELY (ret))
|
|
||||||
CLUTTER_NOTE (BACKEND, "Successfully realized stage");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (retry_cookie == 0)
|
|
||||||
return FALSE; /* we've been told not to try again! */
|
|
||||||
|
|
||||||
g_warning ("%s: Trying fallback", G_STRFUNC);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_return_val_if_reached (FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -323,4 +210,29 @@ clutter_stage_egl_class_init (ClutterStageEGLClass *klass)
|
|||||||
static void
|
static void
|
||||||
clutter_stage_egl_init (ClutterStageEGL *stage)
|
clutter_stage_egl_init (ClutterStageEGL *stage)
|
||||||
{
|
{
|
||||||
|
stage->egl_surface = EGL_NO_SURFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clutter_stage_egl_redraw (ClutterStageEGL *stage_egl,
|
||||||
|
ClutterStage *stage)
|
||||||
|
{
|
||||||
|
ClutterBackend *backend = clutter_get_default_backend ();
|
||||||
|
ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
|
||||||
|
ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_egl);
|
||||||
|
ClutterStageWindow *impl;
|
||||||
|
|
||||||
|
impl = _clutter_stage_get_window (stage);
|
||||||
|
if (impl == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_assert (CLUTTER_IS_STAGE_EGL (impl));
|
||||||
|
stage_egl = CLUTTER_STAGE_EGL (impl);
|
||||||
|
|
||||||
|
eglWaitNative (EGL_CORE_NATIVE_ENGINE);
|
||||||
|
clutter_actor_paint (CLUTTER_ACTOR (stage_x11->wrapper));
|
||||||
|
cogl_flush ();
|
||||||
|
|
||||||
|
eglWaitGL ();
|
||||||
|
eglSwapBuffers (backend_egl->edpy, stage_egl->egl_surface);
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,7 @@ struct _ClutterStageEGLClass
|
|||||||
|
|
||||||
GType clutter_stage_egl_get_type (void) G_GNUC_CONST;
|
GType clutter_stage_egl_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
void clutter_stage_egl_redraw (ClutterStageEGL *stage_egl,
|
||||||
|
ClutterStage *stage);
|
||||||
|
|
||||||
#endif /* __CLUTTER_STAGE_EGL_H__ */
|
#endif /* __CLUTTER_STAGE_EGL_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user