2 * DirectDraw driver interface
4 * Copyright 2001 TransGaming Technologies, Inc.
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(x11drv
);
21 LPDDRAWI_DDRAWSURFACE_LCL X11DRV_DD_Primary
;
22 LPDDRAWI_DDRAWSURFACE_GBL X11DRV_DD_PrimaryGbl
;
23 HBITMAP X11DRV_DD_PrimaryDIB
;
24 Drawable X11DRV_DD_PrimaryDrawable
;
25 ATOM X11DRV_DD_UserClass
;
26 BOOL X11DRV_DD_IsDirect
;
28 static void SetPrimaryDIB(HBITMAP hBmp
)
30 X11DRV_DD_PrimaryDIB
= hBmp
;
33 bmp
= (BITMAPOBJ
*)GDI_GetObjPtr( hBmp
, BITMAP_MAGIC
);
34 X11DRV_DD_PrimaryDrawable
= (Pixmap
)bmp
->physBitmap
;
35 GDI_ReleaseObj( hBmp
);
37 X11DRV_DD_PrimaryDrawable
= 0;
41 static DWORD PASCAL
X11DRV_DDHAL_DestroyDriver(LPDDHAL_DESTROYDRIVERDATA data
)
44 return DDHAL_DRIVER_HANDLED
;
47 static DWORD PASCAL
X11DRV_DDHAL_CreateSurface(LPDDHAL_CREATESURFACEDATA data
)
49 if (data
->lpDDSurfaceDesc
->ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) {
50 X11DRV_DD_Primary
= *data
->lplpSList
;
51 X11DRV_DD_PrimaryGbl
= X11DRV_DD_Primary
->lpGbl
;
52 SetPrimaryDIB(GET_LPDDRAWSURFACE_GBL_MORE(X11DRV_DD_PrimaryGbl
)->hKernelSurface
);
53 X11DRV_DD_UserClass
= GlobalFindAtomA("WINE_DDRAW");
56 return DDHAL_DRIVER_NOTHANDLED
;
59 static DWORD PASCAL
X11DRV_DDHAL_CreatePalette(LPDDHAL_CREATEPALETTEDATA data
)
62 /* only makes sense to do anything if the X server is running at 8bpp,
63 * which few people do nowadays */
65 return DDHAL_DRIVER_HANDLED
;
68 static DDHAL_DDCALLBACKS hal_ddcallbacks
= {
69 sizeof(DDHAL_DDCALLBACKS
),
70 0x3ff, /* all callbacks are 32-bit */
71 X11DRV_DDHAL_DestroyDriver
,
72 X11DRV_DDHAL_CreateSurface
,
73 NULL
, /* SetColorKey */
75 NULL
, /* WaitForVerticalBlank */
76 NULL
, /* CanCreateSurface */
77 X11DRV_DDHAL_CreatePalette
,
78 NULL
, /* GetScanLine */
79 NULL
, /* SetExclusiveMode */
80 NULL
/* FlipToGDISurface */
83 static DWORD PASCAL
X11DRV_DDHAL_DestroySurface(LPDDHAL_DESTROYSURFACEDATA data
)
85 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
86 X11DRV_DD_Primary
= NULL
;
87 X11DRV_DD_PrimaryGbl
= NULL
;
89 X11DRV_DD_UserClass
= 0;
92 return DDHAL_DRIVER_HANDLED
;
95 static DWORD PASCAL
X11DRV_DDHAL_SetPalette(LPDDHAL_SETPALETTEDATA data
)
97 Colormap pal
= data
->lpDDPalette
->u1
.dwReserved1
;
99 if (data
->lpDDSurface
== X11DRV_DD_Primary
) {
101 /* we should probably find the ddraw window (maybe data->lpDD->lpExclusiveOwner->hWnd),
102 * and attach the palette to it */
105 data
->ddRVal
= DD_OK
;
106 return DDHAL_DRIVER_HANDLED
;
109 static DDHAL_DDSURFACECALLBACKS hal_ddsurfcallbacks
= {
110 sizeof(DDHAL_DDSURFACECALLBACKS
),
111 0x3fff, /* all callbacks are 32-bit */
112 X11DRV_DDHAL_DestroySurface
,
114 NULL
, /* SetClipList */
118 NULL
, /* SetColorKey */
119 NULL
, /* AddAttachedSurface */
120 NULL
, /* GetBltStatus */
121 NULL
, /* GetFlipStatus */
122 NULL
, /* UpdateOverlay */
123 NULL
, /* SetOverlayPosition */
124 NULL
, /* reserved4 */
125 X11DRV_DDHAL_SetPalette
128 static DWORD PASCAL
X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data
)
130 Colormap pal
= data
->lpDDPalette
->u1
.dwReserved1
;
131 if (pal
) TSXFreeColormap(display
, pal
);
132 data
->ddRVal
= DD_OK
;
133 return DDHAL_DRIVER_HANDLED
;
136 static DWORD PASCAL
X11DRV_DDHAL_SetPaletteEntries(LPDDHAL_SETENTRIESDATA data
)
138 X11DRV_DDHAL_SetPalEntries(data
->lpDDPalette
->u1
.dwReserved1
,
139 data
->dwBase
, data
->dwNumEntries
,
141 data
->ddRVal
= DD_OK
;
142 return DDHAL_DRIVER_HANDLED
;
145 static DDHAL_DDPALETTECALLBACKS hal_ddpalcallbacks
= {
146 sizeof(DDHAL_DDPALETTECALLBACKS
),
147 0x3, /* all callbacks are 32-bit */
148 X11DRV_DDHAL_DestroyPalette
,
149 X11DRV_DDHAL_SetPaletteEntries
152 static DDHALINFO hal_info
= {
155 &hal_ddsurfcallbacks
,
163 0, /* dwMonitorFrequency */
164 NULL
, /* GetDriverInfo */
166 NULL
, /* lpdwFourCC */
168 NULL
, /* lpModeInfo */
169 DDHALINFO_ISPRIMARYDISPLAY
| DDHALINFO_MODEXILLEGAL
, /* dwFlags */
170 NULL
, /* lpPDevice */
174 static LPDDHALDDRAWFNS ddraw_fns
;
175 static DWORD ddraw_ver
;
177 static void X11DRV_DDHAL_SetInfo(void)
179 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
182 INT
X11DRV_DCICommand(INT cbInput
, LPVOID lpInData
, LPVOID lpOutData
)
184 LPDCICMD lpCmd
= (LPDCICMD
)lpInData
;
186 TRACE("(%d,(%ld,%ld,%ld),%p)\n", cbInput
, lpCmd
->dwCommand
,
187 lpCmd
->dwParam1
, lpCmd
->dwParam2
, lpOutData
);
189 switch (lpCmd
->dwCommand
) {
190 case DDNEWCALLBACKFNS
:
191 ddraw_fns
= (LPDDHALDDRAWFNS
)lpCmd
->dwParam1
;
195 LPDDVERSIONDATA lpVer
= (LPDDVERSIONDATA
)lpOutData
;
196 ddraw_ver
= lpCmd
->dwParam1
;
198 /* well, whatever... the DDK says so */
199 lpVer
->dwHALVersion
= DD_RUNTIME_VERSION
;
202 case DDGET32BITDRIVERNAME
:
204 LPDD32BITDRIVERDATA lpData
= (LPDD32BITDRIVERDATA
)lpOutData
;
205 /* here, we could ask ddraw to load a separate DLL, that
206 * would contain the 32-bit ddraw HAL */
207 strcpy(lpData
->szName
,"x11drv");
208 /* the entry point named here should initialize our hal_info
209 * with 32-bit entry points (ignored for now) */
210 strcpy(lpData
->szEntryPoint
,"DriverInit");
211 lpData
->dwContext
= 0;
214 case DDCREATEDRIVEROBJECT
:
216 LPDWORD lpInstance
= (LPDWORD
)lpOutData
;
218 /* FIXME: get x11drv's hInstance */
219 #ifdef HAVE_LIBXXF86DGA2
220 /*if (!X11DRV_XF86DGA2_CreateDriver(&hal_info))*/
223 #ifdef HAVE_LIBXXF86VM
224 X11DRV_XF86VM_CreateDriver(&hal_info
);
228 (ddraw_fns
->lpSetInfo
)(&hal_info
, FALSE
);
229 *lpInstance
= hal_info
.hInstance
;
236 void X11DRV_DDHAL_SwitchMode(DWORD dwModeIndex
, LPVOID fb_addr
)
238 LPDDHALMODEINFO info
= &hal_info
.lpModeInfo
[dwModeIndex
];
240 hal_info
.dwModeIndex
= dwModeIndex
;
241 hal_info
.dwMonitorFrequency
= info
->wRefreshRate
;
242 hal_info
.vmiData
.fpPrimary
= (FLATPTR
)fb_addr
;
243 hal_info
.vmiData
.dwDisplayWidth
= info
->dwWidth
;
244 hal_info
.vmiData
.dwDisplayHeight
= info
->dwHeight
;
245 hal_info
.vmiData
.lDisplayPitch
= info
->lPitch
;
246 hal_info
.vmiData
.ddpfDisplay
.dwSize
= info
->dwBPP
? sizeof(hal_info
.vmiData
.ddpfDisplay
) : 0;
247 hal_info
.vmiData
.ddpfDisplay
.dwFlags
= (info
->wFlags
& DDMODEINFO_PALETTIZED
) ? DDPF_PALETTEINDEXED8
: 0;
248 hal_info
.vmiData
.ddpfDisplay
.u1
.dwRGBBitCount
= (info
->dwBPP
> 24) ? 24 : info
->dwBPP
;
249 hal_info
.vmiData
.ddpfDisplay
.u2
.dwRBitMask
= info
->dwRBitMask
;
250 hal_info
.vmiData
.ddpfDisplay
.u3
.dwGBitMask
= info
->dwGBitMask
;
251 hal_info
.vmiData
.ddpfDisplay
.u4
.dwBBitMask
= info
->dwBBitMask
;
253 X11DRV_DDHAL_SetInfo();
256 void X11DRV_DDHAL_SetPalEntries(Colormap pal
, DWORD dwBase
, DWORD dwNumEntries
,
257 LPPALETTEENTRY lpEntries
)
263 c
.flags
= DoRed
|DoGreen
|DoBlue
;
265 for (n
=0; n
<dwNumEntries
; n
++,c
.pixel
++) {
266 c
.red
= lpEntries
[n
].peRed
<< 8;
267 c
.green
= lpEntries
[n
].peGreen
<< 8;
268 c
.blue
= lpEntries
[n
].peBlue
<< 8;
269 TSXStoreColor(display
, pal
, &c
);
271 TSXFlush(display
); /* update display immediate */