Like the AUTORADIOBUTTON, the parent of a RADIOBUTTON style button
[wine] / dlls / ddraw / dsurface / dga.c
1 /*              DirectDrawSurface XF86DGA implementation
2  *
3  * Copyright 1997-2000 Marcus Meissner
4  * Copyright 1998-2000 Lionel Ulmer (most of Direct3D stuff)
5  */
6 #include "config.h"
7 #include "winerror.h"
8
9 #include <unistd.h>
10 #include <assert.h>
11 #include <fcntl.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15
16 #include "debugtools.h"
17 #include "dga_private.h"
18
19 DEFAULT_DEBUG_CHANNEL(ddraw);
20
21 #define DDPRIVATE(x) dga_dd_private *ddpriv = ((dga_dd_private*)(x)->private)
22 #define DPPRIVATE(x) dga_dp_private *dppriv = ((dga_dp_private*)(x)->private)
23 #define DSPRIVATE(x) dga_ds_private *dspriv = ((dga_ds_private*)(x)->private)
24
25 /******************************************************************************
26  *              IDirectDrawSurface methods
27  *
28  * Since DDS3 and DDS2 are supersets of DDS, we implement DDS3 and let
29  * DDS and DDS2 use those functions. (Function calls did not change (except
30  * using different DirectDrawSurfaceX version), just added flags and functions)
31  */
32
33 HRESULT WINAPI DGA_IDirectDrawSurface4Impl_Flip(
34     LPDIRECTDRAWSURFACE4 iface,LPDIRECTDRAWSURFACE4 flipto,DWORD dwFlags
35 ) {
36     ICOM_THIS(IDirectDrawSurface4Impl,iface);
37     DSPRIVATE(This);
38     dga_ds_private      *fspriv;
39     IDirectDrawSurface4Impl* iflipto=(IDirectDrawSurface4Impl*)flipto;
40     DWORD               xheight;
41     LPBYTE              surf;
42
43     TRACE("(%p)->Flip(%p,%08lx)\n",This,iflipto,dwFlags);
44     iflipto = _common_find_flipto(This,iflipto);
45
46     /* and flip! */
47     fspriv = (dga_ds_private*)iflipto->private;
48     TSXF86DGASetViewPort(display,DefaultScreen(display),0,fspriv->fb_height);
49     if (iflipto->s.palette) {
50         DPPRIVATE(iflipto);
51         
52         if (dppriv->cm)
53             TSXF86DGAInstallColormap(display,DefaultScreen(display),dppriv->cm);
54     }
55     while (!TSXF86DGAViewPortChanged(display,DefaultScreen(display),2)) {
56         /* EMPTY */
57     }
58     /* We need to switch the lowlevel surfaces, for DGA this is: */
59
60     /* The height within the framebuffer */
61     xheight             = dspriv->fb_height;
62     dspriv->fb_height   = fspriv->fb_height;
63     fspriv->fb_height   = xheight;
64
65     /* And the assciated surface pointer */
66     surf                                = This->s.surface_desc.u1.lpSurface;
67     This->s.surface_desc.u1.lpSurface   = iflipto->s.surface_desc.u1.lpSurface;
68     iflipto->s.surface_desc.u1.lpSurface= surf;
69     return DD_OK;
70 }
71
72 HRESULT WINAPI DGA_IDirectDrawSurface4Impl_SetPalette(
73     LPDIRECTDRAWSURFACE4 iface,LPDIRECTDRAWPALETTE pal
74 ) {
75     ICOM_THIS(IDirectDrawSurface4Impl,iface);
76     DDPRIVATE(This->s.ddraw);
77     IDirectDrawPaletteImpl* ipal=(IDirectDrawPaletteImpl*)pal;
78
79     TRACE("(%p)->(%p)\n",This,ipal);
80
81     /* According to spec, we are only supposed to 
82      * AddRef if this is not the same palette.
83      */
84     if( This->s.palette != ipal ) {
85         dga_dp_private  *fppriv;
86         if( ipal != NULL )
87             IDirectDrawPalette_AddRef( (IDirectDrawPalette*)ipal );
88         if( This->s.palette != NULL )
89             IDirectDrawPalette_Release( (IDirectDrawPalette*)This->s.palette );
90         This->s.palette = ipal;
91         fppriv = (dga_dp_private*)This->s.palette->private;
92         ddpriv->InstallColormap(display,DefaultScreen(display),fppriv->cm);
93     }
94     return DD_OK;
95 }
96
97 ULONG WINAPI DGA_IDirectDrawSurface4Impl_Release(LPDIRECTDRAWSURFACE4 iface) {
98     ICOM_THIS(IDirectDrawSurface4Impl,iface);
99     DDPRIVATE(This->s.ddraw);
100     DSPRIVATE(This);
101
102     TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
103
104     if (--(This->ref))
105         return This->ref;
106
107     IDirectDraw2_Release((IDirectDraw2*)This->s.ddraw);
108     /* clear out of surface list */
109     if (ddpriv->fb_height == -1)
110         HeapFree(GetProcessHeap(),0,This->s.surface_desc.u1.lpSurface);
111     else
112         ddpriv->vpmask &= ~(1<<(dspriv->fb_height/ddpriv->fb_height));
113
114     /* Free the DIBSection (if any) */
115     if (This->s.hdc != 0) {
116         SelectObject(This->s.hdc, This->s.holdbitmap);
117         DeleteDC(This->s.hdc);
118         DeleteObject(This->s.DIBsection);
119     }
120     /* Free the clipper if attached to this surface */
121     if( This->s.lpClipper )
122         IDirectDrawClipper_Release(This->s.lpClipper);
123     HeapFree(GetProcessHeap(),0,This);
124     return S_OK;
125 }
126
127 ICOM_VTABLE(IDirectDrawSurface4) dga_dds4vt = 
128 {
129     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
130     IDirectDrawSurface4Impl_QueryInterface,
131     IDirectDrawSurface4Impl_AddRef,
132     DGA_IDirectDrawSurface4Impl_Release,
133     IDirectDrawSurface4Impl_AddAttachedSurface,
134     IDirectDrawSurface4Impl_AddOverlayDirtyRect,
135     IDirectDrawSurface4Impl_Blt,
136     IDirectDrawSurface4Impl_BltBatch,
137     IDirectDrawSurface4Impl_BltFast,
138     IDirectDrawSurface4Impl_DeleteAttachedSurface,
139     IDirectDrawSurface4Impl_EnumAttachedSurfaces,
140     IDirectDrawSurface4Impl_EnumOverlayZOrders,
141     DGA_IDirectDrawSurface4Impl_Flip,
142     IDirectDrawSurface4Impl_GetAttachedSurface,
143     IDirectDrawSurface4Impl_GetBltStatus,
144     IDirectDrawSurface4Impl_GetCaps,
145     IDirectDrawSurface4Impl_GetClipper,
146     IDirectDrawSurface4Impl_GetColorKey,
147     IDirectDrawSurface4Impl_GetDC,
148     IDirectDrawSurface4Impl_GetFlipStatus,
149     IDirectDrawSurface4Impl_GetOverlayPosition,
150     IDirectDrawSurface4Impl_GetPalette,
151     IDirectDrawSurface4Impl_GetPixelFormat,
152     IDirectDrawSurface4Impl_GetSurfaceDesc,
153     IDirectDrawSurface4Impl_Initialize,
154     IDirectDrawSurface4Impl_IsLost,
155     IDirectDrawSurface4Impl_Lock,
156     IDirectDrawSurface4Impl_ReleaseDC,
157     IDirectDrawSurface4Impl_Restore,
158     IDirectDrawSurface4Impl_SetClipper,
159     IDirectDrawSurface4Impl_SetColorKey,
160     IDirectDrawSurface4Impl_SetOverlayPosition,
161     DGA_IDirectDrawSurface4Impl_SetPalette,
162     IDirectDrawSurface4Impl_Unlock,
163     IDirectDrawSurface4Impl_UpdateOverlay,
164     IDirectDrawSurface4Impl_UpdateOverlayDisplay,
165     IDirectDrawSurface4Impl_UpdateOverlayZOrder,
166     IDirectDrawSurface4Impl_GetDDInterface,
167     IDirectDrawSurface4Impl_PageLock,
168     IDirectDrawSurface4Impl_PageUnlock,
169     IDirectDrawSurface4Impl_SetSurfaceDesc,
170     IDirectDrawSurface4Impl_SetPrivateData,
171     IDirectDrawSurface4Impl_GetPrivateData,
172     IDirectDrawSurface4Impl_FreePrivateData,
173     IDirectDrawSurface4Impl_GetUniquenessValue,
174     IDirectDrawSurface4Impl_ChangeUniquenessValue
175 };