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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
43 LPDDRAWI_DDRAWSURFACE_LCL X11DRV_DD_Primary
;
44 LPDDRAWI_DDRAWSURFACE_GBL X11DRV_DD_PrimaryGbl
;
45 HWND X11DRV_DD_PrimaryWnd
;
46 HBITMAP X11DRV_DD_PrimaryDIB
;
47 Drawable X11DRV_DD_PrimaryDrawable
;
48 ATOM X11DRV_DD_UserClass
;
49 BOOL X11DRV_DD_IsDirect
;
50 static UINT X11DRV_DD_GrabMessage
;
51 static WNDPROC X11DRV_DD_GrabOldProcedure
;
53 static void SetPrimaryDIB(HBITMAP hBmp
)
55 X11DRV_DD_PrimaryDIB
= hBmp
;
58 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hBmp
, BITMAP_MAGIC
);
59 X11DRV_DD_PrimaryDrawable
= (Pixmap
)bmp
->physBitmap
;
60 GDI_ReleaseObj( hBmp
);
62 X11DRV_DD_PrimaryDrawable
= 0;
66 static LRESULT WINAPI
GrabWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
68 Display
*display
= thread_display();
70 if(message
!= X11DRV_DD_GrabMessage
)
71 return CallWindowProcA(X11DRV_DD_GrabOldProcedure
, hWnd
, message
, wParam
, lParam
);
73 TRACE("hwnd=%p, grab=%d\n", hWnd
, wParam
);
77 /* find the X11 window that ddraw uses */
78 Window win
= X11DRV_get_whole_window(hWnd
);
79 TRACE("X11 window: %ld\n", win
);
81 TRACE("host off desktop\n");
85 TSXGrabPointer(display
, win
, True
, 0, GrabModeAsync
, GrabModeAsync
, win
, None
, CurrentTime
);
89 TSXUngrabPointer(display
, CurrentTime
);
95 static void GrabPointer(BOOL grab
)
98 Window window
= X11DRV_get_whole_window(GetFocus());
100 XSetInputFocus(thread_display(), window
, RevertToParent
, CurrentTime
);
103 if(!X11DRV_DD_GrabMessage
)
104 X11DRV_DD_GrabMessage
= RegisterWindowMessageA("WINE_X11DRV_GRABPOINTER");
106 /* FIXME: Replace with SetWindowLongPtrA when available */
107 X11DRV_DD_GrabOldProcedure
= (WNDPROC
)SetWindowLongA(X11DRV_DD_PrimaryWnd
,
108 GWL_WNDPROC
, (LONG
)GrabWndProc
);
110 SendMessageA(X11DRV_DD_PrimaryWnd
, X11DRV_DD_GrabMessage
, grab
? 1 : 0, 0);
112 /* FIXME: Replace with SetWindowLongPtrA when available */
113 if(SetWindowLongA(X11DRV_DD_PrimaryWnd
, GWL_WNDPROC
,
114 (LONG
)X11DRV_DD_GrabOldProcedure
) != (LONG
)GrabWndProc
)
115 ERR("Window procedure has been changed!\n");
118 static DWORD PASCAL
X11DRV_DDHAL_DestroyDriver(LPDDHAL_DESTROYDRIVERDATA data
)
120 data
->ddRVal
= DD_OK
;
121 return DDHAL_DRIVER_HANDLED
;
124 static DWORD PASCAL
X11DRV_DDHAL_CreateSurface(LPDDHAL_CREATESURFACEDATA data
)
126 if (data
->lpDDSurfaceDesc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) {
127 X11DRV_DD_Primary
= *data
->lplpSList
;
128 X11DRV_DD_PrimaryWnd
= (HWND
)X11DRV_DD_Primary
->lpSurfMore
->lpDDRAWReserved
;
129 X11DRV_DD_PrimaryGbl
= X11DRV_DD_Primary
->lpGbl
;
130 SetPrimaryDIB((HBITMAP
)GET_LPDDRAWSURFACE_GBL_MORE(X11DRV_DD_PrimaryGbl
)->hKernelSurface
);
131 X11DRV_DD_UserClass
= GlobalFindAtomA("WINE_DDRAW");
132 if (dxgrab
) GrabPointer(TRUE
);
134 data
->ddRVal
= DD_OK
;
135 return DDHAL_DRIVER_NOTHANDLED
;
138 static DWORD PASCAL
X11DRV_DDHAL_CreatePalette(LPDDHAL_CREATEPALETTEDATA data
)
141 /* only makes sense to do anything if the X server is running at 8bpp,
142 * which few people do nowadays */
143 data
->ddRVal
= DD_OK
;
144 return DDHAL_DRIVER_HANDLED
;
147 static DDHAL_DDCALLBACKS hal_ddcallbacks
= {
148 sizeof(DDHAL_DDCALLBACKS
),
149 0x3ff, /* all callbacks are 32-bit */
150 X11DRV_DDHAL_DestroyDriver
,
151 X11DRV_DDHAL_CreateSurface
,
152 NULL
, /* SetColorKey */
154 NULL
, /* WaitForVerticalBlank */
155 NULL
, /* CanCreateSurface */
156 X11DRV_DDHAL_CreatePalette
,
157 NULL
, /* GetScanLine */
158 NULL
, /* SetExclusiveMode */
159 NULL
/* FlipToGDISurface */
162 static DWORD PASCAL
X11DRV_DDHAL_DestroySurface(LPDDHAL_DESTROYSURFACEDATA data
)
164 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
165 if (dxgrab
) GrabPointer(FALSE
);
166 X11DRV_DD_Primary
= NULL
;
167 X11DRV_DD_PrimaryWnd
= 0;
168 X11DRV_DD_PrimaryGbl
= NULL
;
170 X11DRV_DD_UserClass
= 0;
172 data
->ddRVal
= DD_OK
;
173 return DDHAL_DRIVER_HANDLED
;
176 static DWORD PASCAL
X11DRV_DDHAL_SetPalette(LPDDHAL_SETPALETTEDATA data
)
178 if (data
->lpDDPalette
&& data
->lpDDPalette
->u1
.dwReserved1
) {
179 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
181 /* we should probably find the ddraw window (maybe data->lpDD->lpExclusiveOwner->hWnd),
182 * and attach the palette to it
184 * Colormap pal = data->lpDDPalette->u1.dwReserved1;
188 data
->ddRVal
= DD_OK
;
189 return DDHAL_DRIVER_HANDLED
;
192 static DDHAL_DDSURFACECALLBACKS hal_ddsurfcallbacks
= {
193 sizeof(DDHAL_DDSURFACECALLBACKS
),
194 0x3fff, /* all callbacks are 32-bit */
195 X11DRV_DDHAL_DestroySurface
,
197 NULL
, /* SetClipList */
201 NULL
, /* SetColorKey */
202 NULL
, /* AddAttachedSurface */
203 NULL
, /* GetBltStatus */
204 NULL
, /* GetFlipStatus */
205 NULL
, /* UpdateOverlay */
206 NULL
, /* SetOverlayPosition */
207 NULL
, /* reserved4 */
208 X11DRV_DDHAL_SetPalette
211 static DWORD PASCAL
X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data
)
213 Colormap pal
= data
->lpDDPalette
->u1
.dwReserved1
;
214 if (pal
) TSXFreeColormap(gdi_display
, pal
);
215 data
->ddRVal
= DD_OK
;
216 return DDHAL_DRIVER_HANDLED
;
219 static DWORD PASCAL
X11DRV_DDHAL_SetPaletteEntries(LPDDHAL_SETENTRIESDATA data
)
221 X11DRV_DDHAL_SetPalEntries(data
->lpDDPalette
->u1
.dwReserved1
,
222 data
->dwBase
, data
->dwNumEntries
,
224 data
->ddRVal
= DD_OK
;
225 return DDHAL_DRIVER_HANDLED
;
228 static DDHAL_DDPALETTECALLBACKS hal_ddpalcallbacks
= {
229 sizeof(DDHAL_DDPALETTECALLBACKS
),
230 0x3, /* all callbacks are 32-bit */
231 X11DRV_DDHAL_DestroyPalette
,
232 X11DRV_DDHAL_SetPaletteEntries
235 static X11DEVICE x11device
= {
239 static DWORD PASCAL
X11DRV_DDHAL_GetDriverInfo(LPDDHAL_GETDRIVERINFODATA data
)
241 LPX11DRIVERINFO info
= x11device
.lpInfo
;
243 if (IsEqualGUID(&data
->guidInfo
, info
->lpGuid
)) {
244 DWORD dwSize
= info
->dwSize
;
245 data
->dwActualSize
= dwSize
;
246 if (data
->dwExpectedSize
< dwSize
) dwSize
= data
->dwExpectedSize
;
247 memcpy(data
->lpvData
, info
->lpvData
, dwSize
);
248 data
->ddRVal
= DD_OK
;
249 return DDHAL_DRIVER_HANDLED
;
253 data
->ddRVal
= DDERR_CURRENTLYNOTAVAIL
;
254 return DDHAL_DRIVER_HANDLED
;
257 static DDHALINFO hal_info
= {
260 &hal_ddsurfcallbacks
,
265 { /* ddCaps (only stuff the HAL implements here) */
266 sizeof(DDCORECAPS
), /* dwSize */
267 DDCAPS_GDI
| DDCAPS_PALETTE
, /* dwCaps */
268 DDCAPS2_CERTIFIED
| DDCAPS2_NONLOCALVIDMEM
| DDCAPS2_NOPAGELOCKREQUIRED
| DDCAPS2_CANRENDERWINDOWED
|
269 DDCAPS2_WIDESURFACES
| DDCAPS2_PRIMARYGAMMA
| DDCAPS2_FLIPNOVSYNC
, /* dwCaps2 */
272 0, /* dwFXAlphaCaps */
273 DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
, /* dwPalCaps */
275 0, /* dwAlphaBltConstBitDepths */
276 0, /* dwAlphaBltPixelBitDepths */
277 0, /* dwAlphaBltSurfaceBitDepths */
278 0, /* dwAlphaOverlayBltConstBitDepths */
279 0, /* dwAlphaOverlayBltPixelBitDepths */
280 0, /* dwAlphaOverlayBltSurfaceBitDepths */
281 0, /* dwZBufferBitDepths */
282 16*1024*1024, /* dwVidMemTotal */
283 16*1024*1024, /* dwVidMemFree */
284 0, /* dwMaxVisibleOverlays */
285 0, /* dwCurrVisibleOverlays */
286 0, /* dwNumFourCCCodes */
287 0, /* dwAlignBoundarySrc */
288 0, /* dwAlignSizeSrc */
289 0, /* dwAlignBoundaryDest */
290 0, /* dwAlignSizeDest */
291 0, /* dwAlignStrideAlign */
294 DDSCAPS_BACKBUFFER
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
|
295 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_PALETTE
| DDSCAPS_PRIMARYSURFACE
|
296 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
|
297 DDSCAPS_VISIBLE
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_NONLOCALVIDMEM
/* dwCaps */
299 0, /* dwMinOverlayStretch */
300 0, /* dwMaxOverlayStretch */
301 0, /* dwMinLiveVideoStretch */
302 0, /* dwMaxLiveVideoStretch */
303 0, /* dwMinHwCodecStretch */
304 0, /* dwMaxHwCodecStretch */
309 0, /* dwSVBCKeyCaps */
313 0, /* dwVSBCKeyCaps */
317 0, /* dwSSBCKeyCaps */
320 0, /* dwMaxVideoPorts */
321 0, /* dwCurrVideoPorts */
324 0, /* dwMonitorFrequency */
325 X11DRV_DDHAL_GetDriverInfo
,
327 NULL
, /* lpdwFourCC */
329 NULL
, /* lpModeInfo */
330 DDHALINFO_ISPRIMARYDISPLAY
| DDHALINFO_MODEXILLEGAL
| DDHALINFO_GETDRIVERINFOSET
, /* dwFlags */
333 0, /* lpD3DGlobalDriverData */
334 0, /* lpD3DHALCallbacks */
335 NULL
/* lpDDExeBufCallbacks */
338 static LPDDHALDDRAWFNS ddraw_fns
;
339 static DWORD ddraw_ver
;
341 static void X11DRV_DDHAL_SetInfo(void)
343 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
346 INT
X11DRV_DCICommand(INT cbInput
, const DCICMD
*lpCmd
, LPVOID lpOutData
)
348 TRACE("(%d,(%ld,%ld,%ld),%p)\n", cbInput
, lpCmd
->dwCommand
,
349 lpCmd
->dwParam1
, lpCmd
->dwParam2
, lpOutData
);
351 switch (lpCmd
->dwCommand
) {
352 case DDNEWCALLBACKFNS
:
353 ddraw_fns
= (LPDDHALDDRAWFNS
)lpCmd
->dwParam1
;
357 LPDDVERSIONDATA lpVer
= (LPDDVERSIONDATA
)lpOutData
;
358 ddraw_ver
= lpCmd
->dwParam1
;
360 /* well, whatever... the DDK says so */
361 lpVer
->dwHALVersion
= DD_RUNTIME_VERSION
;
364 case DDGET32BITDRIVERNAME
:
366 LPDD32BITDRIVERDATA lpData
= (LPDD32BITDRIVERDATA
)lpOutData
;
367 /* here, we could ask ddraw to load a separate DLL, that
368 * would contain the 32-bit ddraw HAL */
369 strcpy(lpData
->szName
,"x11drv");
370 /* the entry point named here should initialize our hal_info
371 * with 32-bit entry points (ignored for now) */
372 strcpy(lpData
->szEntryPoint
,"DriverInit");
373 lpData
->dwContext
= 0;
376 case DDCREATEDRIVEROBJECT
:
378 LPDWORD lpInstance
= (LPDWORD
)lpOutData
;
380 /* FIXME: get x11drv's hInstance */
381 #ifdef HAVE_LIBXXF86DGA2
382 if (!X11DRV_XF86DGA2_CreateDriver(&hal_info
))
385 #ifdef HAVE_LIBXXF86VM
386 X11DRV_XF86VM_CreateDriver(&hal_info
);
390 /*X11DRV_GLX_CreateDriver(&hal_info);*/
393 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
394 *lpInstance
= hal_info
.hInstance
;
401 void X11DRV_DDHAL_SwitchMode(DWORD dwModeIndex
, LPVOID fb_addr
, LPVIDMEM fb_mem
)
403 LPDDHALMODEINFO info
= &hal_info
.lpModeInfo
[dwModeIndex
];
405 hal_info
.dwModeIndex
= dwModeIndex
;
406 hal_info
.dwMonitorFrequency
= info
->wRefreshRate
;
407 hal_info
.vmiData
.fpPrimary
= (FLATPTR
)fb_addr
;
408 hal_info
.vmiData
.dwDisplayWidth
= info
->dwWidth
;
409 hal_info
.vmiData
.dwDisplayHeight
= info
->dwHeight
;
410 hal_info
.vmiData
.lDisplayPitch
= info
->lPitch
;
411 hal_info
.vmiData
.ddpfDisplay
.dwSize
= info
->dwBPP
? sizeof(hal_info
.vmiData
.ddpfDisplay
) : 0;
412 hal_info
.vmiData
.ddpfDisplay
.dwFlags
= (info
->wFlags
& DDMODEINFO_PALETTIZED
) ? DDPF_PALETTEINDEXED8
: 0;
413 hal_info
.vmiData
.ddpfDisplay
.u1
.dwRGBBitCount
= (info
->dwBPP
> 24) ? 24 : info
->dwBPP
;
414 hal_info
.vmiData
.ddpfDisplay
.u2
.dwRBitMask
= info
->dwRBitMask
;
415 hal_info
.vmiData
.ddpfDisplay
.u3
.dwGBitMask
= info
->dwGBitMask
;
416 hal_info
.vmiData
.ddpfDisplay
.u4
.dwBBitMask
= info
->dwBBitMask
;
417 hal_info
.vmiData
.dwNumHeaps
= fb_mem
? 1 : 0;
418 hal_info
.vmiData
.pvmList
= fb_mem
;
420 X11DRV_DDHAL_SetInfo();
423 void X11DRV_DDHAL_SetPalEntries(Colormap pal
, DWORD dwBase
, DWORD dwNumEntries
,
424 LPPALETTEENTRY lpEntries
)
430 c
.flags
= DoRed
|DoGreen
|DoBlue
;
432 for (n
=0; n
<dwNumEntries
; n
++,c
.pixel
++) {
433 c
.red
= lpEntries
[n
].peRed
<< 8;
434 c
.green
= lpEntries
[n
].peGreen
<< 8;
435 c
.blue
= lpEntries
[n
].peBlue
<< 8;
436 TSXStoreColor(gdi_display
, pal
, &c
);
438 TSXFlush(gdi_display
); /* update display immediately */