VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c@ 32891

Last change on this file since 32891 was 28475, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.43

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
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
39WINE_DEFAULT_DEBUG_CHANNEL(d3d);
40
41#define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
42
43static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID riid, void **object)
44{
45 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
46
47 if (IsEqualGUID(riid, &IID_IWineD3DPalette)
48 || IsEqualGUID(riid, &IID_IWineD3DBase)
49 || IsEqualGUID(riid, &IID_IUnknown))
50 {
51 IUnknown_AddRef(iface);
52 *object = iface;
53 return S_OK;
54 }
55
56 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
57
58 *object = NULL;
59 return E_NOINTERFACE;
60}
61
62static ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
63 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
64 ULONG ref = InterlockedIncrement(&This->ref);
65
66 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
67
68 return ref;
69}
70
71static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
72 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
73 ULONG ref = InterlockedDecrement(&This->ref);
74
75 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
76
77 if (!ref) {
78 DeleteObject(This->hpal);
79 HeapFree(GetProcessHeap(), 0, This);
80 return 0;
81 }
82
83 return ref;
84}
85
86/* Not called from the vtable */
87static DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags)
88{
89 switch (dwFlags & SIZE_BITS) {
90 case WINEDDPCAPS_1BIT: return 2;
91 case WINEDDPCAPS_2BIT: return 4;
92 case WINEDDPCAPS_4BIT: return 16;
93 case WINEDDPCAPS_8BIT: return 256;
94 default:
95 FIXME("Unhandled size bits %#x.\n", dwFlags & SIZE_BITS);
96 return 256;
97 }
98}
99
100static HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt) {
101 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
102
103 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
104
105 if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
106 if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
107 return WINED3DERR_INVALIDCALL;
108
109 if (This->Flags & WINEDDPCAPS_8BITENTRIES)
110 {
111 unsigned int i;
112 LPBYTE entry = (LPBYTE)PalEnt;
113
114 for (i=Start; i < Count+Start; i++)
115 *entry++ = This->palents[i].peRed;
116 }
117 else
118 memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
119
120 return WINED3D_OK;
121}
122
123static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface,
124 DWORD Flags, DWORD Start, DWORD Count, const PALETTEENTRY *PalEnt)
125{
126 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
127 IWineD3DResourceImpl *res;
128
129 TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
130 TRACE("Palette flags: %#x\n", This->Flags);
131
132 if (This->Flags & WINEDDPCAPS_8BITENTRIES) {
133 unsigned int i;
134 const BYTE* entry = (const BYTE*)PalEnt;
135
136 for (i=Start; i < Count+Start; i++)
137 This->palents[i].peRed = *entry++;
138 }
139 else {
140 memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
141
142 /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
143 if(!(This->Flags & WINEDDPCAPS_ALLOW256))
144 {
145 TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n");
146 This->palents[0].peRed = 0;
147 This->palents[0].peGreen = 0;
148 This->palents[0].peBlue = 0;
149
150 This->palents[255].peRed = 255;
151 This->palents[255].peGreen = 255;
152 This->palents[255].peBlue = 255;
153 }
154
155 if (This->hpal)
156 SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
157 }
158
159#if 0
160 /* Now, if we are in 'depth conversion mode', update the screen palette */
161 /* FIXME: we need to update the image or we won't get palette fading. */
162 if (This->ddraw->d->palette_convert != NULL)
163 This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
164#endif
165
166 /* If the palette is attached to the render target, update all render targets */
167
168 LIST_FOR_EACH_ENTRY(res, &This->device->resources, IWineD3DResourceImpl, resource.resource_list_entry)
169 {
170 if(IWineD3DResource_GetType((IWineD3DResource *) res) == WINED3DRTYPE_SURFACE) {
171 IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res;
172 if(impl->palette == This)
173 IWineD3DSurface_RealizePalette((IWineD3DSurface *) res);
174 }
175 }
176
177 return WINED3D_OK;
178}
179
180static HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
181 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
182 TRACE("(%p)->(%p)\n", This, Caps);
183
184 *Caps = This->Flags;
185 return WINED3D_OK;
186}
187
188static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
189 IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
190 TRACE("(%p)->(%p)\n", This, Parent);
191
192 *Parent = This->parent;
193 IUnknown_AddRef(This->parent);
194 return WINED3D_OK;
195}
196
197static const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
198{
199 /*** IUnknown ***/
200 IWineD3DPaletteImpl_QueryInterface,
201 IWineD3DPaletteImpl_AddRef,
202 IWineD3DPaletteImpl_Release,
203 /*** IWineD3DPalette ***/
204 IWineD3DPaletteImpl_GetParent,
205 IWineD3DPaletteImpl_GetEntries,
206 IWineD3DPaletteImpl_GetCaps,
207 IWineD3DPaletteImpl_SetEntries
208};
209
210HRESULT wined3d_palette_init(IWineD3DPaletteImpl *palette, IWineD3DDeviceImpl *device,
211 DWORD flags, const PALETTEENTRY *entries, IUnknown *parent)
212{
213 HRESULT hr;
214
215 palette->lpVtbl = &IWineD3DPalette_Vtbl;
216 palette->ref = 1;
217 palette->parent = parent;
218 palette->device = device;
219 palette->Flags = flags;
220
221 palette->palNumEntries = IWineD3DPaletteImpl_Size(flags);
222 palette->hpal = CreatePalette((const LOGPALETTE *)&palette->palVersion);
223 if (!palette->hpal)
224 {
225 WARN("Failed to create palette.\n");
226 return E_FAIL;
227 }
228
229 hr = IWineD3DPalette_SetEntries((IWineD3DPalette *)palette, 0, 0, IWineD3DPaletteImpl_Size(flags), entries);
230 if (FAILED(hr))
231 {
232 WARN("Failed to set palette entries, hr %#x.\n", hr);
233 DeleteObject(palette->hpal);
234 return hr;
235 }
236
237 return WINED3D_OK;
238}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette