glx: implement __DRIbackgroundCallableExtension.isThreadSafe
authorGregory Hainaut <gregory.hainaut@gmail.com>
Mon, 29 May 2017 11:18:26 +0000 (13:18 +0200)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 29 May 2017 16:06:49 +0000 (17:06 +0100)
v2:
bump version

v3:
Add code comment
s/IsGlThread/IsThread/ (and variation)

v4:
DRI3 doesn't hit X through GL call so it is always safe

Signed-off-by: Gregory Hainaut <gregory.hainaut@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/glx/dri2_glx.c
src/glx/dri3_glx.c

index 145f44d6e8cffee23f3fffa5cbee31852cb480b4..4f163688f2c3ba65864c21d406012f091545bf65 100644 (file)
@@ -953,6 +953,18 @@ driSetBackgroundContext(void *loaderPrivate)
    __glXSetCurrentContext(&pcp->base);
 }
 
+static GLboolean
+driIsThreadSafe(void *loaderPrivate)
+{
+   struct dri2_context *pcp = (struct dri2_context *) loaderPrivate;
+   /* Check Xlib is running in thread safe mode
+    *
+    * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
+    * It wll be NULL if XInitThreads wasn't called.
+    */
+   return pcp->base.psc->dpy->lock_fns != NULL;
+}
+
 static const __DRIdri2LoaderExtension dri2LoaderExtension = {
    .base = { __DRI_DRI2_LOADER, 3 },
 
@@ -974,9 +986,10 @@ static const __DRIuseInvalidateExtension dri2UseInvalidate = {
 };
 
 static const __DRIbackgroundCallableExtension driBackgroundCallable = {
-   .base = { __DRI_BACKGROUND_CALLABLE, 1 },
+   .base = { __DRI_BACKGROUND_CALLABLE, 2 },
 
    .setBackgroundContext    = driSetBackgroundContext,
+   .isThreadSafe            = driIsThreadSafe,
 };
 
 _X_HIDDEN void
index e1dc5aa4a83a9ea0768058b66b36ebbcb7021d56..d07968e3c5e24e107ce0d2dffb70eac56a058c90 100644 (file)
@@ -503,6 +503,15 @@ dri_set_background_context(void *loaderPrivate)
    __glXSetCurrentContext(&pcp->base);
 }
 
+static GLboolean
+dri_is_thread_safe(void *loaderPrivate)
+{
+   /* Unlike DRI2, DRI3 doesn't call GetBuffers/GetBuffersWithFormat
+    * during draw so we're safe here.
+    */
+   return true;
+}
+
 /* The image loader extension record for DRI3
  */
 static const __DRIimageLoaderExtension imageLoaderExtension = {
@@ -517,9 +526,10 @@ const __DRIuseInvalidateExtension dri3UseInvalidate = {
 };
 
 static const __DRIbackgroundCallableExtension driBackgroundCallable = {
-   .base = { __DRI_BACKGROUND_CALLABLE, 1 },
+   .base = { __DRI_BACKGROUND_CALLABLE, 2 },
 
    .setBackgroundContext = dri_set_background_context,
+   .isThreadSafe         = dri_is_thread_safe,
 };
 
 static const __DRIextension *loader_extensions[] = {