From 00d5d77ddca9ff8e70d3272b4e5ea6d1a3035b57 Mon Sep 17 00:00:00 2001
From: Lionel Ulmer <lionel.ulmer@free.fr>
Date: Sat, 29 Apr 2000 17:16:53 +0000
Subject: [PATCH] - added thread-safety protection to XListPixmapFormats -
 moved pixmap / image format matching ERRs to WARNs

---
 dlls/ddraw/ddraw/x11.c | 16 ++++++++--------
 include/ts_xlib.h      |  1 +
 tsx11/X11_calls        |  1 +
 tsx11/ts_xlib.c        | 11 +++++++++++
 4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/dlls/ddraw/ddraw/x11.c b/dlls/ddraw/ddraw/x11.c
index 92a3e84a067..a6c5d2ab939 100644
--- a/dlls/ddraw/ddraw/x11.c
+++ b/dlls/ddraw/ddraw/x11.c
@@ -49,7 +49,7 @@ int _common_depth_to_pixelformat(
   int index = -2;
 
   vi = TSXGetVisualInfo(display, VisualNoMask, &vt, &nvisuals);
-  pf = XListPixmapFormats(display, &npixmap);
+  pf = TSXListPixmapFormats(display, &npixmap);
 
   for (i = 0; i < npixmap; i++) {
     if (pf[i].depth == depth) {
@@ -83,7 +83,7 @@ int _common_depth_to_pixelformat(
 	  goto clean_up_and_exit;
 	}
       }
-      ERR("No visual corresponding to pixmap format !\n");
+      WARN("No visual corresponding to pixmap format !\n");
     }
   }
 
@@ -694,7 +694,7 @@ static HRESULT WINAPI Xlib_IDirectDraw2Impl_EnumDisplayModes(
   maxHeight = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
   
   vi = TSXGetVisualInfo(display, VisualNoMask, &vt, &nvisuals);
-  pf = XListPixmapFormats(display, &npixmap);
+  pf = TSXListPixmapFormats(display, &npixmap);
 
   i = 0;
   emu = 0;
@@ -734,8 +734,8 @@ static HRESULT WINAPI Xlib_IDirectDraw2Impl_EnumDisplayModes(
 	  
 	  has_mode[mode_index] = 1;
 	} else {
-      /* All the 'true color' depths (15, 16 and 24)
-	 First, find the corresponding visual to extract the bit masks */
+	  /* All the 'true color' depths (15, 16 and 24)
+	     First, find the corresponding visual to extract the bit masks */
 	  for (j = 0; j < nvisuals; j++) {
 	    if (vi[j].depth == pf[i].depth) {
 	      ddsfd.ddsCaps.dwCaps = 0;
@@ -756,7 +756,7 @@ static HRESULT WINAPI Xlib_IDirectDraw2Impl_EnumDisplayModes(
 	    }
 	  }
 	  if (j == nvisuals)
-	    ERR("Did not find visual corresponding the the pixmap format !\n");
+	    WARN("Did not find visual corresponding the the pixmap format !\n");
 	}
       }
       i++;
@@ -787,7 +787,7 @@ static HRESULT WINAPI Xlib_IDirectDraw2Impl_EnumDisplayModes(
 		      ddsfd.ddpfPixelFormat.u1.dwRBitMask = 0;
 		      ddsfd.ddpfPixelFormat.u2.dwGBitMask = 0;
 		      ddsfd.ddpfPixelFormat.u3.dwBBitMask = 0;
-    } else {
+		    } else {
 		      ddsfd.ddpfPixelFormat.dwFlags = DDPF_RGB;
 		      ddsfd.ddpfPixelFormat.u.dwRGBBitCount = ModeEmulations[c].dest.bpp;
 		      ddsfd.ddpfPixelFormat.u1.dwRBitMask = ModeEmulations[c].dest.rmask;
@@ -799,7 +799,7 @@ static HRESULT WINAPI Xlib_IDirectDraw2Impl_EnumDisplayModes(
 		  }
 		  
 		  if (send_mode == 0)
-		    ERR("No visual corresponding to pixmap format !\n");
+		    WARN("No visual corresponding to pixmap format !\n");
 		}
 	      }
 	    }
diff --git a/include/ts_xlib.h b/include/ts_xlib.h
index a5208307fde..72d300ba142 100644
--- a/include/ts_xlib.h
+++ b/include/ts_xlib.h
@@ -38,6 +38,7 @@ extern KeySym  TSXLookupKeysym(XKeyEvent*, int);
 extern KeySym * TSXGetKeyboardMapping(Display*, unsigned int, int, int*);
 extern char * TSXResourceManagerString(Display*);
 extern int   TSXInitThreads(void);
+extern XPixmapFormatValues * TSXListPixmapFormats(Display*, int*);
 extern int * TSXListDepths(Display*, int, int*);
 extern int   TSXReconfigureWMWindow(Display*, Window, int, unsigned int, XWindowChanges*);
 extern int   TSXSetWMProtocols(Display*, Window, Atom*, int);
diff --git a/tsx11/X11_calls b/tsx11/X11_calls
index 1a7a121d1ff..5a558ca5923 100644
--- a/tsx11/X11_calls
+++ b/tsx11/X11_calls
@@ -91,6 +91,7 @@ XKeysymToKeycode
 XKeysymToString
 XListDepths
 XListFonts
+XListPixmapFormats
 XLoadQueryFont
 XLookupKeysym
 XLookupString
diff --git a/tsx11/ts_xlib.c b/tsx11/ts_xlib.c
index c54e3668c9c..a5763f3d379 100644
--- a/tsx11/ts_xlib.c
+++ b/tsx11/ts_xlib.c
@@ -277,6 +277,17 @@ int   TSXInitThreads(void)
   return r;
 }
 
+XPixmapFormatValues * TSXListPixmapFormats(Display* a0, int* a1)
+{
+  XPixmapFormatValues * r;
+  TRACE("Call XListPixmapFormats\n");
+  EnterCriticalSection( &X11DRV_CritSection );
+  r = XListPixmapFormats(a0, a1);
+  LeaveCriticalSection( &X11DRV_CritSection );
+  TRACE("Ret XListPixmapFormats\n");
+  return r;
+}
+
 int * TSXListDepths(Display* a0, int a1, int* a2)
 {
   int * r;
-- 
GitLab