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 *****************************************************************************/
40 static HRESULT WINAPI
ddraw_palette_QueryInterface(IDirectDrawPalette
*iface
, REFIID refiid
, void **obj
)
42 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
44 if (IsEqualGUID(refiid
, &IID_IUnknown
)
45 || IsEqualGUID(refiid
, &IID_IDirectDrawPalette
))
48 IDirectDrawPalette_AddRef(iface
);
58 /*****************************************************************************
59 * IDirectDrawPaletteImpl::AddRef
61 * Increases the refcount.
66 *****************************************************************************/
67 static ULONG WINAPI
ddraw_palette_AddRef(IDirectDrawPalette
*iface
)
69 struct ddraw_palette
*This
= impl_from_IDirectDrawPalette(iface
);
70 ULONG ref
= InterlockedIncrement(&This
->ref
);
72 TRACE("%p increasing refcount to %u.\n", This
, ref
);
77 /*****************************************************************************
78 * IDirectDrawPaletteImpl::Release
80 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
85 *****************************************************************************/
86 static ULONG WINAPI
ddraw_palette_Release(IDirectDrawPalette
*iface
)
88 struct ddraw_palette
*This
= impl_from_IDirectDrawPalette(iface
);
89 ULONG ref
= InterlockedDecrement(&This
->ref
);
91 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
96 wined3d_palette_decref(This
->wineD3DPalette
);
97 if(This
->ifaceToRelease
)
99 IUnknown_Release(This
->ifaceToRelease
);
101 wined3d_mutex_unlock();
103 HeapFree(GetProcessHeap(), 0, This
);
109 /*****************************************************************************
110 * IDirectDrawPalette::Initialize
112 * Initializes the palette. As we start initialized, return
113 * DDERR_ALREADYINITIALIZED
116 * DD: DirectDraw interface this palette is assigned to
117 * Flags: Some flags, as usual
118 * ColorTable: The startup color table
121 * DDERR_ALREADYINITIALIZED
123 *****************************************************************************/
124 static HRESULT WINAPI
ddraw_palette_Initialize(IDirectDrawPalette
*iface
,
125 IDirectDraw
*ddraw
, DWORD flags
, PALETTEENTRY
*entries
)
127 TRACE("iface %p, ddraw %p, flags %#x, entries %p.\n",
128 iface
, ddraw
, flags
, entries
);
130 return DDERR_ALREADYINITIALIZED
;
133 /*****************************************************************************
134 * IDirectDrawPalette::GetCaps
136 * Returns the palette description
139 * Caps: Address to store the caps at
143 * DDERR_INVALIDPARAMS if Caps is NULL
144 * For more details, see IWineD3DPalette::GetCaps
146 *****************************************************************************/
147 static HRESULT WINAPI
ddraw_palette_GetCaps(IDirectDrawPalette
*iface
, DWORD
*caps
)
149 struct ddraw_palette
*palette
= impl_from_IDirectDrawPalette(iface
);
151 TRACE("iface %p, caps %p.\n", iface
, caps
);
153 wined3d_mutex_lock();
154 *caps
= wined3d_palette_get_flags(palette
->wineD3DPalette
);
155 wined3d_mutex_unlock();
160 /*****************************************************************************
161 * IDirectDrawPalette::SetEntries
163 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
164 * care for updating the surface.
167 * Flags: Flags, as usual
168 * Start: First palette entry to set
169 * Count: Number of entries to set
170 * PalEnt: Source entries
174 * DDERR_INVALIDPARAMS if PalEnt is NULL
175 * For details, see IWineD3DDevice::SetEntries
177 *****************************************************************************/
178 static HRESULT WINAPI
ddraw_palette_SetEntries(IDirectDrawPalette
*iface
,
179 DWORD flags
, DWORD start
, DWORD count
, PALETTEENTRY
*entries
)
181 struct ddraw_palette
*palette
= impl_from_IDirectDrawPalette(iface
);
184 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
185 iface
, flags
, start
, count
, entries
);
188 return DDERR_INVALIDPARAMS
;
190 wined3d_mutex_lock();
191 hr
= wined3d_palette_set_entries(palette
->wineD3DPalette
, flags
, start
, count
, entries
);
192 wined3d_mutex_unlock();
197 /*****************************************************************************
198 * IDirectDrawPalette::GetEntries
200 * Returns the entries stored in this interface.
204 * Start: First entry to return
205 * Count: The number of entries to return
206 * PalEnt: PALETTEENTRY structure to write the entries to
210 * DDERR_INVALIDPARAMS if PalEnt is NULL
211 * For details, see IWineD3DDevice::SetEntries
213 *****************************************************************************/
214 static HRESULT WINAPI
ddraw_palette_GetEntries(IDirectDrawPalette
*iface
,
215 DWORD flags
, DWORD start
, DWORD count
, PALETTEENTRY
*entries
)
217 struct ddraw_palette
*palette
= impl_from_IDirectDrawPalette(iface
);
220 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
221 iface
, flags
, start
, count
, entries
);
224 return DDERR_INVALIDPARAMS
;
226 wined3d_mutex_lock();
227 hr
= wined3d_palette_get_entries(palette
->wineD3DPalette
, flags
, start
, count
, entries
);
228 wined3d_mutex_unlock();
233 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl
=
236 ddraw_palette_QueryInterface
,
237 ddraw_palette_AddRef
,
238 ddraw_palette_Release
,
239 /*** IDirectDrawPalette ***/
240 ddraw_palette_GetCaps
,
241 ddraw_palette_GetEntries
,
242 ddraw_palette_Initialize
,
243 ddraw_palette_SetEntries
246 struct ddraw_palette
*unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette
*iface
)
248 if (!iface
) return NULL
;
249 assert(iface
->lpVtbl
== &ddraw_palette_vtbl
);
250 return CONTAINING_RECORD(iface
, struct ddraw_palette
, IDirectDrawPalette_iface
);
253 HRESULT
ddraw_palette_init(struct ddraw_palette
*palette
,
254 struct ddraw
*ddraw
, DWORD flags
, PALETTEENTRY
*entries
)
258 palette
->IDirectDrawPalette_iface
.lpVtbl
= &ddraw_palette_vtbl
;
261 if (FAILED(hr
= wined3d_palette_create(ddraw
->wined3d_device
, flags
, entries
, &palette
->wineD3DPalette
)))
263 WARN("Failed to create wined3d palette, hr %#x.\n", hr
);
267 palette
->ifaceToRelease
= (IUnknown
*)&ddraw
->IDirectDraw7_iface
;
268 IUnknown_AddRef(palette
->ifaceToRelease
);