20#include <freerdp/config.h>
24#include <winpr/assert.h>
26#include <freerdp/log.h>
27#include <freerdp/update.h>
28#include <freerdp/freerdp.h>
29#include <winpr/stream.h>
34#define TAG FREERDP_TAG("cache.brush")
45 pCacheBrush CacheBrush;
48 UINT32 paddingA[16 - 4];
51 UINT32 maxMonoEntries;
53 BRUSH_ENTRY* monoEntries;
54 UINT32 paddingB[32 - 20];
59static BOOL update_gdi_patblt(rdpContext* context,
PATBLT_ORDER* patblt)
63 WINPR_ASSERT(context);
66 const rdpCache* cache = context->cache;
69 rdpBrush* brush = &patblt->brush;
70 WINPR_ASSERT(brush->style <= UINT8_MAX);
71 const rdpBrush save = *brush;
73 if (brush->style & CACHED_BRUSH)
75 brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
81 WINPR_ASSERT(cache->brush);
82 IFCALLRET(cache->brush->PatBlt, ret, context, patblt);
87static BOOL update_gdi_polygon_sc(rdpContext* context,
const POLYGON_SC_ORDER* polygon_sc)
89 rdpCache* cache =
nullptr;
90 WINPR_ASSERT(context);
91 cache = context->cache;
93 WINPR_ASSERT(cache->brush);
94 return IFCALLRESULT(TRUE, cache->brush->PolygonSC, context, polygon_sc);
97static BOOL update_gdi_polygon_cb(rdpContext* context,
POLYGON_CB_ORDER* polygon_cb)
101 WINPR_ASSERT(context);
102 WINPR_ASSERT(polygon_cb);
104 rdpCache* cache = context->cache;
107 rdpBrush* brush = &polygon_cb->brush;
108 WINPR_ASSERT(brush->style <= UINT8_MAX);
109 const rdpBrush save = *brush;
111 if (brush->style & CACHED_BRUSH)
113 brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
119 WINPR_ASSERT(cache->brush);
120 IFCALLRET(cache->brush->PolygonCB, ret, context, polygon_cb);
126static BOOL update_gdi_cache_brush(rdpContext* context,
const CACHE_BRUSH_ORDER* cacheBrush)
129 void* data =
nullptr;
130 rdpCache* cache =
nullptr;
132 WINPR_ASSERT(context);
133 WINPR_ASSERT(cacheBrush);
135 cache = context->cache;
138 length = cacheBrush->bpp * 64 / 8;
139 data = malloc(length);
144 CopyMemory(data, cacheBrush->data, length);
145 brush_cache_put(cache->brush, cacheBrush->index, data, cacheBrush->bpp);
149void* brush_cache_get(rdpBrushCache* brushCache, UINT32 index, UINT32* bpp)
151 void* entry =
nullptr;
161 if (index >= brushCache->maxMonoEntries)
163 WLog_ERR(TAG,
"invalid brush (%" PRIu32
" bpp) index: 0x%08" PRIX32
"", *bpp, index);
167 *bpp = brushCache->monoEntries[index].bpp;
168 entry = brushCache->monoEntries[index].entry;
172 if (index >= brushCache->maxEntries)
174 WLog_ERR(TAG,
"invalid brush (%" PRIu32
" bpp) index: 0x%08" PRIX32
"", *bpp, index);
178 *bpp = brushCache->entries[index].bpp;
179 entry = brushCache->entries[index].entry;
182 if (entry ==
nullptr)
184 WLog_ERR(TAG,
"invalid brush (%" PRIu32
" bpp) at index: 0x%08" PRIX32
"", *bpp, index);
191void brush_cache_put(rdpBrushCache* brushCache, UINT32 index,
void* entry, UINT32 bpp)
193 WINPR_ASSERT(brushCache);
197 if (index >= brushCache->maxMonoEntries)
199 WLog_ERR(TAG,
"invalid brush (%" PRIu32
" bpp) index: 0x%08" PRIX32
"", bpp, index);
204 WINPR_ASSERT(brushCache->monoEntries);
205 free(brushCache->monoEntries[index].entry);
206 brushCache->monoEntries[index].bpp = bpp;
207 brushCache->monoEntries[index].entry = entry;
211 if (index >= brushCache->maxEntries)
213 WLog_ERR(TAG,
"invalid brush (%" PRIu32
" bpp) index: 0x%08" PRIX32
"", bpp, index);
218 WINPR_ASSERT(brushCache->entries);
219 free(brushCache->entries[index].entry);
220 brushCache->entries[index].bpp = bpp;
221 brushCache->entries[index].entry = entry;
225void brush_cache_register_callbacks(rdpUpdate* update)
227 WINPR_ASSERT(update);
228 WINPR_ASSERT(update->context);
229 WINPR_ASSERT(update->primary);
230 WINPR_ASSERT(update->secondary);
234 rdpCache* cache = update->context->cache;
236 WINPR_ASSERT(cache->brush);
238 cache->brush->PatBlt = update->primary->PatBlt;
239 cache->brush->PolygonSC = update->primary->PolygonSC;
240 cache->brush->PolygonCB = update->primary->PolygonCB;
241 update->primary->PatBlt = update_gdi_patblt;
242 update->primary->PolygonSC = update_gdi_polygon_sc;
243 update->primary->PolygonCB = update_gdi_polygon_cb;
244 update->secondary->CacheBrush = update_gdi_cache_brush;
248rdpBrushCache* brush_cache_new(rdpContext* context)
250 rdpBrushCache* brushCache =
nullptr;
252 WINPR_ASSERT(context);
254 brushCache = (rdpBrushCache*)calloc(1,
sizeof(rdpBrushCache));
259 brushCache->context = context;
260 brushCache->maxEntries = 64;
261 brushCache->maxMonoEntries = 64;
262 brushCache->entries = (BRUSH_ENTRY*)calloc(brushCache->maxEntries,
sizeof(BRUSH_ENTRY));
264 if (!brushCache->entries)
267 brushCache->monoEntries = (BRUSH_ENTRY*)calloc(brushCache->maxMonoEntries,
sizeof(BRUSH_ENTRY));
269 if (!brushCache->monoEntries)
274 WINPR_PRAGMA_DIAG_PUSH
275 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
276 brush_cache_free(brushCache);
277 WINPR_PRAGMA_DIAG_POP
281void brush_cache_free(rdpBrushCache* brushCache)
285 if (brushCache->entries)
287 for (
size_t i = 0; i < brushCache->maxEntries; i++)
288 free(brushCache->entries[i].entry);
290 free(brushCache->entries);
293 if (brushCache->monoEntries)
295 for (
size_t i = 0; i < brushCache->maxMonoEntries; i++)
296 free(brushCache->monoEntries[i].entry);
298 free(brushCache->monoEntries);
307 WINPR_UNUSED(context);
315 WINPR_ASSERT(context);
325 free_cache_brush_order(context, dst);
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.