3 # Create threads safe wrappers around X11 calls.
5 # Copyright 1998 Kristian Nielsen.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # FIXME: This does not do full C prototype parsing, but relies on
22 # knowledge on how the X11 include files are formatted. It will
23 # probably need to be modified for new include files. It also fails
24 # for certain prototypes (notably those with function pointer
25 # arguments or results), so these must be added manually. And it
26 # relies on a fixed location of X11 includes (/usr/X11R6/include/).
28 # This program expects to be run from Wine's main directory.
30 $X11_include_dir = "/usr/X11/include";
32 $wantfile = "$outdir/X11_calls";
33 @dolist = ("Xlib", "Xresource", "Xutil", "XShm", "xf86dga", "xf86dga2", "xf86vmode", "shape", "xvideo");
35 # First read list of wanted function names.
37 open(WANT
, $wantfile) || die "open";
39 next if /^\s*\#/; # Skip comment lines.
40 next if /^\s*$/; # Skip empty lines.
41 if(/^\s*([a-zA-Z0-9_]+)\s*$/) {
44 die "syntax error in file '$wantfile', in line '$_'";
49 foreach $name (@dolist) {
54 $outfile = "/ts_$lcname";
55 open(OUTC
, ">$outdir/$outfile.c") || die "open";
56 open(OUTH
, ">include/$outfile.h") || die "open";
60 $pre_file = "#ifdef HAVE_X11_XLIB_H\n";
61 $post_file = "#endif /* defined(HAVE_X11_XLIB_H) */\n";
63 if($name eq "Xutil" || $name eq "Xresource" || $name eq "XShm") {
64 $x11_incl = "#include <X11/Xlib.h>\n";
65 # For Xutil, we need X11/Xresource.h for XUniqueContext().
66 $x11_incl .= "#include <X11/Xresource.h>\n" if $name eq "Xutil";
68 if($name eq "xf86dga") {
69 $x11_incl = "#include <X11/Xlib.h>\n";
70 $extensions_dir = "extensions/";
71 $pre_file = "#ifdef HAVE_LIBXXF86DGA\n";
72 $post_file = "#endif /* defined(HAVE_LIBXXF86DGA) */\n";
74 if($name eq "xf86dga2") {
75 $x11_incl = "#include <X11/Xlib.h>\n";
76 $extensions_dir = "extensions/";
77 $pre_file = "#ifdef HAVE_LIBXXF86DGA2\n";
78 $post_file = "#endif /* defined(HAVE_LIBXXF86DGA2) */\n";
79 $inc_name = "xf86dga";
82 $extensions_dir = "extensions/";
83 $pre_file = "#ifdef HAVE_LIBXXSHM\n";
84 $post_file = "#endif /* defined(HAVE_LIBXXSHM) */\n";
86 if($name eq "xf86vmode") {
87 $x11_incl = "#include <X11/Xlib.h>\n";
88 $extensions_dir = "extensions/";
89 $pre_file = "#include \"windef.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n#include \"basetsd.h\"\n";
90 $post_file = "#endif /* defined(HAVE_LIBXXF86VM) */\n";
92 if($name eq "shape") {
93 $extensions_dir = "extensions/";
94 $pre_file = "#ifdef HAVE_LIBXSHAPE\n#include <X11/IntrinsicP.h>\n";
95 $post_file = "#endif /* defined(HAVE_LIBXSHAPE) */\n";
98 if($name eq "xvideo") {
99 $x11_incl = "#include <X11/Xlib.h>\n#include <X11/extensions/Xv.h>\n#include <X11/extensions/XShm.h>\n";
100 $extensions_dir = "extensions/";
101 $pre_file = "#ifdef HAVE_XVIDEO\n";
102 $post_file = "#endif /* defined(HAVE_XVIDEO) */\n";
109 * Thread safe wrappers around $name calls.
110 * Always include this file instead of <X11/$name.h>.
111 * This file was generated automatically by tools/make_X11wrappers
115 #ifndef __WINE_TS_$ucname\_H
116 #define __WINE_TS_$ucname\_H
118 #ifndef __WINE_CONFIG_H
119 # error You must include config.h to use this header
123 $x11_incl#include <X11/$extensions_dir$inc_name.h>
125 extern void (*wine_tsx11_lock)(void);
126 extern void (*wine_tsx11_unlock)(void);
132 * Thread safe wrappers around $name calls.
133 * This file was generated automatically by tools/make_X11wrappers
140 $x11_incl#include <X11/$extensions_dir$inc_name.h>
142 #include "ts_$lcname.h"
146 if ($name eq "XShm") {
147 output_fn
("XShmQueryExtension", "Bool",
148 "Display *", "Display *a0", "a0");
149 output_fn
("XShmQueryVersion", "Bool",
150 "Display *, int *, int *, Bool *",
151 "Display *a0, int *a1, int *a2, Bool *a3", "a0, a1, a2, a3");
152 output_fn
("XShmPixmapFormat", "int",
153 "Display *", "Display *a0", "a0");
154 output_fn
("XShmAttach", Status
,
155 "Display *, XShmSegmentInfo *",
156 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
157 output_fn
("XShmDetach", Status
,
158 "Display *, XShmSegmentInfo *",
159 "Display *a0, XShmSegmentInfo *a1", "a0, a1");
160 output_fn
("XShmPutImage", Status
,
161 "Display *, Drawable, GC, XImage *, int, int, int, int, unsigned int, unsigned int, Bool",
162 "Display *a0, Drawable a1, GC a2, XImage *a3, int a4, int a5, int a6, int a7, unsigned int a8, unsigned int a9, Bool a10", "a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10");
163 output_fn
("XShmGetImage", Status
,
164 "Display *, Drawable, XImage *, int, int, unsigned long",
165 "Display *a0, Drawable a1, XImage *a2, int a3, int a4, unsigned long a5",
166 "a0, a1, a2, a3, a4, a5");
167 output_fn
("XShmCreateImage", "XImage *",
168 "Display *, Visual *, unsigned int, int, char *, XShmSegmentInfo *, unsigned int, unsigned int",
169 "Display *a0, Visual *a1, unsigned int a2, int a3, char *a4, XShmSegmentInfo *a5, unsigned int a6, unsigned int a7",
170 "a0, a1, a2, a3, a4, a5, a6, a7");
171 output_fn
("XShmCreatePixmap", "Pixmap",
172 "Display *, Drawable, char *, XShmSegmentInfo *, unsigned int, unsigned int, unsigned int",
173 "Display *a0, Drawable a1, char *a2, XShmSegmentInfo *a3, unsigned int a4, unsigned int a5, unsigned int a6",
174 "a0, a1, a2, a3, a4, a5, a6");
175 } elsif($name eq "xf86dga") {
176 output_fn
("XF86DGAQueryVersion",Bool
,
177 "Display*,int*,int*",
178 "Display*a0,int*a1,int*a2",
181 output_fn
("XF86DGAQueryExtension",Bool
,
182 "Display*,int*,int*",
183 "Display*a0,int*a1,int*a2",
186 output_fn
("XF86DGAGetVideo",Status
,
187 "Display*,int,char**,int*,int*,int*",
188 "Display*a0,int a1,char**a2,int*a3,int*a4,int*a5",
191 output_fn
("XF86DGADirectVideo",Status
,
193 "Display*a0,int a1,int a2",
196 output_fn
("XF86DGAGetViewPortSize",Status
,
197 "Display*,int,int*,int*",
198 "Display*a0,int a1,int *a2,int *a3",
201 output_fn
("XF86DGASetViewPort",Status
,
202 "Display*,int,int,int",
203 "Display*a0,int a1,int a2,int a3",
206 output_fn
("XF86DGAInstallColormap",Status
,
207 "Display*,int,Colormap",
208 "Display*a0,int a1,Colormap a2",
211 output_fn
("XF86DGAQueryDirectVideo",Status
,
213 "Display*a0,int a1,int *a2",
216 output_fn
("XF86DGAViewPortChanged",Status
,
218 "Display*a0,int a1,int a2",
221 } elsif($name eq "xf86dga2") {
222 output_fn_short
("Bool", "XDGAQueryVersion", "Display*" ,"int*","int*");
223 output_fn_short
("Bool", "XDGAQueryExtension", "Display*" ,"int*","int*");
224 output_fn_short
("XDGAMode*", "XDGAQueryModes", "Display*" ,"int", "int*");
225 output_fn_short
("XDGADevice*", "XDGASetMode", "Display*" ,"int","int");
226 output_fn_short
("Bool", "XDGAOpenFramebuffer", "Display*" ,"int");
227 output_fn_short
("void", "XDGACloseFramebuffer", "Display*" ,"int");
228 output_fn_short
("void", "XDGASetViewport", "Display*" ,"int", "int", "int", "int");
229 output_fn_short
("void", "XDGAInstallColormap", "Display*" , "int", "Colormap");
230 output_fn_short
("Colormap", "XDGACreateColormap", "Display*" ,"int", "XDGADevice*", "int");
231 output_fn_short
("void", "XDGASelectInput", "Display*" ,"int", "long");
232 output_fn_short
("void", "XDGAFillRectangle", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "unsigned long");
233 output_fn_short
("void", "XDGACopyArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int");
234 output_fn_short
("void", "XDGACopyTransparentArea", "Display*" ,"int", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned long");
235 output_fn_short
("int", "XDGAGetViewportStatus", "Display*" ,"int");
236 output_fn_short
("void", "XDGASync", "Display*" ,"int");
237 output_fn_short
("Bool", "XDGASetClientVersion", "Display*");
238 output_fn_short
("void", "XDGAChangePixmapMode", "Display*" ,"int", "int*", "int*", "int");
239 output_fn_short
("void", "XDGAKeyEventToXKeyEvent", "XDGAKeyEvent*" ,"XKeyEvent*");
240 } elsif ($name eq "xvideo") {
241 output_fn_short
("int", "XvQueryExtension", "Display*", "unsigned int*", "unsigned int*", "unsigned int*", "unsigned int*", "unsigned int*");
242 output_fn_short
("int", "XvQueryAdaptors", "Display*", "Window", "unsigned int*", "XvAdaptorInfo**");
243 output_fn_short
("int", "XvQueryEncodings", "Display*", "XvPortID", "unsigned int*", "XvEncodingInfo**");
244 output_fn_short
("int", "XvPutVideo", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
245 output_fn_short
("int", "XvPutStill", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
246 output_fn_short
("int", "XvGetVideo", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
247 output_fn_short
("int", "XvGetStill", "Display*", "XvPortID", "Drawable", "GC", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
248 output_fn_short
("int", "XvStopVideo", "Display*", "XvPortID", "Drawable");
249 output_fn_short
("int", "XvGrabPort", "Display*", "XvPortID", "Time");
250 output_fn_short
("int", "XvUngrabPort", "Display*", "XvPortID", "Time");
251 output_fn_short
("int", "XvSelectVideoNotify", "Display*", "Drawable", "Bool");
252 output_fn_short
("int", "XvSelectPortNotify", "Display*", "XvPortID", "Bool");
253 output_fn_short
("int", "XvSetPortAttribute", "Display*", "XvPortID", "Atom", "int");
254 output_fn_short
("int", "XvGetPortAttribute", "Display*", "XvPortID", "Atom", "int*");
255 output_fn_short
("int", "XvQueryBestSize", "Display*", "XvPortID", "Bool", "unsigned int", "unsigned int", "unsigned int", "unsigned int", "unsigned int*", "unsigned int*");
256 output_fn_short
("XvAttribute*", "XvQueryPortAttributes", "Display*", "XvPortID", "int*");
257 output_fn_short
("void", "XvFreeAdaptorInfo", "XvAdaptorInfo*");
258 output_fn_short
("void", "XvFreeEncodingInfo", "XvEncodingInfo*");
259 output_fn_short
("XvImageFormatValues *", "XvListImageFormats", "Display*", "XvPortID", "int*");
260 output_fn_short
("XvImage *", "XvCreateImage", "Display*", "XvPortID", "int", "char*", "int", "int");
261 output_fn_short
("int", "XvPutImage", "Display*", "XvPortID", "Drawable", "GC", "XvImage*", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int");
262 output_fn_short
("int", "XvShmPutImage", "Display*", "XvPortID", "Drawable", "GC", "XvImage*", "int", "int", "unsigned int", "unsigned int", "int", "int", "unsigned int", "unsigned int", "Bool");
263 output_fn_short
("XvImage *", "XvShmCreateImage", "Display*", "XvPortID", "int", "char*", "int", "int", "XShmSegmentInfo*");
264 } elsif($name eq "xf86vmode") {
265 output_fn
("XF86VidModeQueryVersion",Bool
,
266 "Display*,int*,int*",
267 "Display*a0,int*a1,int*a2",
270 output_fn
("XF86VidModeQueryExtension",Bool
,
271 "Display*,int*,int*",
272 "Display*a0,int*a1,int*a2",
275 output_fn
("XF86VidModeGetModeLine",Bool
,
276 "Display*,int,int*,XF86VidModeModeLine*",
277 "Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
280 output_fn
("XF86VidModeGetAllModeLines",Bool
,
281 "Display*,int,int*,XF86VidModeModeInfo***",
282 "Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
285 output_fn
("XF86VidModeAddModeLine",Bool
,
286 "Display*,int,XF86VidModeModeInfo*,XF86VidModeModeInfo*",
287 "Display*a0,int a1,XF86VidModeModeInfo*a2,XF86VidModeModeInfo*a3",
290 output_fn
("XF86VidModeDeleteModeLine",Bool
,
291 "Display*,int,XF86VidModeModeInfo*",
292 "Display*a0,int a1,XF86VidModeModeInfo*a2",
295 output_fn
("XF86VidModeModModeLine",Bool
,
296 "Display*,int,XF86VidModeModeLine*",
297 "Display*a0,int a1,XF86VidModeModeLine*a2",
300 output_fn
("XF86VidModeValidateModeLine",Status
,
301 "Display*,int,XF86VidModeModeInfo*",
302 "Display*a0,int a1,XF86VidModeModeInfo*a2",
305 output_fn
("XF86VidModeSwitchMode",Bool
,
307 "Display*a0,int a1,int a2",
310 output_fn
("XF86VidModeSwitchToMode",Bool
,
311 "Display*,int,XF86VidModeModeInfo*",
312 "Display*a0,int a1,XF86VidModeModeInfo*a2",
315 output_fn
("XF86VidModeLockModeSwitch",Bool
,
317 "Display*a0,int a1,int a2",
320 output_fn
("XF86VidModeGetMonitor",Bool
,
321 "Display*,int,XF86VidModeMonitor*",
322 "Display*a0,int a1,XF86VidModeMonitor*a2",
325 output_fn
("XF86VidModeGetViewPort",Bool
,
326 "Display*,int,int*,int*",
327 "Display*a0,int a1,int*a2,int*a3",
330 output_fn
("XF86VidModeSetViewPort",Bool
,
331 "Display*,int,int,int",
332 "Display*a0,int a1,int a2,int a3",
338 "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | " .
339 "gcc -L$X11_include_dir -DNeedFunctionPrototypes -E - | " .
340 "grep -v '^[ \t]*\$)' |"
344 if(m
'extern\s+([^()]*)\b([a-zA-Z0-9_]+)\s*\(') {
347 $result_type = "int" if $result_type =~ /^\s*$/;
351 # Give up on vararg functions and function pointer args.
352 if(m
'\.\.\.|\(\*\)') {
356 if(m
'\s*([^,]*[^, \t])\s*(,?\n)') {
357 $args[$#args+1] = $1;
358 if ($1 =~ /char\s*\[/) { # small hack for XQueryKeymap
359 $args[$#args] = "char*";
363 # Skip if vararg, function pointer arg, or not needed.
364 next unless $fn_name;
365 next unless $want{$fn_name} && $want{$fn_name} == 1;
367 # Special case for no arguments (which is specified as "void").
368 if($#args == 0 && $args[0] eq "void") {
374 for($i = 0; $i <= $#args; $i++) {
375 $comma = $i < $#args ?
", " : "";
376 $proto .= "$args[$i]$comma";
377 $formals .= "$args[$i] a$i$comma";
378 $actuals .= "a$i$comma";
380 $proto = $formals = "void" if $#args == -1;
381 output_fn
($fn_name, $result_type, $proto, $formals, $actuals);
386 if($name eq "Xlib") {
387 raw_output_fn
("XSynchronize", "int (*r)(Display *)",
388 "int (*TSXSynchronize(Display *, Bool))(Display *)",
389 "int (*TSXSynchronize(Display *a0, Bool a1))(Display *)",
391 } elsif($name eq "Xutil") {
392 output_fn
("XDestroyImage", "int",
393 "struct _XImage *", "struct _XImage *a0", "a0");
394 output_fn
("XGetPixel", "unsigned long",
395 "struct _XImage *, int, int",
396 "struct _XImage *a0, int a1, int a2",
398 output_fn
("XPutPixel", "int",
399 "struct _XImage *, int, int, unsigned long",
400 "struct _XImage *a0, int a1, int a2, unsigned long a3",
402 output_fn
("XSubImage", "struct _XImage *",
403 "struct _XImage *, int, int, unsigned int, unsigned int",
404 "struct _XImage *a0, int a1, int a2, unsigned int a3, unsigned int a4",
405 "a0, a1, a2, a3, a4");
406 output_fn
("XAddPixel", "int",
407 "struct _XImage *, long",
408 "struct _XImage *a0, long a1", "a0, a1");
409 output_fn
("XUniqueContext", "XContext", "void", "void", "");
410 output_fn
("XDeleteContext", "int",
411 "Display*,XID,XContext",
412 "Display*a0,XID a1,XContext a2",
419 #endif /* __WINE_TS_$ucname\_H */
430 foreach $i (keys %want) {
432 print "Unresolved: $i\n";
439 # output_fn("main", "int", "int, char **", "int a0, char **a1", "a0, a1")
442 my ($fn_name, $result_type, $protos, $formals, $actuals) = @_;
444 return raw_output_fn
($fn_name,
445 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
446 "$result_type TS$fn_name($protos)",
447 "$result_type TS$fn_name($formals)",
451 sub output_fn_short
{
453 # output_fn_sort("Bool", "XDGAQueryExtension", "Display *", "int *", "int *");
455 my ($result_type, $fn_name, @args) = @_;
457 my ($i, $proto, $formals, $actuals) = (0,
458 "$result_type TS$fn_name(",
459 "$result_type TS$fn_name(",
461 while ($val = shift @args) {
462 $proto = $proto . $val;
463 $formals = $formals . $val . " a$i";
464 $actuals = $actuals . " a$i";
467 $proto = $proto . ", ";
468 $formals = $formals . ", ";
469 $actuals = $actuals . ", ";
472 $proto = $proto . ")";
473 $formals = $formals . ")";
476 raw_output_fn
($fn_name,
477 $result_type =~ /^\s*void\s*$/ ?
"" : "$result_type r",
485 # output_fn("main", "int r", "int main(int, char **)", "int main(int a0, char **a1)", "a0, a1")
488 my ($fn_name, $resultdecl, $protodecl, $defdecl, $actuals) = @_;
490 return undef unless $want{$fn_name} && $want{$fn_name} == 1;
492 print OUTC
"\n$defdecl\n";
493 print OUTH
"extern $protodecl;\n";
494 # print OUTH "#define $fn_name TS$fn_name\n";
496 print OUTC
" $resultdecl;\n" if $resultdecl;
497 print OUTC
" wine_tsx11_lock();\n";
499 print OUTC
"r = " if $resultdecl;
500 print OUTC
"$fn_name($actuals);\n";
501 print OUTC
" wine_tsx11_unlock();\n";
502 print OUTC
" return r;\n" if $resultdecl;