2 * Copyright 2006 Stefan Dösinger
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.
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.
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
20 #include "wine/port.h"
22 #include "ddraw_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
26 /*****************************************************************************
27 * IDirectDrawPalette::QueryInterface
29 * A usual QueryInterface implementation. Can only Query IUnknown and
33 * refiid: The interface id queried for
34 * obj: Address to return the interface pointer at
38 * E_NOINTERFACE if the requested interface wasn't found
39 *****************************************************************************/
41 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette
*iface
,
45 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
47 if (IsEqualGUID(refiid
, &IID_IUnknown
)
48 || IsEqualGUID(refiid
, &IID_IDirectDrawPalette
))
51 IDirectDrawPalette_AddRef(iface
);
61 /*****************************************************************************
62 * IDirectDrawPaletteImpl::AddRef
64 * Increases the refcount.
69 *****************************************************************************/
71 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette
*iface
)
73 IDirectDrawPaletteImpl
*This
= impl_from_IDirectDrawPalette(iface
);
74 ULONG ref
= InterlockedIncrement(&This
->ref
);
76 TRACE("%p increasing refcount to %u.\n", This
, ref
);
81 /*****************************************************************************
82 * IDirectDrawPaletteImpl::Release
84 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
89 *****************************************************************************/
91 IDirectDrawPaletteImpl_Release(IDirectDrawPalette
*iface
)
93 IDirectDrawPaletteImpl
*This
= impl_from_IDirectDrawPalette(iface
);
94 ULONG ref
= InterlockedDecrement(&This
->ref
);
96 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
100 wined3d_mutex_lock();
101 wined3d_palette_decref(This
->wineD3DPalette
);
102 if(This
->ifaceToRelease
)
104 IUnknown_Release(This
->ifaceToRelease
);
106 wined3d_mutex_unlock();
108 HeapFree(GetProcessHeap(), 0, This
);
114 /*****************************************************************************
115 * IDirectDrawPalette::Initialize
117 * Initializes the palette. As we start initialized, return
118 * DDERR_ALREADYINITIALIZED
121 * DD: DirectDraw interface this palette is assigned to
122 * Flags: Some flags, as usual
123 * ColorTable: The startup color table
126 * DDERR_ALREADYINITIALIZED
128 *****************************************************************************/
129 static HRESULT WINAPI
130 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette
*iface
,
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
147 * Caps: Address to store the caps at
151 * DDERR_INVALIDPARAMS if Caps is NULL
152 * For more details, see IWineD3DPalette::GetCaps
154 *****************************************************************************/
155 static HRESULT WINAPI
156 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette
*iface
,
159 IDirectDrawPaletteImpl
*This
= impl_from_IDirectDrawPalette(iface
);
161 TRACE("iface %p, caps %p.\n", iface
, Caps
);
163 wined3d_mutex_lock();
164 *Caps
= wined3d_palette_get_flags(This
->wineD3DPalette
);
165 wined3d_mutex_unlock();
170 /*****************************************************************************
171 * IDirectDrawPalette::SetEntries
173 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
174 * care for updating the surface.
177 * Flags: Flags, as usual
178 * Start: First palette entry to set
179 * Count: Number of entries to set
180 * PalEnt: Source entries
184 * DDERR_INVALIDPARAMS if PalEnt is NULL
185 * For details, see IWineD3DDevice::SetEntries
187 *****************************************************************************/
188 static HRESULT WINAPI
189 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette
*iface
,
193 PALETTEENTRY
*PalEnt
)
195 IDirectDrawPaletteImpl
*This
= impl_from_IDirectDrawPalette(iface
);
198 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
199 iface
, Flags
, Start
, Count
, PalEnt
);
202 return DDERR_INVALIDPARAMS
;
204 wined3d_mutex_lock();
205 hr
= wined3d_palette_set_entries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
206 wined3d_mutex_unlock();
211 /*****************************************************************************
212 * IDirectDrawPalette::GetEntries
214 * Returns the entries stored in this interface.
218 * Start: First entry to return
219 * Count: The number of entries to return
220 * PalEnt: PALETTEENTRY structure to write the entries to
224 * DDERR_INVALIDPARAMS if PalEnt is NULL
225 * For details, see IWineD3DDevice::SetEntries
227 *****************************************************************************/
228 static HRESULT WINAPI
229 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette
*iface
,
233 PALETTEENTRY
*PalEnt
)
235 IDirectDrawPaletteImpl
*This
= impl_from_IDirectDrawPalette(iface
);
238 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
239 iface
, Flags
, Start
, Count
, PalEnt
);
242 return DDERR_INVALIDPARAMS
;
244 wined3d_mutex_lock();
245 hr
= wined3d_palette_get_entries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
246 wined3d_mutex_unlock();
251 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl
=
254 IDirectDrawPaletteImpl_QueryInterface
,
255 IDirectDrawPaletteImpl_AddRef
,
256 IDirectDrawPaletteImpl_Release
,
257 /*** IDirectDrawPalette ***/
258 IDirectDrawPaletteImpl_GetCaps
,
259 IDirectDrawPaletteImpl_GetEntries
,
260 IDirectDrawPaletteImpl_Initialize
,
261 IDirectDrawPaletteImpl_SetEntries
264 IDirectDrawPaletteImpl
*unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette
*iface
)
266 if (!iface
) return NULL
;
267 assert(iface
->lpVtbl
== &ddraw_palette_vtbl
);
268 return CONTAINING_RECORD(iface
, IDirectDrawPaletteImpl
, IDirectDrawPalette_iface
);
271 HRESULT
ddraw_palette_init(IDirectDrawPaletteImpl
*palette
,
272 IDirectDrawImpl
*ddraw
, DWORD flags
, PALETTEENTRY
*entries
)
276 palette
->IDirectDrawPalette_iface
.lpVtbl
= &ddraw_palette_vtbl
;
279 hr
= wined3d_palette_create(ddraw
->wined3d_device
, flags
,
280 entries
, palette
, &palette
->wineD3DPalette
);
283 WARN("Failed to create wined3d palette, hr %#x.\n", hr
);
287 palette
->ifaceToRelease
= (IUnknown
*)&ddraw
->IDirectDraw7_iface
;
288 IUnknown_AddRef(palette
->ifaceToRelease
);