From f27bb660b3046e6df18e61bc006ad7f222b28547 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 13 Dec 2013 09:07:48 +0100 Subject: [PATCH] wined3d: Explicitly pass the palette size to wined3d_palette_create(). --- dlls/ddraw/palette.c | 27 ++++++++++++++++++++++++++- dlls/wined3d/palette.c | 33 ++++++++------------------------- dlls/wined3d/wined3d.spec | 2 +- include/wine/wined3d.h | 2 +- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/dlls/ddraw/palette.c b/dlls/ddraw/palette.c index f35531e4cde..214c91231db 100644 --- a/dlls/ddraw/palette.c +++ b/dlls/ddraw/palette.c @@ -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; diff --git a/dlls/wined3d/palette.c b/dlls/wined3d/palette.c index 555a9622deb..27e6b245b6f 100644 --- a/dlls/wined3d/palette.c +++ b/dlls/wined3d/palette.c @@ -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); diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index bbd5775aca7..a1a99d956e5 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -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) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 4599678da10..52f8e52ba2b 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -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);