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