2010-09-08 11:24:49 +02:00
|
|
|
/*
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright 2006 Stefan Dösinger
|
2006-06-09 19:36:12 +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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ddraw_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPalette::QueryInterface
|
|
|
|
*
|
|
|
|
* A usual QueryInterface implementation. Can only Query IUnknown and
|
|
|
|
* IDirectDrawPalette
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* refiid: The interface id queried for
|
|
|
|
* obj: Address to return the interface pointer at
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* S_OK on success
|
|
|
|
* E_NOINTERFACE if the requested interface wasn't found
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static HRESULT WINAPI ddraw_palette_QueryInterface(IDirectDrawPalette *iface, REFIID refiid, void **obj)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(refiid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(refiid, &IID_IDirectDrawPalette))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IDirectDrawPalette_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*obj = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPaletteImpl::AddRef
|
|
|
|
*
|
|
|
|
* Increases the refcount.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static ULONG WINAPI ddraw_palette_AddRef(IDirectDrawPalette *iface)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-03-12 19:56:10 +01:00
|
|
|
struct ddraw_palette *This = impl_from_IDirectDrawPalette(iface);
|
2006-06-09 19:36:12 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-04-14 15:27:40 +02:00
|
|
|
TRACE("%p increasing refcount to %lu.\n", This, ref);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPaletteImpl::Release
|
|
|
|
*
|
|
|
|
* Reduces the refcount. If the refcount falls to 0, the object is destroyed
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static ULONG WINAPI ddraw_palette_Release(IDirectDrawPalette *iface)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2016-08-26 13:51:21 +02:00
|
|
|
struct ddraw_palette *palette = impl_from_IDirectDrawPalette(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&palette->ref);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2022-04-14 15:27:40 +02:00
|
|
|
TRACE("%p decreasing refcount to %lu.\n", palette, ref);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-08-26 13:51:21 +02:00
|
|
|
wined3d_palette_decref(palette->wined3d_palette);
|
|
|
|
if ((palette->flags & DDPCAPS_PRIMARYSURFACE) && palette->ddraw->primary)
|
|
|
|
palette->ddraw->primary->palette = NULL;
|
|
|
|
if (palette->ifaceToRelease)
|
|
|
|
IUnknown_Release(palette->ifaceToRelease);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2018-02-13 10:32:47 +01:00
|
|
|
heap_free(palette);
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPalette::Initialize
|
|
|
|
*
|
|
|
|
* Initializes the palette. As we start initialized, return
|
|
|
|
* DDERR_ALREADYINITIALIZED
|
|
|
|
*
|
|
|
|
* Params:
|
2008-04-02 21:26:42 +02:00
|
|
|
* DD: DirectDraw interface this palette is assigned to
|
2006-06-09 19:36:12 +02:00
|
|
|
* Flags: Some flags, as usual
|
|
|
|
* ColorTable: The startup color table
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDERR_ALREADYINITIALIZED
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static HRESULT WINAPI ddraw_palette_Initialize(IDirectDrawPalette *iface,
|
|
|
|
IDirectDraw *ddraw, DWORD flags, PALETTEENTRY *entries)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2022-04-14 15:27:40 +02:00
|
|
|
TRACE("iface %p, ddraw %p, flags %#lx, entries %p.\n",
|
2012-03-12 19:56:10 +01:00
|
|
|
iface, ddraw, flags, entries);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_ALREADYINITIALIZED;
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
static HRESULT WINAPI ddraw_palette_GetCaps(IDirectDrawPalette *iface, DWORD *caps)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-03-12 19:56:10 +01:00
|
|
|
struct ddraw_palette *palette = impl_from_IDirectDrawPalette(iface);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
TRACE("iface %p, caps %p.\n", iface, caps);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2013-12-12 10:23:32 +01:00
|
|
|
*caps = palette->flags;
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2011-02-02 20:22:52 +01:00
|
|
|
|
|
|
|
return D3D_OK;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPalette::SetEntries
|
|
|
|
*
|
|
|
|
* Sets the palette entries from a PALETTEENTRY structure. WineD3D takes
|
|
|
|
* care for updating the surface.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Flags: Flags, as usual
|
|
|
|
* Start: First palette entry to set
|
|
|
|
* Count: Number of entries to set
|
|
|
|
* PalEnt: Source entries
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if PalEnt is NULL
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static HRESULT WINAPI ddraw_palette_SetEntries(IDirectDrawPalette *iface,
|
|
|
|
DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-03-12 19:56:10 +01:00
|
|
|
struct ddraw_palette *palette = impl_from_IDirectDrawPalette(iface);
|
2007-05-30 16:11:25 +02:00
|
|
|
HRESULT hr;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2022-04-14 15:27:40 +02:00
|
|
|
TRACE("iface %p, flags %#lx, start %lu, count %lu, entries %p.\n",
|
2012-03-12 19:56:10 +01:00
|
|
|
iface, flags, start, count, entries);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
if (!entries)
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-08-26 13:51:21 +02:00
|
|
|
hr = wined3d_palette_set_entries(palette->wined3d_palette, flags, start, count, entries);
|
2014-06-28 10:49:32 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && palette->flags & DDPCAPS_PRIMARYSURFACE)
|
2018-03-27 13:06:52 +02:00
|
|
|
ddraw_surface_update_frontbuffer(palette->ddraw->primary, NULL, FALSE, 0);
|
2014-06-28 10:49:32 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-30 16:11:25 +02:00
|
|
|
return hr;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectDrawPalette::GetEntries
|
|
|
|
*
|
|
|
|
* Returns the entries stored in this interface.
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* Flags: Flags :)
|
|
|
|
* Start: First entry to return
|
|
|
|
* Count: The number of entries to return
|
|
|
|
* PalEnt: PALETTEENTRY structure to write the entries to
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* D3D_OK on success
|
|
|
|
* DDERR_INVALIDPARAMS if PalEnt is NULL
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2012-03-12 19:56:10 +01:00
|
|
|
static HRESULT WINAPI ddraw_palette_GetEntries(IDirectDrawPalette *iface,
|
|
|
|
DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-03-12 19:56:10 +01:00
|
|
|
struct ddraw_palette *palette = impl_from_IDirectDrawPalette(iface);
|
2007-05-30 16:11:25 +02:00
|
|
|
HRESULT hr;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2022-04-14 15:27:40 +02:00
|
|
|
TRACE("iface %p, flags %#lx, start %lu, count %lu, entries %p.\n",
|
2012-03-12 19:56:10 +01:00
|
|
|
iface, flags, start, count, entries);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
if (!entries)
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2016-08-26 13:51:21 +02:00
|
|
|
hr = wined3d_palette_get_entries(palette->wined3d_palette, flags, start, count, entries);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-30 16:11:25 +02:00
|
|
|
return hr;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
|
|
|
|
2020-04-27 05:58:28 +02:00
|
|
|
/* Some windowed mode wrappers expect this vtbl to be writable. */
|
|
|
|
static struct IDirectDrawPaletteVtbl ddraw_palette_vtbl =
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
|
|
|
/*** IUnknown ***/
|
2012-03-12 19:56:10 +01:00
|
|
|
ddraw_palette_QueryInterface,
|
|
|
|
ddraw_palette_AddRef,
|
|
|
|
ddraw_palette_Release,
|
2006-06-09 19:36:12 +02:00
|
|
|
/*** IDirectDrawPalette ***/
|
2012-03-12 19:56:10 +01:00
|
|
|
ddraw_palette_GetCaps,
|
|
|
|
ddraw_palette_GetEntries,
|
|
|
|
ddraw_palette_Initialize,
|
|
|
|
ddraw_palette_SetEntries
|
2006-06-09 19:36:12 +02:00
|
|
|
};
|
2010-08-19 18:57:46 +02:00
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
struct ddraw_palette *unsafe_impl_from_IDirectDrawPalette(IDirectDrawPalette *iface)
|
2011-10-04 00:14:08 +02:00
|
|
|
{
|
|
|
|
if (!iface) return NULL;
|
|
|
|
assert(iface->lpVtbl == &ddraw_palette_vtbl);
|
2012-03-12 19:56:10 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct ddraw_palette, IDirectDrawPalette_iface);
|
2011-10-04 00:14:08 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 19:56:10 +01:00
|
|
|
HRESULT ddraw_palette_init(struct ddraw_palette *palette,
|
2012-03-08 20:27:16 +01:00
|
|
|
struct ddraw *ddraw, DWORD flags, PALETTEENTRY *entries)
|
2010-08-19 18:57:46 +02:00
|
|
|
{
|
2013-12-13 09:07:48 +01:00
|
|
|
unsigned int entry_count;
|
2013-12-13 09:07:49 +01:00
|
|
|
DWORD wined3d_flags = 0;
|
2010-08-19 18:57:46 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
if ((entry_count = palette_size(flags)) == ~0u)
|
|
|
|
{
|
2022-04-14 15:27:40 +02:00
|
|
|
WARN("Invalid flags %#lx.\n", flags);
|
2013-12-13 09:07:48 +01:00
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:07:49 +01:00
|
|
|
if (flags & DDPCAPS_8BITENTRIES)
|
|
|
|
wined3d_flags |= WINED3D_PALETTE_8BIT_ENTRIES;
|
|
|
|
if (flags & DDPCAPS_ALLOW256)
|
|
|
|
wined3d_flags |= WINED3D_PALETTE_ALLOW_256;
|
|
|
|
if (flags & DDPCAPS_ALPHA)
|
|
|
|
wined3d_flags |= WINED3D_PALETTE_ALPHA;
|
|
|
|
|
2011-10-04 00:14:27 +02:00
|
|
|
palette->IDirectDrawPalette_iface.lpVtbl = &ddraw_palette_vtbl;
|
2010-08-19 18:57:46 +02:00
|
|
|
palette->ref = 1;
|
2013-12-12 10:23:32 +01:00
|
|
|
palette->flags = flags;
|
2010-08-19 18:57:46 +02:00
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
if (FAILED(hr = wined3d_palette_create(ddraw->wined3d_device,
|
2016-08-26 13:51:21 +02:00
|
|
|
wined3d_flags, entry_count, entries, &palette->wined3d_palette)))
|
2010-08-19 18:57:46 +02:00
|
|
|
{
|
2022-04-14 15:27:40 +02:00
|
|
|
WARN("Failed to create wined3d palette, hr %#lx.\n", hr);
|
2010-08-19 18:57:46 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-12-13 09:07:45 +01:00
|
|
|
palette->ddraw = ddraw;
|
2011-01-19 01:42:43 +01:00
|
|
|
palette->ifaceToRelease = (IUnknown *)&ddraw->IDirectDraw7_iface;
|
2010-08-19 18:57:46 +02:00
|
|
|
IUnknown_AddRef(palette->ifaceToRelease);
|
|
|
|
|
|
|
|
return DD_OK;
|
|
|
|
}
|