2006-04-17 17:04:59 +02:00
|
|
|
|
/* DirectDraw - IDirectPalette base interface
|
|
|
|
|
*
|
|
|
|
|
* Copyright 1997-2000 Marcus Meissner
|
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
|
|
|
|
* Copyright 2006 Stefan D<EFBFBD>singer for CodeWeavers
|
|
|
|
|
*
|
|
|
|
|
* 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 <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
|
2006-04-21 00:00:30 +02:00
|
|
|
|
#define SIZE_BITS (DDPCAPS_1BIT | DDPCAPS_2BIT | DDPCAPS_4BIT | DDPCAPS_8BIT)
|
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_QueryInterface(IWineD3DPalette *iface, REFIID refiid, void **obj) {
|
2006-04-17 17:04:59 +02:00
|
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
|
TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
|
|
|
|
|
|
|
|
|
|
if (IsEqualGUID(refiid, &IID_IUnknown)
|
|
|
|
|
|| IsEqualGUID(refiid, &IID_IWineD3DPalette)) {
|
|
|
|
|
*obj = iface;
|
|
|
|
|
IWineD3DPalette_AddRef(iface);
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2006-04-25 23:59:12 +02:00
|
|
|
|
*obj = NULL;
|
2006-04-17 17:04:59 +02:00
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 00:00:30 +02:00
|
|
|
|
/* Not called from the vtable */
|
|
|
|
|
DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) {
|
|
|
|
|
switch (dwFlags & SIZE_BITS) {
|
|
|
|
|
case DDPCAPS_1BIT: return 2;
|
|
|
|
|
case DDPCAPS_2BIT: return 4;
|
|
|
|
|
case DDPCAPS_4BIT: return 16;
|
|
|
|
|
case DDPCAPS_8BIT: return 256;
|
|
|
|
|
default: assert(0); return 256;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 13:15:32 +02: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;
|
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
|
TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
|
|
|
|
|
if (Flags != 0) return WINED3DERR_INVALIDCALL; /* unchecked */
|
|
|
|
|
if (Start + Count > IWineD3DPaletteImpl_Size(This->Flags))
|
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
|
|
if (This->Flags & DDPCAPS_8BITENTRIES)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface, DWORD Flags, DWORD Start, DWORD Count, PALETTEENTRY *PalEnt)
|
2006-04-21 00:00:30 +02:00
|
|
|
|
{
|
|
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
|
ResourceList *res;
|
|
|
|
|
|
2006-10-01 05:20:10 +02:00
|
|
|
|
TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
|
|
|
|
|
if (This->Flags & DDPCAPS_8BITENTRIES) {
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
if (This->ddraw->d->palette_convert != NULL)
|
|
|
|
|
This->ddraw->d->palette_convert(palent,This->screen_palents,start,count);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* If the palette is attached to the render target, update all render targets */
|
|
|
|
|
|
|
|
|
|
for(res = This->wineD3DDevice->resources; res != NULL; res=res->next) {
|
2007-02-15 13:31:54 +01:00
|
|
|
|
if(IWineD3DResource_GetType(res->resource) == WINED3DRTYPE_SURFACE) {
|
2006-04-21 00:00:30 +02:00
|
|
|
|
IWineD3DSurfaceImpl *impl = (IWineD3DSurfaceImpl *) res->resource;
|
|
|
|
|
if(impl->palette == This)
|
|
|
|
|
IWineD3DSurface_RealizePalette( (IWineD3DSurface *) res->resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-09 20:47:03 +02:00
|
|
|
|
/* If the palette is the primary palette, set the entries to the device */
|
|
|
|
|
if(This->Flags & DDPCAPS_PRIMARYSURFACE) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
IWineD3DDeviceImpl *device = This->wineD3DDevice;
|
|
|
|
|
PALETTEENTRY *entry = PalEnt;
|
|
|
|
|
|
|
|
|
|
for(i = Start; i < Start+Count; i++) {
|
|
|
|
|
device->palettes[device->currentPalette][i] = *entry++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
*Caps = This->Flags;
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-10 13:15:32 +02:00
|
|
|
|
static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUnknown **Parent) {
|
2006-04-21 00:00:30 +02:00
|
|
|
|
IWineD3DPaletteImpl *This = (IWineD3DPaletteImpl *)iface;
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, Parent);
|
|
|
|
|
|
|
|
|
|
*Parent = (IUnknown *) This->parent;
|
|
|
|
|
IUnknown_AddRef( (IUnknown *) This->parent);
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
|
|
|
|
|
{
|
|
|
|
|
/*** IUnknown ***/
|
|
|
|
|
IWineD3DPaletteImpl_QueryInterface,
|
|
|
|
|
IWineD3DPaletteImpl_AddRef,
|
|
|
|
|
IWineD3DPaletteImpl_Release,
|
|
|
|
|
/*** IWineD3DPalette ***/
|
|
|
|
|
IWineD3DPaletteImpl_GetParent,
|
|
|
|
|
IWineD3DPaletteImpl_GetEntries,
|
|
|
|
|
IWineD3DPaletteImpl_GetCaps,
|
|
|
|
|
IWineD3DPaletteImpl_SetEntries
|
|
|
|
|
};
|