ddraw: Remove unused / redundant includes.
[wine/wine-gecko.git] / dlls / ddraw / palette.c
blob2937ec666859e7a1b7b4b6ff535aeadf6ff94b38
1 /* DirectDraw - IDirectPalette base interface
3 * Copyright 2006 Stefan Dösinger
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include "ddraw_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
27 /*****************************************************************************
28 * IDirectDrawPalette::QueryInterface
30 * A usual QueryInterface implementation. Can only Query IUnknown and
31 * IDirectDrawPalette
33 * Params:
34 * refiid: The interface id queried for
35 * obj: Address to return the interface pointer at
37 * Returns:
38 * S_OK on success
39 * E_NOINTERFACE if the requested interface wasn't found
40 *****************************************************************************/
41 static HRESULT WINAPI
42 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette *iface,
43 REFIID refiid,
44 void **obj)
46 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
47 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
49 if (IsEqualGUID(refiid, &IID_IUnknown)
50 || IsEqualGUID(refiid, &IID_IDirectDrawPalette))
52 *obj = iface;
53 IDirectDrawPalette_AddRef(iface);
54 return S_OK;
56 else
58 *obj = NULL;
59 return E_NOINTERFACE;
63 /*****************************************************************************
64 * IDirectDrawPaletteImpl::AddRef
66 * Increases the refcount.
68 * Returns:
69 * The new refcount
71 *****************************************************************************/
72 static ULONG WINAPI
73 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface)
75 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
76 ULONG ref = InterlockedIncrement(&This->ref);
78 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
80 return ref;
83 /*****************************************************************************
84 * IDirectDrawPaletteImpl::Release
86 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
88 * Returns:
89 * The new refcount
91 *****************************************************************************/
92 static ULONG WINAPI
93 IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
95 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
96 ULONG ref = InterlockedDecrement(&This->ref);
98 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
100 if (ref == 0)
102 EnterCriticalSection(&ddraw_cs);
103 IWineD3DPalette_Release(This->wineD3DPalette);
104 if(This->ifaceToRelease)
106 IUnknown_Release(This->ifaceToRelease);
108 LeaveCriticalSection(&ddraw_cs);
109 HeapFree(GetProcessHeap(), 0, This);
112 return ref;
115 /*****************************************************************************
116 * IDirectDrawPalette::Initialize
118 * Initializes the palette. As we start initialized, return
119 * DDERR_ALREADYINITIALIZED
121 * Params:
122 * DD: DirectDraw interface this palette is assigned to
123 * Flags: Some flags, as usual
124 * ColorTable: The startup color table
126 * Returns:
127 * DDERR_ALREADYINITIALIZED
129 *****************************************************************************/
130 static HRESULT WINAPI
131 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette *iface,
132 IDirectDraw *DD,
133 DWORD Flags,
134 PALETTEENTRY *ColorTable)
136 TRACE("(%p)->(%p,%x,%p)\n", iface, DD, Flags, ColorTable);
137 return DDERR_ALREADYINITIALIZED;
140 /*****************************************************************************
141 * IDirectDrawPalette::GetCaps
143 * Returns the palette description
145 * Params:
146 * Caps: Address to store the caps at
148 * Returns:
149 * D3D_OK on success
150 * DDERR_INVALIDPARAMS if Caps is NULL
151 * For more details, see IWineD3DPalette::GetCaps
153 *****************************************************************************/
154 static HRESULT WINAPI
155 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
156 DWORD *Caps)
158 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
159 HRESULT hr;
160 TRACE("(%p)->(%p): Relay\n", This, Caps);
162 EnterCriticalSection(&ddraw_cs);
163 hr = IWineD3DPalette_GetCaps(This->wineD3DPalette, Caps);
164 LeaveCriticalSection(&ddraw_cs);
165 return hr;
168 /*****************************************************************************
169 * IDirectDrawPalette::SetEntries
171 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
172 * care for updating the surface.
174 * Params:
175 * Flags: Flags, as usual
176 * Start: First palette entry to set
177 * Count: Number of entries to set
178 * PalEnt: Source entries
180 * Returns:
181 * D3D_OK on success
182 * DDERR_INVALIDPARAMS if PalEnt is NULL
183 * For details, see IWineD3DDevice::SetEntries
185 *****************************************************************************/
186 static HRESULT WINAPI
187 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
188 DWORD Flags,
189 DWORD Start,
190 DWORD Count,
191 PALETTEENTRY *PalEnt)
193 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
194 HRESULT hr;
195 TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This, Flags, Start, Count, PalEnt);
197 if(!PalEnt)
198 return DDERR_INVALIDPARAMS;
200 EnterCriticalSection(&ddraw_cs);
201 hr = IWineD3DPalette_SetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
202 LeaveCriticalSection(&ddraw_cs);
203 return hr;
206 /*****************************************************************************
207 * IDirectDrawPalette::GetEntries
209 * Returns the entries stored in this interface.
211 * Params:
212 * Flags: Flags :)
213 * Start: First entry to return
214 * Count: The number of entries to return
215 * PalEnt: PALETTEENTRY structure to write the entries to
217 * Returns:
218 * D3D_OK on success
219 * DDERR_INVALIDPARAMS if PalEnt is NULL
220 * For details, see IWineD3DDevice::SetEntries
222 *****************************************************************************/
223 static HRESULT WINAPI
224 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
225 DWORD Flags,
226 DWORD Start,
227 DWORD Count,
228 PALETTEENTRY *PalEnt)
230 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
231 HRESULT hr;
232 TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This, Flags, Start, Count, PalEnt);
234 if(!PalEnt)
235 return DDERR_INVALIDPARAMS;
237 EnterCriticalSection(&ddraw_cs);
238 hr = IWineD3DPalette_GetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
239 LeaveCriticalSection(&ddraw_cs);
240 return hr;
243 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl =
245 /*** IUnknown ***/
246 IDirectDrawPaletteImpl_QueryInterface,
247 IDirectDrawPaletteImpl_AddRef,
248 IDirectDrawPaletteImpl_Release,
249 /*** IDirectDrawPalette ***/
250 IDirectDrawPaletteImpl_GetCaps,
251 IDirectDrawPaletteImpl_GetEntries,
252 IDirectDrawPaletteImpl_Initialize,
253 IDirectDrawPaletteImpl_SetEntries