2 * DirectDraw driver interface
4 * Copyright 2001 TransGaming Technologies, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
44 LPDDRAWI_DDRAWSURFACE_LCL X11DRV_DD_Primary
;
45 LPDDRAWI_DDRAWSURFACE_GBL X11DRV_DD_PrimaryGbl
;
46 HWND X11DRV_DD_PrimaryWnd
;
47 HBITMAP X11DRV_DD_PrimaryDIB
;
48 Drawable X11DRV_DD_PrimaryDrawable
;
49 ATOM X11DRV_DD_UserClass
;
50 BOOL X11DRV_DD_IsDirect
;
51 static UINT X11DRV_DD_GrabMessage
;
52 static WNDPROC X11DRV_DD_GrabOldProcedure
;
54 static void SetPrimaryDIB(HBITMAP hBmp
)
56 X11DRV_DD_PrimaryDIB
= hBmp
;
59 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hBmp
, BITMAP_MAGIC
);
60 X11DRV_DD_PrimaryDrawable
= (Pixmap
)bmp
->physBitmap
;
61 GDI_ReleaseObj( hBmp
);
63 X11DRV_DD_PrimaryDrawable
= 0;
67 static LRESULT WINAPI
GrabWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
69 Display
*display
= thread_display();
71 if(message
!= X11DRV_DD_GrabMessage
)
72 return CallWindowProcA(X11DRV_DD_GrabOldProcedure
, hWnd
, message
, wParam
, lParam
);
74 TRACE("hwnd=%p, grab=%d\n", hWnd
, wParam
);
78 /* find the X11 window that ddraw uses */
79 Window win
= X11DRV_get_whole_window(hWnd
);
80 TRACE("X11 window: %ld\n", win
);
82 TRACE("host off desktop\n");
87 XGrabPointer(display
, win
, True
, 0, GrabModeAsync
, GrabModeAsync
, win
, None
, CurrentTime
);
93 XUngrabPointer(display
, CurrentTime
);
100 static void GrabPointer(BOOL grab
)
103 Window window
= X11DRV_get_whole_window(GetFocus());
105 XSetInputFocus(thread_display(), window
, RevertToParent
, CurrentTime
);
108 if(!X11DRV_DD_GrabMessage
)
109 X11DRV_DD_GrabMessage
= RegisterWindowMessageA("WINE_X11DRV_GRABPOINTER");
111 /* FIXME: Replace with SetWindowLongPtrA when available */
112 X11DRV_DD_GrabOldProcedure
= (WNDPROC
)SetWindowLongA(X11DRV_DD_PrimaryWnd
,
113 GWL_WNDPROC
, (LONG
)GrabWndProc
);
115 SendMessageA(X11DRV_DD_PrimaryWnd
, X11DRV_DD_GrabMessage
, grab
? 1 : 0, 0);
117 /* FIXME: Replace with SetWindowLongPtrA when available */
118 if(SetWindowLongA(X11DRV_DD_PrimaryWnd
, GWL_WNDPROC
,
119 (LONG
)X11DRV_DD_GrabOldProcedure
) != (LONG
)GrabWndProc
)
120 ERR("Window procedure has been changed!\n");
123 static DWORD PASCAL
X11DRV_DDHAL_DestroyDriver(LPDDHAL_DESTROYDRIVERDATA data
)
125 data
->ddRVal
= DD_OK
;
126 return DDHAL_DRIVER_HANDLED
;
129 static DWORD PASCAL
X11DRV_DDHAL_CreateSurface(LPDDHAL_CREATESURFACEDATA data
)
131 if (data
->lpDDSurfaceDesc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) {
132 X11DRV_DD_Primary
= *data
->lplpSList
;
133 X11DRV_DD_PrimaryWnd
= (HWND
)X11DRV_DD_Primary
->lpSurfMore
->lpDDRAWReserved
;
134 X11DRV_DD_PrimaryGbl
= X11DRV_DD_Primary
->lpGbl
;
135 SetPrimaryDIB((HBITMAP
)GET_LPDDRAWSURFACE_GBL_MORE(X11DRV_DD_PrimaryGbl
)->hKernelSurface
);
136 X11DRV_DD_UserClass
= GlobalFindAtomA("WINE_DDRAW");
137 if (dxgrab
) GrabPointer(TRUE
);
139 data
->ddRVal
= DD_OK
;
140 return DDHAL_DRIVER_NOTHANDLED
;
143 static DWORD PASCAL
X11DRV_DDHAL_CreatePalette(LPDDHAL_CREATEPALETTEDATA data
)
146 /* only makes sense to do anything if the X server is running at 8bpp,
147 * which few people do nowadays */
148 data
->ddRVal
= DD_OK
;
149 return DDHAL_DRIVER_HANDLED
;
152 static DDHAL_DDCALLBACKS hal_ddcallbacks
= {
153 sizeof(DDHAL_DDCALLBACKS
),
154 0x3ff, /* all callbacks are 32-bit */
155 X11DRV_DDHAL_DestroyDriver
,
156 X11DRV_DDHAL_CreateSurface
,
157 NULL
, /* SetColorKey */
159 NULL
, /* WaitForVerticalBlank */
160 NULL
, /* CanCreateSurface */
161 X11DRV_DDHAL_CreatePalette
,
162 NULL
, /* GetScanLine */
163 NULL
, /* SetExclusiveMode */
164 NULL
/* FlipToGDISurface */
167 static DWORD PASCAL
X11DRV_DDHAL_DestroySurface(LPDDHAL_DESTROYSURFACEDATA data
)
169 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
170 if (dxgrab
) GrabPointer(FALSE
);
171 X11DRV_DD_Primary
= NULL
;
172 X11DRV_DD_PrimaryWnd
= 0;
173 X11DRV_DD_PrimaryGbl
= NULL
;
175 X11DRV_DD_UserClass
= 0;
177 data
->ddRVal
= DD_OK
;
178 return DDHAL_DRIVER_HANDLED
;
181 static DWORD PASCAL
X11DRV_DDHAL_SetPalette(LPDDHAL_SETPALETTEDATA data
)
183 if (data
->lpDDPalette
&& data
->lpDDPalette
->u1
.dwReserved1
) {
184 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
186 /* we should probably find the ddraw window (maybe data->lpDD->lpExclusiveOwner->hWnd),
187 * and attach the palette to it
189 * Colormap pal = data->lpDDPalette->u1.dwReserved1;
193 data
->ddRVal
= DD_OK
;
194 return DDHAL_DRIVER_HANDLED
;
197 static DDHAL_DDSURFACECALLBACKS hal_ddsurfcallbacks
= {
198 sizeof(DDHAL_DDSURFACECALLBACKS
),
199 0x3fff, /* all callbacks are 32-bit */
200 X11DRV_DDHAL_DestroySurface
,
202 NULL
, /* SetClipList */
206 NULL
, /* SetColorKey */
207 NULL
, /* AddAttachedSurface */
208 NULL
, /* GetBltStatus */
209 NULL
, /* GetFlipStatus */
210 NULL
, /* UpdateOverlay */
211 NULL
, /* SetOverlayPosition */
212 NULL
, /* reserved4 */
213 X11DRV_DDHAL_SetPalette
216 static DWORD PASCAL
X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data
)
218 Colormap pal
= data
->lpDDPalette
->u1
.dwReserved1
;
222 XFreeColormap(gdi_display
, pal
);
225 data
->ddRVal
= DD_OK
;
226 return DDHAL_DRIVER_HANDLED
;
229 static DWORD PASCAL
X11DRV_DDHAL_SetPaletteEntries(LPDDHAL_SETENTRIESDATA data
)
231 X11DRV_DDHAL_SetPalEntries(data
->lpDDPalette
->u1
.dwReserved1
,
232 data
->dwBase
, data
->dwNumEntries
,
234 data
->ddRVal
= DD_OK
;
235 return DDHAL_DRIVER_HANDLED
;
238 static DDHAL_DDPALETTECALLBACKS hal_ddpalcallbacks
= {
239 sizeof(DDHAL_DDPALETTECALLBACKS
),
240 0x3, /* all callbacks are 32-bit */
241 X11DRV_DDHAL_DestroyPalette
,
242 X11DRV_DDHAL_SetPaletteEntries
245 static X11DEVICE x11device
= {
249 static DWORD PASCAL
X11DRV_DDHAL_GetDriverInfo(LPDDHAL_GETDRIVERINFODATA data
)
251 LPX11DRIVERINFO info
= x11device
.lpInfo
;
253 if (IsEqualGUID(&data
->guidInfo
, info
->lpGuid
)) {
254 DWORD dwSize
= info
->dwSize
;
255 data
->dwActualSize
= dwSize
;
256 if (data
->dwExpectedSize
< dwSize
) dwSize
= data
->dwExpectedSize
;
257 memcpy(data
->lpvData
, info
->lpvData
, dwSize
);
258 data
->ddRVal
= DD_OK
;
259 return DDHAL_DRIVER_HANDLED
;
263 data
->ddRVal
= DDERR_CURRENTLYNOTAVAIL
;
264 return DDHAL_DRIVER_HANDLED
;
267 static DDHALINFO hal_info
= {
270 &hal_ddsurfcallbacks
,
275 { /* ddCaps (only stuff the HAL implements here) */
276 sizeof(DDCORECAPS
), /* dwSize */
277 DDCAPS_GDI
| DDCAPS_PALETTE
, /* dwCaps */
278 DDCAPS2_CERTIFIED
| DDCAPS2_NONLOCALVIDMEM
| DDCAPS2_NOPAGELOCKREQUIRED
| DDCAPS2_CANRENDERWINDOWED
|
279 DDCAPS2_WIDESURFACES
| DDCAPS2_PRIMARYGAMMA
| DDCAPS2_FLIPNOVSYNC
, /* dwCaps2 */
282 0, /* dwFXAlphaCaps */
283 DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
, /* dwPalCaps */
285 0, /* dwAlphaBltConstBitDepths */
286 0, /* dwAlphaBltPixelBitDepths */
287 0, /* dwAlphaBltSurfaceBitDepths */
288 0, /* dwAlphaOverlayBltConstBitDepths */
289 0, /* dwAlphaOverlayBltPixelBitDepths */
290 0, /* dwAlphaOverlayBltSurfaceBitDepths */
291 0, /* dwZBufferBitDepths */
292 16*1024*1024, /* dwVidMemTotal */
293 16*1024*1024, /* dwVidMemFree */
294 0, /* dwMaxVisibleOverlays */
295 0, /* dwCurrVisibleOverlays */
296 0, /* dwNumFourCCCodes */
297 0, /* dwAlignBoundarySrc */
298 0, /* dwAlignSizeSrc */
299 0, /* dwAlignBoundaryDest */
300 0, /* dwAlignSizeDest */
301 0, /* dwAlignStrideAlign */
304 DDSCAPS_BACKBUFFER
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
|
305 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_PALETTE
| DDSCAPS_PRIMARYSURFACE
|
306 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
|
307 DDSCAPS_VISIBLE
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_NONLOCALVIDMEM
/* dwCaps */
309 0, /* dwMinOverlayStretch */
310 0, /* dwMaxOverlayStretch */
311 0, /* dwMinLiveVideoStretch */
312 0, /* dwMaxLiveVideoStretch */
313 0, /* dwMinHwCodecStretch */
314 0, /* dwMaxHwCodecStretch */
319 0, /* dwSVBCKeyCaps */
323 0, /* dwVSBCKeyCaps */
327 0, /* dwSSBCKeyCaps */
330 0, /* dwMaxVideoPorts */
331 0, /* dwCurrVideoPorts */
334 0, /* dwMonitorFrequency */
335 X11DRV_DDHAL_GetDriverInfo
,
337 NULL
, /* lpdwFourCC */
339 NULL
, /* lpModeInfo */
340 DDHALINFO_ISPRIMARYDISPLAY
| DDHALINFO_MODEXILLEGAL
| DDHALINFO_GETDRIVERINFOSET
, /* dwFlags */
343 0, /* lpD3DGlobalDriverData */
344 0, /* lpD3DHALCallbacks */
345 NULL
/* lpDDExeBufCallbacks */
348 static LPDDHALDDRAWFNS ddraw_fns
;
349 static DWORD ddraw_ver
;
351 static void X11DRV_DDHAL_SetInfo(void)
353 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
356 INT
X11DRV_DCICommand(INT cbInput
, const DCICMD
*lpCmd
, LPVOID lpOutData
)
358 TRACE("(%d,(%ld,%ld,%ld),%p)\n", cbInput
, lpCmd
->dwCommand
,
359 lpCmd
->dwParam1
, lpCmd
->dwParam2
, lpOutData
);
361 switch (lpCmd
->dwCommand
) {
362 case DDNEWCALLBACKFNS
:
363 ddraw_fns
= (LPDDHALDDRAWFNS
)lpCmd
->dwParam1
;
367 LPDDVERSIONDATA lpVer
= (LPDDVERSIONDATA
)lpOutData
;
368 ddraw_ver
= lpCmd
->dwParam1
;
370 /* well, whatever... the DDK says so */
371 lpVer
->dwHALVersion
= DD_RUNTIME_VERSION
;
374 case DDGET32BITDRIVERNAME
:
376 LPDD32BITDRIVERDATA lpData
= (LPDD32BITDRIVERDATA
)lpOutData
;
377 /* here, we could ask ddraw to load a separate DLL, that
378 * would contain the 32-bit ddraw HAL */
379 strcpy(lpData
->szName
,"x11drv");
380 /* the entry point named here should initialize our hal_info
381 * with 32-bit entry points (ignored for now) */
382 strcpy(lpData
->szEntryPoint
,"DriverInit");
383 lpData
->dwContext
= 0;
386 case DDCREATEDRIVEROBJECT
:
388 LPDWORD lpInstance
= (LPDWORD
)lpOutData
;
390 /* FIXME: get x11drv's hInstance */
391 #ifdef HAVE_LIBXXF86DGA2
392 if (!X11DRV_XF86DGA2_CreateDriver(&hal_info
))
395 X11DRV_Settings_CreateDriver(&hal_info
);
398 /*X11DRV_GLX_CreateDriver(&hal_info);*/
401 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
402 *lpInstance
= hal_info
.hInstance
;
409 void X11DRV_DDHAL_SwitchMode(DWORD dwModeIndex
, LPVOID fb_addr
, LPVIDMEM fb_mem
)
411 LPDDHALMODEINFO info
= &hal_info
.lpModeInfo
[dwModeIndex
];
413 hal_info
.dwModeIndex
= dwModeIndex
;
414 hal_info
.dwMonitorFrequency
= info
->wRefreshRate
;
415 hal_info
.vmiData
.fpPrimary
= (FLATPTR
)fb_addr
;
416 hal_info
.vmiData
.dwDisplayWidth
= info
->dwWidth
;
417 hal_info
.vmiData
.dwDisplayHeight
= info
->dwHeight
;
418 hal_info
.vmiData
.lDisplayPitch
= info
->lPitch
;
419 hal_info
.vmiData
.ddpfDisplay
.dwSize
= info
->dwBPP
? sizeof(hal_info
.vmiData
.ddpfDisplay
) : 0;
420 hal_info
.vmiData
.ddpfDisplay
.dwFlags
= (info
->wFlags
& DDMODEINFO_PALETTIZED
) ? DDPF_PALETTEINDEXED8
: 0;
421 hal_info
.vmiData
.ddpfDisplay
.u1
.dwRGBBitCount
= (info
->dwBPP
> 24) ? 24 : info
->dwBPP
;
422 hal_info
.vmiData
.ddpfDisplay
.u2
.dwRBitMask
= info
->dwRBitMask
;
423 hal_info
.vmiData
.ddpfDisplay
.u3
.dwGBitMask
= info
->dwGBitMask
;
424 hal_info
.vmiData
.ddpfDisplay
.u4
.dwBBitMask
= info
->dwBBitMask
;
425 hal_info
.vmiData
.dwNumHeaps
= fb_mem
? 1 : 0;
426 hal_info
.vmiData
.pvmList
= fb_mem
;
428 X11DRV_DDHAL_SetInfo();
431 void X11DRV_DDHAL_SetPalEntries(Colormap pal
, DWORD dwBase
, DWORD dwNumEntries
,
432 LPPALETTEENTRY lpEntries
)
439 c
.flags
= DoRed
|DoGreen
|DoBlue
;
441 for (n
=0; n
<dwNumEntries
; n
++,c
.pixel
++) {
442 c
.red
= lpEntries
[n
].peRed
<< 8;
443 c
.green
= lpEntries
[n
].peGreen
<< 8;
444 c
.blue
= lpEntries
[n
].peBlue
<< 8;
445 XStoreColor(gdi_display
, pal
, &c
);
447 XFlush(gdi_display
); /* update display immediately */