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
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
34 * refiid: The interface id queried for
35 * obj: Address to return the interface pointer at
39 * E_NOINTERFACE if the requested interface wasn't found
40 *****************************************************************************/
42 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette
*iface
,
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
))
52 IDirectDrawPalette_AddRef(iface
);
62 /*****************************************************************************
63 * IDirectDrawPaletteImpl::AddRef
65 * Increases the refcount.
70 *****************************************************************************/
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
);
82 /*****************************************************************************
83 * IDirectDrawPaletteImpl::Release
85 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
90 *****************************************************************************/
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
);
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
);
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
= (IDirectDrawPaletteImpl
*)iface
;
162 TRACE("iface %p, caps %p.\n", iface
, Caps
);
164 EnterCriticalSection(&ddraw_cs
);
165 hr
= IWineD3DPalette_GetCaps(This
->wineD3DPalette
, Caps
);
166 LeaveCriticalSection(&ddraw_cs
);
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
= (IDirectDrawPaletteImpl
*)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 EnterCriticalSection(&ddraw_cs
);
205 hr
= IWineD3DPalette_SetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
206 LeaveCriticalSection(&ddraw_cs
);
210 /*****************************************************************************
211 * IDirectDrawPalette::GetEntries
213 * Returns the entries stored in this interface.
217 * Start: First entry to return
218 * Count: The number of entries to return
219 * PalEnt: PALETTEENTRY structure to write the entries to
223 * DDERR_INVALIDPARAMS if PalEnt is NULL
224 * For details, see IWineD3DDevice::SetEntries
226 *****************************************************************************/
227 static HRESULT WINAPI
228 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette
*iface
,
232 PALETTEENTRY
*PalEnt
)
234 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
237 TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
238 iface
, Flags
, Start
, Count
, PalEnt
);
241 return DDERR_INVALIDPARAMS
;
243 EnterCriticalSection(&ddraw_cs
);
244 hr
= IWineD3DPalette_GetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
245 LeaveCriticalSection(&ddraw_cs
);
249 static const struct IDirectDrawPaletteVtbl ddraw_palette_vtbl
=
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
)
267 palette
->lpVtbl
= &ddraw_palette_vtbl
;
270 hr
= IWineD3DDevice_CreatePalette(ddraw
->wineD3DDevice
, flags
,
271 entries
, &palette
->wineD3DPalette
, (IUnknown
*)palette
);
274 WARN("Failed to create wined3d palette, hr %#x.\n", hr
);
278 palette
->ifaceToRelease
= (IUnknown
*)ddraw
;
279 IUnknown_AddRef(palette
->ifaceToRelease
);