libfreerdp-codec: make use of ObjectPool for tiles
This commit is contained in:
parent
f8e870a258
commit
b972830841
@ -22,6 +22,7 @@
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/constants.h>
|
||||
|
||||
#include <winpr/stream.h>
|
||||
|
@ -138,6 +138,39 @@ static void rfx_profiler_print(RFX_CONTEXT* context)
|
||||
PROFILER_PRINT_FOOTER;
|
||||
}
|
||||
|
||||
void rfx_tile_init(RFX_TILE* tile)
|
||||
{
|
||||
if (tile)
|
||||
{
|
||||
tile->x = 0;
|
||||
tile->y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
RFX_TILE* rfx_tile_new()
|
||||
{
|
||||
RFX_TILE* tile = NULL;
|
||||
|
||||
tile = (RFX_TILE*) malloc(sizeof(RFX_TILE));
|
||||
|
||||
if (tile)
|
||||
{
|
||||
ZeroMemory(tile, sizeof(RFX_TILE));
|
||||
|
||||
tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */
|
||||
}
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
void rfx_tile_free(RFX_TILE* tile)
|
||||
{
|
||||
if (tile)
|
||||
{
|
||||
free(tile->data);
|
||||
free(tile);
|
||||
}
|
||||
}
|
||||
|
||||
RFX_CONTEXT* rfx_context_new(void)
|
||||
{
|
||||
@ -155,7 +188,10 @@ RFX_CONTEXT* rfx_context_new(void)
|
||||
context->priv = (RFX_CONTEXT_PRIV*) malloc(sizeof(RFX_CONTEXT_PRIV));
|
||||
ZeroMemory(context->priv, sizeof(RFX_CONTEXT_PRIV));
|
||||
|
||||
context->priv->TilePool = Queue_New(TRUE, -1, -1);
|
||||
context->priv->TilePool = ObjectPool_New(TRUE);
|
||||
ObjectPool_Object(context->priv->TilePool)->fnObjectNew = (OBJECT_NEW_FN) rfx_tile_new;
|
||||
ObjectPool_Object(context->priv->TilePool)->fnObjectInit = (OBJECT_INIT_FN) rfx_tile_init;
|
||||
ObjectPool_Object(context->priv->TilePool)->fnObjectFree = (OBJECT_FREE_FN) rfx_tile_free;
|
||||
|
||||
/*
|
||||
* align buffers to 16 byte boundary (needed for SSE/NEON instructions)
|
||||
@ -254,7 +290,7 @@ void rfx_context_free(RFX_CONTEXT* context)
|
||||
{
|
||||
free(context->quants);
|
||||
|
||||
Queue_Free(context->priv->TilePool);
|
||||
ObjectPool_Free(context->priv->TilePool);
|
||||
|
||||
rfx_profiler_print(context);
|
||||
rfx_profiler_free(context);
|
||||
@ -311,29 +347,6 @@ void rfx_context_reset(RFX_CONTEXT* context)
|
||||
context->frame_idx = 0;
|
||||
}
|
||||
|
||||
RFX_TILE* rfx_tile_pool_take(RFX_CONTEXT* context)
|
||||
{
|
||||
RFX_TILE* tile = NULL;
|
||||
|
||||
tile = Queue_Dequeue(context->priv->TilePool);
|
||||
|
||||
if (!tile)
|
||||
{
|
||||
tile = (RFX_TILE*) malloc(sizeof(RFX_TILE));
|
||||
|
||||
tile->x = tile->y = 0;
|
||||
tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */
|
||||
}
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
int rfx_tile_pool_return(RFX_CONTEXT* context, RFX_TILE* tile)
|
||||
{
|
||||
Queue_Enqueue(context->priv->TilePool, tile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s)
|
||||
{
|
||||
UINT32 magic;
|
||||
@ -724,7 +737,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
|
||||
break;
|
||||
}
|
||||
|
||||
message->tiles[i] = rfx_tile_pool_take(context);
|
||||
message->tiles[i] = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool);
|
||||
|
||||
if (context->priv->UseThreads)
|
||||
{
|
||||
@ -885,7 +898,9 @@ void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message)
|
||||
if (message->tiles)
|
||||
{
|
||||
for (i = 0; i < message->num_tiles; i++)
|
||||
rfx_tile_pool_return(context, message->tiles[i]);
|
||||
{
|
||||
ObjectPool_Return(context->priv->TilePool, (void*) message->tiles[i]);
|
||||
}
|
||||
|
||||
free(message->tiles);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
struct _RFX_CONTEXT_PRIV
|
||||
{
|
||||
wQueue* TilePool;
|
||||
wObjectPool* TilePool;
|
||||
|
||||
BOOL UseThreads;
|
||||
DWORD MinThreadCount;
|
||||
|
@ -35,12 +35,16 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* (*OBJECT_NEW_FN)(void);
|
||||
typedef void (*OBJECT_INIT_FN)(void* obj);
|
||||
typedef void (*OBJECT_UNINIT_FN)(void* obj);
|
||||
typedef void (*OBJECT_FREE_FN)(void* obj);
|
||||
typedef void (*OBJECT_EQUALS_FN)(void* objA, void* objB);
|
||||
|
||||
struct _wObject
|
||||
{
|
||||
OBJECT_NEW_FN fnObjectNew;
|
||||
OBJECT_INIT_FN fnObjectInit;
|
||||
OBJECT_UNINIT_FN fnObjectUninit;
|
||||
OBJECT_FREE_FN fnObjectFree;
|
||||
OBJECT_EQUALS_FN fnObjectEquals;
|
||||
};
|
||||
|
@ -54,6 +54,9 @@ void* ObjectPool_Take(wObjectPool* pool)
|
||||
obj = pool->object.fnObjectNew();
|
||||
}
|
||||
|
||||
if (pool->object.fnObjectInit)
|
||||
pool->object.fnObjectInit(obj);
|
||||
|
||||
if (pool->synchronized)
|
||||
LeaveCriticalSection(&pool->lock);
|
||||
|
||||
@ -77,6 +80,9 @@ void ObjectPool_Return(wObjectPool* pool, void* obj)
|
||||
|
||||
pool->array[(pool->size)++] = obj;
|
||||
|
||||
if (pool->object.fnObjectUninit)
|
||||
pool->object.fnObjectUninit(obj);
|
||||
|
||||
if (pool->synchronized)
|
||||
LeaveCriticalSection(&pool->lock);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user