Skip to content

Commit

Permalink
make sure we don't update the palette twice
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 16, 2024
1 parent bbe8c4f commit 39b2e69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions inc/ddpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "IDirectDrawPalette.h"
#include "dd.h"

#define DDPCAPS_REFRESH_CHANGED_ONLY (1 << 31)

HRESULT ddp_GetEntries(IDirectDrawPaletteImpl* This, DWORD dwFlags, DWORD dwBase, DWORD dwNumEntries, LPPALETTEENTRY lpEntries);
HRESULT ddp_SetEntries(IDirectDrawPaletteImpl* This, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries);
HRESULT dd_CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, IDirectDrawPaletteImpl** lpDDPalette, IUnknown FAR* unkOuter);
Expand Down
14 changes: 14 additions & 0 deletions src/ddpalette.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ddsurface.h"
#include "IDirectDrawPalette.h"
#include "debug.h"
#include "crc32.h"


HRESULT ddp_GetEntries(
Expand Down Expand Up @@ -38,6 +39,13 @@ HRESULT ddp_SetEntries(
if (!lpEntries)
return DDERR_INVALIDPARAMS;

unsigned long crc32 = 0;

if ((dwFlags & DDPCAPS_REFRESH_CHANGED_ONLY))
{
crc32 = Crc32_ComputeBuf(0, This->data_rgb, sizeof(This->data_rgb));
}

for (int i = dwStartingEntry, x = 0; i < dwStartingEntry + dwCount && i < 256; i++, x++)
{
This->data_bgr[i] = (lpEntries[x].peBlue << 16) | (lpEntries[x].peGreen << 8) | lpEntries[x].peRed;
Expand All @@ -64,6 +72,12 @@ HRESULT ddp_SetEntries(
This->data_rgb[255].rgbReserved = 0;
}

if (crc32 && crc32 == Crc32_ComputeBuf(0, This->data_rgb, sizeof(This->data_rgb)))
{
// do not set palette_updated BOOL if nothing changed
return DD_OK;
}

if (g_ddraw.ref && g_ddraw.primary && g_ddraw.primary->palette == This && g_ddraw.render.run)
{
InterlockedExchange(&g_ddraw.render.palette_updated, TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/winapi_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ UINT WINAPI fake_RealizePalette(HDC hdc)

ddp_SetEntries(
g_ddraw.primary->palette,
0,
DDPCAPS_REFRESH_CHANGED_ONLY,
0,
g_ddraw.primary->selected_pal_count,
g_ddraw.primary->selected_pal);
Expand Down

0 comments on commit 39b2e69

Please sign in to comment.