[cogl/wip/wayland-compositor: 5/18] egl: Check EGL extension as early as possible



commit 1a0089eb25b4a080cac8774bfb876e4f81fd3fcf
Author: Robert Bragg <robert linux intel com>
Date:   Tue May 24 17:21:28 2011 +0100

    egl: Check EGL extension as early as possible
    
    Instead of waiting until initializing a CoglContext we now check EGL
    extensions after calling eglInitialize.

 cogl/cogl-feature-private.h                     |    5 +-
 cogl/winsys/cogl-winsys-egl-feature-functions.h |    8 +--
 cogl/winsys/cogl-winsys-egl.c                   |   73 ++++++++++++++---------
 3 files changed, 49 insertions(+), 37 deletions(-)
---
diff --git a/cogl/cogl-feature-private.h b/cogl/cogl-feature-private.h
index 5b26b70..d81693d 100644
--- a/cogl/cogl-feature-private.h
+++ b/cogl/cogl-feature-private.h
@@ -61,8 +61,9 @@ struct _CoglFeatureData
   const char *extension_names;
   /* A set of feature flags to enable if the extension is available */
   CoglFeatureFlags feature_flags;
-  /* FIXME: This is now unused */
-  int padding_feature_flags_private;
+  /* A set of private feature flags to enable if the extension is
+   * available */
+  int feature_flags_private;
   /* An optional corresponding winsys feature. */
   CoglWinsysFeature winsys_feature;
   /* A list of functions required for this feature. Terminated with a
diff --git a/cogl/winsys/cogl-winsys-egl-feature-functions.h b/cogl/winsys/cogl-winsys-egl-feature-functions.h
index 58c0734..5a961ea 100644
--- a/cogl/winsys/cogl-winsys-egl-feature-functions.h
+++ b/cogl/winsys/cogl-winsys-egl-feature-functions.h
@@ -28,9 +28,7 @@
 
 /* Macro prototypes:
  * COGL_WINSYS_FEATURE_BEGIN (name, namespaces, extension_names,
- *                            implied_public_feature_flags,
- *                            implied_private_feature_flags,
- *                            implied_winsys_feature)
+ *                            implied_private_egl_feature_flags)
  * COGL_WINSYS_FEATURE_FUNCTION (return_type, function_name,
  *                               (arguments))
  * ...
@@ -46,9 +44,7 @@
 COGL_WINSYS_FEATURE_BEGIN (swap_region,
                            "NOK\0",
                            "swap_region\0",
-                           0,
-                           0,
-                           COGL_WINSYS_FEATURE_SWAP_REGION)
+                           COGL_EGL_WINSYS_FEATURE_SWAP_REGION)
 COGL_WINSYS_FEATURE_FUNCTION (EGLBoolean, eglSwapBuffersRegion,
                               (EGLDisplay dpy,
                                EGLSurface surface,
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index d9da042..3af67c1 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -65,12 +65,21 @@
 #define COGL_ONSCREEN_X11_EVENT_MASK StructureNotifyMask
 #endif
 
+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
+} CoglEGLWinsysFeature;
+
 typedef struct _CoglRendererEGL
 {
 #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
   CoglRendererXlib _parent;
 #endif
 
+  CoglEGLWinsysFeature private_features;
+
 #ifdef COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT
   struct wl_display *wayland_display;
   struct wl_compositor *wayland_compositor;
@@ -87,7 +96,7 @@ typedef struct _CoglRendererEGL
 #endif
 
   /* Function pointers for GLX specific extensions */
-#define COGL_WINSYS_FEATURE_BEGIN(a, b, c, d, e, f)
+#define COGL_WINSYS_FEATURE_BEGIN(a, b, c, d)
 
 #define COGL_WINSYS_FEATURE_FUNCTION(ret, name, args) \
   ret (APIENTRY * pf_ ## name) args;
@@ -159,8 +168,7 @@ typedef struct _CoglOnscreenEGL
 /* Define a set of arrays containing the functions required from GL
    for each winsys feature */
 #define COGL_WINSYS_FEATURE_BEGIN(name, namespaces, extension_names,    \
-                                  feature_flags, feature_flags_private, \
-                                  winsys_feature)                       \
+                                  egl_private_flags)                    \
   static const CoglFeatureFunction                                      \
   cogl_egl_feature_ ## name ## _funcs[] = {
 #define COGL_WINSYS_FEATURE_FUNCTION(ret, name, args)                   \
@@ -173,11 +181,10 @@ typedef struct _CoglOnscreenEGL
 /* Define an array of features */
 #undef COGL_WINSYS_FEATURE_BEGIN
 #define COGL_WINSYS_FEATURE_BEGIN(name, namespaces, extension_names,    \
-                                  feature_flags, feature_flags_private, \
-                                  winsys_feature)                       \
+                                  egl_private_flags)                    \
   { 255, 255, namespaces, extension_names,                              \
-      feature_flags, feature_flags_private,                             \
-      winsys_feature, \
+      0, egl_private_flags,                                             \
+      0,                                                                \
       cogl_egl_feature_ ## name ## _funcs },
 #undef COGL_WINSYS_FEATURE_FUNCTION
 #define COGL_WINSYS_FEATURE_FUNCTION(ret, name, args)
@@ -314,6 +321,31 @@ force_roundtrip(struct wl_display *display)
 }
 #endif
 
+/* Updates all the function pointers */
+static void
+check_egl_extensions (CoglRenderer *renderer)
+{
+  CoglRendererEGL *egl_renderer = renderer->winsys;
+  const CoglWinsysVtable *winsys = renderer->winsys_vtable;
+  const char *egl_extensions;
+  int i;
+
+  egl_extensions = eglQueryString (egl_renderer->edpy, EGL_EXTENSIONS);
+
+  COGL_NOTE (WINSYS, "  EGL Extensions: %s", egl_extensions);
+
+  egl_renderer->private_features = 0;
+  for (i = 0; i < G_N_ELEMENTS (winsys_feature_data); i++)
+    if (_cogl_feature_check (winsys,
+                             "EGL", winsys_feature_data + i, 0, 0,
+                             egl_extensions,
+                             egl_renderer))
+      {
+        egl_renderer->private_features |=
+          winsys_feature_data[0].feature_flags_private;
+      }
+}
+
 static gboolean
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                GError **error)
@@ -445,6 +477,8 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   gdl_close ();
 #endif
 
+  check_egl_extensions (renderer);
+
   return TRUE;
 
 error:
@@ -457,18 +491,14 @@ update_winsys_features (CoglContext *context)
 {
   CoglDisplayEGL *egl_display = context->display->winsys;
   CoglRendererEGL *egl_renderer = context->display->renderer->winsys;
-  const char *egl_extensions;
-  int i;
 
   g_return_if_fail (egl_display->egl_context);
 
-  _cogl_gl_update_features (context);
-
   memset (context->winsys_features, 0, sizeof (context->winsys_features));
 
-  egl_extensions = eglQueryString (egl_renderer->edpy, EGL_EXTENSIONS);
+  check_egl_extensions (context->display->renderer);
 
-  COGL_NOTE (WINSYS, "  EGL Extensions: %s", egl_extensions);
+  _cogl_gl_update_features (context);
 
 #if defined (COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT) || \
     defined (COGL_HAS_EGL_PLATFORM_WAYLAND_SUPPORT)
@@ -478,22 +508,7 @@ update_winsys_features (CoglContext *context)
                   TRUE);
 #endif
 
-  for (i = 0; i < G_N_ELEMENTS (winsys_feature_data); i++)
-    if (_cogl_feature_check (_cogl_context_get_winsys (context),
-                             "EGL", winsys_feature_data + i, 0, 0,
-                             egl_extensions,
-                             egl_renderer))
-      {
-        context->feature_flags |= winsys_feature_data[i].feature_flags;
-        if (winsys_feature_data[i].winsys_feature)
-          COGL_FLAGS_SET (context->winsys_features,
-                          winsys_feature_data[i].winsys_feature,
-                          TRUE);
-      }
-
-  /* FIXME: the winsys_feature_data can currently only have one
-   * winsys feature per extension... */
-  if (egl_renderer->pf_eglSwapBuffersRegion)
+  if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_SWAP_REGION)
     {
       COGL_FLAGS_SET (context->winsys_features,
                       COGL_WINSYS_FEATURE_SWAP_REGION, TRUE);



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