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
|
|
|
*/
|
2021-12-01 15:56:55 +01:00
|
|
|
|
2006-04-17 17:04:59 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
ULONG CDECL wined3d_palette_incref(struct wined3d_palette *palette)
|
2009-12-20 20:41:39 +01:00
|
|
|
{
|
2011-02-02 20:22:52 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&palette->ref);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", palette, refcount);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
return refcount;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2016-06-22 10:39:04 +02:00
|
|
|
static void wined3d_palette_destroy_object(void *object)
|
|
|
|
{
|
2021-02-11 11:52:16 +01:00
|
|
|
TRACE("object %p.\n", object);
|
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(object);
|
2016-06-22 10:39:04 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&palette->ref);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", palette, refcount);
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
if (!refcount)
|
2021-10-15 14:25:57 +02:00
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(palette->device->cs, wined3d_palette_destroy_object, palette);
|
2021-10-15 14:25:57 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
2006-04-17 17:04:59 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
return refcount;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
HRESULT CDECL wined3d_palette_get_entries(const struct wined3d_palette *palette,
|
|
|
|
DWORD flags, DWORD start, DWORD count, PALETTEENTRY *entries)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2014-05-07 18:02:14 +02:00
|
|
|
unsigned int i;
|
2011-02-02 20:22:52 +01:00
|
|
|
TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n",
|
|
|
|
palette, flags, start, count, entries);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
if (flags)
|
|
|
|
return WINED3DERR_INVALIDCALL; /* unchecked */
|
2021-07-07 03:43:42 +02:00
|
|
|
if (!wined3d_bound_range(start, count, palette->size))
|
2006-04-21 00:00:30 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2013-12-13 09:07:49 +01:00
|
|
|
if (palette->flags & WINED3D_PALETTE_8BIT_ENTRIES)
|
2006-04-21 00:00:30 +02:00
|
|
|
{
|
2011-02-02 20:22:52 +01:00
|
|
|
BYTE *entry = (BYTE *)entries;
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
for (i = start; i < count + start; ++i)
|
2014-05-07 18:02:14 +02:00
|
|
|
*entry++ = palette->colors[i].rgbRed;
|
2006-04-21 00:00:30 +02:00
|
|
|
}
|
|
|
|
else
|
2014-05-07 18:02:14 +02:00
|
|
|
{
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
entries[i].peRed = palette->colors[i + start].rgbRed;
|
|
|
|
entries[i].peGreen = palette->colors[i + start].rgbGreen;
|
|
|
|
entries[i].peBlue = palette->colors[i + start].rgbBlue;
|
|
|
|
entries[i].peFlags = palette->colors[i + start].rgbReserved;
|
|
|
|
}
|
|
|
|
}
|
2006-04-21 00:00:30 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 16:13:31 +02:00
|
|
|
void CDECL wined3d_palette_apply_to_dc(const struct wined3d_palette *palette, HDC dc)
|
|
|
|
{
|
|
|
|
if (SetDIBColorTable(dc, 0, 256, palette->colors) != 256)
|
|
|
|
ERR("Failed to set DIB color table.\n");
|
|
|
|
}
|
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
HRESULT CDECL wined3d_palette_set_entries(struct wined3d_palette *palette,
|
|
|
|
DWORD flags, DWORD start, DWORD count, const PALETTEENTRY *entries)
|
2006-04-21 00:00:30 +02:00
|
|
|
{
|
2014-05-07 18:02:14 +02:00
|
|
|
unsigned int i;
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
TRACE("palette %p, flags %#x, start %u, count %u, entries %p.\n",
|
|
|
|
palette, flags, start, count, entries);
|
|
|
|
TRACE("Palette flags: %#x.\n", palette->flags);
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2019-01-12 12:23:18 +01:00
|
|
|
wined3d_cs_finish(palette->device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
|
|
|
|
2013-12-13 09:07:49 +01:00
|
|
|
if (palette->flags & WINED3D_PALETTE_8BIT_ENTRIES)
|
2010-11-15 13:43:33 +01:00
|
|
|
{
|
2011-02-02 20:22:52 +01:00
|
|
|
const BYTE *entry = (const BYTE *)entries;
|
2006-04-21 00:00:30 +02:00
|
|
|
|
2011-02-02 20:22:52 +01:00
|
|
|
for (i = start; i < count + start; ++i)
|
2014-05-07 18:02:14 +02:00
|
|
|
palette->colors[i].rgbRed = *entry++;
|
2006-04-21 00:00:30 +02:00
|
|
|
}
|
2011-02-02 20:22:52 +01:00
|
|
|
else
|
|
|
|
{
|
2014-05-07 18:02:14 +02:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
palette->colors[i + start].rgbRed = entries[i].peRed;
|
|
|
|
palette->colors[i + start].rgbGreen = entries[i].peGreen;
|
|
|
|
palette->colors[i + start].rgbBlue = entries[i].peBlue;
|
|
|
|
palette->colors[i + start].rgbReserved = entries[i].peFlags;
|
|
|
|
}
|
2006-04-21 00:00:30 +02:00
|
|
|
|
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 */
|
2013-12-13 09:07:49 +01:00
|
|
|
if (!(palette->flags & WINED3D_PALETTE_ALLOW_256))
|
2008-02-17 18:02:17 +01:00
|
|
|
{
|
2013-12-13 09:07:49 +01:00
|
|
|
TRACE("WINED3D_PALETTE_ALLOW_256 not set, overriding palette entry 0 with black and 255 with white.\n");
|
2014-05-07 18:02:14 +02:00
|
|
|
palette->colors[0].rgbRed = 0;
|
|
|
|
palette->colors[0].rgbGreen = 0;
|
|
|
|
palette->colors[0].rgbBlue = 0;
|
2008-02-17 18:02:17 +01:00
|
|
|
|
2014-05-07 18:02:14 +02:00
|
|
|
palette->colors[255].rgbRed = 255;
|
|
|
|
palette->colors[255].rgbGreen = 255;
|
|
|
|
palette->colors[255].rgbBlue = 255;
|
2008-02-17 18:02:17 +01:00
|
|
|
}
|
2006-04-21 00:00:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2006-04-17 17:04:59 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT wined3d_palette_init(struct wined3d_palette *palette, struct wined3d_device *device,
|
2013-12-13 09:07:48 +01:00
|
|
|
DWORD flags, unsigned int entry_count, const PALETTEENTRY *entries)
|
2010-04-13 20:46:25 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
palette->ref = 1;
|
|
|
|
palette->device = device;
|
2010-11-15 13:43:33 +01:00
|
|
|
palette->flags = flags;
|
2014-05-02 13:43:24 +02:00
|
|
|
palette->size = entry_count;
|
2010-04-13 20:46:25 +02:00
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
if (FAILED(hr = wined3d_palette_set_entries(palette, 0, 0, entry_count, entries)))
|
2010-04-13 20:46:25 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to set palette entries, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_palette_create(struct wined3d_device *device, DWORD flags,
|
2013-12-13 09:07:48 +01:00
|
|
|
unsigned int entry_count, const PALETTEENTRY *entries, struct wined3d_palette **palette)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_palette *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("device %p, flags %#x, entry_count %u, entries %p, palette %p.\n",
|
|
|
|
device, flags, entry_count, entries, palette);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2018-02-14 07:39:59 +01:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2011-05-10 21:18:47 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-12-13 09:07:48 +01:00
|
|
|
if (FAILED(hr = wined3d_palette_init(object, device, flags, entry_count, entries)))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize palette, hr %#x.\n", hr);
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(object);
|
2011-05-10 21:18:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created palette %p.\n", object);
|
|
|
|
*palette = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|