egl: Allow multiple EGL platforms

The #ifdefs in cogl-winsys-egl have been changed so that they
additionally check renderer->winsys_vtable->id for the corresponding
winsys ID so that multiple EGL platforms can be enabled.

The is a stop-gap solution until we can move all of the EGL platforms
into their own winsys files with overrides of the EGL vtable. However
with this approach we can move one platform at a time which will make
it easier.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2011-12-08 17:38:19 +00:00
parent a1e1527b69
commit 93e6e2051f
3 changed files with 849 additions and 719 deletions

View File

@ -98,27 +98,23 @@ typedef struct _CoglDisplayEGL
#endif #endif
EGLContext egl_context; EGLContext egl_context;
#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT)
EGLSurface dummy_surface; EGLSurface dummy_surface;
#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
struct wl_surface *wayland_surface; struct wl_surface *wayland_surface;
struct wl_egl_window *wayland_egl_native_window; struct wl_egl_window *wayland_egl_native_window;
EGLSurface dummy_surface; #endif
#elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \ #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
CoglDisplayKMS kms_display;
#endif
#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \ defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \ defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
EGLSurface egl_surface;
#else
CoglDisplayKMS kms_display;
#endif
int egl_surface_width; int egl_surface_width;
int egl_surface_height; int egl_surface_height;
gboolean have_onscreen; gboolean have_onscreen;
#else
#error "Unknown EGL platform"
#endif #endif
EGLSurface egl_surface;
EGLConfig egl_config; EGLConfig egl_config;
gboolean found_egl_config; gboolean found_egl_config;

View File

@ -104,9 +104,8 @@ typedef struct _CoglOnscreenEGL
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
CoglOnscreenKMS kms_onscreen; CoglOnscreenKMS kms_onscreen;
#else
EGLSurface egl_surface;
#endif #endif
EGLSurface egl_surface;
} CoglOnscreenEGL; } CoglOnscreenEGL;
#ifdef EGL_KHR_image_pixmap #ifdef EGL_KHR_image_pixmap
@ -228,11 +227,13 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
CoglRendererEGL *egl_renderer = renderer->winsys; CoglRendererEGL *egl_renderer = renderer->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
if (egl_renderer->gdl_initialized) if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_GDL &&
egl_renderer->gdl_initialized)
gdl_close (); gdl_close ();
#endif #endif
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11)
_cogl_xlib_renderer_disconnect (renderer); _cogl_xlib_renderer_disconnect (renderer);
#endif #endif
@ -304,7 +305,15 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
renderer->winsys = g_slice_new0 (CoglRendererEGL); renderer->winsys = g_slice_new0 (CoglRendererEGL);
egl_renderer = renderer->winsys; egl_renderer = renderer->winsys;
switch (renderer->winsys_vtable->id)
{
default:
g_warn_if_reached ();
goto error;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
case COGL_WINSYS_ID_EGL_X11:
xlib_renderer = renderer->winsys; xlib_renderer = renderer->winsys;
if (!_cogl_xlib_renderer_connect (renderer, error)) if (!_cogl_xlib_renderer_connect (renderer, error))
@ -316,9 +325,11 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
status = eglInitialize (egl_renderer->edpy, status = eglInitialize (egl_renderer->edpy,
&egl_renderer->egl_version_major, &egl_renderer->egl_version_major,
&egl_renderer->egl_version_minor); &egl_renderer->egl_version_minor);
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
case COGL_WINSYS_ID_EGL_WAYLAND:
/* The EGL API doesn't provide for a way to explicitly select a /* The EGL API doesn't provide for a way to explicitly select a
* platform when the driver can support multiple. Mesa allows * platform when the driver can support multiple. Mesa allows
* selection using an environment variable though so that's what * selection using an environment variable though so that's what
@ -334,7 +345,8 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
* retrospectively be notified of the these objects. */ * retrospectively be notified of the these objects. */
g_assert (renderer->foreign_wayland_compositor); g_assert (renderer->foreign_wayland_compositor);
g_assert (renderer->foreign_wayland_shell); g_assert (renderer->foreign_wayland_shell);
egl_renderer->wayland_compositor = renderer->foreign_wayland_compositor; egl_renderer->wayland_compositor =
renderer->foreign_wayland_compositor;
egl_renderer->wayland_shell = renderer->foreign_wayland_shell; egl_renderer->wayland_shell = renderer->foreign_wayland_shell;
} }
else else
@ -354,9 +366,10 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
} }
/* /*
* Ensure that that we've received the messages setting up the compostor and * Ensure that that we've received the messages setting up the
* shell object. This is better than just wl_display_iterate since it will * compostor and shell object. This is better than just
* always ensure that something is available to be read * wl_display_iterate since it will always ensure that something
* is available to be read
*/ */
while (!(egl_renderer->wayland_compositor && egl_renderer->wayland_shell)) while (!(egl_renderer->wayland_compositor && egl_renderer->wayland_shell))
wl_display_roundtrip (egl_renderer->wayland_display); wl_display_roundtrip (egl_renderer->wayland_display);
@ -367,19 +380,28 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
status = eglInitialize (egl_renderer->edpy, status = eglInitialize (egl_renderer->edpy,
&egl_renderer->egl_version_major, &egl_renderer->egl_version_major,
&egl_renderer->egl_version_minor); &egl_renderer->egl_version_minor);
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
case COGL_WINSYS_ID_EGL_KMS:
if (!_cogl_winsys_kms_connect (&egl_renderer->kms_renderer, error)) if (!_cogl_winsys_kms_connect (&egl_renderer->kms_renderer, error))
goto error; goto error;
egl_renderer->edpy = egl_renderer->kms_renderer.dpy; egl_renderer->edpy = egl_renderer->kms_renderer.dpy;
status = EGL_TRUE; status = EGL_TRUE;
#else break;
#endif
case COGL_WINSYS_ID_EGL_GDL:
case COGL_WINSYS_ID_EGL_ANDROID:
case COGL_WINSYS_ID_EGL_NULL:
egl_renderer->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY); egl_renderer->edpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);
status = eglInitialize (egl_renderer->edpy, status = eglInitialize (egl_renderer->edpy,
&egl_renderer->egl_version_major, &egl_renderer->egl_version_major,
&egl_renderer->egl_version_minor); &egl_renderer->egl_version_minor);
#endif break;
}
if (status != EGL_TRUE) if (status != EGL_TRUE)
{ {
@ -390,6 +412,8 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
} }
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_GDL)
{
/* Check we can talk to the GDL library */ /* Check we can talk to the GDL library */
rc = gdl_init (NULL); rc = gdl_init (NULL);
@ -414,6 +438,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
} }
gdl_close (); gdl_close ();
}
#endif #endif
check_egl_extensions (renderer); check_egl_extensions (renderer);
@ -428,27 +453,29 @@ error:
static gboolean static gboolean
update_winsys_features (CoglContext *context, GError **error) update_winsys_features (CoglContext *context, GError **error)
{ {
CoglRenderer *renderer = context->display->renderer;
CoglDisplayEGL *egl_display = context->display->winsys; CoglDisplayEGL *egl_display = context->display->winsys;
CoglRendererEGL *egl_renderer = context->display->renderer->winsys; CoglRendererEGL *egl_renderer = renderer->winsys;
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE); _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE);
memset (context->winsys_features, 0, sizeof (context->winsys_features)); memset (context->winsys_features, 0, sizeof (context->winsys_features));
check_egl_extensions (context->display->renderer); check_egl_extensions (renderer);
if (!_cogl_context_update_features (context, error)) if (!_cogl_context_update_features (context, error))
return FALSE; return FALSE;
#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \ if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11 ||
defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_WAYLAND)
{
context->feature_flags |= COGL_FEATURE_ONSCREEN_MULTIPLE; context->feature_flags |= COGL_FEATURE_ONSCREEN_MULTIPLE;
COGL_FLAGS_SET (context->features, COGL_FLAGS_SET (context->features,
COGL_FEATURE_ID_ONSCREEN_MULTIPLE, TRUE); COGL_FEATURE_ID_ONSCREEN_MULTIPLE, TRUE);
COGL_FLAGS_SET (context->winsys_features, COGL_FLAGS_SET (context->winsys_features,
COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN, COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
TRUE); TRUE);
#endif }
if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_SWAP_REGION) if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_SWAP_REGION)
{ {
@ -517,6 +544,7 @@ egl_attributes_from_framebuffer_config (CoglDisplay *display,
gboolean needs_stencil_override, gboolean needs_stencil_override,
EGLint *attributes) EGLint *attributes)
{ {
CoglRenderer *renderer = display->renderer;
int i = 0; int i = 0;
attributes[i++] = EGL_STENCIL_SIZE; attributes[i++] = EGL_STENCIL_SIZE;
@ -537,19 +565,22 @@ egl_attributes_from_framebuffer_config (CoglDisplay *display,
/* XXX: Why does the GDL platform choose these by default? */ /* XXX: Why does the GDL platform choose these by default? */
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_GDL)
{
attributes[i++] = EGL_BIND_TO_TEXTURE_RGBA; attributes[i++] = EGL_BIND_TO_TEXTURE_RGBA;
attributes[i++] = EGL_TRUE; attributes[i++] = EGL_TRUE;
attributes[i++] = EGL_BIND_TO_TEXTURE_RGB; attributes[i++] = EGL_BIND_TO_TEXTURE_RGB;
attributes[i++] = EGL_TRUE; attributes[i++] = EGL_TRUE;
}
#endif #endif
attributes[i++] = EGL_BUFFER_SIZE; attributes[i++] = EGL_BUFFER_SIZE;
attributes[i++] = EGL_DONT_CARE; attributes[i++] = EGL_DONT_CARE;
attributes[i++] = EGL_RENDERABLE_TYPE; attributes[i++] = EGL_RENDERABLE_TYPE;
attributes[i++] = (display->renderer->driver == COGL_DRIVER_GL ? attributes[i++] = (renderer->driver == COGL_DRIVER_GL ?
EGL_OPENGL_BIT : EGL_OPENGL_BIT :
display->renderer->driver == COGL_DRIVER_GLES1 ? renderer->driver == COGL_DRIVER_GLES1 ?
EGL_OPENGL_ES_BIT : EGL_OPENGL_ES_BIT :
EGL_OPENGL_ES2_BIT); EGL_OPENGL_ES2_BIT);
@ -574,19 +605,18 @@ try_create_context (CoglDisplay *display,
gboolean with_stencil_buffer, gboolean with_stencil_buffer,
GError **error) GError **error)
{ {
CoglRenderer *renderer = display->renderer;
CoglDisplayEGL *egl_display = display->winsys; CoglDisplayEGL *egl_display = display->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
CoglXlibDisplay *xlib_display = display->winsys; CoglXlibDisplay *xlib_display = display->winsys;
CoglXlibRenderer *xlib_renderer = display->renderer->winsys; CoglXlibRenderer *xlib_renderer = renderer->winsys;
#endif #endif
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT CoglRendererEGL *egl_renderer = renderer->winsys;
CoglRendererEGL *egl_renderer = display->renderer->winsys;
EGLDisplay edpy; EGLDisplay edpy;
EGLConfig config; EGLConfig config;
EGLint config_count = 0; EGLint config_count = 0;
EGLBoolean status; EGLBoolean status;
EGLint attribs[3]; EGLint attribs[3];
#endif
EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS]; EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS];
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
XVisualInfo *xvisinfo; XVisualInfo *xvisinfo;
@ -601,10 +631,11 @@ try_create_context (CoglDisplay *display,
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context == NULL, TRUE); _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context == NULL, TRUE);
if (display->renderer->driver == COGL_DRIVER_GL) if (renderer->driver == COGL_DRIVER_GL)
eglBindAPI (EGL_OPENGL_API); eglBindAPI (EGL_OPENGL_API);
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_KMS)
{
edpy = egl_renderer->edpy; edpy = egl_renderer->edpy;
status = eglChooseConfig (edpy, status = eglChooseConfig (edpy,
@ -637,9 +668,16 @@ try_create_context (CoglDisplay *display,
error_message = "Unable to create a suitable EGL context"; error_message = "Unable to create a suitable EGL context";
goto fail; goto fail;
} }
#endif }
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
switch (renderer->winsys_vtable->id)
{
default:
g_warn_if_reached ();
goto fail;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
case COGL_WINSYS_ID_EGL_X11:
xvisinfo = get_visual_info (display, config); xvisinfo = get_visual_info (display, config);
if (xvisinfo == NULL) if (xvisinfo == NULL)
{ {
@ -689,9 +727,11 @@ try_create_context (CoglDisplay *display,
error_message = "Unable to eglMakeCurrent with dummy surface"; error_message = "Unable to eglMakeCurrent with dummy surface";
goto fail; goto fail;
} }
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
case COGL_WINSYS_ID_EGL_WAYLAND:
egl_display->wayland_surface = egl_display->wayland_surface =
wl_compositor_create_surface (egl_renderer->wayland_compositor); wl_compositor_create_surface (egl_renderer->wayland_compositor);
if (!egl_display->wayland_surface) if (!egl_display->wayland_surface)
@ -730,8 +770,11 @@ try_create_context (CoglDisplay *display,
error_message = "Unable to eglMakeCurrent with dummy surface"; error_message = "Unable to eglMakeCurrent with dummy surface";
goto fail; goto fail;
} }
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT
case COGL_WINSYS_ID_EGL_ANDROID:
{ {
EGLint format; EGLint format;
@ -783,9 +826,11 @@ try_create_context (CoglDisplay *display,
EGL_HEIGHT, EGL_HEIGHT,
&egl_display->egl_surface_height); &egl_display->egl_surface_height);
} }
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
case COGL_WINSYS_ID_EGL_GDL:
egl_display->egl_surface = egl_display->egl_surface =
eglCreateWindowSurface (edpy, eglCreateWindowSurface (edpy,
config, config,
@ -816,9 +861,11 @@ try_create_context (CoglDisplay *display,
egl_display->egl_surface, egl_display->egl_surface,
EGL_HEIGHT, EGL_HEIGHT,
&egl_display->egl_surface_height); &egl_display->egl_surface_height);
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT
case COGL_WINSYS_ID_EGL_NULL:
egl_display->egl_surface = egl_display->egl_surface =
eglCreateWindowSurface (edpy, eglCreateWindowSurface (edpy,
config, config,
@ -848,8 +895,11 @@ try_create_context (CoglDisplay *display,
egl_display->egl_surface, egl_display->egl_surface,
EGL_HEIGHT, EGL_HEIGHT,
&egl_display->egl_surface_height); &egl_display->egl_surface_height);
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
case COGL_WINSYS_ID_EGL_KMS:
if (!_cogl_winsys_kms_create_context (display->renderer, if (!_cogl_winsys_kms_create_context (display->renderer,
display, display,
error)) error))
@ -858,15 +908,13 @@ try_create_context (CoglDisplay *display,
egl_display->egl_surface_width = egl_display->kms_display.width; egl_display->egl_surface_width = egl_display->kms_display.width;
egl_display->egl_surface_height = egl_display->kms_display.height; egl_display->egl_surface_height = egl_display->kms_display.height;
egl_display->egl_context = egl_display->kms_display.egl_context; egl_display->egl_context = egl_display->kms_display.egl_context;
#else break;
#error "Unknown EGL platform"
#endif #endif
}
return TRUE; return TRUE;
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
fail: fail:
#endif
g_set_error (error, COGL_WINSYS_ERROR, g_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_CREATE_CONTEXT, COGL_WINSYS_ERROR_CREATE_CONTEXT,
"%s", error_message); "%s", error_message);
@ -876,22 +924,28 @@ fail:
static void static void
cleanup_context (CoglDisplay *display) cleanup_context (CoglDisplay *display)
{ {
CoglRenderer *renderer = display->renderer;
CoglDisplayEGL *egl_display = display->winsys; CoglDisplayEGL *egl_display = display->winsys;
CoglRendererEGL *egl_renderer = display->renderer->winsys; CoglRendererEGL *egl_renderer = renderer->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
CoglXlibDisplay *xlib_display = display->winsys; CoglXlibDisplay *xlib_display = display->winsys;
CoglXlibRenderer *xlib_renderer = display->renderer->winsys; CoglXlibRenderer *xlib_renderer = renderer->winsys;
#endif #endif
#if defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) #if defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_KMS)
{
GError *error = NULL; GError *error = NULL;
if (!_cogl_winsys_kms_destroy_context (&egl_renderer->kms_renderer, if (!_cogl_winsys_kms_destroy_context (&egl_renderer->kms_renderer,
&egl_display->kms_display, &egl_display->kms_display,
&error)) &error))
{ {
g_critical (G_STRLOC ": Error cleaning up KMS rendering state: %s", error->message); g_critical (G_STRLOC ": Error cleaning up KMS rendering state: %s",
error->message);
g_clear_error (&error); g_clear_error (&error);
} }
}
#endif #endif
if (egl_display->egl_context != EGL_NO_CONTEXT) if (egl_display->egl_context != EGL_NO_CONTEXT)
@ -902,14 +956,25 @@ cleanup_context (CoglDisplay *display)
egl_display->egl_context = EGL_NO_CONTEXT; egl_display->egl_context = EGL_NO_CONTEXT;
} }
switch (renderer->winsys_vtable->id)
{
default:
break;
#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \ #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT)
case COGL_WINSYS_ID_EGL_NULL:
case COGL_WINSYS_ID_EGL_GDL:
if (egl_display->egl_surface != EGL_NO_SURFACE) if (egl_display->egl_surface != EGL_NO_SURFACE)
{ {
eglDestroySurface (egl_renderer->edpy, egl_display->egl_surface); eglDestroySurface (egl_renderer->edpy, egl_display->egl_surface);
egl_display->egl_surface = EGL_NO_SURFACE; egl_display->egl_surface = EGL_NO_SURFACE;
} }
#elif COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT break;
#endif
#if COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
case COGL_WINSYS_ID_EGL_X11:
if (egl_display->dummy_surface != EGL_NO_SURFACE) if (egl_display->dummy_surface != EGL_NO_SURFACE)
{ {
eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface); eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface);
@ -921,7 +986,11 @@ cleanup_context (CoglDisplay *display)
XDestroyWindow (xlib_renderer->xdpy, xlib_display->dummy_xwin); XDestroyWindow (xlib_renderer->xdpy, xlib_display->dummy_xwin);
xlib_display->dummy_xwin = None; xlib_display->dummy_xwin = None;
} }
#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) break;
#endif
#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
case COGL_WINSYS_ID_EGL_WAYLAND:
if (egl_display->dummy_surface != EGL_NO_SURFACE) if (egl_display->dummy_surface != EGL_NO_SURFACE)
{ {
eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface); eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface);
@ -939,8 +1008,10 @@ cleanup_context (CoglDisplay *display)
wl_surface_destroy (egl_display->wayland_surface); wl_surface_destroy (egl_display->wayland_surface);
egl_display->wayland_surface = NULL; egl_display->wayland_surface = NULL;
} }
break;
#endif #endif
} }
}
static gboolean static gboolean
create_context (CoglDisplay *display, GError **error) create_context (CoglDisplay *display, GError **error)
@ -1071,9 +1142,9 @@ _cogl_winsys_display_setup (CoglDisplay *display,
GError **error) GError **error)
{ {
CoglDisplayEGL *egl_display; CoglDisplayEGL *egl_display;
#if defined (COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT) || \ CoglRenderer *renderer = display->renderer;
defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) #ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT
CoglRendererEGL *egl_renderer = display->renderer->winsys; CoglRendererEGL *egl_renderer = renderer->winsys;
#endif #endif
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE); _COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);
@ -1082,12 +1153,14 @@ _cogl_winsys_display_setup (CoglDisplay *display,
display->winsys = egl_display; display->winsys = egl_display;
#ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
if (!gdl_plane_init (display, error)) if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_GDL &&
!gdl_plane_init (display, error))
goto error; goto error;
#endif #endif
#ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT #ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT
if (display->wayland_compositor_display) if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_WAYLAND &&
display->wayland_compositor_display)
{ {
struct wl_display *wayland_display = display->wayland_compositor_display; struct wl_display *wayland_display = display->wayland_compositor_display;
egl_renderer->pf_eglBindWaylandDisplay (egl_renderer->edpy, egl_renderer->pf_eglBindWaylandDisplay (egl_renderer->edpy,
@ -1096,7 +1169,8 @@ _cogl_winsys_display_setup (CoglDisplay *display,
#endif #endif
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
if (!_cogl_winsys_kms_display_setup (display, error)) if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_KMS &&
!_cogl_winsys_kms_display_setup (display, error))
goto error; goto error;
#endif #endif
@ -1118,6 +1192,7 @@ _cogl_winsys_context_init (CoglContext *context, GError **error)
context->winsys = g_new0 (CoglContextEGL, 1); context->winsys = g_new0 (CoglContextEGL, 1);
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
if (context->display->renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11)
cogl_xlib_renderer_add_filter (context->display->renderer, cogl_xlib_renderer_add_filter (context->display->renderer,
event_filter_cb, event_filter_cb,
context); context);
@ -1129,6 +1204,7 @@ static void
_cogl_winsys_context_deinit (CoglContext *context) _cogl_winsys_context_deinit (CoglContext *context)
{ {
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
if (context->display->renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11)
cogl_xlib_renderer_remove_filter (context->display->renderer, cogl_xlib_renderer_remove_filter (context->display->renderer,
event_filter_cb, event_filter_cb,
context); context);
@ -1144,30 +1220,25 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
CoglContext *context = framebuffer->context; CoglContext *context = framebuffer->context;
CoglDisplay *display = context->display; CoglDisplay *display = context->display;
CoglDisplayEGL *egl_display = display->winsys; CoglDisplayEGL *egl_display = display->winsys;
CoglRenderer *renderer = display->renderer;
CoglRendererEGL *egl_renderer = renderer->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
CoglRendererEGL *egl_renderer = display->renderer->winsys; CoglXlibRenderer *xlib_renderer = renderer->winsys;
CoglXlibRenderer *xlib_renderer = display->renderer->winsys;
CoglOnscreenXlib *xlib_onscreen; CoglOnscreenXlib *xlib_onscreen;
Window xwin; Window xwin;
#endif
#if defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
CoglRendererEGL *egl_renderer = display->renderer->winsys;
#endif #endif
CoglOnscreenEGL *egl_onscreen; CoglOnscreenEGL *egl_onscreen;
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
EGLint attributes[MAX_EGL_CONFIG_ATTRIBS]; EGLint attributes[MAX_EGL_CONFIG_ATTRIBS];
EGLConfig egl_config; EGLConfig egl_config;
EGLint config_count = 0; EGLint config_count = 0;
EGLBoolean status; EGLBoolean status;
gboolean need_stencil = gboolean need_stencil =
egl_display->stencil_disabled ? FALSE : framebuffer->config.need_stencil; egl_display->stencil_disabled ? FALSE : framebuffer->config.need_stencil;
#endif
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE); _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE);
if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_KMS)
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT {
egl_attributes_from_framebuffer_config (display, egl_attributes_from_framebuffer_config (display,
&framebuffer->config, &framebuffer->config,
need_stencil, need_stencil,
@ -1196,9 +1267,11 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
g_return_val_if_fail (status == EGL_TRUE, TRUE); g_return_val_if_fail (status == EGL_TRUE, TRUE);
framebuffer->samples_per_pixel = samples; framebuffer->samples_per_pixel = samples;
} }
#endif }
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11)
{
/* FIXME: We need to explicitly Select for ConfigureNotify events. /* FIXME: We need to explicitly Select for ConfigureNotify events.
* For foreign windows we need to be careful not to mess up any * For foreign windows we need to be careful not to mess up any
* existing event mask. * existing event mask.
@ -1220,7 +1293,8 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
_cogl_xlib_renderer_trap_errors (display->renderer, &state); _cogl_xlib_renderer_trap_errors (display->renderer, &state);
status = XGetWindowAttributes (xlib_renderer->xdpy, xwin, &attr); status = XGetWindowAttributes (xlib_renderer->xdpy, xwin, &attr);
xerror = _cogl_xlib_renderer_untrap_errors (display->renderer, &state); xerror = _cogl_xlib_renderer_untrap_errors (display->renderer,
&state);
if (status == 0 || xerror) if (status == 0 || xerror)
{ {
char message[1000]; char message[1000];
@ -1228,7 +1302,8 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
message, sizeof (message)); message, sizeof (message));
g_set_error (error, COGL_WINSYS_ERROR, g_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_CREATE_ONSCREEN, COGL_WINSYS_ERROR_CREATE_ONSCREEN,
"Unable to query geometry of foreign xid 0x%08lX: %s", "Unable to query geometry of foreign "
"xid 0x%08lX: %s",
xwin, message); xwin, message);
return FALSE; return FALSE;
} }
@ -1239,7 +1314,8 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
/* Make sure the app selects for the events we require... */ /* Make sure the app selects for the events we require... */
onscreen->foreign_update_mask_callback (onscreen, onscreen->foreign_update_mask_callback (onscreen,
COGL_ONSCREEN_X11_EVENT_MASK, COGL_ONSCREEN_X11_EVENT_MASK,
onscreen->foreign_update_mask_data); onscreen->
foreign_update_mask_data);
} }
else else
{ {
@ -1267,11 +1343,13 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
} }
/* window attributes */ /* window attributes */
xattr.background_pixel = WhitePixel (xlib_renderer->xdpy, xattr.background_pixel =
WhitePixel (xlib_renderer->xdpy,
DefaultScreen (xlib_renderer->xdpy)); DefaultScreen (xlib_renderer->xdpy));
xattr.border_pixel = 0; xattr.border_pixel = 0;
/* XXX: is this an X resource that we are leaking‽... */ /* XXX: is this an X resource that we are leaking‽... */
xattr.colormap = XCreateColormap (xlib_renderer->xdpy, xattr.colormap =
XCreateColormap (xlib_renderer->xdpy,
DefaultRootWindow (xlib_renderer->xdpy), DefaultRootWindow (xlib_renderer->xdpy),
xvisinfo->visual, xvisinfo->visual,
AllocNone); AllocNone);
@ -1292,7 +1370,8 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
XFree (xvisinfo); XFree (xvisinfo);
XSync (xlib_renderer->xdpy, False); XSync (xlib_renderer->xdpy, False);
xerror = _cogl_xlib_renderer_untrap_errors (display->renderer, &state); xerror =
_cogl_xlib_renderer_untrap_errors (display->renderer, &state);
if (xerror) if (xerror)
{ {
char message[1000]; char message[1000];
@ -1305,12 +1384,16 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
return FALSE; return FALSE;
} }
} }
}
#endif #endif
onscreen->winsys = g_slice_new0 (CoglOnscreenEGL); onscreen->winsys = g_slice_new0 (CoglOnscreenEGL);
egl_onscreen = onscreen->winsys; egl_onscreen = onscreen->winsys;
switch (renderer->winsys_vtable->id)
{
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
case COGL_WINSYS_ID_EGL_X11:
xlib_onscreen = onscreen->winsys; xlib_onscreen = onscreen->winsys;
xlib_onscreen->xwin = xwin; xlib_onscreen->xwin = xwin;
@ -1321,8 +1404,11 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
egl_config, egl_config,
(NativeWindowType) xlib_onscreen->xwin, (NativeWindowType) xlib_onscreen->xwin,
NULL); NULL);
#elif defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) break;
#endif
#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
case COGL_WINSYS_ID_EGL_WAYLAND:
egl_onscreen->wayland_surface = egl_onscreen->wayland_surface =
wl_compositor_create_surface (egl_renderer->wayland_compositor); wl_compositor_create_surface (egl_renderer->wayland_compositor);
if (!egl_onscreen->wayland_surface) if (!egl_onscreen->wayland_surface)
@ -1358,11 +1444,18 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
NULL); NULL);
wl_shell_surface_set_toplevel (egl_onscreen->wayland_shell_surface); wl_shell_surface_set_toplevel (egl_onscreen->wayland_shell_surface);
break;
#endif
#elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \ #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \ defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \ defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT) defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
case COGL_WINSYS_ID_EGL_NULL:
case COGL_WINSYS_ID_EGL_ANDROID:
case COGL_WINSYS_ID_EGL_GDL:
case COGL_WINSYS_ID_EGL_KMS:
if (egl_display->have_onscreen) if (egl_display->have_onscreen)
{ {
g_set_error (error, COGL_WINSYS_ERROR, g_set_error (error, COGL_WINSYS_ERROR,
@ -1372,24 +1465,32 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
} }
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
if (!_cogl_winsys_kms_onscreen_init (cogl_framebuffer_get_context (framebuffer), if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_KMS)
{
CoglContext *context = cogl_framebuffer_get_context (framebuffer);
if (!_cogl_winsys_kms_onscreen_init (context,
&egl_renderer->kms_renderer, &egl_renderer->kms_renderer,
&egl_display->kms_display, &egl_display->kms_display,
&egl_onscreen->kms_onscreen, &egl_onscreen->kms_onscreen,
error)) error))
return FALSE; return FALSE;
#else }
egl_onscreen->egl_surface = egl_display->egl_surface; else
#endif #endif
egl_onscreen->egl_surface = egl_display->egl_surface;
_cogl_framebuffer_winsys_update_size (framebuffer, _cogl_framebuffer_winsys_update_size (framebuffer,
egl_display->egl_surface_width, egl_display->egl_surface_width,
egl_display->egl_surface_height); egl_display->egl_surface_height);
egl_display->have_onscreen = TRUE; egl_display->have_onscreen = TRUE;
#else break;
#error "Unknown EGL platform"
#endif #endif
default:
g_warn_if_reached ();
return FALSE;
}
return TRUE; return TRUE;
} }
@ -1398,12 +1499,14 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = framebuffer->context; CoglContext *context = framebuffer->context;
CoglRendererEGL *egl_renderer = context->display->renderer->winsys; CoglRenderer *renderer = context->display->renderer;
CoglRendererEGL *egl_renderer = renderer->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
CoglXlibRenderer *xlib_renderer = context->display->renderer->winsys; CoglXlibRenderer *xlib_renderer = renderer->winsys;
CoglXlibTrapState old_state; CoglXlibTrapState old_state;
CoglOnscreenXlib *xlib_onscreen = onscreen->winsys; CoglOnscreenXlib *xlib_onscreen = onscreen->winsys;
#elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) #endif
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT
CoglDisplayEGL *egl_display = context->display->winsys; CoglDisplayEGL *egl_display = context->display->winsys;
#endif #endif
CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
@ -1411,21 +1514,20 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
/* If we never successfully allocated then there's nothing to do */ /* If we never successfully allocated then there's nothing to do */
if (egl_onscreen == NULL) if (egl_onscreen == NULL)
return; return;
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_KMS &&
if (egl_onscreen->egl_surface != EGL_NO_SURFACE) egl_onscreen->egl_surface != EGL_NO_SURFACE)
{ {
if (eglDestroySurface (egl_renderer->edpy, egl_onscreen->egl_surface) if (eglDestroySurface (egl_renderer->edpy, egl_onscreen->egl_surface)
== EGL_FALSE) == EGL_FALSE)
g_warning ("Failed to destroy EGL surface"); g_warning ("Failed to destroy EGL surface");
egl_onscreen->egl_surface = EGL_NO_SURFACE; egl_onscreen->egl_surface = EGL_NO_SURFACE;
} }
#endif
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT
egl_display->have_onscreen = FALSE; egl_display->have_onscreen = FALSE;
#endif #endif
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
_cogl_xlib_renderer_trap_errors (context->display->renderer, &old_state); _cogl_xlib_renderer_trap_errors (renderer, &old_state);
if (!xlib_onscreen->is_foreign_xwin && xlib_onscreen->xwin != None) if (!xlib_onscreen->is_foreign_xwin && xlib_onscreen->xwin != None)
{ {
@ -1437,7 +1539,7 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
XSync (xlib_renderer->xdpy, False); XSync (xlib_renderer->xdpy, False);
if (_cogl_xlib_renderer_untrap_errors (context->display->renderer, if (_cogl_xlib_renderer_untrap_errors (renderer,
&old_state) != Success) &old_state) != Success)
g_warning ("X Error while destroying X window"); g_warning ("X Error while destroying X window");
#endif #endif
@ -1470,39 +1572,43 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
{ {
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglDisplayEGL *egl_display = context->display->winsys; CoglDisplayEGL *egl_display = context->display->winsys;
CoglRendererEGL *egl_renderer = context->display->renderer->winsys; CoglRenderer *renderer = context->display->renderer;
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT CoglRendererEGL *egl_renderer = renderer->winsys;
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
CoglContextEGL *egl_context = context->winsys;
#endif
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_KMS)
{
_cogl_winsys_kms_bind (&egl_renderer->kms_renderer, _cogl_winsys_kms_bind (&egl_renderer->kms_renderer,
&egl_display->kms_display); &egl_display->kms_display);
return; return;
}
#endif
#else #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
{
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
CoglContextEGL *egl_context = context->winsys;
if (egl_context->current_surface == egl_onscreen->egl_surface) if (egl_context->current_surface == egl_onscreen->egl_surface)
return; return;
if (G_UNLIKELY (!onscreen)) if (G_UNLIKELY (!onscreen))
{ {
#if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \ if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11 ||
defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT) renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_WAYLAND)
{
eglMakeCurrent (egl_renderer->edpy, eglMakeCurrent (egl_renderer->edpy,
egl_display->dummy_surface, egl_display->dummy_surface,
egl_display->dummy_surface, egl_display->dummy_surface,
egl_display->egl_context); egl_display->egl_context);
egl_context->current_surface = egl_display->dummy_surface; egl_context->current_surface = egl_display->dummy_surface;
#elif defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \ }
defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \ else
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT)
return; return;
#else
#error "Unknown EGL platform"
#endif
} }
else else
{ {
@ -1517,7 +1623,7 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
eglSwapInterval (egl_renderer->edpy, 1); eglSwapInterval (egl_renderer->edpy, 1);
else else
eglSwapInterval (egl_renderer->edpy, 0); eglSwapInterval (egl_renderer->edpy, 0);
}
#endif #endif
} }
@ -1526,18 +1632,26 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
const int *user_rectangles, const int *user_rectangles,
int n_rectangles) int n_rectangles)
{ {
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_NULL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_GDL_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \
defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRendererEGL *egl_renderer = context->display->renderer->winsys; CoglRenderer *renderer = context->display->renderer;
CoglRendererEGL *egl_renderer = renderer->winsys;
CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
int framebuffer_height = cogl_framebuffer_get_height (framebuffer); int framebuffer_height = cogl_framebuffer_get_height (framebuffer);
int *rectangles = g_alloca (sizeof (int) * n_rectangles * 4); int *rectangles = g_alloca (sizeof (int) * n_rectangles * 4);
int i; int i;
/* eglSwapBuffersRegion expects rectangles relative to the bottom left corner if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_KMS)
* but we are given rectangles relative to the top left so we need to flip {
* them... */ /* eglSwapBuffersRegion expects rectangles relative to the
* bottom left corner but we are given rectangles relative to
* the top left so we need to flip them... */
memcpy (rectangles, user_rectangles, sizeof (int) * n_rectangles * 4); memcpy (rectangles, user_rectangles, sizeof (int) * n_rectangles * 4);
for (i = 0; i < n_rectangles; i++) for (i = 0; i < n_rectangles; i++)
{ {
@ -1558,6 +1672,7 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
n_rectangles, n_rectangles,
rectangles) == EGL_FALSE) rectangles) == EGL_FALSE)
g_warning ("Error reported by eglSwapBuffersRegion"); g_warning ("Error reported by eglSwapBuffersRegion");
}
#endif #endif
} }
@ -1567,9 +1682,13 @@ _cogl_winsys_onscreen_set_visibility (CoglOnscreen *onscreen,
gboolean visibility) gboolean visibility)
{ {
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglXlibRenderer *xlib_renderer = context->display->renderer->winsys; CoglRenderer *renderer = context->display->renderer;
CoglXlibRenderer *xlib_renderer = renderer->winsys;
CoglOnscreenXlib *xlib_onscreen = onscreen->winsys; CoglOnscreenXlib *xlib_onscreen = onscreen->winsys;
if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_X11)
return;
if (visibility) if (visibility)
XMapWindow (xlib_renderer->xdpy, xlib_onscreen->xwin); XMapWindow (xlib_renderer->xdpy, xlib_onscreen->xwin);
else else
@ -1581,18 +1700,23 @@ static void
_cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen) _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
{ {
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRendererEGL *egl_renderer = context->display->renderer->winsys; CoglRenderer *renderer = context->display->renderer;
CoglRendererEGL *egl_renderer = renderer->winsys;
CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
CoglDisplayEGL *egl_display = context->display->winsys; CoglDisplayEGL *egl_display = context->display->winsys;
#endif #endif
#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_KMS)
{
_cogl_winsys_kms_swap_buffers (&egl_renderer->kms_renderer, _cogl_winsys_kms_swap_buffers (&egl_renderer->kms_renderer,
&egl_display->kms_display, &egl_display->kms_display,
&egl_onscreen->kms_onscreen); &egl_onscreen->kms_onscreen);
return; return;
#else }
#endif
/* The specification for EGL (at least in 1.4) says that the surface /* The specification for EGL (at least in 1.4) says that the surface
needs to be bound to the current context for the swap to work needs to be bound to the current context for the swap to work
although it may change in future. Mesa explicitly checks for this although it may change in future. Mesa explicitly checks for this
@ -1603,7 +1727,6 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
COGL_FRAMEBUFFER_STATE_BIND); COGL_FRAMEBUFFER_STATE_BIND);
eglSwapBuffers (egl_renderer->edpy, egl_onscreen->egl_surface); eglSwapBuffers (egl_renderer->edpy, egl_onscreen->egl_surface);
#endif
#ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
/* /*
@ -1612,6 +1735,7 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
* the implementation changing we should explicitly ensure all messages are * the implementation changing we should explicitly ensure all messages are
* sent. * sent.
*/ */
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_WAYLAND)
wl_display_flush (egl_renderer->wayland_display); wl_display_flush (egl_renderer->wayland_display);
#endif #endif
} }
@ -1619,17 +1743,28 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
#ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
static guint32 static guint32
_cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen) _cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen)
{
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRenderer *renderer = context->display->renderer;
if (renderer->winsys_vtable->id == COGL_WINSYS_ID_EGL_X11)
{ {
CoglOnscreenXlib *xlib_onscreen = onscreen->winsys; CoglOnscreenXlib *xlib_onscreen = onscreen->winsys;
return xlib_onscreen->xwin; return xlib_onscreen->xwin;
} }
else
return None;
}
#endif #endif
static void static void
_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen) _cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
{ {
#ifndef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRenderer *renderer = context->display->renderer;
if (renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_KMS)
{
CoglContextEGL *egl_context = context->winsys; CoglContextEGL *egl_context = context->winsys;
CoglOnscreenEGL *egl_onscreen = onscreen->winsys; CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
@ -1637,7 +1772,8 @@ _cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
return; return;
egl_context->current_surface = EGL_NO_SURFACE; egl_context->current_surface = EGL_NO_SURFACE;
#endif }
_cogl_winsys_onscreen_bind (onscreen); _cogl_winsys_onscreen_bind (onscreen);
} }
@ -1652,6 +1788,9 @@ _cogl_winsys_xlib_get_visual_info (void)
_COGL_RETURN_VAL_IF_FAIL (ctx->display->winsys, FALSE); _COGL_RETURN_VAL_IF_FAIL (ctx->display->winsys, FALSE);
if (ctx->display->renderer->winsys_vtable->id != COGL_WINSYS_ID_EGL_X11)
return NULL;
egl_display = ctx->display->winsys; egl_display = ctx->display->winsys;
if (!egl_display->found_egl_config) if (!egl_display->found_egl_config)

View File

@ -839,11 +839,6 @@ AS_IF([test "x$enable_xlib_egl_platform" = "xyes"],
AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_POWERVR_X11, AM_CONDITIONAL(SUPPORT_EGL_PLATFORM_POWERVR_X11,
[test "x$enable_xlib_egl_platform" = "xyes"]) [test "x$enable_xlib_egl_platform" = "xyes"])
AS_IF([test $EGL_PLATFORM_COUNT -gt 1],
[AC_MSG_ERROR(['The --enable-*-egl-platform options are currently mutually exclusive'])])
AS_IF([test "x$NEED_EGL" = "xyes" && test "x$EGL_CHECKED" != "xyes"], AS_IF([test "x$NEED_EGL" = "xyes" && test "x$EGL_CHECKED" != "xyes"],
[ [
PKG_CHECK_EXISTS([egl], PKG_CHECK_EXISTS([egl],