[waffle] [PATCH] add robust access context support

Bas Nieuwenhuizen bas at basnieuwenhuizen.nl
Mon Apr 4 11:31:01 UTC 2016


Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
---
 include/waffle/waffle.h              |  2 ++
 src/waffle/core/wcore_config_attrs.c |  3 +++
 src/waffle/core/wcore_config_attrs.h |  1 +
 src/waffle/core/wcore_util.c         |  1 +
 src/waffle/egl/wegl_config.c         | 16 ++++++++++++++++
 src/waffle/egl/wegl_context.c        |  6 ++++++
 src/waffle/egl/wegl_display.c        |  3 ++-
 src/waffle/egl/wegl_display.h        |  1 +
 src/waffle/glx/glx_config.c          |  7 +++++++
 src/waffle/glx/glx_context.c         |  4 ++++
 src/waffle/glx/glx_display.c         |  1 +
 src/waffle/glx/glx_display.h         |  1 +
 src/waffle/wgl/wgl_config.c          |  7 +++++++
 src/waffle/wgl/wgl_context.c         |  4 ++++
 src/waffle/wgl/wgl_display.h         |  1 +
 15 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h
index df0218e..cd13119 100644
--- a/include/waffle/waffle.h
+++ b/include/waffle/waffle.h
@@ -142,6 +142,8 @@ enum waffle_enum {
     WAFFLE_CONTEXT_DEBUG                                        = 0x0216,
 #endif
 
+    WAFFLE_CONTEXT_ROBUST_ACCESS                                = 0x0217,
+
     WAFFLE_RED_SIZE                                             = 0x0201,
     WAFFLE_GREEN_SIZE                                           = 0x0202,
     WAFFLE_BLUE_SIZE                                            = 0x0203,
diff --git a/src/waffle/core/wcore_config_attrs.c b/src/waffle/core/wcore_config_attrs.c
index 4a2cb5d..9caa0cc 100644
--- a/src/waffle/core/wcore_config_attrs.c
+++ b/src/waffle/core/wcore_config_attrs.c
@@ -54,6 +54,7 @@ check_keys(const int32_t attrib_list[])
             case WAFFLE_CONTEXT_PROFILE:
             case WAFFLE_CONTEXT_FORWARD_COMPATIBLE:
             case WAFFLE_CONTEXT_DEBUG:
+            case WAFFLE_CONTEXT_ROBUST_ACCESS:
             case WAFFLE_RED_SIZE:
             case WAFFLE_GREEN_SIZE:
             case WAFFLE_BLUE_SIZE:
@@ -339,6 +340,7 @@ set_misc_defaults(struct wcore_config_attrs *attrs)
     // [2] EGL 1.4 spec (2011.04.06), Table 3.4
 
     attrs->context_debug        = false;
+    attrs->context_robust       = false;
 
     attrs->rgba_size            = 0;
     attrs->red_size             = 0;
@@ -414,6 +416,7 @@ parse_misc(struct wcore_config_attrs *attrs,
             CASE_INT(WAFFLE_SAMPLES, samples)
 
             CASE_BOOL(WAFFLE_CONTEXT_DEBUG, context_debug, false);
+            CASE_BOOL(WAFFLE_CONTEXT_ROBUST_ACCESS, context_robust, false);
             CASE_BOOL(WAFFLE_SAMPLE_BUFFERS, sample_buffers, DEFAULT_SAMPLE_BUFFERS);
             CASE_BOOL(WAFFLE_DOUBLE_BUFFERED, double_buffered, DEFAULT_DOUBLE_BUFFERED);
             CASE_BOOL(WAFFLE_ACCUM_BUFFER, accum_buffer, DEFAULT_ACCUM_BUFFER);
diff --git a/src/waffle/core/wcore_config_attrs.h b/src/waffle/core/wcore_config_attrs.h
index cca5e8b..e00e517 100644
--- a/src/waffle/core/wcore_config_attrs.h
+++ b/src/waffle/core/wcore_config_attrs.h
@@ -54,6 +54,7 @@ struct wcore_config_attrs {
 
     bool context_forward_compatible;
     bool context_debug;
+    bool context_robust;
     bool double_buffered;
     bool sample_buffers;
     bool accum_buffer;
diff --git a/src/waffle/core/wcore_util.c b/src/waffle/core/wcore_util.c
index c563fae..4c09164 100644
--- a/src/waffle/core/wcore_util.c
+++ b/src/waffle/core/wcore_util.c
@@ -97,6 +97,7 @@ wcore_enum_to_string(int32_t e)
         CASE(WAFFLE_CONTEXT_COMPATIBILITY_PROFILE);
         CASE(WAFFLE_CONTEXT_FORWARD_COMPATIBLE);
         CASE(WAFFLE_CONTEXT_DEBUG);
+        CASE(WAFFLE_CONTEXT_ROBUST_ACCESS);
         CASE(WAFFLE_RED_SIZE);
         CASE(WAFFLE_GREEN_SIZE);
         CASE(WAFFLE_BLUE_SIZE);
diff --git a/src/waffle/egl/wegl_config.c b/src/waffle/egl/wegl_config.c
index a79bc53..1c3f416 100644
--- a/src/waffle/egl/wegl_config.c
+++ b/src/waffle/egl/wegl_config.c
@@ -55,6 +55,22 @@ check_context_attrs(struct wegl_display *dpy,
         return false;
     }
 
+    if (attrs->context_robust && !dpy->EXT_create_context_robustness &&
+        attrs->context_api != WAFFLE_CONTEXT_OPENGL) {
+        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+                     "EGL_EXT_create_context_robustness is required in order to "
+                     "request a robust access context for OpenGL ES");
+        return false;
+    }
+
+    if (attrs->context_robust && !dpy->KHR_create_context &&
+        attrs->context_api == WAFFLE_CONTEXT_OPENGL) {
+        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+                     "EGL_KHR_create_context is required in order to "
+                     "request a robust access context for OpenGL");
+        return false;
+    }
+
     switch (attrs->context_api) {
         case WAFFLE_CONTEXT_OPENGL:
             if (!wcore_config_attrs_version_eq(attrs, 10) && !dpy->KHR_create_context) {
diff --git a/src/waffle/egl/wegl_context.c b/src/waffle/egl/wegl_context.c
index f4ee6cd..00cd251 100644
--- a/src/waffle/egl/wegl_context.c
+++ b/src/waffle/egl/wegl_context.c
@@ -112,6 +112,8 @@ create_real_context(struct wegl_config *config,
                         return EGL_NO_CONTEXT;
                 }
             }
+            if (attrs->context_robust)
+                context_flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
             break;
 
         case WAFFLE_CONTEXT_OPENGL_ES1:
@@ -128,6 +130,10 @@ create_real_context(struct wegl_config *config,
                 assert(attrs->context_minor_version == 0);
             }
 
+            if (attrs->context_robust) {
+                attrib_list[i++] = EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT;
+                attrib_list[i++] = EGL_TRUE;
+            }
             break;
 
         default:
diff --git a/src/waffle/egl/wegl_display.c b/src/waffle/egl/wegl_display.c
index 88fce7a..e185e20 100644
--- a/src/waffle/egl/wegl_display.c
+++ b/src/waffle/egl/wegl_display.c
@@ -49,7 +49,8 @@ get_extensions(struct wegl_display *dpy)
     // pending emission.
     assert(wcore_error_get_code() == 0);
 
-    dpy->KHR_create_context = waffle_is_extension_in_string(extensions, "EGL_KHR_create_context");
+    dpy->EXT_create_context_robustness = waffle_is_extension_in_string(extensions, "EGL_EXT_create_context_robustness");
+    dpy->KHR_create_context            = waffle_is_extension_in_string(extensions, "EGL_KHR_create_context");
 
     return true;
 }
diff --git a/src/waffle/egl/wegl_display.h b/src/waffle/egl/wegl_display.h
index 43b83ef..b82a2ec 100644
--- a/src/waffle/egl/wegl_display.h
+++ b/src/waffle/egl/wegl_display.h
@@ -37,6 +37,7 @@ struct wcore_display;
 struct wegl_display {
     struct wcore_display wcore;
     EGLDisplay egl;
+    bool EXT_create_context_robustness;
     bool KHR_create_context;
 };
 
diff --git a/src/waffle/glx/glx_config.c b/src/waffle/glx/glx_config.c
index 7792aa0..5561e28 100644
--- a/src/waffle/glx/glx_config.c
+++ b/src/waffle/glx/glx_config.c
@@ -68,6 +68,13 @@ glx_config_check_context_attrs(struct glx_display *dpy,
         return false;
     }
 
+    if (attrs->context_robust && !dpy->ARB_create_context_robustness) {
+        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+                     "GLX_ARB_create_context_robustness is required in order to "
+                     "request a robust access context");
+        return false;
+    }
+
     switch (attrs->context_api) {
         case WAFFLE_CONTEXT_OPENGL:
             if (!wcore_config_attrs_version_eq(attrs, 10) && !dpy->ARB_create_context) {
diff --git a/src/waffle/glx/glx_context.c b/src/waffle/glx/glx_context.c
index 1f9290b..c6cd813 100644
--- a/src/waffle/glx/glx_context.c
+++ b/src/waffle/glx/glx_context.c
@@ -151,6 +151,10 @@ glx_context_fill_attrib_list(struct glx_config *config,
         context_flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
     }
 
+    if (attrs->context_robust) {
+        context_flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB;
+    }
+
     if (context_flags != 0) {
         attrib_list[i++] = GLX_CONTEXT_FLAGS_ARB;
         attrib_list[i++] = context_flags;
diff --git a/src/waffle/glx/glx_display.c b/src/waffle/glx/glx_display.c
index 24e967c..0c6851d 100644
--- a/src/waffle/glx/glx_display.c
+++ b/src/waffle/glx/glx_display.c
@@ -63,6 +63,7 @@ glx_display_set_extensions(struct glx_display *self)
 
     self->ARB_create_context                     = waffle_is_extension_in_string(s, "GLX_ARB_create_context");
     self->ARB_create_context_profile             = waffle_is_extension_in_string(s, "GLX_ARB_create_context_profile");
+    self->ARB_create_context_robustness          = waffle_is_extension_in_string(s, "GLX_ARB_create_context_robustness");
     self->EXT_create_context_es_profile          = waffle_is_extension_in_string(s, "GLX_EXT_create_context_es_profile");
 
     // The GLX_EXT_create_context_es2_profile spec, version 4 2012/03/28,
diff --git a/src/waffle/glx/glx_display.h b/src/waffle/glx/glx_display.h
index 4b8f687..b8bb875 100644
--- a/src/waffle/glx/glx_display.h
+++ b/src/waffle/glx/glx_display.h
@@ -46,6 +46,7 @@ struct glx_display {
 
     bool ARB_create_context;
     bool ARB_create_context_profile;
+    bool ARB_create_context_robustness;
     bool EXT_create_context_es_profile;
     bool EXT_create_context_es2_profile;
 };
diff --git a/src/waffle/wgl/wgl_config.c b/src/waffle/wgl/wgl_config.c
index 59a70a6..80d45fc 100644
--- a/src/waffle/wgl/wgl_config.c
+++ b/src/waffle/wgl/wgl_config.c
@@ -71,6 +71,13 @@ wgl_config_check_context_attrs(struct wgl_display *dpy,
         return false;
     }
 
+    if (attrs->context_robust && !dpy->ARB_create_context_robustness) {
+        wcore_errorf(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM,
+                     "WGL_ARB_create_context_robustness is required in order to "
+                     "request a robust access context");
+        return false;
+    }
+
     switch (attrs->context_api) {
         case WAFFLE_CONTEXT_OPENGL:
             if (!wcore_config_attrs_version_eq(attrs, 10) && !dpy->ARB_create_context) {
diff --git a/src/waffle/wgl/wgl_context.c b/src/waffle/wgl/wgl_context.c
index dd45f81..c7a351f 100644
--- a/src/waffle/wgl/wgl_context.c
+++ b/src/waffle/wgl/wgl_context.c
@@ -135,6 +135,10 @@ wgl_context_fill_attrib_list(struct wgl_config *config,
         context_flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
     }
 
+    if (attrs->context_robust) {
+        context_flags |= WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB;
+    }
+
     if (context_flags != 0) {
         attrib_list[i++] = WGL_CONTEXT_FLAGS_ARB;
         attrib_list[i++] = context_flags;
diff --git a/src/waffle/wgl/wgl_display.h b/src/waffle/wgl/wgl_display.h
index d0d94fe..c8dfb81 100644
--- a/src/waffle/wgl/wgl_display.h
+++ b/src/waffle/wgl/wgl_display.h
@@ -55,6 +55,7 @@ struct wgl_display {
 
     bool ARB_create_context;
     bool ARB_create_context_profile;
+    bool ARB_create_context_robustness;
     bool EXT_create_context_es_profile;
     bool EXT_create_context_es2_profile;
     bool ARB_pixel_format;
-- 
2.7.4



More information about the waffle mailing list