[Mesa-dev] [PATCH 06/26] egl: Implement __DRI_BACKGROUND_CALLABLE

Marek Olšák maraeo at gmail.com
Wed Feb 8 18:03:20 UTC 2017


From: Eric Anholt <eric at anholt.net>

---
 src/egl/drivers/dri2/egl_dri2.c     | 14 ++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h     |  1 +
 src/egl/drivers/dri2/platform_x11.c |  2 ++
 src/egl/main/eglcontext.c           |  2 +-
 src/egl/main/eglcontext.h           |  3 +++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 94b7c20..da26b4e 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -76,20 +76,34 @@
 #endif
 
 #ifndef DRM_FORMAT_R16
 #define DRM_FORMAT_R16           fourcc_code('R', '1', '6', ' ') /* [15:0] R 16 little endian */
 #endif
 
 #ifndef DRM_FORMAT_GR1616
 #define DRM_FORMAT_GR1616        fourcc_code('G', 'R', '3', '2') /* [31:0] R:G 16:16 little endian */
 #endif
 
+static void
+dri_set_background_context(void *loaderPrivate)
+{
+   _EGLContext *ctx = _eglGetCurrentContext();
+   _EGLThreadInfo *t = _eglGetCurrentThread();
+
+   _eglBindContextToThread(ctx, t);
+}
+
+const __DRIbackgroundCallableExtension background_callable_extension = {
+   { __DRI_BACKGROUND_CALLABLE, __DRI_BACKGROUND_CALLABLE_VERSION },
+   dri_set_background_context,
+};
+
 const __DRIuseInvalidateExtension use_invalidate = {
    .base = { __DRI_USE_INVALIDATE, 1 }
 };
 
 EGLint dri2_to_egl_attribute_map[] = {
    0,
    EGL_BUFFER_SIZE,                /* __DRI_ATTRIB_BUFFER_SIZE */
    EGL_LEVEL,                        /* __DRI_ATTRIB_LEVEL */
    EGL_RED_SIZE,                /* __DRI_ATTRIB_RED_SIZE */
    EGL_GREEN_SIZE,                /* __DRI_ATTRIB_GREEN_SIZE */
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index f3437e2..4a093cb 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -335,20 +335,21 @@ struct dri2_egl_sync {
 #define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
 
 /* standard typecasts */
 _EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
 _EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
 _EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
 
 extern const __DRIimageLookupExtension image_lookup_extension;
 extern const __DRIuseInvalidateExtension use_invalidate;
+extern const __DRIbackgroundCallableExtension background_callable_extension;
 
 EGLBoolean
 dri2_load_driver(_EGLDisplay *disp);
 
 /* Helper for platforms not using dri2_create_screen */
 void
 dri2_setup_screen(_EGLDisplay *disp);
 
 EGLBoolean
 dri2_load_driver_swrast(_EGLDisplay *disp);
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index c5bb973..2f1086e 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -1416,26 +1416,28 @@ static const __DRIdri2LoaderExtension dri2_loader_extension = {
    .base = { __DRI_DRI2_LOADER, 3 },
 
    .getBuffers           = dri2_x11_get_buffers,
    .flushFrontBuffer     = dri2_x11_flush_front_buffer,
    .getBuffersWithFormat = dri2_x11_get_buffers_with_format,
 };
 
 static const __DRIextension *dri2_loader_extensions_old[] = {
    &dri2_loader_extension_old.base,
    &image_lookup_extension.base,
+   &background_callable_extension.base,
    NULL,
 };
 
 static const __DRIextension *dri2_loader_extensions[] = {
    &dri2_loader_extension.base,
    &image_lookup_extension.base,
+   &background_callable_extension.base,
    NULL,
 };
 
 static EGLBoolean
 dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
 {
    struct dri2_egl_display *dri2_dpy;
 
    dri2_dpy = calloc(1, sizeof *dri2_dpy);
    if (!dri2_dpy)
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index 5313e1da..05cc523 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -576,21 +576,21 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c,
 
    return EGL_TRUE;
 }
 
 
 /**
  * Bind the context to the thread and return the previous context.
  *
  * Note that the context may be NULL.
  */
-static _EGLContext *
+_EGLContext *
 _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t)
 {
    _EGLContext *oldCtx;
 
    oldCtx = t->CurrentContext;
    if (ctx != oldCtx) {
       if (oldCtx)
          oldCtx->Binding = NULL;
       if (ctx)
          ctx->Binding = t;
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 69bf77d..f2fe806 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -75,20 +75,23 @@ _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
 
 extern EGLBoolean
 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
 
 
 extern EGLBoolean
 _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
                 _EGLContext **old_ctx,
                 _EGLSurface **old_draw, _EGLSurface **old_read);
 
+extern _EGLContext *
+_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
+
 
 /**
  * Increment reference count for the context.
  */
 static inline _EGLContext *
 _eglGetContext(_EGLContext *ctx)
 {
    if (ctx)
       _eglGetResource(&ctx->Resource);
    return ctx;
-- 
2.7.4



More information about the mesa-dev mailing list