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
= (IDirectDrawPaletteImpl
*)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
= (IDirectDrawPaletteImpl
*)iface
;
94 ULONG ref
= InterlockedDecrement(&This
->ref
);
96 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
100 EnterCriticalSection(&ddraw_cs
);
101 IWineD3DPalette_Release(This
->wineD3DPalette
);
102 if(This
->ifaceToRelease
)
104 IUnknown_Release(This
->ifaceToRelease
);
106 LeaveCriticalSection(&ddraw_cs
);
107 HeapFree(GetProcessHeap(), 0, This
);
113 /*****************************************************************************
114 * IDirectDrawPalette::Initialize
116 * Initializes the palette. As we start initialized, return
117 * DDERR_ALREADYINITIALIZED
120 * DD: DirectDraw interface this palette is assigned to
121 * Flags: Some flags, as usual
122 * ColorTable: The startup color table
125 * DDERR_ALREADYINITIALIZED
127 *****************************************************************************/
128 static HRESULT WINAPI
129 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette
*iface
,
132 PALETTEENTRY
*ColorTable
)
134 TRACE("iface %p, ddraw %p, flags %#x, entries %p.\n",
135 iface
, DD
, Flags
, ColorTable
);
137 return DDERR_ALREADYINITIALIZED
;
140 /*****************************************************************************
141 * IDirectDrawPalette::GetCaps
143 * Returns the palette description
146 * Caps: Address to store the caps at
150 * DDERR_INVALIDPARAMS if Caps is NULL
151 * For more details, see IWineD3DPalette::GetCaps
153 *****************************************************************************/
154 static HRESULT WINAPI
155 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette
*iface
,
158 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
161 TRACE("iface %p, caps %p.\n", iface
, Caps
);
163 EnterCriticalSection(&ddraw_cs
);
164 hr
= IWineD3DPalette_GetCaps(This
->wineD3DPalette
, Caps
);
165 LeaveCriticalSection(&ddraw_cs
);
169 /*****************************************************************************
170 * IDirectDrawPalette::SetEntries
172 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
173 * care for updating the surface.
176 * Flags: Flags, as usual
177 * Start: First palette entry to set
178 * Count: Number of entries to set
179 * PalEnt: Source entries
183 * DDERR_INVALIDPARAMS if PalEnt is NULL
184 * For details, see IWineD3DDevice::SetEntries
186 *****************************************************************************/
187 static HRESULT WINAPI
188 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette
*iface
,
192 PALETTEENTRY
*PalEnt
)
194 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
197 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
198 iface
, Flags
, Start
, Count
, PalEnt
);
201 return DDERR_INVALIDPARAMS
;
203 EnterCriticalSection(&ddraw_cs
);
204 hr
= IWineD3DPalette_SetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
205 LeaveCriticalSection(&ddraw_cs
);
209 /*****************************************************************************
210 * IDirectDrawPalette::GetEntries
212 * Returns the entries stored in this interface.
216 * Start: First entry to return
217 * Count: The number of entries to return
218 * PalEnt: PALETTEENTRY structure to write the entries to
222 * DDERR_INVALIDPARAMS if PalEnt is NULL
223 * For details, see IWineD3DDevice::SetEntries
225 *****************************************************************************/
226 static HRESULT WINAPI
227 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette
*iface
,
231 PALETTEENTRY
*PalEnt
)
233 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
236 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
237 iface
, Flags
, Start
, Count
, PalEnt
);
240 return DDERR_INVALIDPARAMS
;
242 EnterCriticalSection(&ddraw_cs
);
243 hr
= IWineD3DPalette_GetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
244 LeaveCriticalSection(&ddraw_cs
);
248 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl
=
251 IDirectDrawPaletteImpl_QueryInterface
,
252 IDirectDrawPaletteImpl_AddRef
,
253 IDirectDrawPaletteImpl_Release
,
254 /*** IDirectDrawPalette ***/
255 IDirectDrawPaletteImpl_GetCaps
,
256 IDirectDrawPaletteImpl_GetEntries
,
257 IDirectDrawPaletteImpl_Initialize
,
258 IDirectDrawPaletteImpl_SetEntries
261 HRESULT
ddraw_palette_init(IDirectDrawPaletteImpl
*palette
,
262 IDirectDrawImpl
*ddraw
, DWORD flags
, PALETTEENTRY
*entries
)
266 palette
->lpVtbl
= &ddraw_palette_vtbl
;
269 hr
= IWineD3DDevice_CreatePalette(ddraw
->wineD3DDevice
, flags
,
270 entries
, palette
, &palette
->wineD3DPalette
);
273 WARN("Failed to create wined3d palette, hr %#x.\n", hr
);
277 palette
->ifaceToRelease
= (IUnknown
*)ddraw
;
278 IUnknown_AddRef(palette
->ifaceToRelease
);