[mutter] renderer-native: Always use MetaEgl when interacting with EGL



commit b0e42d3f6e095feee5e2e62cb04f2370fb7bfca8
Author: Jonas Ådahl <jadahl gmail com>
Date:   Mon Jul 24 16:19:55 2017 +0800

    renderer-native: Always use MetaEgl when interacting with EGL
    
    Partly for consistency, partly for error handling functionality.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785381

 src/backends/meta-egl.c                    |   50 ++++++++++++++++++++++++++++
 src/backends/meta-egl.h                    |   16 +++++++++
 src/backends/native/meta-renderer-native.c |   34 +++++++++++++------
 3 files changed, 89 insertions(+), 11 deletions(-)
---
diff --git a/src/backends/meta-egl.c b/src/backends/meta-egl.c
index 3031e9b..3e3a567 100644
--- a/src/backends/meta-egl.c
+++ b/src/backends/meta-egl.c
@@ -291,6 +291,27 @@ meta_egl_choose_config (MetaEgl      *egl,
 }
 
 EGLSurface
+meta_egl_create_window_surface (MetaEgl            *egl,
+                                EGLDisplay          display,
+                                EGLConfig           config,
+                                EGLNativeWindowType native_window_type,
+                                const EGLint       *attrib_list,
+                                GError            **error)
+{
+  EGLSurface surface;
+
+  surface = eglCreateWindowSurface (display, config,
+                                    native_window_type, attrib_list);
+  if (surface == EGL_NO_SURFACE)
+    {
+      set_egl_error (error);
+      return EGL_NO_SURFACE;
+    }
+
+  return surface;
+}
+
+EGLSurface
 meta_egl_create_pbuffer_surface (MetaEgl      *egl,
                                  EGLDisplay    display,
                                  EGLConfig     config,
@@ -309,6 +330,21 @@ meta_egl_create_pbuffer_surface (MetaEgl      *egl,
   return surface;
 }
 
+gboolean
+meta_egl_destroy_surface (MetaEgl   *egl,
+                          EGLDisplay display,
+                          EGLSurface surface,
+                          GError   **error)
+{
+  if (!eglDestroySurface (display, surface))
+    {
+      set_egl_error (error);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
 static gboolean
 is_egl_proc_valid_real (void       *proc,
                         const char *proc_name,
@@ -353,6 +389,20 @@ meta_egl_get_platform_display (MetaEgl      *egl,
   return display;
 }
 
+gboolean
+meta_egl_terminate (MetaEgl   *egl,
+                    EGLDisplay display,
+                    GError   **error)
+{
+  if (!eglTerminate (display))
+    {
+      set_egl_error (error);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
 EGLImageKHR
 meta_egl_create_image (MetaEgl        *egl,
                        EGLDisplay      display,
diff --git a/src/backends/meta-egl.h b/src/backends/meta-egl.h
index 881ccb7..fea5e00 100644
--- a/src/backends/meta-egl.h
+++ b/src/backends/meta-egl.h
@@ -71,18 +71,34 @@ gboolean meta_egl_destroy_image (MetaEgl    *egl,
                                  EGLImageKHR image,
                                  GError    **error);
 
+EGLSurface meta_egl_create_window_surface (MetaEgl            *egl,
+                                           EGLDisplay          display,
+                                           EGLConfig           config,
+                                           EGLNativeWindowType native_window_type,
+                                           const EGLint       *attrib_list,
+                                           GError            **error);
+
 EGLSurface meta_egl_create_pbuffer_surface (MetaEgl      *egl,
                                             EGLDisplay    display,
                                             EGLConfig     config,
                                             const EGLint *attrib_list,
                                             GError      **error);
 
+gboolean meta_egl_destroy_surface (MetaEgl   *egl,
+                                   EGLDisplay display,
+                                   EGLSurface surface,
+                                   GError   **error);
+
 EGLDisplay meta_egl_get_platform_display (MetaEgl      *egl,
                                           EGLenum       platform,
                                           void         *native_display,
                                           const EGLint *attrib_list,
                                           GError      **error);
 
+gboolean meta_egl_terminate (MetaEgl   *egl,
+                             EGLDisplay display,
+                             GError   **error);
+
 gboolean meta_egl_query_wayland_buffer (MetaEgl            *egl,
                                         EGLDisplay          display,
                                         struct wl_resource *buffer,
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index d7d2d47..ede5ac3 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -242,9 +242,11 @@ static void
 meta_renderer_native_disconnect (CoglRenderer *cogl_renderer)
 {
   CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
+  MetaRendererNative *renderer_native = cogl_renderer_egl->platform;
+  MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
 
   if (cogl_renderer_egl->edpy != EGL_NO_DISPLAY)
-    eglTerminate (cogl_renderer_egl->edpy);
+    meta_egl_terminate (egl, cogl_renderer_egl->edpy, NULL);
 
   g_slice_free (CoglRendererEGL, cogl_renderer_egl);
 }
@@ -516,10 +518,15 @@ meta_renderer_native_egl_cleanup_context (CoglDisplay *cogl_display)
   CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
   CoglRenderer *cogl_renderer = cogl_display->renderer;
   CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
+  MetaRendererNative *renderer_native = cogl_renderer_egl->platform;
+  MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
 
   if (cogl_display_egl->dummy_surface != EGL_NO_SURFACE)
     {
-      eglDestroySurface (cogl_renderer_egl->edpy, cogl_display_egl->dummy_surface);
+      meta_egl_destroy_surface (egl,
+                                cogl_renderer_egl->edpy,
+                                cogl_display_egl->dummy_surface,
+                                NULL);
       cogl_display_egl->dummy_surface = EGL_NO_SURFACE;
     }
 }
@@ -1062,6 +1069,7 @@ meta_renderer_native_create_surface_gbm (MetaOnscreenNative  *onscreen_native,
   CoglDisplayEGL *cogl_display_egl = cogl_display->winsys;
   CoglRendererEGL *cogl_renderer_egl = cogl_display->renderer->winsys;
   MetaRendererNative *renderer_native = cogl_renderer_egl->platform;
+  MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
   MetaRendererNativeGpuData *renderer_gpu_data;
   struct gbm_surface *new_gbm_surface;
   EGLNativeWindowType egl_native_window;
@@ -1085,16 +1093,16 @@ meta_renderer_native_create_surface_gbm (MetaOnscreenNative  *onscreen_native,
     }
 
   egl_native_window = (EGLNativeWindowType) new_gbm_surface;
-  new_egl_surface = eglCreateWindowSurface (cogl_renderer_egl->edpy,
-                                            cogl_display_egl->egl_config,
-                                            egl_native_window,
-                                            NULL);
+  new_egl_surface =
+    meta_egl_create_window_surface (egl,
+                                    cogl_renderer_egl->edpy,
+                                    cogl_display_egl->egl_config,
+                                    egl_native_window,
+                                    NULL,
+                                    error);
   if (new_egl_surface == EGL_NO_SURFACE)
     {
       gbm_surface_destroy (new_gbm_surface);
-      g_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_CREATE_ONSCREEN,
-                   "Failed to allocate surface");
       return FALSE;
     }
 
@@ -1458,8 +1466,9 @@ meta_renderer_native_release_onscreen (CoglOnscreen *onscreen)
   CoglContext *cogl_context = framebuffer->context;
   CoglRenderer *cogl_renderer = cogl_context->display->renderer;
   CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
-  CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
   MetaRendererNative *renderer_native = cogl_renderer_egl->platform;
+  MetaEgl *egl = meta_renderer_native_get_egl (renderer_native);
+  CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
   MetaOnscreenNative *onscreen_native;
   MetaRendererNativeGpuData *renderer_gpu_data;
 
@@ -1471,7 +1480,10 @@ meta_renderer_native_release_onscreen (CoglOnscreen *onscreen)
 
   if (onscreen_egl->egl_surface != EGL_NO_SURFACE)
     {
-      eglDestroySurface (cogl_renderer_egl->edpy, onscreen_egl->egl_surface);
+      meta_egl_destroy_surface (egl,
+                                cogl_renderer_egl->edpy,
+                                onscreen_egl->egl_surface,
+                                NULL);
       onscreen_egl->egl_surface = EGL_NO_SURFACE;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]