2 * FreeRDP: A Remote Desktop Protocol client.
3 * RemoteFX Codec Library - Memory Pool
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <freerdp/utils/memory.h>
27 RFX_POOL* rfx_pool_new()
31 pool = xnew(RFX_POOL);
34 pool->tiles = (RFX_TILE**) xzalloc(sizeof(RFX_TILE*) * pool->size);
39 void rfx_pool_free(RFX_POOL* pool)
44 for (i = 0; i < pool->count; i++)
46 tile = pool->tiles[i];
50 if (tile->data != NULL)
61 void rfx_pool_put_tile(RFX_POOL* pool, RFX_TILE* tile)
63 if (pool->count >= pool->size)
66 pool->tiles = (RFX_TILE**) xrealloc((void*) pool->tiles, sizeof(RFX_TILE*) * pool->size);
69 pool->tiles[(pool->count)++] = tile;
72 RFX_TILE* rfx_pool_get_tile(RFX_POOL* pool)
78 tile = xnew(RFX_TILE);
79 tile->data = (uint8*) xmalloc(4096 * 4); /* 64x64 * 4 */
83 tile = pool->tiles[--(pool->count)];
89 void rfx_pool_put_tiles(RFX_POOL* pool, RFX_TILE** tiles, int count)
93 for (i = 0; i < count; i++)
95 rfx_pool_put_tile(pool, tiles[i]);
99 RFX_TILE** rfx_pool_get_tiles(RFX_POOL* pool, int count)
104 tiles = (RFX_TILE**) xmalloc(sizeof(RFX_TILE*) * count);
106 for (i = 0; i < count; i++)
108 tiles[i] = rfx_pool_get_tile(pool);