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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
39 LPDDRAWI_DDRAWSURFACE_LCL X11DRV_DD_Primary;
40 LPDDRAWI_DDRAWSURFACE_GBL X11DRV_DD_PrimaryGbl;
41 HWND X11DRV_DD_PrimaryWnd;
42 HBITMAP X11DRV_DD_PrimaryDIB;
43 Drawable X11DRV_DD_PrimaryDrawable;
44 ATOM X11DRV_DD_UserClass;
45 BOOL X11DRV_DD_IsDirect;
46 static UINT X11DRV_DD_GrabMessage;
47 static WNDPROC X11DRV_DD_GrabOldProcedure;
49 static void SetPrimaryDIB(HBITMAP hBmp)
51 X11DRV_DD_PrimaryDIB = hBmp;
53 X11DRV_DD_PrimaryDrawable = X11DRV_get_pixmap( hBmp );
55 X11DRV_DD_PrimaryDrawable = 0;
59 static LRESULT WINAPI GrabWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
61 struct x11drv_thread_data *data = x11drv_thread_data();
63 if(message != X11DRV_DD_GrabMessage)
64 return CallWindowProcA(X11DRV_DD_GrabOldProcedure, hWnd, message, wParam, lParam);
66 TRACE("hwnd=%p, grab=%d\n", hWnd, wParam);
70 /* find the X11 window that ddraw uses */
71 Window win = X11DRV_get_whole_window(hWnd);
72 TRACE("X11 window: %ld\n", win);
74 TRACE("host off desktop\n");
79 XGrabPointer(data->display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
81 data->grab_window = win;
86 XUngrabPointer(data->display, CurrentTime);
88 data->grab_window = None;
94 static void GrabPointer(BOOL grab)
97 Window window = X11DRV_get_whole_window(GetFocus());
101 XSetInputFocus(thread_display(), window, RevertToParent, CurrentTime);
106 if(!X11DRV_DD_GrabMessage)
107 X11DRV_DD_GrabMessage = RegisterWindowMessageA("WINE_X11DRV_GRABPOINTER");
109 X11DRV_DD_GrabOldProcedure = (WNDPROC)SetWindowLongPtrA(X11DRV_DD_PrimaryWnd,
110 GWLP_WNDPROC, (LONG_PTR)GrabWndProc);
112 SendMessageW(X11DRV_DD_PrimaryWnd, X11DRV_DD_GrabMessage, grab, 0);
114 if(SetWindowLongPtrA(X11DRV_DD_PrimaryWnd, GWLP_WNDPROC,
115 (LONG_PTR)X11DRV_DD_GrabOldProcedure) != (LONG_PTR)GrabWndProc)
116 ERR("Window procedure has been changed!\n");
119 static DWORD PASCAL X11DRV_DDHAL_DestroyDriver(LPDDHAL_DESTROYDRIVERDATA data)
121 data->ddRVal = DD_OK;
122 return DDHAL_DRIVER_HANDLED;
125 static DWORD PASCAL X11DRV_DDHAL_CreateSurface(LPDDHAL_CREATESURFACEDATA data)
127 if (data->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) {
128 X11DRV_DD_Primary = *data->lplpSList;
129 X11DRV_DD_PrimaryWnd = (HWND)X11DRV_DD_Primary->lpSurfMore->lpDDRAWReserved;
130 X11DRV_DD_PrimaryGbl = X11DRV_DD_Primary->lpGbl;
131 SetPrimaryDIB((HBITMAP)GET_LPDDRAWSURFACE_GBL_MORE(X11DRV_DD_PrimaryGbl)->hKernelSurface);
132 X11DRV_DD_UserClass = GlobalFindAtomA("WINE_DDRAW");
133 if (dxgrab) GrabPointer(TRUE);
135 data->ddRVal = DD_OK;
136 return DDHAL_DRIVER_NOTHANDLED;
139 static DWORD PASCAL X11DRV_DDHAL_CreatePalette(LPDDHAL_CREATEPALETTEDATA data)
142 /* only makes sense to do anything if the X server is running at 8bpp,
143 * which few people do nowadays */
144 data->ddRVal = DD_OK;
145 return DDHAL_DRIVER_HANDLED;
148 static DDHAL_DDCALLBACKS hal_ddcallbacks = {
149 sizeof(DDHAL_DDCALLBACKS),
150 0x3ff, /* all callbacks are 32-bit */
151 X11DRV_DDHAL_DestroyDriver,
152 X11DRV_DDHAL_CreateSurface,
153 NULL, /* SetColorKey */
155 NULL, /* WaitForVerticalBlank */
156 NULL, /* CanCreateSurface */
157 X11DRV_DDHAL_CreatePalette,
158 NULL, /* GetScanLine */
159 NULL, /* SetExclusiveMode */
160 NULL /* FlipToGDISurface */
163 static DWORD PASCAL X11DRV_DDHAL_DestroySurface(LPDDHAL_DESTROYSURFACEDATA data)
165 if (data->lpDDSurface == X11DRV_DD_Primary) {
166 if (dxgrab) GrabPointer(FALSE);
167 X11DRV_DD_Primary = NULL;
168 X11DRV_DD_PrimaryWnd = 0;
169 X11DRV_DD_PrimaryGbl = NULL;
171 X11DRV_DD_UserClass = 0;
173 data->ddRVal = DD_OK;
174 return DDHAL_DRIVER_HANDLED;
177 static DWORD PASCAL X11DRV_DDHAL_SetPalette(LPDDHAL_SETPALETTEDATA data)
179 if (data->lpDDPalette && data->lpDDPalette->u1.dwReserved1) {
180 if (data->lpDDSurface == X11DRV_DD_Primary) {
182 /* we should probably find the ddraw window (maybe data->lpDD->lpExclusiveOwner->hWnd),
183 * and attach the palette to it
185 * Colormap pal = data->lpDDPalette->u1.dwReserved1;
189 data->ddRVal = DD_OK;
190 return DDHAL_DRIVER_HANDLED;
193 static DDHAL_DDSURFACECALLBACKS hal_ddsurfcallbacks = {
194 sizeof(DDHAL_DDSURFACECALLBACKS),
195 0x3fff, /* all callbacks are 32-bit */
196 X11DRV_DDHAL_DestroySurface,
198 NULL, /* SetClipList */
202 NULL, /* SetColorKey */
203 NULL, /* AddAttachedSurface */
204 NULL, /* GetBltStatus */
205 NULL, /* GetFlipStatus */
206 NULL, /* UpdateOverlay */
207 NULL, /* SetOverlayPosition */
208 NULL, /* reserved4 */
209 X11DRV_DDHAL_SetPalette
212 static DWORD PASCAL X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data)
214 Colormap pal = data->lpDDPalette->u1.dwReserved1;
218 XFreeColormap(gdi_display, pal);
221 data->ddRVal = DD_OK;
222 return DDHAL_DRIVER_HANDLED;
225 static DWORD PASCAL X11DRV_DDHAL_SetPaletteEntries(LPDDHAL_SETENTRIESDATA data)
227 X11DRV_DDHAL_SetPalEntries(data->lpDDPalette->u1.dwReserved1,
228 data->dwBase, data->dwNumEntries,
230 data->ddRVal = DD_OK;
231 return DDHAL_DRIVER_HANDLED;
234 static DDHAL_DDPALETTECALLBACKS hal_ddpalcallbacks = {
235 sizeof(DDHAL_DDPALETTECALLBACKS),
236 0x3, /* all callbacks are 32-bit */
237 X11DRV_DDHAL_DestroyPalette,
238 X11DRV_DDHAL_SetPaletteEntries
241 static X11DEVICE x11device = {
245 static DWORD PASCAL X11DRV_DDHAL_GetDriverInfo(LPDDHAL_GETDRIVERINFODATA data)
247 LPX11DRIVERINFO info = x11device.lpInfo;
249 if (IsEqualGUID(&data->guidInfo, info->lpGuid)) {
250 DWORD dwSize = info->dwSize;
251 data->dwActualSize = dwSize;
252 if (data->dwExpectedSize < dwSize) dwSize = data->dwExpectedSize;
253 memcpy(data->lpvData, info->lpvData, dwSize);
254 data->ddRVal = DD_OK;
255 return DDHAL_DRIVER_HANDLED;
259 data->ddRVal = DDERR_CURRENTLYNOTAVAIL;
260 return DDHAL_DRIVER_HANDLED;
263 static DDHALINFO hal_info = {
266 &hal_ddsurfcallbacks,
271 { /* ddCaps (only stuff the HAL implements here) */
272 sizeof(DDCORECAPS), /* dwSize */
273 DDCAPS_GDI | DDCAPS_PALETTE, /* dwCaps */
274 DDCAPS2_CERTIFIED | DDCAPS2_NONLOCALVIDMEM | DDCAPS2_NOPAGELOCKREQUIRED | DDCAPS2_CANRENDERWINDOWED |
275 DDCAPS2_WIDESURFACES | DDCAPS2_PRIMARYGAMMA | DDCAPS2_FLIPNOVSYNC, /* dwCaps2 */
278 0, /* dwFXAlphaCaps */
279 DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE, /* dwPalCaps */
281 0, /* dwAlphaBltConstBitDepths */
282 0, /* dwAlphaBltPixelBitDepths */
283 0, /* dwAlphaBltSurfaceBitDepths */
284 0, /* dwAlphaOverlayBltConstBitDepths */
285 0, /* dwAlphaOverlayBltPixelBitDepths */
286 0, /* dwAlphaOverlayBltSurfaceBitDepths */
287 0, /* dwZBufferBitDepths */
288 16*1024*1024, /* dwVidMemTotal */
289 16*1024*1024, /* dwVidMemFree */
290 0, /* dwMaxVisibleOverlays */
291 0, /* dwCurrVisibleOverlays */
292 0, /* dwNumFourCCCodes */
293 0, /* dwAlignBoundarySrc */
294 0, /* dwAlignSizeSrc */
295 0, /* dwAlignBoundaryDest */
296 0, /* dwAlignSizeDest */
297 0, /* dwAlignStrideAlign */
300 DDSCAPS_BACKBUFFER | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER |
301 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE | DDSCAPS_PRIMARYSURFACE |
302 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY |
303 DDSCAPS_VISIBLE | DDSCAPS_LOCALVIDMEM | DDSCAPS_NONLOCALVIDMEM /* dwCaps */
305 0, /* dwMinOverlayStretch */
306 0, /* dwMaxOverlayStretch */
307 0, /* dwMinLiveVideoStretch */
308 0, /* dwMaxLiveVideoStretch */
309 0, /* dwMinHwCodecStretch */
310 0, /* dwMaxHwCodecStretch */
315 0, /* dwSVBCKeyCaps */
319 0, /* dwVSBCKeyCaps */
323 0, /* dwSSBCKeyCaps */
326 0, /* dwMaxVideoPorts */
327 0, /* dwCurrVideoPorts */
330 0, /* dwMonitorFrequency */
331 X11DRV_DDHAL_GetDriverInfo,
333 NULL, /* lpdwFourCC */
335 NULL, /* lpModeInfo */
336 DDHALINFO_ISPRIMARYDISPLAY | DDHALINFO_MODEXILLEGAL | DDHALINFO_GETDRIVERINFOSET, /* dwFlags */
339 0, /* lpD3DGlobalDriverData */
340 0, /* lpD3DHALCallbacks */
341 NULL /* lpDDExeBufCallbacks */
344 static LPDDHALDDRAWFNS ddraw_fns;
345 static DWORD ddraw_ver;
347 static void X11DRV_DDHAL_SetInfo(void)
349 (ddraw_fns->lpSetInfo)(&hal_info, FALSE);
352 INT X11DRV_DCICommand(INT cbInput, const DCICMD *lpCmd, LPVOID lpOutData)
354 TRACE("(%d,(%ld,%ld,%ld),%p)\n", cbInput, lpCmd->dwCommand,
355 lpCmd->dwParam1, lpCmd->dwParam2, lpOutData);
357 switch (lpCmd->dwCommand) {
358 case DDNEWCALLBACKFNS:
359 ddraw_fns = (LPDDHALDDRAWFNS)lpCmd->dwParam1;
363 LPDDVERSIONDATA lpVer = (LPDDVERSIONDATA)lpOutData;
364 ddraw_ver = lpCmd->dwParam1;
366 /* well, whatever... the DDK says so */
367 lpVer->dwHALVersion = DD_RUNTIME_VERSION;
370 case DDGET32BITDRIVERNAME:
372 LPDD32BITDRIVERDATA lpData = (LPDD32BITDRIVERDATA)lpOutData;
373 /* here, we could ask ddraw to load a separate DLL, that
374 * would contain the 32-bit ddraw HAL */
375 strcpy(lpData->szName,"x11drv");
376 /* the entry point named here should initialize our hal_info
377 * with 32-bit entry points (ignored for now) */
378 strcpy(lpData->szEntryPoint,"DriverInit");
379 lpData->dwContext = 0;
382 case DDCREATEDRIVEROBJECT:
384 LPDWORD lpInstance = (LPDWORD)lpOutData;
386 /* FIXME: get x11drv's hInstance */
387 X11DRV_Settings_CreateDriver(&hal_info);
389 /*X11DRV_GLX_CreateDriver(&hal_info);*/
392 (ddraw_fns->lpSetInfo)(&hal_info, FALSE);
393 *lpInstance = hal_info.hInstance;
400 void X11DRV_DDHAL_SwitchMode(DWORD dwModeIndex, LPVOID fb_addr, LPVIDMEM fb_mem)
402 LPDDHALMODEINFO info = &hal_info.lpModeInfo[dwModeIndex];
404 hal_info.dwModeIndex = dwModeIndex;
405 hal_info.dwMonitorFrequency = info->wRefreshRate;
406 hal_info.vmiData.fpPrimary = (FLATPTR)fb_addr;
407 hal_info.vmiData.dwDisplayWidth = info->dwWidth;
408 hal_info.vmiData.dwDisplayHeight = info->dwHeight;
409 hal_info.vmiData.lDisplayPitch = info->lPitch;
410 hal_info.vmiData.ddpfDisplay.dwSize = info->dwBPP ? sizeof(hal_info.vmiData.ddpfDisplay) : 0;
411 hal_info.vmiData.ddpfDisplay.dwFlags = (info->wFlags & DDMODEINFO_PALETTIZED) ? DDPF_PALETTEINDEXED8 : 0;
412 hal_info.vmiData.ddpfDisplay.u1.dwRGBBitCount = (info->dwBPP > 24) ? 24 : info->dwBPP;
413 hal_info.vmiData.ddpfDisplay.u2.dwRBitMask = info->dwRBitMask;
414 hal_info.vmiData.ddpfDisplay.u3.dwGBitMask = info->dwGBitMask;
415 hal_info.vmiData.ddpfDisplay.u4.dwBBitMask = info->dwBBitMask;
416 hal_info.vmiData.dwNumHeaps = fb_mem ? 1 : 0;
417 hal_info.vmiData.pvmList = fb_mem;
419 X11DRV_DDHAL_SetInfo();
422 void X11DRV_DDHAL_SetPalEntries(Colormap pal, DWORD dwBase, DWORD dwNumEntries,
423 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 XStoreColor(gdi_display, pal, &c);
438 XFlush(gdi_display); /* update display immediately */