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 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
47 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(refiid
),obj
);
49 if (IsEqualGUID(refiid
, &IID_IUnknown
)
50 || IsEqualGUID(refiid
, &IID_IDirectDrawPalette
))
53 IDirectDrawPalette_AddRef(iface
);
63 /*****************************************************************************
64 * IDirectDrawPaletteImpl::AddRef
66 * Increases the refcount.
71 *****************************************************************************/
73 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette
*iface
)
75 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
76 ULONG ref
= InterlockedIncrement(&This
->ref
);
78 TRACE("(%p)->() incrementing from %u.\n", This
, ref
- 1);
83 /*****************************************************************************
84 * IDirectDrawPaletteImpl::Release
86 * Reduces the refcount. If the refcount falls to 0, the object is destroyed
91 *****************************************************************************/
93 IDirectDrawPaletteImpl_Release(IDirectDrawPalette
*iface
)
95 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
96 ULONG ref
= InterlockedDecrement(&This
->ref
);
98 TRACE("(%p)->() decrementing from %u.\n", This
, ref
+ 1);
102 EnterCriticalSection(&ddraw_cs
);
103 IWineD3DPalette_Release(This
->wineD3DPalette
);
104 if(This
->ifaceToRelease
)
106 IUnknown_Release(This
->ifaceToRelease
);
108 LeaveCriticalSection(&ddraw_cs
);
109 HeapFree(GetProcessHeap(), 0, This
);
115 /*****************************************************************************
116 * IDirectDrawPalette::Initialize
118 * Initializes the palette. As we start initialized, return
119 * DDERR_ALREADYINITIALIZED
122 * DD: DirectDraw interface this palette is assigned to
123 * Flags: Some flags, as usual
124 * ColorTable: The startup color table
127 * DDERR_ALREADYINITIALIZED
129 *****************************************************************************/
130 static HRESULT WINAPI
131 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette
*iface
,
134 PALETTEENTRY
*ColorTable
)
136 TRACE("(%p)->(%p,%x,%p)\n", 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
;
160 TRACE("(%p)->(%p): Relay\n", This
, Caps
);
162 EnterCriticalSection(&ddraw_cs
);
163 hr
= IWineD3DPalette_GetCaps(This
->wineD3DPalette
, Caps
);
164 LeaveCriticalSection(&ddraw_cs
);
168 /*****************************************************************************
169 * IDirectDrawPalette::SetEntries
171 * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
172 * care for updating the surface.
175 * Flags: Flags, as usual
176 * Start: First palette entry to set
177 * Count: Number of entries to set
178 * PalEnt: Source entries
182 * DDERR_INVALIDPARAMS if PalEnt is NULL
183 * For details, see IWineD3DDevice::SetEntries
185 *****************************************************************************/
186 static HRESULT WINAPI
187 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette
*iface
,
191 PALETTEENTRY
*PalEnt
)
193 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
195 TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This
, Flags
, Start
, Count
, PalEnt
);
198 return DDERR_INVALIDPARAMS
;
200 EnterCriticalSection(&ddraw_cs
);
201 hr
= IWineD3DPalette_SetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
202 LeaveCriticalSection(&ddraw_cs
);
206 /*****************************************************************************
207 * IDirectDrawPalette::GetEntries
209 * Returns the entries stored in this interface.
213 * Start: First entry to return
214 * Count: The number of entries to return
215 * PalEnt: PALETTEENTRY structure to write the entries to
219 * DDERR_INVALIDPARAMS if PalEnt is NULL
220 * For details, see IWineD3DDevice::SetEntries
222 *****************************************************************************/
223 static HRESULT WINAPI
224 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette
*iface
,
228 PALETTEENTRY
*PalEnt
)
230 IDirectDrawPaletteImpl
*This
= (IDirectDrawPaletteImpl
*)iface
;
232 TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This
, Flags
, Start
, Count
, PalEnt
);
235 return DDERR_INVALIDPARAMS
;
237 EnterCriticalSection(&ddraw_cs
);
238 hr
= IWineD3DPalette_GetEntries(This
->wineD3DPalette
, Flags
, Start
, Count
, PalEnt
);
239 LeaveCriticalSection(&ddraw_cs
);
243 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl
=
246 IDirectDrawPaletteImpl_QueryInterface
,
247 IDirectDrawPaletteImpl_AddRef
,
248 IDirectDrawPaletteImpl_Release
,
249 /*** IDirectDrawPalette ***/
250 IDirectDrawPaletteImpl_GetCaps
,
251 IDirectDrawPaletteImpl_GetEntries
,
252 IDirectDrawPaletteImpl_Initialize
,
253 IDirectDrawPaletteImpl_SetEntries