1 /* DirectDraw using DGA2
3 * Based (well, plagiarized :-) ) on Marcus' dga.c
11 #ifdef HAVE_SYS_SIGNAL_H
12 # include <sys/signal.h>
20 #include "wine/exception.h"
23 #include "debugtools.h"
26 #include "dga2_private.h"
28 DEFAULT_DEBUG_CHANNEL(ddraw
);
30 static inline BOOL
get_option( const char *name
, BOOL def
) {
31 return PROFILE_GetWineIniBool( "x11drv", name
, def
);
35 DDRAW_DGA2_Available(void)
37 int evbase
, evret
, majver
, minver
;
38 static BYTE return_value
= 0xFF;
40 /* This prevents from probing X times for DGA */
41 if (return_value
!= 0xFF)
44 if (!get_option( "UseDGA", 1 )) {
45 TRACE("UseDGA disabled.\n");
50 /* First, query the extenstion and its version */
51 if (!TSXF86DGAQueryExtension(display
,&evbase
,&evret
)) {
52 TRACE("DGA extension not detected.\n");
57 if (!TSXF86DGAQueryVersion(display
,&majver
,&minver
)) {
58 TRACE("DGA version not detected.\n");
64 /* We have DGA 2.0 available ! */
65 if (TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
66 TSXDGACloseFramebuffer(display
, DefaultScreen(display
));
77 DGA2_Create( LPDIRECTDRAW
*lplpDD
) {
78 IDirectDrawImpl
* ddraw
;
79 dga2_dd_private
* dgpriv
;
86 /* Get DGA availability / version */
87 dga_version
= DDRAW_DGA2_Available();
91 /* If we were just testing ... return OK */
95 ddraw
= (IDirectDrawImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawImpl
));
96 *lplpDD
= (LPDIRECTDRAW
)ddraw
;
98 ICOM_VTBL(ddraw
) = &dga2_ddvt
;
100 ddraw
->d
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*(ddraw
->d
)));
102 ddraw
->d
->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(dga2_dd_private
));
104 dgpriv
= (dga2_dd_private
*)ddraw
->d
->private;
106 TSXDGAQueryVersion(display
,&major
,&minor
);
107 TRACE("XDGA is version %d.%d\n",major
,minor
);
109 TRACE("Opening the frame buffer.\n");
110 if (!TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
111 ERR("Error opening the frame buffer !!!\n");
112 return DDERR_GENERIC
;
115 /* List all available modes */
116 modes
= TSXDGAQueryModes(display
, DefaultScreen(display
), &num_modes
);
117 dgpriv
->modes
= modes
;
118 dgpriv
->num_modes
= num_modes
;
120 TRACE("Available modes :\n");
121 for (i
= 0; i
< num_modes
; i
++) {
122 if (TRACE_ON(ddraw
)) {
123 DPRINTF(" %d) - %s (FB: %dx%d / VP: %dx%d) - depth %d -",
125 modes
[i
].name
, modes
[i
].imageWidth
, modes
[i
].imageHeight
,
126 modes
[i
].viewportWidth
, modes
[i
].viewportHeight
,
129 #define XX(x) if (modes[i].flags & x) DPRINTF(" "#x" ");
130 XX(XDGAConcurrentAccess
);
131 XX(XDGASolidFillRect
);
133 XX(XDGABlitTransRect
);
138 if ((GetSystemMetrics(SM_CYSCREEN
) == modes
[i
].viewportHeight
) &&
139 (GetSystemMetrics(SM_CXSCREEN
) == modes
[i
].viewportWidth
) &&
140 (X11DRV_GetDepth() == modes
[i
].depth
)
142 mode_to_use
= modes
[i
].num
;
145 if (mode_to_use
== 0) {
146 ERR("Could not find mode !\n");
149 TRACE("Using mode number %d\n", mode_to_use
);
152 dgpriv
->DGA
.InstallColormap
= TSXDGAInstallColormap
;
154 /* Initialize the frame buffer */
155 _DGA2_Initialize_FrameBuffer(ddraw
, mode_to_use
);
157 /* Register frame buffer with the kernel, it is a potential DIB section */
158 VirtualAlloc(dgpriv
->DGA
.fb_addr
, dgpriv
->DGA
.fb_memsize
, MEM_RESERVE
|MEM_SYSTEM
, PAGE_READWRITE
);
160 /* Set the input handling for relative mouse movements */
161 X11DRV_EVENT_SetInputMethod(X11DRV_INPUT_RELATIVE
);
166 /* Where do these GUIDs come from? mkuuid.
167 * They exist solely to distinguish between the targets Wine support,
168 * and should be different than any other GUIDs in existence.
170 static GUID DGA2_DirectDraw_GUID
= { /* e2dcb020-dc60-11d1-8407-9714f5d50803 */
174 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x03}
177 ddraw_driver dga2_driver
= {
178 &DGA2_DirectDraw_GUID
,
180 "WINE XF86DGA2 DirectDraw Driver",
185 DECL_GLOBAL_CONSTRUCTOR(DGA2_register
) { ddraw_register_driver(&dga2_driver
); }