wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / ddraw / palette.c
blobf92277462b2d7c56244055b499f8b7ed97cbfe4b
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 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
48 if (IsEqualGUID(refiid, &IID_IUnknown)
49 || IsEqualGUID(refiid, &IID_IDirectDrawPalette))
51 *obj = iface;
52 IDirectDrawPalette_AddRef(iface);
53 return S_OK;
55 else
57 *obj = NULL;
58 return E_NOINTERFACE;
62 /*****************************************************************************
63 * IDirectDrawPaletteImpl::AddRef
65 * Increases the refcount.
67 * Returns:
68 * The new refcount
70 *****************************************************************************/
71 static ULONG WINAPI
72 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface)
74 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
75 ULONG ref = InterlockedIncrement(&This->ref);
77 TRACE("%p increasing refcount to %u.\n", This, ref);
79 return ref;
82 /*****************************************************************************
83 * IDirectDrawPaletteImpl::Release
85 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
87 * Returns:
88 * The new refcount
90 *****************************************************************************/
91 static ULONG WINAPI
92 IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
94 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
95 ULONG ref = InterlockedDecrement(&This->ref);
97 TRACE("%p decreasing refcount to %u.\n", This, ref);
99 if (ref == 0)
101 EnterCriticalSection(&ddraw_cs);
102 IWineD3DPalette_Release(This->wineD3DPalette);
103 if(This->ifaceToRelease)
105 IUnknown_Release(This->ifaceToRelease);
107 LeaveCriticalSection(&ddraw_cs);
108 HeapFree(GetProcessHeap(), 0, This);
111 return ref;
114 /*****************************************************************************
115 * IDirectDrawPalette::Initialize
117 * Initializes the palette. As we start initialized, return
118 * DDERR_ALREADYINITIALIZED
120 * Params:
121 * DD: DirectDraw interface this palette is assigned to
122 * Flags: Some flags, as usual
123 * ColorTable: The startup color table
125 * Returns:
126 * DDERR_ALREADYINITIALIZED
128 *****************************************************************************/
129 static HRESULT WINAPI
130 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette *iface,
131 IDirectDraw *DD,
132 DWORD Flags,
133 PALETTEENTRY *ColorTable)
135 TRACE("iface %p, ddraw %p, flags %#x, entries %p.\n",
136 iface, DD, Flags, ColorTable);
138 return DDERR_ALREADYINITIALIZED;
141 /*****************************************************************************
142 * IDirectDrawPalette::GetCaps
144 * Returns the palette description
146 * Params:
147 * Caps: Address to store the caps at
149 * Returns:
150 * D3D_OK on success
151 * DDERR_INVALIDPARAMS if Caps is NULL
152 * For more details, see IWineD3DPalette::GetCaps
154 *****************************************************************************/
155 static HRESULT WINAPI
156 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
157 DWORD *Caps)
159 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
160 HRESULT hr;
162 TRACE("iface %p, caps %p.\n", iface, Caps);
164 EnterCriticalSection(&ddraw_cs);
165 hr = IWineD3DPalette_GetCaps(This->wineD3DPalette, Caps);
166 LeaveCriticalSection(&ddraw_cs);
167 return hr;
170 /*****************************************************************************
171 * IDirectDrawPalette::SetEntries
173 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
174 * care for updating the surface.
176 * Params:
177 * Flags: Flags, as usual
178 * Start: First palette entry to set
179 * Count: Number of entries to set
180 * PalEnt: Source entries
182 * Returns:
183 * D3D_OK on success
184 * DDERR_INVALIDPARAMS if PalEnt is NULL
185 * For details, see IWineD3DDevice::SetEntries
187 *****************************************************************************/
188 static HRESULT WINAPI
189 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
190 DWORD Flags,
191 DWORD Start,
192 DWORD Count,
193 PALETTEENTRY *PalEnt)
195 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
196 HRESULT hr;
198 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
199 iface, Flags, Start, Count, PalEnt);
201 if(!PalEnt)
202 return DDERR_INVALIDPARAMS;
204 EnterCriticalSection(&ddraw_cs);
205 hr = IWineD3DPalette_SetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
206 LeaveCriticalSection(&ddraw_cs);
207 return hr;
210 /*****************************************************************************
211 * IDirectDrawPalette::GetEntries
213 * Returns the entries stored in this interface.
215 * Params:
216 * Flags: Flags :)
217 * Start: First entry to return
218 * Count: The number of entries to return
219 * PalEnt: PALETTEENTRY structure to write the entries to
221 * Returns:
222 * D3D_OK on success
223 * DDERR_INVALIDPARAMS if PalEnt is NULL
224 * For details, see IWineD3DDevice::SetEntries
226 *****************************************************************************/
227 static HRESULT WINAPI
228 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
229 DWORD Flags,
230 DWORD Start,
231 DWORD Count,
232 PALETTEENTRY *PalEnt)
234 IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
235 HRESULT hr;
237 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
238 iface, Flags, Start, Count, PalEnt);
240 if(!PalEnt)
241 return DDERR_INVALIDPARAMS;
243 EnterCriticalSection(&ddraw_cs);
244 hr = IWineD3DPalette_GetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
245 LeaveCriticalSection(&ddraw_cs);
246 return hr;
249 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl =
251 /*** IUnknown ***/
252 IDirectDrawPaletteImpl_QueryInterface,
253 IDirectDrawPaletteImpl_AddRef,
254 IDirectDrawPaletteImpl_Release,
255 /*** IDirectDrawPalette ***/
256 IDirectDrawPaletteImpl_GetCaps,
257 IDirectDrawPaletteImpl_GetEntries,
258 IDirectDrawPaletteImpl_Initialize,
259 IDirectDrawPaletteImpl_SetEntries
262 HRESULT ddraw_palette_init(IDirectDrawPaletteImpl *palette,
263 IDirectDrawImpl *ddraw, DWORD flags, PALETTEENTRY *entries)
265 HRESULT hr;
267 palette->lpVtbl = &ddraw_palette_vtbl;
268 palette->ref = 1;
270 hr = IWineD3DDevice_CreatePalette(ddraw->wineD3DDevice, flags,
271 entries, &palette->wineD3DPalette, (IUnknown *)palette);
272 if (FAILED(hr))
274 WARN("Failed to create wined3d palette, hr %#x.\n", hr);
275 return hr;
278 palette->ifaceToRelease = (IUnknown *)ddraw;
279 IUnknown_AddRef(palette->ifaceToRelease);
281 return DD_OK;