Commit f27bb660 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Explicitly pass the palette size to wined3d_palette_create().

parent 89dedf64
......@@ -236,16 +236,41 @@ struct ddraw_palette *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *if
return CONTAINING_RECORD(iface, struct ddraw_palette, IDirectDrawPalette_iface);
}
static unsigned int palette_size(DWORD flags)
{
switch (flags & (DDPCAPS_1BIT | DDPCAPS_2BIT | DDPCAPS_4BIT | DDPCAPS_8BIT))
{
case DDPCAPS_1BIT:
return 2;
case DDPCAPS_2BIT:
return 4;
case DDPCAPS_4BIT:
return 16;
case DDPCAPS_8BIT:
return 256;
default:
return ~0u;
}
}
HRESULT ddraw_palette_init(struct ddraw_palette *palette,
struct ddraw *ddraw, DWORD flags, PALETTEENTRY *entries)
{
unsigned int entry_count;
HRESULT hr;
if ((entry_count = palette_size(flags)) == ~0u)
{
WARN("Invalid flags %#x.\n", flags);
return DDERR_INVALIDPARAMS;
}
palette->IDirectDrawPalette_iface.lpVtbl = &ddraw_palette_vtbl;
palette->ref = 1;
palette->flags = flags;
if (FAILED(hr = wined3d_palette_create(ddraw->wined3d_device, flags, entries, &palette->wineD3DPalette)))
if (FAILED(hr = wined3d_palette_create(ddraw->wined3d_device,
flags, entry_count, entries, &palette->wineD3DPalette)))
{
WARN("Failed to create wined3d palette, hr %#x.\n", hr);
return hr;
......
......@@ -29,8 +29,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
#define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
ULONG CDECL wined3d_palette_incref(struct wined3d_palette *palette)
{
ULONG refcount = InterlockedIncrement(&palette->ref);
......@@ -55,28 +53,15 @@ ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette)
return refcount;
}
static WORD wined3d_palette_size(DWORD flags)
{
switch (flags & SIZE_BITS)
{
case WINEDDPCAPS_1BIT: return 2;
case WINEDDPCAPS_2BIT: return 4;
case WINEDDPCAPS_4BIT: return 16;
case WINEDDPCAPS_8BIT: return 256;
default:
FIXME("Unhandled size bits %#x.\n", flags & SIZE_BITS);
return 256;
}
}
HRESULT CDECL wined3d_palette_get_entries(const struct wined3d_palette *palette,
DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries)
{
TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n",
palette, flags, start, count, entries);
if (flags) return WINED3DERR_INVALIDCALL; /* unchecked */
if (start + count > wined3d_palette_size(palette->flags))
if (flags)
return WINED3DERR_INVALIDCALL; /* unchecked */
if (start > palette->palNumEntries || count > palette->palNumEntries - start)
return WINED3DERR_INVALIDCALL;
if (palette->flags & WINEDDPCAPS_8BITENTRIES)
......@@ -146,7 +131,7 @@ HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette,
}
static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wined3d_device *device,
DWORD flags, const PALETTEENTRY *entries)
DWORD flags, unsigned int entry_count, const PALETTEENTRY *entries)
{
HRESULT hr;
......@@ -154,7 +139,7 @@ static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wine
palette->device = device;
palette->flags = flags;
palette->palNumEntries = wined3d_palette_size(flags);
palette->palNumEntries = entry_count;
palette->hpal = CreatePalette((const LOGPALETTE *)&palette->palVersion);
if (!palette->hpal)
{
......@@ -162,8 +147,7 @@ static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wine
return E_FAIL;
}
hr = wined3d_palette_set_entries(palette, 0, 0, wined3d_palette_size(flags), entries);
if (FAILED(hr))
if (FAILED(hr = wined3d_palette_set_entries(palette, 0, 0, entry_count, entries)))
{
WARN("Failed to set palette entries, hr %#x.\n", hr);
DeleteObject(palette->hpal);
......@@ -174,7 +158,7 @@ static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wine
}
HRESULT CDECL wined3d_palette_create(struct wined3d_device *device, DWORD flags,
const PALETTEENTRY *entries, struct wined3d_palette **palette)
unsigned int entry_count, const PALETTEENTRY *entries, struct wined3d_palette **palette)
{
struct wined3d_palette *object;
HRESULT hr;
......@@ -186,8 +170,7 @@ HRESULT CDECL wined3d_palette_create(struct wined3d_device *device, DWORD flags,
if (!object)
return E_OUTOFMEMORY;
hr = wined3d_palette_init(object, device, flags, entries);
if (FAILED(hr))
if (FAILED(hr = wined3d_palette_init(object, device, flags, entry_count, entries)))
{
WARN("Failed to initialize palette, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
......
......@@ -156,7 +156,7 @@
@ cdecl wined3d_device_update_texture(ptr ptr ptr)
@ cdecl wined3d_device_validate_device(ptr ptr)
@ cdecl wined3d_palette_create(ptr long ptr ptr)
@ cdecl wined3d_palette_create(ptr long long ptr ptr)
@ cdecl wined3d_palette_decref(ptr)
@ cdecl wined3d_palette_get_entries(ptr long long long ptr)
@ cdecl wined3d_palette_incref(ptr)
......
......@@ -2234,7 +2234,7 @@ HRESULT __cdecl wined3d_device_update_texture(struct wined3d_device *device,
HRESULT __cdecl wined3d_device_validate_device(const struct wined3d_device *device, DWORD *num_passes);
HRESULT __cdecl wined3d_palette_create(struct wined3d_device *device, DWORD flags,
const PALETTEENTRY *entries, struct wined3d_palette **palette);
unsigned int entry_count, const PALETTEENTRY *entries, struct wined3d_palette **palette);
ULONG __cdecl wined3d_palette_decref(struct wined3d_palette *palette);
HRESULT __cdecl wined3d_palette_get_entries(const struct wined3d_palette *palette,
DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment