1 /* DirectDraw using DGA or Xlib
3 * Copyright 1997,1998 Marcus Meissner
5 /* When DirectVideo mode is enabled you can no longer use 'normal' X
6 * applications nor can you switch to a virtual console. Also, enabling
7 * only works, if you have switched to the screen where the application
9 * Some ways to debug this stuff are:
10 * - A terminal connected to the serial port. Can be bought used for cheap.
11 * (This is the method I am using.)
12 * - Another machine connected over some kind of network.
14 * FIXME: The Xshm implementation has been temporarily removed. It will be
15 * later reintegrated into the Xlib implementation.
17 * FIXME: The Xlib implementation hangs the windowmanager and all other
18 * running X clients, even though I am polling X events and answering
19 * them. But you can switch to another console (ctrl-alt-fx) and
20 * "killall wine" processes. Any help on this one appreciated. -Marcus
21 * NOTE: The hanging only seems to happen with -managed. I have
22 * implemented support for the -desktop option. This seems
23 * to not have the hanging problems. - Peter Hunnisett
30 #include <sys/signal.h>
34 #include "interfaces.h"
48 #ifdef HAVE_LIBXXF86DGA
49 #include "ts_xf86dga.h"
52 /* define this if you want to play Diablo using XF86DGA. (bug workaround) */
55 /* restore signal handlers overwritten by XF86DGA
56 * this is a define, for it will only work in emulator mode
58 #undef RESTORE_SIGNALS
60 /* Where do these GUIDs come from? mkuuid.
61 * They exist solely to distinguish between the targets Wine support,
62 * and should be different than any other GUIDs in existence.
64 static GUID DGA_DirectDraw_GUID = { /* e2dcb020-dc60-11d1-8407-9714f5d50802 */
68 {0x84, 0x07, 0x97, 0x14, 0xf5, 0xd5, 0x08, 0x02}
71 static GUID XLIB_DirectDraw_GUID = { /* 1574a740-dc61-11d1-8407-f7875a7d1879 */
75 {0x84, 0x07, 0xf7, 0x87, 0x5a, 0x7d, 0x18, 0x79}
78 static struct IDirectDrawSurface3_VTable dga_dds3vt, xlib_dds3vt;
79 static struct IDirectDraw_VTable dga_ddvt, xlib_ddvt;
80 static struct IDirectDraw2_VTable dga_dd2vt, xlib_dd2vt;
81 static struct IDirectDrawClipper_VTable ddclipvt;
82 static struct IDirectDrawPalette_VTable dga_ddpalvt, xlib_ddpalvt;
83 static struct IDirect3D_VTable d3dvt;
84 static struct IDirect3D2_VTable d3d2vt;
86 void Xlib_MessagePump(HWND32 hwnd) {
89 while (EVENT_WaitNetEvent(FALSE,FALSE)) {
90 while (PeekMessage32A(&msg32,0,0,0,0)) {
91 GetMessage32A(&msg32,0,0,0);
92 TranslateMessage32(&msg32);
93 DispatchMessage32A(&msg32);
101 #ifdef HAVE_LIBXXF86DGA
103 return (getuid() == 0)&&TSXF86DGAQueryExtension(display,&evbase,&evret);
104 #else /* defined(HAVE_LIBXXF86DGA) */
106 #endif /* defined(HAVE_LIBXXF86DGA) */
110 DirectDrawEnumerate32A(LPDDENUMCALLBACK32A ddenumproc,LPVOID data) {
111 if (DDRAW_DGA_Available()) {
112 ddenumproc(&DGA_DirectDraw_GUID,"WINE with XFree86 DGA","display",data);
114 ddenumproc(&XLIB_DirectDraw_GUID,"WINE with Xlib","display",data);
115 ddenumproc(NULL,"WINE","display",data);
119 /* What is this doing here? */
121 DSoundHelp(DWORD x,DWORD y,DWORD z) {
122 FIXME(ddraw,"(0x%08lx,0x%08lx,0x%08lx),stub!\n",x,y,z);
127 /******************************************************************************
128 * internal helper functions
130 static void _dump_DDBLTFX(DWORD flagmask) {
136 #define FE(x) { x, #x},
137 FE(DDBLTFX_ARITHSTRETCHY)
138 FE(DDBLTFX_MIRRORLEFTRIGHT)
139 FE(DDBLTFX_MIRRORUPDOWN)
140 FE(DDBLTFX_NOTEARING)
141 FE(DDBLTFX_ROTATE180)
142 FE(DDBLTFX_ROTATE270)
144 FE(DDBLTFX_ZBUFFERRANGE)
145 FE(DDBLTFX_ZBUFFERBASEDEST)
147 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
148 if (flags[i].mask & flagmask) {
149 DUMP("%s ",flags[i].name);
156 static void _dump_DDBLTFAST(DWORD flagmask) {
162 #define FE(x) { x, #x},
163 FE(DDBLTFAST_NOCOLORKEY)
164 FE(DDBLTFAST_SRCCOLORKEY)
165 FE(DDBLTFAST_DESTCOLORKEY)
168 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
169 if (flags[i].mask & flagmask)
170 DUMP("%s ",flags[i].name);
174 static void _dump_DDBLT(DWORD flagmask) {
180 #define FE(x) { x, #x},
182 FE(DDBLT_ALPHADESTCONSTOVERRIDE)
183 FE(DDBLT_ALPHADESTNEG)
184 FE(DDBLT_ALPHADESTSURFACEOVERRIDE)
185 FE(DDBLT_ALPHAEDGEBLEND)
187 FE(DDBLT_ALPHASRCCONSTOVERRIDE)
188 FE(DDBLT_ALPHASRCNEG)
189 FE(DDBLT_ALPHASRCSURFACEOVERRIDE)
195 FE(DDBLT_KEYDESTOVERRIDE)
197 FE(DDBLT_KEYSRCOVERRIDE)
199 FE(DDBLT_ROTATIONANGLE)
201 FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE)
202 FE(DDBLT_ZBUFFERDESTOVERRIDE)
203 FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE)
204 FE(DDBLT_ZBUFFERSRCOVERRIDE)
208 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
209 if (flags[i].mask & flagmask)
210 DUMP("%s ",flags[i].name);
213 static void _dump_DDSCAPS(DWORD flagmask) {
219 #define FE(x) { x, #x},
220 FE(DDSCAPS_RESERVED1)
222 FE(DDSCAPS_BACKBUFFER)
225 FE(DDSCAPS_FRONTBUFFER)
226 FE(DDSCAPS_OFFSCREENPLAIN)
229 FE(DDSCAPS_PRIMARYSURFACE)
230 FE(DDSCAPS_PRIMARYSURFACELEFT)
231 FE(DDSCAPS_SYSTEMMEMORY)
234 FE(DDSCAPS_VIDEOMEMORY)
236 FE(DDSCAPS_WRITEONLY)
239 FE(DDSCAPS_LIVEVIDEO)
243 FE(DDSCAPS_RESERVED2)
244 FE(DDSCAPS_ALLOCONLOAD)
245 FE(DDSCAPS_VIDEOPORT)
246 FE(DDSCAPS_LOCALVIDMEM)
247 FE(DDSCAPS_NONLOCALVIDMEM)
248 FE(DDSCAPS_STANDARDVGAMODE)
249 FE(DDSCAPS_OPTIMIZED)
251 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
252 if (flags[i].mask & flagmask)
253 DUMP("%s ",flags[i].name);
257 static void _dump_DDSD(DWORD flagmask) {
267 FE(DDSD_BACKBUFFERCOUNT)
268 FE(DDSD_ZBUFFERBITDEPTH)
269 FE(DDSD_ALPHABITDEPTH)
271 FE(DDSD_CKDESTOVERLAY)
273 FE(DDSD_CKSRCOVERLAY)
280 for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
281 if (flags[i].mask & flagmask)
282 DUMP("%s ",flags[i].name);
286 static int _getpixelformat(LPDIRECTDRAW2 ddraw,LPDDPIXELFORMAT pf) {
287 static XVisualInfo *vi;
292 vi = TSXGetVisualInfo(display,VisualNoMask,&vt,&nitems);
295 if (ddraw->d.depth==8) {
296 pf->dwFlags = DDPF_RGB|DDPF_PALETTEINDEXED8;
297 pf->x.dwRGBBitCount = 8;
298 pf->y.dwRBitMask = 0;
299 pf->z.dwGBitMask = 0;
300 pf->xx.dwBBitMask = 0;
301 pf->xy.dwRGBAlphaBitMask= 0;
304 if (ddraw->d.depth==16) {
305 pf->dwFlags = DDPF_RGB;
306 pf->x.dwRGBBitCount = 16;
307 pf->y.dwRBitMask = vi[0].red_mask;
308 pf->z.dwGBitMask = vi[0].green_mask;
309 pf->xx.dwBBitMask = vi[0].blue_mask;
310 pf->xy.dwRGBAlphaBitMask= 0;
313 FIXME(ddraw,"_getpixelformat:unknown depth %ld?\n",ddraw->d.depth);
314 return DDERR_GENERIC;
317 /******************************************************************************
318 * IDirectDrawSurface,IDirectDrawSurface2,IDirectDrawSurface3
320 * Since DDS3 and DDS2 are supersets of DDS, we implement DDS3 and let
321 * DDS and DDS2 use those functions. (Function calls did not change (except
322 * using different DirectDrawSurfaceX version), just added flags and functions)
324 static HRESULT WINAPI IDirectDrawSurface3_Lock(
325 LPDIRECTDRAWSURFACE3 this,LPRECT32 lprect,LPDDSURFACEDESC lpddsd,DWORD flags, HANDLE32 hnd
327 TRACE(ddraw, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
328 this,lprect,lpddsd,flags,(DWORD)hnd);
329 if (flags & ~(DDLOCK_WAIT|DDLOCK_READONLY|DDLOCK_WRITEONLY))
330 WARN(ddraw, "(%p)->Lock(%p,%p,%08lx,%08lx)\n",
331 this,lprect,lpddsd,flags,(DWORD)hnd);
334 FIXME(ddraw," lprect: %dx%d-%dx%d\n",
335 lprect->top,lprect->left,lprect->bottom,lprect->right
337 lpddsd->y.lpSurface = this->s.surface +
338 (lprect->top*this->s.lpitch) +
339 (lprect->left*(this->s.ddraw->d.depth/8));
341 assert(this->s.surface);
342 lpddsd->y.lpSurface = this->s.surface;
344 lpddsd->dwFlags = DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_PITCH|DDSD_LPSURFACE;
345 lpddsd->dwWidth = this->s.width;
346 lpddsd->dwHeight = this->s.height;
347 lpddsd->lPitch = this->s.lpitch;
348 _getpixelformat(this->s.ddraw,&(lpddsd->ddpfPixelFormat));
352 static HRESULT WINAPI DGA_IDirectDrawSurface3_Unlock(
353 LPDIRECTDRAWSURFACE3 this,LPVOID surface
355 TRACE(ddraw,"(%p)->Unlock(%p)\n",this,surface);
359 static HRESULT WINAPI Xlib_IDirectDrawSurface3_Unlock(
360 LPDIRECTDRAWSURFACE3 this,LPVOID surface
362 Xlib_MessagePump(this->s.ddraw->e.xlib.window);
364 TRACE(ddraw,"(%p)->Unlock(%p)\n",this,surface);
366 if (!this->s.ddraw->e.xlib.paintable)
371 TSXPutImage( display,
372 this->s.ddraw->e.xlib.drawable,
373 DefaultGCOfScreen(screen),
376 this->t.xlib.image->width,
377 this->t.xlib.image->height
379 if (this->s.palette && this->s.palette->cm) {
380 TSXSetWindowColormap(display,this->s.ddraw->e.xlib.drawable,this->s.palette->cm);
385 static HRESULT WINAPI DGA_IDirectDrawSurface3_Flip(
386 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWSURFACE3 flipto,DWORD dwFlags
388 #ifdef HAVE_LIBXXF86DGA
389 TRACE(ddraw,"(%p)->Flip(%p,%08lx)\n",this,flipto,dwFlags);
391 if (this->s.backbuffer)
392 flipto = this->s.backbuffer;
396 TSXF86DGASetViewPort(display,DefaultScreen(display),0,flipto->t.dga.fb_height);
398 if (flipto->s.palette && flipto->s.palette->cm) {
399 TSXF86DGAInstallColormap(display,DefaultScreen(display),flipto->s.palette->cm);
401 while (!TSXF86DGAViewPortChanged(display,DefaultScreen(display),2)) {
407 tmp = this->t.dga.fb_height;
408 this->t.dga.fb_height = flipto->t.dga.fb_height;
409 flipto->t.dga.fb_height = tmp;
411 ptmp = this->s.surface;
412 this->s.surface = flipto->s.surface;
413 flipto->s.surface = ptmp;
416 #else /* defined(HAVE_LIBXXF86DGA) */
418 #endif /* defined(HAVE_LIBXXF86DGA) */
421 static HRESULT WINAPI Xlib_IDirectDrawSurface3_Flip(
422 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWSURFACE3 flipto,DWORD dwFlags
425 TRACE(ddraw,"(%p)->Flip(%p,%08lx)\n",this,flipto,dwFlags);
426 Xlib_MessagePump(this->s.ddraw->e.xlib.window);
427 if (!this->s.ddraw->e.xlib.paintable)
431 if (this->s.backbuffer)
432 flipto = this->s.backbuffer;
438 this->s.ddraw->e.xlib.drawable,
439 DefaultGCOfScreen(screen),
440 flipto->t.xlib.image,
442 flipto->t.xlib.image->width,
443 flipto->t.xlib.image->height);
444 if (this->s.palette && this->s.palette->cm) {
445 TSXSetWindowColormap(display,
446 this->s.ddraw->e.xlib.drawable,
447 this->s.palette->cm);
452 tmp = this->t.xlib.image;
453 this->t.xlib.image = flipto->t.xlib.image;
454 flipto->t.xlib.image = tmp;
455 surf = this->s.surface;
456 this->s.surface = flipto->s.surface;
457 flipto->s.surface = surf;
462 /* The IDirectDrawSurface3::SetPalette method attaches the specified
463 * DirectDrawPalette object to a surface. The surface uses this palette for all
464 * subsequent operations. The palette change takes place immediately.
466 static HRESULT WINAPI IDirectDrawSurface3_SetPalette(
467 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWPALETTE pal
469 TRACE(ddraw,"(%p)->SetPalette(%p)\n",this,pal);
471 /* According to spec, we are only supposed to
472 * AddRef if this is not the same palette.
474 if( this->s.palette != pal )
478 pal->lpvtbl->fnAddRef( pal );
480 if( this->s.palette != NULL )
482 this->s.palette->lpvtbl->fnRelease( this->s.palette );
484 this->s.palette = pal;
486 /* I think that we need to attach it to all backbuffers...*/
487 if( this->s.backbuffer )
489 if( this->s.backbuffer->s.palette )
491 this->s.backbuffer->s.palette->lpvtbl->fnRelease(
492 this->s.backbuffer->s.palette );
494 this->s.backbuffer->s.palette = pal;
497 pal->lpvtbl->fnAddRef( pal );
501 /* Perform the refresh */
502 TSXSetWindowColormap(display,
503 this->s.ddraw->e.xlib.drawable,
504 this->s.palette->cm);
510 static HRESULT WINAPI IDirectDrawSurface3_Blt(
511 LPDIRECTDRAWSURFACE3 this,LPRECT32 rdst,LPDIRECTDRAWSURFACE3 src,LPRECT32 rsrc,DWORD dwFlags,LPDDBLTFX lpbltfx
517 memcpy(&xdst,rdst,sizeof(xdst));
520 xdst.bottom = this->s.height;
522 xdst.right = this->s.width;
526 memcpy(&xsrc,rsrc,sizeof(xsrc));
529 xsrc.bottom = src->s.height;
531 xsrc.right = src->s.width;
534 if (dwFlags & DDBLT_COLORFILL) {
535 int bpp = this->s.ddraw->d.depth/8;
538 xline = (LPBYTE)this->s.surface+xdst.top*this->s.lpitch;
539 for (i=xdst.top;i<xdst.bottom;i++) {
540 xpixel = xline+bpp*xdst.left;
542 for (j=xdst.left;j<xdst.right;j++) {
543 /* FIXME: this only works on little endian
544 * architectures, where DWORD starts with low
547 memcpy(xpixel,&(lpbltfx->b.dwFillColor),bpp);
550 xline += this->s.lpitch;
552 dwFlags &= ~(DDBLT_COLORFILL);
554 dwFlags &= ~(DDBLT_WAIT|DDBLT_ASYNC);/* FIXME: can't handle right now */
555 if ( (xsrc.top ==0) && (xsrc.bottom ==this->s.height) &&
556 (xsrc.left==0) && (xsrc.right ==this->s.width) &&
557 (xdst.top ==0) && (xdst.bottom ==this->s.height) &&
558 (xdst.left==0) && (xdst.right ==this->s.width) &&
561 memcpy(this->s.surface,src->s.surface,this->s.height*this->s.lpitch);
565 FIXME(ddraw,"(%p)->(%p,%p,%p,%08lx,%p),stub!\n",
566 this,rdst,src,rsrc,dwFlags,lpbltfx
568 if (rdst) TRACE(ddraw," destrect :%dx%d-%dx%d\n",rdst->left,rdst->top,rdst->right,rdst->bottom);
569 if (rsrc) TRACE(ddraw," srcrect :%dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
570 TRACE(ddraw,"\tflags: ");_dump_DDBLT(dwFlags);fprintf(stderr,"\n");
572 if (dwFlags & DDBLT_DDFX) {
573 TRACE(ddraw," blitfx: \n");_dump_DDBLTFX(lpbltfx->dwDDFX);
578 static HRESULT WINAPI IDirectDrawSurface3_BltFast(
579 LPDIRECTDRAWSURFACE3 this,DWORD dstx,DWORD dsty,LPDIRECTDRAWSURFACE3 src,LPRECT32 rsrc,DWORD trans
582 if (TRACE_ON(ddraw)) {
583 FIXME(ddraw,"(%p)->(%ld,%ld,%p,%p,%08lx),stub!\n",
584 this,dstx,dsty,src,rsrc,trans
586 TRACE(ddraw," trans:");_dump_DDBLTFAST(trans);fprintf(stderr,"\n");
587 TRACE(ddraw," srcrect: %dx%d-%dx%d\n",rsrc->left,rsrc->top,rsrc->right,rsrc->bottom);
589 bpp = this->s.ddraw->d.depth/8;
590 for (i=0;i<rsrc->bottom-rsrc->top;i++) {
591 memcpy( this->s.surface+((i+dsty)*this->s.width*bpp)+dstx*bpp,
592 src->s.surface +(rsrc->top+i)*src->s.width*bpp+rsrc->left*bpp,
593 (rsrc->right-rsrc->left)*bpp
599 static HRESULT WINAPI IDirectDrawSurface3_BltBatch(
600 LPDIRECTDRAWSURFACE3 this,LPDDBLTBATCH ddbltbatch,DWORD x,DWORD y
602 TRACE(ddraw,"(%p)->BltBatch(%p,%08lx,%08lx),stub!\n",
608 static HRESULT WINAPI IDirectDrawSurface3_GetCaps(
609 LPDIRECTDRAWSURFACE3 this,LPDDSCAPS caps
611 TRACE(ddraw,"(%p)->GetCaps(%p)\n",this,caps);
612 caps->dwCaps = DDCAPS_PALETTE; /* probably more */
616 static HRESULT WINAPI IDirectDrawSurface3_GetSurfaceDesc(
617 LPDIRECTDRAWSURFACE3 this,LPDDSURFACEDESC ddsd
619 if (TRACE_ON(ddraw)) {
620 TRACE(ddraw, "(%p)->GetSurfaceDesc(%p)\n",
622 fprintf(stderr," flags: ");
623 _dump_DDSD(ddsd->dwFlags);
624 fprintf(stderr,"\n");
627 ddsd->dwFlags |= DDSD_PIXELFORMAT|DDSD_CAPS|DDSD_BACKBUFFERCOUNT|DDSD_HEIGHT|DDSD_WIDTH;
628 ddsd->ddsCaps.dwCaps = DDSCAPS_PALETTE;
629 ddsd->dwBackBufferCount = 1;
630 ddsd->dwHeight = this->s.height;
631 ddsd->dwWidth = this->s.width;
632 ddsd->lPitch = this->s.lpitch;
633 if (this->s.backbuffer)
634 ddsd->ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP;
635 _getpixelformat(this->s.ddraw,&(ddsd->ddpfPixelFormat));
640 static ULONG WINAPI IDirectDrawSurface3_AddRef(LPDIRECTDRAWSURFACE3 this) {
641 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
643 return ++(this->ref);
646 static ULONG WINAPI DGA_IDirectDrawSurface3_Release(LPDIRECTDRAWSURFACE3 this) {
647 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
649 #ifdef HAVE_LIBXXF86DGA
650 if (!--(this->ref)) {
651 this->s.ddraw->lpvtbl->fnRelease(this->s.ddraw);
652 /* clear out of surface list */
653 if (this->t.dga.fb_height == -1) {
654 HeapFree(GetProcessHeap(),0,this->s.surface);
656 this->s.ddraw->e.dga.vpmask &= ~(1<<(this->t.dga.fb_height/this->s.ddraw->e.dga.fb_height));
658 HeapFree(GetProcessHeap(),0,this);
661 #endif /* defined(HAVE_LIBXXF86DGA) */
665 static ULONG WINAPI Xlib_IDirectDrawSurface3_Release(LPDIRECTDRAWSURFACE3 this) {
666 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
668 if (!--(this->ref)) {
669 this->s.ddraw->lpvtbl->fnRelease(this->s.ddraw);
670 HeapFree(GetProcessHeap(),0,this->s.surface);
672 if( this->s.backbuffer )
674 this->s.backbuffer->lpvtbl->fnRelease(this->s.backbuffer);
677 this->t.xlib.image->data = NULL;
678 TSXDestroyImage(this->t.xlib.image);
679 this->t.xlib.image = 0;
681 if (this->s.palette) {
682 this->s.palette->lpvtbl->fnRelease(this->s.palette);
685 HeapFree(GetProcessHeap(),0,this);
691 static HRESULT WINAPI IDirectDrawSurface3_GetAttachedSurface(
692 LPDIRECTDRAWSURFACE3 this,LPDDSCAPS lpddsd,LPDIRECTDRAWSURFACE3 *lpdsf
694 TRACE(ddraw, "(%p)->GetAttachedSurface(%p,%p)\n",
695 this, lpddsd, lpdsf);
697 if (TRACE_ON(ddraw)) {
698 TRACE(ddraw," caps ");
699 _dump_DDSCAPS(lpddsd->dwCaps);
702 if (!(lpddsd->dwCaps & DDSCAPS_BACKBUFFER)) {
703 FIXME(ddraw,"whoops, can only handle backbuffers for now\n");
707 /* FIXME: should handle more than one backbuffer */
708 *lpdsf = this->s.backbuffer;
710 if( this->s.backbuffer )
712 this->s.backbuffer->lpvtbl->fnAddRef( this->s.backbuffer );
718 static HRESULT WINAPI IDirectDrawSurface3_Initialize(
719 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAW ddraw,LPDDSURFACEDESC lpdsfd
721 return DDERR_ALREADYINITIALIZED;
724 static HRESULT WINAPI IDirectDrawSurface3_GetPixelFormat(
725 LPDIRECTDRAWSURFACE3 this,LPDDPIXELFORMAT pf
727 return _getpixelformat(this->s.ddraw,pf);
730 static HRESULT WINAPI IDirectDrawSurface3_GetBltStatus(LPDIRECTDRAWSURFACE3 this,DWORD dwFlags) {
731 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n",this,dwFlags);
735 static HRESULT WINAPI IDirectDrawSurface3_GetOverlayPosition(
736 LPDIRECTDRAWSURFACE3 this,LPLONG x1,LPLONG x2
738 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,x1,x2);
742 static HRESULT WINAPI IDirectDrawSurface3_SetClipper(
743 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWCLIPPER clipper
745 FIXME(ddraw,"(%p)->(%p),stub!\n",this,clipper);
749 static HRESULT WINAPI IDirectDrawSurface3_AddAttachedSurface(
750 LPDIRECTDRAWSURFACE3 this,LPDIRECTDRAWSURFACE3 surf
752 FIXME(ddraw,"(%p)->(%p),stub!\n",this,surf);
753 this->s.backbuffer = surf;
757 static HRESULT WINAPI IDirectDrawSurface3_GetDC(LPDIRECTDRAWSURFACE3 this,HDC32* lphdc) {
758 FIXME(ddraw,"(%p)->GetDC(%p)\n",this,lphdc);
759 *lphdc = BeginPaint32(this->s.ddraw->e.xlib.window,&this->s.ddraw->e.xlib.ps);
763 static HRESULT WINAPI IDirectDrawSurface3_ReleaseDC(LPDIRECTDRAWSURFACE3 this,HDC32 hdc) {
764 FIXME(ddraw,"(%p)->(0x%08lx),stub!\n",this,(long)hdc);
765 EndPaint32(this->s.ddraw->e.xlib.window,&this->s.ddraw->e.xlib.ps);
770 static HRESULT WINAPI IDirectDrawSurface3_QueryInterface(LPDIRECTDRAWSURFACE3 this,REFIID refiid,LPVOID *obj) {
773 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
774 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
776 /* DirectDrawSurface,DirectDrawSurface2 and DirectDrawSurface3 use
777 * the same interface. And IUnknown does that too of course.
779 if ( !memcmp(&IID_IDirectDrawSurface3,refiid,sizeof(IID)) ||
780 !memcmp(&IID_IDirectDrawSurface2,refiid,sizeof(IID)) ||
781 !memcmp(&IID_IDirectDrawSurface,refiid,sizeof(IID)) ||
782 !memcmp(&IID_IUnknown,refiid,sizeof(IID))
785 this->lpvtbl->fnAddRef(this);
788 FIXME(ddraw,"(%p):interface for IID %s NOT found!\n",this,xrefiid);
789 return OLE_E_ENUM_NOMORE;
792 static HRESULT WINAPI IDirectDrawSurface3_IsLost(LPDIRECTDRAWSURFACE3 this) {
793 FIXME(ddraw,"(%p)->(), stub!\n",this);
797 static HRESULT WINAPI IDirectDrawSurface3_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE3 this,LPVOID context,LPDDENUMSURFACESCALLBACK esfcb) {
798 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,context,esfcb);
802 static HRESULT WINAPI IDirectDrawSurface3_Restore(LPDIRECTDRAWSURFACE3 this) {
803 FIXME(ddraw,"(%p)->(),stub!\n",this);
807 static HRESULT WINAPI IDirectDrawSurface3_SetColorKey(
808 LPDIRECTDRAWSURFACE3 this, DWORD dwFlags, LPDDCOLORKEY ckey
810 FIXME(ddraw,"(%p)->(0x%08lx,%p),stub!\n",this,dwFlags,ckey);
812 if( dwFlags & DDCKEY_SRCBLT )
814 dwFlags &= ~DDCKEY_SRCBLT;
819 TRACE( ddraw, "unhandled dwFlags: %08lx\n", dwFlags );
825 static struct IDirectDrawSurface3_VTable dga_dds3vt = {
826 IDirectDrawSurface3_QueryInterface,
827 IDirectDrawSurface3_AddRef,
828 DGA_IDirectDrawSurface3_Release,
829 IDirectDrawSurface3_AddAttachedSurface,
831 IDirectDrawSurface3_Blt,
832 IDirectDrawSurface3_BltBatch,
833 IDirectDrawSurface3_BltFast,
835 IDirectDrawSurface3_EnumAttachedSurfaces,
837 DGA_IDirectDrawSurface3_Flip,
838 IDirectDrawSurface3_GetAttachedSurface,
839 IDirectDrawSurface3_GetBltStatus,
840 IDirectDrawSurface3_GetCaps,
843 IDirectDrawSurface3_GetDC,
845 IDirectDrawSurface3_GetOverlayPosition,
847 IDirectDrawSurface3_GetPixelFormat,
848 IDirectDrawSurface3_GetSurfaceDesc,
849 IDirectDrawSurface3_Initialize,
850 IDirectDrawSurface3_IsLost,
851 IDirectDrawSurface3_Lock,
852 IDirectDrawSurface3_ReleaseDC,
853 IDirectDrawSurface3_Restore,
854 IDirectDrawSurface3_SetClipper,
855 IDirectDrawSurface3_SetColorKey,
857 IDirectDrawSurface3_SetPalette,
858 DGA_IDirectDrawSurface3_Unlock,
868 static struct IDirectDrawSurface3_VTable xlib_dds3vt = {
869 IDirectDrawSurface3_QueryInterface,
870 IDirectDrawSurface3_AddRef,
871 Xlib_IDirectDrawSurface3_Release,
872 IDirectDrawSurface3_AddAttachedSurface,
874 IDirectDrawSurface3_Blt,
875 IDirectDrawSurface3_BltBatch,
876 IDirectDrawSurface3_BltFast,
878 IDirectDrawSurface3_EnumAttachedSurfaces,
880 Xlib_IDirectDrawSurface3_Flip,
881 IDirectDrawSurface3_GetAttachedSurface,
882 IDirectDrawSurface3_GetBltStatus,
883 IDirectDrawSurface3_GetCaps,
886 IDirectDrawSurface3_GetDC,
888 IDirectDrawSurface3_GetOverlayPosition,
890 IDirectDrawSurface3_GetPixelFormat,
891 IDirectDrawSurface3_GetSurfaceDesc,
892 IDirectDrawSurface3_Initialize,
893 IDirectDrawSurface3_IsLost,
894 IDirectDrawSurface3_Lock,
895 IDirectDrawSurface3_ReleaseDC,
896 IDirectDrawSurface3_Restore,
897 IDirectDrawSurface3_SetClipper,
898 IDirectDrawSurface3_SetColorKey,
900 IDirectDrawSurface3_SetPalette,
901 Xlib_IDirectDrawSurface3_Unlock,
911 /******************************************************************************
914 static HRESULT WINAPI IDirectDrawClipper_SetHwnd(
915 LPDIRECTDRAWCLIPPER this,DWORD x,HWND32 hwnd
917 FIXME(ddraw,"(%p)->SetHwnd(0x%08lx,0x%08lx),stub!\n",this,x,(DWORD)hwnd);
921 static ULONG WINAPI IDirectDrawClipper_Release(LPDIRECTDRAWCLIPPER this) {
922 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
927 HeapFree(GetProcessHeap(),0,this);
931 static HRESULT WINAPI IDirectDrawClipper_GetClipList(
932 LPDIRECTDRAWCLIPPER this,LPRECT32 rects,LPRGNDATA lprgn,LPDWORD hmm
934 FIXME(ddraw,"(%p,%p,%p,%p),stub!\n",this,rects,lprgn,hmm);
939 static HRESULT WINAPI IDirectDrawClipper_SetClipList(
940 LPDIRECTDRAWCLIPPER this,LPRGNDATA lprgn,DWORD hmm
942 FIXME(ddraw,"(%p,%p,%ld),stub!\n",this,lprgn,hmm);
946 static struct IDirectDrawClipper_VTable ddclipvt = {
949 IDirectDrawClipper_Release,
950 IDirectDrawClipper_GetClipList,
954 IDirectDrawClipper_SetClipList,
955 IDirectDrawClipper_SetHwnd
958 /******************************************************************************
961 static HRESULT WINAPI IDirectDrawPalette_GetEntries(
962 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
967 if (!this->cm) /* should not happen */ {
968 FIXME(ddraw,"app tried to read colormap for non-palettized mode\n");
969 return DDERR_GENERIC;
971 for (i=0;i<count;i++) {
975 TSXQueryColor(display,this->cm,&xc);
976 palent[i].peRed = xc.red>>8;
977 palent[i].peGreen = xc.green>>8;
978 palent[i].peBlue = xc.blue>>8;
981 palent[i].peRed = this->palents[start+i].peRed;
982 palent[i].peBlue = this->palents[start+i].peBlue;
983 palent[i].peGreen = this->palents[start+i].peGreen;
984 palent[i].peFlags = this->palents[start+i].peFlags;
990 static HRESULT WINAPI Xlib_IDirectDrawPalette_SetEntries(
991 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
996 TRACE(ddraw,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
997 this,x,start,count,palent
999 if (!this->cm) /* should not happen */ {
1000 FIXME(ddraw,"app tried to set colormap in non-palettized mode\n");
1001 return DDERR_GENERIC;
1003 if (!this->ddraw->e.xlib.paintable)
1005 for (i=0;i<count;i++) {
1006 xc.red = palent[i].peRed<<8;
1007 xc.blue = palent[i].peBlue<<8;
1008 xc.green = palent[i].peGreen<<8;
1009 xc.flags = DoRed|DoBlue|DoGreen;
1012 TSXStoreColor(display,this->cm,&xc);
1014 this->palents[start+i].peRed = palent[i].peRed;
1015 this->palents[start+i].peBlue = palent[i].peBlue;
1016 this->palents[start+i].peGreen = palent[i].peGreen;
1017 this->palents[start+i].peFlags = palent[i].peFlags;
1022 static HRESULT WINAPI DGA_IDirectDrawPalette_SetEntries(
1023 LPDIRECTDRAWPALETTE this,DWORD x,DWORD start,DWORD count,LPPALETTEENTRY palent
1025 #ifdef HAVE_LIBXXF86DGA
1030 TRACE(ddraw,"(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",
1031 this,x,start,count,palent
1033 if (!this->cm) /* should not happen */ {
1034 FIXME(ddraw,"app tried to set colormap in non-palettized mode\n");
1035 return DDERR_GENERIC;
1037 /* FIXME: free colorcells instead of freeing whole map */
1039 this->cm = TSXCopyColormapAndFree(display,this->cm);
1040 TSXFreeColormap(display,cm);
1042 for (i=0;i<count;i++) {
1043 xc.red = palent[i].peRed<<8;
1044 xc.blue = palent[i].peBlue<<8;
1045 xc.green = palent[i].peGreen<<8;
1046 xc.flags = DoRed|DoBlue|DoGreen;
1049 TSXStoreColor(display,this->cm,&xc);
1051 this->palents[start+i].peRed = palent[i].peRed;
1052 this->palents[start+i].peBlue = palent[i].peBlue;
1053 this->palents[start+i].peGreen = palent[i].peGreen;
1054 this->palents[start+i].peFlags = palent[i].peFlags;
1056 TSXF86DGAInstallColormap(display,DefaultScreen(display),this->cm);
1058 #else /* defined(HAVE_LIBXXF86DGA) */
1059 return E_UNEXPECTED;
1060 #endif /* defined(HAVE_LIBXXF86DGA) */
1063 static ULONG WINAPI IDirectDrawPalette_Release(LPDIRECTDRAWPALETTE this) {
1064 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1065 if (!--(this->ref)) {
1067 TSXFreeColormap(display,this->cm);
1070 HeapFree(GetProcessHeap(),0,this);
1076 static ULONG WINAPI IDirectDrawPalette_AddRef(LPDIRECTDRAWPALETTE this) {
1078 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1079 return ++(this->ref);
1082 static HRESULT WINAPI IDirectDrawPalette_Initialize(
1083 LPDIRECTDRAWPALETTE this,LPDIRECTDRAW ddraw,DWORD x,LPPALETTEENTRY palent
1085 return DDERR_ALREADYINITIALIZED;
1088 static HRESULT WINAPI IDirectDrawPalette_GetCaps(
1089 LPDIRECTDRAWPALETTE this, LPDWORD lpdwCaps )
1091 FIXME( ddraw, "(%p)->(%p) stub.\n", this, lpdwCaps );
1095 static HRESULT WINAPI IDirectDrawPalette_QueryInterface(
1096 LPDIRECTDRAWPALETTE this,REFIID refiid,LPVOID *obj )
1100 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1101 FIXME(ddraw,"(%p)->(%s,%p) stub.\n",this,xrefiid,obj);
1106 static struct IDirectDrawPalette_VTable dga_ddpalvt = {
1107 IDirectDrawPalette_QueryInterface,
1108 IDirectDrawPalette_AddRef,
1109 IDirectDrawPalette_Release,
1110 IDirectDrawPalette_GetCaps,
1111 IDirectDrawPalette_GetEntries,
1112 IDirectDrawPalette_Initialize,
1113 DGA_IDirectDrawPalette_SetEntries
1116 static struct IDirectDrawPalette_VTable xlib_ddpalvt = {
1117 IDirectDrawPalette_QueryInterface,
1118 IDirectDrawPalette_AddRef,
1119 IDirectDrawPalette_Release,
1120 IDirectDrawPalette_GetCaps,
1121 IDirectDrawPalette_GetEntries,
1122 IDirectDrawPalette_Initialize,
1123 Xlib_IDirectDrawPalette_SetEntries
1126 static HRESULT WINAPI IDirect3D_QueryInterface(
1127 LPDIRECT3D this,REFIID refiid,LPVOID *obj
1129 /* FIXME: Not sure if this is correct */
1132 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1133 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
1134 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
1136 this->lpvtbl->fnAddRef(this);
1139 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
1142 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1144 d3d->ddraw = (LPDIRECTDRAW)this;
1145 this->lpvtbl->fnAddRef(this);
1146 d3d->lpvtbl = &d3dvt;
1150 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D))) {
1153 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1155 d3d->ddraw = (LPDIRECTDRAW)this;
1156 this->lpvtbl->fnAddRef(this);
1157 d3d->lpvtbl = &d3d2vt;
1161 FIXME(ddraw,"(%p):interface for IID %s NOT found!\n",this,xrefiid);
1162 return OLE_E_ENUM_NOMORE;
1165 static ULONG WINAPI IDirect3D_AddRef(LPDIRECT3D this) {
1166 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1168 return ++(this->ref);
1171 static ULONG WINAPI IDirect3D_Release(LPDIRECT3D this)
1173 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1175 if (!--(this->ref)) {
1176 this->ddraw->lpvtbl->fnRelease(this->ddraw);
1177 HeapFree(GetProcessHeap(),0,this);
1183 static HRESULT WINAPI IDirect3D_Initialize(
1184 LPDIRECT3D this, REFIID refiid )
1186 /* FIXME: Not sure if this is correct */
1189 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1190 FIXME(ddraw,"(%p)->(%s):stub.\n",this,xrefiid);
1192 return DDERR_ALREADYINITIALIZED;
1195 /*******************************************************************************
1198 static struct IDirect3D_VTable d3dvt = {
1199 (void*)IDirect3D_QueryInterface,
1200 (void*)IDirect3D_AddRef,
1201 (void*)IDirect3D_Release,
1202 IDirect3D_Initialize,
1210 /*******************************************************************************
1213 static ULONG WINAPI IDirect3D2_Release(LPDIRECT3D2 this) {
1214 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1216 if (!--(this->ref)) {
1217 this->ddraw->lpvtbl->fnRelease(this->ddraw);
1218 HeapFree(GetProcessHeap(),0,this);
1224 static HRESULT WINAPI IDirect3D2_EnumDevices(
1225 LPDIRECT3D2 this,LPD3DENUMDEVICESCALLBACK cb, LPVOID context
1227 D3DDEVICEDESC d1,d2;
1229 FIXME(ddraw,"(%p)->(%p,%p),stub!\n",this,cb,context);
1230 d1.dwSize = sizeof(d1);
1233 d2.dwSize = sizeof(d2);
1235 cb((void*)&IID_IDirect3DHALDevice,"WINE Direct3D HAL","direct3d",&d1,&d2,context);
1239 static struct IDirect3D2_VTable d3d2vt = {
1243 IDirect3D2_EnumDevices,
1251 /*******************************************************************************
1255 /* Used in conjunction with cbWndExtra for storage of the this ptr for the window.
1256 * Please adjust allocation in Xlib_DirectDrawCreate if you store more data here.
1258 static INT32 ddrawXlibThisOffset = 0;
1260 static HRESULT WINAPI DGA_IDirectDraw2_CreateSurface(
1261 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsd,LPDIRECTDRAWSURFACE *lpdsf,IUnknown *lpunk
1263 #ifdef HAVE_LIBXXF86DGA
1266 TRACE(ddraw, "(%p)->(%p,%p,%p)\n",this,lpddsd,lpdsf,lpunk);
1267 if (TRACE_ON(ddraw)) {
1268 DUMP("[w=%ld,h=%ld,flags ",lpddsd->dwWidth,lpddsd->dwHeight);
1269 _dump_DDSD(lpddsd->dwFlags);
1270 fprintf(stderr,"caps ");
1271 _dump_DDSCAPS(lpddsd->ddsCaps.dwCaps);
1272 fprintf(stderr,"]\n");
1275 *lpdsf = (LPDIRECTDRAWSURFACE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface));
1276 this->lpvtbl->fnAddRef(this);
1278 (*lpdsf)->lpvtbl = (LPDIRECTDRAWSURFACE_VTABLE)&dga_dds3vt;
1279 if ( (lpddsd->dwFlags & DDSD_CAPS) &&
1280 (lpddsd->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN)
1282 if (!(lpddsd->dwFlags & DDSD_WIDTH))
1283 lpddsd->dwWidth = this->e.dga.fb_width;
1284 if (!(lpddsd->dwFlags & DDSD_HEIGHT))
1285 lpddsd->dwHeight = this->e.dga.fb_height;
1286 (*lpdsf)->s.surface = (LPBYTE)HeapAlloc(GetProcessHeap(),0,lpddsd->dwWidth*lpddsd->dwHeight*this->d.depth/8);
1287 (*lpdsf)->t.dga.fb_height = -1;
1288 (*lpdsf)->s.lpitch = lpddsd->dwWidth*this->d.depth/8;
1289 TRACE(ddraw,"using system memory for a primary surface\n");
1292 if (!(this->e.dga.vpmask & (1<<i)))
1294 TRACE(ddraw,"using viewport %d for a primary surface\n",i);
1295 /* if i == 32 or maximum ... return error */
1296 this->e.dga.vpmask|=(1<<i);
1297 (*lpdsf)->s.surface = this->e.dga.fb_addr+((i*this->e.dga.fb_height)*this->e.dga.fb_width*this->d.depth/8);
1298 (*lpdsf)->t.dga.fb_height = i*this->e.dga.fb_height;
1299 (*lpdsf)->s.lpitch = this->e.dga.fb_width*this->d.depth/8;
1302 lpddsd->lPitch = (*lpdsf)->s.lpitch;
1304 (*lpdsf)->s.width = this->d.width;
1305 (*lpdsf)->s.height = this->d.height;
1306 (*lpdsf)->s.ddraw = this;
1307 (*lpdsf)->s.backbuffer = NULL;
1308 if (lpddsd->dwFlags & DDSD_BACKBUFFERCOUNT) {
1309 LPDIRECTDRAWSURFACE3 back;
1311 if (lpddsd->dwBackBufferCount>1)
1312 FIXME(ddraw,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd->dwBackBufferCount);
1314 (*lpdsf)->s.backbuffer = back = (LPDIRECTDRAWSURFACE3)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface3));
1315 this->lpvtbl->fnAddRef(this);
1317 back->lpvtbl = (LPDIRECTDRAWSURFACE3_VTABLE)&dga_dds3vt;
1319 if (!(this->e.dga.vpmask & (1<<i)))
1321 TRACE(ddraw,"using viewport %d for backbuffer\n",i);
1322 /* if i == 32 or maximum ... return error */
1323 this->e.dga.vpmask|=(1<<i);
1324 back->s.surface = this->e.dga.fb_addr+((i*this->e.dga.fb_height)*this->e.dga.fb_width*this->d.depth/8);
1325 back->t.dga.fb_height = i*this->e.dga.fb_height;
1327 back->s.width = this->d.width;
1328 back->s.height = this->d.height;
1329 back->s.ddraw = this;
1330 back->s.lpitch = this->e.dga.fb_width*this->d.depth/8;
1331 back->s.backbuffer = NULL; /* does not have a backbuffer, it is
1335 #else /* defined(HAVE_LIBXXF86DGA) */
1336 return E_UNEXPECTED;
1337 #endif /* defined(HAVE_LIBXXF86DGA) */
1340 static HRESULT WINAPI Xlib_IDirectDraw2_CreateSurface(
1341 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsd,LPDIRECTDRAWSURFACE *lpdsf,IUnknown *lpunk
1345 TRACE(ddraw, "(%p)->CreateSurface(%p,%p,%p)\n",
1346 this,lpddsd,lpdsf,lpunk);
1348 if (TRACE_ON(ddraw)) {
1349 fprintf(stderr,"[w=%ld,h=%ld,flags ",lpddsd->dwWidth,lpddsd->dwHeight);
1350 _dump_DDSD(lpddsd->dwFlags);
1351 fprintf(stderr,"caps ");
1352 _dump_DDSCAPS(lpddsd->ddsCaps.dwCaps);
1353 fprintf(stderr,"]\n");
1356 *lpdsf = (LPDIRECTDRAWSURFACE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface));
1358 this->lpvtbl->fnAddRef(this);
1359 (*lpdsf)->s.ddraw = this;
1361 (*lpdsf)->lpvtbl = (LPDIRECTDRAWSURFACE_VTABLE)&xlib_dds3vt;
1363 if ( (lpddsd->dwFlags & DDSD_CAPS) &&
1364 (lpddsd->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN)
1366 if (!(lpddsd->dwFlags & DDSD_WIDTH))
1367 lpddsd->dwWidth = this->d.width;
1368 if (!(lpddsd->dwFlags & DDSD_HEIGHT))
1369 lpddsd->dwHeight = this->d.height;
1370 TRACE(ddraw,"using system memory for a primary surface\n");
1372 TRACE(ddraw,"using standard XImage for a primary surface\n");
1373 /* FIXME: !8 bit images */
1374 if (!(lpddsd->dwFlags & DDSD_WIDTH))
1375 lpddsd->dwWidth = this->d.width;
1376 if (!(lpddsd->dwFlags & DDSD_HEIGHT))
1377 lpddsd->dwHeight = this->d.height;
1380 (*lpdsf)->s.surface = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,lpddsd->dwHeight*lpddsd->dwWidth*this->d.depth/8);
1381 (*lpdsf)->s.width = lpddsd->dwWidth;
1382 (*lpdsf)->s.height = lpddsd->dwHeight;
1385 (*lpdsf)->t.xlib.image = img =
1386 TSXCreateImage( display,
1387 DefaultVisualOfScreen(screen),
1391 (*lpdsf)->s.surface,
1396 /* FIXME: !8 bit images */
1398 /* END FIXME: Xlib */
1401 (*lpdsf)->s.lpitch = img->bytes_per_line;
1402 if (lpddsd->dwFlags & DDSD_BACKBUFFERCOUNT) {
1403 LPDIRECTDRAWSURFACE3 back;
1405 if (lpddsd->dwBackBufferCount>1)
1406 FIXME(ddraw,"urks, wants to have more than one backbuffer (%ld)!\n",lpddsd->dwBackBufferCount);
1408 (*lpdsf)->s.backbuffer = back = (LPDIRECTDRAWSURFACE3)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawSurface3));
1410 this->lpvtbl->fnAddRef(this);
1411 back->s.ddraw = this;
1414 back->lpvtbl = (LPDIRECTDRAWSURFACE3_VTABLE)&xlib_dds3vt;
1415 /* FIXME: !8 bit images */
1416 back->s.surface = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
1417 img->width*img->height
1419 back->t.xlib.image = TSXCreateImage(
1421 DefaultVisualOfScreen(screen),
1430 /* FIXME: !8 bit images */
1432 back->s.width = this->d.width;
1433 back->s.height = this->d.height;
1434 back->s.lpitch = back->t.xlib.image->bytes_per_line;
1435 back->s.backbuffer = NULL; /* does not have a backbuffer, it is
1441 static HRESULT WINAPI IDirectDraw2_DuplicateSurface(
1442 LPDIRECTDRAW2 this,LPDIRECTDRAWSURFACE src,LPDIRECTDRAWSURFACE *dst
1444 FIXME(ddraw,"(%p)->(%p,%p) simply copies\n",this,src,dst);
1445 *dst = src; /* FIXME */
1449 static HRESULT WINAPI IDirectDraw2_SetCooperativeLevel(
1450 LPDIRECTDRAW2 this,HWND32 hwnd,DWORD cooplevel
1457 FE(DDSCL_FULLSCREEN)
1458 FE(DDSCL_ALLOWREBOOT)
1459 FE(DDSCL_NOWINDOWCHANGES)
1461 FE(DDSCL_ALLOWMODEX)
1463 FE(DDSCL_SETFOCUSWINDOW)
1464 FE(DDSCL_SETDEVICEWINDOW)
1465 FE(DDSCL_CREATEDEVICEWINDOW)
1468 TRACE(ddraw,"(%p)->(%08lx,%08lx)\n",this,(DWORD)hwnd,cooplevel);
1469 if(TRACE_ON(ddraw)){
1470 dbg_decl_str(ddraw, 512);
1471 for (i=0;i<sizeof(flagmap)/sizeof(flagmap[0]);i++)
1472 if (flagmap[i].mask & cooplevel)
1473 dsprintf(ddraw, "%s ", flagmap[i].name);
1474 TRACE(ddraw," cooperative level %s\n", dbg_str(ddraw));
1476 this->d.mainWindow = hwnd;
1481 static HRESULT WINAPI DGA_IDirectDraw_SetDisplayMode(
1482 LPDIRECTDRAW this,DWORD width,DWORD height,DWORD depth
1484 #ifdef HAVE_LIBXXF86DGA
1485 int i,*depths,depcount;
1487 TRACE(ddraw, "(%p)->(%ld,%ld,%ld)\n", this, width, height, depth);
1489 depths = TSXListDepths(display,DefaultScreen(display),&depcount);
1490 for (i=0;i<depcount;i++)
1491 if (depths[i]==depth)
1494 if (i==depcount) {/* not found */
1495 ERR(ddraw,"(w=%ld,h=%ld,d=%ld), unsupported depth!\n",width,height,depth);
1496 return DDERR_UNSUPPORTEDMODE;
1498 if (this->d.width < width) {
1499 ERR(ddraw,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld\n",width,height,depth,width,this->d.width);
1500 return DDERR_UNSUPPORTEDMODE;
1502 this->d.width = width;
1503 this->d.height = height;
1504 /* adjust fb_height, so we don't overlap */
1505 if (this->e.dga.fb_height < height)
1506 this->e.dga.fb_height = height;
1507 this->d.depth = depth;
1509 /* FIXME: this function OVERWRITES several signal handlers.
1510 * can we save them? and restore them later? In a way that
1511 * it works for the library too?
1513 TSXF86DGADirectVideo(display,DefaultScreen(display),XF86DGADirectGraphics);
1515 TSXF86DGASetViewPort(display,DefaultScreen(display),0,this->e.dga.fb_height);
1518 #ifdef RESTORE_SIGNALS
1519 SIGNAL_InitEmulator();
1522 #else /* defined(HAVE_LIBXXF86DGA) */
1523 return E_UNEXPECTED;
1524 #endif /* defined(HAVE_LIBXXF86DGA) */
1527 static HRESULT WINAPI Xlib_IDirectDraw_SetDisplayMode(
1528 LPDIRECTDRAW this,DWORD width,DWORD height,DWORD depth
1530 int i,*depths,depcount;
1533 TRACE(ddraw, "(%p)->SetDisplayMode(%ld,%ld,%ld)\n",
1534 this, width, height, depth);
1536 depths = TSXListDepths(display,DefaultScreen(display),&depcount);
1537 for (i=0;i<depcount;i++)
1538 if (depths[i]==depth)
1541 if (i==depcount) {/* not found */
1542 sprintf(buf,"SetDisplayMode(w=%ld,h=%ld,d=%ld), unsupported depth!",width,height,depth);
1543 MessageBox32A(0,buf,"WINE DirectDraw",MB_OK|MB_ICONSTOP);
1544 return DDERR_UNSUPPORTEDMODE;
1547 if (this->d.width < width) {
1548 sprintf(buf,"SetDisplayMode(w=%ld,h=%ld,d=%ld), width %ld exceeds framebuffer width %ld",width,height,depth,width,this->d.width);
1549 MessageBox32A(0,buf,"WINE DirectDraw",MB_OK|MB_ICONSTOP);
1550 return DDERR_UNSUPPORTEDMODE;
1553 this->e.xlib.window = CreateWindowEx32A(
1557 WS_VISIBLE|WS_SYSMENU|WS_THICKFRAME,
1567 /* Store this with the window. We'll use it for the window procedure */
1568 SetWindowLong32A(this->e.xlib.window,ddrawXlibThisOffset,(LONG)this);
1570 this->e.xlib.paintable = 1;
1572 ShowWindow32(this->e.xlib.window,TRUE);
1573 UpdateWindow32(this->e.xlib.window);
1575 assert(this->e.xlib.window);
1577 this->e.xlib.drawable = WIN_FindWndPtr(this->e.xlib.window)->window;
1579 /* We don't have a context for this window. Host off the desktop */
1580 if( !this->e.xlib.drawable )
1582 this->e.xlib.drawable = WIN_GetDesktop()->window;
1585 this->d.width = width;
1586 this->d.height = height;
1587 /* adjust fb_height, so we don't overlap */
1589 if (this->e.dga.fb_height < height)
1590 this->e.dga.fb_height = height; */
1591 this->d.depth = depth;
1595 static HRESULT WINAPI DGA_IDirectDraw2_GetCaps(
1596 LPDIRECTDRAW2 this,LPDDCAPS caps1,LPDDCAPS caps2
1598 #ifdef HAVE_LIBXXF86DGA
1599 TRACE(ddraw,"(%p)->GetCaps(%p,%p)\n",this,caps1,caps2);
1600 caps1->dwVidMemTotal = this->e.dga.fb_memsize;
1601 caps1->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
1602 caps1->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
1604 caps2->dwVidMemTotal = this->e.dga.fb_memsize;
1605 caps2->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
1606 caps2->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
1609 #else /* defined(HAVE_LIBXXF86DGA) */
1610 return E_UNEXPECTED;
1611 #endif /* defined(HAVE_LIBXXF86DGA) */
1614 static HRESULT WINAPI Xlib_IDirectDraw2_GetCaps(
1615 LPDIRECTDRAW2 this,LPDDCAPS caps1,LPDDCAPS caps2
1617 TRACE(ddraw,"(%p)->GetCaps(%p,%p)\n",this,caps1,caps2);
1619 caps1->dwVidMemTotal = 2048*1024;
1620 caps1->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
1621 caps1->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
1623 caps2->dwVidMemTotal = 2048*1024;
1624 caps2->dwCaps = 0xffffffff&~(DDCAPS_BANKSWITCHED); /* we can do anything */
1625 caps2->ddsCaps.dwCaps = 0xffffffff; /* we can do anything */
1627 /* END FIXME: Xlib */
1631 static HRESULT WINAPI IDirectDraw2_CreateClipper(
1632 LPDIRECTDRAW2 this,DWORD x,LPDIRECTDRAWCLIPPER *lpddclip,LPUNKNOWN lpunk
1634 FIXME(ddraw,"(%p)->(%08lx,%p,%p),stub!\n",
1635 this,x,lpddclip,lpunk
1637 *lpddclip = (LPDIRECTDRAWCLIPPER)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawClipper));
1638 (*lpddclip)->ref = 1;
1639 (*lpddclip)->lpvtbl = &ddclipvt;
1643 static HRESULT WINAPI common_IDirectDraw2_CreatePalette(
1644 LPDIRECTDRAW2 this,DWORD x,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk
1646 *lpddpal = (LPDIRECTDRAWPALETTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawPalette));
1647 if (*lpddpal == NULL) return E_OUTOFMEMORY;
1648 (*lpddpal)->ref = 1;
1649 (*lpddpal)->ddraw = (LPDIRECTDRAW)this;
1650 (*lpddpal)->installed = 0;
1651 if (this->d.depth<=8) {
1652 (*lpddpal)->cm = TSXCreateColormap(display,DefaultRootWindow(display),DefaultVisualOfScreen(screen),AllocAll);
1654 /* we don't want palettes in hicolor or truecolor */
1660 static HRESULT WINAPI DGA_IDirectDraw2_CreatePalette(
1661 LPDIRECTDRAW2 this,DWORD x,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk
1664 TRACE(ddraw,"(%p)->(%08lx,%p,%p,%p)\n",this,x,palent,lpddpal,lpunk);
1665 res = common_IDirectDraw2_CreatePalette(this,x,palent,lpddpal,lpunk);
1666 if (res != 0) return res;
1667 (*lpddpal)->lpvtbl = &dga_ddpalvt;
1671 static HRESULT WINAPI Xlib_IDirectDraw2_CreatePalette(
1672 LPDIRECTDRAW2 this,DWORD x,LPPALETTEENTRY palent,LPDIRECTDRAWPALETTE *lpddpal,LPUNKNOWN lpunk
1674 TRACE(ddraw,"(%p)->(%08lx,%p,%p,%p)\n",this,x,palent,lpddpal,lpunk);
1675 *lpddpal = (LPDIRECTDRAWPALETTE)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDrawPalette));
1676 if (*lpddpal == NULL) return E_OUTOFMEMORY;
1677 (*lpddpal)->ref = 1;
1678 (*lpddpal)->installed = 0;
1680 (*lpddpal)->ddraw = (LPDIRECTDRAW)this;
1681 this->lpvtbl->fnAddRef(this);
1683 if (this->d.depth<=8) {
1684 (*lpddpal)->cm = TSXCreateColormap(display,this->e.xlib.drawable,DefaultVisualOfScreen(screen),AllocAll);
1685 /* later installed ...
1686 * TSXInstallColormap(display,(*lpddpal)->cm);
1687 * TSXSetWindowColormap(display,this->e.xlib.drawable,(*lpddpal)->cm);
1689 TSXInstallColormap(display,(*lpddpal)->cm);
1693 /* we don't want palettes in hicolor or truecolor */
1697 (*lpddpal)->lpvtbl = &xlib_ddpalvt;
1701 static HRESULT WINAPI DGA_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2 this) {
1702 #ifdef HAVE_LIBXXF86DGA
1703 TRACE(ddraw, "(%p)->()\n",this);
1705 TSXF86DGADirectVideo(display,DefaultScreen(display),0);
1706 #ifdef RESTORE_SIGNALS
1707 SIGNAL_InitEmulator();
1710 #else /* defined(HAVE_LIBXXF86DGA) */
1711 return E_UNEXPECTED;
1715 static HRESULT WINAPI Xlib_IDirectDraw2_RestoreDisplayMode(LPDIRECTDRAW2 this) {
1716 TRACE(ddraw, "(%p)->RestoreDisplayMode()\n", this);
1721 static HRESULT WINAPI IDirectDraw2_WaitForVerticalBlank(
1722 LPDIRECTDRAW2 this,DWORD x,HANDLE32 h
1724 TRACE(ddraw,"(%p)->(0x%08lx,0x%08x)\n",this,x,h);
1728 static ULONG WINAPI IDirectDraw2_AddRef(LPDIRECTDRAW2 this) {
1729 TRACE( ddraw, "(%p)->() incrementing from %lu.\n", this, this->ref );
1731 return ++(this->ref);
1734 static ULONG WINAPI DGA_IDirectDraw2_Release(LPDIRECTDRAW2 this) {
1735 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1737 #ifdef HAVE_LIBXXF86DGA
1738 if (!--(this->ref)) {
1739 TSXF86DGADirectVideo(display,DefaultScreen(display),0);
1740 #ifdef RESTORE_SIGNALS
1741 SIGNAL_InitEmulator();
1743 HeapFree(GetProcessHeap(),0,this);
1746 #endif /* defined(HAVE_LIBXXF86DGA) */
1750 static ULONG WINAPI Xlib_IDirectDraw2_Release(LPDIRECTDRAW2 this) {
1751 TRACE( ddraw, "(%p)->() decrementing from %lu.\n", this, this->ref );
1753 if (!--(this->ref)) {
1754 HeapFree(GetProcessHeap(),0,this);
1757 /* FIXME: destroy window ... */
1761 static HRESULT WINAPI DGA_IDirectDraw2_QueryInterface(
1762 LPDIRECTDRAW2 this,REFIID refiid,LPVOID *obj
1766 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1767 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
1768 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
1770 this->lpvtbl->fnAddRef(this);
1773 if (!memcmp(&IID_IDirectDraw,refiid,sizeof(IID_IDirectDraw))) {
1774 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&dga_ddvt;
1775 this->lpvtbl->fnAddRef(this);
1779 if (!memcmp(&IID_IDirectDraw2,refiid,sizeof(IID_IDirectDraw2))) {
1780 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&dga_dd2vt;
1781 this->lpvtbl->fnAddRef(this);
1785 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
1788 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1790 d3d->ddraw = (LPDIRECTDRAW)this;
1791 this->lpvtbl->fnAddRef(this);
1792 d3d->lpvtbl = &d3dvt;
1796 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D))) {
1799 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1801 d3d->ddraw = (LPDIRECTDRAW)this;
1802 this->lpvtbl->fnAddRef(this);
1803 d3d->lpvtbl = &d3d2vt;
1807 WARN(ddraw,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid);
1808 return OLE_E_ENUM_NOMORE;
1811 static HRESULT WINAPI Xlib_IDirectDraw2_QueryInterface(
1812 LPDIRECTDRAW2 this,REFIID refiid,LPVOID *obj
1816 WINE_StringFromCLSID((LPCLSID)refiid,xrefiid);
1817 TRACE(ddraw,"(%p)->(%s,%p)\n",this,xrefiid,obj);
1818 if (!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown))) {
1820 this->lpvtbl->fnAddRef(this);
1823 if (!memcmp(&IID_IDirectDraw,refiid,sizeof(IID_IDirectDraw))) {
1824 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&xlib_ddvt;
1825 this->lpvtbl->fnAddRef(this);
1829 if (!memcmp(&IID_IDirectDraw2,refiid,sizeof(IID_IDirectDraw2))) {
1830 this->lpvtbl = (LPDIRECTDRAW2_VTABLE)&xlib_dd2vt;
1831 this->lpvtbl->fnAddRef(this);
1835 if (!memcmp(&IID_IDirect3D,refiid,sizeof(IID_IDirect3D))) {
1838 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1840 d3d->ddraw = (LPDIRECTDRAW)this;
1841 this->lpvtbl->fnAddRef(this);
1842 d3d->lpvtbl = &d3dvt;
1846 if (!memcmp(&IID_IDirect3D2,refiid,sizeof(IID_IDirect3D))) {
1849 d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
1851 d3d->ddraw = (LPDIRECTDRAW)this;
1852 this->lpvtbl->fnAddRef(this);
1853 d3d->lpvtbl = &d3d2vt;
1857 WARN(ddraw,"(%p):interface for IID %s _NOT_ found!\n",this,xrefiid);
1858 return OLE_E_ENUM_NOMORE;
1861 static HRESULT WINAPI IDirectDraw2_GetVerticalBlankStatus(
1862 LPDIRECTDRAW2 this,BOOL32 *status
1864 TRACE(ddraw,"(%p)->(%p)\n",this,status);
1869 static HRESULT WINAPI IDirectDraw2_EnumDisplayModes(
1870 LPDIRECTDRAW2 this,DWORD dwFlags,LPDDSURFACEDESC lpddsfd,LPVOID context,LPDDENUMMODESCALLBACK modescb
1872 DDSURFACEDESC ddsfd;
1874 TRACE(ddraw,"(%p)->(0x%08lx,%p,%p,%p)\n",this,dwFlags,lpddsfd,context,modescb);
1876 _getpixelformat(this,&(ddsfd.ddpfPixelFormat));
1877 ddsfd.dwSize = sizeof(ddsfd);
1878 ddsfd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
1879 if (dwFlags & DDEDM_REFRESHRATES) {
1880 ddsfd.dwFlags |= DDSD_REFRESHRATE;
1881 ddsfd.x.dwRefreshRate = 60;
1884 ddsfd.dwWidth = 640;
1885 ddsfd.dwHeight = 480;
1886 ddsfd.dwBackBufferCount = 1;
1887 ddsfd.ddsCaps.dwCaps = DDSCAPS_PALETTE;
1889 if (!modescb(&ddsfd,context)) return 0;
1891 ddsfd.dwWidth = 800;
1892 ddsfd.dwHeight = 600;
1893 if (!modescb(&ddsfd,context)) return 0;
1895 if (!(dwFlags & DDEDM_STANDARDVGAMODES)) {
1896 /* modeX is not standard VGA */
1898 ddsfd.dwHeight = 200;
1899 ddsfd.dwWidth = 320;
1900 if (!modescb(&ddsfd,context)) return 0;
1905 static HRESULT WINAPI DGA_IDirectDraw2_GetDisplayMode(
1906 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsfd
1908 #ifdef HAVE_LIBXXF86DGA
1909 TRACE(ddraw,"(%p)->(%p)\n",this,lpddsfd);
1910 lpddsfd->dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PITCH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
1911 lpddsfd->dwHeight = screenHeight;
1912 lpddsfd->dwWidth = screenWidth;
1913 lpddsfd->lPitch = this->e.dga.fb_width*this->d.depth/8;
1914 lpddsfd->dwBackBufferCount = 1;
1915 lpddsfd->x.dwRefreshRate = 60;
1916 lpddsfd->ddsCaps.dwCaps = DDSCAPS_PALETTE;
1917 _getpixelformat(this,&(lpddsfd->ddpfPixelFormat));
1919 #else /* defined(HAVE_LIBXXF86DGA) */
1920 return E_UNEXPECTED;
1921 #endif /* defined(HAVE_LIBXXF86DGA) */
1924 static HRESULT WINAPI Xlib_IDirectDraw2_GetDisplayMode(
1925 LPDIRECTDRAW2 this,LPDDSURFACEDESC lpddsfd
1927 TRACE(ddraw,"(%p)->GetDisplayMode(%p)\n",this,lpddsfd);
1928 lpddsfd->dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PITCH|DDSD_BACKBUFFERCOUNT|DDSD_PIXELFORMAT|DDSD_CAPS;
1929 lpddsfd->dwHeight = screenHeight;
1930 lpddsfd->dwWidth = screenWidth;
1931 /* POOLE FIXME: Xlib */
1932 lpddsfd->lPitch = this->e.dga.fb_width*this->d.depth/8;
1933 /* END FIXME: Xlib */
1934 lpddsfd->dwBackBufferCount = 1;
1935 lpddsfd->x.dwRefreshRate = 60;
1936 lpddsfd->ddsCaps.dwCaps = DDSCAPS_PALETTE;
1937 _getpixelformat(this,&(lpddsfd->ddpfPixelFormat));
1941 static HRESULT WINAPI IDirectDraw2_FlipToGDISurface(LPDIRECTDRAW2 this) {
1942 TRACE(ddraw,"(%p)->()\n",this);
1946 static HRESULT WINAPI IDirectDraw2_GetMonitorFrequency(
1947 LPDIRECTDRAW2 this,LPDWORD freq
1949 FIXME(ddraw,"(%p)->(%p) returns 60 Hz always\n",this,freq);
1950 *freq = 60*100; /* 60 Hz */
1954 /* what can we directly decompress? */
1955 static HRESULT WINAPI IDirectDraw2_GetFourCCCodes(
1956 LPDIRECTDRAW2 this,LPDWORD x,LPDWORD y
1958 FIXME(ddraw,"(%p,%p,%p), stub\n",this,x,y);
1962 static HRESULT WINAPI IDirectDraw2_EnumSurfaces(
1963 LPDIRECTDRAW2 this,DWORD x,LPDDSURFACEDESC ddsfd,LPVOID context,LPDDENUMSURFACESCALLBACK ddsfcb
1965 FIXME(ddraw,"(%p)->(0x%08lx,%p,%p,%p),stub!\n",this,x,ddsfd,context,ddsfcb);
1969 static HRESULT WINAPI IDirectDraw2_Compact(
1970 LPDIRECTDRAW2 this )
1972 FIXME(ddraw,"(%p)->()\n", this );
1978 /* Note: Hack so we can reuse the old functions without compiler warnings */
1980 # define XCAST(fun) (typeof(dga_ddvt.fn##fun))
1982 # define XCAST(fun) (void*)
1985 static struct IDirectDraw_VTable dga_ddvt = {
1986 XCAST(QueryInterface)DGA_IDirectDraw2_QueryInterface,
1987 XCAST(AddRef)IDirectDraw2_AddRef,
1988 XCAST(Release)DGA_IDirectDraw2_Release,
1989 XCAST(Compact)IDirectDraw2_Compact,
1990 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
1991 XCAST(CreatePalette)DGA_IDirectDraw2_CreatePalette,
1992 XCAST(CreateSurface)DGA_IDirectDraw2_CreateSurface,
1993 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
1994 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
1995 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
1996 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
1997 XCAST(GetCaps)DGA_IDirectDraw2_GetCaps,
1998 XCAST(GetDisplayMode)DGA_IDirectDraw2_GetDisplayMode,
1999 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
2000 XCAST(GetGDISurface)15,
2001 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
2002 XCAST(GetScanLine)17,
2003 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
2004 XCAST(Initialize)19,
2005 XCAST(RestoreDisplayMode)DGA_IDirectDraw2_RestoreDisplayMode,
2006 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
2007 DGA_IDirectDraw_SetDisplayMode,
2008 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
2011 static struct IDirectDraw_VTable xlib_ddvt = {
2012 XCAST(QueryInterface)Xlib_IDirectDraw2_QueryInterface,
2013 XCAST(AddRef)IDirectDraw2_AddRef,
2014 XCAST(Release)Xlib_IDirectDraw2_Release,
2015 XCAST(Compact)IDirectDraw2_Compact,
2016 XCAST(CreateClipper)IDirectDraw2_CreateClipper,
2017 XCAST(CreatePalette)Xlib_IDirectDraw2_CreatePalette,
2018 XCAST(CreateSurface)Xlib_IDirectDraw2_CreateSurface,
2019 XCAST(DuplicateSurface)IDirectDraw2_DuplicateSurface,
2020 XCAST(EnumDisplayModes)IDirectDraw2_EnumDisplayModes,
2021 XCAST(EnumSurfaces)IDirectDraw2_EnumSurfaces,
2022 XCAST(FlipToGDISurface)IDirectDraw2_FlipToGDISurface,
2023 XCAST(GetCaps)Xlib_IDirectDraw2_GetCaps,
2024 XCAST(GetDisplayMode)Xlib_IDirectDraw2_GetDisplayMode,
2025 XCAST(GetFourCCCodes)IDirectDraw2_GetFourCCCodes,
2026 XCAST(GetGDISurface)15,
2027 XCAST(GetMonitorFrequency)IDirectDraw2_GetMonitorFrequency,
2028 XCAST(GetScanLine)17,
2029 XCAST(GetVerticalBlankStatus)IDirectDraw2_GetVerticalBlankStatus,
2030 XCAST(Initialize)19,
2031 XCAST(RestoreDisplayMode)Xlib_IDirectDraw2_RestoreDisplayMode,
2032 XCAST(SetCooperativeLevel)IDirectDraw2_SetCooperativeLevel,
2033 Xlib_IDirectDraw_SetDisplayMode,
2034 XCAST(WaitForVerticalBlank)IDirectDraw2_WaitForVerticalBlank,
2037 /*****************************************************************************
2043 static HRESULT WINAPI DGA_IDirectDraw2_SetDisplayMode(
2044 LPDIRECTDRAW2 this,DWORD width,DWORD height,DWORD depth,DWORD xx,DWORD yy
2046 return DGA_IDirectDraw_SetDisplayMode((LPDIRECTDRAW)this,width,height,depth);
2049 static HRESULT WINAPI Xlib_IDirectDraw2_SetDisplayMode(
2050 LPDIRECTDRAW2 this,DWORD width,DWORD height,DWORD depth,DWORD xx,DWORD yy
2052 return Xlib_IDirectDraw_SetDisplayMode((LPDIRECTDRAW)this,width,height,depth);
2055 static HRESULT WINAPI DGA_IDirectDraw2_GetAvailableVidMem(
2056 LPDIRECTDRAW2 this,LPDDSCAPS ddscaps,LPDWORD total,LPDWORD free
2058 TRACE(ddraw,"(%p)->(%p,%p,%p)\n",
2059 this,ddscaps,total,free
2061 if (total) *total = this->e.dga.fb_memsize * 1024;
2062 if (free) *free = this->e.dga.fb_memsize * 1024;
2066 static HRESULT WINAPI Xlib_IDirectDraw2_GetAvailableVidMem(
2067 LPDIRECTDRAW2 this,LPDDSCAPS ddscaps,LPDWORD total,LPDWORD free
2069 TRACE(ddraw,"(%p)->(%p,%p,%p)\n",
2070 this,ddscaps,total,free
2072 if (total) *total = 2048 * 1024;
2073 if (free) *free = 2048 * 1024;
2077 static IDirectDraw2_VTable dga_dd2vt = {
2078 DGA_IDirectDraw2_QueryInterface,
2079 IDirectDraw2_AddRef,
2080 DGA_IDirectDraw2_Release,
2081 IDirectDraw2_Compact,
2082 IDirectDraw2_CreateClipper,
2083 DGA_IDirectDraw2_CreatePalette,
2084 DGA_IDirectDraw2_CreateSurface,
2086 IDirectDraw2_EnumDisplayModes,
2087 IDirectDraw2_EnumSurfaces,
2088 IDirectDraw2_FlipToGDISurface,
2089 DGA_IDirectDraw2_GetCaps,
2090 DGA_IDirectDraw2_GetDisplayMode,
2091 IDirectDraw2_GetFourCCCodes,
2093 IDirectDraw2_GetMonitorFrequency,
2095 IDirectDraw2_GetVerticalBlankStatus,
2097 DGA_IDirectDraw2_RestoreDisplayMode,
2098 IDirectDraw2_SetCooperativeLevel,
2099 DGA_IDirectDraw2_SetDisplayMode,
2100 IDirectDraw2_WaitForVerticalBlank,
2101 DGA_IDirectDraw2_GetAvailableVidMem
2104 static struct IDirectDraw2_VTable xlib_dd2vt = {
2105 Xlib_IDirectDraw2_QueryInterface,
2106 IDirectDraw2_AddRef,
2107 Xlib_IDirectDraw2_Release,
2108 IDirectDraw2_Compact,
2109 IDirectDraw2_CreateClipper,
2110 Xlib_IDirectDraw2_CreatePalette,
2111 Xlib_IDirectDraw2_CreateSurface,
2113 IDirectDraw2_EnumDisplayModes,
2114 IDirectDraw2_EnumSurfaces,
2115 IDirectDraw2_FlipToGDISurface,
2116 Xlib_IDirectDraw2_GetCaps,
2117 Xlib_IDirectDraw2_GetDisplayMode,
2118 IDirectDraw2_GetFourCCCodes,
2120 IDirectDraw2_GetMonitorFrequency,
2122 IDirectDraw2_GetVerticalBlankStatus,
2124 Xlib_IDirectDraw2_RestoreDisplayMode,
2125 IDirectDraw2_SetCooperativeLevel,
2126 Xlib_IDirectDraw2_SetDisplayMode,
2127 IDirectDraw2_WaitForVerticalBlank,
2128 Xlib_IDirectDraw2_GetAvailableVidMem
2131 /******************************************************************************
2135 HRESULT WINAPI DGA_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) {
2136 #ifdef HAVE_LIBXXF86DGA
2137 int memsize,banksize,width,major,minor,flags,height;
2140 if (getuid() != 0) {
2141 MSG("Must be root to use XF86DGA!\n");
2142 MessageBox32A(0,"Using the XF86DGA extension requires the program to be run using UID 0.","WINE DirectDraw",MB_OK|MB_ICONSTOP);
2143 return E_UNEXPECTED;
2145 if (!DDRAW_DGA_Available()) {
2146 TRACE(ddraw,"No XF86DGA detected.\n");
2147 return DDERR_GENERIC;
2149 *lplpDD = (LPDIRECTDRAW)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDraw));
2150 (*lplpDD)->lpvtbl = &dga_ddvt;
2152 TSXF86DGAQueryVersion(display,&major,&minor);
2153 TRACE(ddraw,"XF86DGA is version %d.%d\n",major,minor);
2154 TSXF86DGAQueryDirectVideo(display,DefaultScreen(display),&flags);
2155 if (!(flags & XF86DGADirectPresent))
2156 MSG("direct video is NOT PRESENT.\n");
2157 TSXF86DGAGetVideo(display,DefaultScreen(display),&addr,&width,&banksize,&memsize);
2158 TRACE(ddraw,"video framebuffer: begin %p, width %d,banksize %d,memsize %d\n",
2159 addr,width,banksize,memsize
2161 (*lplpDD)->e.dga.fb_width = width;
2162 (*lplpDD)->d.width = width;
2163 (*lplpDD)->e.dga.fb_addr = addr;
2164 (*lplpDD)->e.dga.fb_memsize = memsize;
2165 (*lplpDD)->e.dga.fb_banksize = banksize;
2167 TSXF86DGAGetViewPortSize(display,DefaultScreen(display),&width,&height);
2168 TSXF86DGASetViewPort(display,DefaultScreen(display),0,0);
2169 (*lplpDD)->e.dga.fb_height = screenHeight;
2171 (*lplpDD)->e.dga.vpmask = 1;
2173 (*lplpDD)->e.dga.vpmask = 0;
2176 /* just assume the default depth is the DGA depth too */
2177 (*lplpDD)->d.depth = DefaultDepthOfScreen(screen);
2178 #ifdef RESTORE_SIGNALS
2179 SIGNAL_InitEmulator();
2182 #else /* defined(HAVE_LIBXXF86DGA) */
2183 return DDERR_INVALIDDIRECTDRAWGUID;
2184 #endif /* defined(HAVE_LIBXXF86DGA) */
2187 LRESULT WINAPI Xlib_DDWndProc(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
2190 LPDIRECTDRAW ddraw = NULL;
2193 /*FIXME(ddraw,"(0x%04x,%s,0x%08lx,0x%08lx),stub!\n",(int)hwnd,SPY_GetMsgName(msg),(long)wParam,(long)lParam); */
2195 SetLastError( ERROR_SUCCESS );
2196 ddraw = (LPDIRECTDRAW)GetWindowLong32A( hwnd, ddrawXlibThisOffset );
2198 ( ( lastError = GetLastError() ) != ERROR_SUCCESS )
2201 ERR( ddraw, "Unable to retrieve this ptr from window. Error %08lx\n", lastError );
2206 /* Perform any special direct draw functions */
2209 ddraw->e.xlib.paintable = 1;
2212 /* Now let the application deal with the rest of this */
2213 if( ddraw->d.mainWindow )
2216 /* Don't think that we actually need to call this but...
2217 might as well be on the safe side of things... */
2218 ret = DefWindowProc32A( hwnd, msg, wParam, lParam );
2222 /* We didn't handle the message - give it to the application */
2223 ret = CallWindowProc32A( WIN_FindWndPtr( ddraw->d.mainWindow )->winproc,
2224 ddraw->d.mainWindow, msg, wParam, lParam );
2230 ret = DefWindowProc32A( ddraw->d.mainWindow, msg, wParam, lParam );
2236 ret = DefWindowProc32A(hwnd,msg,wParam,lParam);
2242 HRESULT WINAPI Xlib_DirectDrawCreate( LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter) {
2247 *lplpDD = (LPDIRECTDRAW)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectDraw));
2248 (*lplpDD)->lpvtbl = &xlib_ddvt;
2250 (*lplpDD)->e.xlib.drawable = 0; /* in SetDisplayMode */
2251 (*lplpDD)->e.xlib.use_xshm = have_xshm;
2252 wc.style = CS_GLOBALCLASS;
2253 wc.lpfnWndProc = Xlib_DDWndProc;
2255 wc.cbWndExtra = /* Defines extra mem for window. This is used for storing this */
2256 sizeof( LPDIRECTDRAW ); /* ddrawXlibThisOffset */
2258 /* We can be a child of the desktop since we're really important */
2259 pParentWindow = WIN_GetDesktop();
2260 wc.hInstance = pParentWindow ? pParentWindow->hwndSelf : 0;
2264 wc.hCursor = (HCURSOR32)IDC_ARROW32A;
2265 wc.hbrBackground= NULL_BRUSH;
2266 wc.lpszMenuName = 0;
2267 wc.lpszClassName= "WINE_DirectDraw";
2269 (*lplpDD)->e.xlib.winclass = RegisterClass32A(&wc);
2271 (*lplpDD)->d.depth = DefaultDepthOfScreen(screen);
2272 (*lplpDD)->d.height = screenHeight;
2273 (*lplpDD)->d.width = screenWidth;
2277 HRESULT WINAPI DirectDrawCreate( LPGUID lpGUID, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter ) {
2281 WINE_StringFromCLSID(lpGUID,xclsid);
2283 sprintf(xclsid,"<guid-%0x08x>",(int)lpGUID);
2287 TRACE(ddraw,"(%s,%p,%p)\n",xclsid,lplpDD,pUnkOuter);
2290 /* if they didn't request a particular interface, use the best
2292 if (DDRAW_DGA_Available())
2293 lpGUID = &DGA_DirectDraw_GUID;
2295 lpGUID = &XLIB_DirectDraw_GUID;
2298 if (!memcmp(lpGUID, &DGA_DirectDraw_GUID, sizeof(GUID)))
2299 return DGA_DirectDrawCreate(lplpDD, pUnkOuter);
2300 else if (!memcmp(lpGUID, &XLIB_DirectDraw_GUID, sizeof(GUID)))
2301 return Xlib_DirectDrawCreate(lplpDD, pUnkOuter);
2303 fprintf(stderr,"DirectDrawCreate(%s,%p,%p): did not recognize requested GUID\n",xclsid,lplpDD,pUnkOuter);
2304 return DDERR_INVALIDDIRECTDRAWGUID;