1 /* DirectDraw - IDirectPalette base interface
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/debug.h"
28 #include "wined3d_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32 #define SIZE_BITS (DDPCAPS_1BIT | DDPCAPS_2BIT | DDPCAPS_4BIT | DDPCAPS_8BIT)
34 HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
35 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
36 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
38 if (IsEqualGUID(refiid, &IID_IUnknown)
39 || IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
41 IWineD3DPalette_AddRef(iface);
50 ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
51 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
52 ULONG ref = InterlockedIncrement(&This->ref);
54 TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
59 ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
60 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
61 ULONG ref = InterlockedDecrement(&This->ref);
63 TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
66 HeapFree(GetProcessHeap(), 0, This);
73 /* Not called from the vtable */
74 DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) {
75 switch (dwFlags & SIZE_BITS) {
76 case DDPCAPS_1BIT: return 2;
77 case DDPCAPS_2BIT: return 4;
78 case DDPCAPS_4BIT: return 16;
79 case DDPCAPS_8BIT: return 256;
80 default: assert(0); return 256;
84 HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt) {
85 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
87 TRACE("(%p)->(%08lx,%ld,%ld,%p)\n",This,Flags,Start,Count,PalEnt);
89 if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
90 if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
91 return WINED3DERR_INVALIDCALL;
93 if (This->Flags & DDPCAPS_8BITENTRIES)
96 LPBYTE entry = (LPBYTE)PalEnt;
98 for (i=Start; i < Count+Start; i++)
99 *entry++ = This->palents[i].peRed;
102 memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
107 HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt)
109 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
112 TRACE("(%p)->(%08lx,%ld,%ld,%p)\n",This,Flags,Start,Count,PalEnt);
114 if (This->Flags & DDPCAPS_8BITENTRIES) {
116 const BYTE* entry = (const BYTE*)PalEnt;
118 for (i=Start; i < Count+Start; i++)
119 This->palents[i].peRed = *entry++;
122 memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
125 SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
129 /* Now, if we are in 'depth conversion mode', update the screen palette */
130 /* FIXME: we need to update the image or we won't get palette fading. */
131 if (This->ddraw->d->palette_convert != NULL)
132 This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
135 /* If the palette is attached to the render target, update all render targets */
137 for(res = This->wineD3DDevice->resources; res != NULL; res=res->next) {
138 if(IWineD3DResource_GetType(res->resource) == D3DRTYPE_SURFACE) {
139 IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res->resource;
140 if(impl->palette == This)
141 IWineD3DSurface_RealizePalette( (IWineD3DSurface *) res->resource);
148 HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
149 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
150 TRACE("(%p)->(%p)\n", This, Caps);
156 HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
157 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
158 TRACE("(%p)->(%p)\n", This, Parent);
160 *Parent = (IUnknown *) This->parent;
161 IUnknown_AddRef( (IUnknown *) This->parent);
165 const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
168 IWineD3DPaletteImpl_QueryInterface,
169 IWineD3DPaletteImpl_AddRef,
170 IWineD3DPaletteImpl_Release,
171 /*** IWineD3DPalette ***/
172 IWineD3DPaletteImpl_GetParent,
173 IWineD3DPaletteImpl_GetEntries,
174 IWineD3DPaletteImpl_GetCaps,
175 IWineD3DPaletteImpl_SetEntries