From 867528015a8dbdc29d4fcddfe8b147a4d2cbbcfd Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 21 Jul 2016 10:07:42 +0200 Subject: [PATCH] Simplified bitmap drawing. --- client/X11/xf_graphics.c | 104 +++++++---------------------------- libfreerdp/cache/bitmap.c | 51 +---------------- libfreerdp/cache/offscreen.c | 4 +- libfreerdp/core/graphics.c | 2 - libfreerdp/gdi/gdi.c | 19 ++----- libfreerdp/gdi/gdi.h | 6 +- libfreerdp/gdi/graphics.c | 46 ++++++---------- 7 files changed, 52 insertions(+), 180 deletions(-) diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 311442667..fcf93d9ef 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -124,63 +124,6 @@ static BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) return TRUE; } -static BOOL xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - const BYTE* data, UINT32 width, UINT32 height, UINT32 bpp, UINT32 length, - BOOL compressed, UINT32 codecId) -{ - UINT16 size; - const BYTE* pSrcData; - BYTE* pDstData; - UINT32 SrcSize; - UINT32 SrcFormat; - UINT32 bytesPerPixel; - xfContext* xfc = (xfContext*) context; - bytesPerPixel = (bpp + 7) / 8; - size = width * height * 4; - bitmap->data = (BYTE*) _aligned_malloc(size, 16); - - if (!bitmap->data) - return FALSE; - - pSrcData = data; - SrcSize = (UINT32) length; - pDstData = bitmap->data; - - if (compressed) - { - if (bpp < 32) - { - if (!interleaved_decompress(context->codecs->interleaved, - pSrcData, SrcSize, width, height, bpp, - pDstData, xfc->format, - 0, 0, 0, bitmap->width, bitmap->height, - &context->gdi->palette)) - return FALSE; - } - else - { - if (!planar_decompress(context->codecs->planar, pSrcData, SrcSize, - width, height, - pDstData, xfc->format, 0, 0, 0, bitmap->width, bitmap->height, TRUE)) - return FALSE; - } - } - else - { - SrcFormat = gdi_get_pixel_format(bpp, TRUE); - - if (!freerdp_image_copy(pDstData, xfc->format, 0, 0, 0, - width, height, pSrcData, - SrcFormat, 0, 0, 0, &context->gdi->palette)) - return FALSE; - } - - bitmap->compressed = FALSE; - bitmap->length = size; - bitmap->format = xfc->format; - return TRUE; -} - static BOOL xf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary) { @@ -461,33 +404,26 @@ BOOL xf_register_pointer(rdpGraphics* graphics) BOOL xf_register_graphics(rdpGraphics* graphics) { - rdpBitmap* bitmap = NULL; - rdpGlyph* glyph = NULL; - BOOL ret = FALSE; + rdpBitmap bitmap; + rdpGlyph glyph; - if (!(bitmap = (rdpBitmap*) calloc(1, sizeof(rdpBitmap)))) - goto out; + if (!graphics || !graphics->Bitmap_Prototype || !graphics->Glyph_Prototype) + return FALSE; - if (!(glyph = (rdpGlyph*) calloc(1, sizeof(rdpGlyph)))) - goto out; - - bitmap->size = sizeof(xfBitmap); - bitmap->New = xf_Bitmap_New; - bitmap->Free = xf_Bitmap_Free; - bitmap->Paint = xf_Bitmap_Paint; - bitmap->Decompress = xf_Bitmap_Decompress; - bitmap->SetSurface = xf_Bitmap_SetSurface; - graphics_register_bitmap(graphics, bitmap); - glyph->size = sizeof(xfGlyph); - glyph->New = xf_Glyph_New; - glyph->Free = xf_Glyph_Free; - glyph->Draw = xf_Glyph_Draw; - glyph->BeginDraw = xf_Glyph_BeginDraw; - glyph->EndDraw = xf_Glyph_EndDraw; - graphics_register_glyph(graphics, glyph); - ret = TRUE; -out: - free(bitmap); - free(glyph); - return ret; + bitmap = *graphics->Bitmap_Prototype; + glyph = *graphics->Glyph_Prototype; + bitmap.size = sizeof(xfBitmap); + bitmap.New = xf_Bitmap_New; + bitmap.Free = xf_Bitmap_Free; + bitmap.Paint = xf_Bitmap_Paint; + bitmap.SetSurface = xf_Bitmap_SetSurface; + graphics_register_bitmap(graphics, &bitmap); + glyph.size = sizeof(xfGlyph); + glyph.New = xf_Glyph_New; + glyph.Free = xf_Glyph_Free; + glyph.Draw = xf_Glyph_Draw; + glyph.BeginDraw = xf_Glyph_BeginDraw; + glyph.EndDraw = xf_Glyph_EndDraw; + graphics_register_glyph(graphics, &glyph); + return TRUE; } diff --git a/libfreerdp/cache/bitmap.c b/libfreerdp/cache/bitmap.c index e4887e473..1ccd441cf 100644 --- a/libfreerdp/cache/bitmap.c +++ b/libfreerdp/cache/bitmap.c @@ -33,6 +33,8 @@ #include #include +#include "../gdi/gdi.h" + #define TAG FREERDP_TAG("cache.bitmap") static rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, @@ -236,53 +238,6 @@ static BOOL update_gdi_cache_bitmap_v3(rdpContext* context, return TRUE; } -static BOOL update_gdi_bitmap_update(rdpContext* context, - const BITMAP_UPDATE* bitmapUpdate) -{ - UINT32 i; - - for (i = 0; i < bitmapUpdate->number; i++) - { - const BITMAP_DATA* bitmapData = &bitmapUpdate->rectangles[i]; - rdpBitmap* bitmap = Bitmap_Alloc(context); - - if (!bitmap) - return FALSE; - - bitmap->format = gdi_get_pixel_format(bitmapData->bitsPerPixel, FALSE); - bitmap->length = bitmapData->bitmapLength; - bitmap->compressed = bitmapData->compressed; - Bitmap_SetRectangle(bitmap, - bitmapData->destLeft, bitmapData->destTop, - bitmapData->destRight, bitmapData->destBottom); - - if (!bitmap->Decompress(context, bitmap, - bitmapData->bitmapDataStream, bitmapData->width, bitmapData->height, - bitmapData->bitsPerPixel, bitmapData->bitmapLength, - bitmapData->compressed, RDP_CODEC_ID_NONE)) - { - bitmap->Free(context, bitmap); - return FALSE; - } - - if (!bitmap->New(context, bitmap)) - { - bitmap->Free(context, bitmap); - return FALSE; - } - - if (!bitmap->Paint(context, bitmap)) - { - bitmap->Free(context, bitmap); - return FALSE; - } - - bitmap->Free(context, bitmap); - } - - return TRUE; -} - rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index) { @@ -340,7 +295,7 @@ void bitmap_cache_register_callbacks(rdpUpdate* update) 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 = update_gdi_bitmap_update; + update->BitmapUpdate = gdi_bitmap_update; } rdpBitmapCache* bitmap_cache_new(rdpSettings* settings) diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index 88bd1d649..13c47e7ed 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -48,8 +48,8 @@ static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, if (!bitmap) return FALSE; - bitmap->width = createOffscreenBitmap->cx; - bitmap->height = createOffscreenBitmap->cy; + Bitmap_SetDimensions(bitmap, createOffscreenBitmap->cx, + createOffscreenBitmap->cy); if (!bitmap->New(context, bitmap)) { diff --git a/libfreerdp/core/graphics.c b/libfreerdp/core/graphics.c index 935d84035..f8473b0cc 100644 --- a/libfreerdp/core/graphics.c +++ b/libfreerdp/core/graphics.c @@ -76,8 +76,6 @@ BOOL Bitmap_SetRectangle(rdpBitmap* bitmap, bitmap->top = top; bitmap->right = right; bitmap->bottom = bottom; - bitmap->width = bitmap->right - bitmap->left + 1; - bitmap->height = bitmap->bottom - bitmap->top + 1; return TRUE; } diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 0d5d9a09b..6b12f7261 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -471,8 +471,8 @@ void gdi_bitmap_free_ex(gdiBitmap* bitmap) } } -static BOOL gdi_bitmap_update(rdpContext* context, - const BITMAP_UPDATE* bitmapUpdate) +BOOL gdi_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate) { UINT32 index; rdpGdi* gdi; @@ -487,16 +487,14 @@ static BOOL gdi_bitmap_update(rdpContext* context, for (index = 0; index < bitmapUpdate->number; index++) { const BITMAP_DATA* bitmap = &(bitmapUpdate->rectangles[index]); - const UINT32 nWidth = MIN(bitmap->destRight, - gdi->width - 1) - bitmap->destLeft + 1; /* clip width */ - const UINT32 nHeight = MIN(bitmap->destBottom, - gdi->height - 1) - bitmap->destTop + 1; /* clip height */ rdpBitmap* bmp = Bitmap_Alloc(context); if (!bmp) return FALSE; Bitmap_SetDimensions(bmp, bitmap->width, bitmap->height); + Bitmap_SetRectangle(bmp, bitmap->destLeft, bitmap->destTop, bitmap->destRight, + bitmap->destBottom); if (!bmp->Decompress(context, bmp, bitmap->bitmapDataStream, bitmap->width, bitmap->height, bitmap->bitsPerPixel, @@ -513,20 +511,13 @@ static BOOL gdi_bitmap_update(rdpContext* context, return FALSE; } - if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride, - bitmap->destLeft, bitmap->destTop, nWidth, nHeight, - bmp->data, bmp->format, bmp->width * GetBytesPerPixel(bmp->format), - 0, 0, &gdi->palette)) + if (!bmp->Paint(context, bmp)) { bmp->Free(context, bmp); return FALSE; } bmp->Free(context, bmp); - - if (!gdi_InvalidateRegion(gdi->primary->hdc, bitmap->destLeft, bitmap->destTop, - nWidth, nHeight)) - return FALSE; } return TRUE; diff --git a/libfreerdp/gdi/gdi.h b/libfreerdp/gdi/gdi.h index 6176c8b15..3e23a600c 100644 --- a/libfreerdp/gdi/gdi.h +++ b/libfreerdp/gdi/gdi.h @@ -22,7 +22,11 @@ #include "graphics.h" -gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data); +BOOL gdi_bitmap_update(rdpContext* context, + const BITMAP_UPDATE* bitmapUpdate); + +gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, + BYTE* data); void gdi_bitmap_free_ex(gdiBitmap* gdi_bmp); #endif /* __GDI_CORE_H */ diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 2ce6f5a4b..df674477b 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -313,7 +313,7 @@ static BOOL gdi_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, if (!gdi->drawing || !gdi->drawing->hdc) return FALSE; - gdi_DeleteObject(gdi->drawing->hdc->brush); + gdi_DeleteObject((HGDIOBJECT)gdi->drawing->hdc->brush); gdi_SetNullClipRgn(gdi->drawing->hdc); return TRUE; } @@ -321,33 +321,21 @@ static BOOL gdi_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, /* Graphics Module */ BOOL gdi_register_graphics(rdpGraphics* graphics) { - rdpBitmap* bitmap; - rdpGlyph* glyph; - bitmap = (rdpBitmap*) calloc(1, sizeof(rdpBitmap)); - - if (!bitmap) - return FALSE; - - bitmap->size = sizeof(gdiBitmap); - bitmap->New = gdi_Bitmap_New; - bitmap->Free = gdi_Bitmap_Free; - bitmap->Paint = gdi_Bitmap_Paint; - bitmap->Decompress = gdi_Bitmap_Decompress; - bitmap->SetSurface = gdi_Bitmap_SetSurface; - graphics_register_bitmap(graphics, bitmap); - free(bitmap); - glyph = (rdpGlyph*) calloc(1, sizeof(rdpGlyph)); - - if (!glyph) - return FALSE; - - glyph->size = sizeof(gdiGlyph); - glyph->New = gdi_Glyph_New; - glyph->Free = gdi_Glyph_Free; - glyph->Draw = gdi_Glyph_Draw; - glyph->BeginDraw = gdi_Glyph_BeginDraw; - glyph->EndDraw = gdi_Glyph_EndDraw; - graphics_register_glyph(graphics, glyph); - free(glyph); + rdpBitmap bitmap; + rdpGlyph glyph; + bitmap.size = sizeof(gdiBitmap); + bitmap.New = gdi_Bitmap_New; + bitmap.Free = gdi_Bitmap_Free; + bitmap.Paint = gdi_Bitmap_Paint; + bitmap.Decompress = gdi_Bitmap_Decompress; + bitmap.SetSurface = gdi_Bitmap_SetSurface; + graphics_register_bitmap(graphics, &bitmap); + glyph.size = sizeof(gdiGlyph); + glyph.New = gdi_Glyph_New; + glyph.Free = gdi_Glyph_Free; + glyph.Draw = gdi_Glyph_Draw; + glyph.BeginDraw = gdi_Glyph_BeginDraw; + glyph.EndDraw = gdi_Glyph_EndDraw; + graphics_register_glyph(graphics, &glyph); return TRUE; }