20 #include <freerdp/config.h>
24 #include <winpr/crt.h>
25 #include <winpr/assert.h>
26 #include <winpr/stream.h>
28 #include <freerdp/log.h>
30 #include "../core/graphics.h"
32 #include "offscreen.h"
35 #define TAG FREERDP_TAG("cache.offscreen")
37 struct rdp_offscreen_cache
42 UINT32 currentSurface;
47 static void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap);
48 static void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index);
51 update_gdi_create_offscreen_bitmap(rdpContext* context,
55 rdpBitmap* bitmap = NULL;
56 rdpCache* cache = NULL;
58 if (!context || !createOffscreenBitmap || !context->cache)
61 cache = context->cache;
62 bitmap = Bitmap_Alloc(context);
67 Bitmap_SetDimensions(bitmap, createOffscreenBitmap->cx, createOffscreenBitmap->cy);
69 if (!bitmap->New(context, bitmap))
71 Bitmap_Free(context, bitmap);
75 offscreen_cache_delete(cache->offscreen, createOffscreenBitmap->id);
76 offscreen_cache_put(cache->offscreen, createOffscreenBitmap->id, bitmap);
78 if (cache->offscreen->currentSurface == createOffscreenBitmap->id)
79 bitmap->SetSurface(context, bitmap, FALSE);
81 for (UINT32 i = 0; i < createOffscreenBitmap->deleteList.cIndices; i++)
83 index = createOffscreenBitmap->deleteList.indices[i];
84 offscreen_cache_delete(cache->offscreen, index);
90 static BOOL update_gdi_switch_surface(rdpContext* context,
93 rdpCache* cache = NULL;
94 rdpBitmap* bitmap = NULL;
96 if (!context || !context->cache || !switchSurface || !context->graphics)
99 cache = context->cache;
100 bitmap = context->graphics->Bitmap_Prototype;
104 if (switchSurface->bitmapId == SCREEN_BITMAP_SURFACE)
106 bitmap->SetSurface(context, NULL, TRUE);
110 rdpBitmap* bmp = NULL;
111 bmp = offscreen_cache_get(cache->offscreen, switchSurface->bitmapId);
115 bitmap->SetSurface(context, bmp, FALSE);
118 cache->offscreen->currentSurface = switchSurface->bitmapId;
122 rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index)
124 rdpBitmap* bitmap = NULL;
126 WINPR_ASSERT(offscreenCache);
128 if (index >= offscreenCache->maxEntries)
130 WLog_ERR(TAG,
"invalid offscreen bitmap index: 0x%08" PRIX32
"", index);
134 bitmap = offscreenCache->entries[index];
138 WLog_ERR(TAG,
"invalid offscreen bitmap at index: 0x%08" PRIX32
"", index);
145 void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap)
147 WINPR_ASSERT(offscreenCache);
149 if (index >= offscreenCache->maxEntries)
151 WLog_ERR(TAG,
"invalid offscreen bitmap index: 0x%08" PRIX32
"", index);
155 offscreen_cache_delete(offscreenCache, index);
156 offscreenCache->entries[index] = bitmap;
159 void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index)
161 rdpBitmap* prevBitmap = NULL;
163 WINPR_ASSERT(offscreenCache);
165 if (index >= offscreenCache->maxEntries)
167 WLog_ERR(TAG,
"invalid offscreen bitmap index (delete): 0x%08" PRIX32
"", index);
171 prevBitmap = offscreenCache->entries[index];
173 if (prevBitmap != NULL)
174 Bitmap_Free(offscreenCache->context, prevBitmap);
176 offscreenCache->entries[index] = NULL;
179 void offscreen_cache_register_callbacks(rdpUpdate* update)
181 WINPR_ASSERT(update);
182 WINPR_ASSERT(update->altsec);
184 update->altsec->CreateOffscreenBitmap = update_gdi_create_offscreen_bitmap;
185 update->altsec->SwitchSurface = update_gdi_switch_surface;
188 rdpOffscreenCache* offscreen_cache_new(rdpContext* context)
190 rdpOffscreenCache* offscreenCache = NULL;
191 rdpSettings* settings = NULL;
193 WINPR_ASSERT(context);
195 settings = context->settings;
196 WINPR_ASSERT(settings);
198 offscreenCache = (rdpOffscreenCache*)calloc(1,
sizeof(rdpOffscreenCache));
203 offscreenCache->context = context;
204 offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE;
205 offscreenCache->maxSize = 7680;
206 offscreenCache->maxEntries = 2000;
210 offscreenCache->maxEntries))
212 offscreenCache->entries = (rdpBitmap**)calloc(offscreenCache->maxEntries,
sizeof(rdpBitmap*));
214 if (!offscreenCache->entries)
217 return offscreenCache;
219 WINPR_PRAGMA_DIAG_PUSH
220 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
221 offscreen_cache_free(offscreenCache);
222 WINPR_PRAGMA_DIAG_POP
226 void offscreen_cache_free(rdpOffscreenCache* offscreenCache)
230 if (offscreenCache->entries)
232 for (
size_t i = 0; i < offscreenCache->maxEntries; i++)
234 rdpBitmap* bitmap = offscreenCache->entries[i];
235 Bitmap_Free(offscreenCache->context, bitmap);
239 free(offscreenCache->entries);
240 free(offscreenCache);
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.