2011-08-06 00:56:40 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-06 00:56:40 +04:00
|
|
|
* Bitmap Cache V2
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-09-24 02:41:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2021-09-06 15:00:12 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2012-07-24 23:05:22 +04:00
|
|
|
#include <freerdp/constants.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2014-09-15 11:01:05 +04:00
|
|
|
#include <freerdp/log.h>
|
2016-04-14 00:10:08 +03:00
|
|
|
#include <freerdp/gdi/bitmap.h>
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2016-07-21 11:07:42 +03:00
|
|
|
#include "../gdi/gdi.h"
|
2016-10-10 11:38:54 +03:00
|
|
|
#include "../core/graphics.h"
|
2016-07-21 11:07:42 +03:00
|
|
|
|
2018-03-30 11:43:20 +03:00
|
|
|
#include "bitmap.h"
|
2023-02-07 17:42:52 +03:00
|
|
|
#include "cache.h"
|
2018-03-30 11:43:20 +03:00
|
|
|
|
2014-09-15 11:01:05 +04:00
|
|
|
#define TAG FREERDP_TAG("cache.bitmap")
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index);
|
2024-09-03 12:04:32 +03:00
|
|
|
static BOOL bitmap_cache_put(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index,
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpBitmap* bitmap);
|
2016-10-10 11:38:54 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
|
2011-10-13 23:51:07 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpBitmap* bitmap = NULL;
|
|
|
|
rdpCache* cache = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
cache = context->cache;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2011-10-14 03:32:18 +04:00
|
|
|
if (memblt->cacheId == 0xFF)
|
2011-10-13 23:51:07 +04:00
|
|
|
bitmap = offscreen_cache_get(cache->offscreen, memblt->cacheIndex);
|
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmap = bitmap_cache_get(cache->bitmap, (BYTE)memblt->cacheId, memblt->cacheIndex);
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
/* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */
|
2015-04-14 11:14:23 +03:00
|
|
|
if (bitmap == NULL)
|
|
|
|
return TRUE;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
|
|
|
memblt->bitmap = bitmap;
|
2015-04-17 17:21:55 +03:00
|
|
|
return IFCALLRESULT(TRUE, cache->bitmap->MemBlt, context, memblt);
|
2011-10-13 23:51:07 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
|
2011-10-13 23:51:07 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE style = 0;
|
|
|
|
rdpBitmap* bitmap = NULL;
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2012-02-13 03:12:28 +04:00
|
|
|
rdpBrush* brush = &mem3blt->brush;
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL ret = TRUE;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2011-10-14 03:32:18 +04:00
|
|
|
if (mem3blt->cacheId == 0xFF)
|
2011-10-13 23:51:07 +04:00
|
|
|
bitmap = offscreen_cache_get(cache->offscreen, mem3blt->cacheIndex);
|
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmap = bitmap_cache_get(cache->bitmap, (BYTE)mem3blt->cacheId, mem3blt->cacheIndex);
|
2013-11-03 22:51:41 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
/* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */
|
2013-11-03 22:51:41 +04:00
|
|
|
if (!bitmap)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2012-02-13 03:12:28 +04:00
|
|
|
style = brush->style;
|
|
|
|
|
|
|
|
if (brush->style & CACHED_BRUSH)
|
|
|
|
{
|
|
|
|
brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!brush->data)
|
|
|
|
return FALSE;
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2012-02-13 03:12:28 +04:00
|
|
|
brush->style = 0x03;
|
|
|
|
}
|
|
|
|
|
2011-10-13 23:51:07 +04:00
|
|
|
mem3blt->bitmap = bitmap;
|
2015-04-14 11:14:23 +03:00
|
|
|
IFCALLRET(cache->bitmap->Mem3Blt, ret, context, mem3blt);
|
2012-02-13 03:12:28 +04:00
|
|
|
brush->style = style;
|
2015-04-14 11:14:23 +03:00
|
|
|
return ret;
|
2011-10-13 23:51:07 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_cache_bitmap(rdpContext* context, const CACHE_BITMAP_ORDER* cacheBitmap)
|
2011-11-11 10:48:31 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpBitmap* bitmap = NULL;
|
|
|
|
rdpBitmap* prevBitmap = NULL;
|
2012-01-05 05:17:11 +04:00
|
|
|
rdpCache* cache = context->cache;
|
|
|
|
bitmap = Bitmap_Alloc(context);
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!bitmap)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Bitmap_SetDimensions(bitmap, cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight);
|
2016-07-20 16:34:06 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!bitmap->Decompress(context, bitmap, cacheBitmap->bitmapDataStream,
|
|
|
|
cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight,
|
2018-03-30 11:43:20 +03:00
|
|
|
cacheBitmap->bitmapBpp, cacheBitmap->bitmapLength,
|
|
|
|
cacheBitmap->compressed, RDP_CODEC_ID_NONE))
|
2015-04-14 11:14:23 +03:00
|
|
|
{
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bitmap);
|
2015-04-14 11:14:23 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-05 05:17:11 +04:00
|
|
|
|
2016-04-14 00:10:08 +03:00
|
|
|
if (!bitmap->New(context, bitmap))
|
2016-07-19 14:02:08 +03:00
|
|
|
{
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, bitmap);
|
2016-04-14 00:10:08 +03:00
|
|
|
return FALSE;
|
2016-07-19 14:02:08 +03:00
|
|
|
}
|
2012-01-05 05:17:11 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex);
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, prevBitmap);
|
2019-11-06 17:24:51 +03:00
|
|
|
return bitmap_cache_put(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex, bitmap);
|
2011-11-11 10:48:31 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cacheBitmapV2)
|
2015-04-14 11:14:23 +03:00
|
|
|
|
2011-10-13 23:51:07 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpBitmap* prevBitmap = NULL;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2014-09-12 09:11:40 +04:00
|
|
|
rdpSettings* settings = context->settings;
|
2022-05-02 11:55:44 +03:00
|
|
|
rdpBitmap* bitmap = Bitmap_Alloc(context);
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!bitmap)
|
|
|
|
return FALSE;
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
|
2022-05-30 23:32:23 +03:00
|
|
|
bitmap->key64 = ((UINT64)cacheBitmapV2->key1 | (((UINT64)cacheBitmapV2->key2) << 32));
|
|
|
|
|
2014-09-12 04:12:32 +04:00
|
|
|
if (!cacheBitmapV2->bitmapBpp)
|
2022-05-02 11:55:44 +03:00
|
|
|
cacheBitmapV2->bitmapBpp = ColorDepth;
|
2014-09-12 09:11:40 +04:00
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
if ((ColorDepth == 15) && (cacheBitmapV2->bitmapBpp == 16))
|
|
|
|
cacheBitmapV2->bitmapBpp = ColorDepth;
|
2012-01-03 11:09:14 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Bitmap_SetDimensions(bitmap, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight);
|
|
|
|
|
|
|
|
if (!bitmap->Decompress(context, bitmap, cacheBitmapV2->bitmapDataStream,
|
|
|
|
cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight,
|
|
|
|
cacheBitmapV2->bitmapBpp, cacheBitmapV2->bitmapLength,
|
|
|
|
cacheBitmapV2->compressed, RDP_CODEC_ID_NONE))
|
2022-05-02 11:55:44 +03:00
|
|
|
goto fail;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex);
|
2011-10-13 23:51:07 +04:00
|
|
|
|
2016-04-19 22:30:28 +03:00
|
|
|
if (!bitmap->New(context, bitmap))
|
2022-05-02 11:55:44 +03:00
|
|
|
goto fail;
|
2016-04-14 00:10:08 +03:00
|
|
|
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, prevBitmap);
|
2019-11-06 17:24:51 +03:00
|
|
|
return bitmap_cache_put(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex,
|
|
|
|
bitmap);
|
2022-05-02 11:55:44 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
Bitmap_Free(context, bitmap);
|
|
|
|
return FALSE;
|
2011-10-13 23:51:07 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cacheBitmapV3)
|
2012-07-24 23:05:22 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpBitmap* bitmap = NULL;
|
|
|
|
rdpBitmap* prevBitmap = NULL;
|
2014-09-12 09:11:40 +04:00
|
|
|
BOOL compressed = TRUE;
|
2012-07-24 23:05:22 +04:00
|
|
|
rdpCache* cache = context->cache;
|
2014-09-12 09:11:40 +04:00
|
|
|
rdpSettings* settings = context->settings;
|
2013-11-03 22:51:41 +04:00
|
|
|
BITMAP_DATA_EX* bitmapData = &cacheBitmapV3->bitmapData;
|
2012-07-24 23:05:22 +04:00
|
|
|
bitmap = Bitmap_Alloc(context);
|
2016-07-18 15:42:55 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!bitmap)
|
|
|
|
return FALSE;
|
2012-07-24 23:05:22 +04:00
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
|
2022-05-30 23:32:23 +03:00
|
|
|
bitmap->key64 = ((UINT64)cacheBitmapV3->key1 | (((UINT64)cacheBitmapV3->key2) << 32));
|
|
|
|
|
2014-09-12 04:12:32 +04:00
|
|
|
if (!cacheBitmapV3->bpp)
|
2022-05-02 11:55:44 +03:00
|
|
|
cacheBitmapV3->bpp = ColorDepth;
|
2012-07-24 23:05:22 +04:00
|
|
|
|
2014-09-12 09:11:40 +04:00
|
|
|
compressed = (bitmapData->codecID != RDP_CODEC_ID_NONE);
|
2016-07-20 16:34:06 +03:00
|
|
|
Bitmap_SetDimensions(bitmap, bitmapData->width, bitmapData->height);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!bitmap->Decompress(context, bitmap, bitmapData->data, bitmapData->width,
|
|
|
|
bitmapData->height, bitmapData->bpp, bitmapData->length, compressed,
|
2018-03-30 11:43:20 +03:00
|
|
|
bitmapData->codecID))
|
2022-05-02 11:55:44 +03:00
|
|
|
goto fail;
|
2012-07-24 23:05:22 +04:00
|
|
|
|
2016-04-19 22:30:28 +03:00
|
|
|
if (!bitmap->New(context, bitmap))
|
2022-05-02 11:55:44 +03:00
|
|
|
goto fail;
|
2012-07-24 23:05:22 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex);
|
2016-10-10 11:38:54 +03:00
|
|
|
Bitmap_Free(context, prevBitmap);
|
2019-11-06 17:24:51 +03:00
|
|
|
return bitmap_cache_put(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex,
|
|
|
|
bitmap);
|
2022-05-02 11:55:44 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
Bitmap_Free(context, bitmap);
|
|
|
|
return FALSE;
|
2012-07-24 23:05:22 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index)
|
2011-10-13 23:51:07 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpBitmap* bitmap = NULL;
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2020-03-30 18:13:51 +03:00
|
|
|
if (id >= bitmapCache->maxCells)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "get invalid bitmap cell id: %" PRIu32 "", id);
|
2011-08-06 00:56:40 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-04 03:22:42 +04:00
|
|
|
if (index == BITMAP_CACHE_WAITING_LIST_INDEX)
|
2012-03-27 23:44:03 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
index = bitmapCache->cells[id].number;
|
2012-03-27 23:44:03 +04:00
|
|
|
}
|
2013-11-03 22:51:41 +04:00
|
|
|
else if (index > bitmapCache->cells[id].number)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "get invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id);
|
2011-08-06 00:56:40 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
bitmap = bitmapCache->cells[id].entries[index];
|
2011-10-13 23:51:07 +04:00
|
|
|
return bitmap;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL bitmap_cache_put(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index, rdpBitmap* bitmap)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
if (id > bitmapCache->maxCells)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "put invalid bitmap cell id: %" PRIu32 "", id);
|
2016-10-10 11:38:54 +03:00
|
|
|
return FALSE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2012-01-04 03:22:42 +04:00
|
|
|
if (index == BITMAP_CACHE_WAITING_LIST_INDEX)
|
2012-03-27 23:44:03 +04:00
|
|
|
{
|
2013-11-03 22:51:41 +04:00
|
|
|
index = bitmapCache->cells[id].number;
|
2012-03-27 23:44:03 +04:00
|
|
|
}
|
2013-11-03 22:51:41 +04:00
|
|
|
else if (index > bitmapCache->cells[id].number)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "put invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id);
|
2016-10-10 11:38:54 +03:00
|
|
|
return FALSE;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
bitmapCache->cells[id].entries[index] = bitmap;
|
2016-10-10 11:38:54 +03:00
|
|
|
return TRUE;
|
2011-10-13 23:51:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bitmap_cache_register_callbacks(rdpUpdate* update)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpCache* cache = NULL;
|
2021-09-10 10:06:35 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
WINPR_ASSERT(update->context);
|
|
|
|
WINPR_ASSERT(update->context->cache);
|
|
|
|
|
|
|
|
cache = update->context->cache;
|
|
|
|
WINPR_ASSERT(cache);
|
|
|
|
|
2021-09-17 09:59:10 +03:00
|
|
|
if (!freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding))
|
|
|
|
{
|
|
|
|
cache->bitmap->MemBlt = update->primary->MemBlt;
|
|
|
|
cache->bitmap->Mem3Blt = update->primary->Mem3Blt;
|
|
|
|
update->primary->MemBlt = update_gdi_memblt;
|
|
|
|
update->primary->Mem3Blt = update_gdi_mem3blt;
|
|
|
|
update->secondary->CacheBitmap = update_gdi_cache_bitmap;
|
|
|
|
update->secondary->CacheBitmapV2 = update_gdi_cache_bitmap_v2;
|
|
|
|
update->secondary->CacheBitmapV3 = update_gdi_cache_bitmap_v3;
|
|
|
|
update->BitmapUpdate = gdi_bitmap_update;
|
|
|
|
}
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2022-06-20 16:54:46 +03:00
|
|
|
static int bitmap_cache_save_persistent(rdpBitmapCache* bitmapCache)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
|
|
|
rdpContext* context = bitmapCache->context;
|
|
|
|
rdpSettings* settings = context->settings;
|
|
|
|
|
2023-10-13 09:47:16 +03:00
|
|
|
const UINT32 version = freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheVersion);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
if (version != 2)
|
|
|
|
return 0; /* persistent bitmap cache already saved in egfx channel */
|
|
|
|
|
2023-01-09 17:56:20 +03:00
|
|
|
if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled))
|
2022-05-30 23:32:23 +03:00
|
|
|
return 0;
|
|
|
|
|
2023-10-13 09:47:16 +03:00
|
|
|
const char* BitmapCachePersistFile =
|
|
|
|
freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile);
|
|
|
|
if (!BitmapCachePersistFile)
|
2022-05-30 23:32:23 +03:00
|
|
|
return 0;
|
|
|
|
|
2023-10-13 09:47:16 +03:00
|
|
|
rdpPersistentCache* persistent = persistent_cache_new();
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
if (!persistent)
|
|
|
|
return -1;
|
|
|
|
|
2023-10-13 09:47:16 +03:00
|
|
|
int status = persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, version);
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
if (status < 1)
|
|
|
|
goto end;
|
|
|
|
|
2024-01-23 23:03:28 +03:00
|
|
|
if (bitmapCache->cells)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
2024-01-23 23:03:28 +03:00
|
|
|
for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
|
2022-05-30 23:32:23 +03:00
|
|
|
{
|
2024-01-23 23:03:28 +03:00
|
|
|
BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
|
|
|
|
for (UINT32 j = 0; j < cell->number + 1 && cell->entries; j++)
|
2022-06-23 08:57:38 +03:00
|
|
|
{
|
2024-01-23 23:03:28 +03:00
|
|
|
PERSISTENT_CACHE_ENTRY cacheEntry;
|
|
|
|
rdpBitmap* bitmap = cell->entries[j];
|
|
|
|
|
|
|
|
if (!bitmap || !bitmap->key64)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cacheEntry.key64 = bitmap->key64;
|
|
|
|
cacheEntry.width = bitmap->width;
|
|
|
|
cacheEntry.height = bitmap->height;
|
2024-09-03 11:38:12 +03:00
|
|
|
const UINT64 size = 4ULL * bitmap->width * bitmap->height;
|
|
|
|
if (size > UINT32_MAX)
|
|
|
|
continue;
|
|
|
|
cacheEntry.size = (UINT32)size;
|
2024-01-23 23:03:28 +03:00
|
|
|
cacheEntry.flags = 0;
|
|
|
|
cacheEntry.data = bitmap->data;
|
|
|
|
|
|
|
|
if (persistent_cache_write_entry(persistent, &cacheEntry) < 1)
|
|
|
|
{
|
|
|
|
status = -1;
|
|
|
|
goto end;
|
|
|
|
}
|
2022-05-30 23:32:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
|
|
|
|
end:
|
|
|
|
persistent_cache_free(persistent);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-09-06 15:00:12 +03:00
|
|
|
rdpBitmapCache* bitmap_cache_new(rdpContext* context)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpBitmapCache* bitmapCache = NULL;
|
2021-09-06 15:00:12 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
settings = context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmapCache = (rdpBitmapCache*)calloc(1, sizeof(rdpBitmapCache));
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2016-10-04 09:54:42 +03:00
|
|
|
if (!bitmapCache)
|
|
|
|
return NULL;
|
|
|
|
|
2022-05-02 11:55:44 +03:00
|
|
|
const UINT32 BitmapCacheV2NumCells =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheV2NumCells);
|
2021-09-06 15:00:12 +03:00
|
|
|
bitmapCache->context = context;
|
2022-05-02 11:55:44 +03:00
|
|
|
bitmapCache->cells = (BITMAP_V2_CELL*)calloc(BitmapCacheV2NumCells, sizeof(BITMAP_V2_CELL));
|
2016-10-04 09:54:42 +03:00
|
|
|
|
|
|
|
if (!bitmapCache->cells)
|
|
|
|
goto fail;
|
2022-05-02 11:55:44 +03:00
|
|
|
bitmapCache->maxCells = BitmapCacheV2NumCells;
|
2016-10-04 09:54:42 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2022-05-02 11:55:44 +03:00
|
|
|
const BITMAP_CACHE_V2_CELL_INFO* info =
|
|
|
|
freerdp_settings_get_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, i);
|
2020-04-02 11:50:16 +03:00
|
|
|
BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
|
2022-05-02 11:55:44 +03:00
|
|
|
UINT32 nr = info->numEntries;
|
2016-10-04 09:54:42 +03:00
|
|
|
/* allocate an extra entry for BITMAP_CACHE_WAITING_LIST_INDEX */
|
2020-04-02 11:50:16 +03:00
|
|
|
cell->entries = (rdpBitmap**)calloc((nr + 1), sizeof(rdpBitmap*));
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2020-04-02 11:50:16 +03:00
|
|
|
if (!cell->entries)
|
2016-10-04 09:54:42 +03:00
|
|
|
goto fail;
|
2020-04-02 11:50:16 +03:00
|
|
|
cell->number = nr;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
return bitmapCache;
|
2016-10-04 09:54:42 +03:00
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2020-03-30 18:13:51 +03:00
|
|
|
bitmap_cache_free(bitmapCache);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2016-10-04 09:54:42 +03:00
|
|
|
return NULL;
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-03 22:51:41 +04:00
|
|
|
void bitmap_cache_free(rdpBitmapCache* bitmapCache)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2022-05-30 23:32:23 +03:00
|
|
|
if (!bitmapCache)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bitmap_cache_save_persistent(bitmapCache);
|
|
|
|
|
2024-01-23 23:03:28 +03:00
|
|
|
if (bitmapCache->cells)
|
2011-08-06 00:56:40 +04:00
|
|
|
{
|
2024-01-23 23:03:28 +03:00
|
|
|
for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
|
|
|
|
{
|
|
|
|
UINT32 j = 0;
|
|
|
|
BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
|
2011-08-06 00:56:40 +04:00
|
|
|
|
2024-01-23 23:03:28 +03:00
|
|
|
if (!cell->entries)
|
|
|
|
continue;
|
2022-05-30 23:32:23 +03:00
|
|
|
|
2024-01-23 23:03:28 +03:00
|
|
|
for (j = 0; j < cell->number + 1; j++)
|
|
|
|
{
|
|
|
|
rdpBitmap* bitmap = cell->entries[j];
|
|
|
|
Bitmap_Free(bitmapCache->context, bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cell->entries);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
|
|
|
|
2024-01-23 23:03:28 +03:00
|
|
|
free(bitmapCache->cells);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
2022-05-30 23:32:23 +03:00
|
|
|
|
|
|
|
persistent_cache_free(bitmapCache->persistent);
|
|
|
|
|
|
|
|
free(bitmapCache);
|
2011-08-06 00:56:40 +04:00
|
|
|
}
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
static void free_bitmap_data(BITMAP_DATA* data, size_t count)
|
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < count; x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
free(data[x].bitmapDataStream);
|
|
|
|
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BITMAP_DATA* copy_bitmap_data(const BITMAP_DATA* data, size_t count)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
BITMAP_DATA* dst = (BITMAP_DATA*)calloc(count, sizeof(BITMAP_DATA));
|
2018-03-30 11:43:20 +03:00
|
|
|
|
|
|
|
if (!dst)
|
|
|
|
goto fail;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t x = 0; x < count; x++)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
|
|
|
dst[x] = data[x];
|
|
|
|
|
|
|
|
if (data[x].bitmapLength > 0)
|
|
|
|
{
|
|
|
|
dst[x].bitmapDataStream = malloc(data[x].bitmapLength);
|
|
|
|
|
|
|
|
if (!dst[x].bitmapDataStream)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst[x].bitmapDataStream, data[x].bitmapDataStream, data[x].bitmapLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
|
|
|
free_bitmap_data(dst, count);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_bitmap_update(rdpContext* context, BITMAP_UPDATE* pointer)
|
|
|
|
{
|
|
|
|
if (!pointer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free_bitmap_data(pointer->rectangles, pointer->number);
|
|
|
|
free(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
BITMAP_UPDATE* copy_bitmap_update(rdpContext* context, const BITMAP_UPDATE* pointer)
|
|
|
|
{
|
|
|
|
BITMAP_UPDATE* dst = calloc(1, sizeof(BITMAP_UPDATE));
|
|
|
|
|
|
|
|
if (!dst || !pointer)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *pointer;
|
|
|
|
dst->rectangles = copy_bitmap_data(pointer->rectangles, pointer->number);
|
|
|
|
|
|
|
|
if (!dst->rectangles)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2018-03-30 11:43:20 +03:00
|
|
|
free_bitmap_update(context, dst);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2018-03-30 11:43:20 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_BITMAP_ORDER* copy_cache_bitmap_order(rdpContext* context, const CACHE_BITMAP_ORDER* order)
|
|
|
|
{
|
|
|
|
CACHE_BITMAP_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_ORDER));
|
|
|
|
|
|
|
|
if (!dst || !order)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *order;
|
|
|
|
|
|
|
|
if (order->bitmapLength > 0)
|
|
|
|
{
|
|
|
|
dst->bitmapDataStream = malloc(order->bitmapLength);
|
|
|
|
|
|
|
|
if (!dst->bitmapDataStream)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2018-03-30 11:43:20 +03:00
|
|
|
free_cache_bitmap_order(context, dst);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2018-03-30 11:43:20 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cache_bitmap_order(rdpContext* context, CACHE_BITMAP_ORDER* order)
|
|
|
|
{
|
|
|
|
if (order)
|
|
|
|
free(order->bitmapDataStream);
|
|
|
|
|
|
|
|
free(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_BITMAP_V2_ORDER* copy_cache_bitmap_v2_order(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
const CACHE_BITMAP_V2_ORDER* order)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
|
|
|
CACHE_BITMAP_V2_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V2_ORDER));
|
|
|
|
|
|
|
|
if (!dst || !order)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *order;
|
|
|
|
|
|
|
|
if (order->bitmapLength > 0)
|
|
|
|
{
|
|
|
|
dst->bitmapDataStream = malloc(order->bitmapLength);
|
|
|
|
|
|
|
|
if (!dst->bitmapDataStream)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2018-03-30 11:43:20 +03:00
|
|
|
free_cache_bitmap_v2_order(context, dst);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2018-03-30 11:43:20 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cache_bitmap_v2_order(rdpContext* context, CACHE_BITMAP_V2_ORDER* order)
|
|
|
|
{
|
|
|
|
if (order)
|
|
|
|
free(order->bitmapDataStream);
|
|
|
|
|
|
|
|
free(order);
|
|
|
|
}
|
|
|
|
|
|
|
|
CACHE_BITMAP_V3_ORDER* copy_cache_bitmap_v3_order(rdpContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
const CACHE_BITMAP_V3_ORDER* order)
|
2018-03-30 11:43:20 +03:00
|
|
|
{
|
|
|
|
CACHE_BITMAP_V3_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V3_ORDER));
|
|
|
|
|
|
|
|
if (!dst || !order)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
*dst = *order;
|
|
|
|
|
|
|
|
if (order->bitmapData.length > 0)
|
|
|
|
{
|
|
|
|
dst->bitmapData.data = malloc(order->bitmapData.length);
|
|
|
|
|
|
|
|
if (!dst->bitmapData.data)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(dst->bitmapData.data, order->bitmapData.data, order->bitmapData.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
fail:
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2018-03-30 11:43:20 +03:00
|
|
|
free_cache_bitmap_v3_order(context, dst);
|
2024-02-04 13:11:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2018-03-30 11:43:20 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cache_bitmap_v3_order(rdpContext* context, CACHE_BITMAP_V3_ORDER* order)
|
|
|
|
{
|
|
|
|
if (order)
|
|
|
|
free(order->bitmapData.data);
|
|
|
|
|
|
|
|
free(order);
|
|
|
|
}
|