1 /* DirectDraw using DGA
3 * Copyright 1997,1998 Marcus Meissner
5 /* When DirectVideo mode is enabled you can no longer use 'normal' X
6 * applications nor can you switch to a virtual console. Also, enabling
7 * only works, if you have switched to the screen where the application
9 * Some ways to debug this stuff are:
10 * - A terminal connected to the serial port. Can be bought used for cheap.
11 * (This is the method I am using.)
12 * - Another machine connected over some kind of network.
14 /* Progress on following programs:
16 * - Diablo [640x480x8]:
17 * The movies play. The game doesn't work, it somehow tries to write
18 * into 2 lines _BEFORE_ the start of the surface. Don't know why.
20 * - WingCommander 4 / Win95 Patch [640x480x8]:
21 * The intromovie plays, in 8 bit mode (to reconfigure wc4, run wine
22 * "wc4w.exe -I"). The 16bit mode looks broken, but I think this is due to
23 * my Matrox Mystique which uses 565 (rgb) colorweight instead of the usual
24 * 555. Specifying it in DDPIXELFORMAT didn't help.
25 * Requires to be run in 640x480xdepth mode (doesn't seem to heed
26 * DDSURFACEDESC.lPitch). You can fly the first mission with Maniac, but
27 * it crashes as soon as you arrive at Blue Point Station...
29 * - Monkey Island 3 [640x480x8]:
30 * Goes to the easy/hard selection screen, then hangs due to MT problems.
32 * - DiscWorld 2 [640x480x8]:
33 * [Crashes with 'cli' in released version. Yes. Privileged instructions
34 * in 32bit code. Will they ever learn...]
35 * Plays through nearly all intro movies. Sound and animation skip a lot of
36 * stuff (possible DirectSound problem).
39 * Shows the splash screen, then fails with missing Joystick.
41 * - Tomb Raider 2 Demo (using 8 bit renderer) [640x480x8]:
42 * Playable. Sound is weird.
44 * - WingCommander Prophecy Demo (using software renderer) [640x480x16]:
45 * [Crashes with an invalid opcode (outb) in the release version.]
46 * Plays intromovie, hangs in selection screen (no keyboard input, probably
47 * DirectInput problem).
55 #include <sys/signal.h>
59 #include "interfaces.h"
70 #ifdef HAVE_LIBXXF86DGA
71 #include <X11/extensions/xf86dga.h>
74 /* restore signal handlers overwritten by XF86DGA
75 * this is a define, for it will only work in emulator mode
77 #undef RESTORE_SIGNALS
79 static struct IDirectDrawSurface3_VTable dds3vt
;
80 static struct IDirectDrawSurface2_VTable dds2vt
;
81 static struct IDirectDrawSurface_VTable ddsvt
;
82 static struct IDirectDraw_VTable ddvt
;
83 static struct IDirectDraw2_VTable dd2vt
;
84 static struct IDirect3D_VTable d3dvt
;
85 static struct IDirect3D2_VTable d3d2vt
;
89 DirectDrawEnumerate32A(LPDDENUMCALLBACK32A ddenumproc
,LPVOID data
) {
90 /* we have just one display driver right now ... */
91 ddenumproc(0,"WINE Display","display",data
);
96 DSoundHelp(DWORD x
,DWORD y
,DWORD z
) {
97 FIXME(ddraw
,"(0x%08lx,0x%08lx,0x%08lx),stub!\n",x
,y
,z
);
102 #ifdef HAVE_LIBXXF86DGA
104 /******************************************************************************
105 * internal helper functions
107 static void _dump_DDBLTFX(DWORD flagmask
) {
113 #define FE(x) { x, #x},
114 FE(DDBLTFX_ARITHSTRETCHY
)
115 FE(DDBLTFX_MIRRORLEFTRIGHT
)
116 FE(DDBLTFX_MIRRORUPDOWN
)
117 FE(DDBLTFX_NOTEARING
)
118 FE(DDBLTFX_ROTATE180
)
119 FE(DDBLTFX_ROTATE270
)
121 FE(DDBLTFX_ZBUFFERRANGE
)
122 FE(DDBLTFX_ZBUFFERBASEDEST
)
124 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
125 if (flags
[i
].mask
& flagmask
) {
126 DUMP("%s ",flags
[i
].name
);
133 static void _dump_DDBLTFAST(DWORD flagmask
) {
139 #define FE(x) { x, #x},
140 FE(DDBLTFAST_NOCOLORKEY
)
141 FE(DDBLTFAST_SRCCOLORKEY
)
142 FE(DDBLTFAST_DESTCOLORKEY
)
145 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
146 if (flags
[i
].mask
& flagmask
)
147 DUMP("%s ",i
,flags
[i
].name
);
151 static void _dump_DDBLT(DWORD flagmask
) {
157 #define FE(x) { x, #x},
159 FE(DDBLT_ALPHADESTCONSTOVERRIDE
)
160 FE(DDBLT_ALPHADESTNEG
)
161 FE(DDBLT_ALPHADESTSURFACEOVERRIDE
)
162 FE(DDBLT_ALPHAEDGEBLEND
)
164 FE(DDBLT_ALPHASRCCONSTOVERRIDE
)
165 FE(DDBLT_ALPHASRCNEG
)
166 FE(DDBLT_ALPHASRCSURFACEOVERRIDE
)
172 FE(DDBLT_KEYDESTOVERRIDE
)
174 FE(DDBLT_KEYSRCOVERRIDE
)
176 FE(DDBLT_ROTATIONANGLE
)
178 FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE
)
179 FE(DDBLT_ZBUFFERDESTOVERRIDE
)
180 FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE
)
181 FE(DDBLT_ZBUFFERSRCOVERRIDE
)
185 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
186 if (flags
[i
].mask
& flagmask
)
187 DUMP("%s ",i
,flags
[i
].name
);
190 static void _dump_DDSCAPS(DWORD flagmask
) {
196 #define FE(x) { x, #x},
197 FE(DDSCAPS_RESERVED1
)
199 FE(DDSCAPS_BACKBUFFER
)
202 FE(DDSCAPS_FRONTBUFFER
)
203 FE(DDSCAPS_OFFSCREENPLAIN
)
206 FE(DDSCAPS_PRIMARYSURFACE
)
207 FE(DDSCAPS_PRIMARYSURFACELEFT
)
208 FE(DDSCAPS_SYSTEMMEMORY
)
211 FE(DDSCAPS_VIDEOMEMORY
)
213 FE(DDSCAPS_WRITEONLY
)
216 FE(DDSCAPS_LIVEVIDEO
)
220 FE(DDSCAPS_RESERVED2
)
221 FE(DDSCAPS_ALLOCONLOAD
)
222 FE(DDSCAPS_VIDEOPORT
)
223 FE(DDSCAPS_LOCALVIDMEM
)
224 FE(DDSCAPS_NONLOCALVIDMEM
)
225 FE(DDSCAPS_STANDARDVGAMODE
)
226 FE(DDSCAPS_OPTIMIZED
)
228 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
229 if (flags
[i
].mask
& flagmask
)
230 DUMP("%s ",flags
[i
].name
);
234 static void _dump_DDCAPS(DWORD flagmask
) {
240 #define FE(x) { x, #x},
242 FE(DDCAPS_ALIGNBOUNDARYDEST
)
243 FE(DDCAPS_ALIGNSIZEDEST
)
244 FE(DDCAPS_ALIGNBOUNDARYSRC
)
245 FE(DDCAPS_ALIGNSIZESRC
)
246 FE(DDCAPS_ALIGNSTRIDE
)
250 FE(DDCAPS_BLTSTRETCH
)
253 FE(DDCAPS_OVERLAYCANTCLIP
)
254 FE(DDCAPS_OVERLAYFOURCC
)
255 FE(DDCAPS_OVERLAYSTRETCH
)
257 FE(DDCAPS_PALETTEVSYNC
)
258 FE(DDCAPS_READSCANLINE
)
259 FE(DDCAPS_STEREOVIEW
)
265 FE(DDCAPS_COLORKEYHWASSIST
)
266 FE(DDCAPS_NOHARDWARE
)
267 FE(DDCAPS_BLTCOLORFILL
)
268 FE(DDCAPS_BANKSWITCHED
)
269 FE(DDCAPS_BLTDEPTHFILL
)
271 FE(DDCAPS_CANCLIPSTRETCHED
)
272 FE(DDCAPS_CANBLTSYSMEM
)
274 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
275 if (flags
[i
].mask
& flagmask
)
276 DUMP("%s ",flags
[i
].name
);
280 static void _dump_DDSD(DWORD flagmask
) {
290 FE(DDSD_BACKBUFFERCOUNT
)
291 FE(DDSD_ZBUFFERBITDEPTH
)
292 FE(DDSD_ALPHABITDEPTH
)
294 FE(DDSD_CKDESTOVERLAY
)
296 FE(DDSD_CKSRCOVERLAY
)
303 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
304 if (flags
[i
].mask
& flagmask
)
305 DUMP("%s ",i
,flags
[i
].name
);
309 static int _getpixelformat(LPDIRECTDRAW ddraw
,LPDDPIXELFORMAT pf
) {
310 static XVisualInfo
*vi
;
315 vi
= TSXGetVisualInfo(display
,VisualNoMask
,&vt
,&nitems
);
318 if (ddraw
->d
.depth
==8) {
319 pf
->dwFlags
= DDPF_RGB
|DDPF_PALETTEINDEXED8
;
320 pf
->x
.dwRGBBitCount
= 8;
321 pf
->y
.dwRBitMask
= 0;
322 pf
->z
.dwGBitMask
= 0;
323 pf
->xx
.dwBBitMask
= 0;
324 pf
->xy
.dwRGBAlphaBitMask
= 0;
327 if (ddraw
->d
.depth
==16) {
328 pf
->dwFlags
= DDPF_RGB
;
329 pf
->x
.dwRGBBitCount
= 16;
330 pf
->y
.dwRBitMask
= vi
[0].red_mask
;
331 pf
->z
.dwGBitMask
= vi
[0].green_mask
;
332 pf
->xx
.dwBBitMask
= vi
[0].blue_mask
;
333 pf
->xy
.dwRGBAlphaBitMask
= 0;
336 FIXME(ddraw
,"_getpixelformat:oops?\n");
337 return DDERR_GENERIC
;
340 /******************************************************************************
344 static HRESULT WINAPI
IDirectDrawSurface_Lock(
345 LPDIRECTDRAWSURFACE
this,LPRECT32 lprect
,LPDDSURFACEDESC lpddsd
,DWORD flags
, HANDLE32 hnd
347 TRACE(ddraw
, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
348 this,lprect
,lpddsd
,flags
,(DWORD
)hnd
);
349 if (flags
& ~(DDLOCK_WAIT
|DDLOCK_READONLY
|DDLOCK_WRITEONLY
))
350 WARN(ddraw
, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
351 this,lprect
,lpddsd
,flags
,(DWORD
)hnd
);
354 TRACE(ddraw
," lprect: %dx%d-%dx%d\n",
355 lprect
->top
,lprect
->left
,lprect
->bottom
,lprect
->right
357 lpddsd
->y
.lpSurface
= this->s
.surface
+
358 (lprect
->top
*this->s
.lpitch
)+
359 (lprect
->left
*(this->s
.ddraw
->d
.depth
/8));
361 lpddsd
->y
.lpSurface
= this->s
.surface
;
362 lpddsd
->dwFlags
= DDSD_WIDTH
|DDSD_HEIGHT
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_LPSURFACE
;
363 lpddsd
->dwWidth
= this->s
.width
;
364 lpddsd
->dwHeight
= this->s
.height
;
365 lpddsd
->lPitch
= this->s
.lpitch
;
366 _getpixelformat(this->s
.ddraw
,&(lpddsd
->ddpfPixelFormat
));
370 static HRESULT WINAPI
IDirectDrawSurface_Unlock(
371 LPDIRECTDRAWSURFACE
this,LPVOID surface
373 TRACE(ddraw
,"(%p)->Unlock(%p)\n",this,surface
);
377 static HRESULT WINAPI
IDirectDrawSurface_Flip(
378 LPDIRECTDRAWSURFACE
this,LPDIRECTDRAWSURFACE flipto
,DWORD dwFlags
380 TRACE(ddraw
,"(%p)->Flip(%p,%08lx)\n",this,flipto
,dwFlags
);
382 if (this->s
.backbuffer
)
383 flipto
= this->s
.backbuffer
;
387 XF86DGASetViewPort(display
,DefaultScreen(display
),0,flipto
->s
.fb_height
);
388 if (flipto
->s
.palette
&& flipto
->s
.palette
->cm
)
389 XF86DGAInstallColormap(display
,DefaultScreen(display
),flipto
->s
.palette
->cm
);
390 while (!XF86DGAViewPortChanged(display
,DefaultScreen(display
),2)) {
396 tmp
= this->s
.fb_height
;
397 this->s
.fb_height
= flipto
->s
.fb_height
;
398 flipto
->s
.fb_height
= tmp
;
400 ptmp
= this->s
.surface
;
401 this->s
.surface
= flipto
->s
.surface
;
402 flipto
->s
.surface
= ptmp
;
407 static HRESULT WINAPI
IDirectDrawSurface_SetPalette(
408 LPDIRECTDRAWSURFACE
this,LPDIRECTDRAWPALETTE pal
410 TRACE(ddraw
,"(%p)->SetPalette(%p)\n",this,pal
);
411 this->s
.palette
= pal
; /* probably addref it too */
415 static HRESULT WINAPI
IDirectDrawSurface_Blt(
416 LPDIRECTDRAWSURFACE
this,LPRECT32 rdst
,LPDIRECTDRAWSURFACE src
,LPRECT32 rsrc
,DWORD dwFlags
,LPDDBLTFX lpbltfx
422 memcpy(&xdst
,rdst
,sizeof(xdst
));
425 xdst
.bottom
= this->s
.height
;
427 xdst
.right
= this->s
.width
;
430 memcpy(&xsrc
,rsrc
,sizeof(xsrc
));
433 xsrc
.bottom
= src
->s
.height
;
435 xsrc
.right
= src
->s
.width
;
438 if (dwFlags
& DDBLT_COLORFILL
) {
439 int bpp
= this->s
.ddraw
->d
.depth
/8;
442 xline
= (LPBYTE
)this->s
.surface
+xdst
.top
*this->s
.lpitch
;
443 for (i
=xdst
.top
;i
<xdst
.bottom
;i
++) {
444 xpixel
= xline
+bpp
*xdst
.left
;
446 for (j
=xdst
.left
;j
<xdst
.right
;j
++) {
447 /* FIXME: this only works on little endian
448 * architectures, where DWORD starts with low
451 memcpy(xpixel
,&(lpbltfx
->b
.dwFillColor
),bpp
);
454 xline
+= this->s
.lpitch
;
456 dwFlags
&= ~(DDBLT_COLORFILL
);
458 dwFlags
&= ~(DDBLT_WAIT
|DDBLT_ASYNC
);/* FIXME: can't handle right now */
459 if ( (xsrc
.top
==0) && (xsrc
.bottom
==this->s
.height
) &&
460 (xsrc
.left
==0) && (xsrc
.right
==this->s
.width
) &&
461 (xdst
.top
==0) && (xdst
.bottom
==this->s
.height
) &&
462 (xdst
.left
==0) && (xdst
.right
==this->s
.width
) &&
465 memcpy(this->s
.surface
,src
->s
.surface
,this->s
.height
*this->s
.lpitch
);
469 FIXME(ddraw
,"(%p)->(%p,%p,%p,%08lx,%p),stub!\n",
470 this,rdst
,src
,rsrc
,dwFlags
,lpbltfx
472 if (rdst
) TRACE(ddraw
," destrect :%dx%d-%dx%d\n",rdst
->left
,rdst
->top
,rdst
->right
,rdst
->bottom
);
473 if (rsrc
) TRACE(ddraw
," srcrect :%dx%d-%dx%d\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
474 TRACE(ddraw
,"\tflags: ");_dump_DDBLT(dwFlags
);fprintf(stderr
,"\n");
476 if (dwFlags
& DDBLT_DDFX
) {
477 TRACE(ddraw
," blitfx: \n");_dump_DDBLTFX(lpbltfx
->dwDDFX
);
482 static HRESULT WINAPI
IDirectDrawSurface_BltFast(
483 LPDIRECTDRAWSURFACE
this,DWORD dstx
,DWORD dsty
,LPDIRECTDRAWSURFACE src
,LPRECT32 rsrc
,DWORD trans
486 if (TRACE_ON(ddraw
)) {
487 FIXME(ddraw
,"(%p)->(%ld,%ld,%p,%p,%08lx),stub!\n",
488 this,dstx
,dsty
,src
,rsrc
,trans
490 TRACE(ddraw
," trans:");_dump_DDBLTFAST(trans
);fprintf(stderr
,"\n");
491 TRACE(ddraw
," srcrect: %dx%d-%dx%d\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
493 bpp
= this->s
.ddraw
->d
.depth
/8;
494 for (i
=0;i
<rsrc
->bottom
-rsrc
->top
;i
++) {
495 memcpy( this->s
.surface
+((i
+dsty
)*this->s
.width
*bpp
)+dstx
*bpp
,
496 src
->s
.surface
+(rsrc
->top
+i
)*src
->s
.width
*bpp
+rsrc
->left
*bpp
,
497 (rsrc
->right
-rsrc
->left
)*bpp
503 static HRESULT WINAPI
IDirectDrawSurface_BltBatch(
504 LPDIRECTDRAWSURFACE
this,LPDDBLTBATCH ddbltbatch
,DWORD x
,DWORD y
506 TRACE(ddraw
,"(%p)->BltBatch(%p,%08lx,%08lx),stub!\n",
512 static HRESULT WINAPI
IDirectDrawSurface_GetCaps(
513 LPDIRECTDRAWSURFACE
this,LPDDSCAPS caps
515 TRACE(ddraw
,"(%p)->GetCaps(%p)\n",this,caps
);
516 caps
->dwCaps
= DDCAPS_PALETTE
; /* probably more */
520 static HRESULT WINAPI
IDirectDrawSurface_GetSurfaceDesc(
521 LPDIRECTDRAWSURFACE
this,LPDDSURFACEDESC ddsd
523 if (TRACE_ON(ddraw
)) {
524 TRACE(ddraw
, "(%p)->GetSurfaceDesc(%p)\n",
526 fprintf(stderr
," flags: ");
527 _dump_DDSD(ddsd
->dwFlags
);
528 fprintf(stderr
,"\n");
531 ddsd
->dwFlags
|= DDSD_PIXELFORMAT
|DDSD_CAPS
|DDSD_BACKBUFFERCOUNT
|DDSD_HEIGHT
|DDSD_WIDTH
;
532 ddsd
->ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
533 ddsd
->dwBackBufferCount
= 1;
534 ddsd
->dwHeight
= this->s
.height
;
535 ddsd
->dwWidth
= this->s
.width
;
536 ddsd
->lPitch
= this->s
.lpitch
;
537 if (this->s
.backbuffer
)
538 ddsd
->ddsCaps
.dwCaps
|= DDSCAPS_PRIMARYSURFACE
|DDSCAPS_FLIP
;
539 _getpixelformat(this->s
.ddraw
,&(ddsd
->ddpfPixelFormat
));
544 static ULONG WINAPI
IDirectDrawSurface_AddRef(LPDIRECTDRAWSURFACE
this) {
545 TRACE(ddraw
,"(%p)->AddRef()\n",this);
546 return ++(this->ref
);
549 static ULONG WINAPI
IDirectDrawSurface_Release(LPDIRECTDRAWSURFACE
this) {
550 TRACE(ddraw
,"(%p)->Release()\n",this);
551 if (!--(this->ref
)) {
552 this->s
.ddraw
->lpvtbl
->fnRelease(this->s
.ddraw
);
553 /* clear out of surface list */
554 if (this->s
.fb_height
== -1) {
555 HeapFree(GetProcessHeap(),0,this->s
.surface
);
557 this->s
.ddraw
->d
.vpmask
&= ~(1<<(this->s
.fb_height
/this->s
.ddraw
->d
.fb_height
));
559 HeapFree(GetProcessHeap(),0,this);
565 static HRESULT WINAPI
IDirectDrawSurface_GetAttachedSurface(
566 LPDIRECTDRAWSURFACE
this,LPDDSCAPS lpddsd
,LPDIRECTDRAWSURFACE
*lpdsf
568 TRACE(ddraw
, "(%p)->GetAttachedSurface(%p,%p)\n",
569 this, lpddsd
, lpdsf
);
570 if (TRACE_ON(ddraw
)) {
571 TRACE(ddraw
," caps ");
572 _dump_DDSCAPS(lpddsd
->dwCaps
);
574 if (!(lpddsd
->dwCaps
& DDSCAPS_BACKBUFFER
)) {
575 FIXME(ddraw
,"whoops, can only handle backbuffers for now\n");
578 /* FIXME: should handle more than one backbuffer */
579 *lpdsf
= this->s
.backbuffer
;
583 static HRESULT WINAPI
IDirectDrawSurface_Initialize(
584 LPDIRECTDRAWSURFACE
this,LPDIRECTDRAW ddraw
,LPDDSURFACEDESC lpdsfd
586 return DDERR_ALREADYINITIALIZED
;
589 static HRESULT WINAPI
IDirectDrawSurface_GetPixelFormat(
590 LPDIRECTDRAWSURFACE
this,LPDDPIXELFORMAT pf
592 return _getpixelformat(this->s
.ddraw
,pf
);
595 static HRESULT WINAPI
IDirectDrawSurface_GetBltStatus(LPDIRECTDRAWSURFACE
this,DWORD dwFlags
) {
596 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n",
602 static HRESULT WINAPI
IDirectDrawSurface_GetOverlayPosition(
603 LPDIRECTDRAWSURFACE
this,LPLONG x1
,LPLONG x2
605 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",
611 static HRESULT WINAPI
IDirectDrawSurface_SetClipper(
612 LPDIRECTDRAWSURFACE
this,LPDIRECTDRAWCLIPPER clipper
614 FIXME(ddraw
,"(%p)->(%p),stub!\n",this,clipper
);
618 static HRESULT WINAPI
IDirectDrawSurface_AddAttachedSurface(
619 LPDIRECTDRAWSURFACE
this,LPDIRECTDRAWSURFACE surf
621 FIXME(ddraw
,"(%p)->(%p),stub!\n",this,surf
);
622 this->s
.backbuffer
= surf
;
626 static HRESULT WINAPI
IDirectDrawSurface_GetDC(LPDIRECTDRAWSURFACE
this,HDC32
* lphdc
) {
627 FIXME(ddraw
,"(%p)->GetDC(%p),stub!\n",this,lphdc
);
631 static HRESULT WINAPI
IDirectDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE
this,REFIID refiid
,LPVOID
*obj
) {
634 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
635 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
637 /* thats version 3 (DirectX 5) */
638 if ( !memcmp(&IID_IDirectDrawSurface3
,refiid
,sizeof(IID_IDirectDrawSurface3
))) {
639 this->lpvtbl
->fnAddRef(this);
640 this->lpvtbl
= (LPDIRECTDRAWSURFACE_VTABLE
)&dds3vt
;
644 /* thats version 2 (DirectX 3) */
645 if ( !memcmp(&IID_IDirectDrawSurface2
,refiid
,sizeof(IID_IDirectDrawSurface2
))) {
646 this->lpvtbl
->fnAddRef(this);
647 this->lpvtbl
= (LPDIRECTDRAWSURFACE_VTABLE
)&dds2vt
;
652 if (!memcmp(&IID_IDirectDrawSurface
,refiid
,sizeof(IID_IDirectDrawSurface
))) {
653 this->lpvtbl
->fnAddRef(this);
657 WARN(ddraw
,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid
);
658 return OLE_E_ENUM_NOMORE
;
661 static HRESULT WINAPI
IDirectDrawSurface_IsLost(LPDIRECTDRAWSURFACE
this) {
665 static struct IDirectDrawSurface_VTable ddsvt
= {
666 IDirectDrawSurface_QueryInterface
,
667 IDirectDrawSurface_AddRef
,
668 IDirectDrawSurface_Release
,
669 IDirectDrawSurface_AddAttachedSurface
,
671 IDirectDrawSurface_Blt
,
672 IDirectDrawSurface_BltBatch
,
673 IDirectDrawSurface_BltFast
,
677 IDirectDrawSurface_Flip
,
678 IDirectDrawSurface_GetAttachedSurface
,
679 IDirectDrawSurface_GetBltStatus
,
680 IDirectDrawSurface_GetCaps
,
683 IDirectDrawSurface_GetDC
,
685 IDirectDrawSurface_GetOverlayPosition
,
687 IDirectDrawSurface_GetPixelFormat
,
688 IDirectDrawSurface_GetSurfaceDesc
,
689 IDirectDrawSurface_Initialize
,
690 IDirectDrawSurface_IsLost
,
691 IDirectDrawSurface_Lock
,
694 IDirectDrawSurface_SetClipper
,
697 IDirectDrawSurface_SetPalette
,
698 IDirectDrawSurface_Unlock
,
704 /******************************************************************************
705 * IDirectDrawSurface2
707 * calls IDirectDrawSurface methods where possible
709 static HRESULT WINAPI
IDirectDrawSurface2_Lock(
710 LPDIRECTDRAWSURFACE2
this,LPRECT32 lprect
,LPDDSURFACEDESC lpddsd
,DWORD flags
, HANDLE32 hnd
712 return IDirectDrawSurface_Lock((LPDIRECTDRAWSURFACE
)this,lprect
,lpddsd
,flags
,hnd
);
715 static HRESULT WINAPI
IDirectDrawSurface2_Unlock(
716 LPDIRECTDRAWSURFACE2
this,LPVOID surface
718 TRACE(ddraw
,"(%p)->Unlock(%p)\n",this,surface
);
722 static HRESULT WINAPI
IDirectDrawSurface2_SetPalette(
723 LPDIRECTDRAWSURFACE2
this,LPDIRECTDRAWPALETTE pal
725 return IDirectDrawSurface_SetPalette((LPDIRECTDRAWSURFACE
)this,pal
);
728 static ULONG WINAPI
IDirectDrawSurface2_AddRef(LPDIRECTDRAWSURFACE2
this) {
729 TRACE(ddraw
,"(%p)->AddRef()\n",this);
730 return ++(this->ref
);
733 static ULONG WINAPI
IDirectDrawSurface2_Release(LPDIRECTDRAWSURFACE2
this) {
734 return IDirectDrawSurface_Release((LPDIRECTDRAWSURFACE
)this);
737 static HRESULT WINAPI
IDirectDrawSurface2_GetAttachedSurface(
738 LPDIRECTDRAWSURFACE2
this,LPDDSCAPS lpddsd
,LPDIRECTDRAWSURFACE2
*lpdsf
740 HRESULT ret
= IDirectDrawSurface_GetAttachedSurface((LPDIRECTDRAWSURFACE
)this,lpddsd
,(LPDIRECTDRAWSURFACE
*)lpdsf
);
743 (*lpdsf
)->lpvtbl
= &dds2vt
;
747 static HRESULT WINAPI
IDirectDrawSurface2_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE2
this,LPVOID context
,LPDDENUMSURFACESCALLBACK esfcb
) {
748 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,context
,esfcb
);
752 static HRESULT WINAPI
IDirectDrawSurface2_QueryInterface(
753 LPDIRECTDRAWSURFACE2
this,REFIID riid
,LPVOID
*ppobj
755 return IDirectDrawSurface_QueryInterface((LPDIRECTDRAWSURFACE
)this,riid
,ppobj
);
758 static HRESULT WINAPI
IDirectDrawSurface2_IsLost(LPDIRECTDRAWSURFACE2
this) {
763 static struct IDirectDrawSurface2_VTable dds2vt
= {
764 IDirectDrawSurface2_QueryInterface
,
765 IDirectDrawSurface2_AddRef
,
766 IDirectDrawSurface2_Release
,
769 (void*)6/*IDirectDrawSurface_Blt*/,
770 (void*)7/*IDirectDrawSurface_BltBatch*/,
773 IDirectDrawSurface2_EnumAttachedSurfaces
,
776 IDirectDrawSurface2_GetAttachedSurface
,
778 (void*)15/*IDirectDrawSurface_GetCaps*/,
786 (void*)23/*IDirectDrawSurface_GetSurfaceDesc*/,
788 IDirectDrawSurface2_IsLost
,
789 IDirectDrawSurface2_Lock
,
795 IDirectDrawSurface2_SetPalette
,
796 IDirectDrawSurface2_Unlock
,
805 /******************************************************************************
806 * IDirectDrawSurface3
808 static HRESULT WINAPI
IDirectDrawSurface3_SetPalette(
809 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWPALETTE pal
811 return IDirectDrawSurface_SetPalette((LPDIRECTDRAWSURFACE
)this,pal
);
814 static HRESULT WINAPI
IDirectDrawSurface3_GetPixelFormat(
815 LPDIRECTDRAWSURFACE3
this,LPDDPIXELFORMAT pf
817 return _getpixelformat(this->s
.ddraw
,pf
);
820 static HRESULT WINAPI
IDirectDrawSurface3_GetAttachedSurface(
821 LPDIRECTDRAWSURFACE3
this,LPDDSCAPS lpddsd
,LPDIRECTDRAWSURFACE3
*lpdsf
823 HRESULT ret
= IDirectDrawSurface_GetAttachedSurface((LPDIRECTDRAWSURFACE
)this,lpddsd
,(LPDIRECTDRAWSURFACE
*)lpdsf
);
826 (*lpdsf
)->lpvtbl
= &dds3vt
;
830 static ULONG WINAPI
IDirectDrawSurface3_AddRef(LPDIRECTDRAWSURFACE3
this) {
831 TRACE(ddraw
,"(%p)->AddRef()\n",this);
832 return ++(this->ref
);
835 static ULONG WINAPI
IDirectDrawSurface3_Release(LPDIRECTDRAWSURFACE3
this) {
836 TRACE(ddraw
,"(%p)->Release()\n",this);
837 if (!--(this->ref
)) {
838 this->s
.ddraw
->lpvtbl
->fnRelease(this->s
.ddraw
);
839 this->s
.ddraw
->d
.vpmask
&= ~(1<<(this->s
.fb_height
/this->s
.ddraw
->d
.fb_height
));
840 HeapFree(GetProcessHeap(),0,this);
846 static HRESULT WINAPI
IDirectDrawSurface3_Blt(
847 LPDIRECTDRAWSURFACE3
this,LPRECT32 rdst
,LPDIRECTDRAWSURFACE3 src
,
848 LPRECT32 rsrc
,DWORD dwFlags
,LPDDBLTFX lpbltfx
850 return IDirectDrawSurface_Blt((LPDIRECTDRAWSURFACE
)this,rdst
,(LPDIRECTDRAWSURFACE
)src
,rsrc
,dwFlags
,lpbltfx
);
853 static HRESULT WINAPI
IDirectDrawSurface3_IsLost(LPDIRECTDRAWSURFACE3
this) {
857 static HRESULT WINAPI
IDirectDrawSurface3_Restore(LPDIRECTDRAWSURFACE3
this) {
861 static HRESULT WINAPI
IDirectDrawSurface3_GetBltStatus(
862 LPDIRECTDRAWSURFACE3
this,DWORD dwflags
864 return IDirectDrawSurface_GetBltStatus((LPDIRECTDRAWSURFACE
)this,dwflags
);
867 static HRESULT WINAPI
IDirectDrawSurface3_Flip(
868 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWSURFACE3 flipto
,DWORD dwFlags
870 return IDirectDrawSurface_Flip((LPDIRECTDRAWSURFACE
)this,(LPDIRECTDRAWSURFACE
)flipto
,dwFlags
);
873 static HRESULT WINAPI
IDirectDrawSurface3_Lock(
874 LPDIRECTDRAWSURFACE3
this,LPRECT32 lprect
,LPDDSURFACEDESC lpddsd
,DWORD flags
, HANDLE32 hnd
876 return IDirectDrawSurface_Lock((LPDIRECTDRAWSURFACE
)this,lprect
,lpddsd
,flags
,hnd
);
879 static HRESULT WINAPI
IDirectDrawSurface3_Unlock(
880 LPDIRECTDRAWSURFACE3
this,LPVOID surface
882 return IDirectDrawSurface_Unlock((LPDIRECTDRAWSURFACE
)this,surface
);
885 static HRESULT WINAPI
IDirectDrawSurface3_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE3
this,LPVOID context
,LPDDENUMSURFACESCALLBACK esfcb
) {
886 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,context
,esfcb
);
890 static HRESULT WINAPI
IDirectDrawSurface3_SetClipper(
891 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWCLIPPER clipper
893 return IDirectDrawSurface_SetClipper((LPDIRECTDRAWSURFACE
)this,clipper
);
896 static HRESULT WINAPI
IDirectDrawSurface3_QueryInterface(
897 LPDIRECTDRAWSURFACE3
this,REFIID riid
,LPVOID
*ppobj
899 return IDirectDrawSurface_QueryInterface((LPDIRECTDRAWSURFACE
)this,riid
,ppobj
);
902 static struct IDirectDrawSurface3_VTable dds3vt
= {
903 IDirectDrawSurface3_QueryInterface
,
904 IDirectDrawSurface3_AddRef
,
905 IDirectDrawSurface3_Release
,
908 IDirectDrawSurface3_Blt
,
912 IDirectDrawSurface3_EnumAttachedSurfaces
,
914 IDirectDrawSurface3_Flip
,
915 IDirectDrawSurface3_GetAttachedSurface
,
916 IDirectDrawSurface3_GetBltStatus
,
924 IDirectDrawSurface3_GetPixelFormat
,
927 IDirectDrawSurface3_IsLost
,
928 IDirectDrawSurface3_Lock
,
930 IDirectDrawSurface3_Restore
,
931 IDirectDrawSurface3_SetClipper
,
934 IDirectDrawSurface3_SetPalette
,
935 IDirectDrawSurface3_Unlock
,
946 /******************************************************************************
949 static HRESULT WINAPI
IDirectDrawClipper_SetHwnd(
950 LPDIRECTDRAWCLIPPER
this,DWORD x
,HWND32 hwnd
952 FIXME(ddraw
,"(%p)->SetHwnd(0x%08lx,0x%08lx),stub!\n",this,x
,(DWORD
)hwnd
);
956 static ULONG WINAPI
IDirectDrawClipper_Release(LPDIRECTDRAWCLIPPER
this) {
960 HeapFree(GetProcessHeap(),0,this);
964 static struct IDirectDrawClipper_VTable ddclipvt
= {
967 IDirectDrawClipper_Release
,
973 IDirectDrawClipper_SetHwnd
976 /******************************************************************************
979 static HRESULT WINAPI
IDirectDrawPalette_GetEntries(
980 LPDIRECTDRAWPALETTE
this,DWORD x
,DWORD start
,DWORD end
,LPPALETTEENTRY palent
984 FIXME(ddraw
,"(%p)->GetEntries(%08lx,%ld,%ld,%p),stub!\n",
985 this,x
,start
,end
,palent
987 for (i
=start
;i
<end
;i
++) {
988 palent
[i
-start
].peRed
= i
;
989 palent
[i
-start
].peGreen
= i
;
990 palent
[i
-start
].peBlue
= i
;
995 static HRESULT WINAPI
IDirectDrawPalette_SetEntries(
996 LPDIRECTDRAWPALETTE
this,DWORD x
,DWORD start
,DWORD end
,LPPALETTEENTRY palent
1001 TRACE(ddraw
,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1002 this,x
,start
,end
,palent
1004 if (!this->cm
) /* should not happen */ {
1005 ERR(ddraw
,"no colormap in SetEntries???\n");
1006 return DDERR_GENERIC
;
1008 /* FIXME: free colorcells instead of freeing whole map */
1009 TSXFreeColormap(display
,this->cm
);
1010 this->cm
= TSXCreateColormap(display
,DefaultRootWindow(display
),DefaultVisualOfScreen(screen
),AllocAll
);
1012 xc
.red
= xc
.blue
= xc
.green
= 0; xc
.flags
= DoRed
|DoGreen
|DoBlue
; xc
.pixel
= 0; TSXStoreColor(display
,this->cm
,&xc
);
1013 this->palents
[0].peRed
= 0;
1014 this->palents
[0].peBlue
= 0;
1015 this->palents
[0].peGreen
= 0;
1018 xc
.red
= xc
.blue
= xc
.green
= 0xffff; xc
.flags
= DoRed
|DoGreen
|DoBlue
; xc
.pixel
= 255; TSXStoreColor(display
,this->cm
,&xc
);
1019 this->palents
[255].peRed
= 255;
1020 this->palents
[255].peBlue
= 255;
1021 this->palents
[255].peGreen
= 255;
1023 for (i
=start
;i
<end
;i
++) {
1024 xc
.red
= palent
[i
-start
].peRed
<<8;
1025 xc
.blue
= palent
[i
-start
].peBlue
<<8;
1026 xc
.green
= palent
[i
-start
].peGreen
<<8;
1027 xc
.flags
= DoRed
|DoBlue
|DoGreen
;
1029 TSXStoreColor(display
,this->cm
,&xc
);
1030 this->palents
[i
].peRed
= palent
[i
-start
].peRed
;
1031 this->palents
[i
].peBlue
= palent
[i
-start
].peBlue
;
1032 this->palents
[i
].peGreen
= palent
[i
-start
].peGreen
;
1034 XF86DGAInstallColormap(display
,DefaultScreen(display
),this->cm
);
1038 static ULONG WINAPI
IDirectDrawPalette_Release(LPDIRECTDRAWPALETTE
this) {
1039 if (!--(this->ref
)) {
1041 TSXFreeColormap(display
,this->cm
);
1044 HeapFree(GetProcessHeap(),0,this);
1050 static ULONG WINAPI
IDirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE
this) {
1051 return ++(this->ref
);
1054 static HRESULT WINAPI
IDirectDrawPalette_Initialize(
1055 LPDIRECTDRAWPALETTE
this,LPDIRECTDRAW ddraw
,DWORD x
,LPPALETTEENTRY palent
1057 return DDERR_ALREADYINITIALIZED
;
1060 static struct IDirectDrawPalette_VTable ddpalvt
= {
1062 IDirectDrawPalette_AddRef
,
1063 IDirectDrawPalette_Release
,
1065 IDirectDrawPalette_GetEntries
,
1066 IDirectDrawPalette_Initialize
,
1067 IDirectDrawPalette_SetEntries
1070 /*******************************************************************************
1073 static struct IDirect3D_VTable d3dvt
= {
1085 /*******************************************************************************
1088 static ULONG WINAPI
IDirect3D2_Release(LPDIRECT3D2
this) {
1091 this->ddraw
->lpvtbl
->fnRelease(this->ddraw
);
1092 HeapFree(GetProcessHeap(),0,this);
1098 static HRESULT WINAPI
IDirect3D2_EnumDevices(
1099 LPDIRECT3D2
this,LPD3DENUMDEVICESCALLBACK cb
, LPVOID context
1101 D3DDEVICEDESC d1
,d2
;
1103 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,cb
,context
);
1104 d1
.dwSize
= sizeof(d1
);
1107 d2
.dwSize
= sizeof(d2
);
1109 cb(&IID_IDirect3DHALDevice
,"WINE Direct3D HAL","direct3d",&d1
,&d2
,context
);
1113 static struct IDirect3D2_VTable d3d2vt
= {
1117 IDirect3D2_EnumDevices
,
1125 /*******************************************************************************
1128 static HRESULT WINAPI
IDirectDraw_CreateSurface(
1129 LPDIRECTDRAW
this,LPDDSURFACEDESC lpddsd
,LPDIRECTDRAWSURFACE
*lpdsf
,IUnknown
*lpunk
1133 TRACE(ddraw
, "(%p)->(%p,%p,%p)\n",
1134 this,lpddsd
,lpdsf
,lpunk
);
1135 if (TRACE_ON(ddraw
)) {
1136 DUMP("[w=%ld,h=%ld,flags ",lpddsd
->dwWidth
,lpddsd
->dwHeight
);
1137 _dump_DDSD(lpddsd
->dwFlags
);
1138 fprintf(stderr
,"caps ");
1139 _dump_DDSCAPS(lpddsd
->ddsCaps
.dwCaps
);
1140 fprintf(stderr
,"]\n");
1143 *lpdsf
= (LPDIRECTDRAWSURFACE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface
));
1144 this->lpvtbl
->fnAddRef(this);
1146 (*lpdsf
)->lpvtbl
= &ddsvt
;
1147 if ( (lpddsd
->dwFlags
& DDSD_CAPS
) &&
1148 (lpddsd
->ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
1150 if (!(lpddsd
->dwFlags
& DDSD_WIDTH
))
1151 lpddsd
->dwWidth
= this->d
.fb_width
;
1152 if (!(lpddsd
->dwFlags
& DDSD_HEIGHT
))
1153 lpddsd
->dwWidth
= this->d
.fb_height
;
1154 (*lpdsf
)->s
.surface
= (LPBYTE
)HeapAlloc(GetProcessHeap(),0,lpddsd
->dwWidth
*lpddsd
->dwHeight
*this->d
.depth
/8);
1155 (*lpdsf
)->s
.fb_height
= -1;
1156 (*lpdsf
)->s
.lpitch
= lpddsd
->dwWidth
*this->d
.depth
/8;
1157 TRACE(ddraw
,"using system memory for a primary surface\n");
1160 if (!(this->d
.vpmask
& (1<<i
)))
1162 TRACE(ddraw
,"using viewport %d for a primary surface\n",i
);
1163 /* if i == 32 or maximum ... return error */
1164 this->d
.vpmask
|=(1<<i
);
1165 (*lpdsf
)->s
.surface
= this->d
.fb_addr
+((i
*this->d
.fb_height
)*this->d
.fb_width
*this->d
.depth
/8);
1166 (*lpdsf
)->s
.fb_height
= i
*this->d
.fb_height
;
1167 (*lpdsf
)->s
.lpitch
= this->d
.fb_width
*this->d
.depth
/8;
1170 lpddsd
->lPitch
= (*lpdsf
)->s
.lpitch
;
1172 (*lpdsf
)->s
.width
= this->d
.width
;
1173 (*lpdsf
)->s
.height
= this->d
.height
;
1174 (*lpdsf
)->s
.ddraw
= this;
1175 (*lpdsf
)->s
.backbuffer
= NULL
;
1176 if (lpddsd
->dwFlags
& DDSD_BACKBUFFERCOUNT
) {
1177 LPDIRECTDRAWSURFACE back
;
1179 if (lpddsd
->dwBackBufferCount
>1)
1180 FIXME(ddraw
,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd
->dwBackBufferCount
);
1182 (*lpdsf
)->s
.backbuffer
= back
= (LPDIRECTDRAWSURFACE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface
));
1183 this->lpvtbl
->fnAddRef(this);
1185 back
->lpvtbl
= &ddsvt
;
1187 if (!(this->d
.vpmask
& (1<<i
)))
1189 TRACE(ddraw
,"using viewport %d for backbuffer\n",i
);
1190 /* if i == 32 or maximum ... return error */
1191 this->d
.vpmask
|=(1<<i
);
1192 back
->s
.surface
= this->d
.fb_addr
+((i
*this->d
.fb_height
)*this->d
.fb_width
*this->d
.depth
/8);
1193 back
->s
.fb_height
= i
*this->d
.fb_height
;
1195 back
->s
.width
= this->d
.width
;
1196 back
->s
.height
= this->d
.height
;
1197 back
->s
.ddraw
= this;
1198 back
->s
.lpitch
= this->d
.fb_width
*this->d
.depth
/8;
1199 back
->s
.backbuffer
= NULL
; /* does not have a backbuffer, it is
1205 static HRESULT WINAPI
IDirectDraw_DuplicateSurface(
1206 LPDIRECTDRAW
this,LPDIRECTDRAWSURFACE src
,LPDIRECTDRAWSURFACE
*dst
1208 FIXME(ddraw
,"(%p)->(%p,%p) simply copies\n",this,src
,dst
);
1209 *dst
= src
; /* FIXME */
1213 static HRESULT WINAPI
IDirectDraw_SetCooperativeLevel(
1214 LPDIRECTDRAW
this,HWND32 hwnd
,DWORD cooplevel
1221 FE(DDSCL_FULLSCREEN
)
1222 FE(DDSCL_ALLOWREBOOT
)
1223 FE(DDSCL_NOWINDOWCHANGES
)
1225 FE(DDSCL_ALLOWMODEX
)
1227 FE(DDSCL_SETFOCUSWINDOW
)
1228 FE(DDSCL_SETDEVICEWINDOW
)
1229 FE(DDSCL_CREATEDEVICEWINDOW
)
1232 TRACE(ddraw
,"(%p)->(%08lx,%08lx)\n",
1233 this,(DWORD
)hwnd
,cooplevel
1235 if(TRACE_ON(ddraw
)){
1236 dbg_decl_str(ddraw
, 512);
1237 for (i
=0;i
<sizeof(flagmap
)/sizeof(flagmap
[0]);i
++)
1238 if (flagmap
[i
].mask
& cooplevel
)
1239 dsprintf(ddraw
, "%s ", flagmap
[i
].name
);
1240 TRACE(ddraw
," cooperative level %s\n", dbg_str(ddraw
));
1242 this->d
.mainwindow
= hwnd
;
1247 static HRESULT WINAPI
IDirectDraw_SetDisplayMode(
1248 LPDIRECTDRAW
this,DWORD width
,DWORD height
,DWORD depth
1250 int i
,*depths
,depcount
;
1253 TRACE(ddraw
, "(%p)->(%ld,%ld,%ld)\n",
1254 this, width
, height
, depth
);
1256 depths
= TSXListDepths(display
,DefaultScreen(display
),&depcount
);
1257 for (i
=0;i
<depcount
;i
++)
1258 if (depths
[i
]==depth
)
1261 if (i
==depcount
) {/* not found */
1262 ERR(ddraw
,"(w=%ld,h=%ld,d=%ld), unsupported depth!\n",width
,height
,depth
);
1263 return DDERR_UNSUPPORTEDMODE
;
1265 if (this->d
.fb_width
< width
) {
1266 ERR(ddraw
,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld\n",width
,height
,depth
,width
,this->d
.fb_width
);
1267 return DDERR_UNSUPPORTEDMODE
;
1269 this->d
.width
= width
;
1270 this->d
.height
= height
;
1271 /* adjust fb_height, so we don't overlap */
1272 if (this->d
.fb_height
< height
)
1273 this->d
.fb_height
= height
;
1274 this->d
.depth
= depth
;
1276 /* FIXME: this function OVERWRITES several signal handlers.
1277 * can we save them? and restore them later? In a way that
1278 * it works for the library too?
1280 XF86DGADirectVideo(display
,DefaultScreen(display
),XF86DGADirectGraphics
);
1282 XF86DGASetViewPort(display,DefaultScreen(display),0,this->d.fb_height);
1285 #ifdef RESTORE_SIGNALS
1286 SIGNAL_InitEmulator();
1291 static HRESULT WINAPI
IDirectDraw_GetCaps(
1292 LPDIRECTDRAW
this,LPDDCAPS caps1
,LPDDCAPS caps2
1294 TRACE(ddraw
,"(%p)->(%p,%p)\n",this,caps1
,caps2
);
1295 caps1
->dwVidMemTotal
= this->d
.fb_memsize
;
1296 caps1
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1297 caps1
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1299 caps2
->dwVidMemTotal
= this->d
.fb_memsize
;
1300 caps2
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1301 caps2
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1306 static HRESULT WINAPI
IDirectDraw_CreateClipper(
1307 LPDIRECTDRAW
this,DWORD x
,LPDIRECTDRAWCLIPPER
*lpddclip
,LPUNKNOWN lpunk
1309 FIXME(ddraw
,"(%p)->(%08lx,%p,%p),stub!\n",
1310 this,x
,lpddclip
,lpunk
1312 *lpddclip
= (LPDIRECTDRAWCLIPPER
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawClipper
));
1313 (*lpddclip
)->ref
= 1;
1314 (*lpddclip
)->lpvtbl
= &ddclipvt
;
1318 static HRESULT WINAPI
IDirectDraw_CreatePalette(
1319 LPDIRECTDRAW
this,DWORD x
,LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
*lpddpal
,LPUNKNOWN lpunk
1321 TRACE(ddraw
,"(%p)->(%08lx,%p,%p,%p)\n",
1322 this,x
,palent
,lpddpal
,lpunk
1324 *lpddpal
= (LPDIRECTDRAWPALETTE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawPalette
));
1325 (*lpddpal
)->ref
= 1;
1326 (*lpddpal
)->lpvtbl
= &ddpalvt
;
1327 (*lpddpal
)->ddraw
= this;
1328 if (this->d
.depth
<=8) {
1329 (*lpddpal
)->cm
= TSXCreateColormap(display
,DefaultRootWindow(display
),DefaultVisualOfScreen(screen
),AllocAll
);
1330 } else /* we don't want palettes in hicolor or truecolor */
1336 static HRESULT WINAPI
IDirectDraw_RestoreDisplayMode(LPDIRECTDRAW
this) {
1337 TRACE(ddraw
, "(%p)->()\n",
1340 XF86DGADirectVideo(display
,DefaultScreen(display
),0);
1341 #ifdef RESTORE_SIGNALS
1342 SIGNAL_InitEmulator();
1348 static HRESULT WINAPI
IDirectDraw_WaitForVerticalBlank(
1349 LPDIRECTDRAW
this,DWORD x
,HANDLE32 h
1351 TRACE(ddraw
,"(%p)->(0x%08lx,0x%08x)\n",this,x
,h
);
1355 static ULONG WINAPI
IDirectDraw_AddRef(LPDIRECTDRAW
this) {
1356 return ++(this->ref
);
1359 static ULONG WINAPI
IDirectDraw_Release(LPDIRECTDRAW
this) {
1360 if (!--(this->ref
)) {
1361 XF86DGADirectVideo(display
,DefaultScreen(display
),0);
1362 #ifdef RESTORE_SIGNALS
1363 SIGNAL_InitEmulator();
1365 HeapFree(GetProcessHeap(),0,this);
1371 static HRESULT WINAPI
IDirectDraw_QueryInterface(
1372 LPDIRECTDRAW
this,REFIID refiid
,LPVOID
*obj
1376 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1377 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1378 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1380 this->lpvtbl
->fnAddRef(this);
1383 if (!memcmp(&IID_IDirectDraw
,refiid
,sizeof(IID_IDirectDraw
))) {
1385 this->lpvtbl
->fnAddRef(this);
1388 if (!memcmp(&IID_IDirectDraw2
,refiid
,sizeof(IID_IDirectDraw2
))) {
1389 this->lpvtbl
= (LPDIRECTDRAW_VTABLE
)&dd2vt
;
1390 this->lpvtbl
->fnAddRef(this);
1394 if (!memcmp(&IID_IDirect3D
,refiid
,sizeof(IID_IDirect3D
))) {
1397 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1400 this->lpvtbl
->fnAddRef(this);
1401 d3d
->lpvtbl
= &d3dvt
;
1405 if (!memcmp(&IID_IDirect3D2
,refiid
,sizeof(IID_IDirect3D
))) {
1408 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1411 this->lpvtbl
->fnAddRef(this);
1412 d3d
->lpvtbl
= &d3d2vt
;
1416 WARN(ddraw
,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid
);
1417 return OLE_E_ENUM_NOMORE
;
1420 static HRESULT WINAPI
IDirectDraw_GetVerticalBlankStatus(
1421 LPDIRECTDRAW
this,BOOL32
*status
1423 TRACE(ddraw
,"(%p)->(%p)\n",this,status
);
1428 static HRESULT WINAPI
IDirectDraw_EnumDisplayModes(
1429 LPDIRECTDRAW
this,DWORD dwFlags
,LPDDSURFACEDESC lpddsfd
,LPVOID context
,LPDDENUMMODESCALLBACK modescb
1431 DDSURFACEDESC ddsfd
;
1433 TRACE(ddraw
,"(%p)->(0x%08lx,%p,%p,%p)\n",this,dwFlags
,lpddsfd
,context
,modescb
);
1436 _getpixelformat(this,&(ddsfd
.ddpfPixelFormat
));
1437 ddsfd
.dwSize
= sizeof(ddsfd
);
1438 ddsfd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_BACKBUFFERCOUNT
|DDSD_PIXELFORMAT
|DDSD_CAPS
;
1439 if (dwFlags
& DDEDM_REFRESHRATES
) {
1440 ddsfd
.dwFlags
|= DDSD_REFRESHRATE
;
1441 ddsfd
.x
.dwRefreshRate
= 60;
1444 ddsfd
.dwWidth
= 640;
1445 ddsfd
.dwHeight
= 480;
1446 ddsfd
.dwBackBufferCount
= 1;
1447 ddsfd
.ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
1449 if (!modescb(&ddsfd
,context
)) return 0;
1451 ddsfd
.dwWidth
= 800;
1452 ddsfd
.dwHeight
= 600;
1453 if (!modescb(&ddsfd
,context
)) return 0;
1455 if (!(dwFlags
& DDEDM_STANDARDVGAMODES
)) {
1456 /* modeX is not standard VGA */
1458 ddsfd
.dwHeight
= 200;
1459 ddsfd
.dwWidth
= 320;
1460 if (!modescb(&ddsfd
,context
)) return 0;
1465 static HRESULT WINAPI
IDirectDraw_GetDisplayMode(
1466 LPDIRECTDRAW
this,LPDDSURFACEDESC lpddsfd
1468 TRACE(ddraw
,"(%p)->(%p)\n",this,lpddsfd
);
1469 lpddsfd
->dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PITCH
|DDSD_BACKBUFFERCOUNT
|DDSD_PIXELFORMAT
|DDSD_CAPS
;
1470 lpddsfd
->dwHeight
= screenHeight
;
1471 lpddsfd
->dwWidth
= screenWidth
;
1472 lpddsfd
->lPitch
= this->d
.fb_width
*this->d
.depth
/8;
1473 lpddsfd
->dwBackBufferCount
= 1;
1474 lpddsfd
->x
.dwRefreshRate
= 60;
1475 lpddsfd
->ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
1476 _getpixelformat(this,&(lpddsfd
->ddpfPixelFormat
));
1480 static HRESULT WINAPI
IDirectDraw_FlipToGDISurface(LPDIRECTDRAW
this) {
1481 TRACE(ddraw
,"(%p)->()\n",this);
1485 static HRESULT WINAPI
IDirectDraw_GetMonitorFrequency(
1486 LPDIRECTDRAW
this,LPDWORD freq
1488 FIXME(ddraw
,"(%p)->(%p) returns 60 Hz always\n",this,freq
);
1489 *freq
= 60*100; /* 60 Hz */
1493 static IDirectDraw_VTable ddvt
= {
1494 IDirectDraw_QueryInterface
,
1496 IDirectDraw_Release
,
1498 IDirectDraw_CreateClipper
,
1499 IDirectDraw_CreatePalette
,
1500 IDirectDraw_CreateSurface
,
1501 IDirectDraw_DuplicateSurface
,
1502 IDirectDraw_EnumDisplayModes
,
1504 IDirectDraw_FlipToGDISurface
,
1505 IDirectDraw_GetCaps
,
1506 IDirectDraw_GetDisplayMode
,
1509 IDirectDraw_GetMonitorFrequency
,
1511 IDirectDraw_GetVerticalBlankStatus
,
1513 IDirectDraw_RestoreDisplayMode
,
1514 IDirectDraw_SetCooperativeLevel
,
1515 IDirectDraw_SetDisplayMode
,
1516 IDirectDraw_WaitForVerticalBlank
,
1519 /*****************************************************************************
1523 static HRESULT WINAPI
IDirectDraw2_CreateClipper(
1524 LPDIRECTDRAW2
this,DWORD x
,LPDIRECTDRAWCLIPPER
*lpddclip
,LPUNKNOWN lpunk
1526 return IDirectDraw_CreateClipper((LPDIRECTDRAW
)this,x
,lpddclip
,lpunk
);
1529 static HRESULT WINAPI
IDirectDraw2_CreateSurface(
1530 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsd
,LPDIRECTDRAWSURFACE
*lpdsf
,IUnknown
*lpunk
1532 return IDirectDraw_CreateSurface((LPDIRECTDRAW
)this,lpddsd
,(LPDIRECTDRAWSURFACE
*)lpdsf
,lpunk
);
1535 static HRESULT WINAPI
IDirectDraw2_QueryInterface(
1536 LPDIRECTDRAW2
this,REFIID refiid
,LPVOID
*obj
1538 return IDirectDraw_QueryInterface((LPDIRECTDRAW
)this,refiid
,obj
);
1541 static ULONG WINAPI
IDirectDraw2_AddRef(LPDIRECTDRAW2
this) {
1542 return IDirectDraw_AddRef((LPDIRECTDRAW
)this);
1545 static ULONG WINAPI
IDirectDraw2_Release(LPDIRECTDRAW2
this) {
1546 return IDirectDraw_Release((LPDIRECTDRAW
)this);
1549 static HRESULT WINAPI
IDirectDraw2_GetCaps(
1550 LPDIRECTDRAW2
this,LPDDCAPS caps1
,LPDDCAPS caps2
1552 return IDirectDraw_GetCaps((LPDIRECTDRAW
)this,caps1
,caps2
);
1555 static HRESULT WINAPI
IDirectDraw2_SetCooperativeLevel(
1556 LPDIRECTDRAW2
this,HWND32 hwnd
,DWORD x
1558 return IDirectDraw_SetCooperativeLevel((LPDIRECTDRAW
)this,hwnd
,x
);
1561 static HRESULT WINAPI
IDirectDraw2_CreatePalette(
1562 LPDIRECTDRAW2
this,DWORD x
,LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
*lpddpal
,LPUNKNOWN lpunk
1564 return IDirectDraw_CreatePalette((LPDIRECTDRAW
)this,x
,palent
,lpddpal
,lpunk
);
1568 static HRESULT WINAPI
IDirectDraw2_SetDisplayMode(
1569 LPDIRECTDRAW2
this,DWORD width
,DWORD height
,DWORD depth
,DWORD xx
,DWORD yy
1571 TRACE(ddraw
,"(%p)->(%ld,%ld,%ld,%08lx,%08lx)\n",
1572 this, width
, height
, depth
, xx
, yy
);
1574 return IDirectDraw_SetDisplayMode((LPDIRECTDRAW
)this,width
,height
,depth
);
1577 static HRESULT WINAPI
IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2
this) {
1578 return IDirectDraw_RestoreDisplayMode((LPDIRECTDRAW
)this);
1581 static HRESULT WINAPI
IDirectDraw2_EnumSurfaces(
1582 LPDIRECTDRAW2
this,DWORD x
,LPDDSURFACEDESC ddsfd
,LPVOID context
,LPDDENUMSURFACESCALLBACK ddsfcb
1584 FIXME(ddraw
,"(%p)->(0x%08lx,%p,%p,%p),stub!\n",this,x
,ddsfd
,context
,ddsfcb
);
1588 static HRESULT WINAPI
IDirectDraw2_EnumDisplayModes(
1589 LPDIRECTDRAW2
this,DWORD dwFlags
,LPDDSURFACEDESC lpddsfd
,LPVOID context
,LPDDENUMMODESCALLBACK modescb
1591 return IDirectDraw_EnumDisplayModes((LPDIRECTDRAW
)this,dwFlags
,lpddsfd
,context
,modescb
);
1594 static HRESULT WINAPI
IDirectDraw2_GetDisplayMode(
1595 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsfd
1597 return IDirectDraw_GetDisplayMode((LPDIRECTDRAW
)this,lpddsfd
);
1600 static HRESULT WINAPI
IDirectDraw2_GetAvailableVidMem(
1601 LPDIRECTDRAW2
this,LPDDSCAPS ddscaps
,LPDWORD total
,LPDWORD free
1603 TRACE(ddraw
,"(%p)->(%p,%p,%p)\n",
1604 this,ddscaps
,total
,free
1606 if (total
) *total
= this->d
.fb_memsize
* 1024;
1607 if (free
) *free
= this->d
.fb_memsize
* 1024;
1611 static HRESULT WINAPI
IDirectDraw2_GetMonitorFrequency(
1612 LPDIRECTDRAW2
this,LPDWORD freq
1614 return IDirectDraw_GetMonitorFrequency((LPDIRECTDRAW
)this,freq
);
1617 static HRESULT WINAPI
IDirectDraw2_GetVerticalBlankStatus(
1618 LPDIRECTDRAW2
this,BOOL32
*status
1620 return IDirectDraw_GetVerticalBlankStatus((LPDIRECTDRAW
)this,status
);
1623 static HRESULT WINAPI
IDirectDraw2_WaitForVerticalBlank(
1624 LPDIRECTDRAW2
this,DWORD x
,HANDLE32 h
1626 return IDirectDraw_WaitForVerticalBlank((LPDIRECTDRAW
)this,x
,h
);
1629 static IDirectDraw2_VTable dd2vt
= {
1630 IDirectDraw2_QueryInterface
,
1631 IDirectDraw2_AddRef
,
1632 IDirectDraw2_Release
,
1634 IDirectDraw2_CreateClipper
,
1635 IDirectDraw2_CreatePalette
,
1636 IDirectDraw2_CreateSurface
,
1638 IDirectDraw2_EnumDisplayModes
,
1639 IDirectDraw2_EnumSurfaces
,
1641 IDirectDraw2_GetCaps
,
1642 IDirectDraw2_GetDisplayMode
,
1645 IDirectDraw2_GetMonitorFrequency
,
1647 IDirectDraw2_GetVerticalBlankStatus
,
1649 IDirectDraw2_RestoreDisplayMode
,
1650 IDirectDraw2_SetCooperativeLevel
,
1651 IDirectDraw2_SetDisplayMode
,
1652 IDirectDraw2_WaitForVerticalBlank
,
1653 IDirectDraw2_GetAvailableVidMem
1657 /******************************************************************************
1661 HRESULT WINAPI
DirectDrawCreate( LPGUID lpGUID
, LPDIRECTDRAW
*lplpDD
, LPUNKNOWN pUnkOuter
) {
1664 int memsize
,banksize
,width
,evbase
,evret
,major
,minor
,flags
,height
;
1668 WINE_StringFromCLSID(lpGUID
,xclsid
);
1670 strcpy(xclsid
,"<null>");
1672 TRACE(ddraw
,"(%s,%p,%p)\n",xclsid
,lplpDD
,pUnkOuter
);
1674 MSG("Must be root to use XF86DGA!\n");
1675 MessageBox32A(0,"Using the XF86DGA extension requires the program to be run using UID 0.","WINE DirectDraw",MB_OK
|MB_ICONSTOP
);
1676 return E_UNEXPECTED
;
1678 *lplpDD
= (LPDIRECTDRAW
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDraw
));
1679 (*lplpDD
)->lpvtbl
= &ddvt
;
1681 if (!XF86DGAQueryExtension(display
,&evbase
,&evret
)) {
1682 MSG("Wine DirectDraw: No XF86DGA detected.\n");
1685 XF86DGAQueryVersion(display
,&major
,&minor
);
1686 TRACE(ddraw
,"XF86DGA is version %d.%d\n",major
,minor
);
1687 XF86DGAQueryDirectVideo(display
,DefaultScreen(display
),&flags
);
1688 if (!(flags
& XF86DGADirectPresent
))
1689 MSG("direct video is NOT ENABLED.\n");
1690 XF86DGAGetVideo(display
,DefaultScreen(display
),&addr
,&width
,&banksize
,&memsize
);
1691 TRACE(ddraw
,"video framebuffer: begin %p, width %d,banksize %d,memsize %d\n",
1692 addr
,width
,banksize
,memsize
1694 (*lplpDD
)->d
.fb_width
= width
;
1695 (*lplpDD
)->d
.fb_addr
= addr
;
1696 (*lplpDD
)->d
.fb_memsize
= memsize
;
1697 (*lplpDD
)->d
.fb_banksize
= banksize
;
1699 XF86DGAGetViewPortSize(display
,DefaultScreen(display
),&width
,&height
);
1700 XF86DGASetViewPort(display
,DefaultScreen(display
),0,0);
1701 (*lplpDD
)->d
.vp_width
= width
;
1702 (*lplpDD
)->d
.vp_height
= height
;
1703 (*lplpDD
)->d
.fb_height
= screenHeight
;
1704 (*lplpDD
)->d
.vpmask
= 0;
1706 /* just assume the default depth is the DGA depth too */
1707 (*lplpDD
)->d
.depth
= DefaultDepthOfScreen(screen
);
1708 #ifdef RESTORE_SIGNALS
1709 SIGNAL_InitEmulator();
1715 HRESULT WINAPI
DirectDrawCreate( LPGUID lpGUID
, LPDIRECTDRAW
*lplpDD
, LPUNKNOWN pUnkOuter
) {
1716 MessageBox32A(0,"WINE DirectDraw needs the XF86DGA extensions compiled in. (libXxf86dga.a).","WINE DirectDraw",MB_OK
|MB_ICONSTOP
);
1717 return E_OUTOFMEMORY
;