From: Marc-André Moreau Date: Sun, 3 Nov 2013 18:51:41 +0000 (-0500) Subject: libfreerdp-cache: refactor code style X-Git-Tag: 1.2.0-beta1+android7~149^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edb218df905ca742ed059729ec8633258e74c45d;p=platform%2Fupstream%2Ffreerdp.git libfreerdp-cache: refactor code style --- diff --git a/libfreerdp/cache/bitmap.c b/libfreerdp/cache/bitmap.c index fcd653b..18e8b76 100644 --- a/libfreerdp/cache/bitmap.c +++ b/libfreerdp/cache/bitmap.c @@ -58,8 +58,10 @@ void update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) bitmap = offscreen_cache_get(cache->offscreen, mem3blt->cacheIndex); else bitmap = bitmap_cache_get(cache->bitmap, (BYTE) mem3blt->cacheId, mem3blt->cacheIndex); + /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */ - if (bitmap == NULL) return; + if (!bitmap) + return; style = brush->style; @@ -74,7 +76,7 @@ void update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) brush->style = style; } -void update_gdi_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cache_bitmap) +void update_gdi_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cacheBitmap) { rdpBitmap* bitmap; rdpBitmap* prevBitmap; @@ -82,24 +84,24 @@ void update_gdi_cache_bitmap(rdpContext* context, CACHE_BITMAP_ORDER* cache_bitm bitmap = Bitmap_Alloc(context); - Bitmap_SetDimensions(context, bitmap, cache_bitmap->bitmapWidth, cache_bitmap->bitmapHeight); + Bitmap_SetDimensions(context, bitmap, cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight); bitmap->Decompress(context, bitmap, - cache_bitmap->bitmapDataStream, cache_bitmap->bitmapWidth, cache_bitmap->bitmapHeight, - cache_bitmap->bitmapBpp, cache_bitmap->bitmapLength, - cache_bitmap->compressed, RDP_CODEC_ID_NONE); + cacheBitmap->bitmapDataStream, cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight, + cacheBitmap->bitmapBpp, cacheBitmap->bitmapLength, + cacheBitmap->compressed, RDP_CODEC_ID_NONE); bitmap->New(context, bitmap); - prevBitmap = bitmap_cache_get(cache->bitmap, cache_bitmap->cacheId, cache_bitmap->cacheIndex); + prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex); if (prevBitmap != NULL) Bitmap_Free(context, prevBitmap); - bitmap_cache_put(cache->bitmap, cache_bitmap->cacheId, cache_bitmap->cacheIndex, bitmap); + bitmap_cache_put(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex, bitmap); } -void update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2) +void update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cacheBitmapV2) { rdpBitmap* bitmap; rdpBitmap* prevBitmap; @@ -107,44 +109,44 @@ void update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cach bitmap = Bitmap_Alloc(context); - Bitmap_SetDimensions(context, bitmap, cache_bitmap_v2->bitmapWidth, cache_bitmap_v2->bitmapHeight); + Bitmap_SetDimensions(context, bitmap, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight); - if (cache_bitmap_v2->bitmapBpp == 0) + if (cacheBitmapV2->bitmapBpp == 0) { /* Workaround for Windows 8 bug where bitmapBpp is not set */ - cache_bitmap_v2->bitmapBpp = context->instance->settings->ColorDepth; + cacheBitmapV2->bitmapBpp = context->instance->settings->ColorDepth; } bitmap->Decompress(context, bitmap, - cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapWidth, cache_bitmap_v2->bitmapHeight, - cache_bitmap_v2->bitmapBpp, cache_bitmap_v2->bitmapLength, - cache_bitmap_v2->compressed, RDP_CODEC_ID_NONE); + cacheBitmapV2->bitmapDataStream, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight, + cacheBitmapV2->bitmapBpp, cacheBitmapV2->bitmapLength, + cacheBitmapV2->compressed, RDP_CODEC_ID_NONE); bitmap->New(context, bitmap); - prevBitmap = bitmap_cache_get(cache->bitmap, cache_bitmap_v2->cacheId, cache_bitmap_v2->cacheIndex); + prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex); if (prevBitmap != NULL) Bitmap_Free(context, prevBitmap); - bitmap_cache_put(cache->bitmap, cache_bitmap_v2->cacheId, cache_bitmap_v2->cacheIndex, bitmap); + bitmap_cache_put(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex, bitmap); } -void update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3) +void update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cacheBitmapV3) { rdpBitmap* bitmap; rdpBitmap* prevBitmap; rdpCache* cache = context->cache; - BITMAP_DATA_EX* bitmapData = &cache_bitmap_v3->bitmapData; + BITMAP_DATA_EX* bitmapData = &cacheBitmapV3->bitmapData; bitmap = Bitmap_Alloc(context); Bitmap_SetDimensions(context, bitmap, bitmapData->width, bitmapData->height); - if (cache_bitmap_v3->bitmapData.bpp == 0) + if (cacheBitmapV3->bitmapData.bpp == 0) { /* Workaround for Windows 8 bug where bitmapBpp is not set */ - cache_bitmap_v3->bitmapData.bpp = context->instance->settings->ColorDepth; + cacheBitmapV3->bitmapData.bpp = context->instance->settings->ColorDepth; } bitmap->Decompress(context, bitmap, @@ -154,15 +156,15 @@ void update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cach bitmap->New(context, bitmap); - prevBitmap = bitmap_cache_get(cache->bitmap, cache_bitmap_v3->cacheId, cache_bitmap_v3->cacheIndex); + prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex); if (prevBitmap != NULL) Bitmap_Free(context, prevBitmap); - bitmap_cache_put(cache->bitmap, cache_bitmap_v3->cacheId, cache_bitmap_v3->cacheIndex, bitmap); + bitmap_cache_put(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex, bitmap); } -void update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap_update) +void update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmapUpdate) { int i; rdpBitmap* bitmap; @@ -170,7 +172,7 @@ void update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap_update) BOOL reused = TRUE; rdpCache* cache = context->cache; - if (cache->bitmap->bitmap == NULL) + if (!cache->bitmap->bitmap) { cache->bitmap->bitmap = Bitmap_Alloc(context); cache->bitmap->bitmap->ephemeral = TRUE; @@ -179,9 +181,9 @@ void update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap_update) bitmap = cache->bitmap->bitmap; - for (i = 0; i < (int) bitmap_update->number; i++) + for (i = 0; i < (int) bitmapUpdate->number; i++) { - bitmap_data = &bitmap_update->rectangles[i]; + bitmap_data = &bitmapUpdate->rectangles[i]; bitmap->bpp = bitmap_data->bitsPerPixel; bitmap->length = bitmap_data->bitmapLength; @@ -209,11 +211,11 @@ void update_gdi_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap_update) } } -rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index) +rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index) { rdpBitmap* bitmap; - if (id > bitmap_cache->maxCells) + if (id > bitmapCache->maxCells) { fprintf(stderr, "get invalid bitmap cell id: %d\n", id); return NULL; @@ -221,22 +223,22 @@ rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 inde if (index == BITMAP_CACHE_WAITING_LIST_INDEX) { - index = bitmap_cache->cells[id].number; + index = bitmapCache->cells[id].number; } - else if (index > bitmap_cache->cells[id].number) + else if (index > bitmapCache->cells[id].number) { fprintf(stderr, "get invalid bitmap index %d in cell id: %d\n", index, id); return NULL; } - bitmap = bitmap_cache->cells[id].entries[index]; + bitmap = bitmapCache->cells[id].entries[index]; return bitmap; } -void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdpBitmap* bitmap) +void bitmap_cache_put(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index, rdpBitmap* bitmap) { - if (id > bitmap_cache->maxCells) + if (id > bitmapCache->maxCells) { fprintf(stderr, "put invalid bitmap cell id: %d\n", id); return; @@ -244,15 +246,15 @@ void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdp if (index == BITMAP_CACHE_WAITING_LIST_INDEX) { - index = bitmap_cache->cells[id].number; + index = bitmapCache->cells[id].number; } - else if (index > bitmap_cache->cells[id].number) + else if (index > bitmapCache->cells[id].number) { fprintf(stderr, "put invalid bitmap index %d in cell id: %d\n", index, id); return; } - bitmap_cache->cells[id].entries[index] = bitmap; + bitmapCache->cells[id].entries[index] = bitmap; } void bitmap_cache_register_callbacks(rdpUpdate* update) @@ -275,60 +277,61 @@ void bitmap_cache_register_callbacks(rdpUpdate* update) rdpBitmapCache* bitmap_cache_new(rdpSettings* settings) { int i; - rdpBitmapCache* bitmap_cache; + rdpBitmapCache* bitmapCache; - bitmap_cache = (rdpBitmapCache*) malloc(sizeof(rdpBitmapCache)); - ZeroMemory(bitmap_cache, sizeof(rdpBitmapCache)); + bitmapCache = (rdpBitmapCache*) malloc(sizeof(rdpBitmapCache)); - if (bitmap_cache != NULL) + if (bitmapCache) { - bitmap_cache->settings = settings; - bitmap_cache->update = ((freerdp*) settings->instance)->update; - bitmap_cache->context = bitmap_cache->update->context; + ZeroMemory(bitmapCache, sizeof(rdpBitmapCache)); + + bitmapCache->settings = settings; + bitmapCache->update = ((freerdp*) settings->instance)->update; + bitmapCache->context = bitmapCache->update->context; - bitmap_cache->maxCells = settings->BitmapCacheV2NumCells; + bitmapCache->maxCells = settings->BitmapCacheV2NumCells; - bitmap_cache->cells = (BITMAP_V2_CELL*) malloc(sizeof(BITMAP_V2_CELL) * bitmap_cache->maxCells); - ZeroMemory(bitmap_cache->cells, sizeof(BITMAP_V2_CELL) * bitmap_cache->maxCells); + bitmapCache->cells = (BITMAP_V2_CELL*) malloc(sizeof(BITMAP_V2_CELL) * bitmapCache->maxCells); + ZeroMemory(bitmapCache->cells, sizeof(BITMAP_V2_CELL) * bitmapCache->maxCells); - for (i = 0; i < (int) bitmap_cache->maxCells; i++) + for (i = 0; i < (int) bitmapCache->maxCells; i++) { - bitmap_cache->cells[i].number = settings->BitmapCacheV2CellInfo[i].numEntries; + bitmapCache->cells[i].number = settings->BitmapCacheV2CellInfo[i].numEntries; /* allocate an extra entry for BITMAP_CACHE_WAITING_LIST_INDEX */ - bitmap_cache->cells[i].entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * (bitmap_cache->cells[i].number + 1)); - ZeroMemory(bitmap_cache->cells[i].entries, sizeof(rdpBitmap*) * (bitmap_cache->cells[i].number + 1)); + bitmapCache->cells[i].entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * (bitmapCache->cells[i].number + 1)); + ZeroMemory(bitmapCache->cells[i].entries, sizeof(rdpBitmap*) * (bitmapCache->cells[i].number + 1)); } } - return bitmap_cache; + return bitmapCache; } -void bitmap_cache_free(rdpBitmapCache* bitmap_cache) +void bitmap_cache_free(rdpBitmapCache* bitmapCache) { int i, j; rdpBitmap* bitmap; - if (bitmap_cache != NULL) + if (bitmapCache != NULL) { - for (i = 0; i < (int) bitmap_cache->maxCells; i++) + for (i = 0; i < (int) bitmapCache->maxCells; i++) { - for (j = 0; j < (int) bitmap_cache->cells[i].number + 1; j++) + for (j = 0; j < (int) bitmapCache->cells[i].number + 1; j++) { - bitmap = bitmap_cache->cells[i].entries[j]; + bitmap = bitmapCache->cells[i].entries[j]; if (bitmap != NULL) { - Bitmap_Free(bitmap_cache->context, bitmap); + Bitmap_Free(bitmapCache->context, bitmap); } } - free(bitmap_cache->cells[i].entries); + free(bitmapCache->cells[i].entries); } - if (bitmap_cache->bitmap != NULL) - Bitmap_Free(bitmap_cache->context, bitmap_cache->bitmap); + if (bitmapCache->bitmap) + Bitmap_Free(bitmapCache->context, bitmapCache->bitmap); - free(bitmap_cache->cells); - free(bitmap_cache); + free(bitmapCache->cells); + free(bitmapCache); } } diff --git a/libfreerdp/cache/brush.c b/libfreerdp/cache/brush.c index b4e5373..b5e54f8 100644 --- a/libfreerdp/cache/brush.c +++ b/libfreerdp/cache/brush.c @@ -73,48 +73,48 @@ void update_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) brush->style = style; } -static void update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cache_brush) +static void update_gdi_cache_brush(rdpContext* context, CACHE_BRUSH_ORDER* cacheBrush) { int length; void* data = NULL; rdpCache* cache = context->cache; - length = cache_brush->bpp * 64 / 8; + length = cacheBrush->bpp * 64 / 8; data = malloc(length); - CopyMemory(data, cache_brush->data, length); + CopyMemory(data, cacheBrush->data, length); - brush_cache_put(cache->brush, cache_brush->index, data, cache_brush->bpp); + brush_cache_put(cache->brush, cacheBrush->index, data, cacheBrush->bpp); } -void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp) +void* brush_cache_get(rdpBrushCache* brushCache, UINT32 index, UINT32* bpp) { void* entry; - assert(brush); + assert(brushCache); assert(bpp); if (*bpp == 1) { - if (index >= brush->maxMonoEntries) + if (index >= brushCache->maxMonoEntries) { fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); return NULL; } - *bpp = brush->monoEntries[index].bpp; - entry = brush->monoEntries[index].entry; + *bpp = brushCache->monoEntries[index].bpp; + entry = brushCache->monoEntries[index].entry; } else { - if (index >= brush->maxEntries) + if (index >= brushCache->maxEntries) { fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); return NULL; } - *bpp = brush->entries[index].bpp; - entry = brush->entries[index].entry; + *bpp = brushCache->entries[index].bpp; + entry = brushCache->entries[index].entry; } if (entry == NULL) @@ -126,45 +126,49 @@ void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp) return entry; } -void brush_cache_put(rdpBrushCache* brush, UINT32 index, void* entry, UINT32 bpp) +void brush_cache_put(rdpBrushCache* brushCache, UINT32 index, void* entry, UINT32 bpp) { void* prevEntry; if (bpp == 1) { - if (index >= brush->maxMonoEntries) + if (index >= brushCache->maxMonoEntries) { fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index); + if (entry) free(entry); + return; } - prevEntry = brush->monoEntries[index].entry; + prevEntry = brushCache->monoEntries[index].entry; if (prevEntry != NULL) free(prevEntry); - brush->monoEntries[index].bpp = bpp; - brush->monoEntries[index].entry = entry; + brushCache->monoEntries[index].bpp = bpp; + brushCache->monoEntries[index].entry = entry; } else { - if (index >= brush->maxEntries) + if (index >= brushCache->maxEntries) { fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index); + if (entry) free(entry); + return; } - prevEntry = brush->entries[index].entry; + prevEntry = brushCache->entries[index].entry; if (prevEntry != NULL) free(prevEntry); - brush->entries[index].bpp = bpp; - brush->entries[index].entry = entry; + brushCache->entries[index].bpp = bpp; + brushCache->entries[index].entry = entry; } } @@ -184,56 +188,57 @@ void brush_cache_register_callbacks(rdpUpdate* update) rdpBrushCache* brush_cache_new(rdpSettings* settings) { - rdpBrushCache* brush; + rdpBrushCache* brushCache; - brush = (rdpBrushCache*) malloc(sizeof(rdpBrushCache)); - ZeroMemory(brush, sizeof(rdpBrushCache)); + brushCache = (rdpBrushCache*) malloc(sizeof(rdpBrushCache)); - if (brush != NULL) + if (brushCache) { - brush->settings = settings; + ZeroMemory(brushCache, sizeof(rdpBrushCache)); + + brushCache->settings = settings; - brush->maxEntries = 64; - brush->maxMonoEntries = 64; + brushCache->maxEntries = 64; + brushCache->maxMonoEntries = 64; - brush->entries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brush->maxEntries); - ZeroMemory(brush->entries, sizeof(BRUSH_ENTRY) * brush->maxEntries); + brushCache->entries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxEntries); + ZeroMemory(brushCache->entries, sizeof(BRUSH_ENTRY) * brushCache->maxEntries); - brush->monoEntries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brush->maxMonoEntries); - ZeroMemory(brush->monoEntries, sizeof(BRUSH_ENTRY) * brush->maxMonoEntries); + brushCache->monoEntries = (BRUSH_ENTRY*) malloc(sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries); + ZeroMemory(brushCache->monoEntries, sizeof(BRUSH_ENTRY) * brushCache->maxMonoEntries); } - return brush; + return brushCache; } -void brush_cache_free(rdpBrushCache* brush) +void brush_cache_free(rdpBrushCache* brushCache) { int i; - if (brush != NULL) + if (brushCache) { - if (brush->entries != NULL) + if (brushCache->entries) { - for (i = 0; i < (int) brush->maxEntries; i++) + for (i = 0; i < (int) brushCache->maxEntries; i++) { - if (brush->entries[i].entry != NULL) - free(brush->entries[i].entry); + if (brushCache->entries[i].entry != NULL) + free(brushCache->entries[i].entry); } - free(brush->entries); + free(brushCache->entries); } - if (brush->monoEntries != NULL) + if (brushCache->monoEntries) { - for (i = 0; i < (int) brush->maxMonoEntries; i++) + for (i = 0; i < (int) brushCache->maxMonoEntries; i++) { - if (brush->monoEntries[i].entry != NULL) - free(brush->monoEntries[i].entry); + if (brushCache->monoEntries[i].entry != NULL) + free(brushCache->monoEntries[i].entry); } - free(brush->monoEntries); + free(brushCache->monoEntries); } - free(brush); + free(brushCache); } } diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index ebca2d8..c735f96 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -29,7 +29,7 @@ #include -void update_gdi_create_offscreen_bitmap(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +void update_gdi_create_offscreen_bitmap(rdpContext* context, CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) { int i; UINT16 index; @@ -38,55 +38,55 @@ void update_gdi_create_offscreen_bitmap(rdpContext* context, CREATE_OFFSCREEN_BI bitmap = Bitmap_Alloc(context); - bitmap->width = create_offscreen_bitmap->cx; - bitmap->height = create_offscreen_bitmap->cy; + bitmap->width = createOffscreenBitmap->cx; + bitmap->height = createOffscreenBitmap->cy; bitmap->New(context, bitmap); - offscreen_cache_delete(cache->offscreen, create_offscreen_bitmap->id); - offscreen_cache_put(cache->offscreen, create_offscreen_bitmap->id, bitmap); + offscreen_cache_delete(cache->offscreen, createOffscreenBitmap->id); + offscreen_cache_put(cache->offscreen, createOffscreenBitmap->id, bitmap); - if(cache->offscreen->currentSurface == create_offscreen_bitmap->id) + if(cache->offscreen->currentSurface == createOffscreenBitmap->id) Bitmap_SetSurface(context, bitmap, FALSE); - for (i = 0; i < (int) create_offscreen_bitmap->deleteList.cIndices; i++) + for (i = 0; i < (int) createOffscreenBitmap->deleteList.cIndices; i++) { - index = create_offscreen_bitmap->deleteList.indices[i]; + index = createOffscreenBitmap->deleteList.indices[i]; offscreen_cache_delete(cache->offscreen, index); } } -void update_gdi_switch_surface(rdpContext* context, SWITCH_SURFACE_ORDER* switch_surface) +void update_gdi_switch_surface(rdpContext* context, SWITCH_SURFACE_ORDER* switchSurface) { rdpCache* cache = context->cache; - if (switch_surface->bitmapId == SCREEN_BITMAP_SURFACE) + if (switchSurface->bitmapId == SCREEN_BITMAP_SURFACE) { Bitmap_SetSurface(context, NULL, TRUE); } else { rdpBitmap* bitmap; - bitmap = offscreen_cache_get(cache->offscreen, switch_surface->bitmapId); + bitmap = offscreen_cache_get(cache->offscreen, switchSurface->bitmapId); Bitmap_SetSurface(context, bitmap, FALSE); } - cache->offscreen->currentSurface = switch_surface->bitmapId; + cache->offscreen->currentSurface = switchSurface->bitmapId; } -rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreen_cache, UINT32 index) +rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index) { rdpBitmap* bitmap; - if (index >= offscreen_cache->maxEntries) + if (index >= offscreenCache->maxEntries) { fprintf(stderr, "invalid offscreen bitmap index: 0x%04X\n", index); return NULL; } - bitmap = offscreen_cache->entries[index]; + bitmap = offscreenCache->entries[index]; - if (bitmap == NULL) + if (!bitmap) { fprintf(stderr, "invalid offscreen bitmap at index: 0x%04X\n", index); return NULL; @@ -95,34 +95,34 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreen_cache, UINT32 index) return bitmap; } -void offscreen_cache_put(rdpOffscreenCache* offscreen, UINT32 index, rdpBitmap* bitmap) +void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap) { - if (index >= offscreen->maxEntries) + if (index >= offscreenCache->maxEntries) { fprintf(stderr, "invalid offscreen bitmap index: 0x%04X\n", index); return; } - offscreen_cache_delete(offscreen, index); - offscreen->entries[index] = bitmap; + offscreen_cache_delete(offscreenCache, index); + offscreenCache->entries[index] = bitmap; } -void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index) +void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index) { rdpBitmap* prevBitmap; - if (index >= offscreen->maxEntries) + if (index >= offscreenCache->maxEntries) { fprintf(stderr, "invalid offscreen bitmap index (delete): 0x%04X\n", index); return; } - prevBitmap = offscreen->entries[index]; + prevBitmap = offscreenCache->entries[index]; if (prevBitmap != NULL) - Bitmap_Free(offscreen->update->context, prevBitmap); + Bitmap_Free(offscreenCache->update->context, prevBitmap); - offscreen->entries[index] = NULL; + offscreenCache->entries[index] = NULL; } void offscreen_cache_register_callbacks(rdpUpdate* update) @@ -133,46 +133,47 @@ void offscreen_cache_register_callbacks(rdpUpdate* update) rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings) { - rdpOffscreenCache* offscreen_cache; + rdpOffscreenCache* offscreenCache; - offscreen_cache = (rdpOffscreenCache*) malloc(sizeof(rdpOffscreenCache)); - ZeroMemory(offscreen_cache, sizeof(rdpOffscreenCache)); + offscreenCache = (rdpOffscreenCache*) malloc(sizeof(rdpOffscreenCache)); - if (offscreen_cache != NULL) + if (offscreenCache) { - offscreen_cache->settings = settings; - offscreen_cache->update = ((freerdp*) settings->instance)->update; + ZeroMemory(offscreenCache, sizeof(rdpOffscreenCache)); - offscreen_cache->currentSurface = SCREEN_BITMAP_SURFACE; - offscreen_cache->maxSize = 7680; - offscreen_cache->maxEntries = 2000; + offscreenCache->settings = settings; + offscreenCache->update = ((freerdp*) settings->instance)->update; - settings->OffscreenCacheSize = offscreen_cache->maxSize; - settings->OffscreenCacheEntries = offscreen_cache->maxEntries; + offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE; + offscreenCache->maxSize = 7680; + offscreenCache->maxEntries = 2000; - offscreen_cache->entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * offscreen_cache->maxEntries); - ZeroMemory(offscreen_cache->entries, sizeof(rdpBitmap*) * offscreen_cache->maxEntries); + settings->OffscreenCacheSize = offscreenCache->maxSize; + settings->OffscreenCacheEntries = offscreenCache->maxEntries; + + offscreenCache->entries = (rdpBitmap**) malloc(sizeof(rdpBitmap*) * offscreenCache->maxEntries); + ZeroMemory(offscreenCache->entries, sizeof(rdpBitmap*) * offscreenCache->maxEntries); } - return offscreen_cache; + return offscreenCache; } -void offscreen_cache_free(rdpOffscreenCache* offscreen_cache) +void offscreen_cache_free(rdpOffscreenCache* offscreenCache) { int i; rdpBitmap* bitmap; - if (offscreen_cache != NULL) + if (offscreenCache) { - for (i = 0; i < (int) offscreen_cache->maxEntries; i++) + for (i = 0; i < (int) offscreenCache->maxEntries; i++) { - bitmap = offscreen_cache->entries[i]; + bitmap = offscreenCache->entries[i]; - if (bitmap != NULL) - Bitmap_Free(offscreen_cache->update->context, bitmap); + if (bitmap) + Bitmap_Free(offscreenCache->update->context, bitmap); } - free(offscreen_cache->entries); - free(offscreen_cache); + free(offscreenCache->entries); + free(offscreenCache); } } diff --git a/libfreerdp/cache/palette.c b/libfreerdp/cache/palette.c index 0d93b1a..a8561bb 100644 --- a/libfreerdp/cache/palette.c +++ b/libfreerdp/cache/palette.c @@ -27,30 +27,30 @@ #include -static void update_gdi_cache_color_table(rdpContext* context, - CACHE_COLOR_TABLE_ORDER* cache_color_table) +static void update_gdi_cache_color_table(rdpContext* context, CACHE_COLOR_TABLE_ORDER* cacheColorTable) { UINT32* colorTable; rdpCache* cache = context->cache; colorTable = (UINT32*) malloc(sizeof(UINT32) * 256); - CopyMemory(colorTable, cache_color_table->colorTable, sizeof(UINT32) * 256); + CopyMemory(colorTable, cacheColorTable->colorTable, sizeof(UINT32) * 256); - palette_cache_put(cache->palette, cache_color_table->cacheIndex, (void*) colorTable); + palette_cache_put(cache->palette, cacheColorTable->cacheIndex, (void*) colorTable); } -void* palette_cache_get(rdpPaletteCache* palette_cache, UINT32 index) +void* palette_cache_get(rdpPaletteCache* paletteCache, UINT32 index) { void* entry; - if (index >= palette_cache->maxEntries) + if (index >= paletteCache->maxEntries) { fprintf(stderr, "invalid color table index: 0x%04X\n", index); return NULL; } - entry = palette_cache->entries[index].entry; - if (entry == NULL) + entry = paletteCache->entries[index].entry; + + if (!entry) { fprintf(stderr, "invalid color table at index: 0x%04X\n", index); return NULL; @@ -59,20 +59,22 @@ void* palette_cache_get(rdpPaletteCache* palette_cache, UINT32 index) return entry; } -void palette_cache_put(rdpPaletteCache* palette_cache, UINT32 index, void* entry) +void palette_cache_put(rdpPaletteCache* paletteCache, UINT32 index, void* entry) { - if (index >= palette_cache->maxEntries) + if (index >= paletteCache->maxEntries) { fprintf(stderr, "invalid color table index: 0x%04X\n", index); + if (entry) free(entry); + return; } - if(NULL == palette_cache->entries[index].entry) - free(palette_cache->entries[index].entry); + if (paletteCache->entries[index].entry) + free(paletteCache->entries[index].entry); - palette_cache->entries[index].entry = entry; + paletteCache->entries[index].entry = entry; } void palette_cache_register_callbacks(rdpUpdate* update) @@ -82,34 +84,35 @@ void palette_cache_register_callbacks(rdpUpdate* update) rdpPaletteCache* palette_cache_new(rdpSettings* settings) { - rdpPaletteCache* palette_cache; + rdpPaletteCache* paletteCache; - palette_cache = (rdpPaletteCache*) malloc(sizeof(rdpPaletteCache)); - ZeroMemory(palette_cache, sizeof(rdpPaletteCache)); + paletteCache = (rdpPaletteCache*) malloc(sizeof(rdpPaletteCache)); + ZeroMemory(paletteCache, sizeof(rdpPaletteCache)); - if (palette_cache != NULL) + if (paletteCache) { - palette_cache->settings = settings; - palette_cache->maxEntries = 6; - palette_cache->entries = (PALETTE_TABLE_ENTRY*) malloc(sizeof(PALETTE_TABLE_ENTRY) * palette_cache->maxEntries); - ZeroMemory(palette_cache->entries, sizeof(PALETTE_TABLE_ENTRY) * palette_cache->maxEntries); + paletteCache->settings = settings; + paletteCache->maxEntries = 6; + paletteCache->entries = (PALETTE_TABLE_ENTRY*) malloc(sizeof(PALETTE_TABLE_ENTRY) * paletteCache->maxEntries); + ZeroMemory(paletteCache->entries, sizeof(PALETTE_TABLE_ENTRY) * paletteCache->maxEntries); } - return palette_cache; + return paletteCache; } -void palette_cache_free(rdpPaletteCache* palette_cache) +void palette_cache_free(rdpPaletteCache* paletteCache) { - if (palette_cache != NULL) + if (paletteCache) { int i; - for (i=0; imaxEntries; i++) + for (i = 0; i< paletteCache->maxEntries; i++) { - if (palette_cache->entries[i].entry) - free(palette_cache->entries[i].entry); + if (paletteCache->entries[i].entry) + free(paletteCache->entries[i].entry); } - free(palette_cache->entries); - free(palette_cache); + + free(paletteCache->entries); + free(paletteCache); } }