include: Add some API prototypes to appropriate header files, fix some prototypes.
[wine] / dlls / ddraw / palette.c
1 /*              DirectDraw - IDirectPalette base interface
2  *
3  * Copyright 2006 Stefan Dösinger
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include "config.h"
21 #include "winerror.h"
22 #include "wine/debug.h"
23
24 #define COBJMACROS
25
26 #include <assert.h>
27 #include <string.h>
28
29 #include "ddraw_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
32
33 /*****************************************************************************
34  * IDirectDrawPalette::QueryInterface
35  *
36  * A usual QueryInterface implementation. Can only Query IUnknown and
37  * IDirectDrawPalette
38  *
39  * Params:
40  *  refiid: The interface id queried for
41  *  obj: Address to return the interface pointer at
42  *
43  * Returns:
44  *  S_OK on success
45  *  E_NOINTERFACE if the requested interface wasn't found
46  *****************************************************************************/
47 static HRESULT WINAPI
48 IDirectDrawPaletteImpl_QueryInterface(IDirectDrawPalette *iface,
49                                       REFIID refiid,
50                                       void **obj)
51 {
52     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
53     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
54
55     if (IsEqualGUID(refiid, &IID_IUnknown)
56         || IsEqualGUID(refiid, &IID_IDirectDrawPalette))
57     {
58         *obj = iface;
59         IDirectDrawPalette_AddRef(iface);
60         return S_OK;
61     }
62     else
63     {
64         *obj = NULL;
65         return E_NOINTERFACE;
66     }
67 }
68
69 /*****************************************************************************
70  * IDirectDrawPaletteImpl::AddRef
71  *
72  * Increases the refcount.
73  *
74  * Returns:
75  *  The new refcount
76  *
77  *****************************************************************************/
78 static ULONG WINAPI
79 IDirectDrawPaletteImpl_AddRef(IDirectDrawPalette *iface)
80 {
81     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
82     ULONG ref = InterlockedIncrement(&This->ref);
83
84     TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
85
86     return ref;
87 }
88
89 /*****************************************************************************
90  * IDirectDrawPaletteImpl::Release
91  *
92  * Reduces the refcount. If the refcount falls to 0, the object is destroyed
93  *
94  * Returns:
95  *  The new refcount
96  *
97  *****************************************************************************/
98 static ULONG WINAPI
99 IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
100 {
101     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
102     ULONG ref = InterlockedDecrement(&This->ref);
103
104     TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
105
106     if (ref == 0)
107     {
108         IWineD3DPalette_Release(This->wineD3DPalette);
109         if(This->ifaceToRelease)
110         {
111             IUnknown_Release(This->ifaceToRelease);
112         }
113         HeapFree(GetProcessHeap(), 0, This);
114     }
115
116     return ref;
117 }
118
119 /*****************************************************************************
120  * IDirectDrawPalette::Initialize
121  *
122  * Initializes the palette. As we start initialized, return
123  * DDERR_ALREADYINITIALIZED
124  *
125  * Params:
126  *  DD: DirectDraw interface this palette is asigned to
127  *  Flags: Some flags, as usual
128  *  ColorTable: The startup color table
129  *
130  * Returns:
131  *  DDERR_ALREADYINITIALIZED
132  *
133  *****************************************************************************/
134 static HRESULT WINAPI
135 IDirectDrawPaletteImpl_Initialize(IDirectDrawPalette *iface,
136                                   IDirectDraw *DD,
137                                   DWORD Flags,
138                                   PALETTEENTRY *ColorTable)
139 {
140     TRACE("(%p)->(%p,%x,%p)\n", iface, DD, Flags, ColorTable);
141     return DDERR_ALREADYINITIALIZED;
142 }
143
144 /*****************************************************************************
145  * IDirectDrawPalette::GetCaps
146  *
147  * Returns the palette description
148  *
149  * Params:
150  *  Caps: Address to store the caps at
151  *
152  * Returns:
153  *  D3D_OK on success
154  *  DDERR_INVALIDPARAMS if Caps is NULL
155  *  For more details, see IWineD3DPalette::GetCaps
156  *
157  *****************************************************************************/
158 static HRESULT WINAPI
159 IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
160                                DWORD *Caps)
161 {
162     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
163     TRACE("(%p)->(%p): Relay\n", This, Caps);
164
165     return IWineD3DPalette_GetCaps(This->wineD3DPalette, Caps);
166 }
167
168 /*****************************************************************************
169  * IDirectDrawPalette::SetEntries
170  *
171  * Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
172  * care for updating the surface.
173  *
174  * Params:
175  *  Flags: Flags, as usual
176  *  Start: First palette entry to set
177  *  Count: Number of entries to set
178  *  PalEnt: Source entries
179  *
180  * Returns:
181  *  D3D_OK on success
182  *  DDERR_INVALIDPARAMS if PalEnt is NULL
183  *  For details, see IWineD3DDevice::SetEntries
184  *
185  *****************************************************************************/
186 static HRESULT WINAPI
187 IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
188                                   DWORD Flags,
189                                   DWORD Start,
190                                   DWORD Count,
191                                   PALETTEENTRY *PalEnt)
192 {
193     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
194     TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This, Flags, Start, Count, PalEnt);
195
196     if(!PalEnt)
197         return DDERR_INVALIDPARAMS;
198
199     return IWineD3DPalette_SetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
200 }
201
202 /*****************************************************************************
203  * IDirectDrawPalette::GetEntries
204  *
205  * Returns the entries stored in this interface.
206  *
207  * Params:
208  *  Flags: Flags :)
209  *  Start: First entry to return
210  *  Count: The number of entries to return
211  *  PalEnt: PALETTEENTRY structure to write the entries to
212  *
213  * Returns:
214  *  D3D_OK on success
215  *  DDERR_INVALIDPARAMS if PalEnt is NULL
216  *  For details, see IWineD3DDevice::SetEntries
217  *
218  *****************************************************************************/
219 static HRESULT WINAPI
220 IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
221                                   DWORD Flags,
222                                   DWORD Start,
223                                   DWORD Count,
224                                   PALETTEENTRY *PalEnt)
225 {
226     ICOM_THIS_FROM(IDirectDrawPaletteImpl, IDirectDrawPalette, iface);
227     TRACE("(%p)->(%x,%d,%d,%p): Relay\n", This, Flags, Start, Count, PalEnt);
228
229     if(!PalEnt)
230         return DDERR_INVALIDPARAMS;
231
232     return IWineD3DPalette_GetEntries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
233 }
234
235 const IDirectDrawPaletteVtbl IDirectDrawPalette_Vtbl =
236 {
237     /*** IUnknown ***/
238     IDirectDrawPaletteImpl_QueryInterface,
239     IDirectDrawPaletteImpl_AddRef,
240     IDirectDrawPaletteImpl_Release,
241     /*** IDirectDrawPalette ***/
242     IDirectDrawPaletteImpl_GetCaps,
243     IDirectDrawPaletteImpl_GetEntries,
244     IDirectDrawPaletteImpl_Initialize,
245     IDirectDrawPaletteImpl_SetEntries
246 };