[mutter/wip/carlosg/context-priority: 582/582] cogl/egl: Use EGL_IMG_context_priority



commit 162d6d45a04f40589b7eaa761095b05170015384
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Mar 1 23:52:57 2018 +0100

    cogl/egl: Use EGL_IMG_context_priority
    
    As long as the context_priority extension is available request a high
    priority context, to help the compositor look fluid despite heavy GPU usage
    from other applications at a regular priority.
    
    This becomes sort of pointless if/when unredirection applies, should still
    help with overview/workspace switch animations, or if the application is
    not fullscreen.
    
    Based on a similar patch by Daniel Stone to Weston.

 .../winsys/cogl-winsys-egl-feature-functions.h     |  8 ++++++++
 cogl/cogl/winsys/cogl-winsys-egl-private.h         |  3 ++-
 cogl/cogl/winsys/cogl-winsys-egl.c                 | 23 ++++++++++++++++++++--
 3 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/cogl/cogl/winsys/cogl-winsys-egl-feature-functions.h 
b/cogl/cogl/winsys/cogl-winsys-egl-feature-functions.h
index 17a99f269..b21d8b5ab 100644
--- a/cogl/cogl/winsys/cogl-winsys-egl-feature-functions.h
+++ b/cogl/cogl/winsys/cogl-winsys-egl-feature-functions.h
@@ -147,3 +147,11 @@ COGL_WINSYS_FEATURE_BEGIN (surfaceless_context,
                            "surfaceless_context\0",
                            COGL_EGL_WINSYS_FEATURE_SURFACELESS_CONTEXT)
 COGL_WINSYS_FEATURE_END ()
+
+#ifdef EGL_IMG_context_priority
+COGL_WINSYS_FEATURE_BEGIN (context_priority,
+                           "IMG\0",
+                           "context_priority\0",
+                           COGL_EGL_WINSYS_FEATURE_CONTEXT_PRIORITY)
+COGL_WINSYS_FEATURE_END ()
+#endif
diff --git a/cogl/cogl/winsys/cogl-winsys-egl-private.h b/cogl/cogl/winsys/cogl-winsys-egl-private.h
index d8adfc8d0..2b2883afe 100644
--- a/cogl/cogl/winsys/cogl-winsys-egl-private.h
+++ b/cogl/cogl/winsys/cogl-winsys-egl-private.h
@@ -105,7 +105,8 @@ typedef enum _CoglEGLWinsysFeature
   COGL_EGL_WINSYS_FEATURE_CREATE_CONTEXT                =1L<<3,
   COGL_EGL_WINSYS_FEATURE_BUFFER_AGE                    =1L<<4,
   COGL_EGL_WINSYS_FEATURE_FENCE_SYNC                    =1L<<5,
-  COGL_EGL_WINSYS_FEATURE_SURFACELESS_CONTEXT           =1L<<6
+  COGL_EGL_WINSYS_FEATURE_SURFACELESS_CONTEXT           =1L<<6,
+  COGL_EGL_WINSYS_FEATURE_CONTEXT_PRIORITY              =1L<<7,
 } CoglEGLWinsysFeature;
 
 typedef struct _CoglRendererEGL
diff --git a/cogl/cogl/winsys/cogl-winsys-egl.c b/cogl/cogl/winsys/cogl-winsys-egl.c
index 222e5a6e7..41d300154 100644
--- a/cogl/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/cogl/winsys/cogl-winsys-egl.c
@@ -345,7 +345,7 @@ try_create_context (CoglDisplay *display,
   CoglRendererEGL *egl_renderer = renderer->winsys;
   EGLDisplay edpy;
   EGLConfig config;
-  EGLint attribs[9];
+  EGLint attribs[11];
   EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS];
   GError *config_error = NULL;
   const char *error_message;
@@ -394,7 +394,15 @@ try_create_context (CoglDisplay *display,
       attribs[5] = EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
       attribs[6] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
       attribs[7] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
-      attribs[8] = EGL_NONE;
+
+      if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_CONTEXT_PRIORITY)
+        {
+          attribs[8] = EGL_CONTEXT_PRIORITY_LEVEL_IMG;
+          attribs[9] = EGL_CONTEXT_PRIORITY_HIGH_IMG;
+          attribs[10] = EGL_NONE;
+        }
+      else
+        attribs[8] = EGL_NONE;
     }
   else if (display->renderer->driver == COGL_DRIVER_GLES2)
     {
@@ -416,6 +424,17 @@ try_create_context (CoglDisplay *display,
       goto fail;
     }
 
+  if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_CONTEXT_PRIORITY)
+    {
+      EGLint value = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
+
+      eglQueryContext(egl_renderer->edpy, egl_display->egl_context,
+                      EGL_CONTEXT_PRIORITY_LEVEL_IMG, &value);
+
+      if (value != EGL_CONTEXT_PRIORITY_HIGH_IMG)
+        g_warning ("Failed to obtain high priority context");
+    }
+
   if (egl_renderer->platform_vtable->context_created &&
       !egl_renderer->platform_vtable->context_created (display, error))
     return FALSE;


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