2009-01-09 10:23:43 +01:00
|
|
|
/* DirectDraw - IDirectPalette base interface
|
2006-04-17 17:04:59 +02:00
|
|
|
*
|
|
|
|
* Copyright 1997-2000 Marcus Meissner
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2006 Stefan Dösinger for CodeWeavers
|
2006-04-17 17:04:59 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-04-17 17:04:59 +02:00
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2007-04-14 22:44:55 +02:00
|
|
|
#define SIZE_BITS (WINEDDPCAPS_1BIT | WINEDDPCAPS_2BIT | WINEDDPCAPS_4BIT | WINEDDPCAPS_8BIT)
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2009-12-20 20:41:39 +01:00
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID riid, void **object)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2009-12-20 20:41:39 +01:00
|
|
|
if (IsEqualGUID(riid, &IID_IWineD3DPalette)
|
|
|
|
|| IsEqualGUID(riid, &IID_IWineD3DBase)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
2006-04-17 17:04:59 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2009-12-20 20:41:39 +01:00
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DPaletteImpl_AddRef(IWineD3DPalette *iface) {
|
2006-04-17 17:04:59 +02:00
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
|
2006-04-17 17:04:59 +02:00
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
|
|
|
if (!ref) {
|
2007-12-31 03:03:35 +01:00
|
|
|
DeleteObject(This->hpal);
|
2006-04-17 17:04:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2006-04-21 00:00:30 +02:00
|
|
|
/* Not called from the vtable */
|
2010-11-18 20:50:40 +01:00
|
|
|
static WORD IWineD3DPaletteImpl_Size(DWORD flags)
|
2010-04-13 20:46:25 +02:00
|
|
|
{
|
2010-11-18 20:50:40 +01:00
|
|
|
switch (flags & SIZE_BITS)
|
|
|
|
{
|
2007-04-14 22:44:55 +02:00
|
|
|
case WINEDDPCAPS_1BIT: return 2;
|
|
|
|
case WINEDDPCAPS_2BIT: return 4;
|
|
|
|
case WINEDDPCAPS_4BIT: return 16;
|
|
|
|
case WINEDDPCAPS_8BIT: return 256;
|
2009-06-22 10:16:00 +02:00
|
|
|
default:
|
2010-11-18 20:50:40 +01:00
|
|
|
FIXME("Unhandled size bits %#x.\n", flags & SIZE_BITS);
|
2009-06-22 10:16:00 +02:00
|
|
|
return 256;
|
2006-04-21 00:00:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_GetEntries(IWineD3DPalette *iface,
|
|
|
|
DWORD flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt)
|
|
|
|
{
|
2006-04-21 00:00:30 +02:00
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
|
|
|
|
iface, flags, Start, Count, PalEnt);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
if (flags) return WINED3DERR_INVALIDCALL; /* unchecked */
|
2010-11-15 13:43:33 +01:00
|
|
|
if (Start + Count > IWineD3DPaletteImpl_Size(This->flags))
|
2006-04-21 00:00:30 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2010-11-15 13:43:33 +01:00
|
|
|
if (This->flags & WINEDDPCAPS_8BITENTRIES)
|
2006-04-21 00:00:30 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
LPBYTE entry = (LPBYTE)PalEnt;
|
|
|
|
|
|
|
|
for (i=Start; i < Count+Start; i++)
|
|
|
|
*entry++ = This->palents[i].peRed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memcpy(PalEnt, This->palents+Start, Count * sizeof(PALETTEENTRY));
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:57:39 +01:00
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface,
|
2010-11-18 20:50:40 +01:00
|
|
|
DWORD flags, DWORD Start, DWORD Count, const PALETTEENTRY *PalEnt)
|
2006-04-21 00:00:30 +02:00
|
|
|
{
|
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
2007-11-16 20:28:45 +01:00
|
|
|
IWineD3DResourceImpl *res;
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
TRACE("iface %p, flags %#x, start %u, count %u, entries %p.\n",
|
|
|
|
iface, flags, Start, Count, PalEnt);
|
2010-11-15 13:43:33 +01:00
|
|
|
TRACE("Palette flags: %#x.\n", This->flags);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2010-11-15 13:43:33 +01:00
|
|
|
if (This->flags & WINEDDPCAPS_8BITENTRIES)
|
|
|
|
{
|
2006-04-21 00:00:30 +02:00
|
|
|
unsigned int i;
|
|
|
|
const BYTE* entry = (const BYTE*)PalEnt;
|
|
|
|
|
|
|
|
for (i=Start; i < Count+Start; i++)
|
|
|
|
This->palents[i].peRed = *entry++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
|
|
|
|
|
2008-02-17 18:02:17 +01:00
|
|
|
/* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
|
2010-11-15 13:43:33 +01:00
|
|
|
if (!(This->flags & WINEDDPCAPS_ALLOW256))
|
2008-02-17 18:02:17 +01:00
|
|
|
{
|
|
|
|
TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n");
|
|
|
|
This->palents[0].peRed = 0;
|
|
|
|
This->palents[0].peGreen = 0;
|
|
|
|
This->palents[0].peBlue = 0;
|
|
|
|
|
|
|
|
This->palents[255].peRed = 255;
|
|
|
|
This->palents[255].peGreen = 255;
|
|
|
|
This->palents[255].peBlue = 255;
|
|
|
|
}
|
|
|
|
|
2006-04-21 00:00:30 +02:00
|
|
|
if (This->hpal)
|
|
|
|
SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Now, if we are in 'depth conversion mode', update the screen palette */
|
|
|
|
/* FIXME: we need to update the image or we won't get palette fading. */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (This->ddraw->d->palette_convert)
|
|
|
|
This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
|
2006-04-21 00:00:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If the palette is attached to the render target, update all render targets */
|
|
|
|
|
2009-12-09 20:32:08 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(res, &This->device->resources, IWineD3DResourceImpl, resource.resource_list_entry)
|
|
|
|
{
|
2011-01-24 11:19:37 +01:00
|
|
|
if (IWineD3DResource_GetType((IWineD3DResource *)res) == WINED3DRTYPE_SURFACE)
|
|
|
|
{
|
|
|
|
IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)res;
|
|
|
|
if (surface->palette == This)
|
|
|
|
surface->surface_ops->surface_realize_palette(surface);
|
2006-04-21 00:00:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_GetCaps(IWineD3DPalette *iface, DWORD *Caps) {
|
2006-04-21 00:00:30 +02:00
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
TRACE("(%p)->(%p)\n", This, Caps);
|
|
|
|
|
2010-11-15 13:43:33 +01:00
|
|
|
*Caps = This->flags;
|
2006-04-21 00:00:30 +02:00
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2010-08-31 18:41:40 +02:00
|
|
|
static void * WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface)
|
|
|
|
{
|
|
|
|
TRACE("iface %p.\n", iface);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2010-08-31 18:41:40 +02:00
|
|
|
return ((IWineD3DPaletteImpl *)iface)->parent;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2010-04-13 20:46:25 +02:00
|
|
|
static const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
|
2006-04-17 17:04:59 +02:00
|
|
|
{
|
|
|
|
/*** IUnknown ***/
|
|
|
|
IWineD3DPaletteImpl_QueryInterface,
|
|
|
|
IWineD3DPaletteImpl_AddRef,
|
|
|
|
IWineD3DPaletteImpl_Release,
|
|
|
|
/*** IWineD3DPalette ***/
|
|
|
|
IWineD3DPaletteImpl_GetParent,
|
|
|
|
IWineD3DPaletteImpl_GetEntries,
|
|
|
|
IWineD3DPaletteImpl_GetCaps,
|
|
|
|
IWineD3DPaletteImpl_SetEntries
|
|
|
|
};
|
2010-04-13 20:46:25 +02:00
|
|
|
|
|
|
|
HRESULT wined3d_palette_init(IWineD3DPaletteImpl *palette, IWineD3DDeviceImpl *device,
|
2010-08-31 18:41:40 +02:00
|
|
|
DWORD flags, const PALETTEENTRY *entries, void *parent)
|
2010-04-13 20:46:25 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
palette->lpVtbl = &IWineD3DPalette_Vtbl;
|
|
|
|
palette->ref = 1;
|
|
|
|
palette->parent = parent;
|
|
|
|
palette->device = device;
|
2010-11-15 13:43:33 +01:00
|
|
|
palette->flags = flags;
|
2010-04-13 20:46:25 +02:00
|
|
|
|
|
|
|
palette->palNumEntries = IWineD3DPaletteImpl_Size(flags);
|
|
|
|
palette->hpal = CreatePalette((const LOGPALETTE *)&palette->palVersion);
|
|
|
|
if (!palette->hpal)
|
|
|
|
{
|
|
|
|
WARN("Failed to create palette.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWineD3DPalette_SetEntries((IWineD3DPalette *)palette, 0, 0, IWineD3DPaletteImpl_Size(flags), entries);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to set palette entries, hr %#x.\n", hr);
|
|
|
|
DeleteObject(palette->hpal);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|