[Cogl] [PATCH 2/2] kms: Use a dummy surface instead of the surfaceless extension

Robert Bragg robert at sixbynine.org
Wed Aug 15 09:12:45 PDT 2012


This looks good to land to me:

Reviewed-by: Robert Bragg <robert at linux.intel.com>

thanks,
- Robert

On Mon, Aug 13, 2012 at 3:43 PM, Neil Roberts <neil at linux.intel.com> wrote:
> The surfaceless extension that Mesa advertises has been renamed to
> EGL_KHR_surfaceless_context instead of a separate extension for the
> GLES, GLES2 and GL APIs and the new extension has been ratified by
> Khronos. Therefore the KMS backend no longer runs against Mesa master.
> We could just rename the extension we check for, however Weston (the
> sample Wayland compositor) has switched to just creating a dummy GBM
> surface and not using the surfaceless extension at all. We should
> probably do the same thing.
>
> Using the surfaceless extension could be a good idea but we don't
> really need to rely on it for KMS and we would want to do it for all
> EGL backends, not just the KMS backend.
> ---
>  cogl/winsys/cogl-winsys-egl-feature-functions.h | 15 -----
>  cogl/winsys/cogl-winsys-egl-kms.c               | 79 +++++++++++++++----------
>  cogl/winsys/cogl-winsys-egl-private.h           |  5 +-
>  3 files changed, 49 insertions(+), 50 deletions(-)
>
> diff --git a/cogl/winsys/cogl-winsys-egl-feature-functions.h b/cogl/winsys/cogl-winsys-egl-feature-functions.h
> index e979724..9c8dcca 100644
> --- a/cogl/winsys/cogl-winsys-egl-feature-functions.h
> +++ b/cogl/winsys/cogl-winsys-egl-feature-functions.h
> @@ -88,18 +88,3 @@ COGL_WINSYS_FEATURE_FUNCTION (EGLBoolean, eglUnbindWaylandDisplay,
>                                 struct wl_display *wayland_display))
>  COGL_WINSYS_FEATURE_END ()
>  #endif
> -COGL_WINSYS_FEATURE_BEGIN (surfaceless_opengl,
> -                           "KHR\0",
> -                           "surfaceless_opengl\0",
> -                           COGL_EGL_WINSYS_FEATURE_SURFACELESS_OPENGL)
> -COGL_WINSYS_FEATURE_END ()
> -COGL_WINSYS_FEATURE_BEGIN (surfaceless_gles1,
> -                           "KHR\0",
> -                           "surfaceless_gles1\0",
> -                           COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES1)
> -COGL_WINSYS_FEATURE_END ()
> -COGL_WINSYS_FEATURE_BEGIN (surfaceless_gles2,
> -                           "KHR\0",
> -                           "surfaceless_gles2\0",
> -                           COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES2)
> -COGL_WINSYS_FEATURE_END ()
> diff --git a/cogl/winsys/cogl-winsys-egl-kms.c b/cogl/winsys/cogl-winsys-egl-kms.c
> index 32f5289..085d6c6 100644
> --- a/cogl/winsys/cogl-winsys-egl-kms.c
> +++ b/cogl/winsys/cogl-winsys-egl-kms.c
> @@ -79,6 +79,7 @@ typedef struct _CoglDisplayKMS
>    int width, height;
>    CoglBool pending_set_crtc;
>    CoglBool pending_swap_notify;
> +  struct gbm_surface *dummy_gbm_surface;
>  } CoglDisplayKMS;
>
>  typedef struct _CoglFlipKMS
> @@ -388,8 +389,6 @@ _cogl_winsys_egl_display_setup (CoglDisplay *display,
>    CoglDisplayKMS *kms_display;
>    CoglRendererEGL *egl_renderer = display->renderer->winsys;
>    CoglRendererKMS *kms_renderer = egl_renderer->platform;
> -  CoglEGLWinsysFeature surfaceless_feature = 0;
> -  const char *surfaceless_feature_name = "";
>    drmModeRes *resources;
>    CoglOutputKMS *output0, *output1;
>    CoglBool mirror;
> @@ -397,33 +396,6 @@ _cogl_winsys_egl_display_setup (CoglDisplay *display,
>    kms_display = g_slice_new0 (CoglDisplayKMS);
>    egl_display->platform = kms_display;
>
> -  switch (display->renderer->driver)
> -    {
> -    case COGL_DRIVER_GL:
> -      surfaceless_feature = COGL_EGL_WINSYS_FEATURE_SURFACELESS_OPENGL;
> -      surfaceless_feature_name = "opengl";
> -      break;
> -    case COGL_DRIVER_GLES1:
> -      surfaceless_feature = COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES1;
> -      surfaceless_feature_name = "gles1";
> -      break;
> -    case COGL_DRIVER_GLES2:
> -      surfaceless_feature = COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES2;
> -      surfaceless_feature_name = "gles2";
> -      break;
> -    case COGL_DRIVER_ANY:
> -      g_return_val_if_reached (FALSE);
> -    }
> -
> -  if (!(egl_renderer->private_features & surfaceless_feature))
> -    {
> -      g_set_error (error, COGL_WINSYS_ERROR,
> -                   COGL_WINSYS_ERROR_INIT,
> -                   "EGL_KHR_surfaceless_%s extension not available",
> -                   surfaceless_feature_name);
> -      return FALSE;
> -    }
> -
>    resources = drmModeGetResources (kms_renderer->fd);
>    if (!resources)
>      {
> @@ -538,10 +510,39 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
>                                    GError **error)
>  {
>    CoglDisplayEGL *egl_display = display->winsys;
> +  CoglDisplayKMS *kms_display = egl_display->platform;
> +  CoglRenderer *renderer = display->renderer;
> +  CoglRendererEGL *egl_renderer = renderer->winsys;
> +  CoglRendererKMS *kms_renderer = egl_renderer->platform;
> +
> +  kms_display->dummy_gbm_surface = gbm_surface_create (kms_renderer->gbm,
> +                                                       16, 16,
> +                                                       GBM_FORMAT_XRGB8888,
> +                                                       GBM_BO_USE_RENDERING);
> +  if (!kms_display->dummy_gbm_surface)
> +    {
> +      g_set_error (error, COGL_WINSYS_ERROR,
> +                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
> +                   "Failed to create dummy GBM surface");
> +      return FALSE;
> +    }
> +
> +  egl_display->dummy_surface =
> +    eglCreateWindowSurface (egl_renderer->edpy,
> +                            egl_display->egl_config,
> +                            (NativeWindowType) kms_display->dummy_gbm_surface,
> +                            NULL);
> +  if (egl_display->dummy_surface == EGL_NO_SURFACE)
> +    {
> +      g_set_error (error, COGL_WINSYS_ERROR,
> +                   COGL_WINSYS_ERROR_CREATE_CONTEXT,
> +                   "Failed to create dummy EGL surface");
> +      return FALSE;
> +    }
>
>    if (!_cogl_winsys_egl_make_current (display,
> -                                      EGL_NO_SURFACE,
> -                                      EGL_NO_SURFACE,
> +                                      egl_display->dummy_surface,
> +                                      egl_display->dummy_surface,
>                                        egl_display->egl_context))
>      {
>        g_set_error (error, COGL_WINSYS_ERROR,
> @@ -556,6 +557,22 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
>  static void
>  _cogl_winsys_egl_cleanup_context (CoglDisplay *display)
>  {
> +  CoglDisplayEGL *egl_display = display->winsys;
> +  CoglDisplayKMS *kms_display = egl_display->platform;
> +  CoglRenderer *renderer = display->renderer;
> +  CoglRendererEGL *egl_renderer = renderer->winsys;
> +
> +  if (egl_display->dummy_surface != EGL_NO_SURFACE)
> +    {
> +      eglDestroySurface (egl_renderer->edpy, egl_display->dummy_surface);
> +      egl_display->dummy_surface = EGL_NO_SURFACE;
> +    }
> +
> +  if (kms_display->dummy_gbm_surface != NULL)
> +    {
> +      gbm_surface_destroy (kms_display->dummy_gbm_surface);
> +      kms_display->dummy_gbm_surface = NULL;
> +    }
>  }
>
>  static void
> diff --git a/cogl/winsys/cogl-winsys-egl-private.h b/cogl/winsys/cogl-winsys-egl-private.h
> index 265a423..eeb7028 100644
> --- a/cogl/winsys/cogl-winsys-egl-private.h
> +++ b/cogl/winsys/cogl-winsys-egl-private.h
> @@ -68,10 +68,7 @@ typedef enum _CoglEGLWinsysFeature
>  {
>    COGL_EGL_WINSYS_FEATURE_SWAP_REGION                   =1L<<0,
>    COGL_EGL_WINSYS_FEATURE_EGL_IMAGE_FROM_X11_PIXMAP     =1L<<1,
> -  COGL_EGL_WINSYS_FEATURE_EGL_IMAGE_FROM_WAYLAND_BUFFER =1L<<2,
> -  COGL_EGL_WINSYS_FEATURE_SURFACELESS_OPENGL            =1L<<3,
> -  COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES1             =1L<<4,
> -  COGL_EGL_WINSYS_FEATURE_SURFACELESS_GLES2             =1L<<5
> +  COGL_EGL_WINSYS_FEATURE_EGL_IMAGE_FROM_WAYLAND_BUFFER =1L<<2
>  } CoglEGLWinsysFeature;
>
>  typedef struct _CoglRendererEGL
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list