mir: add support for foreign surfaces

This commit is contained in:
Marco Trevisan (Treviño) 2014-11-17 16:08:59 +01:00
parent a3ae538c45
commit 1b9380ef3c
3 changed files with 51 additions and 10 deletions

View File

@ -77,6 +77,10 @@ struct _CoglOnscreen
struct wl_surface *foreign_surface;
#endif
#ifdef COGL_HAS_EGL_PLATFORM_MIR_SUPPORT
struct MirSurface *foreign_surface;
#endif
CoglBool swap_throttled;
CoglList frame_closures;

View File

@ -270,6 +270,24 @@ cogl_wayland_onscreen_resize (CoglOnscreen *onscreen,
#if defined (COGL_HAS_EGL_PLATFORM_MIR_SUPPORT)
struct MirSurface *
cogl_mir_onscreen_get_surface (CoglOnscreen *onscreen);
/**
* cogl_mir_onscreen_set_foreign_surface:
* @onscreen: An unallocated framebuffer.
* @surface A Mir surface to associate with the @onscreen.
*
* Allows you to explicitly notify Cogl of an existing Mir surface to use,
* which prevents Cogl from allocating a surface for the @onscreen.
* An allocated surface will not be destroyed when the @onscreen is freed.
*
* This function must be called before @onscreen is allocated.
*
* Since: 1.18
* Stability: unstable
*/
void
cogl_mir_onscreen_set_foreign_surface (CoglOnscreen *onscreen,
struct MirSurface *surface);
#endif /* COGL_HAS_EGL_PLATFORM_MIR_SUPPORT */
/**

View File

@ -317,15 +317,21 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
mir_onscreen = g_slice_new0 (CoglOnscreenMir);
egl_onscreen->platform = mir_onscreen;
surfaceparm.name = "CoglSurface";
surfaceparm.width = cogl_framebuffer_get_width (framebuffer);
surfaceparm.height = cogl_framebuffer_get_height (framebuffer);
surfaceparm.pixel_format = _mir_connection_get_valid_format (mir_renderer->mir_connection);
surfaceparm.buffer_usage = mir_buffer_usage_hardware;
surfaceparm.output_id = mir_display_output_id_invalid;
mir_onscreen->mir_surface =
mir_connection_create_surface_sync (mir_renderer->mir_connection, &surfaceparm);
if (mir_surface_is_valid (onscreen->foreign_surface))
{
mir_onscreen->mir_surface = onscreen->foreign_surface;
}
else
{
surfaceparm.name = "CoglSurface";
surfaceparm.width = cogl_framebuffer_get_width (framebuffer);
surfaceparm.height = cogl_framebuffer_get_height (framebuffer);
surfaceparm.pixel_format = _mir_connection_get_valid_format (mir_renderer->mir_connection);
surfaceparm.buffer_usage = mir_buffer_usage_hardware;
surfaceparm.output_id = mir_display_output_id_invalid;
mir_onscreen->mir_surface =
mir_connection_create_surface_sync (mir_renderer->mir_connection, &surfaceparm);
}
mir_onscreen->last_state = mir_surface_get_state (mir_onscreen->mir_surface);
@ -362,7 +368,7 @@ _cogl_winsys_egl_onscreen_deinit (CoglOnscreen *onscreen)
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
CoglOnscreenMir *mir_onscreen = egl_onscreen->platform;
if (mir_onscreen->mir_surface)
if (mir_onscreen->mir_surface && !onscreen->foreign_surface)
{
mir_surface_release (mir_onscreen->mir_surface, NULL, NULL);
mir_onscreen->mir_surface = NULL;
@ -433,6 +439,19 @@ cogl_mir_renderer_get_connection (CoglRenderer *renderer)
return NULL;
}
void
cogl_mir_onscreen_set_foreign_surface (CoglOnscreen *onscreen,
MirSurface *surface)
{
CoglFramebuffer *fb;
_COGL_RETURN_IF_FAIL (mir_surface_is_valid (surface));
fb = COGL_FRAMEBUFFER (onscreen);
_COGL_RETURN_IF_FAIL (!fb->allocated);
onscreen->foreign_surface = surface;
}
MirSurface *
cogl_mir_onscreen_get_surface (CoglOnscreen *onscreen)
{