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"
31 #include "dga2_private.h"
33 DEFAULT_DEBUG_CHANNEL(ddraw
);
35 static inline BOOL
get_option( const char *name
, BOOL def
) {
36 return PROFILE_GetWineIniBool( "x11drv", name
, def
);
40 DDRAW_DGA2_Available(void)
42 int evbase
, evret
, majver
, minver
;
43 static BYTE return_value
= 0xFF;
45 /* This prevents from probing X times for DGA */
46 if (return_value
!= 0xFF)
49 if (!get_option( "UseDGA", 1 )) {
50 TRACE("UseDGA disabled.\n");
55 /* First, query the extenstion and its version */
56 if (!TSXF86DGAQueryExtension(display
,&evbase
,&evret
)) {
57 TRACE("DGA extension not detected.\n");
62 if (!TSXF86DGAQueryVersion(display
,&majver
,&minver
)) {
63 TRACE("DGA version not detected.\n");
69 /* We have DGA 2.0 available ! */
70 if (TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
71 TSXDGACloseFramebuffer(display
, DefaultScreen(display
));
82 DGA2_Create( LPDIRECTDRAW
*lplpDD
) {
83 IDirectDrawImpl
* ddraw
;
84 dga2_dd_private
* dgpriv
;
91 /* Get DGA availability / version */
92 dga_version
= DDRAW_DGA2_Available();
96 /* If we were just testing ... return OK */
100 ddraw
= (IDirectDrawImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawImpl
));
101 *lplpDD
= (LPDIRECTDRAW
)ddraw
;
103 ICOM_VTBL(ddraw
) = &dga2_ddvt
;
105 ddraw
->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(dga2_dd_private
));
107 dgpriv
= (dga2_dd_private
*)ddraw
->private;
109 TSXDGAQueryVersion(display
,&major
,&minor
);
110 TRACE("XDGA is version %d.%d\n",major
,minor
);
112 TRACE("Opening the frame buffer.\n");
113 if (!TSXDGAOpenFramebuffer(display
, DefaultScreen(display
))) {
114 ERR("Error opening the frame buffer !!!\n");
115 return DDERR_GENERIC
;
118 /* List all available modes */
119 modes
= TSXDGAQueryModes(display
, DefaultScreen(display
), &num_modes
);
120 dgpriv
->modes
= modes
;
121 dgpriv
->num_modes
= num_modes
;
123 TRACE("Available modes :\n");
124 for (i
= 0; i
< num_modes
; i
++) {
125 if (TRACE_ON(ddraw
)) {
126 DPRINTF(" %d) - %s (FB: %dx%d / VP: %dx%d) - depth %d -",
128 modes
[i
].name
, modes
[i
].imageWidth
, modes
[i
].imageHeight
,
129 modes
[i
].viewportWidth
, modes
[i
].viewportHeight
,
132 #define XX(x) if (modes[i].flags & x) DPRINTF(" "#x" ");
133 XX(XDGAConcurrentAccess
);
134 XX(XDGASolidFillRect
);
136 XX(XDGABlitTransRect
);
141 if ((MONITOR_GetHeight(&MONITOR_PrimaryMonitor
) == modes
[i
].viewportHeight
) &&
142 (MONITOR_GetWidth(&MONITOR_PrimaryMonitor
) == modes
[i
].viewportWidth
) &&
143 (MONITOR_GetDepth(&MONITOR_PrimaryMonitor
) == modes
[i
].depth
)
145 mode_to_use
= modes
[i
].num
;
148 if (mode_to_use
== 0) {
149 ERR("Could not find mode !\n");
152 TRACE("Using mode number %d\n", mode_to_use
);
155 dgpriv
->DGA
.InstallColormap
= TSXDGAInstallColormap
;
157 /* Initialize the frame buffer */
158 _DGA2_Initialize_FrameBuffer(ddraw
, mode_to_use
);
160 /* Register frame buffer with the kernel, it is as a potential DIB section */
161 VirtualAlloc(dgpriv
->DGA
.fb_addr
, dgpriv
->DGA
.fb_memsize
, MEM_RESERVE
|MEM_SYSTEM
, PAGE_READWRITE
);
163 /* Set the input handling for relative mouse movements */
164 X11DRV_EVENT_SetInputMethod(X11DRV_INPUT_RELATIVE
);
169 /* Where do these GUIDs come from? mkuuid.
170 * They exist solely to distinguish between the targets Wine support,
171 * and should be different than any other GUIDs in existence.
173 static GUID DGA2_DirectDraw_GUID
= { /* e2dcb020-dc60-11d1-8407-9714f5d50803 */
177 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x03}
180 ddraw_driver dga2_driver
= {
181 &DGA2_DirectDraw_GUID
,
183 "WINE XF86DGA2 DirectDraw Driver",
188 DECL_GLOBAL_CONSTRUCTOR(DGA2_register
) { ddraw_register_driver(&dga2_driver
); }