1 /* DirectDraw using DGA2
3 * Based (well, plagiarized :-) ) on Marcus' dga.c
11 #ifdef HAVE_SYS_SIGNAL_H
12 # include <sys/signal.h>
22 #include "wine/exception.h"
25 #include "debugtools.h"
30 #include "dga2_private.h"
32 DEFAULT_DEBUG_CHANNEL(ddraw
);
34 static inline BOOL
get_option( const char *name
, BOOL def
) {
35 return PROFILE_GetWineIniBool( "x11drv", name
, def
);
39 DDRAW_DGA2_Available(void)
41 int evbase
, evret
, majver
, minver
;
42 static BYTE return_value
= 0xFF;
44 /* This prevents from probing X times for DGA */
45 if (return_value
!= 0xFF)
48 if (!get_option( "UseDGA", 1 )) {
49 TRACE("UseDGA disabled.\n");
54 /* First, query the extenstion and its version */
55 if (!TSXF86DGAQueryExtension(display
,&evbase
,&evret
)) {
56 TRACE("DGA extension not detected.\n");
61 if (!TSXF86DGAQueryVersion(display
,&majver
,&minver
)) {
62 TRACE("DGA version not detected.\n");
68 /* We have DGA 2.0 available ! */
69 if (TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
70 TSXDGACloseFramebuffer(display
, DefaultScreen(display
));
81 DGA2_Create( LPDIRECTDRAW
*lplpDD
) {
82 IDirectDrawImpl
* ddraw
;
83 dga2_dd_private
* dgpriv
;
90 /* Get DGA availability / version */
91 dga_version
= DDRAW_DGA2_Available();
95 /* If we were just testing ... return OK */
99 ddraw
= (IDirectDrawImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawImpl
));
100 *lplpDD
= (LPDIRECTDRAW
)ddraw
;
102 ICOM_VTBL(ddraw
) = &dga2_ddvt
;
104 ddraw
->d
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*(ddraw
->d
)));
106 ddraw
->d
->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(dga2_dd_private
));
108 dgpriv
= (dga2_dd_private
*)ddraw
->d
->private;
110 TSXDGAQueryVersion(display
,&major
,&minor
);
111 TRACE("XDGA is version %d.%d\n",major
,minor
);
113 TRACE("Opening the frame buffer.\n");
114 if (!TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
115 ERR("Error opening the frame buffer !!!\n");
116 return DDERR_GENERIC
;
119 /* List all available modes */
120 modes
= TSXDGAQueryModes(display
, DefaultScreen(display
), &num_modes
);
121 dgpriv
->modes
= modes
;
122 dgpriv
->num_modes
= num_modes
;
124 TRACE("Available modes :\n");
125 for (i
= 0; i
< num_modes
; i
++) {
126 if (TRACE_ON(ddraw
)) {
127 DPRINTF(" %d) - %s (FB: %dx%d / VP: %dx%d) - depth %d -",
129 modes
[i
].name
, modes
[i
].imageWidth
, modes
[i
].imageHeight
,
130 modes
[i
].viewportWidth
, modes
[i
].viewportHeight
,
133 #define XX(x) if (modes[i].flags & x) DPRINTF(" "#x" ");
134 XX(XDGAConcurrentAccess
);
135 XX(XDGASolidFillRect
);
137 XX(XDGABlitTransRect
);
142 if ((GetSystemMetrics(SM_CYSCREEN
) == modes
[i
].viewportHeight
) &&
143 (GetSystemMetrics(SM_CXSCREEN
) == modes
[i
].viewportWidth
) &&
144 (X11DRV_GetDepth() == modes
[i
].depth
)
146 mode_to_use
= modes
[i
].num
;
149 if (mode_to_use
== 0) {
150 ERR("Could not find mode !\n");
153 TRACE("Using mode number %d\n", mode_to_use
);
156 dgpriv
->DGA
.InstallColormap
= TSXDGAInstallColormap
;
158 /* Initialize the frame buffer */
159 _DGA2_Initialize_FrameBuffer(ddraw
, mode_to_use
);
161 /* Register frame buffer with the kernel, it is a potential DIB section */
162 VirtualAlloc(dgpriv
->DGA
.fb_addr
, dgpriv
->DGA
.fb_memsize
, MEM_RESERVE
|MEM_SYSTEM
, PAGE_READWRITE
);
164 /* Set the input handling for relative mouse movements */
165 X11DRV_EVENT_SetInputMethod(X11DRV_INPUT_RELATIVE
);
170 /* Where do these GUIDs come from? mkuuid.
171 * They exist solely to distinguish between the targets Wine support,
172 * and should be different than any other GUIDs in existence.
174 static GUID DGA2_DirectDraw_GUID
= { /* e2dcb020-dc60-11d1-8407-9714f5d50803 */
178 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x03}
181 ddraw_driver dga2_driver
= {
182 &DGA2_DirectDraw_GUID
,
184 "WINE XF86DGA2 DirectDraw Driver",
189 DECL_GLOBAL_CONSTRUCTOR(DGA2_register
) { ddraw_register_driver(&dga2_driver
); }