Merged msacm and msacm32 dlls.
[wine] / dlls / ddraw / x11.c
1 /*              DirectDraw using DGA or Xlib(XSHM)
2  *
3  * Copyright 1997-1999 Marcus Meissner
4  * Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
5  */
6 #include "config.h"
7
8 #include <unistd.h>
9 #include <assert.h>
10 #include <fcntl.h>
11 #include <string.h>
12 #include <stdio.h>
13
14 #include "winerror.h"
15 #include "options.h"
16 #include "monitor.h"
17 #include "debugtools.h"
18 #include "ddraw.h"
19
20 DEFAULT_DEBUG_CHANNEL(ddraw);
21
22 #include "x11_private.h"
23
24 #ifdef HAVE_LIBXXSHM
25 int XShmErrorFlag = 0;
26 #endif
27
28 static inline BOOL get_option( const char *name, BOOL def ) {
29     return PROFILE_GetWineIniBool( "x11drv", name, def );
30 }
31
32 static BOOL
33 DDRAW_XSHM_Available(void) {
34 #ifdef HAVE_LIBXXSHM
35     if (get_option( "UseXShm", 1 )) {
36         if (TSXShmQueryExtension(display)) {
37             int         major,minor;
38             Bool        shpix;
39
40             if (TSXShmQueryVersion(display, &major, &minor, &shpix))
41                 return TRUE;
42         }
43     }
44 #endif
45     return FALSE;
46 }
47
48 static HRESULT X11_Create( LPDIRECTDRAW *lplpDD ) {
49     IDirectDrawImpl*    ddraw;
50     int                 depth;
51     x11_dd_private      *x11priv;
52
53     if (lplpDD == NULL) /* Testing ... this driver works all the time */
54         return DD_OK;
55
56     *lplpDD = (LPDIRECTDRAW)HeapAlloc(
57         GetProcessHeap(),
58         HEAP_ZERO_MEMORY,
59         sizeof(IDirectDrawImpl)
60     );
61     ddraw = (IDirectDrawImpl*)*lplpDD;
62     ICOM_VTBL(ddraw)= &xlib_ddvt;
63     ddraw->ref  = 1;
64
65     ddraw->d = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*(ddraw->d)));
66     ddraw->d->ref = 1;
67     ddraw->d->private   = HeapAlloc(
68         GetProcessHeap(),
69         HEAP_ZERO_MEMORY,
70         sizeof(x11_dd_private)
71     );
72     x11priv = (x11_dd_private*)ddraw->d->private;
73
74     /* At DirectDraw creation, the depth is the default depth */
75     depth = DefaultDepthOfScreen(X11DRV_GetXScreen());
76
77     switch (_common_depth_to_pixelformat(depth,(LPDIRECTDRAW)ddraw)) {
78     case -2: ERR("no depth conversion mode for depth %d found\n",depth); break;
79     case -1: WARN("No conversion needed for depth %d.\n",depth); break;
80     case 0: MESSAGE("Conversion needed from %d.\n",depth); break;
81     }
82
83     ddraw->d->height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
84     ddraw->d->width = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
85 #ifdef HAVE_LIBXXSHM
86     /* Test if XShm is available. */
87     if ((x11priv->xshm_active = DDRAW_XSHM_Available())) {
88         x11priv->xshm_compl = 0;
89         TRACE("Using XShm extension.\n");
90     }
91 #endif
92     return DD_OK;
93 }
94
95 /* Where do these GUIDs come from?  mkuuid.
96  * They exist solely to distinguish between the targets Wine support,
97  * and should be different than any other GUIDs in existence.
98  */
99 static GUID X11_DirectDraw_GUID = { /* 1574a740-dc61-11d1-8407-f7875a7d1879 */
100     0x1574a740,
101     0xdc61,
102     0x11d1,
103     {0x84, 0x07, 0xf7, 0x87, 0x5a, 0x7d, 0x18, 0x79}
104 };
105
106 ddraw_driver x11_driver = {
107     &X11_DirectDraw_GUID,
108     "display",
109     "WINE X11 DirectDraw Driver",
110     50,
111     X11_Create
112 }; 
113
114 DECL_GLOBAL_CONSTRUCTOR(X11_register) { ddraw_register_driver(&x11_driver); }