1 | /* DirectDraw - IDirectPalette base interface
|
---|
2 | *
|
---|
3 | * Copyright 1997-2000 Marcus Meissner
|
---|
4 | * Copyright 2000-2001 TransGaming Technologies Inc.
|
---|
5 | * Copyright 2006 Stefan Dösinger for CodeWeavers
|
---|
6 | *
|
---|
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.
|
---|
11 | *
|
---|
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.
|
---|
16 | *
|
---|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
24 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
25 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
26 | * a choice of LGPL license versions is made available with the language indicating
|
---|
27 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
28 | * of the LGPL is applied is otherwise unspecified.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #include "config.h"
|
---|
32 | #include "winerror.h"
|
---|
33 | #include "wine/debug.h"
|
---|
34 |
|
---|
35 | #include <string.h>
|
---|
36 |
|
---|
37 | #include "wined3d_private.h"
|
---|
38 |
|
---|
39 | WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
---|
40 |
|
---|
41 | #define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
|
---|
42 |
|
---|
43 | static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
|
---|
44 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
45 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
|
---|
46 |
|
---|
47 | if (IsEqualGUID(refiid, &IID_IUnknown)
|
---|
48 | || IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
|
---|
49 | *obj = iface;
|
---|
50 | IWineD3DPalette_AddRef(iface);
|
---|
51 | return S_OK;
|
---|
52 | }
|
---|
53 | else {
|
---|
54 | *obj = NULL;
|
---|
55 | return E_NOINTERFACE;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | static ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
|
---|
60 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
61 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
62 |
|
---|
63 | TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
|
---|
64 |
|
---|
65 | return ref;
|
---|
66 | }
|
---|
67 |
|
---|
68 | static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
|
---|
69 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
70 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
71 |
|
---|
72 | TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
|
---|
73 |
|
---|
74 | if (!ref) {
|
---|
75 | DeleteObject(This->hpal);
|
---|
76 | HeapFree(GetProcessHeap(), 0, This);
|
---|
77 | return 0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | return ref;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /* Not called from the vtable */
|
---|
84 | DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) {
|
---|
85 | switch (dwFlags & SIZE_BITS) {
|
---|
86 | case WINEDDPCAPS_1BIT: return 2;
|
---|
87 | case WINEDDPCAPS_2BIT: return 4;
|
---|
88 | case WINEDDPCAPS_4BIT: return 16;
|
---|
89 | case WINEDDPCAPS_8BIT: return 256;
|
---|
90 | default:
|
---|
91 | FIXME("Unhandled size bits %#x.\n", dwFlags & SIZE_BITS);
|
---|
92 | return 256;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | static HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt) {
|
---|
97 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
98 |
|
---|
99 | TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
|
---|
100 |
|
---|
101 | if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
|
---|
102 | if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
|
---|
103 | return WINED3DERR_INVALIDCALL;
|
---|
104 |
|
---|
105 | if (This->Flags & WINEDDPCAPS_8BITENTRIES)
|
---|
106 | {
|
---|
107 | unsigned int i;
|
---|
108 | LPBYTE entry = (LPBYTE)PalEnt;
|
---|
109 |
|
---|
110 | for (i=Start; i < Count+Start; i++)
|
---|
111 | *entry++ = This->palents[i].peRed;
|
---|
112 | }
|
---|
113 | else
|
---|
114 | memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
|
---|
115 |
|
---|
116 | return WINED3D_OK;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface,
|
---|
120 | DWORD Flags, DWORD Start, DWORD Count, const PALETTEENTRY *PalEnt)
|
---|
121 | {
|
---|
122 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
123 | IWineD3DResourceImpl *res;
|
---|
124 |
|
---|
125 | TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
|
---|
126 | TRACE("Palette flags: %#x\n", This->Flags);
|
---|
127 |
|
---|
128 | if (This->Flags & WINEDDPCAPS_8BITENTRIES) {
|
---|
129 | unsigned int i;
|
---|
130 | const BYTE* entry = (const BYTE*)PalEnt;
|
---|
131 |
|
---|
132 | for (i=Start; i < Count+Start; i++)
|
---|
133 | This->palents[i].peRed = *entry++;
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
|
---|
137 |
|
---|
138 | /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
|
---|
139 | if(!(This->Flags & WINEDDPCAPS_ALLOW256))
|
---|
140 | {
|
---|
141 | TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n");
|
---|
142 | This->palents[0].peRed = 0;
|
---|
143 | This->palents[0].peGreen = 0;
|
---|
144 | This->palents[0].peBlue = 0;
|
---|
145 |
|
---|
146 | This->palents[255].peRed = 255;
|
---|
147 | This->palents[255].peGreen = 255;
|
---|
148 | This->palents[255].peBlue = 255;
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (This->hpal)
|
---|
152 | SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
|
---|
153 | }
|
---|
154 |
|
---|
155 | #if 0
|
---|
156 | /* Now, if we are in 'depth conversion mode', update the screen palette */
|
---|
157 | /* FIXME: we need to update the image or we won't get palette fading. */
|
---|
158 | if (This->ddraw->d->palette_convert != NULL)
|
---|
159 | This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | /* If the palette is attached to the render target, update all render targets */
|
---|
163 |
|
---|
164 | LIST_FOR_EACH_ENTRY(res, &This->wineD3DDevice->resources, IWineD3DResourceImpl, resource.resource_list_entry) {
|
---|
165 | if(IWineD3DResource_GetType((IWineD3DResource *) res) == WINED3DRTYPE_SURFACE) {
|
---|
166 | IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res;
|
---|
167 | if(impl->palette == This)
|
---|
168 | IWineD3DSurface_RealizePalette((IWineD3DSurface *) res);
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | return WINED3D_OK;
|
---|
173 | }
|
---|
174 |
|
---|
175 | static HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
|
---|
176 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
177 | TRACE("(%p)->(%p)\n", This, Caps);
|
---|
178 |
|
---|
179 | *Caps = This->Flags;
|
---|
180 | return WINED3D_OK;
|
---|
181 | }
|
---|
182 |
|
---|
183 | static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
|
---|
184 | IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
---|
185 | TRACE("(%p)->(%p)\n", This, Parent);
|
---|
186 |
|
---|
187 | *Parent = This->parent;
|
---|
188 | IUnknown_AddRef(This->parent);
|
---|
189 | return WINED3D_OK;
|
---|
190 | }
|
---|
191 |
|
---|
192 | const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
|
---|
193 | {
|
---|
194 | /*** IUnknown ***/
|
---|
195 | IWineD3DPaletteImpl_QueryInterface,
|
---|
196 | IWineD3DPaletteImpl_AddRef,
|
---|
197 | IWineD3DPaletteImpl_Release,
|
---|
198 | /*** IWineD3DPalette ***/
|
---|
199 | IWineD3DPaletteImpl_GetParent,
|
---|
200 | IWineD3DPaletteImpl_GetEntries,
|
---|
201 | IWineD3DPaletteImpl_GetCaps,
|
---|
202 | IWineD3DPaletteImpl_SetEntries
|
---|
203 | };
|
---|