wined3d: Add position_transformed flag to Strided data format.
[wine] / dlls / ddraw / palette.c
1 /*              DirectDraw - IDirectPalette base interface
2  *
3  * Copyright 2006 Stefan Dösinger
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21 #include "winerror.h"
22 #include "wine/debug.h"
23
24 #include <assert.h>
25 #include <string.h>
26
27 #include "ddraw_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
30
31 /*****************************************************************************
32  * IDirectDrawPalette::QueryInterface
33  *
34  * A usual QueryInterface implementation. Can only Query IUnknown and
35  * IDirectDrawPalette
36  *
37  * Params:
38  *  refiid: The interface id queried for
39  *  obj: Address to return the interface pointer at
40  *
41  * Returns:
42  *  S_OK on success
43  *  E_NOINTERFACE if the requested interface wasn't found
44  *****************************************************************************/
45 static HRESULT WINAPI
46 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette *iface,
47                                       REFIID refiid,
48                                       void **obj)
49 {
50     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
51     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
52
53     if (IsEqualGUID(refiid, &IID_IUnknown)
54         || IsEqualGUID(refiid, &IID_IDirectDrawPalette))
55     {
56         *obj = iface;
57         IDirectDrawPalette_AddRef(iface);
58         return S_OK;
59     }
60     else
61     {
62         *obj = NULL;
63         return E_NOINTERFACE;
64     }
65 }
66
67 /*****************************************************************************
68  * IDirectDrawPaletteImpl::AddRef
69  *
70  * Increases the refcount.
71  *
72  * Returns:
73  *  The new refcount
74  *
75  *****************************************************************************/
76 static ULONG WINAPI
77 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface)
78 {
79     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
80     ULONG ref = InterlockedIncrement(&This->ref);
81
82     TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
83
84     return ref;
85 }
86
87 /*****************************************************************************
88  * IDirectDrawPaletteImpl::Release
89  *
90  * Reduces the refcount. If the refcount falls to 0, the object is destroyed
91  *
92  * Returns:
93  *  The new refcount
94  *
95  *****************************************************************************/
96 static ULONG WINAPI
97 IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
98 {
99     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
100     ULONG ref = InterlockedDecrement(&This->ref);
101
102     TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
103
104     if (ref == 0)
105     {
106         IWineD3DPalette_Release(This->wineD3DPalette);
107         IDirectDraw7_Release(ICOM_INTERFACE(This->ddraw_owner, IDirectDraw7));
108         HeapFree(GetProcessHeap(), 0, This);
109     }
110
111     return ref;
112 }
113
114 /*****************************************************************************
115  * IDirectDrawPalette::Initialize
116  *
117  * Initializes the palette. As we start initialized, return
118  * DDERR_ALREADYINITIALIZED
119  *
120  * Params:
121  *  DD: DirectDraw interface this palette is asigned to
122  *  Flags: Some flags, as usual
123  *  ColorTable: The startup color table
124  *
125  * Returns:
126  *  DDERR_ALREADYINITIALIZED
127  *
128  *****************************************************************************/
129 static HRESULT WINAPI
130 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette *iface,
131                                   IDirectDraw *DD,
132                                   DWORD Flags,
133                                   PALETTEENTRY *ColorTable)
134 {
135     TRACE("(%p)->(%p,%lx,%p)\n", iface, DD, Flags, ColorTable);
136     return DDERR_ALREADYINITIALIZED;
137 }
138
139 /*****************************************************************************
140  * IDirectDrawPalette::GetCaps
141  *
142  * Returns the palette description
143  *
144  * Params:
145  *  Caps: Address to store the caps at
146  *
147  * Returns:
148  *  D3D_OK on success
149  *  DDERR_INVALIDPARAMS if Caps is NULL
150  *  For more details, see IWineD3DPalette::GetCaps
151  *
152  *****************************************************************************/
153 static HRESULT WINAPI
154 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
155                                DWORD *Caps)
156 {
157     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
158     TRACE("(%p)->(%p): Relay\n", This, Caps);
159
160     return IWineD3DPalette_GetCaps(This->wineD3DPalette, Caps);
161 }
162
163 /*****************************************************************************
164  * IDirectDrawPalette::SetEntries
165  *
166  * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
167  * care for updating the surface.
168  *
169  * Params:
170  *  Flags: Flags, as usual
171  *  Start: First palette entry to set
172  *  Count: Number of entries to set
173  *  PalEnt: Source entries
174  *
175  * Returns:
176  *  D3D_OK on success
177  *  DDERR_INVALIDPARAMS if PalEnt is NULL
178  *  For details, see IWineD3DDevice::SetEntries
179  *
180  *****************************************************************************/
181 static HRESULT WINAPI
182 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
183                                   DWORD Flags,
184                                   DWORD Start,
185                                   DWORD Count,
186                                   PALETTEENTRY *PalEnt)
187 {
188     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
189     TRACE("(%p)->(%lx,%ld,%ld,%p): Relay\n", This, Flags, Start, Count, PalEnt);
190
191     if(!PalEnt)
192         return DDERR_INVALIDPARAMS;
193
194     return IWineD3DPalette_SetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
195 }
196
197 /*****************************************************************************
198  * IDirectDrawPalette::GetEntries
199  *
200  * Returns the entries stored in this interface.
201  *
202  * Params:
203  *  Flags: Flags :)
204  *  Start: First entry to return
205  *  Count: The number of entries to return
206  *  PalEnt: PALETTEENTRY structure to write the entries to
207  *
208  * Returns:
209  *  D3D_OK on success
210  *  DDERR_INVALIDPARAMS if PalEnt is NULL
211  *  For details, see IWineD3DDevice::SetEntries
212  *
213  *****************************************************************************/
214 static HRESULT WINAPI
215 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
216                                   DWORD Flags,
217                                   DWORD Start,
218                                   DWORD Count,
219                                   PALETTEENTRY *PalEnt)
220 {
221     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
222     TRACE("(%p)->(%lx,%ld,%ld,%p): Relay\n", This, Flags, Start, Count, PalEnt);
223
224     if(!PalEnt)
225         return DDERR_INVALIDPARAMS;
226
227     return IWineD3DPalette_GetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
228 }
229
230 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl =
231 {
232     /*** IUnknown ***/
233     IDirectDrawPaletteImpl_QueryInterface,
234     IDirectDrawPaletteImpl_AddRef,
235     IDirectDrawPaletteImpl_Release,
236     /*** IDirectDrawPalette ***/
237     IDirectDrawPaletteImpl_GetCaps,
238     IDirectDrawPaletteImpl_GetEntries,
239     IDirectDrawPaletteImpl_Initialize,
240     IDirectDrawPaletteImpl_SetEntries
241 };