1 /* DirectDraw using DGA or Xlib(XSHM)
3 * Copyright 1997,1998 Marcus Meissner
4 * Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
7 * When DirectVideo mode is enabled you can no longer use 'normal' X
8 * applications nor can you switch to a virtual console. Also, enabling
9 * only works, if you have switched to the screen where the application
11 * Some ways to debug this stuff are:
12 * - A terminal connected to the serial port. Can be bought used for cheap.
13 * (This is the method I am using.)
14 * - Another machine connected over some kind of network.
22 #include <sys/signal.h>
28 #ifdef HAVE_LIBXXF86VM
29 /* X is retarted and insists on declaring INT32, INT16 etc in Xmd.h,
30 this is a crude hack to get around it */
32 #include "ts_xf86vmode.h"
51 #ifdef HAVE_LIBXXF86DGA
52 #include "ts_xf86dga.h"
57 #include <sys/types.h>
63 /* This for all the enumeration and creation of D3D-related objects */
64 #include "d3d_private.h"
66 /* define this if you want to play Diablo using XF86DGA. (bug workaround) */
69 /* Restore signal handlers overwritten by XF86DGA
71 #define RESTORE_SIGNALS
72 BOOL32 (*SIGNAL_Reinit)(void); /* didn't find any obvious place to put this */
74 /* Where do these GUIDs come from? mkuuid.
75 * They exist solely to distinguish between the targets Wine support,
76 * and should be different than any other GUIDs in existence.
78 static GUID DGA_DirectDraw_GUID = { /* e2dcb020-dc60-11d1-8407-9714f5d50802 */
82 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x02}
85 static GUID XLIB_DirectDraw_GUID = { /* 1574a740-dc61-11d1-8407-f7875a7d1879 */
89 {0x84, 0x07, 0xf7, 0x87, 0x5a, 0x7d, 0x18, 0x79}
92 static struct IDirectDrawSurface4_VTable dga_dds4vt, xlib_dds4vt;
93 static struct IDirectDraw_VTable dga_ddvt, xlib_ddvt;
94 static struct IDirectDraw2_VTable dga_dd2vt, xlib_dd2vt;
95 static struct IDirectDraw4_VTable dga_dd4vt, xlib_dd4vt;
96 static struct IDirectDrawClipper_VTable ddclipvt;
97 static struct IDirectDrawPalette_VTable dga_ddpalvt, xlib_ddpalvt;
98 static struct IDirect3D_VTable d3dvt;
99 static struct IDirect3D2_VTable d3d2vt;
101 #ifdef HAVE_LIBXXF86VM
102 static XF86VidModeModeInfo *orig_mode = NULL;
106 DDRAW_DGA_Available(void)
108 #ifdef HAVE_LIBXXF86DGA
109 int evbase, evret, fd;
114 /* You don't have to be root to use DGA extensions. Simply having access to /dev/mem will do the trick */
115 /* This can be achieved by adding the user to the "kmem" group on Debian 2.x systems, don't know about */
116 /* others. --stephenc */
117 if ((fd = open("/dev/mem", O_RDWR)) != -1)
120 return (fd != -1) && TSXF86DGAQueryExtension(display,&evbase,&evret);
121 #else /* defined(HAVE_LIBXXF86DGA) */
123 #endif /* defined(HAVE_LIBXXF86DGA) */
127 DirectDrawEnumerate32A(LPDDENUMCALLBACK32A ddenumproc,LPVOID data) {
128 if (DDRAW_DGA_Available()) {
129 TRACE(ddraw, "Enumerating DGA interface\n");
130 ddenumproc(&DGA_DirectDraw_GUID,"WINE with XFree86 DGA","display",data);
132 TRACE(ddraw, "Enumerating Xlib interface\n");
133 ddenumproc(&XLIB_DirectDraw_GUID,"WINE with Xlib","display",data);
134 TRACE(ddraw, "Enumerating Default interface\n");
135 ddenumproc(NULL,"WINE (default)","display",data);
139 /* What is this doing here? */
141 DSoundHelp(DWORD x,DWORD y,DWORD z) {
142 FIXME(ddraw,"(0x%08lx,0x%08lx,0x%08lx),stub!\n",x,y,z);
147 /******************************************************************************
148 * internal helper functions
150 static void _dump_DDBLTFX(DWORD flagmask) {
156 #define FE(x) { x, #x},
157 FE(DDBLTFX_ARITHSTRETCHY)
158 FE(DDBLTFX_MIRRORLEFTRIGHT)
159 FE(DDBLTFX_MIRRORUPDOWN)
160 FE(DDBLTFX_NOTEARING)
161 FE(DDBLTFX_ROTATE180)
162 FE(DDBLTFX_ROTATE270)
164 FE(DDBLTFX_ZBUFFERRANGE)
165 FE(DDBLTFX_ZBUFFERBASEDEST)
167 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
168 if (flags[i].mask & flagmask) {
169 DUMP("%s ",flags[i].name);
176 static void _dump_DDBLTFAST(DWORD flagmask) {
182 #define FE(x) { x, #x},
183 FE(DDBLTFAST_NOCOLORKEY)
184 FE(DDBLTFAST_SRCCOLORKEY)
185 FE(DDBLTFAST_DESTCOLORKEY)
188 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
189 if (flags[i].mask & flagmask)
190 DUMP("%s ",flags[i].name);
194 static void _dump_DDBLT(DWORD flagmask) {
200 #define FE(x) { x, #x},
202 FE(DDBLT_ALPHADESTCONSTOVERRIDE)
203 FE(DDBLT_ALPHADESTNEG)
204 FE(DDBLT_ALPHADESTSURFACEOVERRIDE)
205 FE(DDBLT_ALPHAEDGEBLEND)
207 FE(DDBLT_ALPHASRCCONSTOVERRIDE)
208 FE(DDBLT_ALPHASRCNEG)
209 FE(DDBLT_ALPHASRCSURFACEOVERRIDE)
215 FE(DDBLT_KEYDESTOVERRIDE)
217 FE(DDBLT_KEYSRCOVERRIDE)
219 FE(DDBLT_ROTATIONANGLE)
221 FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE)
222 FE(DDBLT_ZBUFFERDESTOVERRIDE)
223 FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE)
224 FE(DDBLT_ZBUFFERSRCOVERRIDE)
228 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
229 if (flags[i].mask & flagmask)
230 DUMP("%s ",flags[i].name);
233 static void _dump_DDSCAPS(DWORD flagmask) {
239 #define FE(x) { x, #x},
240 FE(DDSCAPS_RESERVED1)
242 FE(DDSCAPS_BACKBUFFER)
245 FE(DDSCAPS_FRONTBUFFER)
246 FE(DDSCAPS_OFFSCREENPLAIN)
249 FE(DDSCAPS_PRIMARYSURFACE)
250 FE(DDSCAPS_PRIMARYSURFACELEFT)
251 FE(DDSCAPS_SYSTEMMEMORY)
254 FE(DDSCAPS_VIDEOMEMORY)
256 FE(DDSCAPS_WRITEONLY)
259 FE(DDSCAPS_LIVEVIDEO)
263 FE(DDSCAPS_RESERVED2)
264 FE(DDSCAPS_ALLOCONLOAD)
265 FE(DDSCAPS_VIDEOPORT)
266 FE(DDSCAPS_LOCALVIDMEM)
267 FE(DDSCAPS_NONLOCALVIDMEM)
268 FE(DDSCAPS_STANDARDVGAMODE)
269 FE(DDSCAPS_OPTIMIZED)
271 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
272 if (flags[i].mask & flagmask)
273 DUMP("%s ",flags[i].name);
277 static void _dump_DDSD(DWORD flagmask) {
287 FE(DDSD_BACKBUFFERCOUNT)
288 FE(DDSD_ZBUFFERBITDEPTH)
289 FE(DDSD_ALPHABITDEPTH)
291 FE(DDSD_CKDESTOVERLAY)
293 FE(DDSD_CKSRCOVERLAY)
300 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
301 if (flags[i].mask & flagmask)
302 DUMP("%s ",flags[i].name);
306 static void _dump_DDCOLORKEY(DWORD flagmask) {
312 #define FE(x) { x, #x},
316 FE(DDPF_PALETTEINDEXED4)
317 FE(DDPF_PALETTEINDEXEDTO8)
318 FE(DDPF_PALETTEINDEXED8)
324 FE(DDPF_PALETTEINDEXED1)
325 FE(DDPF_PALETTEINDEXED2)
328 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
329 if (flags[i].mask & flagmask)
330 DUMP("%s ",flags[i].name);
334 static void _dump_pixelformat(LPDDPIXELFORMAT pf) {
335 DUMP("Size : %ld\n", pf->dwSize);
337 _dump_DDCOLORKEY(pf->dwFlags);
338 DUMP("dwFourCC : %ld\n", pf->dwFourCC);
339 DUMP("RGB bit count : %ld\n", pf->x.dwRGBBitCount);
340 DUMP("Masks : R %08lx G %08lx B %08lx A %08lx\n",
341 pf->y.dwRBitMask, pf->z.dwGBitMask, pf->xx.dwBBitMask, pf->xy.dwRGBAlphaBitMask);
344 static int _getpixelformat(LPDIRECTDRAW2 ddraw,LPDDPIXELFORMAT pf) {
345 static XVisualInfo *vi;
350 vi = TSXGetVisualInfo(display,VisualNoMask,&vt,&nitems);
353 pf->dwSize = sizeof(DDPIXELFORMAT);
354 if (ddraw->d.depth==8) {
355 pf->dwFlags = DDPF_RGB|DDPF_PALETTEINDEXED8;
356 pf->x.dwRGBBitCount = 8;
357 pf->y.dwRBitMask = 0;
358 pf->z.dwGBitMask = 0;
359 pf->xx.dwBBitMask = 0;
360 pf->xy.dwRGBAlphaBitMask= 0;
363 if (ddraw->d.depth==16) {
364 pf->dwFlags = DDPF_RGB;
365 pf->x.dwRGBBitCount = 16;
366 pf->y.dwRBitMask = vi[0].red_mask;
367 pf->z.dwGBitMask = vi[0].green_mask;
368 pf->xx.dwBBitMask = vi[0].blue_mask;
369 pf->xy.dwRGBAlphaBitMask= 0;
372 FIXME(ddraw,"_getpixelformat:unknown depth %ld?\n",ddraw->d.depth);
373 return DDERR_GENERIC;
376 /******************************************************************************
377 * IDirectDrawSurface methods
379 * Since DDS3 and DDS2 are supersets of DDS, we implement DDS3 and let
380 * DDS and DDS2 use those functions. (Function calls did not change (except
381 * using different DirectDrawSurfaceX version), just added flags and functions)
383 static HRESULT WINAPI IDirectDrawSurface4_Lock(
384 LPDIRECTDRAWSURFACE4 this,LPRECT32 lprect,LPDDSURFACEDESC lpddsd,DWORD flags, HANDLE32 hnd
386 TRACE(ddraw, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
387 this,lprect,lpddsd,flags,(DWORD)hnd);
388 if (flags & ~(DDLOCK_WAIT|DDLOCK_READONLY|DDLOCK_WRITEONLY))
389 WARN(ddraw, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
390 this,lprect,lpddsd,flags,(DWORD)hnd);
392 /* First, copy the Surface description */
393 *lpddsd = this->s.surface_desc;
394 TRACE(ddraw,"locked surface: height=%ld, width=%ld, pitch=%ld\n",
395 lpddsd->dwHeight,lpddsd->dwWidth,lpddsd->lPitch);
397 /* If asked only for a part, change the surface pointer */
399 FIXME(ddraw," lprect: %dx%d-%dx%d\n",
400 lprect->top,lprect->left,lprect->bottom,lprect->right
402 lpddsd->y.lpSurface = this->s.surface_desc.y.lpSurface +
403 (lprect->top*this->s.surface_desc.lPitch) +
404 (lprect->left*(this->s.surface_desc.ddpfPixelFormat.x.dwRGBBitCount / 8));
406 assert(this->s.surface_desc.y.lpSurface);
411 static HRESULT WINAPI DGA_IDirectDrawSurface4_Unlock(
412 LPDIRECTDRAWSURFACE4 this,LPVOID surface
414 TRACE(ddraw,"(%p)->Unlock(%p)\n",this,surface);
418 static void Xlib_copy_surface_on_screen(LPDIRECTDRAWSURFACE4 this) {
419 if (this->s.ddraw->d.depth != this->s.ddraw->d.screen_depth) {
420 /* Pixel convertion ! */
421 if ((this->s.ddraw->d.depth == 8) && (this->s.ddraw->d.screen_depth == 16)) {
422 unsigned char *src = (unsigned char *) this->s.surface_desc.y.lpSurface;
423 unsigned short *dst = (unsigned short *) this->t.xlib.image->data;
427 if (this->s.palette != NULL) {
428 pal = (unsigned short *) this->s.palette->screen_palents;
429 for (y = 0; y < this->s.surface_desc.dwHeight; y++) {
430 for (x = 0; x < this->s.surface_desc.dwWidth; x++) {
431 dst[x + y * this->s.surface_desc.lPitch] = pal[src[x + y * this->s.surface_desc.lPitch]];
435 WARN(ddraw, "No palette set...\n");
436 memset(dst, 0, this->s.surface_desc.lPitch * this->s.surface_desc.dwHeight * 2);
439 ERR(ddraw, "Unsupported pixel convertion...\n");
444 if (this->s.ddraw->e.xlib.xshm_active)
445 TSXShmPutImage(display,
446 this->s.ddraw->d.drawable,
447 DefaultGCOfScreen(screen),
450 this->t.xlib.image->width,
451 this->t.xlib.image->height,
455 TSXPutImage( display,
456 this->s.ddraw->d.drawable,
457 DefaultGCOfScreen(screen),
460 this->t.xlib.image->width,
461 this->t.xlib.image->height);
464 static HRESULT WINAPI Xlib_IDirectDrawSurface4_Unlock(
465 LPDIRECTDRAWSURFACE4 this,LPVOID surface)
467 TRACE(ddraw,"(%p)->Unlock(%p)\n",this,surface);
469 if (!this->s.ddraw->d.paintable)
472 /* Only redraw the screen when unlocking the buffer that is on screen */
473 if ((this->t.xlib.image != NULL) &&
474 (this->s.surface_desc.ddsCaps.dwCaps & DDSCAPS_VISIBLE)) {
475 Xlib_copy_surface_on_screen(this);
477 if (this->s.palette && this->s.palette->cm)
478 TSXSetWindowColormap(display,this->s.ddraw->d.drawable,this->s.palette->cm);
484 static HRESULT WINAPI DGA_IDirectDrawSurface4_Flip(
485 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWSURFACE4 flipto,DWORD dwFlags
487 #ifdef HAVE_LIBXXF86DGA
488 TRACE(ddraw,"(%p)->Flip(%p,%08lx)\n",this,flipto,dwFlags);
490 if (this->s.backbuffer)
491 flipto = this->s.backbuffer;
495 TSXF86DGASetViewPort(display,DefaultScreen(display),0,flipto->t.dga.fb_height);
497 if (flipto->s.palette && flipto->s.palette->cm) {
498 TSXF86DGAInstallColormap(display,DefaultScreen(display),flipto->s.palette->cm);
500 while (!TSXF86DGAViewPortChanged(display,DefaultScreen(display),2)) {
506 tmp = this->t.dga.fb_height;
507 this->t.dga.fb_height = flipto->t.dga.fb_height;
508 flipto->t.dga.fb_height = tmp;
510 ptmp = this->s.surface_desc.y.lpSurface;
511 this->s.surface_desc.y.lpSurface = flipto->s.surface_desc.y.lpSurface;
512 flipto->s.surface_desc.y.lpSurface = ptmp;
515 #else /* defined(HAVE_LIBXXF86DGA) */
517 #endif /* defined(HAVE_LIBXXF86DGA) */
520 static HRESULT WINAPI Xlib_IDirectDrawSurface4_Flip(
521 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWSURFACE4 flipto,DWORD dwFlags
523 TRACE(ddraw,"(%p)->Flip(%p,%08lx)\n",this,flipto,dwFlags);
524 if (!this->s.ddraw->d.paintable)
528 if (this->s.backbuffer)
529 flipto = this->s.backbuffer;
534 Xlib_copy_surface_on_screen(this);
536 if (flipto->s.palette && flipto->s.palette->cm) {
537 TSXSetWindowColormap(display,this->s.ddraw->d.drawable,flipto->s.palette->cm);
542 tmp = this->t.xlib.image;
543 this->t.xlib.image = flipto->t.xlib.image;
544 flipto->t.xlib.image = tmp;
545 surf = this->s.surface_desc.y.lpSurface;
546 this->s.surface_desc.y.lpSurface = flipto->s.surface_desc.y.lpSurface;
547 flipto->s.surface_desc.y.lpSurface = surf;
553 /* The IDirectDrawSurface4::SetPalette method attaches the specified
554 * DirectDrawPalette object to a surface. The surface uses this palette for all
555 * subsequent operations. The palette change takes place immediately.
557 static HRESULT WINAPI Xlib_IDirectDrawSurface4_SetPalette(
558 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWPALETTE pal
561 TRACE(ddraw,"(%p)->(%p)\n",this,pal);
564 if( this->s.palette != NULL )
565 this->s.palette->lpvtbl->fnRelease( this->s.palette );
566 this->s.palette = pal;
571 if( !(pal->cm) && (this->s.ddraw->d.screen_depth<=8))
573 pal->cm = TSXCreateColormap(display,this->s.ddraw->d.drawable,DefaultVisualOfScreen(screen),AllocAll);
575 if (!Options.managed)
576 TSXInstallColormap(display,pal->cm);
578 for (i=0;i<256;i++) {
581 xc.red = pal->palents[i].peRed<<8;
582 xc.blue = pal->palents[i].peBlue<<8;
583 xc.green = pal->palents[i].peGreen<<8;
584 xc.flags = DoRed|DoBlue|DoGreen;
586 TSXStoreColor(display,pal->cm,&xc);
588 TSXInstallColormap(display,pal->cm);
591 /* According to spec, we are only supposed to
592 * AddRef if this is not the same palette.
594 if( this->s.palette != pal )
597 pal->lpvtbl->fnAddRef( pal );
598 if( this->s.palette != NULL )
599 this->s.palette->lpvtbl->fnRelease( this->s.palette );
600 this->s.palette = pal;
602 /* I think that we need to attach it to all backbuffers...*/
603 if( this->s.backbuffer ) {
604 if( this->s.backbuffer->s.palette )
605 this->s.backbuffer->s.palette->lpvtbl->fnRelease(
606 this->s.backbuffer->s.palette );
607 this->s.backbuffer->s.palette = pal;
609 pal->lpvtbl->fnAddRef( pal );
611 /* Perform the refresh */
612 TSXSetWindowColormap(display,this->s.ddraw->d.drawable,this->s.palette->cm);
617 static HRESULT WINAPI DGA_IDirectDrawSurface4_SetPalette(
618 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWPALETTE pal
620 TRACE(ddraw,"(%p)->(%p)\n",this,pal);
621 #ifdef HAVE_LIBXXF86DGA
622 /* According to spec, we are only supposed to
623 * AddRef if this is not the same palette.
625 if( this->s.palette != pal )
628 pal->lpvtbl->fnAddRef( pal );
629 if( this->s.palette != NULL )
630 this->s.palette->lpvtbl->fnRelease( this->s.palette );
631 this->s.palette = pal;
633 /* I think that we need to attach it to all backbuffers...*/
634 if( this->s.backbuffer ) {
635 if( this->s.backbuffer->s.palette )
636 this->s.backbuffer->s.palette->lpvtbl->fnRelease(this->s.backbuffer->s.palette );
637 this->s.backbuffer->s.palette = pal;
638 if( pal ) pal->lpvtbl->fnAddRef( pal );
640 TSXF86DGAInstallColormap(display,DefaultScreen(display),this->s.palette->cm);
643 #else /* defined(HAVE_LIBXXF86DGA) */
645 #endif /* defined(HAVE_LIBXXF86DGA) */
650 static HRESULT WINAPI IDirectDrawSurface4_Blt(
651 LPDIRECTDRAWSURFACE4 this,LPRECT32 rdst,LPDIRECTDRAWSURFACE4 src,LPRECT32 rsrc,DWORD dwFlags,LPDDBLTFX lpbltfx
654 DDSURFACEDESC ddesc,sdesc;
657 TRACE(ddraw,"(%p)->(%p,%p,%p,%08lx,%p)\n",
658 this,rdst,src,rsrc,dwFlags,lpbltfx);
661 src ->lpvtbl->fnLock(src, NULL,&sdesc,0,0);
662 this->lpvtbl->fnLock(this,NULL,&ddesc,0,0);
664 if (TRACE_ON(ddraw)) {
665 if (rdst) TRACE(ddraw," destrect :%dx%d-%dx%d\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
666 if (rsrc) TRACE(ddraw," srcrect :%dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
667 TRACE(ddraw,"\tflags: ");_dump_DDBLT(dwFlags);fprintf(stderr,"\n");
668 if (dwFlags & DDBLT_DDFX) {
669 TRACE(ddraw," blitfx: \n");_dump_DDBLTFX(lpbltfx->dwDDFX);
674 memcpy(&xdst,rdst,sizeof(xdst));
677 xdst.bottom = ddesc.dwHeight;
679 xdst.right = ddesc.dwWidth;
683 memcpy(&xsrc,rsrc,sizeof(xsrc));
687 xsrc.bottom = sdesc.dwHeight;
689 xsrc.right = sdesc.dwWidth;
691 memset(&xsrc,0,sizeof(xsrc));
695 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);/* FIXME: can't handle right now */
697 /* First, all the 'source-less' blits */
698 if (dwFlags & DDBLT_COLORFILL) {
699 int bpp = ddesc.ddpfPixelFormat.x.dwRGBBitCount / 8;
702 xline = (LPBYTE) ddesc.y.lpSurface + xdst.top * ddesc.lPitch;
703 for (i=xdst.top;i<xdst.bottom;i++) {
704 xpixel = xline+bpp*xdst.left;
706 for (j=xdst.left;j<xdst.right;j++) {
707 /* FIXME: this only works on little endian
708 * architectures, where DWORD starts with low
711 memcpy(xpixel,&(lpbltfx->b.dwFillColor),bpp);
714 xline += ddesc.lPitch;
716 dwFlags &= ~(DDBLT_COLORFILL);
719 if (dwFlags & DDBLT_DEPTHFILL) {
723 /* Clears the screen */
724 TRACE(ddraw, " Filling depth buffer with %ld\n", lpbltfx->b.dwFillDepth);
725 glClearDepth(lpbltfx->b.dwFillDepth / 65535.0); /* We suppose a 16 bit Z Buffer */
726 glGetBooleanv(GL_DEPTH_TEST, &ztest);
727 glDepthMask(GL_TRUE); /* Enables Z writing to be sure to delete also the Z buffer */
728 glClear(GL_DEPTH_BUFFER_BIT);
731 dwFlags &= ~(DDBLT_DEPTHFILL);
737 TRACE(ddraw,"\t(src=NULL):Unsupported flags: ");_dump_DDBLT(dwFlags);fprintf(stderr,"\n");
739 this->lpvtbl->fnUnlock(this,ddesc.y.lpSurface);
743 /* Now the 'with source' blits */
745 /* Standard 'full-surface' blit without special effects */
746 if ( (xsrc.top ==0) && (xsrc.bottom ==ddesc.dwHeight) &&
747 (xsrc.left==0) && (xsrc.right ==ddesc.dwWidth) &&
748 (xdst.top ==0) && (xdst.bottom ==ddesc.dwHeight) &&
749 (xdst.left==0) && (xdst.right ==ddesc.dwWidth) &&
752 memcpy(ddesc.y.lpSurface,
754 ddesc.dwHeight * ddesc.lPitch);
756 int bpp = ddesc.ddpfPixelFormat.x.dwRGBBitCount / 8;
757 int srcheight = xsrc.bottom - xsrc.top;
758 int srcwidth = xsrc.right - xsrc.left;
759 int dstheight = xdst.bottom - xdst.top;
760 int dstwidth = xdst.right - xdst.left;
761 int width = (xsrc.right - xsrc.left) * bpp;
764 /* Sanity check for rectangle sizes */
765 if ((srcheight != dstheight) || (srcwidth != dstwidth)) {
768 /* I think we should do a Blit with 'stretching' here....
769 Tomb Raider II uses this to display the background during the menu selection
770 when the screen resolution is != than 640x480 */
771 TRACE(ddraw, "Blt with stretching\n");
773 /* This is a basic stretch implementation. It is painfully slow and quite ugly. */
775 /* In this case, we cannot do any anti-aliasing */
776 if(dwFlags & DDBLT_KEYSRC) {
777 for (y = xdst.top; y < xdst.bottom; y++) {
778 for (x = xdst.left; x < xdst.right; x++) {
781 unsigned char *dbuf = (unsigned char *) ddesc.y.lpSurface;
782 unsigned char *sbuf = (unsigned char *) sdesc.y.lpSurface;
784 sx = (((double) (x - xdst.left) / dstwidth) * srcwidth) + xsrc.left;
785 sy = (((double) (y - xdst.top) / dstheight) * srcheight) + xsrc.top;
787 tmp = sbuf[(((int) sy) * sdesc.lPitch) + ((int) sx)];
789 if ((tmp < src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue) ||
790 (tmp > src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue))
791 dbuf[(y * ddesc.lPitch) + x] = tmp;
795 for (y = xdst.top; y < xdst.bottom; y++) {
796 for (x = xdst.left; x < xdst.right; x++) {
798 unsigned char *dbuf = (unsigned char *) ddesc.y.lpSurface;
799 unsigned char *sbuf = (unsigned char *) sdesc.y.lpSurface;
801 sx = (((double) (x - xdst.left) / dstwidth) * srcwidth) + xsrc.left;
802 sy = (((double) (y - xdst.top) / dstheight) * srcheight) + xsrc.top;
804 dbuf[(y * ddesc.lPitch) + x] = sbuf[(((int) sy) * sdesc.lPitch) + ((int) sx)];
809 FIXME(ddraw, "Not done yet for depth != 8\n");
812 /* Same size => fast blit */
813 if (dwFlags & DDBLT_KEYSRC) {
816 unsigned char tmp,*psrc,*pdst;
819 for (h = 0; h < srcheight; h++) {
820 psrc=sdesc.y.lpSurface +
821 ((h + xsrc.top) * sdesc.lPitch) + xsrc.left;
822 pdst=ddesc.y.lpSurface +
823 ((h + xdst.top) * ddesc.lPitch) + xdst.left;
824 for(i=0;i<srcwidth;i++) {
826 if ((tmp < src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue) ||
827 (tmp > src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue))
831 dwFlags&=~(DDBLT_KEYSRC);
835 unsigned short tmp,*psrc,*pdst;
838 for (h = 0; h < srcheight; h++) {
839 psrc=sdesc.y.lpSurface +
840 ((h + xsrc.top) * sdesc.lPitch) + xsrc.left;
841 pdst=ddesc.y.lpSurface +
842 ((h + xdst.top) * ddesc.lPitch) + xdst.left;
843 for(i=0;i<srcwidth;i++) {
845 if ((tmp < src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue) ||
846 (tmp > src->s.surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue))
850 dwFlags&=~(DDBLT_KEYSRC);
854 FIXME(ddraw, "Bitblt, KEYSRC: Not done yet for depth > 16\n");
857 /* Non-stretching Blt without color keying */
858 for (h = 0; h < srcheight; h++) {
859 memcpy(ddesc.y.lpSurface + ((h + xdst.top) * ddesc.lPitch) + xdst.left * bpp,
860 sdesc.y.lpSurface + ((h + xsrc.top) * sdesc.lPitch) + xsrc.left * bpp,
867 if (dwFlags && FIXME_ON(ddraw)) {
868 FIXME(ddraw,"\tUnsupported flags: ");_dump_DDBLT(dwFlags);
871 this->lpvtbl->fnUnlock(this,ddesc.y.lpSurface);
872 src ->lpvtbl->fnUnlock(src,sdesc.y.lpSurface);
877 static HRESULT WINAPI IDirectDrawSurface4_BltFast(
878 LPDIRECTDRAWSURFACE4 this,DWORD dstx,DWORD dsty,LPDIRECTDRAWSURFACE4 src,LPRECT32 rsrc,DWORD trans
881 DDSURFACEDESC ddesc,sdesc;
883 if (1 || TRACE_ON(ddraw)) {
884 FIXME(ddraw,"(%p)->(%ld,%ld,%p,%p,%08lx)\n",
885 this,dstx,dsty,src,rsrc,trans
887 FIXME(ddraw," trans:");_dump_DDBLTFAST(trans);fprintf(stderr,"\n");
888 FIXME(ddraw," srcrect: %dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
890 /* We need to lock the surfaces, or we won't get refreshes when done. */
891 src ->lpvtbl->fnLock(src, NULL,&sdesc,DDLOCK_READONLY, 0);
892 this->lpvtbl->fnLock(this,NULL,&ddesc,DDLOCK_WRITEONLY,0);
893 bpp = this->s.surface_desc.ddpfPixelFormat.x.dwRGBBitCount / 8;
894 h=rsrc->bottom-rsrc->top;
895 if (h>ddesc.dwHeight-dsty) h=ddesc.dwHeight-dsty;
896 if (h>sdesc.dwHeight-rsrc->top) h=sdesc.dwHeight-rsrc->top;
898 w=rsrc->right-rsrc->left;
899 if (w>ddesc.dwWidth-dstx) w=ddesc.dwWidth-dstx;
900 if (w>sdesc.dwWidth-rsrc->left) w=sdesc.dwWidth-rsrc->left;
904 memcpy( ddesc.y.lpSurface+(dsty +i)*ddesc.lPitch+dstx*bpp,
905 sdesc.y.lpSurface+(rsrc->top+i)*sdesc.lPitch+rsrc->left*bpp,
909 this->lpvtbl->fnUnlock(this,ddesc.y.lpSurface);
910 src ->lpvtbl->fnUnlock(src,sdesc.y.lpSurface);
914 static HRESULT WINAPI IDirectDrawSurface4_BltBatch(
915 LPDIRECTDRAWSURFACE4 this,LPDDBLTBATCH ddbltbatch,DWORD x,DWORD y
917 FIXME(ddraw,"(%p)->BltBatch(%p,%08lx,%08lx),stub!\n",
923 static HRESULT WINAPI IDirectDrawSurface4_GetCaps(
924 LPDIRECTDRAWSURFACE4 this,LPDDSCAPS caps
926 TRACE(ddraw,"(%p)->GetCaps(%p)\n",this,caps);
927 caps->dwCaps = DDSCAPS_PALETTE; /* probably more */
931 static HRESULT WINAPI IDirectDrawSurface4_GetSurfaceDesc(
932 LPDIRECTDRAWSURFACE4 this,LPDDSURFACEDESC ddsd
934 TRACE(ddraw, "(%p)->GetSurfaceDesc(%p)\n",
937 /* Simply copy the surface description stored in the object */
938 *ddsd = this->s.surface_desc;
940 if (TRACE_ON(ddraw)) {
941 fprintf(stderr," flags: ");
942 _dump_DDSD(ddsd->dwFlags);
943 if (ddsd->dwFlags & DDSD_CAPS) {
944 fprintf(stderr, " caps: ");
945 _dump_DDSCAPS(ddsd->ddsCaps.dwCaps);
947 fprintf(stderr,"\n");
953 static ULONG WINAPI IDirectDrawSurface4_AddRef(LPDIRECTDRAWSURFACE4 this) {
954 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
956 return ++(this->ref);
959 static ULONG WINAPI DGA_IDirectDrawSurface4_Release(LPDIRECTDRAWSURFACE4 this) {
960 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
962 #ifdef HAVE_LIBXXF86DGA
963 if (!--(this->ref)) {
964 this->s.ddraw->lpvtbl->fnRelease(this->s.ddraw);
965 /* clear out of surface list */
966 if (this->t.dga.fb_height == -1) {
967 HeapFree(GetProcessHeap(),0,this->s.surface_desc.y.lpSurface);
969 this->s.ddraw->e.dga.vpmask &= ~(1<<(this->t.dga.fb_height/this->s.ddraw->e.dga.fb_height));
972 /* Free the backbuffer */
973 if (this->s.backbuffer)
974 this->s.backbuffer->lpvtbl->fnRelease(this->s.backbuffer);
976 HeapFree(GetProcessHeap(),0,this);
979 #endif /* defined(HAVE_LIBXXF86DGA) */
983 static ULONG WINAPI Xlib_IDirectDrawSurface4_Release(LPDIRECTDRAWSURFACE4 this) {
984 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
986 if (!--(this->ref)) {
987 this->s.ddraw->lpvtbl->fnRelease(this->s.ddraw);
989 if( this->s.backbuffer )
990 this->s.backbuffer->lpvtbl->fnRelease(this->s.backbuffer);
992 if (this->t.xlib.image != NULL) {
993 if (this->s.ddraw->d.depth != this->s.ddraw->d.screen_depth) {
994 /* In pixel conversion mode, there are two buffers to release... */
995 HeapFree(GetProcessHeap(),0,this->s.surface_desc.y.lpSurface);
998 if (this->s.ddraw->e.xlib.xshm_active) {
999 TSXShmDetach(display, &(this->t.xlib.shminfo));
1000 TSXDestroyImage(this->t.xlib.image);
1001 shmdt(this->t.xlib.shminfo.shmaddr);
1004 HeapFree(GetProcessHeap(),0,this->t.xlib.image->data);
1005 this->t.xlib.image->data = NULL;
1006 TSXDestroyImage(this->t.xlib.image);
1007 #ifdef HAVE_LIBXXSHM
1012 this->t.xlib.image->data = NULL;
1014 #ifdef HAVE_LIBXXSHM
1015 if (this->s.ddraw->e.xlib.xshm_active) {
1016 TSXShmDetach(display, &(this->t.xlib.shminfo));
1017 TSXDestroyImage(this->t.xlib.image);
1018 shmdt(this->t.xlib.shminfo.shmaddr);
1021 HeapFree(GetProcessHeap(),0,this->s.surface_desc.y.lpSurface);
1022 TSXDestroyImage(this->t.xlib.image);
1023 #ifdef HAVE_LIBXXSHM
1028 this->t.xlib.image = 0;
1030 HeapFree(GetProcessHeap(),0,this->s.surface_desc.y.lpSurface);
1033 if (this->s.palette)
1034 this->s.palette->lpvtbl->fnRelease(this->s.palette);
1036 HeapFree(GetProcessHeap(),0,this);
1043 static HRESULT WINAPI IDirectDrawSurface4_GetAttachedSurface(
1044 LPDIRECTDRAWSURFACE4 this,LPDDSCAPS lpddsd,LPDIRECTDRAWSURFACE4 *lpdsf
1046 TRACE(ddraw, "(%p)->GetAttachedSurface(%p,%p)\n",
1047 this, lpddsd, lpdsf);
1049 if (TRACE_ON(ddraw)) {
1050 TRACE(ddraw," caps ");
1051 _dump_DDSCAPS(lpddsd->dwCaps);
1054 if (!(lpddsd->dwCaps & DDSCAPS_BACKBUFFER)) {
1055 FIXME(ddraw,"whoops, can only handle backbuffers for now\n");
1059 /* FIXME: should handle more than one backbuffer */
1060 *lpdsf = this->s.backbuffer;
1062 if( this->s.backbuffer )
1063 this->s.backbuffer->lpvtbl->fnAddRef( this->s.backbuffer );
1068 static HRESULT WINAPI IDirectDrawSurface4_Initialize(
1069 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAW ddraw,LPDDSURFACEDESC lpdsfd
1071 TRACE(ddraw,"(%p)->(%p, %p)\n",this,ddraw,lpdsfd);
1073 return DDERR_ALREADYINITIALIZED;
1076 static HRESULT WINAPI IDirectDrawSurface4_GetPixelFormat(
1077 LPDIRECTDRAWSURFACE4 this,LPDDPIXELFORMAT pf
1079 TRACE(ddraw,"(%p)->(%p)\n",this,pf);
1081 *pf = this->s.surface_desc.ddpfPixelFormat;
1086 static HRESULT WINAPI IDirectDrawSurface4_GetBltStatus(LPDIRECTDRAWSURFACE4 this,DWORD dwFlags) {
1087 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n",this,dwFlags);
1091 static HRESULT WINAPI IDirectDrawSurface4_GetOverlayPosition(
1092 LPDIRECTDRAWSURFACE4 this,LPLONG x1,LPLONG x2
1094 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,x1,x2);
1098 static HRESULT WINAPI IDirectDrawSurface4_SetClipper(
1099 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWCLIPPER clipper
1101 FIXME(ddraw,"(%p)->(%p),stub!\n",this,clipper);
1105 static HRESULT WINAPI IDirectDrawSurface4_AddAttachedSurface(
1106 LPDIRECTDRAWSURFACE4 this,LPDIRECTDRAWSURFACE4 surf
1108 FIXME(ddraw,"(%p)->(%p),stub!\n",this,surf);
1110 this->lpvtbl->fnAddRef(this);
1112 /* This hack will be enough for the moment */
1113 if (this->s.backbuffer == NULL)
1114 this->s.backbuffer = surf;
1118 static HRESULT WINAPI IDirectDrawSurface4_GetDC(LPDIRECTDRAWSURFACE4 this,HDC32* lphdc) {
1119 FIXME(ddraw,"(%p)->GetDC(%p)\n",this,lphdc);
1120 *lphdc = BeginPaint32(this->s.ddraw->d.window,&this->s.ddraw->d.ps);
1124 static HRESULT WINAPI IDirectDrawSurface4_ReleaseDC(LPDIRECTDRAWSURFACE4 this,HDC32 hdc) {
1128 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n",this,(long)hdc);
1129 EndPaint32(this->s.ddraw->d.window,&this->s.ddraw->d.ps);
1131 /* Well, as what the application did paint in this DC is NOT saved in the surface,
1132 I fill it with 'dummy' values to have something on the screen */
1133 this->lpvtbl->fnLock(this,NULL,&desc,0,0);
1134 for (y = 0; y < desc.dwHeight; y++) {
1135 for (x = 0; x < desc.dwWidth; x++) {
1136 ((unsigned char *) desc.y.lpSurface)[x + y * desc.dwWidth] = (unsigned int) this + x + y;
1139 this->lpvtbl->fnUnlock(this,NULL);
1145 static HRESULT WINAPI IDirectDrawSurface4_QueryInterface(LPDIRECTDRAWSURFACE4 this,REFIID refiid,LPVOID *obj) {
1148 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1149 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
1151 /* All DirectDrawSurface versions (1, 2, 3 and 4) use
1152 * the same interface. And IUnknown does that too of course.
1154 if ( !memcmp(&IID_IDirectDrawSurface4,refiid,sizeof(IID)) ||
1155 !memcmp(&IID_IDirectDrawSurface3,refiid,sizeof(IID)) ||
1156 !memcmp(&IID_IDirectDrawSurface2,refiid,sizeof(IID)) ||
1157 !memcmp(&IID_IDirectDrawSurface,refiid,sizeof(IID)) ||
1158 !memcmp(&IID_IUnknown,refiid,sizeof(IID))
1161 this->lpvtbl->fnAddRef(this);
1163 TRACE(ddraw, " Creating IDirectDrawSurface interface (%p)\n", *obj);
1167 else if (!memcmp(&IID_IDirect3DTexture2,refiid,sizeof(IID)))
1169 /* Texture interface */
1170 *obj = d3dtexture2_create(this);
1171 this->lpvtbl->fnAddRef(this);
1173 TRACE(ddraw, " Creating IDirect3DTexture2 interface (%p)\n", *obj);
1177 else if (!memcmp(&IID_IDirect3DTexture,refiid,sizeof(IID)))
1179 /* Texture interface */
1180 *obj = d3dtexture_create(this);
1181 this->lpvtbl->fnAddRef(this);
1183 TRACE(ddraw, " Creating IDirect3DTexture interface (%p)\n", *obj);
1187 else if (is_OpenGL_dx3(refiid, (LPDIRECTDRAWSURFACE) this, (LPDIRECT3DDEVICE *) obj))
1189 /* It is the OpenGL Direct3D Device */
1190 this->lpvtbl->fnAddRef(this);
1192 TRACE(ddraw, " Creating IDirect3DDevice interface (%p)\n", *obj);
1197 FIXME(ddraw,"(%p):interface for IID %s NOT found!\n",this,xrefiid);
1198 return OLE_E_ENUM_NOMORE;
1201 static HRESULT WINAPI IDirectDrawSurface4_IsLost(LPDIRECTDRAWSURFACE4 this) {
1202 TRACE(ddraw,"(%p)->(), stub!\n",this);
1203 return DD_OK; /* hmm */
1206 static HRESULT WINAPI IDirectDrawSurface4_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE4 this,LPVOID context,LPDDENUMSURFACESCALLBACK esfcb) {
1207 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,context,esfcb);
1211 static HRESULT WINAPI IDirectDrawSurface4_Restore(LPDIRECTDRAWSURFACE4 this) {
1212 FIXME(ddraw,"(%p)->(),stub!\n",this);
1216 static HRESULT WINAPI IDirectDrawSurface4_SetColorKey(
1217 LPDIRECTDRAWSURFACE4 this, DWORD dwFlags, LPDDCOLORKEY ckey )
1219 TRACE(ddraw,"(%p)->(0x%08lx,%p)\n",this,dwFlags,ckey);
1221 if( dwFlags & DDCKEY_SRCBLT )
1223 dwFlags &= ~DDCKEY_SRCBLT;
1224 this->s.surface_desc.dwFlags |= DDSD_CKSRCBLT;
1225 memcpy( &(this->s.surface_desc.ddckCKSrcBlt), ckey, sizeof( *ckey ) );
1228 if( dwFlags & DDCKEY_DESTBLT )
1230 dwFlags &= ~DDCKEY_DESTBLT;
1231 this->s.surface_desc.dwFlags |= DDSD_CKDESTBLT;
1232 memcpy( &(this->s.surface_desc.ddckCKDestBlt), ckey, sizeof( *ckey ) );
1235 if( dwFlags & DDCKEY_SRCOVERLAY )
1237 dwFlags &= ~DDCKEY_SRCOVERLAY;
1238 this->s.surface_desc.dwFlags |= DDSD_CKSRCOVERLAY;
1239 memcpy( &(this->s.surface_desc.ddckCKSrcOverlay), ckey, sizeof( *ckey ) );
1242 if( dwFlags & DDCKEY_DESTOVERLAY )
1244 dwFlags &= ~DDCKEY_DESTOVERLAY;
1245 this->s.surface_desc.dwFlags |= DDSD_CKDESTOVERLAY;
1246 memcpy( &(this->s.surface_desc.ddckCKDestOverlay), ckey, sizeof( *ckey ) );
1251 FIXME( ddraw, "unhandled dwFlags: 0x%08lx\n", dwFlags );
1258 static HRESULT WINAPI IDirectDrawSurface4_AddOverlayDirtyRect(
1259 LPDIRECTDRAWSURFACE4 this,
1262 FIXME(ddraw,"(%p)->(%p),stub!\n",this,lpRect);
1267 static HRESULT WINAPI IDirectDrawSurface4_DeleteAttachedSurface(
1268 LPDIRECTDRAWSURFACE4 this,
1270 LPDIRECTDRAWSURFACE4 lpDDSAttachedSurface )
1272 FIXME(ddraw,"(%p)->(0x%08lx,%p),stub!\n",this,dwFlags,lpDDSAttachedSurface);
1277 static HRESULT WINAPI IDirectDrawSurface4_EnumOverlayZOrders(
1278 LPDIRECTDRAWSURFACE4 this,
1281 LPDDENUMSURFACESCALLBACK lpfnCallback )
1283 FIXME(ddraw,"(%p)->(0x%08lx,%p,%p),stub!\n", this,dwFlags,
1284 lpContext, lpfnCallback );
1289 static HRESULT WINAPI IDirectDrawSurface4_GetClipper(
1290 LPDIRECTDRAWSURFACE4 this,
1291 LPDIRECTDRAWCLIPPER* lplpDDClipper )
1293 FIXME(ddraw,"(%p)->(%p),stub!\n", this, lplpDDClipper);
1298 static HRESULT WINAPI IDirectDrawSurface4_GetColorKey(
1299 LPDIRECTDRAWSURFACE4 this,
1301 LPDDCOLORKEY lpDDColorKey )
1303 TRACE(ddraw,"(%p)->(0x%08lx,%p)\n", this, dwFlags, lpDDColorKey);
1305 if( dwFlags & DDCKEY_SRCBLT ) {
1306 dwFlags &= ~DDCKEY_SRCBLT;
1307 memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKSrcBlt), sizeof( *lpDDColorKey ) );
1310 if( dwFlags & DDCKEY_DESTBLT )
1312 dwFlags &= ~DDCKEY_DESTBLT;
1313 memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKDestBlt), sizeof( *lpDDColorKey ) );
1316 if( dwFlags & DDCKEY_SRCOVERLAY )
1318 dwFlags &= ~DDCKEY_SRCOVERLAY;
1319 memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKSrcOverlay), sizeof( *lpDDColorKey ) );
1322 if( dwFlags & DDCKEY_DESTOVERLAY )
1324 dwFlags &= ~DDCKEY_DESTOVERLAY;
1325 memcpy( lpDDColorKey, &(this->s.surface_desc.ddckCKDestOverlay), sizeof( *lpDDColorKey ) );
1330 FIXME( ddraw, "unhandled dwFlags: 0x%08lx\n", dwFlags );
1336 static HRESULT WINAPI IDirectDrawSurface4_GetFlipStatus(
1337 LPDIRECTDRAWSURFACE4 this,
1340 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n", this, dwFlags);
1345 static HRESULT WINAPI IDirectDrawSurface4_GetPalette(
1346 LPDIRECTDRAWSURFACE4 this,
1347 LPDIRECTDRAWPALETTE* lplpDDPalette )
1349 FIXME(ddraw,"(%p)->(%p),stub!\n", this, lplpDDPalette);
1354 static HRESULT WINAPI IDirectDrawSurface4_SetOverlayPosition(
1355 LPDIRECTDRAWSURFACE4 this,
1359 FIXME(ddraw,"(%p)->(%ld,%ld),stub!\n", this, lX, lY);
1364 static HRESULT WINAPI IDirectDrawSurface4_UpdateOverlay(
1365 LPDIRECTDRAWSURFACE4 this,
1367 LPDIRECTDRAWSURFACE4 lpDDDestSurface,
1368 LPRECT32 lpDestRect,
1370 LPDDOVERLAYFX lpDDOverlayFx )
1372 FIXME(ddraw,"(%p)->(%p,%p,%p,0x%08lx,%p),stub!\n", this,
1373 lpSrcRect, lpDDDestSurface, lpDestRect, dwFlags, lpDDOverlayFx );
1378 static HRESULT WINAPI IDirectDrawSurface4_UpdateOverlayDisplay(
1379 LPDIRECTDRAWSURFACE4 this,
1382 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n", this, dwFlags);
1387 static HRESULT WINAPI IDirectDrawSurface4_UpdateOverlayZOrder(
1388 LPDIRECTDRAWSURFACE4 this,
1390 LPDIRECTDRAWSURFACE4 lpDDSReference )
1392 FIXME(ddraw,"(%p)->(0x%08lx,%p),stub!\n", this, dwFlags, lpDDSReference);
1397 static HRESULT WINAPI IDirectDrawSurface4_GetDDInterface(
1398 LPDIRECTDRAWSURFACE4 this,
1401 FIXME(ddraw,"(%p)->(%p),stub!\n", this, lplpDD);
1403 /* Not sure about that... */
1404 *lplpDD = (void *) this->s.ddraw;
1409 static HRESULT WINAPI IDirectDrawSurface4_PageLock(
1410 LPDIRECTDRAWSURFACE4 this,
1413 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n", this, dwFlags);
1418 static HRESULT WINAPI IDirectDrawSurface4_PageUnlock(
1419 LPDIRECTDRAWSURFACE4 this,
1422 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n", this, dwFlags);
1427 static HRESULT WINAPI IDirectDrawSurface4_SetSurfaceDesc(
1428 LPDIRECTDRAWSURFACE4 this,
1429 LPDDSURFACEDESC lpDDSD,
1432 FIXME(ddraw,"(%p)->(%p,0x%08lx),stub!\n", this, lpDDSD, dwFlags);
1437 static HRESULT WINAPI IDirectDrawSurface4_SetPrivateData(LPDIRECTDRAWSURFACE4 this,
1442 FIXME(ddraw, "(%p)->(%p,%p,%ld,%08lx\n", this, guidTag, lpData, cbSize, dwFlags);
1447 static HRESULT WINAPI IDirectDrawSurface4_GetPrivateData(LPDIRECTDRAWSURFACE4 this,
1450 LPDWORD lpcbBufferSize) {
1451 FIXME(ddraw, "(%p)->(%p,%p,%p)\n", this, guidTag, lpBuffer, lpcbBufferSize);
1456 static HRESULT WINAPI IDirectDrawSurface4_FreePrivateData(LPDIRECTDRAWSURFACE4 this,
1458 FIXME(ddraw, "(%p)->(%p)\n", this, guidTag);
1463 static HRESULT WINAPI IDirectDrawSurface4_GetUniquenessValue(LPDIRECTDRAWSURFACE4 this,
1465 FIXME(ddraw, "(%p)->(%p)\n", this, lpValue);
1470 static HRESULT WINAPI IDirectDrawSurface4_ChangeUniquenessValue(LPDIRECTDRAWSURFACE4 this) {
1471 FIXME(ddraw, "(%p)\n", this);
1476 static struct IDirectDrawSurface4_VTable dga_dds4vt = {
1477 IDirectDrawSurface4_QueryInterface,
1478 IDirectDrawSurface4_AddRef,
1479 DGA_IDirectDrawSurface4_Release,
1480 IDirectDrawSurface4_AddAttachedSurface,
1481 IDirectDrawSurface4_AddOverlayDirtyRect,
1482 IDirectDrawSurface4_Blt,
1483 IDirectDrawSurface4_BltBatch,
1484 IDirectDrawSurface4_BltFast,
1485 IDirectDrawSurface4_DeleteAttachedSurface,
1486 IDirectDrawSurface4_EnumAttachedSurfaces,
1487 IDirectDrawSurface4_EnumOverlayZOrders,
1488 DGA_IDirectDrawSurface4_Flip,
1489 IDirectDrawSurface4_GetAttachedSurface,
1490 IDirectDrawSurface4_GetBltStatus,
1491 IDirectDrawSurface4_GetCaps,
1492 IDirectDrawSurface4_GetClipper,
1493 IDirectDrawSurface4_GetColorKey,
1494 IDirectDrawSurface4_GetDC,
1495 IDirectDrawSurface4_GetFlipStatus,
1496 IDirectDrawSurface4_GetOverlayPosition,
1497 IDirectDrawSurface4_GetPalette,
1498 IDirectDrawSurface4_GetPixelFormat,
1499 IDirectDrawSurface4_GetSurfaceDesc,
1500 IDirectDrawSurface4_Initialize,
1501 IDirectDrawSurface4_IsLost,
1502 IDirectDrawSurface4_Lock,
1503 IDirectDrawSurface4_ReleaseDC,
1504 IDirectDrawSurface4_Restore,
1505 IDirectDrawSurface4_SetClipper,
1506 IDirectDrawSurface4_SetColorKey,
1507 IDirectDrawSurface4_SetOverlayPosition,
1508 DGA_IDirectDrawSurface4_SetPalette,
1509 DGA_IDirectDrawSurface4_Unlock,
1510 IDirectDrawSurface4_UpdateOverlay,
1511 IDirectDrawSurface4_UpdateOverlayDisplay,
1512 IDirectDrawSurface4_UpdateOverlayZOrder,
1513 IDirectDrawSurface4_GetDDInterface,
1514 IDirectDrawSurface4_PageLock,
1515 IDirectDrawSurface4_PageUnlock,
1516 IDirectDrawSurface4_SetSurfaceDesc,
1517 IDirectDrawSurface4_SetPrivateData,
1518 IDirectDrawSurface4_GetPrivateData,
1519 IDirectDrawSurface4_FreePrivateData,
1520 IDirectDrawSurface4_GetUniquenessValue,
1521 IDirectDrawSurface4_ChangeUniquenessValue
1524 static struct IDirectDrawSurface4_VTable xlib_dds4vt = {
1525 IDirectDrawSurface4_QueryInterface,
1526 IDirectDrawSurface4_AddRef,
1527 Xlib_IDirectDrawSurface4_Release,
1528 IDirectDrawSurface4_AddAttachedSurface,
1529 IDirectDrawSurface4_AddOverlayDirtyRect,
1530 IDirectDrawSurface4_Blt,
1531 IDirectDrawSurface4_BltBatch,
1532 IDirectDrawSurface4_BltFast,
1533 IDirectDrawSurface4_DeleteAttachedSurface,
1534 IDirectDrawSurface4_EnumAttachedSurfaces,
1535 IDirectDrawSurface4_EnumOverlayZOrders,
1536 Xlib_IDirectDrawSurface4_Flip,
1537 IDirectDrawSurface4_GetAttachedSurface,
1538 IDirectDrawSurface4_GetBltStatus,
1539 IDirectDrawSurface4_GetCaps,
1540 IDirectDrawSurface4_GetClipper,
1541 IDirectDrawSurface4_GetColorKey,
1542 IDirectDrawSurface4_GetDC,
1543 IDirectDrawSurface4_GetFlipStatus,
1544 IDirectDrawSurface4_GetOverlayPosition,
1545 IDirectDrawSurface4_GetPalette,
1546 IDirectDrawSurface4_GetPixelFormat,
1547 IDirectDrawSurface4_GetSurfaceDesc,
1548 IDirectDrawSurface4_Initialize,
1549 IDirectDrawSurface4_IsLost,
1550 IDirectDrawSurface4_Lock,
1551 IDirectDrawSurface4_ReleaseDC,
1552 IDirectDrawSurface4_Restore,
1553 IDirectDrawSurface4_SetClipper,
1554 IDirectDrawSurface4_SetColorKey,
1555 IDirectDrawSurface4_SetOverlayPosition,
1556 Xlib_IDirectDrawSurface4_SetPalette,
1557 Xlib_IDirectDrawSurface4_Unlock,
1558 IDirectDrawSurface4_UpdateOverlay,
1559 IDirectDrawSurface4_UpdateOverlayDisplay,
1560 IDirectDrawSurface4_UpdateOverlayZOrder,
1561 IDirectDrawSurface4_GetDDInterface,
1562 IDirectDrawSurface4_PageLock,
1563 IDirectDrawSurface4_PageUnlock,
1564 IDirectDrawSurface4_SetSurfaceDesc,
1565 IDirectDrawSurface4_SetPrivateData,
1566 IDirectDrawSurface4_GetPrivateData,
1567 IDirectDrawSurface4_FreePrivateData,
1568 IDirectDrawSurface4_GetUniquenessValue,
1569 IDirectDrawSurface4_ChangeUniquenessValue
1572 /******************************************************************************
1573 * DirectDrawCreateClipper (DDRAW.7)
1575 HRESULT WINAPI DirectDrawCreateClipper( DWORD dwFlags,
1576 LPDIRECTDRAWCLIPPER *lplpDDClipper,
1577 LPUNKNOWN pUnkOuter)
1579 TRACE(ddraw, "(%08lx,%p,%p)\n", dwFlags, lplpDDClipper, pUnkOuter);
1581 *lplpDDClipper = (LPDIRECTDRAWCLIPPER)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawClipper));
1582 (*lplpDDClipper)->lpvtbl = &ddclipvt;
1583 (*lplpDDClipper)->ref = 1;
1588 /******************************************************************************
1589 * IDirectDrawClipper
1591 static HRESULT WINAPI IDirectDrawClipper_SetHwnd(
1592 LPDIRECTDRAWCLIPPER this,DWORD x,HWND32 hwnd
1594 FIXME(ddraw,"(%p)->SetHwnd(0x%08lx,0x%08lx),stub!\n",this,x,(DWORD)hwnd);
1598 static ULONG WINAPI IDirectDrawClipper_Release(LPDIRECTDRAWCLIPPER this) {
1599 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1604 HeapFree(GetProcessHeap(),0,this);
1608 static HRESULT WINAPI IDirectDrawClipper_GetClipList(
1609 LPDIRECTDRAWCLIPPER this,LPRECT32 rects,LPRGNDATA lprgn,LPDWORD hmm
1611 FIXME(ddraw,"(%p,%p,%p,%p),stub!\n",this,rects,lprgn,hmm);
1616 static HRESULT WINAPI IDirectDrawClipper_SetClipList(
1617 LPDIRECTDRAWCLIPPER this,LPRGNDATA lprgn,DWORD hmm
1619 FIXME(ddraw,"(%p,%p,%ld),stub!\n",this,lprgn,hmm);
1623 static HRESULT WINAPI IDirectDrawClipper_QueryInterface(
1624 LPDIRECTDRAWCLIPPER this,
1628 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,riid,ppvObj);
1629 return OLE_E_ENUM_NOMORE;
1632 static ULONG WINAPI IDirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER this )
1634 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1635 return ++(this->ref);
1638 static HRESULT WINAPI IDirectDrawClipper_GetHWnd(
1639 LPDIRECTDRAWCLIPPER this,
1642 FIXME(ddraw,"(%p)->(%p),stub!\n",this,HWndPtr);
1646 static HRESULT WINAPI IDirectDrawClipper_Initialize(
1647 LPDIRECTDRAWCLIPPER this,
1651 FIXME(ddraw,"(%p)->(%p,0x%08lx),stub!\n",this,lpDD,dwFlags);
1655 static HRESULT WINAPI IDirectDrawClipper_IsClipListChanged(
1656 LPDIRECTDRAWCLIPPER this,
1657 BOOL32* lpbChanged )
1659 FIXME(ddraw,"(%p)->(%p),stub!\n",this,lpbChanged);
1663 static struct IDirectDrawClipper_VTable ddclipvt = {
1664 IDirectDrawClipper_QueryInterface,
1665 IDirectDrawClipper_AddRef,
1666 IDirectDrawClipper_Release,
1667 IDirectDrawClipper_GetClipList,
1668 IDirectDrawClipper_GetHWnd,
1669 IDirectDrawClipper_Initialize,
1670 IDirectDrawClipper_IsClipListChanged,
1671 IDirectDrawClipper_SetClipList,
1672 IDirectDrawClipper_SetHwnd
1676 /******************************************************************************
1677 * IDirectDrawPalette
1679 static HRESULT WINAPI IDirectDrawPalette_GetEntries(
1680 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
1684 TRACE(ddraw,"(%p)->GetEntries(%08lx,%ld,%ld,%p)\n",
1685 this,x,start,count,palent);
1687 if (!this->cm) /* should not happen */ {
1688 FIXME(ddraw,"app tried to read colormap for non-palettized mode\n");
1689 return DDERR_GENERIC;
1691 for (i=0;i<count;i++) {
1692 palent[i].peRed = this->palents[start+i].peRed;
1693 palent[i].peBlue = this->palents[start+i].peBlue;
1694 palent[i].peGreen = this->palents[start+i].peGreen;
1695 palent[i].peFlags = this->palents[start+i].peFlags;
1701 static HRESULT WINAPI Xlib_IDirectDrawPalette_SetEntries(
1702 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
1707 TRACE(ddraw,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1708 this,x,start,count,palent
1710 for (i=0;i<count;i++) {
1711 xc.red = palent[i].peRed<<8;
1712 xc.blue = palent[i].peBlue<<8;
1713 xc.green = palent[i].peGreen<<8;
1714 xc.flags = DoRed|DoBlue|DoGreen;
1718 TSXStoreColor(display,this->cm,&xc);
1720 this->palents[start+i].peRed = palent[i].peRed;
1721 this->palents[start+i].peBlue = palent[i].peBlue;
1722 this->palents[start+i].peGreen = palent[i].peGreen;
1723 this->palents[start+i].peFlags = palent[i].peFlags;
1726 /* Now, if we are in 'depth conversion mode', update the screen palette */
1727 if (this->ddraw->d.depth != this->ddraw->d.screen_depth) {
1730 switch (this->ddraw->d.screen_depth) {
1732 unsigned short *screen_palette = (unsigned short *) this->screen_palents;
1734 for (i = 0; i < count; i++) {
1735 screen_palette[start + i] = (((((unsigned short) palent[i].peRed) & 0xF8) << 8) |
1736 ((((unsigned short) palent[i].peBlue) & 0xF8) >> 3) |
1737 ((((unsigned short) palent[i].peGreen) & 0xFC) << 3));
1742 ERR(ddraw, "Memory corruption !\n");
1747 if (!this->cm) /* should not happen */ {
1752 static HRESULT WINAPI DGA_IDirectDrawPalette_SetEntries(
1753 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
1755 #ifdef HAVE_LIBXXF86DGA
1760 TRACE(ddraw,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1761 this,x,start,count,palent
1763 if (!this->cm) /* should not happen */ {
1764 FIXME(ddraw,"app tried to set colormap in non-palettized mode\n");
1765 return DDERR_GENERIC;
1767 /* FIXME: free colorcells instead of freeing whole map */
1769 this->cm = TSXCopyColormapAndFree(display,this->cm);
1770 TSXFreeColormap(display,cm);
1772 for (i=0;i<count;i++) {
1773 xc.red = palent[i].peRed<<8;
1774 xc.blue = palent[i].peBlue<<8;
1775 xc.green = palent[i].peGreen<<8;
1776 xc.flags = DoRed|DoBlue|DoGreen;
1779 TSXStoreColor(display,this->cm,&xc);
1781 this->palents[start+i].peRed = palent[i].peRed;
1782 this->palents[start+i].peBlue = palent[i].peBlue;
1783 this->palents[start+i].peGreen = palent[i].peGreen;
1784 this->palents[start+i].peFlags = palent[i].peFlags;
1786 TSXF86DGAInstallColormap(display,DefaultScreen(display),this->cm);
1788 #else /* defined(HAVE_LIBXXF86DGA) */
1789 return E_UNEXPECTED;
1790 #endif /* defined(HAVE_LIBXXF86DGA) */
1793 static ULONG WINAPI IDirectDrawPalette_Release(LPDIRECTDRAWPALETTE this) {
1794 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1795 if (!--(this->ref)) {
1797 TSXFreeColormap(display,this->cm);
1800 HeapFree(GetProcessHeap(),0,this);
1806 static ULONG WINAPI IDirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE this) {
1808 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1809 return ++(this->ref);
1812 static HRESULT WINAPI IDirectDrawPalette_Initialize(
1813 LPDIRECTDRAWPALETTE this,LPDIRECTDRAW ddraw,DWORD x,LPPALETTEENTRY palent
1815 TRACE(ddraw,"(%p)->(%p,%ld,%p)\n", this, ddraw, x, palent);
1817 return DDERR_ALREADYINITIALIZED;
1820 static HRESULT WINAPI IDirectDrawPalette_GetCaps(
1821 LPDIRECTDRAWPALETTE this, LPDWORD lpdwCaps )
1823 FIXME( ddraw, "(%p)->(%p) stub.\n", this, lpdwCaps );
1827 static HRESULT WINAPI IDirectDrawPalette_QueryInterface(
1828 LPDIRECTDRAWPALETTE this,REFIID refiid,LPVOID *obj )
1832 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1833 FIXME(ddraw,"(%p)->(%s,%p) stub.\n",this,xrefiid,obj);
1838 static struct IDirectDrawPalette_VTable dga_ddpalvt = {
1839 IDirectDrawPalette_QueryInterface,
1840 IDirectDrawPalette_AddRef,
1841 IDirectDrawPalette_Release,
1842 IDirectDrawPalette_GetCaps,
1843 IDirectDrawPalette_GetEntries,
1844 IDirectDrawPalette_Initialize,
1845 DGA_IDirectDrawPalette_SetEntries
1848 static struct IDirectDrawPalette_VTable xlib_ddpalvt = {
1849 IDirectDrawPalette_QueryInterface,
1850 IDirectDrawPalette_AddRef,
1851 IDirectDrawPalette_Release,
1852 IDirectDrawPalette_GetCaps,
1853 IDirectDrawPalette_GetEntries,
1854 IDirectDrawPalette_Initialize,
1855 Xlib_IDirectDrawPalette_SetEntries
1858 /*******************************************************************************
1861 static HRESULT WINAPI IDirect3D_QueryInterface(
1862 LPDIRECT3D this,REFIID refiid,LPVOID *obj
1864 /* FIXME: Not sure if this is correct */
1867 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1868 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
1869 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
1871 this->lpvtbl->fnAddRef(this);
1873 TRACE(ddraw, " Creating IUnknown interface (%p)\n", *obj);
1877 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
1880 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1882 d3d->ddraw = (LPDIRECTDRAW)this;
1883 this->lpvtbl->fnAddRef(this);
1884 d3d->lpvtbl = &d3dvt;
1887 TRACE(ddraw, " Creating IDirect3D interface (%p)\n", *obj);
1891 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D2))) {
1894 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1896 d3d->ddraw = (LPDIRECTDRAW)this;
1897 this->lpvtbl->fnAddRef(this);
1898 d3d->lpvtbl = &d3d2vt;
1901 TRACE(ddraw, " Creating IDirect3D2 interface (%p)\n", *obj);
1905 FIXME(ddraw,"(%p):interface for IID %s NOT found!\n",this,xrefiid);
1906 return OLE_E_ENUM_NOMORE;
1909 static ULONG WINAPI IDirect3D_AddRef(LPDIRECT3D this) {
1910 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1912 return ++(this->ref);
1915 static ULONG WINAPI IDirect3D_Release(LPDIRECT3D this)
1917 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1919 if (!--(this->ref)) {
1920 this->ddraw->lpvtbl->fnRelease(this->ddraw);
1921 HeapFree(GetProcessHeap(),0,this);
1927 static HRESULT WINAPI IDirect3D_Initialize(
1928 LPDIRECT3D this, REFIID refiid )
1930 /* FIXME: Not sure if this is correct */
1933 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1934 FIXME(ddraw,"(%p)->(%s):stub.\n",this,xrefiid);
1936 return DDERR_ALREADYINITIALIZED;
1939 static HRESULT WINAPI IDirect3D_EnumDevices(LPDIRECT3D this,
1940 LPD3DENUMDEVICESCALLBACK cb,
1942 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,cb,context);
1944 /* Call functions defined in d3ddevices.c */
1945 if (d3d_OpenGL_dx3(cb, context))
1951 static HRESULT WINAPI IDirect3D_CreateLight(LPDIRECT3D this,
1952 LPDIRECT3DLIGHT *lplight,
1955 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lplight, lpunk);
1957 /* Call the creation function that is located in d3dlight.c */
1958 *lplight = d3dlight_create_dx3(this);
1963 static HRESULT WINAPI IDirect3D_CreateMaterial(LPDIRECT3D this,
1964 LPDIRECT3DMATERIAL *lpmaterial,
1967 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpmaterial, lpunk);
1969 /* Call the creation function that is located in d3dviewport.c */
1970 *lpmaterial = d3dmaterial_create(this);
1975 static HRESULT WINAPI IDirect3D_CreateViewport(LPDIRECT3D this,
1976 LPDIRECT3DVIEWPORT *lpviewport,
1979 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpviewport, lpunk);
1981 /* Call the creation function that is located in d3dviewport.c */
1982 *lpviewport = d3dviewport_create(this);
1987 static HRESULT WINAPI IDirect3D_FindDevice(LPDIRECT3D this,
1988 LPD3DFINDDEVICESEARCH lpfinddevsrc,
1989 LPD3DFINDDEVICERESULT lpfinddevrst)
1991 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpfinddevsrc, lpfinddevrst);
1996 static struct IDirect3D_VTable d3dvt = {
1997 IDirect3D_QueryInterface,
2000 IDirect3D_Initialize,
2001 IDirect3D_EnumDevices,
2002 IDirect3D_CreateLight,
2003 IDirect3D_CreateMaterial,
2004 IDirect3D_CreateViewport,
2005 IDirect3D_FindDevice
2008 /*******************************************************************************
2011 static HRESULT WINAPI IDirect3D2_QueryInterface(
2012 LPDIRECT3D2 this,REFIID refiid,LPVOID *obj) {
2013 /* For the moment, we use the same function as in IDirect3D */
2014 TRACE(ddraw, "Calling IDirect3D enumerating function.\n");
2016 return IDirect3D_QueryInterface((LPDIRECT3D) this, refiid, obj);
2019 static ULONG WINAPI IDirect3D2_AddRef(LPDIRECT3D2 this) {
2020 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
2022 return ++(this->ref);
2025 static ULONG WINAPI IDirect3D2_Release(LPDIRECT3D2 this) {
2026 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
2028 if (!--(this->ref)) {
2029 this->ddraw->lpvtbl->fnRelease(this->ddraw);
2030 HeapFree(GetProcessHeap(),0,this);
2036 static HRESULT WINAPI IDirect3D2_EnumDevices(
2037 LPDIRECT3D2 this,LPD3DENUMDEVICESCALLBACK cb, LPVOID context
2039 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,cb,context);
2041 /* Call functions defined in d3ddevices.c */
2042 if (d3d_OpenGL(cb, context))
2048 static HRESULT WINAPI IDirect3D2_CreateLight(LPDIRECT3D2 this,
2049 LPDIRECT3DLIGHT *lplight,
2052 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lplight, lpunk);
2054 /* Call the creation function that is located in d3dlight.c */
2055 *lplight = d3dlight_create(this);
2060 static HRESULT WINAPI IDirect3D2_CreateMaterial(LPDIRECT3D2 this,
2061 LPDIRECT3DMATERIAL2 *lpmaterial,
2064 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpmaterial, lpunk);
2066 /* Call the creation function that is located in d3dviewport.c */
2067 *lpmaterial = d3dmaterial2_create(this);
2072 static HRESULT WINAPI IDirect3D2_CreateViewport(LPDIRECT3D2 this,
2073 LPDIRECT3DVIEWPORT2 *lpviewport,
2076 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpviewport, lpunk);
2078 /* Call the creation function that is located in d3dviewport.c */
2079 *lpviewport = d3dviewport2_create(this);
2084 static HRESULT WINAPI IDirect3D2_FindDevice(LPDIRECT3D2 this,
2085 LPD3DFINDDEVICESEARCH lpfinddevsrc,
2086 LPD3DFINDDEVICERESULT lpfinddevrst)
2088 TRACE(ddraw, "(%p)->(%p,%p): stub\n", this, lpfinddevsrc, lpfinddevrst);
2093 static HRESULT WINAPI IDirect3D2_CreateDevice(LPDIRECT3D2 this,
2095 LPDIRECTDRAWSURFACE surface,
2096 LPDIRECT3DDEVICE2 *device)
2100 WINE_StringFromCLSID(rguid,xbuf);
2101 FIXME(ddraw,"(%p)->(%s,%p,%p): stub\n",this,xbuf,surface,device);
2103 if (is_OpenGL(rguid, surface, device, this)) {
2104 this->lpvtbl->fnAddRef(this);
2108 return DDERR_INVALIDPARAMS;
2111 static struct IDirect3D2_VTable d3d2vt = {
2112 IDirect3D2_QueryInterface,
2115 IDirect3D2_EnumDevices,
2116 IDirect3D2_CreateLight,
2117 IDirect3D2_CreateMaterial,
2118 IDirect3D2_CreateViewport,
2119 IDirect3D2_FindDevice,
2120 IDirect3D2_CreateDevice
2123 /*******************************************************************************
2127 /* Used in conjunction with cbWndExtra for storage of the this ptr for the window.
2128 * Please adjust allocation in Xlib_DirectDrawCreate if you store more data here.
2130 static INT32 ddrawXlibThisOffset = 0;
2132 static HRESULT common_off_screen_CreateSurface(LPDIRECTDRAW2 this,
2133 LPDDSURFACEDESC lpddsd,
2134 LPDIRECTDRAWSURFACE lpdsf)
2138 /* The surface was already allocated when entering in this function */
2139 TRACE(ddraw,"using system memory for a surface (%p)\n", lpdsf);
2141 if (lpddsd->dwFlags & DDSD_ZBUFFERBITDEPTH) {
2142 /* This is a Z Buffer */
2143 TRACE(ddraw, "Creating Z-Buffer of %ld bit depth\n", lpddsd->x.dwZBufferBitDepth);
2144 bpp = lpddsd->x.dwZBufferBitDepth / 8;
2146 /* This is a standard image */
2147 if (!(lpddsd->dwFlags & DDSD_PIXELFORMAT)) {
2148 /* No pixel format => use DirectDraw's format */
2149 _getpixelformat(this,&(lpddsd->ddpfPixelFormat));
2150 lpddsd->dwFlags |= DDSD_PIXELFORMAT;
2152 /* To check what the program wants */
2153 if (TRACE_ON(ddraw)) {
2154 _dump_pixelformat(&(lpddsd->ddpfPixelFormat));
2158 if (lpddsd->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) {
2161 bpp = lpddsd->ddpfPixelFormat.x.dwRGBBitCount / 8;
2165 /* Copy the surface description */
2166 lpdsf->s.surface_desc = *lpddsd;
2168 lpdsf->s.surface_desc.dwFlags |= DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_LPSURFACE;
2169 lpdsf->s.surface_desc.y.lpSurface = (LPBYTE)HeapAlloc(GetProcessHeap(),0,lpddsd->dwWidth * lpddsd->dwHeight * bpp);
2170 lpdsf->s.surface_desc.lPitch = lpddsd->dwWidth * bpp;
2175 static HRESULT WINAPI DGA_IDirectDraw2_CreateSurface(
2176 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsd,LPDIRECTDRAWSURFACE *lpdsf,IUnknown *lpunk
2178 #ifdef HAVE_LIBXXF86DGA
2181 TRACE(ddraw, "(%p)->(%p,%p,%p)\n",this,lpddsd,lpdsf,lpunk);
2182 if (TRACE_ON(ddraw)) {
2183 DUMP("[w=%ld,h=%ld,flags ",lpddsd->dwWidth,lpddsd->dwHeight);
2184 _dump_DDSD(lpddsd->dwFlags);
2185 fprintf(stderr,"caps ");
2186 _dump_DDSCAPS(lpddsd->ddsCaps.dwCaps);
2187 fprintf(stderr,"]\n");
2190 *lpdsf = (LPDIRECTDRAWSURFACE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface));
2191 this->lpvtbl->fnAddRef(this);
2194 (*lpdsf)->lpvtbl = (LPDIRECTDRAWSURFACE_VTABLE)&dga_dds4vt;
2195 (*lpdsf)->s.ddraw = this;
2196 (*lpdsf)->s.palette = NULL;
2197 (*lpdsf)->t.dga.fb_height = -1; /* This is to have non-on screen surfaces freed */
2199 if (!(lpddsd->dwFlags & DDSD_WIDTH))
2200 lpddsd->dwWidth = this->d.width;
2201 if (!(lpddsd->dwFlags & DDSD_HEIGHT))
2202 lpddsd->dwHeight = this->d.height;
2204 /* Check if this a 'primary surface' or not */
2205 if ((lpddsd->dwFlags & DDSD_CAPS) &&
2206 (lpddsd->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) {
2208 /* This is THE primary surface => there is DGA-specific code */
2209 /* First, store the surface description */
2210 (*lpdsf)->s.surface_desc = *lpddsd;
2212 /* Find a viewport */
2214 if (!(this->e.dga.vpmask & (1<<i)))
2216 TRACE(ddraw,"using viewport %d for a primary surface\n",i);
2217 /* if i == 32 or maximum ... return error */
2218 this->e.dga.vpmask|=(1<<i);
2219 (*lpdsf)->s.surface_desc.y.lpSurface =
2220 this->e.dga.fb_addr+((i*this->e.dga.fb_height)*this->e.dga.fb_width*this->d.depth/8);
2221 (*lpdsf)->t.dga.fb_height = i*this->e.dga.fb_height;
2222 (*lpdsf)->s.surface_desc.lPitch = this->e.dga.fb_width*this->d.depth/8;
2223 lpddsd->lPitch = (*lpdsf)->s.surface_desc.lPitch;
2225 /* Add flags if there were not present */
2226 (*lpdsf)->s.surface_desc.dwFlags |= DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_LPSURFACE;
2227 (*lpdsf)->s.surface_desc.dwWidth = this->d.width;
2228 (*lpdsf)->s.surface_desc.dwHeight = this->d.height;
2229 TRACE(ddraw,"primary surface: dwWidth=%ld, dwHeight=%ld, lPitch=%ld\n",this->d.width,this->d.height,lpddsd->lPitch);
2230 /* We put our surface always in video memory */
2231 (*lpdsf)->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_VISIBLE|DDSCAPS_VIDEOMEMORY;
2232 _getpixelformat(this,&((*lpdsf)->s.surface_desc.ddpfPixelFormat));
2233 (*lpdsf)->s.backbuffer = NULL;
2235 if (lpddsd->dwFlags & DDSD_BACKBUFFERCOUNT) {
2236 LPDIRECTDRAWSURFACE4 back;
2238 if (lpddsd->dwBackBufferCount>1)
2239 FIXME(ddraw,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd->dwBackBufferCount);
2241 (*lpdsf)->s.backbuffer = back =
2242 (LPDIRECTDRAWSURFACE4)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface4));
2243 this->lpvtbl->fnAddRef(this);
2245 back->lpvtbl = (LPDIRECTDRAWSURFACE4_VTABLE)&dga_dds4vt;
2247 if (!(this->e.dga.vpmask & (1<<i)))
2249 TRACE(ddraw,"using viewport %d for backbuffer\n",i);
2250 /* if i == 32 or maximum ... return error */
2251 this->e.dga.vpmask|=(1<<i);
2252 back->t.dga.fb_height = i*this->e.dga.fb_height;
2254 /* Copy the surface description from the front buffer */
2255 back->s.surface_desc = (*lpdsf)->s.surface_desc;
2256 /* Change the parameters that are not the same */
2257 back->s.surface_desc.y.lpSurface = this->e.dga.fb_addr+
2258 ((i*this->e.dga.fb_height)*this->e.dga.fb_width*this->d.depth/8);
2259 back->s.ddraw = this;
2260 back->s.backbuffer = NULL; /* does not have a backbuffer, it is
2263 /* Add relevant info to front and back buffers */
2264 (*lpdsf)->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
2265 back->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
2266 back->s.surface_desc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
2267 back->s.surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_VISIBLE;
2268 back->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
2271 /* There is no DGA-specific code here...
2272 Go to the common surface creation function */
2273 return common_off_screen_CreateSurface(this, lpddsd, *lpdsf);
2277 #else /* defined(HAVE_LIBXXF86DGA) */
2278 return E_UNEXPECTED;
2279 #endif /* defined(HAVE_LIBXXF86DGA) */
2282 static XImage *create_ximage(LPDIRECTDRAW2 this, LPDIRECTDRAWSURFACE4 lpdsf) {
2286 #ifdef HAVE_LIBXXSHM
2287 if (this->e.xlib.xshm_active) {
2288 img = TSXShmCreateImage(display,
2289 DefaultVisualOfScreen(screen),
2290 this->d.screen_depth,
2293 &(lpdsf->t.xlib.shminfo),
2294 lpdsf->s.surface_desc.dwWidth,
2295 lpdsf->s.surface_desc.dwHeight);
2300 lpdsf->t.xlib.shminfo.shmid = shmget( IPC_PRIVATE, img->bytes_per_line * img->height, IPC_CREAT|0777 );
2301 if (lpdsf->t.xlib.shminfo.shmid < 0) {
2302 TSXDestroyImage(img);
2306 lpdsf->t.xlib.shminfo.shmaddr = img->data = (char*)shmat(lpdsf->t.xlib.shminfo.shmid, 0, 0);
2308 if (img->data == (char *) -1) {
2309 TSXDestroyImage(img);
2310 shmctl(lpdsf->t.xlib.shminfo.shmid, IPC_RMID, 0);
2313 lpdsf->t.xlib.shminfo.readOnly = False;
2315 TSXShmAttach(display, &(lpdsf->t.xlib.shminfo));
2316 TSXSync(display, False);
2318 shmctl(lpdsf->t.xlib.shminfo.shmid, IPC_RMID, 0);
2320 if (this->d.depth != this->d.screen_depth) {
2321 lpdsf->s.surface_desc.y.lpSurface = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
2322 lpdsf->s.surface_desc.dwWidth *
2323 lpdsf->s.surface_desc.dwHeight *
2324 (this->d.depth / 8));
2326 lpdsf->s.surface_desc.y.lpSurface = img->data;
2330 /* Allocate surface memory */
2331 lpdsf->s.surface_desc.y.lpSurface = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
2332 lpdsf->s.surface_desc.dwWidth *
2333 lpdsf->s.surface_desc.dwHeight *
2334 (this->d.depth / 8));
2336 if (this->d.depth != this->d.screen_depth) {
2337 img_data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
2338 lpdsf->s.surface_desc.dwWidth *
2339 lpdsf->s.surface_desc.dwHeight *
2340 (this->d.screen_depth / 8));
2342 img_data = lpdsf->s.surface_desc.y.lpSurface;
2345 /* In this case, create an XImage */
2347 TSXCreateImage(display,
2348 DefaultVisualOfScreen(screen),
2349 this->d.screen_depth,
2353 lpdsf->s.surface_desc.dwWidth,
2354 lpdsf->s.surface_desc.dwHeight,
2356 lpdsf->s.surface_desc.dwWidth * (this->d.screen_depth / 8)
2359 #ifdef HAVE_LIBXXSHM
2362 if (this->d.depth != this->d.screen_depth) {
2363 lpdsf->s.surface_desc.lPitch = (this->d.depth / 8) * lpdsf->s.surface_desc.dwWidth;
2365 lpdsf->s.surface_desc.lPitch = img->bytes_per_line;
2371 static HRESULT WINAPI Xlib_IDirectDraw2_CreateSurface(
2372 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsd,LPDIRECTDRAWSURFACE *lpdsf,IUnknown *lpunk
2374 TRACE(ddraw, "(%p)->CreateSurface(%p,%p,%p)\n",
2375 this,lpddsd,lpdsf,lpunk);
2377 if (TRACE_ON(ddraw)) {
2378 fprintf(stderr,"[w=%ld,h=%ld,flags ",lpddsd->dwWidth,lpddsd->dwHeight);
2379 _dump_DDSD(lpddsd->dwFlags);
2380 fprintf(stderr,"caps ");
2381 _dump_DDSCAPS(lpddsd->ddsCaps.dwCaps);
2382 fprintf(stderr,"]\n");
2385 *lpdsf = (LPDIRECTDRAWSURFACE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface));
2387 this->lpvtbl->fnAddRef(this);
2388 (*lpdsf)->s.ddraw = this;
2390 (*lpdsf)->lpvtbl = (LPDIRECTDRAWSURFACE_VTABLE)&xlib_dds4vt;
2391 (*lpdsf)->s.palette = NULL;
2392 (*lpdsf)->t.xlib.image = NULL; /* This is for off-screen buffers */
2394 if (!(lpddsd->dwFlags & DDSD_WIDTH))
2395 lpddsd->dwWidth = this->d.width;
2396 if (!(lpddsd->dwFlags & DDSD_HEIGHT))
2397 lpddsd->dwHeight = this->d.height;
2399 /* Check if this a 'primary surface' or not */
2400 if ((lpddsd->dwFlags & DDSD_CAPS) &&
2401 (lpddsd->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) {
2404 TRACE(ddraw,"using standard XImage for a primary surface (%p)\n", *lpdsf);
2406 /* First, store the surface description */
2407 (*lpdsf)->s.surface_desc = *lpddsd;
2409 /* Create the XImage */
2410 img = create_ximage(this, (LPDIRECTDRAWSURFACE4) *lpdsf);
2412 return DDERR_OUTOFMEMORY;
2413 (*lpdsf)->t.xlib.image = img;
2415 /* Add flags if there were not present */
2416 (*lpdsf)->s.surface_desc.dwFlags |= DDSD_WIDTH|DDSD_HEIGHT|DDSD_PITCH|DDSD_LPSURFACE;
2417 (*lpdsf)->s.surface_desc.dwWidth = this->d.width;
2418 (*lpdsf)->s.surface_desc.dwHeight = this->d.height;
2419 (*lpdsf)->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_VISIBLE|DDSCAPS_VIDEOMEMORY;
2420 _getpixelformat(this,&((*lpdsf)->s.surface_desc.ddpfPixelFormat));
2421 (*lpdsf)->s.backbuffer = NULL;
2423 /* Check for backbuffers */
2424 if (lpddsd->dwFlags & DDSD_BACKBUFFERCOUNT) {
2425 LPDIRECTDRAWSURFACE4 back;
2428 if (lpddsd->dwBackBufferCount>1)
2429 FIXME(ddraw,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd->dwBackBufferCount);
2431 (*lpdsf)->s.backbuffer = back =
2432 (LPDIRECTDRAWSURFACE4)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface4));
2434 TRACE(ddraw,"allocated back-buffer (%p)\n", back);
2436 this->lpvtbl->fnAddRef(this);
2437 back->s.ddraw = this;
2440 back->lpvtbl = (LPDIRECTDRAWSURFACE4_VTABLE)&xlib_dds4vt;
2441 /* Copy the surface description from the front buffer */
2442 back->s.surface_desc = (*lpdsf)->s.surface_desc;
2444 /* Create the XImage */
2445 img = create_ximage(this, back);
2447 return DDERR_OUTOFMEMORY;
2448 back->t.xlib.image = img;
2450 back->s.backbuffer = NULL; /* does not have a backbuffer, it is
2453 /* Add relevant info to front and back buffers */
2454 (*lpdsf)->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
2455 back->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
2456 back->s.surface_desc.dwFlags &= ~DDSD_BACKBUFFERCOUNT;
2457 back->s.surface_desc.ddsCaps.dwCaps &= ~DDSCAPS_VISIBLE;
2458 back->s.surface_desc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
2461 /* There is no Xlib-specific code here...
2462 Go to the common surface creation function */
2463 return common_off_screen_CreateSurface(this, lpddsd, *lpdsf);
2469 static HRESULT WINAPI IDirectDraw2_DuplicateSurface(
2470 LPDIRECTDRAW2 this,LPDIRECTDRAWSURFACE src,LPDIRECTDRAWSURFACE *dst
2472 FIXME(ddraw,"(%p)->(%p,%p) simply copies\n",this,src,dst);
2473 *dst = src; /* FIXME */
2478 * The Xlib Implementation tries to use the passed hwnd as drawing window,
2479 * even when the approbiate bitmasks are not specified.
2481 static HRESULT WINAPI IDirectDraw2_SetCooperativeLevel(
2482 LPDIRECTDRAW2 this,HWND32 hwnd,DWORD cooplevel
2489 FE(DDSCL_FULLSCREEN)
2490 FE(DDSCL_ALLOWREBOOT)
2491 FE(DDSCL_NOWINDOWCHANGES)
2493 FE(DDSCL_ALLOWMODEX)
2495 FE(DDSCL_SETFOCUSWINDOW)
2496 FE(DDSCL_SETDEVICEWINDOW)
2497 FE(DDSCL_CREATEDEVICEWINDOW)
2500 FIXME(ddraw,"(%p)->(%08lx,%08lx)\n",this,(DWORD)hwnd,cooplevel);
2501 if(TRACE_ON(ddraw)){
2502 dbg_decl_str(ddraw, 512);
2503 for (i=0;i<sizeof(flagmap)/sizeof(flagmap[0]);i++)
2504 if (flagmap[i].mask & cooplevel)
2505 dsprintf(ddraw, "%s ", flagmap[i].name);
2506 TRACE(ddraw," cooperative level %s\n", dbg_str(ddraw));
2508 this->d.mainWindow = hwnd;
2510 /* This will be overwritten in the case of Full Screen mode.
2511 Windowed games could work with that :-) */
2513 this->d.drawable = ((X11DRV_WND_DATA *) WIN_FindWndPtr(hwnd)->pDriverData)->window;
2518 /* Small helper to either use the cooperative window or create a new
2519 * one (for mouse and keyboard input) and drawing in the Xlib implementation.
2521 static void _common_IDirectDraw_SetDisplayMode(LPDIRECTDRAW this) {
2524 /* Do not destroy the application supplied cooperative window */
2525 if (this->d.window && this->d.window != this->d.mainWindow) {
2526 DestroyWindow32(this->d.window);
2529 /* Sanity check cooperative window before assigning it to drawing. */
2530 if ( IsWindow32(this->d.mainWindow) &&
2531 IsWindowVisible32(this->d.mainWindow)
2533 GetWindowRect32(this->d.mainWindow,&rect);
2534 if (((rect.right-rect.left) >= this->d.width) &&
2535 ((rect.bottom-rect.top) >= this->d.height)
2537 this->d.window = this->d.mainWindow;
2539 /* ... failed, create new one. */
2540 if (!this->d.window) {
2541 this->d.window = CreateWindowEx32A(
2545 WS_VISIBLE|WS_SYSMENU|WS_THICKFRAME,
2554 /*Store THIS with the window. We'll use it in the window procedure*/
2555 SetWindowLong32A(this->d.window,ddrawXlibThisOffset,(LONG)this);
2556 ShowWindow32(this->d.window,TRUE);
2557 UpdateWindow32(this->d.window);
2559 SetFocus32(this->d.window);
2562 static HRESULT WINAPI DGA_IDirectDraw_SetDisplayMode(
2563 LPDIRECTDRAW this,DWORD width,DWORD height,DWORD depth
2565 #ifdef HAVE_LIBXXF86DGA
2566 int i,*depths,depcount,mode_count;
2568 TRACE(ddraw, "(%p)->(%ld,%ld,%ld)\n", this, width, height, depth);
2570 /* We hope getting the asked for depth */
2571 this->d.screen_depth = depth;
2573 depths = TSXListDepths(display,DefaultScreen(display),&depcount);
2574 for (i=0;i<depcount;i++)
2575 if (depths[i]==depth)
2578 if (i==depcount) {/* not found */
2579 ERR(ddraw,"(w=%ld,h=%ld,d=%ld), unsupported depth!\n",width,height,depth);
2580 return DDERR_UNSUPPORTEDMODE;
2582 if (this->d.width < width) {
2583 ERR(ddraw,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld\n",width,height,depth,width,this->d.width);
2584 return DDERR_UNSUPPORTEDMODE;
2586 this->d.width = width;
2587 this->d.height = height;
2588 this->d.depth = depth;
2590 /* adjust fb_height, so we don't overlap */
2591 if (this->e.dga.fb_height < height)
2592 this->e.dga.fb_height = height;
2593 _common_IDirectDraw_SetDisplayMode(this);
2595 #ifdef HAVE_LIBXXF86VM
2597 XF86VidModeModeInfo **all_modes, *vidmode = NULL;
2598 XF86VidModeModeLine mod_tmp;
2599 /* int dotclock_tmp; */
2601 /* save original video mode and set fullscreen if available*/
2602 orig_mode = (XF86VidModeModeInfo *) malloc (sizeof(XF86VidModeModeInfo));
2603 TSXF86VidModeGetModeLine(display, DefaultScreen(display), &orig_mode->dotclock, &mod_tmp);
2604 orig_mode->hdisplay = mod_tmp.hdisplay;
2605 orig_mode->hsyncstart = mod_tmp.hsyncstart;
2606 orig_mode->hsyncend = mod_tmp.hsyncend;
2607 orig_mode->htotal = mod_tmp.htotal;
2608 orig_mode->vdisplay = mod_tmp.vdisplay;
2609 orig_mode->vsyncstart = mod_tmp.vsyncstart;
2610 orig_mode->vsyncend = mod_tmp.vsyncend;
2611 orig_mode->vtotal = mod_tmp.vtotal;
2612 orig_mode->flags = mod_tmp.flags;
2613 orig_mode->private = mod_tmp.private;
2615 TSXF86VidModeGetAllModeLines(display,DefaultScreen(display),&mode_count,&all_modes);
2616 for (i=0;i<mode_count;i++)
2618 if (all_modes[i]->hdisplay == width && all_modes[i]->vdisplay == height)
2620 vidmode = (XF86VidModeModeInfo *)malloc(sizeof(XF86VidModeModeInfo));
2621 *vidmode = *(all_modes[i]);
2624 TSXFree(all_modes[i]->private);
2626 for (i++;i<mode_count;i++) TSXFree(all_modes[i]->private);
2630 WARN(ddraw, "Fullscreen mode not available!\n");
2634 TRACE(ddraw,"SwitchToMode(%dx%d)\n",vidmode->hdisplay,vidmode->vdisplay);
2635 TSXF86VidModeSwitchToMode(display, DefaultScreen(display), vidmode);
2636 #if 0 /* This messes up my screen (XF86_Mach64, 3.3.2.3a) for some reason, and should now be unnecessary */
2637 TSXF86VidModeSetViewPort(display, DefaultScreen(display), 0, 0);
2643 /* FIXME: this function OVERWRITES several signal handlers.
2644 * can we save them? and restore them later? In a way that
2645 * it works for the library too?
2647 TSXF86DGADirectVideo(display,DefaultScreen(display),XF86DGADirectGraphics);
2649 TSXF86DGASetViewPort(display,DefaultScreen(display),0,this->e.dga.fb_height);
2651 TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
2654 #ifdef RESTORE_SIGNALS
2655 if (SIGNAL_Reinit) SIGNAL_Reinit();
2658 #else /* defined(HAVE_LIBXXF86DGA) */
2659 return E_UNEXPECTED;
2660 #endif /* defined(HAVE_LIBXXF86DGA) */
2663 static HRESULT WINAPI Xlib_IDirectDraw_SetDisplayMode(
2664 LPDIRECTDRAW this,DWORD width,DWORD height,DWORD depth
2666 int i,*depths,depcount;
2669 TRACE(ddraw, "(%p)->SetDisplayMode(%ld,%ld,%ld)\n",
2670 this, width, height, depth);
2672 /* We hope getting the asked for depth */
2673 this->d.screen_depth = depth;
2675 depths = TSXListDepths(display,DefaultScreen(display),&depcount);
2676 for (i=0;i<depcount;i++)
2677 if (depths[i]==depth)
2679 if (i==depcount) {/* not found */
2680 for (i=0;i<depcount;i++)
2685 sprintf(buf,"SetDisplayMode(w=%ld,h=%ld,d=%ld), unsupported depth!",width,height,depth);
2686 MessageBox32A(0,buf,"WINE DirectDraw",MB_OK|MB_ICONSTOP);
2688 return DDERR_UNSUPPORTEDMODE;
2690 WARN(ddraw, "Warning : running in depth-convertion mode. Should run using a %ld depth for optimal performances.\n", depth);
2691 this->d.screen_depth = 16;
2696 this->d.width = width;
2697 this->d.height = height;
2698 this->d.depth = depth;
2700 _common_IDirectDraw_SetDisplayMode(this);
2702 this->d.paintable = 1;
2703 this->d.drawable = ((X11DRV_WND_DATA *) WIN_FindWndPtr(this->d.window)->pDriverData)->window;
2704 /* We don't have a context for this window. Host off the desktop */
2705 if( !this->d.drawable )
2706 this->d.drawable = ((X11DRV_WND_DATA *) WIN_GetDesktop()->pDriverData)->window;
2710 static HRESULT WINAPI DGA_IDirectDraw2_GetCaps(
2711 LPDIRECTDRAW2 this,LPDDCAPS caps1,LPDDCAPS caps2
2713 #ifdef HAVE_LIBXXF86DGA
2714 TRACE(ddraw,"(%p)->GetCaps(%p,%p)\n",this,caps1,caps2);
2715 caps1->dwVidMemTotal = this->e.dga.fb_memsize;
2716 caps1->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
2717 caps1->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
2719 caps2->dwVidMemTotal = this->e.dga.fb_memsize;
2720 caps2->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
2721 caps2->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
2724 #else /* defined(HAVE_LIBXXF86DGA) */
2725 return E_UNEXPECTED;
2726 #endif /* defined(HAVE_LIBXXF86DGA) */
2729 static void fill_caps(LPDDCAPS caps) {
2730 /* This function tries to fill the capabilities of Wine's DDraw implementation.
2731 Need to be fixed, though.. */
2735 caps->dwSize = sizeof(*caps);
2736 caps->dwCaps = DDCAPS_3D | DDCAPS_ALPHA | DDCAPS_BLT | DDCAPS_BLTSTRETCH | DDCAPS_BLTCOLORFILL | DDCAPS_BLTDEPTHFILL |
2737 DDCAPS_CANBLTSYSMEM | DDCAPS_COLORKEY | DDCAPS_PALETTE | DDCAPS_ZBLTS;
2738 caps->dwCaps2 = DDCAPS2_CERTIFIED | DDCAPS2_NO2DDURING3DSCENE | DDCAPS2_NOPAGELOCKREQUIRED |
2739 DDCAPS2_WIDESURFACES;
2740 caps->dwCKeyCaps = 0xFFFFFFFF; /* Should put real caps here one day... */
2742 caps->dwFXAlphaCaps = 0;
2743 caps->dwPalCaps = DDPCAPS_8BIT | DDPCAPS_ALLOW256;
2745 caps->dwZBufferBitDepths = DDBD_16;
2746 /* I put here 8 Mo so that D3D applications will believe they have enough memory
2747 to put textures in video memory.
2748 BTW, is this only frame buffer memory or also texture memory (for Voodoo boards
2750 caps->dwVidMemTotal = 8192 * 1024;
2751 caps->dwVidMemFree = 8192 * 1024;
2752 /* These are all the supported capabilities of the surfaces */
2753 caps->ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_ALPHA | DDSCAPS_BACKBUFFER | DDSCAPS_COMPLEX | DDSCAPS_FLIP |
2754 DDSCAPS_FRONTBUFFER | DDSCAPS_LOCALVIDMEM | DDSCAPS_MIPMAP | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_OFFSCREENPLAIN |
2755 DDSCAPS_OVERLAY | DDSCAPS_PALETTE | DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY | DDSCAPS_TEXTURE |
2756 DDSCAPS_VIDEOMEMORY | DDSCAPS_VISIBLE | DDSCAPS_ZBUFFER;
2759 static HRESULT WINAPI Xlib_IDirectDraw2_GetCaps(
2760 LPDIRECTDRAW2 this,LPDDCAPS caps1,LPDDCAPS caps2
2762 TRACE(ddraw,"(%p)->GetCaps(%p,%p)\n",this,caps1,caps2);
2764 /* Put the same caps for the two capabilities */
2771 static HRESULT WINAPI IDirectDraw2_CreateClipper(
2772 LPDIRECTDRAW2 this,DWORD x,LPDIRECTDRAWCLIPPER *lpddclip,LPUNKNOWN lpunk
2774 FIXME(ddraw,"(%p)->(%08lx,%p,%p),stub!\n",
2775 this,x,lpddclip,lpunk
2777 *lpddclip = (LPDIRECTDRAWCLIPPER)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawClipper));
2778 (*lpddclip)->ref = 1;
2779 (*lpddclip)->lpvtbl = &ddclipvt;
2783 static HRESULT WINAPI common_IDirectDraw2_CreatePalette(
2784 LPDIRECTDRAW2 this,DWORD dwFlags,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk,int *psize
2788 *lpddpal = (LPDIRECTDRAWPALETTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawPalette));
2789 if (*lpddpal == NULL) return E_OUTOFMEMORY;
2790 (*lpddpal)->ref = 1;
2791 (*lpddpal)->ddraw = (LPDIRECTDRAW)this;
2792 (*lpddpal)->installed = 0;
2794 if (dwFlags & DDPCAPS_1BIT)
2796 else if (dwFlags & DDPCAPS_2BIT)
2798 else if (dwFlags & DDPCAPS_4BIT)
2800 else if (dwFlags & DDPCAPS_8BIT)
2803 ERR(ddraw, "unhandled palette format\n");
2808 /* Now, if we are in 'depth conversion mode', create the screen palette */
2809 if (this->d.depth != this->d.screen_depth) {
2812 switch (this->d.screen_depth) {
2814 unsigned short *screen_palette = (unsigned short *) (*lpddpal)->screen_palents;
2816 for (i = 0; i < size; i++) {
2817 screen_palette[i] = (((((unsigned short) palent[i].peRed) & 0xF8) << 8) |
2818 ((((unsigned short) palent[i].peBlue) & 0xF8) >> 3) |
2819 ((((unsigned short) palent[i].peGreen) & 0xFC) << 3));
2824 ERR(ddraw, "Memory corruption ! (depth=%ld, screen_depth=%ld)\n",this->d.depth,this->d.screen_depth);
2829 memcpy((*lpddpal)->palents, palent, size * sizeof(PALETTEENTRY));
2830 } else if (this->d.depth != this->d.screen_depth) {
2833 switch (this->d.screen_depth) {
2835 unsigned short *screen_palette = (unsigned short *) (*lpddpal)->screen_palents;
2837 for (i = 0; i < size; i++) {
2838 screen_palette[i] = 0xFFFF;
2843 ERR(ddraw, "Memory corruption !\n");
2851 static HRESULT WINAPI DGA_IDirectDraw2_CreatePalette(
2852 LPDIRECTDRAW2 this,DWORD dwFlags,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk
2857 TRACE(ddraw,"(%p)->(%08lx,%p,%p,%p)\n",this,dwFlags,palent,lpddpal,lpunk);
2858 res = common_IDirectDraw2_CreatePalette(this,dwFlags,palent,lpddpal,lpunk,&xsize);
2859 if (res != 0) return res;
2860 (*lpddpal)->lpvtbl = &dga_ddpalvt;
2861 if (this->d.depth<=8) {
2862 (*lpddpal)->cm = TSXCreateColormap(display,DefaultRootWindow(display),DefaultVisualOfScreen(screen),AllocAll);
2864 FIXME(ddraw,"why are we doing CreatePalette in hi/truecolor?\n");
2867 if (((*lpddpal)->cm)&&xsize) {
2868 for (i=0;i<xsize;i++) {
2871 xc.red = (*lpddpal)->palents[i].peRed<<8;
2872 xc.blue = (*lpddpal)->palents[i].peBlue<<8;
2873 xc.green = (*lpddpal)->palents[i].peGreen<<8;
2874 xc.flags = DoRed|DoBlue|DoGreen;
2876 TSXStoreColor(display,(*lpddpal)->cm,&xc);
2882 static HRESULT WINAPI Xlib_IDirectDraw2_CreatePalette(
2883 LPDIRECTDRAW2 this,DWORD dwFlags,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk
2888 TRACE(ddraw,"(%p)->(%08lx,%p,%p,%p)\n",this,dwFlags,palent,lpddpal,lpunk);
2889 res = common_IDirectDraw2_CreatePalette(this,dwFlags,palent,lpddpal,lpunk,&xsize);
2890 if (res != 0) return res;
2891 (*lpddpal)->lpvtbl = &xlib_ddpalvt;
2895 static HRESULT WINAPI DGA_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2 this) {
2896 #ifdef HAVE_LIBXXF86DGA
2897 TRACE(ddraw, "(%p)->()\n",this);
2899 TSXF86DGADirectVideo(display,DefaultScreen(display),0);
2900 #ifdef RESTORE_SIGNALS
2901 if (SIGNAL_Reinit) SIGNAL_Reinit();
2904 #else /* defined(HAVE_LIBXXF86DGA) */
2905 return E_UNEXPECTED;
2909 static HRESULT WINAPI Xlib_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2 this) {
2910 TRACE(ddraw, "(%p)->RestoreDisplayMode()\n", this);
2915 static HRESULT WINAPI IDirectDraw2_WaitForVerticalBlank(
2916 LPDIRECTDRAW2 this,DWORD x,HANDLE32 h
2918 TRACE(ddraw,"(%p)->(0x%08lx,0x%08x)\n",this,x,h);
2922 static ULONG WINAPI IDirectDraw2_AddRef(LPDIRECTDRAW2 this) {
2923 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
2925 return ++(this->ref);
2928 static ULONG WINAPI DGA_IDirectDraw2_Release(LPDIRECTDRAW2 this) {
2929 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
2931 #ifdef HAVE_LIBXXF86DGA
2932 if (!--(this->ref)) {
2933 TSXF86DGADirectVideo(display,DefaultScreen(display),0);
2935 #ifdef HAVE_LIBXXF86VM
2937 TSXF86VidModeSwitchToMode(
2939 DefaultScreen(display),
2941 if (orig_mode->privsize)
2942 TSXFree(orig_mode->private);
2948 #ifdef RESTORE_SIGNALS
2949 if (SIGNAL_Reinit) SIGNAL_Reinit();
2951 HeapFree(GetProcessHeap(),0,this);
2954 #endif /* defined(HAVE_LIBXXF86DGA) */
2958 static ULONG WINAPI Xlib_IDirectDraw2_Release(LPDIRECTDRAW2 this) {
2959 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
2961 if (!--(this->ref)) {
2962 HeapFree(GetProcessHeap(),0,this);
2965 /* FIXME: destroy window ... */
2969 static HRESULT WINAPI DGA_IDirectDraw2_QueryInterface(
2970 LPDIRECTDRAW2 this,REFIID refiid,LPVOID *obj
2974 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
2975 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
2976 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
2978 this->lpvtbl->fnAddRef(this);
2980 TRACE(ddraw, " Creating IUnknown interface (%p)\n", *obj);
2984 if (!memcmp(&IID_IDirectDraw,refiid,sizeof(IID_IDirectDraw))) {
2985 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&dga_ddvt;
2986 this->lpvtbl->fnAddRef(this);
2989 TRACE(ddraw, " Creating IDirectDraw interface (%p)\n", *obj);
2993 if (!memcmp(&IID_IDirectDraw2,refiid,sizeof(IID_IDirectDraw2))) {
2994 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&dga_dd2vt;
2995 this->lpvtbl->fnAddRef(this);
2998 TRACE(ddraw, " Creating IDirectDraw2 interface (%p)\n", *obj);
3002 if (!memcmp(&IID_IDirectDraw4,refiid,sizeof(IID_IDirectDraw4))) {
3003 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&dga_dd4vt;
3004 this->lpvtbl->fnAddRef(this);
3007 TRACE(ddraw, " Creating IDirectDraw4 interface (%p)\n", *obj);
3011 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
3014 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
3016 d3d->ddraw = (LPDIRECTDRAW)this;
3017 this->lpvtbl->fnAddRef(this);
3018 d3d->lpvtbl = &d3dvt;
3021 TRACE(ddraw, " Creating IDirect3D interface (%p)\n", *obj);
3025 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D2))) {
3028 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
3030 d3d->ddraw = (LPDIRECTDRAW)this;
3031 this->lpvtbl->fnAddRef(this);
3032 d3d->lpvtbl = &d3d2vt;
3035 TRACE(ddraw, " Creating IDirect3D2 interface (%p)\n", *obj);
3039 WARN(ddraw,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid);
3040 return OLE_E_ENUM_NOMORE;
3043 static HRESULT WINAPI Xlib_IDirectDraw2_QueryInterface(
3044 LPDIRECTDRAW2 this,REFIID refiid,LPVOID *obj
3048 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
3049 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
3050 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
3052 this->lpvtbl->fnAddRef(this);
3054 TRACE(ddraw, " Creating IUnknown interface (%p)\n", *obj);
3058 if (!memcmp(&IID_IDirectDraw,refiid,sizeof(IID_IDirectDraw))) {
3059 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&xlib_ddvt;
3060 this->lpvtbl->fnAddRef(this);
3063 TRACE(ddraw, " Creating IDirectDraw interface (%p)\n", *obj);
3067 if (!memcmp(&IID_IDirectDraw2,refiid,sizeof(IID_IDirectDraw2))) {
3068 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&xlib_dd2vt;
3069 this->lpvtbl->fnAddRef(this);
3072 TRACE(ddraw, " Creating IDirectDraw2 interface (%p)\n", *obj);
3076 if (!memcmp(&IID_IDirectDraw4,refiid,sizeof(IID_IDirectDraw4))) {
3077 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&xlib_dd4vt;
3078 this->lpvtbl->fnAddRef(this);
3081 TRACE(ddraw, " Creating IDirectDraw4 interface (%p)\n", *obj);
3085 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
3088 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
3090 d3d->ddraw = (LPDIRECTDRAW)this;
3091 this->lpvtbl->fnAddRef(this);
3092 d3d->lpvtbl = &d3dvt;
3095 TRACE(ddraw, " Creating IDirect3D interface (%p)\n", *obj);
3099 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D))) {
3102 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
3104 d3d->ddraw = (LPDIRECTDRAW)this;
3105 this->lpvtbl->fnAddRef(this);
3106 d3d->lpvtbl = &d3d2vt;
3109 TRACE(ddraw, " Creating IDirect3D2 interface (%p)\n", *obj);
3113 WARN(ddraw,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid);
3114 return OLE_E_ENUM_NOMORE;
3117 static HRESULT WINAPI IDirectDraw2_GetVerticalBlankStatus(
3118 LPDIRECTDRAW2 this,BOOL32 *status
3120 TRACE(ddraw,"(%p)->(%p)\n",this,status);
3125 static HRESULT WINAPI IDirectDraw2_EnumDisplayModes(
3126 LPDIRECTDRAW2 this,DWORD dwFlags,LPDDSURFACEDESC lpddsfd,LPVOID context,LPDDENUMMODESCALLBACK modescb
3128 DDSURFACEDESC ddsfd;
3131 } modes[5] = { /* some of the usual modes */
3138 static int depths[4] = {8,16,24,32};
3141 TRACE(ddraw,"(%p)->(0x%08lx,%p,%p,%p)\n",this,dwFlags,lpddsfd,context,modescb);
3142 ddsfd.dwSize = sizeof(ddsfd);
3143 ddsfd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
3144 if (dwFlags & DDEDM_REFRESHRATES) {
3145 ddsfd.dwFlags |= DDSD_REFRESHRATE;
3146 ddsfd.x.dwRefreshRate = 60;
3149 for (i=0;i<sizeof(depths)/sizeof(depths[0]);i++) {
3150 ddsfd.dwBackBufferCount = 1;
3151 ddsfd.ddpfPixelFormat.dwFourCC = 0;
3152 ddsfd.ddpfPixelFormat.dwFlags = DDPF_RGB;
3153 ddsfd.ddpfPixelFormat.x.dwRGBBitCount = depths[i];
3154 /* FIXME: those masks would have to be set in depth > 8 */
3156 ddsfd.ddpfPixelFormat.y.dwRBitMask = 0;
3157 ddsfd.ddpfPixelFormat.z.dwGBitMask = 0;
3158 ddsfd.ddpfPixelFormat.xx.dwBBitMask = 0;
3159 ddsfd.ddpfPixelFormat.xy.dwRGBAlphaBitMask= 0;
3160 ddsfd.ddsCaps.dwCaps=DDSCAPS_PALETTE;
3161 ddsfd.ddpfPixelFormat.dwFlags|=DDPF_PALETTEINDEXED8;
3163 ddsfd.ddpfPixelFormat.xy.dwRGBAlphaBitMask= 0;
3165 /* FIXME: We should query those from X itself */
3166 switch (depths[i]) {
3168 ddsfd.ddpfPixelFormat.y.dwRBitMask = 0xF800;
3169 ddsfd.ddpfPixelFormat.z.dwGBitMask = 0x07E0;
3170 ddsfd.ddpfPixelFormat.xx.dwBBitMask= 0x001F;
3173 ddsfd.ddpfPixelFormat.y.dwRBitMask = 0x00FF0000;
3174 ddsfd.ddpfPixelFormat.z.dwGBitMask = 0x0000FF00;
3175 ddsfd.ddpfPixelFormat.xx.dwBBitMask= 0x000000FF;
3178 ddsfd.ddpfPixelFormat.y.dwRBitMask = 0x00FF0000;
3179 ddsfd.ddpfPixelFormat.z.dwGBitMask = 0x0000FF00;
3180 ddsfd.ddpfPixelFormat.xx.dwBBitMask= 0x000000FF;
3185 ddsfd.dwWidth = screenWidth;
3186 ddsfd.dwHeight = screenHeight;
3187 TRACE(ddraw," enumerating (%ldx%ldx%d)\n",ddsfd.dwWidth,ddsfd.dwHeight,depths[i]);
3188 if (!modescb(&ddsfd,context)) return DD_OK;
3190 for (j=0;j<sizeof(modes)/sizeof(modes[0]);j++) {
3191 ddsfd.dwWidth = modes[j].w;
3192 ddsfd.dwHeight = modes[j].h;
3193 TRACE(ddraw," enumerating (%ldx%ldx%d)\n",ddsfd.dwWidth,ddsfd.dwHeight,depths[i]);
3194 if (!modescb(&ddsfd,context)) return DD_OK;
3197 if (!(dwFlags & DDEDM_STANDARDVGAMODES)) {
3198 /* modeX is not standard VGA */
3200 ddsfd.dwHeight = 200;
3201 ddsfd.dwWidth = 320;
3202 TRACE(ddraw," enumerating (320x200x%d)\n",depths[i]);
3203 if (!modescb(&ddsfd,context)) return DD_OK;
3209 static HRESULT WINAPI DGA_IDirectDraw2_GetDisplayMode(
3210 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsfd
3212 #ifdef HAVE_LIBXXF86DGA
3213 TRACE(ddraw,"(%p)->(%p)\n",this,lpddsfd);
3214 lpddsfd->dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PITCH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
3215 lpddsfd->dwHeight = screenHeight;
3216 lpddsfd->dwWidth = screenWidth;
3217 lpddsfd->lPitch = this->e.dga.fb_width*this->d.depth/8;
3218 lpddsfd->dwBackBufferCount = 1;
3219 lpddsfd->x.dwRefreshRate = 60;
3220 lpddsfd->ddsCaps.dwCaps = DDSCAPS_PALETTE;
3221 _getpixelformat(this,&(lpddsfd->ddpfPixelFormat));
3223 #else /* defined(HAVE_LIBXXF86DGA) */
3224 return E_UNEXPECTED;
3225 #endif /* defined(HAVE_LIBXXF86DGA) */
3228 static HRESULT WINAPI Xlib_IDirectDraw2_GetDisplayMode(
3229 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsfd
3231 TRACE(ddraw,"(%p)->GetDisplayMode(%p)\n",this,lpddsfd);
3232 lpddsfd->dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PITCH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
3233 lpddsfd->dwHeight = screenHeight;
3234 lpddsfd->dwWidth = screenWidth;
3235 /* POOLE FIXME: Xlib */
3236 lpddsfd->lPitch = this->e.dga.fb_width*this->d.depth/8;
3237 /* END FIXME: Xlib */
3238 lpddsfd->dwBackBufferCount = 1;
3239 lpddsfd->x.dwRefreshRate = 60;
3240 lpddsfd->ddsCaps.dwCaps = DDSCAPS_PALETTE;
3241 _getpixelformat(this,&(lpddsfd->ddpfPixelFormat));
3245 static HRESULT WINAPI IDirectDraw2_FlipToGDISurface(LPDIRECTDRAW2 this) {
3246 TRACE(ddraw,"(%p)->()\n",this);
3250 static HRESULT WINAPI IDirectDraw2_GetMonitorFrequency(
3251 LPDIRECTDRAW2 this,LPDWORD freq
3253 FIXME(ddraw,"(%p)->(%p) returns 60 Hz always\n",this,freq);
3254 *freq = 60*100; /* 60 Hz */
3258 /* what can we directly decompress? */
3259 static HRESULT WINAPI IDirectDraw2_GetFourCCCodes(
3260 LPDIRECTDRAW2 this,LPDWORD x,LPDWORD y
3262 FIXME(ddraw,"(%p,%p,%p), stub\n",this,x,y);
3266 static HRESULT WINAPI IDirectDraw2_EnumSurfaces(
3267 LPDIRECTDRAW2 this,DWORD x,LPDDSURFACEDESC ddsfd,LPVOID context,LPDDENUMSURFACESCALLBACK ddsfcb
3269 FIXME(ddraw,"(%p)->(0x%08lx,%p,%p,%p),stub!\n",this,x,ddsfd,context,ddsfcb);
3273 static HRESULT WINAPI IDirectDraw2_Compact(
3274 LPDIRECTDRAW2 this )
3276 FIXME(ddraw,"(%p)->()\n", this );
3281 static HRESULT WINAPI IDirectDraw2_GetGDISurface(LPDIRECTDRAW2 this,
3282 LPDIRECTDRAWSURFACE *lplpGDIDDSSurface) {
3283 FIXME(ddraw,"(%p)->(%p)\n", this, lplpGDIDDSSurface);
3288 static HRESULT WINAPI IDirectDraw2_GetScanLine(LPDIRECTDRAW2 this,
3289 LPDWORD lpdwScanLine) {
3290 FIXME(ddraw,"(%p)->(%p)\n", this, lpdwScanLine);
3295 static HRESULT WINAPI IDirectDraw2_Initialize(LPDIRECTDRAW2 this,
3297 FIXME(ddraw,"(%p)->(%p)\n", this, lpGUID);
3302 /* Note: Hack so we can reuse the old functions without compiler warnings */
3304 # define XCAST(fun) (typeof(dga_ddvt.fn##fun))
3306 # define XCAST(fun) (void*)
3309 static struct IDirectDraw_VTable dga_ddvt = {
3310 XCAST(QueryInterface)DGA_IDirectDraw2_QueryInterface,
3311 XCAST(AddRef)IDirectDraw2_AddRef,
3312 XCAST(Release)DGA_IDirectDraw2_Release,
3313 XCAST(Compact)IDirectDraw2_Compact,
3314 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
3315 XCAST(CreatePalette)DGA_IDirectDraw2_CreatePalette,
3316 XCAST(CreateSurface)DGA_IDirectDraw2_CreateSurface,
3317 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
3318 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
3319 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
3320 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
3321 XCAST(GetCaps)DGA_IDirectDraw2_GetCaps,
3322 XCAST(GetDisplayMode)DGA_IDirectDraw2_GetDisplayMode,
3323 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
3324 XCAST(GetGDISurface)IDirectDraw2_GetGDISurface,
3325 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
3326 XCAST(GetScanLine)IDirectDraw2_GetScanLine,
3327 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
3328 XCAST(Initialize)IDirectDraw2_Initialize,
3329 XCAST(RestoreDisplayMode)DGA_IDirectDraw2_RestoreDisplayMode,
3330 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
3331 DGA_IDirectDraw_SetDisplayMode,
3332 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
3335 static struct IDirectDraw_VTable xlib_ddvt = {
3336 XCAST(QueryInterface)Xlib_IDirectDraw2_QueryInterface,
3337 XCAST(AddRef)IDirectDraw2_AddRef,
3338 XCAST(Release)Xlib_IDirectDraw2_Release,
3339 XCAST(Compact)IDirectDraw2_Compact,
3340 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
3341 XCAST(CreatePalette)Xlib_IDirectDraw2_CreatePalette,
3342 XCAST(CreateSurface)Xlib_IDirectDraw2_CreateSurface,
3343 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
3344 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
3345 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
3346 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
3347 XCAST(GetCaps)Xlib_IDirectDraw2_GetCaps,
3348 XCAST(GetDisplayMode)Xlib_IDirectDraw2_GetDisplayMode,
3349 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
3350 XCAST(GetGDISurface)IDirectDraw2_GetGDISurface,
3351 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
3352 XCAST(GetScanLine)IDirectDraw2_GetScanLine,
3353 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
3354 XCAST(Initialize)IDirectDraw2_Initialize,
3355 XCAST(RestoreDisplayMode)Xlib_IDirectDraw2_RestoreDisplayMode,
3356 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
3357 Xlib_IDirectDraw_SetDisplayMode,
3358 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
3363 /*****************************************************************************
3369 static HRESULT WINAPI DGA_IDirectDraw2_SetDisplayMode(
3370 LPDIRECTDRAW2 this,DWORD width,DWORD height,DWORD depth,DWORD xx,DWORD yy
3372 return DGA_IDirectDraw_SetDisplayMode((LPDIRECTDRAW)this,width,height,depth);
3375 static HRESULT WINAPI Xlib_IDirectDraw2_SetDisplayMode(
3376 LPDIRECTDRAW2 this,DWORD width,DWORD height,DWORD depth,DWORD xx,DWORD yy
3378 return Xlib_IDirectDraw_SetDisplayMode((LPDIRECTDRAW)this,width,height,depth);
3381 static HRESULT WINAPI DGA_IDirectDraw2_GetAvailableVidMem(
3382 LPDIRECTDRAW2 this,LPDDSCAPS ddscaps,LPDWORD total,LPDWORD free
3384 TRACE(ddraw,"(%p)->(%p,%p,%p)\n",
3385 this,ddscaps,total,free
3387 if (total) *total = this->e.dga.fb_memsize * 1024;
3388 if (free) *free = this->e.dga.fb_memsize * 1024;
3392 static HRESULT WINAPI Xlib_IDirectDraw2_GetAvailableVidMem(
3393 LPDIRECTDRAW2 this,LPDDSCAPS ddscaps,LPDWORD total,LPDWORD free
3395 TRACE(ddraw,"(%p)->(%p,%p,%p)\n",
3396 this,ddscaps,total,free
3398 if (total) *total = 2048 * 1024;
3399 if (free) *free = 2048 * 1024;
3403 static IDirectDraw2_VTable dga_dd2vt = {
3404 DGA_IDirectDraw2_QueryInterface,
3405 IDirectDraw2_AddRef,
3406 DGA_IDirectDraw2_Release,
3407 IDirectDraw2_Compact,
3408 IDirectDraw2_CreateClipper,
3409 DGA_IDirectDraw2_CreatePalette,
3410 DGA_IDirectDraw2_CreateSurface,
3411 IDirectDraw2_DuplicateSurface,
3412 IDirectDraw2_EnumDisplayModes,
3413 IDirectDraw2_EnumSurfaces,
3414 IDirectDraw2_FlipToGDISurface,
3415 DGA_IDirectDraw2_GetCaps,
3416 DGA_IDirectDraw2_GetDisplayMode,
3417 IDirectDraw2_GetFourCCCodes,
3418 IDirectDraw2_GetGDISurface,
3419 IDirectDraw2_GetMonitorFrequency,
3420 IDirectDraw2_GetScanLine,
3421 IDirectDraw2_GetVerticalBlankStatus,
3422 IDirectDraw2_Initialize,
3423 DGA_IDirectDraw2_RestoreDisplayMode,
3424 IDirectDraw2_SetCooperativeLevel,
3425 DGA_IDirectDraw2_SetDisplayMode,
3426 IDirectDraw2_WaitForVerticalBlank,
3427 DGA_IDirectDraw2_GetAvailableVidMem
3430 static struct IDirectDraw2_VTable xlib_dd2vt = {
3431 Xlib_IDirectDraw2_QueryInterface,
3432 IDirectDraw2_AddRef,
3433 Xlib_IDirectDraw2_Release,
3434 IDirectDraw2_Compact,
3435 IDirectDraw2_CreateClipper,
3436 Xlib_IDirectDraw2_CreatePalette,
3437 Xlib_IDirectDraw2_CreateSurface,
3438 IDirectDraw2_DuplicateSurface,
3439 IDirectDraw2_EnumDisplayModes,
3440 IDirectDraw2_EnumSurfaces,
3441 IDirectDraw2_FlipToGDISurface,
3442 Xlib_IDirectDraw2_GetCaps,
3443 Xlib_IDirectDraw2_GetDisplayMode,
3444 IDirectDraw2_GetFourCCCodes,
3445 IDirectDraw2_GetGDISurface,
3446 IDirectDraw2_GetMonitorFrequency,
3447 IDirectDraw2_GetScanLine,
3448 IDirectDraw2_GetVerticalBlankStatus,
3449 IDirectDraw2_Initialize,
3450 Xlib_IDirectDraw2_RestoreDisplayMode,
3451 IDirectDraw2_SetCooperativeLevel,
3452 Xlib_IDirectDraw2_SetDisplayMode,
3453 IDirectDraw2_WaitForVerticalBlank,
3454 Xlib_IDirectDraw2_GetAvailableVidMem
3457 /*****************************************************************************
3462 static HRESULT WINAPI IDirectDraw4_GetSurfaceFromDC(LPDIRECTDRAW4 this,
3464 LPDIRECTDRAWSURFACE *lpDDS) {
3465 FIXME(ddraw, "(%p)->(%08ld,%p)\n", this, (DWORD) hdc, lpDDS);
3470 static HRESULT WINAPI IDirectDraw4_RestoreAllSurfaces(LPDIRECTDRAW4 this) {
3471 FIXME(ddraw, "(%p)->()\n", this);
3476 static HRESULT WINAPI IDirectDraw4_TestCooperativeLevel(LPDIRECTDRAW4 this) {
3477 FIXME(ddraw, "(%p)->()\n", this);
3482 static HRESULT WINAPI IDirectDraw4_GetDeviceIdentifier(LPDIRECTDRAW4 this,
3483 LPDDDEVICEIDENTIFIER lpdddi,
3485 FIXME(ddraw, "(%p)->(%p,%08lx)\n", this, lpdddi, dwFlags);
3491 # define XCAST(fun) (typeof(dga_dd4vt.fn##fun))
3493 # define XCAST(fun) (void*)
3497 static struct IDirectDraw4_VTable dga_dd4vt = {
3498 XCAST(QueryInterface)DGA_IDirectDraw2_QueryInterface,
3499 XCAST(AddRef)IDirectDraw2_AddRef,
3500 XCAST(Release)DGA_IDirectDraw2_Release,
3501 XCAST(Compact)IDirectDraw2_Compact,
3502 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
3503 XCAST(CreatePalette)DGA_IDirectDraw2_CreatePalette,
3504 XCAST(CreateSurface)DGA_IDirectDraw2_CreateSurface,
3505 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
3506 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
3507 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
3508 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
3509 XCAST(GetCaps)DGA_IDirectDraw2_GetCaps,
3510 XCAST(GetDisplayMode)DGA_IDirectDraw2_GetDisplayMode,
3511 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
3512 XCAST(GetGDISurface)IDirectDraw2_GetGDISurface,
3513 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
3514 XCAST(GetScanLine)IDirectDraw2_GetScanLine,
3515 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
3516 XCAST(Initialize)IDirectDraw2_Initialize,
3517 XCAST(RestoreDisplayMode)DGA_IDirectDraw2_RestoreDisplayMode,
3518 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
3519 XCAST(SetDisplayMode)DGA_IDirectDraw_SetDisplayMode,
3520 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
3521 XCAST(GetAvailableVidMem)DGA_IDirectDraw2_GetAvailableVidMem,
3522 IDirectDraw4_GetSurfaceFromDC,
3523 IDirectDraw4_RestoreAllSurfaces,
3524 IDirectDraw4_TestCooperativeLevel,
3525 IDirectDraw4_GetDeviceIdentifier
3528 static struct IDirectDraw4_VTable xlib_dd4vt = {
3529 XCAST(QueryInterface)Xlib_IDirectDraw2_QueryInterface,
3530 XCAST(AddRef)IDirectDraw2_AddRef,
3531 XCAST(Release)Xlib_IDirectDraw2_Release,
3532 XCAST(Compact)IDirectDraw2_Compact,
3533 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
3534 XCAST(CreatePalette)Xlib_IDirectDraw2_CreatePalette,
3535 XCAST(CreateSurface)Xlib_IDirectDraw2_CreateSurface,
3536 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
3537 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
3538 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
3539 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
3540 XCAST(GetCaps)Xlib_IDirectDraw2_GetCaps,
3541 XCAST(GetDisplayMode)Xlib_IDirectDraw2_GetDisplayMode,
3542 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
3543 XCAST(GetGDISurface)IDirectDraw2_GetGDISurface,
3544 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
3545 XCAST(GetScanLine)IDirectDraw2_GetScanLine,
3546 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
3547 XCAST(Initialize)IDirectDraw2_Initialize,
3548 XCAST(RestoreDisplayMode)Xlib_IDirectDraw2_RestoreDisplayMode,
3549 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
3550 XCAST(SetDisplayMode)Xlib_IDirectDraw_SetDisplayMode,
3551 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
3552 XCAST(GetAvailableVidMem)Xlib_IDirectDraw2_GetAvailableVidMem,
3553 IDirectDraw4_GetSurfaceFromDC,
3554 IDirectDraw4_RestoreAllSurfaces,
3555 IDirectDraw4_TestCooperativeLevel,
3556 IDirectDraw4_GetDeviceIdentifier
3561 /******************************************************************************
3565 LRESULT WINAPI Xlib_DDWndProc(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
3568 LPDIRECTDRAW ddraw = NULL;
3571 /* FIXME(ddraw,"(0x%04x,%s,0x%08lx,0x%08lx),stub!\n",(int)hwnd,SPY_GetMsgName(msg),(long)wParam,(long)lParam); */
3573 SetLastError( ERROR_SUCCESS );
3574 ddraw = (LPDIRECTDRAW)GetWindowLong32A( hwnd, ddrawXlibThisOffset );
3576 ( ( lastError = GetLastError() ) != ERROR_SUCCESS )
3579 ERR( ddraw, "Unable to retrieve this ptr from window. Error %08lx\n", lastError );
3584 /* Perform any special direct draw functions */
3586 ddraw->d.paintable = 1;
3588 /* Now let the application deal with the rest of this */
3589 if( ddraw->d.mainWindow )
3592 /* Don't think that we actually need to call this but...
3593 might as well be on the safe side of things... */
3595 /* I changed hwnd to ddraw->d.mainWindow as I did not see why
3596 it should be the procedures of our fake window that gets called
3597 instead of those of the window provided by the application.
3598 And with this patch, mouse clicks work with Monkey Island III
3600 ret = DefWindowProc32A( ddraw->d.mainWindow, msg, wParam, lParam );
3604 /* We didn't handle the message - give it to the application */
3605 if (ddraw && ddraw->d.mainWindow && WIN_FindWndPtr(ddraw->d.mainWindow)) {
3606 ret = CallWindowProc32A( WIN_FindWndPtr( ddraw->d.mainWindow )->winproc,
3607 ddraw->d.mainWindow, msg, wParam, lParam );
3612 ret = DefWindowProc32A(hwnd, msg, wParam, lParam );
3618 ret = DefWindowProc32A(hwnd,msg,wParam,lParam);
3624 HRESULT WINAPI DGA_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) {
3625 #ifdef HAVE_LIBXXF86DGA
3626 int memsize,banksize,width,major,minor,flags,height;
3630 /* Must be able to access /dev/mem for DGA extensions to work, root is not neccessary. --stephenc */
3631 if ((fd = open("/dev/mem", O_RDWR)) != -1)
3635 MSG("Must be able to access /dev/mem to use XF86DGA!\n");
3636 MessageBox32A(0,"Using the XF86DGA extension requires access to /dev/mem.","WINE DirectDraw",MB_OK|MB_ICONSTOP);
3637 return E_UNEXPECTED;
3639 if (!DDRAW_DGA_Available()) {
3640 TRACE(ddraw,"No XF86DGA detected.\n");
3641 return DDERR_GENERIC;
3643 *lplpDD = (LPDIRECTDRAW)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDraw));
3644 (*lplpDD)->lpvtbl = &dga_ddvt;
3646 TSXF86DGAQueryVersion(display,&major,&minor);
3647 TRACE(ddraw,"XF86DGA is version %d.%d\n",major,minor);
3648 TSXF86DGAQueryDirectVideo(display,DefaultScreen(display),&flags);
3649 if (!(flags & XF86DGADirectPresent))
3650 MSG("direct video is NOT PRESENT.\n");
3651 TSXF86DGAGetVideo(display,DefaultScreen(display),&addr,&width,&banksize,&memsize);
3652 TRACE(ddraw,"video framebuffer: begin %p, width %d,banksize %d,memsize %d\n",
3653 addr,width,banksize,memsize
3655 (*lplpDD)->e.dga.fb_width = width;
3656 (*lplpDD)->d.width = width;
3657 (*lplpDD)->e.dga.fb_addr = addr;
3658 (*lplpDD)->e.dga.fb_memsize = memsize;
3659 (*lplpDD)->e.dga.fb_banksize = banksize;
3661 TSXF86DGAGetViewPortSize(display,DefaultScreen(display),&width,&height);
3662 TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
3663 (*lplpDD)->e.dga.fb_height = screenHeight;
3665 (*lplpDD)->e.dga.vpmask = 1;
3667 (*lplpDD)->e.dga.vpmask = 0;
3670 /* just assume the default depth is the DGA depth too */
3671 (*lplpDD)->d.screen_depth = DefaultDepthOfScreen(screen);
3672 (*lplpDD)->d.depth = DefaultDepthOfScreen(screen);
3673 #ifdef RESTORE_SIGNALS
3674 if (SIGNAL_Reinit) SIGNAL_Reinit();
3678 #else /* defined(HAVE_LIBXXF86DGA) */
3679 return DDERR_INVALIDDIRECTDRAWGUID;
3680 #endif /* defined(HAVE_LIBXXF86DGA) */
3684 DDRAW_XSHM_Available(void)
3686 #ifdef HAVE_LIBXXSHM
3687 if (TSXShmQueryExtension(display))
3692 if (TSXShmQueryVersion(display, &major, &minor, &shpix))
3704 HRESULT WINAPI Xlib_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) {
3706 *lplpDD = (LPDIRECTDRAW)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDraw));
3707 (*lplpDD)->lpvtbl = &xlib_ddvt;
3709 (*lplpDD)->d.drawable = 0; /* in SetDisplayMode */
3711 (*lplpDD)->d.screen_depth = DefaultDepthOfScreen(screen);
3712 (*lplpDD)->d.depth = DefaultDepthOfScreen(screen);
3713 (*lplpDD)->d.height = screenHeight;
3714 (*lplpDD)->d.width = screenWidth;
3716 #ifdef HAVE_LIBXXSHM
3717 /* Test if XShm is available. */
3718 if (((*lplpDD)->e.xlib.xshm_active = DDRAW_XSHM_Available()))
3719 TRACE(ddraw, "Using XShm extension.\n");
3725 HRESULT WINAPI DirectDrawCreate( LPGUID lpGUID, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter ) {
3732 WINE_StringFromCLSID(lpGUID,xclsid);
3734 sprintf(xclsid,"<guid-0x%08x>",(int)lpGUID);
3738 TRACE(ddraw,"(%s,%p,%p)\n",xclsid,lplpDD,pUnkOuter);
3741 /* if they didn't request a particular interface, use the best
3743 if (DDRAW_DGA_Available())
3744 lpGUID = &DGA_DirectDraw_GUID;
3746 lpGUID = &XLIB_DirectDraw_GUID;
3749 wc.style = CS_GLOBALCLASS;
3750 wc.lpfnWndProc = Xlib_DDWndProc;
3752 wc.cbWndExtra = /* Defines extra mem for window. This is used for storing this */
3753 sizeof( LPDIRECTDRAW ); /* ddrawXlibThisOffset */
3755 /* We can be a child of the desktop since we're really important */
3756 pParentWindow = WIN_GetDesktop();
3757 wc.hInstance = pParentWindow ? pParentWindow->hwndSelf : 0;
3761 wc.hCursor = (HCURSOR32)IDC_ARROW32A;
3762 wc.hbrBackground= NULL_BRUSH;
3763 wc.lpszMenuName = 0;
3764 wc.lpszClassName= "WINE_DirectDraw";
3765 RegisterClass32A(&wc);
3767 if (!memcmp(lpGUID, &DGA_DirectDraw_GUID, sizeof(GUID)))
3768 ret = DGA_DirectDrawCreate(lplpDD, pUnkOuter);
3769 else if (!memcmp(lpGUID, &XLIB_DirectDraw_GUID, sizeof(GUID)))
3770 ret = Xlib_DirectDrawCreate(lplpDD, pUnkOuter);
3774 (*lplpDD)->d.winclass = RegisterClass32A(&wc);
3778 fprintf(stderr,"DirectDrawCreate(%s,%p,%p): did not recognize requested GUID\n",xclsid,lplpDD,pUnkOuter);
3779 return DDERR_INVALIDDIRECTDRAWGUID;