diff --git a/inc/ddpalette.h b/inc/ddpalette.h index 5f6d112527..e780b5af8c 100644 --- a/inc/ddpalette.h +++ b/inc/ddpalette.h @@ -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); diff --git a/src/ddpalette.c b/src/ddpalette.c index af18231b9d..46af3a1c65 100644 --- a/src/ddpalette.c +++ b/src/ddpalette.c @@ -5,6 +5,7 @@ #include "ddsurface.h" #include "IDirectDrawPalette.h" #include "debug.h" +#include "crc32.h" HRESULT ddp_GetEntries( @@ -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; @@ -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); diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index e06e6f129c..4bcfa3cb3e 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -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);