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
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
41 LPDDRAWI_DDRAWSURFACE_LCL X11DRV_DD_Primary;
42 LPDDRAWI_DDRAWSURFACE_GBL X11DRV_DD_PrimaryGbl;
43 HWND X11DRV_DD_PrimaryWnd;
44 HBITMAP X11DRV_DD_PrimaryDIB;
45 Drawable X11DRV_DD_PrimaryDrawable;
46 ATOM X11DRV_DD_UserClass;
47 BOOL X11DRV_DD_IsDirect;
48 static UINT X11DRV_DD_GrabMessage;
49 static WNDPROC X11DRV_DD_GrabOldProcedure;
51 static void SetPrimaryDIB(HBITMAP hBmp)
53 X11DRV_DD_PrimaryDIB = hBmp;
56 bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC );
57 X11DRV_DD_PrimaryDrawable = (Pixmap)bmp->physBitmap;
58 GDI_ReleaseObj( hBmp );
60 X11DRV_DD_PrimaryDrawable = 0;
64 static LRESULT WINAPI GrabWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
66 Display *display = thread_display();
68 if(message != X11DRV_DD_GrabMessage)
69 return CallWindowProcA(X11DRV_DD_GrabOldProcedure, hWnd, message, wParam, lParam);
71 TRACE("hwnd=%d, grab=%d\n", hWnd, wParam);
75 /* find the X11 window that ddraw uses */
76 Window win = X11DRV_get_whole_window(hWnd);
77 TRACE("X11 window: %ld\n", win);
79 TRACE("host off desktop\n");
83 TSXGrabPointer(display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
87 TSXUngrabPointer(display, CurrentTime);
93 static void GrabPointer(BOOL grab)
96 Window window = X11DRV_get_whole_window(GetFocus());
98 XSetInputFocus(thread_display(), window, RevertToParent, CurrentTime);
101 if(!X11DRV_DD_GrabMessage)
102 X11DRV_DD_GrabMessage = RegisterWindowMessageA("WINE_X11DRV_GRABPOINTER");
104 /* FIXME: Replace with SetWindowLongPtrA when available */
105 X11DRV_DD_GrabOldProcedure = (WNDPROC)SetWindowLongA(X11DRV_DD_PrimaryWnd,
106 GWL_WNDPROC, (LONG)GrabWndProc);
108 SendMessageA(X11DRV_DD_PrimaryWnd, X11DRV_DD_GrabMessage, grab ? 1 : 0, 0);
110 /* FIXME: Replace with SetWindowLongPtrA when available */
111 if(SetWindowLongA(X11DRV_DD_PrimaryWnd, GWL_WNDPROC,
112 (LONG)X11DRV_DD_GrabOldProcedure) != (LONG)GrabWndProc)
113 ERR("Window procedure has been changed!\n");
116 static DWORD PASCAL X11DRV_DDHAL_DestroyDriver(LPDDHAL_DESTROYDRIVERDATA data)
118 data->ddRVal = DD_OK;
119 return DDHAL_DRIVER_HANDLED;
122 static DWORD PASCAL X11DRV_DDHAL_CreateSurface(LPDDHAL_CREATESURFACEDATA data)
124 if (data->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) {
125 X11DRV_DD_Primary = *data->lplpSList;
126 X11DRV_DD_PrimaryWnd = (HWND)X11DRV_DD_Primary->lpSurfMore->lpDDRAWReserved;
127 X11DRV_DD_PrimaryGbl = X11DRV_DD_Primary->lpGbl;
128 SetPrimaryDIB(GET_LPDDRAWSURFACE_GBL_MORE(X11DRV_DD_PrimaryGbl)->hKernelSurface);
129 X11DRV_DD_UserClass = GlobalFindAtomA("WINE_DDRAW");
130 if (dxgrab) GrabPointer(TRUE);
132 data->ddRVal = DD_OK;
133 return DDHAL_DRIVER_NOTHANDLED;
136 static DWORD PASCAL X11DRV_DDHAL_CreatePalette(LPDDHAL_CREATEPALETTEDATA data)
139 /* only makes sense to do anything if the X server is running at 8bpp,
140 * which few people do nowadays */
141 data->ddRVal = DD_OK;
142 return DDHAL_DRIVER_HANDLED;
145 static DDHAL_DDCALLBACKS hal_ddcallbacks = {
146 sizeof(DDHAL_DDCALLBACKS),
147 0x3ff, /* all callbacks are 32-bit */
148 X11DRV_DDHAL_DestroyDriver,
149 X11DRV_DDHAL_CreateSurface,
150 NULL, /* SetColorKey */
152 NULL, /* WaitForVerticalBlank */
153 NULL, /* CanCreateSurface */
154 X11DRV_DDHAL_CreatePalette,
155 NULL, /* GetScanLine */
156 NULL, /* SetExclusiveMode */
157 NULL /* FlipToGDISurface */
160 static DWORD PASCAL X11DRV_DDHAL_DestroySurface(LPDDHAL_DESTROYSURFACEDATA data)
162 if (data->lpDDSurface == X11DRV_DD_Primary) {
163 if (dxgrab) GrabPointer(FALSE);
164 X11DRV_DD_Primary = NULL;
165 X11DRV_DD_PrimaryWnd = 0;
166 X11DRV_DD_PrimaryGbl = NULL;
168 X11DRV_DD_UserClass = 0;
170 data->ddRVal = DD_OK;
171 return DDHAL_DRIVER_HANDLED;
174 static DWORD PASCAL X11DRV_DDHAL_SetPalette(LPDDHAL_SETPALETTEDATA data)
176 if (data->lpDDPalette && data->lpDDPalette->u1.dwReserved1) {
177 if (data->lpDDSurface == X11DRV_DD_Primary) {
179 /* we should probably find the ddraw window (maybe data->lpDD->lpExclusiveOwner->hWnd),
180 * and attach the palette to it
182 * Colormap pal = data->lpDDPalette->u1.dwReserved1;
186 data->ddRVal = DD_OK;
187 return DDHAL_DRIVER_HANDLED;
190 static DDHAL_DDSURFACECALLBACKS hal_ddsurfcallbacks = {
191 sizeof(DDHAL_DDSURFACECALLBACKS),
192 0x3fff, /* all callbacks are 32-bit */
193 X11DRV_DDHAL_DestroySurface,
195 NULL, /* SetClipList */
199 NULL, /* SetColorKey */
200 NULL, /* AddAttachedSurface */
201 NULL, /* GetBltStatus */
202 NULL, /* GetFlipStatus */
203 NULL, /* UpdateOverlay */
204 NULL, /* SetOverlayPosition */
205 NULL, /* reserved4 */
206 X11DRV_DDHAL_SetPalette
209 static DWORD PASCAL X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data)
211 Colormap pal = data->lpDDPalette->u1.dwReserved1;
212 if (pal) TSXFreeColormap(gdi_display, pal);
213 data->ddRVal = DD_OK;
214 return DDHAL_DRIVER_HANDLED;
217 static DWORD PASCAL X11DRV_DDHAL_SetPaletteEntries(LPDDHAL_SETENTRIESDATA data)
219 X11DRV_DDHAL_SetPalEntries(data->lpDDPalette->u1.dwReserved1,
220 data->dwBase, data->dwNumEntries,
222 data->ddRVal = DD_OK;
223 return DDHAL_DRIVER_HANDLED;
226 static DDHAL_DDPALETTECALLBACKS hal_ddpalcallbacks = {
227 sizeof(DDHAL_DDPALETTECALLBACKS),
228 0x3, /* all callbacks are 32-bit */
229 X11DRV_DDHAL_DestroyPalette,
230 X11DRV_DDHAL_SetPaletteEntries
233 static X11DEVICE x11device = {
237 static DWORD PASCAL X11DRV_DDHAL_GetDriverInfo(LPDDHAL_GETDRIVERINFODATA data)
239 LPX11DRIVERINFO info = x11device.lpInfo;
241 if (IsEqualGUID(&data->guidInfo, info->lpGuid)) {
242 DWORD dwSize = info->dwSize;
243 data->dwActualSize = dwSize;
244 if (data->dwExpectedSize < dwSize) dwSize = data->dwExpectedSize;
245 memcpy(data->lpvData, info->lpvData, dwSize);
246 data->ddRVal = DD_OK;
247 return DDHAL_DRIVER_HANDLED;
251 data->ddRVal = DDERR_CURRENTLYNOTAVAIL;
252 return DDHAL_DRIVER_HANDLED;
255 static DDHALINFO hal_info = {
258 &hal_ddsurfcallbacks,
263 { /* ddCaps (only stuff the HAL implements here) */
264 sizeof(DDCORECAPS), /* dwSize */
265 DDCAPS_GDI | DDCAPS_PALETTE, /* dwCaps */
266 DDCAPS2_CERTIFIED | DDCAPS2_NONLOCALVIDMEM | DDCAPS2_NOPAGELOCKREQUIRED |
267 DDCAPS2_WIDESURFACES | DDCAPS2_PRIMARYGAMMA | DDCAPS2_FLIPNOVSYNC, /* dwCaps2 */
270 0, /* dwFXAlphaCaps */
271 DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE, /* dwPalCaps */
273 0, /* dwAlphaBltConstBitDepths */
274 0, /* dwAlphaBltPixelBitDepths */
275 0, /* dwAlphaBltSurfaceBitDepths */
276 0, /* dwAlphaOverlayBltConstBitDepths */
277 0, /* dwAlphaOverlayBltPixelBitDepths */
278 0, /* dwAlphaOverlayBltSurfaceBitDepths */
279 0, /* dwZBufferBitDepths */
280 16*1024*1024, /* dwVidMemTotal */
281 16*1024*1024, /* dwVidMemFree */
282 0, /* dwMaxVisibleOverlays */
283 0, /* dwCurrVisibleOverlays */
284 0, /* dwNumFourCCCodes */
285 0, /* dwAlignBoundarySrc */
286 0, /* dwAlignSizeSrc */
287 0, /* dwAlignBoundaryDest */
288 0, /* dwAlignSizeDest */
289 0, /* dwAlignStrideAlign */
292 DDSCAPS_BACKBUFFER | DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER |
293 DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE | DDSCAPS_PRIMARYSURFACE |
294 DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY |
295 DDSCAPS_VISIBLE | DDSCAPS_LOCALVIDMEM | DDSCAPS_NONLOCALVIDMEM /* dwCaps */
297 0, /* dwMinOverlayStretch */
298 0, /* dwMaxOverlayStretch */
299 0, /* dwMinLiveVideoStretch */
300 0, /* dwMaxLiveVideoStretch */
301 0, /* dwMinHwCodecStretch */
302 0, /* dwMaxHwCodecStretch */
307 0, /* dwSVBCKeyCaps */
311 0, /* dwVSBCKeyCaps */
315 0, /* dwSSBCKeyCaps */
318 0, /* dwMaxVideoPorts */
319 0, /* dwCurrVideoPorts */
322 0, /* dwMonitorFrequency */
323 X11DRV_DDHAL_GetDriverInfo,
325 NULL, /* lpdwFourCC */
327 NULL, /* lpModeInfo */
328 DDHALINFO_ISPRIMARYDISPLAY | DDHALINFO_MODEXILLEGAL | DDHALINFO_GETDRIVERINFOSET, /* dwFlags */
331 0, /* lpD3DGlobalDriverData */
332 0, /* lpD3DHALCallbacks */
333 NULL /* lpDDExeBufCallbacks */
336 static LPDDHALDDRAWFNS ddraw_fns;
337 static DWORD ddraw_ver;
339 static void X11DRV_DDHAL_SetInfo(void)
341 (ddraw_fns->lpSetInfo)(&hal_info, FALSE);
344 INT X11DRV_DCICommand(INT cbInput, const DCICMD *lpCmd, LPVOID lpOutData)
346 TRACE("(%d,(%ld,%ld,%ld),%p)\n", cbInput, lpCmd->dwCommand,
347 lpCmd->dwParam1, lpCmd->dwParam2, lpOutData);
349 switch (lpCmd->dwCommand) {
350 case DDNEWCALLBACKFNS:
351 ddraw_fns = (LPDDHALDDRAWFNS)lpCmd->dwParam1;
355 LPDDVERSIONDATA lpVer = (LPDDVERSIONDATA)lpOutData;
356 ddraw_ver = lpCmd->dwParam1;
358 /* well, whatever... the DDK says so */
359 lpVer->dwHALVersion = DD_RUNTIME_VERSION;
362 case DDGET32BITDRIVERNAME:
364 LPDD32BITDRIVERDATA lpData = (LPDD32BITDRIVERDATA)lpOutData;
365 /* here, we could ask ddraw to load a separate DLL, that
366 * would contain the 32-bit ddraw HAL */
367 strcpy(lpData->szName,"x11drv");
368 /* the entry point named here should initialize our hal_info
369 * with 32-bit entry points (ignored for now) */
370 strcpy(lpData->szEntryPoint,"DriverInit");
371 lpData->dwContext = 0;
374 case DDCREATEDRIVEROBJECT:
376 LPDWORD lpInstance = (LPDWORD)lpOutData;
378 /* FIXME: get x11drv's hInstance */
379 #ifdef HAVE_LIBXXF86DGA2
380 if (!X11DRV_XF86DGA2_CreateDriver(&hal_info))
383 #ifdef HAVE_LIBXXF86VM
384 X11DRV_XF86VM_CreateDriver(&hal_info);
388 /*X11DRV_GLX_CreateDriver(&hal_info);*/
391 (ddraw_fns->lpSetInfo)(&hal_info, FALSE);
392 *lpInstance = hal_info.hInstance;
399 void X11DRV_DDHAL_SwitchMode(DWORD dwModeIndex, LPVOID fb_addr, LPVIDMEM fb_mem)
401 LPDDHALMODEINFO info = &hal_info.lpModeInfo[dwModeIndex];
403 hal_info.dwModeIndex = dwModeIndex;
404 hal_info.dwMonitorFrequency = info->wRefreshRate;
405 hal_info.vmiData.fpPrimary = (FLATPTR)fb_addr;
406 hal_info.vmiData.dwDisplayWidth = info->dwWidth;
407 hal_info.vmiData.dwDisplayHeight = info->dwHeight;
408 hal_info.vmiData.lDisplayPitch = info->lPitch;
409 hal_info.vmiData.ddpfDisplay.dwSize = info->dwBPP ? sizeof(hal_info.vmiData.ddpfDisplay) : 0;
410 hal_info.vmiData.ddpfDisplay.dwFlags = (info->wFlags & DDMODEINFO_PALETTIZED) ? DDPF_PALETTEINDEXED8 : 0;
411 hal_info.vmiData.ddpfDisplay.u1.dwRGBBitCount = (info->dwBPP > 24) ? 24 : info->dwBPP;
412 hal_info.vmiData.ddpfDisplay.u2.dwRBitMask = info->dwRBitMask;
413 hal_info.vmiData.ddpfDisplay.u3.dwGBitMask = info->dwGBitMask;
414 hal_info.vmiData.ddpfDisplay.u4.dwBBitMask = info->dwBBitMask;
415 hal_info.vmiData.dwNumHeaps = fb_mem ? 1 : 0;
416 hal_info.vmiData.pvmList = fb_mem;
418 X11DRV_DDHAL_SetInfo();
421 void X11DRV_DDHAL_SetPalEntries(Colormap pal, DWORD dwBase, DWORD dwNumEntries,
422 LPPALETTEENTRY lpEntries)
428 c.flags = DoRed|DoGreen|DoBlue;
430 for (n=0; n<dwNumEntries; n++,c.pixel++) {
431 c.red = lpEntries[n].peRed << 8;
432 c.green = lpEntries[n].peGreen << 8;
433 c.blue = lpEntries[n].peBlue << 8;
434 TSXStoreColor(gdi_display, pal, &c);
436 TSXFlush(gdi_display); /* update display immediately */