Added DECL_GLOBAL_CONSTRUCTOR macro.
[wine.git] / dlls / ddraw / dga.c
blobc8ce82d3ebcebcb462e04c6223bff6bebfb388e0
1 /* DirectDraw using DGA
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 1998-2000 Lionel Ulmer (most of Direct3D stuff)
5 */
6 /* XF86DGA:
7 * When DirectVideo mode is enabled you can no longer use 'normal' X
8 * applications nor can you switch to a virtual console. Also, enabling
9 * only works, if you have switched to the screen where the application
10 * is running.
11 * Some ways to debug this stuff are:
12 * - A terminal connected to the serial port. Can be bought used for cheap.
13 * (This is the method I am using.)
14 * - Another machine connected over some kind of network.
17 #include "config.h"
18 #include "winerror.h"
20 #include <unistd.h>
21 #include <assert.h>
22 #ifdef HAVE_SYS_SIGNAL_H
23 # include <sys/signal.h>
24 #endif
25 #include <fcntl.h>
26 #include <string.h>
27 #include <stdio.h>
29 #include "gdi.h"
30 #include "heap.h"
31 #include "dc.h"
32 #include "win.h"
33 #include "wine/exception.h"
34 #include "ddraw.h"
35 #include "d3d.h"
36 #include "debugtools.h"
37 #include "spy.h"
38 #include "message.h"
39 #include "options.h"
40 #include "monitor.h"
42 #include "dga_private.h"
44 #define RESTORE__SIGNALS
46 DEFAULT_DEBUG_CHANNEL(ddraw);
48 #ifdef HAVE_LIBXXF86VM
49 XF86VidModeModeInfo *orig_mode = NULL;
50 #endif
52 static inline BOOL get_option( const char *name, BOOL def ) {
53 return PROFILE_GetWineIniBool( "x11drv", name, def );
56 static BYTE
57 DDRAW_DGA_Available(void)
59 int fd, evbase, evret, majver, minver;
60 static BYTE return_value = 0xFF;
62 /* This prevents from probing X times for DGA */
63 if (return_value != 0xFF)
64 return return_value;
66 if (!get_option( "UseDGA", 1 )) {
67 TRACE("UseDGA disabled.\n");
68 return_value = 0;
69 return 0;
72 /* First, query the extenstion and its version */
73 if (!TSXF86DGAQueryExtension(display,&evbase,&evret)) {
74 TRACE("DGA extension not detected.\n");
75 return_value = 0;
76 return 0;
79 if (!TSXF86DGAQueryVersion(display,&majver,&minver)) {
80 TRACE("DGA version not detected.\n");
81 return_value = 0;
82 return 0;
85 /* You don't have to be root to use DGA extensions. Simply having access
86 * to /dev/mem will do the trick
87 * This can be achieved by adding the user to the "kmem" group on
88 * Debian 2.x systems, don't know about
89 * others. --stephenc
91 if ((fd = open("/dev/mem", O_RDWR)) != -1)
92 close(fd);
94 if (fd != -1)
95 return_value = 1;
96 else {
97 TRACE("You have no access to /dev/mem\n");
98 return_value = 0;
100 return return_value;
103 HRESULT
104 DGA_Create( LPDIRECTDRAW *lplpDD ) {
105 IDirectDrawImpl* ddraw;
106 dga_dd_private* dgpriv;
107 int memsize,banksize,major,minor,flags;
108 char *addr;
109 int depth;
110 int dga_version;
111 int width, height;
113 /* Get DGA availability / version */
114 dga_version = DDRAW_DGA_Available();
115 if (dga_version == 0)
116 return DDERR_GENERIC;
118 /* If we were just testing ... return OK */
119 if (lplpDD == NULL)
120 return DD_OK;
122 ddraw = (IDirectDrawImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawImpl));
123 *lplpDD = (LPDIRECTDRAW)ddraw;
124 ddraw->ref = 1;
125 ICOM_VTBL(ddraw) = &dga_ddvt;
127 ddraw->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(dga_dd_private));
129 dgpriv = (dga_dd_private*)ddraw->private;
131 TSXF86DGAQueryVersion(display,&major,&minor);
132 TRACE("XF86DGA is version %d.%d\n",major,minor);
134 TSXF86DGAQueryDirectVideo(display,DefaultScreen(display),&flags);
135 if (!(flags & XF86DGADirectPresent))
136 MESSAGE("direct video is NOT PRESENT.\n");
137 TSXF86DGAGetVideo(display,DefaultScreen(display),&addr,&width,&banksize,&memsize);
138 dgpriv->fb_width = width;
139 TSXF86DGAGetViewPortSize(display,DefaultScreen(display),&width,&height);
140 TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
141 dgpriv->fb_height = height;
142 TRACE("video framebuffer: begin %p, width %d,banksize %d,memsize %d\n",
143 addr,width,banksize,memsize
145 TRACE("viewport height: %d\n",height);
146 /* Get the screen dimensions as seen by Wine.
147 * In that case, it may be better to ignore the -desktop mode and
148 * return the real screen size => print a warning
150 ddraw->d.height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
151 ddraw->d.width = MONITOR_GetWidth(&MONITOR_PrimaryMonitor);
152 if ((ddraw->d.height != height) || (ddraw->d.width != width))
153 WARN("You seem to be running in -desktop mode. This may prove dangerous in DGA mode...\n");
154 dgpriv->fb_addr = addr;
155 dgpriv->fb_memsize = memsize;
156 dgpriv->vpmask = 0;
158 /* The cast is because DGA2's install colormap does not return a value whereas
159 DGA1 version does */
160 dgpriv->InstallColormap = (void (*)(Display *, int, Colormap)) TSXF86DGAInstallColormap;
162 /* just assume the default depth is the DGA depth too */
163 depth = DefaultDepthOfScreen(X11DRV_GetXScreen());
165 _common_depth_to_pixelformat(depth, &(ddraw->d.directdraw_pixelformat), &(ddraw->d.screen_pixelformat), NULL);
167 #ifdef RESTORE_SIGNALS
168 SIGNAL_Init();
169 #endif
171 return DD_OK;
174 /* Where do these GUIDs come from? mkuuid.
175 * They exist solely to distinguish between the targets Wine support,
176 * and should be different than any other GUIDs in existence.
178 static GUID DGA_DirectDraw_GUID = { /* e2dcb020-dc60-11d1-8407-9714f5d50802 */
179 0xe2dcb020,
180 0xdc60,
181 0x11d1,
182 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x02}
185 ddraw_driver dga_driver = {
186 &DGA_DirectDraw_GUID,
187 "display",
188 "WINE XF86DGA DirectDraw Driver",
189 100,
190 DGA_Create
193 DECL_GLOBAL_CONSTRUCTOR(DGA_register) { ddraw_register_driver(&dga_driver); }