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