1 /* DirectDraw using DGA or Xlib
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 * FIXME: The Xshm implementation has been temporarily removed. It will be
15 * later reintegrated into the Xlib implementation.
22 #include <sys/signal.h>
26 #include "interfaces.h"
40 #ifdef HAVE_LIBXXF86DGA
41 #include "ts_xf86dga.h"
44 /* define this if you want to play Diablo using XF86DGA. (bug workaround) */
47 /* restore signal handlers overwritten by XF86DGA
48 * this is a define, for it will only work in emulator mode
50 #undef RESTORE_SIGNALS
52 /* Where do these GUIDs come from? mkuuid.
53 * They exist solely to distinguish between the targets Wine support,
54 * and should be different than any other GUIDs in existence.
56 static GUID DGA_DirectDraw_GUID
= { /* e2dcb020-dc60-11d1-8407-9714f5d50802 */
60 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x02}
63 static GUID XLIB_DirectDraw_GUID
= { /* 1574a740-dc61-11d1-8407-f7875a7d1879 */
67 {0x84, 0x07, 0xf7, 0x87, 0x5a, 0x7d, 0x18, 0x79}
70 static struct IDirectDrawSurface3_VTable dga_dds3vt
, xlib_dds3vt
;
71 static struct IDirectDraw_VTable dga_ddvt
, xlib_ddvt
;
72 static struct IDirectDraw2_VTable dga_dd2vt
, xlib_dd2vt
;
73 static struct IDirectDrawClipper_VTable ddclipvt
;
74 static struct IDirectDrawPalette_VTable dga_ddpalvt
, xlib_ddpalvt
;
75 static struct IDirect3D_VTable d3dvt
;
76 static struct IDirect3D2_VTable d3d2vt
;
81 #ifdef HAVE_LIBXXF86DGA
83 return (getuid() == 0)&&TSXF86DGAQueryExtension(display
,&evbase
,&evret
);
84 #else /* defined(HAVE_LIBXXF86DGA) */
86 #endif /* defined(HAVE_LIBXXF86DGA) */
90 DirectDrawEnumerate32A(LPDDENUMCALLBACK32A ddenumproc
,LPVOID data
) {
91 if (DDRAW_DGA_Available()) {
92 ddenumproc(&DGA_DirectDraw_GUID
,"WINE with XFree86 DGA","display",data
);
94 ddenumproc(&XLIB_DirectDraw_GUID
,"WINE with Xlib","display",data
);
95 ddenumproc(NULL
,"WINE","display",data
);
99 /* What is this doing here? */
101 DSoundHelp(DWORD x
,DWORD y
,DWORD z
) {
102 FIXME(ddraw
,"(0x%08lx,0x%08lx,0x%08lx),stub!\n",x
,y
,z
);
107 /******************************************************************************
108 * internal helper functions
110 static void _dump_DDBLTFX(DWORD flagmask
) {
116 #define FE(x) { x, #x},
117 FE(DDBLTFX_ARITHSTRETCHY
)
118 FE(DDBLTFX_MIRRORLEFTRIGHT
)
119 FE(DDBLTFX_MIRRORUPDOWN
)
120 FE(DDBLTFX_NOTEARING
)
121 FE(DDBLTFX_ROTATE180
)
122 FE(DDBLTFX_ROTATE270
)
124 FE(DDBLTFX_ZBUFFERRANGE
)
125 FE(DDBLTFX_ZBUFFERBASEDEST
)
127 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
128 if (flags
[i
].mask
& flagmask
) {
129 DUMP("%s ",flags
[i
].name
);
136 static void _dump_DDBLTFAST(DWORD flagmask
) {
142 #define FE(x) { x, #x},
143 FE(DDBLTFAST_NOCOLORKEY
)
144 FE(DDBLTFAST_SRCCOLORKEY
)
145 FE(DDBLTFAST_DESTCOLORKEY
)
148 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
149 if (flags
[i
].mask
& flagmask
)
150 DUMP("%s ",flags
[i
].name
);
154 static void _dump_DDBLT(DWORD flagmask
) {
160 #define FE(x) { x, #x},
162 FE(DDBLT_ALPHADESTCONSTOVERRIDE
)
163 FE(DDBLT_ALPHADESTNEG
)
164 FE(DDBLT_ALPHADESTSURFACEOVERRIDE
)
165 FE(DDBLT_ALPHAEDGEBLEND
)
167 FE(DDBLT_ALPHASRCCONSTOVERRIDE
)
168 FE(DDBLT_ALPHASRCNEG
)
169 FE(DDBLT_ALPHASRCSURFACEOVERRIDE
)
175 FE(DDBLT_KEYDESTOVERRIDE
)
177 FE(DDBLT_KEYSRCOVERRIDE
)
179 FE(DDBLT_ROTATIONANGLE
)
181 FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE
)
182 FE(DDBLT_ZBUFFERDESTOVERRIDE
)
183 FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE
)
184 FE(DDBLT_ZBUFFERSRCOVERRIDE
)
188 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
189 if (flags
[i
].mask
& flagmask
)
190 DUMP("%s ",flags
[i
].name
);
193 static void _dump_DDSCAPS(DWORD flagmask
) {
199 #define FE(x) { x, #x},
200 FE(DDSCAPS_RESERVED1
)
202 FE(DDSCAPS_BACKBUFFER
)
205 FE(DDSCAPS_FRONTBUFFER
)
206 FE(DDSCAPS_OFFSCREENPLAIN
)
209 FE(DDSCAPS_PRIMARYSURFACE
)
210 FE(DDSCAPS_PRIMARYSURFACELEFT
)
211 FE(DDSCAPS_SYSTEMMEMORY
)
214 FE(DDSCAPS_VIDEOMEMORY
)
216 FE(DDSCAPS_WRITEONLY
)
219 FE(DDSCAPS_LIVEVIDEO
)
223 FE(DDSCAPS_RESERVED2
)
224 FE(DDSCAPS_ALLOCONLOAD
)
225 FE(DDSCAPS_VIDEOPORT
)
226 FE(DDSCAPS_LOCALVIDMEM
)
227 FE(DDSCAPS_NONLOCALVIDMEM
)
228 FE(DDSCAPS_STANDARDVGAMODE
)
229 FE(DDSCAPS_OPTIMIZED
)
231 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
232 if (flags
[i
].mask
& flagmask
)
233 DUMP("%s ",flags
[i
].name
);
237 static void _dump_DDSD(DWORD flagmask
) {
247 FE(DDSD_BACKBUFFERCOUNT
)
248 FE(DDSD_ZBUFFERBITDEPTH
)
249 FE(DDSD_ALPHABITDEPTH
)
251 FE(DDSD_CKDESTOVERLAY
)
253 FE(DDSD_CKSRCOVERLAY
)
260 for (i
=0;i
<sizeof(flags
)/sizeof(flags
[0]);i
++)
261 if (flags
[i
].mask
& flagmask
)
262 DUMP("%s ",flags
[i
].name
);
266 static int _getpixelformat(LPDIRECTDRAW2 ddraw
,LPDDPIXELFORMAT pf
) {
267 static XVisualInfo
*vi
;
272 vi
= TSXGetVisualInfo(display
,VisualNoMask
,&vt
,&nitems
);
275 if (ddraw
->d
.depth
==8) {
276 pf
->dwFlags
= DDPF_RGB
|DDPF_PALETTEINDEXED8
;
277 pf
->x
.dwRGBBitCount
= 8;
278 pf
->y
.dwRBitMask
= 0;
279 pf
->z
.dwGBitMask
= 0;
280 pf
->xx
.dwBBitMask
= 0;
281 pf
->xy
.dwRGBAlphaBitMask
= 0;
284 if (ddraw
->d
.depth
==16) {
285 pf
->dwFlags
= DDPF_RGB
;
286 pf
->x
.dwRGBBitCount
= 16;
287 pf
->y
.dwRBitMask
= vi
[0].red_mask
;
288 pf
->z
.dwGBitMask
= vi
[0].green_mask
;
289 pf
->xx
.dwBBitMask
= vi
[0].blue_mask
;
290 pf
->xy
.dwRGBAlphaBitMask
= 0;
293 FIXME(ddraw
,"_getpixelformat:unknown depth %ld?\n",ddraw
->d
.depth
);
294 return DDERR_GENERIC
;
297 /******************************************************************************
298 * IDirectDrawSurface,IDirectDrawSurface2,IDirectDrawSurface3
300 * Since DDS3 and DDS2 are supersets of DDS, we implement DDS3 and let
301 * DDS and DDS2 use those functions. (Function calls did not change (except
302 * using different DirectDrawSurfaceX version), just added flags and functions)
304 static HRESULT WINAPI
IDirectDrawSurface3_Lock(
305 LPDIRECTDRAWSURFACE3
this,LPRECT32 lprect
,LPDDSURFACEDESC lpddsd
,DWORD flags
, HANDLE32 hnd
307 TRACE(ddraw
, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
308 this,lprect
,lpddsd
,flags
,(DWORD
)hnd
);
309 if (flags
& ~(DDLOCK_WAIT
|DDLOCK_READONLY
|DDLOCK_WRITEONLY
))
310 WARN(ddraw
, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
311 this,lprect
,lpddsd
,flags
,(DWORD
)hnd
);
314 FIXME(ddraw
," lprect: %dx%d-%dx%d\n",
315 lprect
->top
,lprect
->left
,lprect
->bottom
,lprect
->right
317 lpddsd
->y
.lpSurface
= this->s
.surface
+
318 (lprect
->top
*this->s
.lpitch
) +
319 (lprect
->left
*(this->s
.ddraw
->d
.depth
/8));
321 assert(this->s
.surface
);
322 lpddsd
->y
.lpSurface
= this->s
.surface
;
324 lpddsd
->dwFlags
= DDSD_WIDTH
|DDSD_HEIGHT
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_LPSURFACE
;
325 lpddsd
->dwWidth
= this->s
.width
;
326 lpddsd
->dwHeight
= this->s
.height
;
327 lpddsd
->lPitch
= this->s
.lpitch
;
328 _getpixelformat(this->s
.ddraw
,&(lpddsd
->ddpfPixelFormat
));
332 static HRESULT WINAPI
DGA_IDirectDrawSurface3_Unlock(
333 LPDIRECTDRAWSURFACE3
this,LPVOID surface
335 TRACE(ddraw
,"(%p)->Unlock(%p)\n",this,surface
);
339 static HRESULT WINAPI
Xlib_IDirectDrawSurface3_Unlock(
340 LPDIRECTDRAWSURFACE3
this,LPVOID surface
)
342 TRACE(ddraw
,"(%p)->Unlock(%p)\n",this,surface
);
344 if (!this->s
.ddraw
->e
.xlib
.paintable
)
347 /* Only redraw the screen when unlocking the buffer that is on screen */
348 if ((this->t
.xlib
.image
!= NULL
) && (this->t
.xlib
.on_screen
))
349 TSXPutImage( display
,
350 this->s
.ddraw
->e
.xlib
.drawable
,
351 DefaultGCOfScreen(screen
),
354 this->t
.xlib
.image
->width
,
355 this->t
.xlib
.image
->height
);
357 if (this->s
.palette
&& this->s
.palette
->cm
)
358 TSXSetWindowColormap(display
,this->s
.ddraw
->e
.xlib
.drawable
,this->s
.palette
->cm
);
363 static HRESULT WINAPI
DGA_IDirectDrawSurface3_Flip(
364 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWSURFACE3 flipto
,DWORD dwFlags
366 #ifdef HAVE_LIBXXF86DGA
367 TRACE(ddraw
,"(%p)->Flip(%p,%08lx)\n",this,flipto
,dwFlags
);
369 if (this->s
.backbuffer
)
370 flipto
= this->s
.backbuffer
;
374 TSXF86DGASetViewPort(display
,DefaultScreen(display
),0,flipto
->t
.dga
.fb_height
);
376 if (flipto
->s
.palette
&& flipto
->s
.palette
->cm
) {
377 TSXF86DGAInstallColormap(display
,DefaultScreen(display
),flipto
->s
.palette
->cm
);
379 while (!TSXF86DGAViewPortChanged(display
,DefaultScreen(display
),2)) {
385 tmp
= this->t
.dga
.fb_height
;
386 this->t
.dga
.fb_height
= flipto
->t
.dga
.fb_height
;
387 flipto
->t
.dga
.fb_height
= tmp
;
389 ptmp
= this->s
.surface
;
390 this->s
.surface
= flipto
->s
.surface
;
391 flipto
->s
.surface
= ptmp
;
394 #else /* defined(HAVE_LIBXXF86DGA) */
396 #endif /* defined(HAVE_LIBXXF86DGA) */
399 static HRESULT WINAPI
Xlib_IDirectDrawSurface3_Flip(
400 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWSURFACE3 flipto
,DWORD dwFlags
402 TRACE(ddraw
,"(%p)->Flip(%p,%08lx)\n",this,flipto
,dwFlags
);
403 if (!this->s
.ddraw
->e
.xlib
.paintable
)
407 if (this->s
.backbuffer
)
408 flipto
= this->s
.backbuffer
;
414 this->s
.ddraw
->e
.xlib
.drawable
,
415 DefaultGCOfScreen(screen
),
416 flipto
->t
.xlib
.image
,
418 flipto
->t
.xlib
.image
->width
,
419 flipto
->t
.xlib
.image
->height
);
420 TSXSetWindowColormap(display
,this->s
.ddraw
->e
.xlib
.drawable
,this->s
.palette
->cm
);
424 tmp
= this->t
.xlib
.image
;
425 this->t
.xlib
.image
= flipto
->t
.xlib
.image
;
426 flipto
->t
.xlib
.image
= tmp
;
427 surf
= this->s
.surface
;
428 this->s
.surface
= flipto
->s
.surface
;
429 flipto
->s
.surface
= surf
;
431 flipto
->t
.xlib
.on_screen
= TRUE
;
432 this->t
.xlib
.on_screen
= FALSE
;
437 /* The IDirectDrawSurface3::SetPalette method attaches the specified
438 * DirectDrawPalette object to a surface. The surface uses this palette for all
439 * subsequent operations. The palette change takes place immediately.
441 static HRESULT WINAPI
Xlib_IDirectDrawSurface3_SetPalette(
442 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWPALETTE pal
444 TRACE(ddraw
,"(%p)->SetPalette(%p)\n",this,pal
);
445 /* According to spec, we are only supposed to
446 * AddRef if this is not the same palette.
448 if( this->s
.palette
!= pal
)
451 pal
->lpvtbl
->fnAddRef( pal
);
452 if( this->s
.palette
!= NULL
)
453 this->s
.palette
->lpvtbl
->fnRelease( this->s
.palette
);
454 this->s
.palette
= pal
;
456 /* I think that we need to attach it to all backbuffers...*/
457 if( this->s
.backbuffer
) {
458 if( this->s
.backbuffer
->s
.palette
)
459 this->s
.backbuffer
->s
.palette
->lpvtbl
->fnRelease(
460 this->s
.backbuffer
->s
.palette
);
461 this->s
.backbuffer
->s
.palette
= pal
;
463 pal
->lpvtbl
->fnAddRef( pal
);
466 /* Perform the refresh */
467 TSXSetWindowColormap(display
,this->s
.ddraw
->e
.xlib
.drawable
,this->s
.palette
->cm
);
473 static HRESULT WINAPI
DGA_IDirectDrawSurface3_SetPalette(
474 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWPALETTE pal
476 TRACE(ddraw
,"(%p)->SetPalette(%p)\n",this,pal
);
477 #ifdef HAVE_LIBXXF86DGA
478 /* According to spec, we are only supposed to
479 * AddRef if this is not the same palette.
481 if( this->s
.palette
!= pal
)
484 pal
->lpvtbl
->fnAddRef( pal
);
485 if( this->s
.palette
!= NULL
)
486 this->s
.palette
->lpvtbl
->fnRelease( this->s
.palette
);
487 this->s
.palette
= pal
;
489 /* I think that we need to attach it to all backbuffers...*/
490 if( this->s
.backbuffer
) {
491 if( this->s
.backbuffer
->s
.palette
)
492 this->s
.backbuffer
->s
.palette
->lpvtbl
->fnRelease(this->s
.backbuffer
->s
.palette
);
493 this->s
.backbuffer
->s
.palette
= pal
;
494 if( pal
) pal
->lpvtbl
->fnAddRef( pal
);
496 TSXF86DGAInstallColormap(display
,DefaultScreen(display
),this->s
.palette
->cm
);
499 #else /* defined(HAVE_LIBXXF86DGA) */
501 #endif /* defined(HAVE_LIBXXF86DGA) */
506 static HRESULT WINAPI
IDirectDrawSurface3_Blt(
507 LPDIRECTDRAWSURFACE3
this,LPRECT32 rdst
,LPDIRECTDRAWSURFACE3 src
,LPRECT32 rsrc
,DWORD dwFlags
,LPDDBLTFX lpbltfx
512 TRACE(ddraw
,"(%p)->(%p,%p,%p,%08lx,%p)\n",
513 this,rdst
,src
,rsrc
,dwFlags
,lpbltfx
);
514 if (rdst
) TRACE(ddraw
," destrect :%dx%d-%dx%d\n",rdst
->left
,rdst
->top
,rdst
->right
,rdst
->bottom
);
515 if (rsrc
) TRACE(ddraw
," srcrect :%dx%d-%dx%d\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
516 TRACE(ddraw
,"\tflags: ");_dump_DDBLT(dwFlags
);fprintf(stderr
,"\n");
517 if (dwFlags
& DDBLT_DDFX
) {
518 TRACE(ddraw
," blitfx: \n");_dump_DDBLTFX(lpbltfx
->dwDDFX
);
522 memcpy(&xdst
,rdst
,sizeof(xdst
));
525 xdst
.bottom
= this->s
.height
;
527 xdst
.right
= this->s
.width
;
531 memcpy(&xsrc
,rsrc
,sizeof(xsrc
));
534 xsrc
.bottom
= src
->s
.height
;
536 xsrc
.right
= src
->s
.width
;
539 if (dwFlags
& DDBLT_COLORFILL
) {
540 int bpp
= this->s
.ddraw
->d
.depth
/8;
543 xline
= (LPBYTE
)this->s
.surface
+xdst
.top
*this->s
.lpitch
;
544 for (i
=xdst
.top
;i
<xdst
.bottom
;i
++) {
545 xpixel
= xline
+bpp
*xdst
.left
;
547 for (j
=xdst
.left
;j
<xdst
.right
;j
++) {
548 /* FIXME: this only works on little endian
549 * architectures, where DWORD starts with low
552 memcpy(xpixel
,&(lpbltfx
->b
.dwFillColor
),bpp
);
555 xline
+= this->s
.lpitch
;
557 dwFlags
&= ~(DDBLT_COLORFILL
);
559 dwFlags
&= ~(DDBLT_WAIT
|DDBLT_ASYNC
);/* FIXME: can't handle right now */
560 if ( (xsrc
.top
==0) && (xsrc
.bottom
==this->s
.height
) &&
561 (xsrc
.left
==0) && (xsrc
.right
==this->s
.width
) &&
562 (xdst
.top
==0) && (xdst
.bottom
==this->s
.height
) &&
563 (xdst
.left
==0) && (xdst
.right
==this->s
.width
) &&
566 memcpy(this->s
.surface
,src
->s
.surface
,this->s
.height
*this->s
.lpitch
);
569 /* Non full screen Blit. In this case, we need to copy line per line.
570 WARNING : if the program behaves badly (ie sizes of structures are different
571 or buffer not big enough) this may crash Wine... */
572 int bpp
= this->s
.ddraw
->d
.depth
/ 8;
573 int height
= xsrc
.bottom
- xsrc
.top
;
574 int width
= (xsrc
.right
- xsrc
.left
) * bpp
;
577 for (h
= 0; h
< height
; h
++) {
578 memcpy(this->s
.surface
+ ((h
+ xdst
.top
) * this->s
.lpitch
) + xdst
.left
* bpp
,
579 src
->s
.surface
+ ((h
+ xsrc
.top
) * src
->s
.lpitch
) + xsrc
.left
* bpp
,
585 TRACE(ddraw
,"\tUnsupported flags: ");_dump_DDBLT(dwFlags
);fprintf(stderr
,"\n");
591 static HRESULT WINAPI
Xlib_IDirectDrawSurface3_Blt(
592 LPDIRECTDRAWSURFACE3
this,LPRECT32 rdst
,LPDIRECTDRAWSURFACE3 src
,LPRECT32 rsrc
,DWORD dwFlags
,LPDDBLTFX lpbltfx
596 /* First, call the "common" blit function */
597 ret
= IDirectDrawSurface3_Blt(this, rdst
, src
, rsrc
, dwFlags
, lpbltfx
);
599 /* Then put the result on screen if blited on main screen buffer */
600 if (!this->s
.ddraw
->e
.xlib
.paintable
)
603 if ((this->t
.xlib
.image
!= NULL
) && (this->t
.xlib
.on_screen
))
605 this->s
.ddraw
->e
.xlib
.drawable
,
606 DefaultGCOfScreen(screen
),
609 this->t
.xlib
.image
->width
,
610 this->t
.xlib
.image
->height
);
611 if (this->s
.palette
&& this->s
.palette
->cm
)
612 TSXSetWindowColormap(display
,this->s
.ddraw
->e
.xlib
.drawable
,this->s
.palette
->cm
);
617 static HRESULT WINAPI
IDirectDrawSurface3_BltFast(
618 LPDIRECTDRAWSURFACE3
this,DWORD dstx
,DWORD dsty
,LPDIRECTDRAWSURFACE3 src
,LPRECT32 rsrc
,DWORD trans
621 if (TRACE_ON(ddraw
)) {
622 FIXME(ddraw
,"(%p)->(%ld,%ld,%p,%p,%08lx),stub!\n",
623 this,dstx
,dsty
,src
,rsrc
,trans
625 TRACE(ddraw
," trans:");_dump_DDBLTFAST(trans
);fprintf(stderr
,"\n");
626 TRACE(ddraw
," srcrect: %dx%d-%dx%d\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
628 bpp
= this->s
.ddraw
->d
.depth
/8;
629 for (i
=0;i
<rsrc
->bottom
-rsrc
->top
;i
++) {
630 memcpy( this->s
.surface
+((i
+dsty
)*this->s
.width
*bpp
)+dstx
*bpp
,
631 src
->s
.surface
+(rsrc
->top
+i
)*src
->s
.width
*bpp
+rsrc
->left
*bpp
,
632 (rsrc
->right
-rsrc
->left
)*bpp
638 static HRESULT WINAPI
IDirectDrawSurface3_BltBatch(
639 LPDIRECTDRAWSURFACE3
this,LPDDBLTBATCH ddbltbatch
,DWORD x
,DWORD y
641 FIXME(ddraw
,"(%p)->BltBatch(%p,%08lx,%08lx),stub!\n",
647 static HRESULT WINAPI
IDirectDrawSurface3_GetCaps(
648 LPDIRECTDRAWSURFACE3
this,LPDDSCAPS caps
650 TRACE(ddraw
,"(%p)->GetCaps(%p)\n",this,caps
);
651 caps
->dwCaps
= DDCAPS_PALETTE
; /* probably more */
655 static HRESULT WINAPI
IDirectDrawSurface3_GetSurfaceDesc(
656 LPDIRECTDRAWSURFACE3
this,LPDDSURFACEDESC ddsd
658 if (TRACE_ON(ddraw
)) {
659 TRACE(ddraw
, "(%p)->GetSurfaceDesc(%p)\n",
661 fprintf(stderr
," flags: ");
662 _dump_DDSD(ddsd
->dwFlags
);
663 fprintf(stderr
,"\n");
666 ddsd
->dwFlags
|= DDSD_PIXELFORMAT
|DDSD_CAPS
|DDSD_BACKBUFFERCOUNT
|DDSD_HEIGHT
|DDSD_WIDTH
;
667 ddsd
->ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
668 ddsd
->dwBackBufferCount
= 1;
669 ddsd
->dwHeight
= this->s
.height
;
670 ddsd
->dwWidth
= this->s
.width
;
671 ddsd
->lPitch
= this->s
.lpitch
;
672 if (this->s
.backbuffer
)
673 ddsd
->ddsCaps
.dwCaps
|= DDSCAPS_PRIMARYSURFACE
|DDSCAPS_FLIP
;
674 _getpixelformat(this->s
.ddraw
,&(ddsd
->ddpfPixelFormat
));
679 static ULONG WINAPI
IDirectDrawSurface3_AddRef(LPDIRECTDRAWSURFACE3
this) {
680 TRACE( ddraw
, "(%p)->() incrementing from %lu.\n", this, this->ref
);
682 return ++(this->ref
);
685 static ULONG WINAPI
DGA_IDirectDrawSurface3_Release(LPDIRECTDRAWSURFACE3
this) {
686 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
688 #ifdef HAVE_LIBXXF86DGA
689 if (!--(this->ref
)) {
690 this->s
.ddraw
->lpvtbl
->fnRelease(this->s
.ddraw
);
691 /* clear out of surface list */
692 if (this->t
.dga
.fb_height
== -1) {
693 HeapFree(GetProcessHeap(),0,this->s
.surface
);
695 this->s
.ddraw
->e
.dga
.vpmask
&= ~(1<<(this->t
.dga
.fb_height
/this->s
.ddraw
->e
.dga
.fb_height
));
697 HeapFree(GetProcessHeap(),0,this);
700 #endif /* defined(HAVE_LIBXXF86DGA) */
704 static ULONG WINAPI
Xlib_IDirectDrawSurface3_Release(LPDIRECTDRAWSURFACE3
this) {
705 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
707 if (!--(this->ref
)) {
708 this->s
.ddraw
->lpvtbl
->fnRelease(this->s
.ddraw
);
709 HeapFree(GetProcessHeap(),0,this->s
.surface
);
711 if( this->s
.backbuffer
)
713 this->s
.backbuffer
->lpvtbl
->fnRelease(this->s
.backbuffer
);
716 if (this->t
.xlib
.image
!= NULL
) {
717 this->t
.xlib
.image
->data
= NULL
;
718 TSXDestroyImage(this->t
.xlib
.image
);
719 this->t
.xlib
.image
= 0;
723 this->s
.palette
->lpvtbl
->fnRelease(this->s
.palette
);
726 HeapFree(GetProcessHeap(),0,this);
732 static HRESULT WINAPI
IDirectDrawSurface3_GetAttachedSurface(
733 LPDIRECTDRAWSURFACE3
this,LPDDSCAPS lpddsd
,LPDIRECTDRAWSURFACE3
*lpdsf
735 TRACE(ddraw
, "(%p)->GetAttachedSurface(%p,%p)\n",
736 this, lpddsd
, lpdsf
);
738 if (TRACE_ON(ddraw
)) {
739 TRACE(ddraw
," caps ");
740 _dump_DDSCAPS(lpddsd
->dwCaps
);
743 if (!(lpddsd
->dwCaps
& DDSCAPS_BACKBUFFER
)) {
744 FIXME(ddraw
,"whoops, can only handle backbuffers for now\n");
748 /* FIXME: should handle more than one backbuffer */
749 *lpdsf
= this->s
.backbuffer
;
751 if( this->s
.backbuffer
)
753 this->s
.backbuffer
->lpvtbl
->fnAddRef( this->s
.backbuffer
);
759 static HRESULT WINAPI
IDirectDrawSurface3_Initialize(
760 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAW ddraw
,LPDDSURFACEDESC lpdsfd
762 return DDERR_ALREADYINITIALIZED
;
765 static HRESULT WINAPI
IDirectDrawSurface3_GetPixelFormat(
766 LPDIRECTDRAWSURFACE3
this,LPDDPIXELFORMAT pf
768 TRACE(ddraw
,"(%p)->(%p)\n",this,pf
);
769 return _getpixelformat(this->s
.ddraw
,pf
);
772 static HRESULT WINAPI
IDirectDrawSurface3_GetBltStatus(LPDIRECTDRAWSURFACE3
this,DWORD dwFlags
) {
773 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n",this,dwFlags
);
777 static HRESULT WINAPI
IDirectDrawSurface3_GetOverlayPosition(
778 LPDIRECTDRAWSURFACE3
this,LPLONG x1
,LPLONG x2
780 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,x1
,x2
);
784 static HRESULT WINAPI
IDirectDrawSurface3_SetClipper(
785 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWCLIPPER clipper
787 FIXME(ddraw
,"(%p)->(%p),stub!\n",this,clipper
);
791 static HRESULT WINAPI
IDirectDrawSurface3_AddAttachedSurface(
792 LPDIRECTDRAWSURFACE3
this,LPDIRECTDRAWSURFACE3 surf
794 FIXME(ddraw
,"(%p)->(%p),stub!\n",this,surf
);
795 this->s
.backbuffer
= surf
;
799 static HRESULT WINAPI
IDirectDrawSurface3_GetDC(LPDIRECTDRAWSURFACE3
this,HDC32
* lphdc
) {
800 FIXME(ddraw
,"(%p)->GetDC(%p)\n",this,lphdc
);
801 *lphdc
= BeginPaint32(this->s
.ddraw
->e
.xlib
.window
,&this->s
.ddraw
->e
.xlib
.ps
);
805 static HRESULT WINAPI
IDirectDrawSurface3_ReleaseDC(LPDIRECTDRAWSURFACE3
this,HDC32 hdc
) {
806 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n",this,(long)hdc
);
807 EndPaint32(this->s
.ddraw
->e
.xlib
.window
,&this->s
.ddraw
->e
.xlib
.ps
);
812 static HRESULT WINAPI
IDirectDrawSurface3_QueryInterface(LPDIRECTDRAWSURFACE3
this,REFIID refiid
,LPVOID
*obj
) {
815 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
816 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
818 /* DirectDrawSurface,DirectDrawSurface2 and DirectDrawSurface3 use
819 * the same interface. And IUnknown does that too of course.
821 if ( !memcmp(&IID_IDirectDrawSurface3
,refiid
,sizeof(IID
)) ||
822 !memcmp(&IID_IDirectDrawSurface2
,refiid
,sizeof(IID
)) ||
823 !memcmp(&IID_IDirectDrawSurface
,refiid
,sizeof(IID
)) ||
824 !memcmp(&IID_IUnknown
,refiid
,sizeof(IID
))
827 this->lpvtbl
->fnAddRef(this);
830 FIXME(ddraw
,"(%p):interface for IID %s NOT found!\n",this,xrefiid
);
831 return OLE_E_ENUM_NOMORE
;
834 static HRESULT WINAPI
IDirectDrawSurface3_IsLost(LPDIRECTDRAWSURFACE3
this) {
835 TRACE(ddraw
,"(%p)->(), stub!\n",this);
839 static HRESULT WINAPI
IDirectDrawSurface3_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE3
this,LPVOID context
,LPDDENUMSURFACESCALLBACK esfcb
) {
840 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,context
,esfcb
);
844 static HRESULT WINAPI
IDirectDrawSurface3_Restore(LPDIRECTDRAWSURFACE3
this) {
845 FIXME(ddraw
,"(%p)->(),stub!\n",this);
849 static HRESULT WINAPI
IDirectDrawSurface3_SetColorKey(
850 LPDIRECTDRAWSURFACE3
this, DWORD dwFlags
, LPDDCOLORKEY ckey
852 FIXME(ddraw
,"(%p)->(0x%08lx,%p),stub!\n",this,dwFlags
,ckey
);
854 if( dwFlags
& DDCKEY_SRCBLT
)
855 dwFlags
&= ~DDCKEY_SRCBLT
;
857 TRACE( ddraw
, "unhandled dwFlags: %08lx\n", dwFlags
);
861 static HRESULT WINAPI
IDirectDrawSurface3_AddOverlayDirtyRect(
862 LPDIRECTDRAWSURFACE3
this,
865 FIXME(ddraw
,"(%p)->(%p),stub!\n",this,lpRect
);
870 static HRESULT WINAPI
IDirectDrawSurface3_DeleteAttachedSurface(
871 LPDIRECTDRAWSURFACE3
this,
873 LPDIRECTDRAWSURFACE3 lpDDSAttachedSurface
)
875 FIXME(ddraw
,"(%p)->(0x%08lx,%p),stub!\n",this,dwFlags
,lpDDSAttachedSurface
);
880 static HRESULT WINAPI
IDirectDrawSurface3_EnumOverlayZOrders(
881 LPDIRECTDRAWSURFACE3
this,
884 LPDDENUMSURFACESCALLBACK lpfnCallback
)
886 FIXME(ddraw
,"(%p)->(0x%08lx,%p,%p),stub!\n", this,dwFlags
,
887 lpContext
, lpfnCallback
);
892 static HRESULT WINAPI
IDirectDrawSurface3_GetClipper(
893 LPDIRECTDRAWSURFACE3
this,
894 LPDIRECTDRAWCLIPPER
* lplpDDClipper
)
896 FIXME(ddraw
,"(%p)->(%p),stub!\n", this, lplpDDClipper
);
901 static HRESULT WINAPI
IDirectDrawSurface3_GetColorKey(
902 LPDIRECTDRAWSURFACE3
this,
904 LPDDCOLORKEY lpDDColorKey
)
906 FIXME(ddraw
,"(%p)->(0x%08lx,%p),stub!\n", this, dwFlags
, lpDDColorKey
);
911 static HRESULT WINAPI
IDirectDrawSurface3_GetFlipStatus(
912 LPDIRECTDRAWSURFACE3
this,
915 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n", this, dwFlags
);
920 static HRESULT WINAPI
IDirectDrawSurface3_GetPalette(
921 LPDIRECTDRAWSURFACE3
this,
922 LPDIRECTDRAWPALETTE
* lplpDDPalette
)
924 FIXME(ddraw
,"(%p)->(%p),stub!\n", this, lplpDDPalette
);
929 static HRESULT WINAPI
IDirectDrawSurface3_SetOverlayPosition(
930 LPDIRECTDRAWSURFACE3
this,
934 FIXME(ddraw
,"(%p)->(%ld,%ld),stub!\n", this, lX
, lY
);
939 static HRESULT WINAPI
IDirectDrawSurface3_UpdateOverlay(
940 LPDIRECTDRAWSURFACE3
this,
942 LPDIRECTDRAWSURFACE3 lpDDDestSurface
,
945 LPDDOVERLAYFX lpDDOverlayFx
)
947 FIXME(ddraw
,"(%p)->(%p,%p,%p,0x%08lx,%p),stub!\n", this,
948 lpSrcRect
, lpDDDestSurface
, lpDestRect
, dwFlags
, lpDDOverlayFx
);
953 static HRESULT WINAPI
IDirectDrawSurface3_UpdateOverlayDisplay(
954 LPDIRECTDRAWSURFACE3
this,
957 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n", this, dwFlags
);
962 static HRESULT WINAPI
IDirectDrawSurface3_UpdateOverlayZOrder(
963 LPDIRECTDRAWSURFACE3
this,
965 LPDIRECTDRAWSURFACE3 lpDDSReference
)
967 FIXME(ddraw
,"(%p)->(0x%08lx,%p),stub!\n", this, dwFlags
, lpDDSReference
);
972 static HRESULT WINAPI
IDirectDrawSurface3_GetDDInterface(
973 LPDIRECTDRAWSURFACE3
this,
976 FIXME(ddraw
,"(%p)->(%p),stub!\n", this, lplpDD
);
981 static HRESULT WINAPI
IDirectDrawSurface3_PageLock(
982 LPDIRECTDRAWSURFACE3
this,
985 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n", this, dwFlags
);
990 static HRESULT WINAPI
IDirectDrawSurface3_PageUnlock(
991 LPDIRECTDRAWSURFACE3
this,
994 FIXME(ddraw
,"(%p)->(0x%08lx),stub!\n", this, dwFlags
);
999 static HRESULT WINAPI
IDirectDrawSurface3_SetSurfaceDesc(
1000 LPDIRECTDRAWSURFACE3
this,
1001 LPDDSURFACEDESC lpDDSD
,
1004 FIXME(ddraw
,"(%p)->(%p,0x%08lx),stub!\n", this, lpDDSD
, dwFlags
);
1009 static struct IDirectDrawSurface3_VTable dga_dds3vt
= {
1010 IDirectDrawSurface3_QueryInterface
,
1011 IDirectDrawSurface3_AddRef
,
1012 DGA_IDirectDrawSurface3_Release
,
1013 IDirectDrawSurface3_AddAttachedSurface
,
1014 IDirectDrawSurface3_AddOverlayDirtyRect
,
1015 IDirectDrawSurface3_Blt
,
1016 IDirectDrawSurface3_BltBatch
,
1017 IDirectDrawSurface3_BltFast
,
1018 IDirectDrawSurface3_DeleteAttachedSurface
,
1019 IDirectDrawSurface3_EnumAttachedSurfaces
,
1020 IDirectDrawSurface3_EnumOverlayZOrders
,
1021 DGA_IDirectDrawSurface3_Flip
,
1022 IDirectDrawSurface3_GetAttachedSurface
,
1023 IDirectDrawSurface3_GetBltStatus
,
1024 IDirectDrawSurface3_GetCaps
,
1025 IDirectDrawSurface3_GetClipper
,
1026 IDirectDrawSurface3_GetColorKey
,
1027 IDirectDrawSurface3_GetDC
,
1028 IDirectDrawSurface3_GetFlipStatus
,
1029 IDirectDrawSurface3_GetOverlayPosition
,
1030 IDirectDrawSurface3_GetPalette
,
1031 IDirectDrawSurface3_GetPixelFormat
,
1032 IDirectDrawSurface3_GetSurfaceDesc
,
1033 IDirectDrawSurface3_Initialize
,
1034 IDirectDrawSurface3_IsLost
,
1035 IDirectDrawSurface3_Lock
,
1036 IDirectDrawSurface3_ReleaseDC
,
1037 IDirectDrawSurface3_Restore
,
1038 IDirectDrawSurface3_SetClipper
,
1039 IDirectDrawSurface3_SetColorKey
,
1040 IDirectDrawSurface3_SetOverlayPosition
,
1041 DGA_IDirectDrawSurface3_SetPalette
,
1042 DGA_IDirectDrawSurface3_Unlock
,
1043 IDirectDrawSurface3_UpdateOverlay
,
1044 IDirectDrawSurface3_UpdateOverlayDisplay
,
1045 IDirectDrawSurface3_UpdateOverlayZOrder
,
1046 IDirectDrawSurface3_GetDDInterface
,
1047 IDirectDrawSurface3_PageLock
,
1048 IDirectDrawSurface3_PageUnlock
,
1049 IDirectDrawSurface3_SetSurfaceDesc
,
1052 static struct IDirectDrawSurface3_VTable xlib_dds3vt
= {
1053 IDirectDrawSurface3_QueryInterface
,
1054 IDirectDrawSurface3_AddRef
,
1055 Xlib_IDirectDrawSurface3_Release
,
1056 IDirectDrawSurface3_AddAttachedSurface
,
1057 IDirectDrawSurface3_AddOverlayDirtyRect
,
1058 Xlib_IDirectDrawSurface3_Blt
,
1059 IDirectDrawSurface3_BltBatch
,
1060 IDirectDrawSurface3_BltFast
,
1061 IDirectDrawSurface3_DeleteAttachedSurface
,
1062 IDirectDrawSurface3_EnumAttachedSurfaces
,
1063 IDirectDrawSurface3_EnumOverlayZOrders
,
1064 Xlib_IDirectDrawSurface3_Flip
,
1065 IDirectDrawSurface3_GetAttachedSurface
,
1066 IDirectDrawSurface3_GetBltStatus
,
1067 IDirectDrawSurface3_GetCaps
,
1068 IDirectDrawSurface3_GetClipper
,
1069 IDirectDrawSurface3_GetColorKey
,
1070 IDirectDrawSurface3_GetDC
,
1071 IDirectDrawSurface3_GetFlipStatus
,
1072 IDirectDrawSurface3_GetOverlayPosition
,
1073 IDirectDrawSurface3_GetPalette
,
1074 IDirectDrawSurface3_GetPixelFormat
,
1075 IDirectDrawSurface3_GetSurfaceDesc
,
1076 IDirectDrawSurface3_Initialize
,
1077 IDirectDrawSurface3_IsLost
,
1078 IDirectDrawSurface3_Lock
,
1079 IDirectDrawSurface3_ReleaseDC
,
1080 IDirectDrawSurface3_Restore
,
1081 IDirectDrawSurface3_SetClipper
,
1082 IDirectDrawSurface3_SetColorKey
,
1083 IDirectDrawSurface3_SetOverlayPosition
,
1084 Xlib_IDirectDrawSurface3_SetPalette
,
1085 Xlib_IDirectDrawSurface3_Unlock
,
1086 IDirectDrawSurface3_UpdateOverlay
,
1087 IDirectDrawSurface3_UpdateOverlayDisplay
,
1088 IDirectDrawSurface3_UpdateOverlayZOrder
,
1089 IDirectDrawSurface3_GetDDInterface
,
1090 IDirectDrawSurface3_PageLock
,
1091 IDirectDrawSurface3_PageUnlock
,
1092 IDirectDrawSurface3_SetSurfaceDesc
,
1095 /******************************************************************************
1096 * IDirectDrawClipper
1098 static HRESULT WINAPI
IDirectDrawClipper_SetHwnd(
1099 LPDIRECTDRAWCLIPPER
this,DWORD x
,HWND32 hwnd
1101 FIXME(ddraw
,"(%p)->SetHwnd(0x%08lx,0x%08lx),stub!\n",this,x
,(DWORD
)hwnd
);
1105 static ULONG WINAPI
IDirectDrawClipper_Release(LPDIRECTDRAWCLIPPER
this) {
1106 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1111 HeapFree(GetProcessHeap(),0,this);
1115 static HRESULT WINAPI
IDirectDrawClipper_GetClipList(
1116 LPDIRECTDRAWCLIPPER
this,LPRECT32 rects
,LPRGNDATA lprgn
,LPDWORD hmm
1118 FIXME(ddraw
,"(%p,%p,%p,%p),stub!\n",this,rects
,lprgn
,hmm
);
1123 static HRESULT WINAPI
IDirectDrawClipper_SetClipList(
1124 LPDIRECTDRAWCLIPPER
this,LPRGNDATA lprgn
,DWORD hmm
1126 FIXME(ddraw
,"(%p,%p,%ld),stub!\n",this,lprgn
,hmm
);
1130 static struct IDirectDrawClipper_VTable ddclipvt
= {
1133 IDirectDrawClipper_Release
,
1134 IDirectDrawClipper_GetClipList
,
1138 IDirectDrawClipper_SetClipList
,
1139 IDirectDrawClipper_SetHwnd
1142 /******************************************************************************
1143 * IDirectDrawPalette
1145 static HRESULT WINAPI
IDirectDrawPalette_GetEntries(
1146 LPDIRECTDRAWPALETTE
this,DWORD x
,DWORD start
,DWORD count
,LPPALETTEENTRY palent
1150 if (!this->cm
) /* should not happen */ {
1151 FIXME(ddraw
,"app tried to read colormap for non-palettized mode\n");
1152 return DDERR_GENERIC
;
1154 for (i
=0;i
<count
;i
++) {
1155 palent
[i
].peRed
= this->palents
[start
+i
].peRed
;
1156 palent
[i
].peBlue
= this->palents
[start
+i
].peBlue
;
1157 palent
[i
].peGreen
= this->palents
[start
+i
].peGreen
;
1158 palent
[i
].peFlags
= this->palents
[start
+i
].peFlags
;
1164 static HRESULT WINAPI
Xlib_IDirectDrawPalette_SetEntries(
1165 LPDIRECTDRAWPALETTE
this,DWORD x
,DWORD start
,DWORD count
,LPPALETTEENTRY palent
1170 TRACE(ddraw
,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1171 this,x
,start
,count
,palent
1173 if (!this->cm
) /* should not happen */ {
1174 FIXME(ddraw
,"app tried to set colormap in non-palettized mode\n");
1175 return DDERR_GENERIC
;
1177 if (!this->ddraw
->e
.xlib
.paintable
)
1179 for (i
=0;i
<count
;i
++) {
1180 xc
.red
= palent
[i
].peRed
<<8;
1181 xc
.blue
= palent
[i
].peBlue
<<8;
1182 xc
.green
= palent
[i
].peGreen
<<8;
1183 xc
.flags
= DoRed
|DoBlue
|DoGreen
;
1186 TSXStoreColor(display
,this->cm
,&xc
);
1188 this->palents
[start
+i
].peRed
= palent
[i
].peRed
;
1189 this->palents
[start
+i
].peBlue
= palent
[i
].peBlue
;
1190 this->palents
[start
+i
].peGreen
= palent
[i
].peGreen
;
1191 this->palents
[start
+i
].peFlags
= palent
[i
].peFlags
;
1196 static HRESULT WINAPI
DGA_IDirectDrawPalette_SetEntries(
1197 LPDIRECTDRAWPALETTE
this,DWORD x
,DWORD start
,DWORD count
,LPPALETTEENTRY palent
1199 #ifdef HAVE_LIBXXF86DGA
1204 TRACE(ddraw
,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1205 this,x
,start
,count
,palent
1207 if (!this->cm
) /* should not happen */ {
1208 FIXME(ddraw
,"app tried to set colormap in non-palettized mode\n");
1209 return DDERR_GENERIC
;
1211 /* FIXME: free colorcells instead of freeing whole map */
1213 this->cm
= TSXCopyColormapAndFree(display
,this->cm
);
1214 TSXFreeColormap(display
,cm
);
1216 for (i
=0;i
<count
;i
++) {
1217 xc
.red
= palent
[i
].peRed
<<8;
1218 xc
.blue
= palent
[i
].peBlue
<<8;
1219 xc
.green
= palent
[i
].peGreen
<<8;
1220 xc
.flags
= DoRed
|DoBlue
|DoGreen
;
1223 TSXStoreColor(display
,this->cm
,&xc
);
1225 this->palents
[start
+i
].peRed
= palent
[i
].peRed
;
1226 this->palents
[start
+i
].peBlue
= palent
[i
].peBlue
;
1227 this->palents
[start
+i
].peGreen
= palent
[i
].peGreen
;
1228 this->palents
[start
+i
].peFlags
= palent
[i
].peFlags
;
1230 TSXF86DGAInstallColormap(display
,DefaultScreen(display
),this->cm
);
1232 #else /* defined(HAVE_LIBXXF86DGA) */
1233 return E_UNEXPECTED
;
1234 #endif /* defined(HAVE_LIBXXF86DGA) */
1237 static ULONG WINAPI
IDirectDrawPalette_Release(LPDIRECTDRAWPALETTE
this) {
1238 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1239 if (!--(this->ref
)) {
1241 TSXFreeColormap(display
,this->cm
);
1244 HeapFree(GetProcessHeap(),0,this);
1250 static ULONG WINAPI
IDirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE
this) {
1252 TRACE( ddraw
, "(%p)->() incrementing from %lu.\n", this, this->ref
);
1253 return ++(this->ref
);
1256 static HRESULT WINAPI
IDirectDrawPalette_Initialize(
1257 LPDIRECTDRAWPALETTE
this,LPDIRECTDRAW ddraw
,DWORD x
,LPPALETTEENTRY palent
1259 return DDERR_ALREADYINITIALIZED
;
1262 static HRESULT WINAPI
IDirectDrawPalette_GetCaps(
1263 LPDIRECTDRAWPALETTE
this, LPDWORD lpdwCaps
)
1265 FIXME( ddraw
, "(%p)->(%p) stub.\n", this, lpdwCaps
);
1269 static HRESULT WINAPI
IDirectDrawPalette_QueryInterface(
1270 LPDIRECTDRAWPALETTE
this,REFIID refiid
,LPVOID
*obj
)
1274 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1275 FIXME(ddraw
,"(%p)->(%s,%p) stub.\n",this,xrefiid
,obj
);
1280 static struct IDirectDrawPalette_VTable dga_ddpalvt
= {
1281 IDirectDrawPalette_QueryInterface
,
1282 IDirectDrawPalette_AddRef
,
1283 IDirectDrawPalette_Release
,
1284 IDirectDrawPalette_GetCaps
,
1285 IDirectDrawPalette_GetEntries
,
1286 IDirectDrawPalette_Initialize
,
1287 DGA_IDirectDrawPalette_SetEntries
1290 static struct IDirectDrawPalette_VTable xlib_ddpalvt
= {
1291 IDirectDrawPalette_QueryInterface
,
1292 IDirectDrawPalette_AddRef
,
1293 IDirectDrawPalette_Release
,
1294 IDirectDrawPalette_GetCaps
,
1295 IDirectDrawPalette_GetEntries
,
1296 IDirectDrawPalette_Initialize
,
1297 Xlib_IDirectDrawPalette_SetEntries
1300 static HRESULT WINAPI
IDirect3D_QueryInterface(
1301 LPDIRECT3D
this,REFIID refiid
,LPVOID
*obj
1303 /* FIXME: Not sure if this is correct */
1306 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1307 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1308 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1310 this->lpvtbl
->fnAddRef(this);
1313 if (!memcmp(&IID_IDirect3D
,refiid
,sizeof(IID_IDirect3D
))) {
1316 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1318 d3d
->ddraw
= (LPDIRECTDRAW
)this;
1319 this->lpvtbl
->fnAddRef(this);
1320 d3d
->lpvtbl
= &d3dvt
;
1324 if (!memcmp(&IID_IDirect3D2
,refiid
,sizeof(IID_IDirect3D
))) {
1327 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1329 d3d
->ddraw
= (LPDIRECTDRAW
)this;
1330 this->lpvtbl
->fnAddRef(this);
1331 d3d
->lpvtbl
= &d3d2vt
;
1335 FIXME(ddraw
,"(%p):interface for IID %s NOT found!\n",this,xrefiid
);
1336 return OLE_E_ENUM_NOMORE
;
1339 static ULONG WINAPI
IDirect3D_AddRef(LPDIRECT3D
this) {
1340 TRACE( ddraw
, "(%p)->() incrementing from %lu.\n", this, this->ref
);
1342 return ++(this->ref
);
1345 static ULONG WINAPI
IDirect3D_Release(LPDIRECT3D
this)
1347 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1349 if (!--(this->ref
)) {
1350 this->ddraw
->lpvtbl
->fnRelease(this->ddraw
);
1351 HeapFree(GetProcessHeap(),0,this);
1357 static HRESULT WINAPI
IDirect3D_Initialize(
1358 LPDIRECT3D
this, REFIID refiid
)
1360 /* FIXME: Not sure if this is correct */
1363 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1364 FIXME(ddraw
,"(%p)->(%s):stub.\n",this,xrefiid
);
1366 return DDERR_ALREADYINITIALIZED
;
1369 /*******************************************************************************
1372 static struct IDirect3D_VTable d3dvt
= {
1373 (void*)IDirect3D_QueryInterface
,
1374 (void*)IDirect3D_AddRef
,
1375 (void*)IDirect3D_Release
,
1376 IDirect3D_Initialize
,
1384 /*******************************************************************************
1387 static ULONG WINAPI
IDirect3D2_Release(LPDIRECT3D2
this) {
1388 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1390 if (!--(this->ref
)) {
1391 this->ddraw
->lpvtbl
->fnRelease(this->ddraw
);
1392 HeapFree(GetProcessHeap(),0,this);
1398 static HRESULT WINAPI
IDirect3D2_EnumDevices(
1399 LPDIRECT3D2
this,LPD3DENUMDEVICESCALLBACK cb
, LPVOID context
1401 D3DDEVICEDESC d1
,d2
;
1403 FIXME(ddraw
,"(%p)->(%p,%p),stub!\n",this,cb
,context
);
1405 d1
.dwSize
= sizeof(d1
);
1408 d2
.dwSize
= sizeof(d2
);
1411 cb((void*)&IID_IDirect3DHALDevice
,"WINE Direct3D HAL","direct3d",&d1
,&d2
,context
);
1416 static struct IDirect3D2_VTable d3d2vt
= {
1420 IDirect3D2_EnumDevices
,
1428 /*******************************************************************************
1432 /* Used in conjunction with cbWndExtra for storage of the this ptr for the window.
1433 * Please adjust allocation in Xlib_DirectDrawCreate if you store more data here.
1435 static INT32 ddrawXlibThisOffset
= 0;
1437 static HRESULT WINAPI
DGA_IDirectDraw2_CreateSurface(
1438 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsd
,LPDIRECTDRAWSURFACE
*lpdsf
,IUnknown
*lpunk
1440 #ifdef HAVE_LIBXXF86DGA
1443 TRACE(ddraw
, "(%p)->(%p,%p,%p)\n",this,lpddsd
,lpdsf
,lpunk
);
1444 if (TRACE_ON(ddraw
)) {
1445 DUMP("[w=%ld,h=%ld,flags ",lpddsd
->dwWidth
,lpddsd
->dwHeight
);
1446 _dump_DDSD(lpddsd
->dwFlags
);
1447 fprintf(stderr
,"caps ");
1448 _dump_DDSCAPS(lpddsd
->ddsCaps
.dwCaps
);
1449 fprintf(stderr
,"]\n");
1452 *lpdsf
= (LPDIRECTDRAWSURFACE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface
));
1453 this->lpvtbl
->fnAddRef(this);
1455 (*lpdsf
)->lpvtbl
= (LPDIRECTDRAWSURFACE_VTABLE
)&dga_dds3vt
;
1456 if ( (lpddsd
->dwFlags
& DDSD_CAPS
) &&
1457 (lpddsd
->ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)
1459 if (!(lpddsd
->dwFlags
& DDSD_WIDTH
))
1460 lpddsd
->dwWidth
= this->e
.dga
.fb_width
;
1461 if (!(lpddsd
->dwFlags
& DDSD_HEIGHT
))
1462 lpddsd
->dwHeight
= this->e
.dga
.fb_height
;
1463 (*lpdsf
)->s
.surface
= (LPBYTE
)HeapAlloc(GetProcessHeap(),0,lpddsd
->dwWidth
*lpddsd
->dwHeight
*this->d
.depth
/8);
1464 (*lpdsf
)->t
.dga
.fb_height
= -1;
1465 (*lpdsf
)->s
.lpitch
= lpddsd
->dwWidth
*this->d
.depth
/8;
1466 TRACE(ddraw
,"using system memory for a primary surface\n");
1469 if (!(this->e
.dga
.vpmask
& (1<<i
)))
1471 TRACE(ddraw
,"using viewport %d for a primary surface\n",i
);
1472 /* if i == 32 or maximum ... return error */
1473 this->e
.dga
.vpmask
|=(1<<i
);
1474 (*lpdsf
)->s
.surface
= this->e
.dga
.fb_addr
+((i
*this->e
.dga
.fb_height
)*this->e
.dga
.fb_width
*this->d
.depth
/8);
1475 (*lpdsf
)->t
.dga
.fb_height
= i
*this->e
.dga
.fb_height
;
1476 (*lpdsf
)->s
.lpitch
= this->e
.dga
.fb_width
*this->d
.depth
/8;
1479 lpddsd
->lPitch
= (*lpdsf
)->s
.lpitch
;
1481 (*lpdsf
)->s
.width
= this->d
.width
;
1482 (*lpdsf
)->s
.height
= this->d
.height
;
1483 (*lpdsf
)->s
.ddraw
= this;
1484 (*lpdsf
)->s
.backbuffer
= NULL
;
1485 if (lpddsd
->dwFlags
& DDSD_BACKBUFFERCOUNT
) {
1486 LPDIRECTDRAWSURFACE3 back
;
1488 if (lpddsd
->dwBackBufferCount
>1)
1489 FIXME(ddraw
,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd
->dwBackBufferCount
);
1491 (*lpdsf
)->s
.backbuffer
= back
= (LPDIRECTDRAWSURFACE3
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface3
));
1492 this->lpvtbl
->fnAddRef(this);
1494 back
->lpvtbl
= (LPDIRECTDRAWSURFACE3_VTABLE
)&dga_dds3vt
;
1496 if (!(this->e
.dga
.vpmask
& (1<<i
)))
1498 TRACE(ddraw
,"using viewport %d for backbuffer\n",i
);
1499 /* if i == 32 or maximum ... return error */
1500 this->e
.dga
.vpmask
|=(1<<i
);
1501 back
->s
.surface
= this->e
.dga
.fb_addr
+((i
*this->e
.dga
.fb_height
)*this->e
.dga
.fb_width
*this->d
.depth
/8);
1502 back
->t
.dga
.fb_height
= i
*this->e
.dga
.fb_height
;
1504 back
->s
.width
= this->d
.width
;
1505 back
->s
.height
= this->d
.height
;
1506 back
->s
.ddraw
= this;
1507 back
->s
.lpitch
= this->e
.dga
.fb_width
*this->d
.depth
/8;
1508 back
->s
.backbuffer
= NULL
; /* does not have a backbuffer, it is
1512 #else /* defined(HAVE_LIBXXF86DGA) */
1513 return E_UNEXPECTED
;
1514 #endif /* defined(HAVE_LIBXXF86DGA) */
1517 static HRESULT WINAPI
Xlib_IDirectDraw2_CreateSurface(
1518 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsd
,LPDIRECTDRAWSURFACE
*lpdsf
,IUnknown
*lpunk
1520 TRACE(ddraw
, "(%p)->CreateSurface(%p,%p,%p)\n",
1521 this,lpddsd
,lpdsf
,lpunk
);
1523 if (TRACE_ON(ddraw
)) {
1524 fprintf(stderr
,"[w=%ld,h=%ld,flags ",lpddsd
->dwWidth
,lpddsd
->dwHeight
);
1525 _dump_DDSD(lpddsd
->dwFlags
);
1526 fprintf(stderr
,"caps ");
1527 _dump_DDSCAPS(lpddsd
->ddsCaps
.dwCaps
);
1528 fprintf(stderr
,"]\n");
1531 *lpdsf
= (LPDIRECTDRAWSURFACE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface
));
1533 this->lpvtbl
->fnAddRef(this);
1534 (*lpdsf
)->s
.ddraw
= this;
1536 (*lpdsf
)->lpvtbl
= (LPDIRECTDRAWSURFACE_VTABLE
)&xlib_dds3vt
;
1538 if (!(lpddsd
->dwFlags
& DDSD_WIDTH
))
1539 lpddsd
->dwWidth
= this->d
.width
;
1540 if (!(lpddsd
->dwFlags
& DDSD_HEIGHT
))
1541 lpddsd
->dwHeight
= this->d
.height
;
1542 (*lpdsf
)->s
.surface
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,lpddsd
->dwWidth
*lpddsd
->dwHeight
*this->d
.depth
/8);
1544 (*lpdsf
)->s
.width
= lpddsd
->dwWidth
;
1545 (*lpdsf
)->s
.height
= lpddsd
->dwHeight
;
1547 if ((lpddsd
->dwFlags
& DDSD_CAPS
) &&
1548 (lpddsd
->ddsCaps
.dwCaps
& DDSCAPS_OFFSCREENPLAIN
)) {
1550 /* No XImage for a offscreen buffer */
1551 (*lpdsf
)->t
.xlib
.image
= NULL
;
1552 (*lpdsf
)->t
.xlib
.on_screen
= FALSE
;
1553 (*lpdsf
)->s
.lpitch
= lpddsd
->dwWidth
* (this->d
.depth
/ 8);
1555 TRACE(ddraw
,"using system memory for a primary surface\n");
1559 TRACE(ddraw
,"using standard XImage for a primary surface\n");
1561 /* In this case, create an XImage */
1563 TSXCreateImage( display
,
1564 DefaultVisualOfScreen(screen
),
1568 (*lpdsf
)->s
.surface
,
1572 (*lpdsf
)->s
.width
* (this->d
.depth
/ 8)
1574 (*lpdsf
)->t
.xlib
.image
= img
;
1575 (*lpdsf
)->t
.xlib
.on_screen
= TRUE
;
1576 (*lpdsf
)->s
.lpitch
= img
->bytes_per_line
;
1578 /* Check for backbuffers */
1579 if (lpddsd
->dwFlags
& DDSD_BACKBUFFERCOUNT
) {
1580 LPDIRECTDRAWSURFACE3 back
;
1582 if (lpddsd
->dwBackBufferCount
>1)
1583 FIXME(ddraw
,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd
->dwBackBufferCount
);
1585 (*lpdsf
)->s
.backbuffer
= back
= (LPDIRECTDRAWSURFACE3
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawSurface3
));
1587 this->lpvtbl
->fnAddRef(this);
1588 back
->s
.ddraw
= this;
1591 back
->lpvtbl
= (LPDIRECTDRAWSURFACE3_VTABLE
)&xlib_dds3vt
;
1592 /* FIXME: !8 bit images */
1593 back
->s
.surface
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
1594 img
->width
*img
->height
*(this->d
.depth
/ 8)
1596 back
->t
.xlib
.image
= TSXCreateImage(display
,
1597 DefaultVisualOfScreen(screen
),
1605 this->d
.width
*(this->d
.depth
/ 8)
1607 back
->t
.xlib
.on_screen
= FALSE
;
1608 back
->s
.width
= this->d
.width
;
1609 back
->s
.height
= this->d
.height
;
1610 back
->s
.lpitch
= back
->t
.xlib
.image
->bytes_per_line
;
1611 back
->s
.backbuffer
= NULL
; /* does not have a backbuffer, it is
1619 static HRESULT WINAPI
IDirectDraw2_DuplicateSurface(
1620 LPDIRECTDRAW2
this,LPDIRECTDRAWSURFACE src
,LPDIRECTDRAWSURFACE
*dst
1622 FIXME(ddraw
,"(%p)->(%p,%p) simply copies\n",this,src
,dst
);
1623 *dst
= src
; /* FIXME */
1627 static HRESULT WINAPI
IDirectDraw2_SetCooperativeLevel(
1628 LPDIRECTDRAW2
this,HWND32 hwnd
,DWORD cooplevel
1635 FE(DDSCL_FULLSCREEN
)
1636 FE(DDSCL_ALLOWREBOOT
)
1637 FE(DDSCL_NOWINDOWCHANGES
)
1639 FE(DDSCL_ALLOWMODEX
)
1641 FE(DDSCL_SETFOCUSWINDOW
)
1642 FE(DDSCL_SETDEVICEWINDOW
)
1643 FE(DDSCL_CREATEDEVICEWINDOW
)
1646 FIXME(ddraw
,"(%p)->(%08lx,%08lx)\n",this,(DWORD
)hwnd
,cooplevel
);
1647 if(TRACE_ON(ddraw
)){
1648 dbg_decl_str(ddraw
, 512);
1649 for (i
=0;i
<sizeof(flagmap
)/sizeof(flagmap
[0]);i
++)
1650 if (flagmap
[i
].mask
& cooplevel
)
1651 dsprintf(ddraw
, "%s ", flagmap
[i
].name
);
1652 TRACE(ddraw
," cooperative level %s\n", dbg_str(ddraw
));
1654 this->d
.mainWindow
= hwnd
;
1659 static HRESULT WINAPI
DGA_IDirectDraw_SetDisplayMode(
1660 LPDIRECTDRAW
this,DWORD width
,DWORD height
,DWORD depth
1662 #ifdef HAVE_LIBXXF86DGA
1663 int i
,*depths
,depcount
;
1665 TRACE(ddraw
, "(%p)->(%ld,%ld,%ld)\n", this, width
, height
, depth
);
1667 depths
= TSXListDepths(display
,DefaultScreen(display
),&depcount
);
1668 for (i
=0;i
<depcount
;i
++)
1669 if (depths
[i
]==depth
)
1672 if (i
==depcount
) {/* not found */
1673 ERR(ddraw
,"(w=%ld,h=%ld,d=%ld), unsupported depth!\n",width
,height
,depth
);
1674 return DDERR_UNSUPPORTEDMODE
;
1676 if (this->d
.width
< width
) {
1677 ERR(ddraw
,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld\n",width
,height
,depth
,width
,this->d
.width
);
1678 return DDERR_UNSUPPORTEDMODE
;
1680 this->d
.width
= width
;
1681 this->d
.height
= height
;
1682 /* adjust fb_height, so we don't overlap */
1683 if (this->e
.dga
.fb_height
< height
)
1684 this->e
.dga
.fb_height
= height
;
1685 this->d
.depth
= depth
;
1687 /* FIXME: this function OVERWRITES several signal handlers.
1688 * can we save them? and restore them later? In a way that
1689 * it works for the library too?
1691 TSXF86DGADirectVideo(display
,DefaultScreen(display
),XF86DGADirectGraphics
);
1693 TSXF86DGASetViewPort(display
,DefaultScreen(display
),0,this->e
.dga
.fb_height
);
1696 #ifdef RESTORE_SIGNALS
1697 SIGNAL_InitEmulator();
1700 #else /* defined(HAVE_LIBXXF86DGA) */
1701 return E_UNEXPECTED
;
1702 #endif /* defined(HAVE_LIBXXF86DGA) */
1705 static HRESULT WINAPI
Xlib_IDirectDraw_SetDisplayMode(
1706 LPDIRECTDRAW
this,DWORD width
,DWORD height
,DWORD depth
1708 int i
,*depths
,depcount
;
1711 TRACE(ddraw
, "(%p)->SetDisplayMode(%ld,%ld,%ld)\n",
1712 this, width
, height
, depth
);
1714 depths
= TSXListDepths(display
,DefaultScreen(display
),&depcount
);
1715 for (i
=0;i
<depcount
;i
++)
1716 if (depths
[i
]==depth
)
1719 if (i
==depcount
) {/* not found */
1720 sprintf(buf
,"SetDisplayMode(w=%ld,h=%ld,d=%ld), unsupported depth!",width
,height
,depth
);
1721 MessageBox32A(0,buf
,"WINE DirectDraw",MB_OK
|MB_ICONSTOP
);
1722 return DDERR_UNSUPPORTEDMODE
;
1725 if (this->d.width < width) {
1726 sprintf(buf,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld",width,height,depth,width,this->d.width);
1727 MessageBox32A(0,buf,"WINE DirectDraw",MB_OK|MB_ICONSTOP);
1728 return DDERR_UNSUPPORTEDMODE;
1731 if (this->e
.xlib
.window
)
1732 DestroyWindow32(this->e
.xlib
.window
);
1733 this->e
.xlib
.window
= CreateWindowEx32A(
1737 WS_VISIBLE
|WS_SYSMENU
|WS_THICKFRAME
,
1747 /* Store this with the window. We'll use it for the window procedure */
1748 SetWindowLong32A(this->e
.xlib
.window
,ddrawXlibThisOffset
,(LONG
)this);
1750 this->e
.xlib
.paintable
= 1;
1752 ShowWindow32(this->e
.xlib
.window
,TRUE
);
1753 UpdateWindow32(this->e
.xlib
.window
);
1755 assert(this->e
.xlib
.window
);
1757 this->e
.xlib
.drawable
= WIN_FindWndPtr(this->e
.xlib
.window
)->window
;
1759 /* We don't have a context for this window. Host off the desktop */
1760 if( !this->e
.xlib
.drawable
)
1762 this->e
.xlib
.drawable
= WIN_GetDesktop()->window
;
1765 this->d
.width
= width
;
1766 this->d
.height
= height
;
1768 /* adjust fb_height, so we don't overlap */
1770 if (this->e.dga.fb_height < height)
1771 this->e.dga.fb_height = height;*/
1772 this->d
.depth
= depth
;
1776 static HRESULT WINAPI
DGA_IDirectDraw2_GetCaps(
1777 LPDIRECTDRAW2
this,LPDDCAPS caps1
,LPDDCAPS caps2
1779 #ifdef HAVE_LIBXXF86DGA
1780 TRACE(ddraw
,"(%p)->GetCaps(%p,%p)\n",this,caps1
,caps2
);
1781 caps1
->dwVidMemTotal
= this->e
.dga
.fb_memsize
;
1782 caps1
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1783 caps1
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1785 caps2
->dwVidMemTotal
= this->e
.dga
.fb_memsize
;
1786 caps2
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1787 caps2
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1790 #else /* defined(HAVE_LIBXXF86DGA) */
1791 return E_UNEXPECTED
;
1792 #endif /* defined(HAVE_LIBXXF86DGA) */
1795 static HRESULT WINAPI
Xlib_IDirectDraw2_GetCaps(
1796 LPDIRECTDRAW2
this,LPDDCAPS caps1
,LPDDCAPS caps2
1798 TRACE(ddraw
,"(%p)->GetCaps(%p,%p)\n",this,caps1
,caps2
);
1800 caps1
->dwVidMemTotal
= 2048*1024;
1801 caps1
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1802 caps1
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1804 caps2
->dwVidMemTotal
= 2048*1024;
1805 caps2
->dwCaps
= 0xffffffff&~(DDCAPS_BANKSWITCHED
); /* we can do anything */
1806 caps2
->ddsCaps
.dwCaps
= 0xffffffff; /* we can do anything */
1808 /* END FIXME: Xlib */
1812 static HRESULT WINAPI
IDirectDraw2_CreateClipper(
1813 LPDIRECTDRAW2
this,DWORD x
,LPDIRECTDRAWCLIPPER
*lpddclip
,LPUNKNOWN lpunk
1815 FIXME(ddraw
,"(%p)->(%08lx,%p,%p),stub!\n",
1816 this,x
,lpddclip
,lpunk
1818 *lpddclip
= (LPDIRECTDRAWCLIPPER
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawClipper
));
1819 (*lpddclip
)->ref
= 1;
1820 (*lpddclip
)->lpvtbl
= &ddclipvt
;
1824 static HRESULT WINAPI
common_IDirectDraw2_CreatePalette(
1825 LPDIRECTDRAW2
this,DWORD x
,LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
*lpddpal
,LPUNKNOWN lpunk
1827 *lpddpal
= (LPDIRECTDRAWPALETTE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawPalette
));
1828 if (*lpddpal
== NULL
) return E_OUTOFMEMORY
;
1829 (*lpddpal
)->ref
= 1;
1830 (*lpddpal
)->ddraw
= (LPDIRECTDRAW
)this;
1831 (*lpddpal
)->installed
= 0;
1832 if (this->d
.depth
<=8) {
1833 (*lpddpal
)->cm
= TSXCreateColormap(display
,DefaultRootWindow(display
),DefaultVisualOfScreen(screen
),AllocAll
);
1835 /* we don't want palettes in hicolor or truecolor */
1841 static HRESULT WINAPI
DGA_IDirectDraw2_CreatePalette(
1842 LPDIRECTDRAW2
this,DWORD x
,LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
*lpddpal
,LPUNKNOWN lpunk
1845 TRACE(ddraw
,"(%p)->(%08lx,%p,%p,%p)\n",this,x
,palent
,lpddpal
,lpunk
);
1846 res
= common_IDirectDraw2_CreatePalette(this,x
,palent
,lpddpal
,lpunk
);
1847 if (res
!= 0) return res
;
1848 (*lpddpal
)->lpvtbl
= &dga_ddpalvt
;
1852 static HRESULT WINAPI
Xlib_IDirectDraw2_CreatePalette(
1853 LPDIRECTDRAW2
this,DWORD x
,LPPALETTEENTRY palent
,LPDIRECTDRAWPALETTE
*lpddpal
,LPUNKNOWN lpunk
1855 TRACE(ddraw
,"(%p)->(%08lx,%p,%p,%p)\n",this,x
,palent
,lpddpal
,lpunk
);
1856 *lpddpal
= (LPDIRECTDRAWPALETTE
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDrawPalette
));
1857 if (*lpddpal
== NULL
) return E_OUTOFMEMORY
;
1858 (*lpddpal
)->ref
= 1;
1859 (*lpddpal
)->installed
= 0;
1861 (*lpddpal
)->ddraw
= (LPDIRECTDRAW
)this;
1862 this->lpvtbl
->fnAddRef(this);
1864 if (this->d
.depth
<=8) {
1865 (*lpddpal
)->cm
= TSXCreateColormap(display
,this->e
.xlib
.drawable
,DefaultVisualOfScreen(screen
),AllocAll
);
1866 /* FIXME: this is not correct, when using -managed */
1867 TSXInstallColormap(display
,(*lpddpal
)->cm
);
1871 /* we don't want palettes in hicolor or truecolor */
1875 (*lpddpal
)->lpvtbl
= &xlib_ddpalvt
;
1879 static HRESULT WINAPI
DGA_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2
this) {
1880 #ifdef HAVE_LIBXXF86DGA
1881 TRACE(ddraw
, "(%p)->()\n",this);
1883 TSXF86DGADirectVideo(display
,DefaultScreen(display
),0);
1884 #ifdef RESTORE_SIGNALS
1885 SIGNAL_InitEmulator();
1888 #else /* defined(HAVE_LIBXXF86DGA) */
1889 return E_UNEXPECTED
;
1893 static HRESULT WINAPI
Xlib_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2
this) {
1894 TRACE(ddraw
, "(%p)->RestoreDisplayMode()\n", this);
1899 static HRESULT WINAPI
IDirectDraw2_WaitForVerticalBlank(
1900 LPDIRECTDRAW2
this,DWORD x
,HANDLE32 h
1902 TRACE(ddraw
,"(%p)->(0x%08lx,0x%08x)\n",this,x
,h
);
1906 static ULONG WINAPI
IDirectDraw2_AddRef(LPDIRECTDRAW2
this) {
1907 TRACE( ddraw
, "(%p)->() incrementing from %lu.\n", this, this->ref
);
1909 return ++(this->ref
);
1912 static ULONG WINAPI
DGA_IDirectDraw2_Release(LPDIRECTDRAW2
this) {
1913 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1915 #ifdef HAVE_LIBXXF86DGA
1916 if (!--(this->ref
)) {
1917 TSXF86DGADirectVideo(display
,DefaultScreen(display
),0);
1918 #ifdef RESTORE_SIGNALS
1919 SIGNAL_InitEmulator();
1921 HeapFree(GetProcessHeap(),0,this);
1924 #endif /* defined(HAVE_LIBXXF86DGA) */
1928 static ULONG WINAPI
Xlib_IDirectDraw2_Release(LPDIRECTDRAW2
this) {
1929 TRACE( ddraw
, "(%p)->() decrementing from %lu.\n", this, this->ref
);
1931 if (!--(this->ref
)) {
1932 HeapFree(GetProcessHeap(),0,this);
1935 /* FIXME: destroy window ... */
1939 static HRESULT WINAPI
DGA_IDirectDraw2_QueryInterface(
1940 LPDIRECTDRAW2
this,REFIID refiid
,LPVOID
*obj
1944 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1945 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1946 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1948 this->lpvtbl
->fnAddRef(this);
1951 if (!memcmp(&IID_IDirectDraw
,refiid
,sizeof(IID_IDirectDraw
))) {
1952 this->lpvtbl
= (LPDIRECTDRAW2_VTABLE
)&dga_ddvt
;
1953 this->lpvtbl
->fnAddRef(this);
1957 if (!memcmp(&IID_IDirectDraw2
,refiid
,sizeof(IID_IDirectDraw2
))) {
1958 this->lpvtbl
= (LPDIRECTDRAW2_VTABLE
)&dga_dd2vt
;
1959 this->lpvtbl
->fnAddRef(this);
1963 if (!memcmp(&IID_IDirect3D
,refiid
,sizeof(IID_IDirect3D
))) {
1966 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1968 d3d
->ddraw
= (LPDIRECTDRAW
)this;
1969 this->lpvtbl
->fnAddRef(this);
1970 d3d
->lpvtbl
= &d3dvt
;
1974 if (!memcmp(&IID_IDirect3D2
,refiid
,sizeof(IID_IDirect3D
))) {
1977 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
1979 d3d
->ddraw
= (LPDIRECTDRAW
)this;
1980 this->lpvtbl
->fnAddRef(this);
1981 d3d
->lpvtbl
= &d3d2vt
;
1985 WARN(ddraw
,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid
);
1986 return OLE_E_ENUM_NOMORE
;
1989 static HRESULT WINAPI
Xlib_IDirectDraw2_QueryInterface(
1990 LPDIRECTDRAW2
this,REFIID refiid
,LPVOID
*obj
1994 WINE_StringFromCLSID((LPCLSID
)refiid
,xrefiid
);
1995 TRACE(ddraw
,"(%p)->(%s,%p)\n",this,xrefiid
,obj
);
1996 if (!memcmp(&IID_IUnknown
,refiid
,sizeof(IID_IUnknown
))) {
1998 this->lpvtbl
->fnAddRef(this);
2001 if (!memcmp(&IID_IDirectDraw
,refiid
,sizeof(IID_IDirectDraw
))) {
2002 this->lpvtbl
= (LPDIRECTDRAW2_VTABLE
)&xlib_ddvt
;
2003 this->lpvtbl
->fnAddRef(this);
2007 if (!memcmp(&IID_IDirectDraw2
,refiid
,sizeof(IID_IDirectDraw2
))) {
2008 this->lpvtbl
= (LPDIRECTDRAW2_VTABLE
)&xlib_dd2vt
;
2009 this->lpvtbl
->fnAddRef(this);
2013 if (!memcmp(&IID_IDirect3D
,refiid
,sizeof(IID_IDirect3D
))) {
2016 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
2018 d3d
->ddraw
= (LPDIRECTDRAW
)this;
2019 this->lpvtbl
->fnAddRef(this);
2020 d3d
->lpvtbl
= &d3dvt
;
2024 if (!memcmp(&IID_IDirect3D2
,refiid
,sizeof(IID_IDirect3D
))) {
2027 d3d
= HeapAlloc(GetProcessHeap(),0,sizeof(*d3d
));
2029 d3d
->ddraw
= (LPDIRECTDRAW
)this;
2030 this->lpvtbl
->fnAddRef(this);
2031 d3d
->lpvtbl
= &d3d2vt
;
2035 WARN(ddraw
,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid
);
2036 return OLE_E_ENUM_NOMORE
;
2039 static HRESULT WINAPI
IDirectDraw2_GetVerticalBlankStatus(
2040 LPDIRECTDRAW2
this,BOOL32
*status
2042 TRACE(ddraw
,"(%p)->(%p)\n",this,status
);
2047 static HRESULT WINAPI
IDirectDraw2_EnumDisplayModes(
2048 LPDIRECTDRAW2
this,DWORD dwFlags
,LPDDSURFACEDESC lpddsfd
,LPVOID context
,LPDDENUMMODESCALLBACK modescb
2050 DDSURFACEDESC ddsfd
;
2053 } modes
[5] = { /* some of the usual modes */
2060 static int depths
[4] = {8,16,24,32};
2063 TRACE(ddraw
,"(%p)->(0x%08lx,%p,%p,%p)\n",this,dwFlags
,lpddsfd
,context
,modescb
);
2064 ddsfd
.dwSize
= sizeof(ddsfd
);
2065 ddsfd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_BACKBUFFERCOUNT
|DDSD_PIXELFORMAT
|DDSD_CAPS
;
2066 if (dwFlags
& DDEDM_REFRESHRATES
) {
2067 ddsfd
.dwFlags
|= DDSD_REFRESHRATE
;
2068 ddsfd
.x
.dwRefreshRate
= 60;
2071 for (i
=0;i
<sizeof(depths
)/sizeof(depths
[0]);i
++) {
2072 ddsfd
.dwBackBufferCount
= 1;
2073 ddsfd
.ddpfPixelFormat
.dwFourCC
= 0;
2074 ddsfd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
2075 ddsfd
.ddpfPixelFormat
.x
.dwRGBBitCount
= depths
[i
];
2077 ddsfd
.ddpfPixelFormat
.y
.dwRBitMask
= 0;
2078 ddsfd
.ddpfPixelFormat
.z
.dwGBitMask
= 0;
2079 ddsfd
.ddpfPixelFormat
.xx
.dwBBitMask
= 0;
2080 ddsfd
.ddpfPixelFormat
.xy
.dwRGBAlphaBitMask
= 0;
2081 ddsfd
.ddsCaps
.dwCaps
=DDSCAPS_PALETTE
;
2082 ddsfd
.ddpfPixelFormat
.dwFlags
|=DDPF_PALETTEINDEXED8
;
2084 ddsfd
.ddpfPixelFormat
.xy
.dwRGBAlphaBitMask
= 0;
2086 /* FIXME: We should query those from X itself */
2087 switch (depths
[i
]) {
2089 ddsfd
.ddpfPixelFormat
.y
.dwRBitMask
= 0x000f;
2090 ddsfd
.ddpfPixelFormat
.z
.dwGBitMask
= 0x00f0;
2091 ddsfd
.ddpfPixelFormat
.xx
.dwBBitMask
= 0x0f00;
2094 ddsfd
.ddpfPixelFormat
.y
.dwRBitMask
= 0x000000ff;
2095 ddsfd
.ddpfPixelFormat
.z
.dwGBitMask
= 0x0000ff00;
2096 ddsfd
.ddpfPixelFormat
.xx
.dwBBitMask
= 0x00ff0000;
2099 ddsfd
.ddpfPixelFormat
.y
.dwRBitMask
= 0x000000ff;
2100 ddsfd
.ddpfPixelFormat
.z
.dwGBitMask
= 0x0000ff00;
2101 ddsfd
.ddpfPixelFormat
.xx
.dwBBitMask
= 0x00ff0000;
2105 ddsfd
.dwWidth
= screenWidth
;
2106 ddsfd
.dwHeight
= screenHeight
;
2107 TRACE(ddraw
," enumerating (%ldx%ldx%d)\n",ddsfd
.dwWidth
,ddsfd
.dwHeight
,depths
[i
]);
2108 if (!modescb(&ddsfd
,context
)) return 0;
2110 for (j
=0;j
<sizeof(modes
)/sizeof(modes
[0]);j
++) {
2111 ddsfd
.dwWidth
= modes
[i
].w
;
2112 ddsfd
.dwHeight
= modes
[i
].h
;
2113 TRACE(ddraw
," enumerating (%ldx%ldx%d)\n",ddsfd
.dwWidth
,ddsfd
.dwHeight
,depths
[i
]);
2114 if (!modescb(&ddsfd
,context
)) return 0;
2117 if (!(dwFlags
& DDEDM_STANDARDVGAMODES
)) {
2118 /* modeX is not standard VGA */
2120 ddsfd
.dwHeight
= 200;
2121 ddsfd
.dwWidth
= 320;
2122 TRACE(ddraw
," enumerating (320x200x%d)\n",depths
[i
]);
2123 if (!modescb(&ddsfd
,context
)) return 0;
2129 static HRESULT WINAPI
DGA_IDirectDraw2_GetDisplayMode(
2130 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsfd
2132 #ifdef HAVE_LIBXXF86DGA
2133 TRACE(ddraw
,"(%p)->(%p)\n",this,lpddsfd
);
2134 lpddsfd
->dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PITCH
|DDSD_BACKBUFFERCOUNT
|DDSD_PIXELFORMAT
|DDSD_CAPS
;
2135 lpddsfd
->dwHeight
= screenHeight
;
2136 lpddsfd
->dwWidth
= screenWidth
;
2137 lpddsfd
->lPitch
= this->e
.dga
.fb_width
*this->d
.depth
/8;
2138 lpddsfd
->dwBackBufferCount
= 1;
2139 lpddsfd
->x
.dwRefreshRate
= 60;
2140 lpddsfd
->ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
2141 _getpixelformat(this,&(lpddsfd
->ddpfPixelFormat
));
2143 #else /* defined(HAVE_LIBXXF86DGA) */
2144 return E_UNEXPECTED
;
2145 #endif /* defined(HAVE_LIBXXF86DGA) */
2148 static HRESULT WINAPI
Xlib_IDirectDraw2_GetDisplayMode(
2149 LPDIRECTDRAW2
this,LPDDSURFACEDESC lpddsfd
2151 TRACE(ddraw
,"(%p)->GetDisplayMode(%p)\n",this,lpddsfd
);
2152 lpddsfd
->dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PITCH
|DDSD_BACKBUFFERCOUNT
|DDSD_PIXELFORMAT
|DDSD_CAPS
;
2153 lpddsfd
->dwHeight
= screenHeight
;
2154 lpddsfd
->dwWidth
= screenWidth
;
2155 /* POOLE FIXME: Xlib */
2156 lpddsfd
->lPitch
= this->e
.dga
.fb_width
*this->d
.depth
/8;
2157 /* END FIXME: Xlib */
2158 lpddsfd
->dwBackBufferCount
= 1;
2159 lpddsfd
->x
.dwRefreshRate
= 60;
2160 lpddsfd
->ddsCaps
.dwCaps
= DDSCAPS_PALETTE
;
2161 _getpixelformat(this,&(lpddsfd
->ddpfPixelFormat
));
2165 static HRESULT WINAPI
IDirectDraw2_FlipToGDISurface(LPDIRECTDRAW2
this) {
2166 TRACE(ddraw
,"(%p)->()\n",this);
2170 static HRESULT WINAPI
IDirectDraw2_GetMonitorFrequency(
2171 LPDIRECTDRAW2
this,LPDWORD freq
2173 FIXME(ddraw
,"(%p)->(%p) returns 60 Hz always\n",this,freq
);
2174 *freq
= 60*100; /* 60 Hz */
2178 /* what can we directly decompress? */
2179 static HRESULT WINAPI
IDirectDraw2_GetFourCCCodes(
2180 LPDIRECTDRAW2
this,LPDWORD x
,LPDWORD y
2182 FIXME(ddraw
,"(%p,%p,%p), stub\n",this,x
,y
);
2186 static HRESULT WINAPI
IDirectDraw2_EnumSurfaces(
2187 LPDIRECTDRAW2
this,DWORD x
,LPDDSURFACEDESC ddsfd
,LPVOID context
,LPDDENUMSURFACESCALLBACK ddsfcb
2189 FIXME(ddraw
,"(%p)->(0x%08lx,%p,%p,%p),stub!\n",this,x
,ddsfd
,context
,ddsfcb
);
2193 static HRESULT WINAPI
IDirectDraw2_Compact(
2194 LPDIRECTDRAW2
this )
2196 FIXME(ddraw
,"(%p)->()\n", this );
2202 /* Note: Hack so we can reuse the old functions without compiler warnings */
2204 # define XCAST(fun) (typeof(dga_ddvt.fn##fun))
2206 # define XCAST(fun) (void*)
2209 static struct IDirectDraw_VTable dga_ddvt
= {
2210 XCAST(QueryInterface
)DGA_IDirectDraw2_QueryInterface
,
2211 XCAST(AddRef
)IDirectDraw2_AddRef
,
2212 XCAST(Release
)DGA_IDirectDraw2_Release
,
2213 XCAST(Compact
)IDirectDraw2_Compact
,
2214 XCAST(CreateClipper
)IDirectDraw2_CreateClipper
,
2215 XCAST(CreatePalette
)DGA_IDirectDraw2_CreatePalette
,
2216 XCAST(CreateSurface
)DGA_IDirectDraw2_CreateSurface
,
2217 XCAST(DuplicateSurface
)IDirectDraw2_DuplicateSurface
,
2218 XCAST(EnumDisplayModes
)IDirectDraw2_EnumDisplayModes
,
2219 XCAST(EnumSurfaces
)IDirectDraw2_EnumSurfaces
,
2220 XCAST(FlipToGDISurface
)IDirectDraw2_FlipToGDISurface
,
2221 XCAST(GetCaps
)DGA_IDirectDraw2_GetCaps
,
2222 XCAST(GetDisplayMode
)DGA_IDirectDraw2_GetDisplayMode
,
2223 XCAST(GetFourCCCodes
)IDirectDraw2_GetFourCCCodes
,
2224 XCAST(GetGDISurface
)15,
2225 XCAST(GetMonitorFrequency
)IDirectDraw2_GetMonitorFrequency
,
2226 XCAST(GetScanLine
)17,
2227 XCAST(GetVerticalBlankStatus
)IDirectDraw2_GetVerticalBlankStatus
,
2228 XCAST(Initialize
)19,
2229 XCAST(RestoreDisplayMode
)DGA_IDirectDraw2_RestoreDisplayMode
,
2230 XCAST(SetCooperativeLevel
)IDirectDraw2_SetCooperativeLevel
,
2231 DGA_IDirectDraw_SetDisplayMode
,
2232 XCAST(WaitForVerticalBlank
)IDirectDraw2_WaitForVerticalBlank
,
2235 static struct IDirectDraw_VTable xlib_ddvt
= {
2236 XCAST(QueryInterface
)Xlib_IDirectDraw2_QueryInterface
,
2237 XCAST(AddRef
)IDirectDraw2_AddRef
,
2238 XCAST(Release
)Xlib_IDirectDraw2_Release
,
2239 XCAST(Compact
)IDirectDraw2_Compact
,
2240 XCAST(CreateClipper
)IDirectDraw2_CreateClipper
,
2241 XCAST(CreatePalette
)Xlib_IDirectDraw2_CreatePalette
,
2242 XCAST(CreateSurface
)Xlib_IDirectDraw2_CreateSurface
,
2243 XCAST(DuplicateSurface
)IDirectDraw2_DuplicateSurface
,
2244 XCAST(EnumDisplayModes
)IDirectDraw2_EnumDisplayModes
,
2245 XCAST(EnumSurfaces
)IDirectDraw2_EnumSurfaces
,
2246 XCAST(FlipToGDISurface
)IDirectDraw2_FlipToGDISurface
,
2247 XCAST(GetCaps
)Xlib_IDirectDraw2_GetCaps
,
2248 XCAST(GetDisplayMode
)Xlib_IDirectDraw2_GetDisplayMode
,
2249 XCAST(GetFourCCCodes
)IDirectDraw2_GetFourCCCodes
,
2250 XCAST(GetGDISurface
)15,
2251 XCAST(GetMonitorFrequency
)IDirectDraw2_GetMonitorFrequency
,
2252 XCAST(GetScanLine
)17,
2253 XCAST(GetVerticalBlankStatus
)IDirectDraw2_GetVerticalBlankStatus
,
2254 XCAST(Initialize
)19,
2255 XCAST(RestoreDisplayMode
)Xlib_IDirectDraw2_RestoreDisplayMode
,
2256 XCAST(SetCooperativeLevel
)IDirectDraw2_SetCooperativeLevel
,
2257 Xlib_IDirectDraw_SetDisplayMode
,
2258 XCAST(WaitForVerticalBlank
)IDirectDraw2_WaitForVerticalBlank
,
2261 /*****************************************************************************
2267 static HRESULT WINAPI
DGA_IDirectDraw2_SetDisplayMode(
2268 LPDIRECTDRAW2
this,DWORD width
,DWORD height
,DWORD depth
,DWORD xx
,DWORD yy
2270 return DGA_IDirectDraw_SetDisplayMode((LPDIRECTDRAW
)this,width
,height
,depth
);
2273 static HRESULT WINAPI
Xlib_IDirectDraw2_SetDisplayMode(
2274 LPDIRECTDRAW2
this,DWORD width
,DWORD height
,DWORD depth
,DWORD xx
,DWORD yy
2276 return Xlib_IDirectDraw_SetDisplayMode((LPDIRECTDRAW
)this,width
,height
,depth
);
2279 static HRESULT WINAPI
DGA_IDirectDraw2_GetAvailableVidMem(
2280 LPDIRECTDRAW2
this,LPDDSCAPS ddscaps
,LPDWORD total
,LPDWORD free
2282 TRACE(ddraw
,"(%p)->(%p,%p,%p)\n",
2283 this,ddscaps
,total
,free
2285 if (total
) *total
= this->e
.dga
.fb_memsize
* 1024;
2286 if (free
) *free
= this->e
.dga
.fb_memsize
* 1024;
2290 static HRESULT WINAPI
Xlib_IDirectDraw2_GetAvailableVidMem(
2291 LPDIRECTDRAW2
this,LPDDSCAPS ddscaps
,LPDWORD total
,LPDWORD free
2293 TRACE(ddraw
,"(%p)->(%p,%p,%p)\n",
2294 this,ddscaps
,total
,free
2296 if (total
) *total
= 2048 * 1024;
2297 if (free
) *free
= 2048 * 1024;
2301 static IDirectDraw2_VTable dga_dd2vt
= {
2302 DGA_IDirectDraw2_QueryInterface
,
2303 IDirectDraw2_AddRef
,
2304 DGA_IDirectDraw2_Release
,
2305 IDirectDraw2_Compact
,
2306 IDirectDraw2_CreateClipper
,
2307 DGA_IDirectDraw2_CreatePalette
,
2308 DGA_IDirectDraw2_CreateSurface
,
2310 IDirectDraw2_EnumDisplayModes
,
2311 IDirectDraw2_EnumSurfaces
,
2312 IDirectDraw2_FlipToGDISurface
,
2313 DGA_IDirectDraw2_GetCaps
,
2314 DGA_IDirectDraw2_GetDisplayMode
,
2315 IDirectDraw2_GetFourCCCodes
,
2317 IDirectDraw2_GetMonitorFrequency
,
2319 IDirectDraw2_GetVerticalBlankStatus
,
2321 DGA_IDirectDraw2_RestoreDisplayMode
,
2322 IDirectDraw2_SetCooperativeLevel
,
2323 DGA_IDirectDraw2_SetDisplayMode
,
2324 IDirectDraw2_WaitForVerticalBlank
,
2325 DGA_IDirectDraw2_GetAvailableVidMem
2328 static struct IDirectDraw2_VTable xlib_dd2vt
= {
2329 Xlib_IDirectDraw2_QueryInterface
,
2330 IDirectDraw2_AddRef
,
2331 Xlib_IDirectDraw2_Release
,
2332 IDirectDraw2_Compact
,
2333 IDirectDraw2_CreateClipper
,
2334 Xlib_IDirectDraw2_CreatePalette
,
2335 Xlib_IDirectDraw2_CreateSurface
,
2337 IDirectDraw2_EnumDisplayModes
,
2338 IDirectDraw2_EnumSurfaces
,
2339 IDirectDraw2_FlipToGDISurface
,
2340 Xlib_IDirectDraw2_GetCaps
,
2341 Xlib_IDirectDraw2_GetDisplayMode
,
2342 IDirectDraw2_GetFourCCCodes
,
2344 IDirectDraw2_GetMonitorFrequency
,
2346 IDirectDraw2_GetVerticalBlankStatus
,
2348 Xlib_IDirectDraw2_RestoreDisplayMode
,
2349 IDirectDraw2_SetCooperativeLevel
,
2350 Xlib_IDirectDraw2_SetDisplayMode
,
2351 IDirectDraw2_WaitForVerticalBlank
,
2352 Xlib_IDirectDraw2_GetAvailableVidMem
2355 /******************************************************************************
2359 HRESULT WINAPI
DGA_DirectDrawCreate( LPDIRECTDRAW
*lplpDD
, LPUNKNOWN pUnkOuter
) {
2360 #ifdef HAVE_LIBXXF86DGA
2361 int memsize
,banksize
,width
,major
,minor
,flags
,height
;
2364 if (getuid() != 0) {
2365 MSG("Must be root to use XF86DGA!\n");
2366 MessageBox32A(0,"Using the XF86DGA extension requires the program to be run using UID 0.","WINE DirectDraw",MB_OK
|MB_ICONSTOP
);
2367 return E_UNEXPECTED
;
2369 if (!DDRAW_DGA_Available()) {
2370 TRACE(ddraw
,"No XF86DGA detected.\n");
2371 return DDERR_GENERIC
;
2373 *lplpDD
= (LPDIRECTDRAW
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDraw
));
2374 (*lplpDD
)->lpvtbl
= &dga_ddvt
;
2376 TSXF86DGAQueryVersion(display
,&major
,&minor
);
2377 TRACE(ddraw
,"XF86DGA is version %d.%d\n",major
,minor
);
2378 TSXF86DGAQueryDirectVideo(display
,DefaultScreen(display
),&flags
);
2379 if (!(flags
& XF86DGADirectPresent
))
2380 MSG("direct video is NOT PRESENT.\n");
2381 TSXF86DGAGetVideo(display
,DefaultScreen(display
),&addr
,&width
,&banksize
,&memsize
);
2382 TRACE(ddraw
,"video framebuffer: begin %p, width %d,banksize %d,memsize %d\n",
2383 addr
,width
,banksize
,memsize
2385 (*lplpDD
)->e
.dga
.fb_width
= width
;
2386 (*lplpDD
)->d
.width
= width
;
2387 (*lplpDD
)->e
.dga
.fb_addr
= addr
;
2388 (*lplpDD
)->e
.dga
.fb_memsize
= memsize
;
2389 (*lplpDD
)->e
.dga
.fb_banksize
= banksize
;
2391 TSXF86DGAGetViewPortSize(display
,DefaultScreen(display
),&width
,&height
);
2392 TSXF86DGASetViewPort(display
,DefaultScreen(display
),0,0);
2393 (*lplpDD
)->e
.dga
.fb_height
= screenHeight
;
2395 (*lplpDD
)->e
.dga
.vpmask
= 1;
2397 (*lplpDD
)->e
.dga
.vpmask
= 0;
2400 /* just assume the default depth is the DGA depth too */
2401 (*lplpDD
)->d
.depth
= DefaultDepthOfScreen(screen
);
2402 #ifdef RESTORE_SIGNALS
2403 SIGNAL_InitEmulator();
2406 #else /* defined(HAVE_LIBXXF86DGA) */
2407 return DDERR_INVALIDDIRECTDRAWGUID
;
2408 #endif /* defined(HAVE_LIBXXF86DGA) */
2411 LRESULT WINAPI
Xlib_DDWndProc(HWND32 hwnd
,UINT32 msg
,WPARAM32 wParam
,LPARAM lParam
)
2414 LPDIRECTDRAW ddraw
= NULL
;
2417 /*FIXME(ddraw,"(0x%04x,%s,0x%08lx,0x%08lx),stub!\n",(int)hwnd,SPY_GetMsgName(msg),(long)wParam,(long)lParam); */
2419 SetLastError( ERROR_SUCCESS
);
2420 ddraw
= (LPDIRECTDRAW
)GetWindowLong32A( hwnd
, ddrawXlibThisOffset
);
2422 ( ( lastError
= GetLastError() ) != ERROR_SUCCESS
)
2425 ERR( ddraw
, "Unable to retrieve this ptr from window. Error %08lx\n", lastError
);
2430 /* Perform any special direct draw functions */
2432 ddraw
->e
.xlib
.paintable
= 1;
2434 /* Now let the application deal with the rest of this */
2435 if( ddraw
->d
.mainWindow
)
2438 /* Don't think that we actually need to call this but...
2439 might as well be on the safe side of things... */
2440 ret
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);
2444 /* We didn't handle the message - give it to the application */
2445 if (ddraw
&& ddraw
->d
.mainWindow
&& WIN_FindWndPtr(ddraw
->d
.mainWindow
))
2446 ret
= CallWindowProc32A( WIN_FindWndPtr( ddraw
->d
.mainWindow
)->winproc
,
2447 ddraw
->d
.mainWindow
, msg
, wParam
, lParam
);
2453 ret
= DefWindowProc32A( ddraw
->d
.mainWindow
, msg
, wParam
, lParam
);
2459 ret
= DefWindowProc32A(hwnd
,msg
,wParam
,lParam
);
2465 HRESULT WINAPI
Xlib_DirectDrawCreate( LPDIRECTDRAW
*lplpDD
, LPUNKNOWN pUnkOuter
) {
2470 *lplpDD
= (LPDIRECTDRAW
)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectDraw
));
2471 (*lplpDD
)->lpvtbl
= &xlib_ddvt
;
2473 (*lplpDD
)->e
.xlib
.drawable
= 0; /* in SetDisplayMode */
2474 (*lplpDD
)->e
.xlib
.use_xshm
= have_xshm
;
2475 wc
.style
= CS_GLOBALCLASS
;
2476 wc
.lpfnWndProc
= Xlib_DDWndProc
;
2478 wc
.cbWndExtra
= /* Defines extra mem for window. This is used for storing this */
2479 sizeof( LPDIRECTDRAW
); /* ddrawXlibThisOffset */
2481 /* We can be a child of the desktop since we're really important */
2482 pParentWindow
= WIN_GetDesktop();
2483 wc
.hInstance
= pParentWindow
? pParentWindow
->hwndSelf
: 0;
2487 wc
.hCursor
= (HCURSOR32
)IDC_ARROW32A
;
2488 wc
.hbrBackground
= NULL_BRUSH
;
2489 wc
.lpszMenuName
= 0;
2490 wc
.lpszClassName
= "WINE_DirectDraw";
2492 (*lplpDD
)->e
.xlib
.winclass
= RegisterClass32A(&wc
);
2494 (*lplpDD
)->d
.depth
= DefaultDepthOfScreen(screen
);
2495 (*lplpDD
)->d
.height
= screenHeight
;
2496 (*lplpDD
)->d
.width
= screenWidth
;
2500 HRESULT WINAPI
DirectDrawCreate( LPGUID lpGUID
, LPDIRECTDRAW
*lplpDD
, LPUNKNOWN pUnkOuter
) {
2504 WINE_StringFromCLSID(lpGUID
,xclsid
);
2506 sprintf(xclsid
,"<guid-%0x08x>",(int)lpGUID
);
2510 TRACE(ddraw
,"(%s,%p,%p)\n",xclsid
,lplpDD
,pUnkOuter
);
2513 /* if they didn't request a particular interface, use the best
2515 if (DDRAW_DGA_Available())
2516 lpGUID
= &DGA_DirectDraw_GUID
;
2518 lpGUID
= &XLIB_DirectDraw_GUID
;
2521 if (!memcmp(lpGUID
, &DGA_DirectDraw_GUID
, sizeof(GUID
)))
2522 return DGA_DirectDrawCreate(lplpDD
, pUnkOuter
);
2523 else if (!memcmp(lpGUID
, &XLIB_DirectDraw_GUID
, sizeof(GUID
)))
2524 return Xlib_DirectDrawCreate(lplpDD
, pUnkOuter
);
2526 fprintf(stderr
,"DirectDrawCreate(%s,%p,%p): did not recognize requested GUID\n",xclsid
,lplpDD
,pUnkOuter
);
2527 return DDERR_INVALIDDIRECTDRAWGUID
;