Fixed cache issues

* Use rdpContext as reference instance
* WINPR_ASSERT what is not otherwise checked
This commit is contained in:
Armin Novak 2021-09-06 14:00:12 +02:00 committed by akallabeth
parent 520367b2da
commit 85f1d46eab
17 changed files with 221 additions and 82 deletions

View File

@ -53,9 +53,7 @@ struct rdp_bitmap_cache
UINT32 paddingB[32 - 18]; /* 18 */
/* internal */
rdpUpdate* update;
rdpContext* context;
rdpSettings* settings;
};
#ifdef __cplusplus
@ -65,7 +63,7 @@ extern "C"
FREERDP_API void bitmap_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpBitmapCache* bitmap_cache_new(rdpSettings* settings);
FREERDP_API rdpBitmapCache* bitmap_cache_new(rdpContext* context);
FREERDP_API void bitmap_cache_free(rdpBitmapCache* bitmap_cache);
#ifdef __cplusplus

View File

@ -41,7 +41,7 @@ extern "C"
FREERDP_API void brush_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpBrushCache* brush_cache_new(rdpSettings* settings);
FREERDP_API rdpBrushCache* brush_cache_new(rdpContext* context);
FREERDP_API void brush_cache_free(rdpBrushCache* brush);
#ifdef __cplusplus

View File

@ -50,7 +50,7 @@ extern "C"
{
#endif
FREERDP_API rdpCache* cache_new(rdpSettings* settings);
FREERDP_API rdpCache* cache_new(rdpContext* context);
FREERDP_API void cache_free(rdpCache* cache);
#ifdef __cplusplus

View File

@ -59,7 +59,6 @@ struct rdp_glyph_cache
wLog* log;
rdpContext* context;
rdpSettings* settings;
};
#ifdef __cplusplus
@ -69,7 +68,7 @@ extern "C"
FREERDP_API void glyph_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpGlyphCache* glyph_cache_new(rdpSettings* settings);
FREERDP_API rdpGlyphCache* glyph_cache_new(rdpContext* context);
FREERDP_API void glyph_cache_free(rdpGlyphCache* glyph);
#ifdef __cplusplus

View File

@ -38,7 +38,7 @@ extern "C"
FREERDP_API void nine_grid_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpNineGridCache* nine_grid_cache_new(rdpSettings* settings);
FREERDP_API rdpNineGridCache* nine_grid_cache_new(rdpContext* context);
FREERDP_API void nine_grid_cache_free(rdpNineGridCache* nine_grid);
#ifdef __cplusplus

View File

@ -38,7 +38,7 @@ extern "C"
FREERDP_API void offscreen_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings);
FREERDP_API rdpOffscreenCache* offscreen_cache_new(rdpContext* context);
FREERDP_API void offscreen_cache_free(rdpOffscreenCache* offscreen);
#ifdef __cplusplus

View File

@ -44,7 +44,7 @@ struct rdp_palette_cache
/* internal */
rdpSettings* settings;
rdpContext* context;
};
#ifdef __cplusplus
@ -54,7 +54,7 @@ extern "C"
FREERDP_API void palette_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpPaletteCache* palette_cache_new(rdpSettings* settings);
FREERDP_API rdpPaletteCache* palette_cache_new(rdpContext* context);
FREERDP_API void palette_cache_free(rdpPaletteCache* palette_cache);
#ifdef __cplusplus

View File

@ -38,9 +38,7 @@ struct rdp_pointer_cache
rdpPointer** entries; /* 1 */
/* internal */
rdpUpdate* update;
rdpSettings* settings;
rdpContext* context;
};
#ifdef __cplusplus
@ -50,7 +48,7 @@ extern "C"
FREERDP_API void pointer_cache_register_callbacks(rdpUpdate* update);
FREERDP_API rdpPointerCache* pointer_cache_new(rdpSettings* settings);
FREERDP_API rdpPointerCache* pointer_cache_new(rdpContext* context);
FREERDP_API void pointer_cache_free(rdpPointerCache* pointer_cache);
#ifdef __cplusplus

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <freerdp/freerdp.h>
#include <freerdp/constants.h>
@ -47,7 +48,9 @@ static BOOL bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 ind
static BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
{
rdpBitmap* bitmap;
rdpCache* cache = context->cache;
rdpCache* cache;
cache = context->cache;
if (memblt->cacheId == 0xFF)
bitmap = offscreen_cache_get(cache->offscreen, memblt->cacheIndex);
@ -269,18 +272,23 @@ void bitmap_cache_register_callbacks(rdpUpdate* update)
update->BitmapUpdate = gdi_bitmap_update;
}
rdpBitmapCache* bitmap_cache_new(rdpSettings* settings)
rdpBitmapCache* bitmap_cache_new(rdpContext* context)
{
UINT32 i;
rdpSettings* settings;
rdpBitmapCache* bitmapCache;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
bitmapCache = (rdpBitmapCache*)calloc(1, sizeof(rdpBitmapCache));
if (!bitmapCache)
return NULL;
bitmapCache->settings = settings;
bitmapCache->update = ((freerdp*)settings->instance)->update;
bitmapCache->context = bitmapCache->update->context;
bitmapCache->context = context;
bitmapCache->cells =
(BITMAP_V2_CELL*)calloc(settings->BitmapCacheV2NumCells, sizeof(BITMAP_V2_CELL));

View File

@ -23,6 +23,7 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <freerdp/log.h>
#include <freerdp/update.h>
@ -58,15 +59,23 @@ struct rdp_brush_cache
/* internal */
rdpSettings* settings;
rdpContext* context;
};
static BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
BYTE style;
BOOL ret = TRUE;
rdpBrush* brush = &patblt->brush;
const rdpCache* cache = context->cache;
rdpBrush* brush;
const rdpCache* cache;
WINPR_ASSERT(context);
WINPR_ASSERT(patblt);
cache = context->cache;
WINPR_ASSERT(cache);
brush = &patblt->brush;
style = brush->style;
if (brush->style & CACHED_BRUSH)
@ -75,6 +84,7 @@ static BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
brush->style = 0x03;
}
WINPR_ASSERT(cache->brush);
IFCALLRET(cache->brush->PatBlt, ret, context, patblt);
brush->style = style;
return ret;
@ -82,16 +92,28 @@ static BOOL update_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
static BOOL update_gdi_polygon_sc(rdpContext* context, const POLYGON_SC_ORDER* polygon_sc)
{
rdpCache* cache = context->cache;
rdpCache* cache;
WINPR_ASSERT(context);
cache = context->cache;
WINPR_ASSERT(cache);
WINPR_ASSERT(cache->brush);
return IFCALLRESULT(TRUE, cache->brush->PolygonSC, context, polygon_sc);
}
static BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
{
BYTE style;
rdpBrush* brush = &polygon_cb->brush;
rdpCache* cache = context->cache;
rdpBrush* brush;
rdpCache* cache;
BOOL ret = TRUE;
WINPR_ASSERT(context);
WINPR_ASSERT(polygon_cb);
cache = context->cache;
WINPR_ASSERT(cache);
brush = &polygon_cb->brush;
style = brush->style;
if (brush->style & CACHED_BRUSH)
@ -100,6 +122,7 @@ static BOOL update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon
brush->style = 0x03;
}
WINPR_ASSERT(cache->brush);
IFCALLRET(cache->brush->PolygonCB, ret, context, polygon_cb);
brush->style = style;
return ret;
@ -109,7 +132,14 @@ static BOOL update_gdi_cache_brush(rdpContext* context, const CACHE_BRUSH_ORDER*
{
UINT32 length;
void* data = NULL;
rdpCache* cache = context->cache;
rdpCache* cache;
WINPR_ASSERT(context);
WINPR_ASSERT(cacheBrush);
cache = context->cache;
WINPR_ASSERT(cache);
length = cacheBrush->bpp * 64 / 8;
data = malloc(length);
@ -165,6 +195,8 @@ void* brush_cache_get(rdpBrushCache* brushCache, UINT32 index, UINT32* bpp)
void brush_cache_put(rdpBrushCache* brushCache, UINT32 index, void* entry, UINT32 bpp)
{
WINPR_ASSERT(brushCache);
if (bpp == 1)
{
if (index >= brushCache->maxMonoEntries)
@ -174,6 +206,7 @@ void brush_cache_put(rdpBrushCache* brushCache, UINT32 index, void* entry, UINT3
return;
}
WINPR_ASSERT(brushCache->monoEntries);
free(brushCache->monoEntries[index].entry);
brushCache->monoEntries[index].bpp = bpp;
brushCache->monoEntries[index].entry = entry;
@ -187,6 +220,7 @@ void brush_cache_put(rdpBrushCache* brushCache, UINT32 index, void* entry, UINT3
return;
}
WINPR_ASSERT(brushCache->entries);
free(brushCache->entries[index].entry);
brushCache->entries[index].bpp = bpp;
brushCache->entries[index].entry = entry;
@ -205,44 +239,45 @@ void brush_cache_register_callbacks(rdpUpdate* update)
update->secondary->CacheBrush = update_gdi_cache_brush;
}
rdpBrushCache* brush_cache_new(rdpSettings* settings)
rdpBrushCache* brush_cache_new(rdpContext* context)
{
rdpBrushCache* brushCache;
WINPR_ASSERT(context);
brushCache = (rdpBrushCache*)calloc(1, sizeof(rdpBrushCache));
if (!brushCache)
return NULL;
brushCache->settings = settings;
brushCache->context = context;
brushCache->maxEntries = 64;
brushCache->maxMonoEntries = 64;
brushCache->entries = (BRUSH_ENTRY*)calloc(brushCache->maxEntries, sizeof(BRUSH_ENTRY));
if (!brushCache->entries)
goto error_entries;
goto fail;
brushCache->monoEntries = (BRUSH_ENTRY*)calloc(brushCache->maxMonoEntries, sizeof(BRUSH_ENTRY));
if (!brushCache->monoEntries)
goto error_mono;
goto fail;
return brushCache;
error_mono:
free(brushCache->entries);
error_entries:
free(brushCache);
fail:
brush_cache_free(brushCache);
return NULL;
}
void brush_cache_free(rdpBrushCache* brushCache)
{
int i;
size_t i;
if (brushCache)
{
if (brushCache->entries)
{
for (i = 0; i < (int)brushCache->maxEntries; i++)
for (i = 0; i < brushCache->maxEntries; i++)
free(brushCache->entries[i].entry);
free(brushCache->entries);
@ -250,7 +285,7 @@ void brush_cache_free(rdpBrushCache* brushCache)
if (brushCache->monoEntries)
{
for (i = 0; i < (int)brushCache->maxMonoEntries; i++)
for (i = 0; i < brushCache->maxMonoEntries; i++)
free(brushCache->monoEntries[i].entry);
free(brushCache->monoEntries);
@ -262,12 +297,17 @@ void brush_cache_free(rdpBrushCache* brushCache)
void free_cache_brush_order(rdpContext* context, CACHE_BRUSH_ORDER* order)
{
WINPR_UNUSED(context);
free(order);
}
CACHE_BRUSH_ORDER* copy_cache_brush_order(rdpContext* context, const CACHE_BRUSH_ORDER* order)
{
CACHE_BRUSH_ORDER* dst = calloc(1, sizeof(CACHE_BRUSH_ORDER));
CACHE_BRUSH_ORDER* dst;
WINPR_ASSERT(context);
dst = calloc(1, sizeof(CACHE_BRUSH_ORDER));
if (!dst || !order)
goto fail;

View File

@ -29,45 +29,48 @@
#include "cache.h"
rdpCache* cache_new(rdpSettings* settings)
rdpCache* cache_new(rdpContext* context)
{
rdpCache* cache;
WINPR_ASSERT(context);
cache = (rdpCache*)calloc(1, sizeof(rdpCache));
if (!cache)
return NULL;
cache->glyph = glyph_cache_new(settings);
cache->glyph = glyph_cache_new(context);
if (!cache->glyph)
goto error;
cache->brush = brush_cache_new(settings);
cache->brush = brush_cache_new(context);
if (!cache->brush)
goto error;
cache->pointer = pointer_cache_new(settings);
cache->pointer = pointer_cache_new(context);
if (!cache->pointer)
goto error;
cache->bitmap = bitmap_cache_new(settings);
cache->bitmap = bitmap_cache_new(context);
if (!cache->bitmap)
goto error;
cache->offscreen = offscreen_cache_new(settings);
cache->offscreen = offscreen_cache_new(context);
if (!cache->offscreen)
goto error;
cache->palette = palette_cache_new(settings);
cache->palette = palette_cache_new(context);
if (!cache->palette)
goto error;
cache->nine_grid = nine_grid_cache_new(settings);
cache->nine_grid = nine_grid_cache_new(context);
if (!cache->nine_grid)
goto error;

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <freerdp/freerdp.h>
#include <winpr/stream.h>
@ -545,6 +546,9 @@ static BOOL update_gdi_cache_glyph_v2(rdpContext* context, const CACHE_GLYPH_V2_
rdpGlyph* glyph_cache_get(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index)
{
rdpGlyph* glyph;
WINPR_ASSERT(glyphCache);
WLog_Print(glyphCache->log, WLOG_DEBUG, "GlyphCacheGet: id: %" PRIu32 " index: %" PRIu32 "", id,
index);
@ -554,6 +558,7 @@ rdpGlyph* glyph_cache_get(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index)
return NULL;
}
WINPR_ASSERT(glyphCache->glyphCache);
if (index > glyphCache->glyphCache[id].number)
{
WLog_ERR(TAG, "index %" PRIu32 " out of range for cache id: %" PRIu32 "", index, id);
@ -573,12 +578,15 @@ BOOL glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyp
{
rdpGlyph* prevGlyph;
WINPR_ASSERT(glyphCache);
if (id > 9)
{
WLog_ERR(TAG, "invalid glyph cache id: %" PRIu32 "", id);
return FALSE;
}
WINPR_ASSERT(glyphCache->glyphCache);
if (index >= glyphCache->glyphCache[id].number)
{
WLog_ERR(TAG, "invalid glyph cache index: %" PRIu32 " in cache id: %" PRIu32 "", index, id);
@ -590,7 +598,10 @@ BOOL glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyp
prevGlyph = glyphCache->glyphCache[id].entries[index];
if (prevGlyph)
{
WINPR_ASSERT(prevGlyph->Free);
prevGlyph->Free(glyphCache->context, prevGlyph);
}
glyphCache->glyphCache[id].entries[index] = glyph;
return TRUE;
@ -600,6 +611,9 @@ const void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index, UI
{
void* fragment;
WINPR_ASSERT(glyphCache);
WINPR_ASSERT(glyphCache->fragCache.entries);
if (index > 255)
{
WLog_ERR(TAG, "invalid glyph cache fragment index: %" PRIu32 "", index);
@ -623,6 +637,9 @@ BOOL glyph_cache_fragment_put(rdpGlyphCache* glyphCache, UINT32 index, UINT32 si
void* prevFragment;
void* copy;
WINPR_ASSERT(glyphCache);
WINPR_ASSERT(glyphCache->fragCache.entries);
if (index > 255)
{
WLog_ERR(TAG, "invalid glyph cache fragment index: %" PRIu32 "", index);
@ -653,18 +670,24 @@ void glyph_cache_register_callbacks(rdpUpdate* update)
update->secondary->CacheGlyphV2 = update_gdi_cache_glyph_v2;
}
rdpGlyphCache* glyph_cache_new(rdpSettings* settings)
rdpGlyphCache* glyph_cache_new(rdpContext* context)
{
int i;
size_t i;
rdpGlyphCache* glyphCache;
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
glyphCache = (rdpGlyphCache*)calloc(1, sizeof(rdpGlyphCache));
if (!glyphCache)
return NULL;
glyphCache->log = WLog_Get("com.freerdp.cache.glyph");
glyphCache->settings = settings;
glyphCache->context = ((freerdp*)settings->instance)->update->context;
glyphCache->context = context;
for (i = 0; i < 10; i++)
{
@ -692,7 +715,7 @@ void glyph_cache_free(rdpGlyphCache* glyphCache)
{
if (glyphCache)
{
int i;
size_t i;
GLYPH_CACHE* cache = glyphCache->glyphCache;
for (i = 0; i < 10; i++)
@ -735,7 +758,11 @@ void glyph_cache_free(rdpGlyphCache* glyphCache)
CACHE_GLYPH_ORDER* copy_cache_glyph_order(rdpContext* context, const CACHE_GLYPH_ORDER* glyph)
{
size_t x;
CACHE_GLYPH_ORDER* dst = calloc(1, sizeof(CACHE_GLYPH_ORDER));
CACHE_GLYPH_ORDER* dst;
WINPR_ASSERT(context);
dst = calloc(1, sizeof(CACHE_GLYPH_ORDER));
if (!dst || !glyph)
goto fail;
@ -797,7 +824,11 @@ CACHE_GLYPH_V2_ORDER* copy_cache_glyph_v2_order(rdpContext* context,
const CACHE_GLYPH_V2_ORDER* glyph)
{
size_t x;
CACHE_GLYPH_V2_ORDER* dst = calloc(1, sizeof(CACHE_GLYPH_V2_ORDER));
CACHE_GLYPH_V2_ORDER* dst;
WINPR_ASSERT(context);
dst = calloc(1, sizeof(CACHE_GLYPH_V2_ORDER));
if (!dst || !glyph)
goto fail;

View File

@ -53,7 +53,7 @@ struct rdp_nine_grid_cache
/* internal */
rdpSettings* settings;
rdpContext* context;
};
static void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index);
@ -117,21 +117,27 @@ void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry)
nine_grid->entries[index].entry = entry;
}
rdpNineGridCache* nine_grid_cache_new(rdpSettings* settings)
rdpNineGridCache* nine_grid_cache_new(rdpContext* context)
{
rdpNineGridCache* nine_grid;
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
nine_grid = (rdpNineGridCache*)calloc(1, sizeof(rdpNineGridCache));
if (!nine_grid)
return NULL;
nine_grid->settings = settings;
nine_grid->context = context;
nine_grid->maxSize = 2560;
nine_grid->maxEntries = 256;
nine_grid->settings->DrawNineGridCacheSize = nine_grid->maxSize;
nine_grid->settings->DrawNineGridCacheEntries = nine_grid->maxEntries;
settings->DrawNineGridCacheSize = nine_grid->maxSize;
settings->DrawNineGridCacheEntries = nine_grid->maxEntries;
nine_grid->entries = (NINE_GRID_ENTRY*)calloc(nine_grid->maxEntries, sizeof(NINE_GRID_ENTRY));
if (!nine_grid->entries)

View File

@ -24,7 +24,7 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/stream.h>
#include <freerdp/log.h>
@ -44,8 +44,7 @@ struct rdp_offscreen_cache
/* internal */
rdpUpdate* update;
rdpSettings* settings;
rdpContext* context;
};
static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, UINT32 index,
@ -129,6 +128,8 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index)
{
rdpBitmap* bitmap;
WINPR_ASSERT(offscreenCache);
if (index >= offscreenCache->maxEntries)
{
WLog_ERR(TAG, "invalid offscreen bitmap index: 0x%08" PRIX32 "", index);
@ -148,6 +149,8 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index)
void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap)
{
WINPR_ASSERT(offscreenCache);
if (index >= offscreenCache->maxEntries)
{
WLog_ERR(TAG, "invalid offscreen bitmap index: 0x%08" PRIX32 "", index);
@ -162,6 +165,8 @@ void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index)
{
rdpBitmap* prevBitmap;
WINPR_ASSERT(offscreenCache);
if (index >= offscreenCache->maxEntries)
{
WLog_ERR(TAG, "invalid offscreen bitmap index (delete): 0x%08" PRIX32 "", index);
@ -171,27 +176,36 @@ void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index)
prevBitmap = offscreenCache->entries[index];
if (prevBitmap != NULL)
Bitmap_Free(offscreenCache->update->context, prevBitmap);
Bitmap_Free(offscreenCache->context, prevBitmap);
offscreenCache->entries[index] = NULL;
}
void offscreen_cache_register_callbacks(rdpUpdate* update)
{
WINPR_ASSERT(update);
WINPR_ASSERT(update->altsec);
update->altsec->CreateOffscreenBitmap = update_gdi_create_offscreen_bitmap;
update->altsec->SwitchSurface = update_gdi_switch_surface;
}
rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings)
rdpOffscreenCache* offscreen_cache_new(rdpContext* context)
{
rdpOffscreenCache* offscreenCache;
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
offscreenCache = (rdpOffscreenCache*)calloc(1, sizeof(rdpOffscreenCache));
if (!offscreenCache)
return NULL;
offscreenCache->settings = settings;
offscreenCache->update = ((freerdp*)settings->instance)->update;
offscreenCache->context = context;
offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE;
offscreenCache->maxSize = 7680;
offscreenCache->maxEntries = 2000;
@ -210,15 +224,15 @@ rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings)
void offscreen_cache_free(rdpOffscreenCache* offscreenCache)
{
int i;
size_t i;
rdpBitmap* bitmap;
if (offscreenCache)
{
for (i = 0; i < (int)offscreenCache->maxEntries; i++)
for (i = 0; i < offscreenCache->maxEntries; i++)
{
bitmap = offscreenCache->entries[i];
Bitmap_Free(offscreenCache->update->context, bitmap);
Bitmap_Free(offscreenCache->context, bitmap);
}
free(offscreenCache->entries);

View File

@ -90,14 +90,17 @@ void palette_cache_register_callbacks(rdpUpdate* update)
update->secondary->CacheColorTable = update_gdi_cache_color_table;
}
rdpPaletteCache* palette_cache_new(rdpSettings* settings)
rdpPaletteCache* palette_cache_new(rdpContext* context)
{
rdpPaletteCache* paletteCache;
WINPR_ASSERT(context);
paletteCache = (rdpPaletteCache*)calloc(1, sizeof(rdpPaletteCache));
if (paletteCache)
{
paletteCache->settings = settings;
paletteCache->context = context;
paletteCache->maxEntries = 6;
paletteCache->entries =
(PALETTE_TABLE_ENTRY*)calloc(paletteCache->maxEntries, sizeof(PALETTE_TABLE_ENTRY));

View File

@ -24,7 +24,7 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/stream.h>
#include <freerdp/log.h>
@ -106,6 +106,7 @@ static BOOL upate_pointer_copy_andxor(rdpPointer* pointer, const BYTE* andMaskDa
pointer->lengthAndMask = 0;
pointer->lengthXorMask = 0;
WINPR_ASSERT(pointer);
if (lengthAndMask && andMaskData)
{
pointer->lengthAndMask = lengthAndMask;
@ -134,7 +135,14 @@ static BOOL upate_pointer_copy_andxor(rdpPointer* pointer, const BYTE* andMaskDa
static BOOL update_pointer_color(rdpContext* context, const POINTER_COLOR_UPDATE* pointer_color)
{
rdpPointer* pointer;
rdpCache* cache = context->cache;
rdpCache* cache;
WINPR_ASSERT(context);
WINPR_ASSERT(pointer_color);
cache = context->cache;
WINPR_ASSERT(cache);
pointer = Pointer_Alloc(context);
if (pointer != NULL)
@ -167,9 +175,16 @@ out_fail:
static BOOL update_pointer_large(rdpContext* context, const POINTER_LARGE_UPDATE* pointer_large)
{
rdpPointer* pointer = Pointer_Alloc(context);
rdpCache* cache = context->cache;
rdpPointer* pointer;
rdpCache* cache;
WINPR_ASSERT(context);
WINPR_ASSERT(pointer_large);
cache = context->cache;
WINPR_ASSERT(cache);
pointer = Pointer_Alloc(context);
if (pointer != NULL)
{
pointer->xorBpp = pointer_large->xorBpp;
@ -237,7 +252,14 @@ out_fail:
static BOOL update_pointer_cached(rdpContext* context, const POINTER_CACHED_UPDATE* pointer_cached)
{
const rdpPointer* pointer;
rdpCache* cache = context->cache;
rdpCache* cache;
WINPR_ASSERT(context);
WINPR_ASSERT(pointer_cached);
cache = context->cache;
WINPR_ASSERT(cache);
pointer = pointer_cache_get(cache->pointer, pointer_cached->cacheIndex);
if (pointer != NULL)
@ -250,12 +272,15 @@ const rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index
{
const rdpPointer* pointer;
WINPR_ASSERT(pointer_cache);
if (index >= pointer_cache->cacheSize)
{
WLog_ERR(TAG, "invalid pointer index:%" PRIu32 "", index);
return NULL;
}
WINPR_ASSERT(pointer_cache->entries);
pointer = pointer_cache->entries[index];
return pointer;
}
@ -264,14 +289,17 @@ BOOL pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, rdpPointer*
{
rdpPointer* prevPointer;
WINPR_ASSERT(pointer_cache);
if (index >= pointer_cache->cacheSize)
{
WLog_ERR(TAG, "invalid pointer index:%" PRIu32 "", index);
return FALSE;
}
WINPR_ASSERT(pointer_cache->entries);
prevPointer = pointer_cache->entries[index];
pointer_free(pointer_cache->update->context, prevPointer);
pointer_free(pointer_cache->context, prevPointer);
pointer_cache->entries[index] = pointer;
return TRUE;
}
@ -287,17 +315,23 @@ void pointer_cache_register_callbacks(rdpUpdate* update)
pointer->PointerCached = update_pointer_cached;
}
rdpPointerCache* pointer_cache_new(rdpSettings* settings)
rdpPointerCache* pointer_cache_new(rdpContext* context)
{
rdpPointerCache* pointer_cache;
rdpSettings* settings;
WINPR_ASSERT(context);
settings = context->settings;
WINPR_ASSERT(settings);
pointer_cache = (rdpPointerCache*)calloc(1, sizeof(rdpPointerCache));
if (!pointer_cache)
return NULL;
pointer_cache->settings = settings;
pointer_cache->context = context;
pointer_cache->cacheSize = settings->PointerCacheSize;
pointer_cache->update = ((freerdp*)settings->instance)->update;
pointer_cache->entries = (rdpPointer**)calloc(pointer_cache->cacheSize, sizeof(rdpPointer*));
if (!pointer_cache->entries)
@ -319,7 +353,7 @@ void pointer_cache_free(rdpPointerCache* pointer_cache)
for (i = 0; i < pointer_cache->cacheSize; i++)
{
pointer = pointer_cache->entries[i];
pointer_free(pointer_cache->update->context, pointer);
pointer_free(pointer_cache->context, pointer);
}
free(pointer_cache->entries);
@ -365,6 +399,8 @@ fail:
void free_pointer_color_update(rdpContext* context, POINTER_COLOR_UPDATE* pointer)
{
WINPR_UNUSED(context);
if (!pointer)
return;
@ -484,11 +520,13 @@ fail:
void free_pointer_cached_update(rdpContext* context, POINTER_CACHED_UPDATE* pointer)
{
WINPR_UNUSED(context);
free(pointer);
}
void free_pointer_position_update(rdpContext* context, POINTER_POSITION_UPDATE* pointer)
{
WINPR_UNUSED(context);
free(pointer);
}
@ -509,6 +547,7 @@ fail:
void free_pointer_system_update(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer)
{
WINPR_UNUSED(context);
free(pointer);
}

View File

@ -1282,7 +1282,7 @@ BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
if (!gdi_init_primary(gdi, stride, gdi->dstFormat, buffer, pfree))
goto fail;
if (!(context->cache = cache_new(instance->settings)))
if (!(context->cache = cache_new(instance->context)))
goto fail;
gdi_register_update_callbacks(instance->update);