Code refactoring.

This commit is contained in:
Armin Novak 2016-07-14 12:42:24 +02:00
parent e6e8f2d4f2
commit 5e9c9f90ab
4 changed files with 349 additions and 348 deletions

View File

@ -415,13 +415,13 @@ static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
if (srcp && dstp)
{
UINT32 color;
UINT32 dstColor;
UINT32 colorA = ReadColor(srcp, hdcSrc->format);
UINT32 colorB = ReadColor(dstp, hdcDest->format);
colorA = ConvertColor(colorA, hdcSrc->format,
hdcDest->format, palette);
color = (colorA & color) | (~colorA & colorB);
WriteColor(dstp, hdcDest->format, color);
dstColor = (colorA & color) | (~colorA & colorB);
WriteColor(dstp, hdcDest->format, dstColor);
}
}
}
@ -799,9 +799,7 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
hdcSrc, nXSrc, nYSrc, palette);
default:
break;
}
WLog_ERR(TAG, "BitBlt: unknown rop: 0x%08X", rop);
return FALSE;
}
}

View File

@ -563,7 +563,7 @@ static BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
UINT32 nWidth, UINT32 nHeight)
{
UINT32 x, y;
UINT32 color = GetColor(hdcDest->format, 0, 0, 0, 0);
UINT32 color = GetColor(hdcDest->format, 0xFF, 0xFF, 0xFF, 0xFF);
for (y = 0; y < nHeight; y++)
{

View File

@ -308,7 +308,7 @@ static const DWORD rop3_code_table[] =
};
/* Hatch Patterns as monochrome data */
static BYTE GDI_BS_HATCHED_PATTERNS[] =
static const BYTE GDI_BS_HATCHED_PATTERNS[] =
{
0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* HS_HORIZONTAL */
0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_VERTICAL */
@ -319,7 +319,6 @@ static BYTE GDI_BS_HATCHED_PATTERNS[] =
};
/* GDI Helper Functions */
INLINE DWORD gdi_rop3_code(BYTE code)
{
return rop3_code_table[code];
@ -487,6 +486,7 @@ static BOOL gdi_bitmap_update(rdpContext* context,
FREERDP_CODEC_INTERLEAVED,
gdi->width, gdi->height))
return FALSE;
status = interleaved_decompress(codecs->interleaved,
pSrcData, SrcSize,
bitsPerPixel,
@ -502,6 +502,7 @@ static BOOL gdi_bitmap_update(rdpContext* context,
FREERDP_CODEC_PLANAR,
gdi->width, gdi->height))
return FALSE;
status = planar_decompress(codecs->planar, pSrcData,
SrcSize, gdi->primary_buffer,
gdi->dstFormat,
@ -542,14 +543,13 @@ static BOOL gdi_bitmap_update(rdpContext* context,
static BOOL gdi_palette_update(rdpContext* context,
const PALETTE_UPDATE* palette)
{
int index;
const PALETTE_ENTRY* pe;
UINT32 index;
rdpGdi* gdi = context->gdi;
gdi->palette.format = gdi->dstFormat;
for (index = 0; index < (int) palette->number; index++)
for (index = 0; index < palette->number; index++)
{
pe = &(palette->entries[index]);
const PALETTE_ENTRY* pe = &(palette->entries[index]);
gdi->palette.palette[index] =
GetColor(gdi->dstFormat, pe->red, pe->green, pe->blue, 0xFF);
}
@ -567,9 +567,7 @@ static BOOL gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
bounds->right - bounds->left + 1, bounds->bottom - bounds->top + 1);
}
else
{
gdi_SetNullClipRgn(gdi->drawing->hdc);
}
return TRUE;
}
@ -584,7 +582,6 @@ static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
BYTE* data;
const rdpBrush* brush = &patblt->brush;
UINT32 foreColor;
UINT32 backColor;
@ -602,8 +599,9 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
gdi->dstFormat, &gdi->palette);
originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
if (brush->style == GDI_BS_SOLID)
switch (brush->style)
{
case GDI_BS_SOLID:
originalBrush = gdi->drawing->hdc->brush;
gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);
@ -622,12 +620,14 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
gdi->drawing->hdc->brush = originalBrush;
}
else if (brush->style == GDI_BS_HATCHED)
break;
case GDI_BS_HATCHED:
{
BYTE* hatched;
const BYTE* hatched;
HGDI_BITMAP hBmp;
data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16);
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat),
16);
if (!data)
{
@ -652,7 +652,6 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
if (!gdi->drawing->hdc->brush)
{
_aligned_free(data);
ret = FALSE;
goto out_error;
}
@ -670,15 +669,14 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
gdi->drawing->hdc->brush = originalBrush;
}
else if (brush->style == GDI_BS_PATTERN)
break;
case GDI_BS_PATTERN:
{
HGDI_BITMAP hBmp;
UINT32 brushFormat;
if (brush->bpp > 1)
{
brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);
data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16);
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat),
16);
if (!data)
{
@ -686,26 +684,28 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
goto out_error;
}
if (brush->bpp > 1)
{
brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);
if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0,
8, 8, brush->data, brushFormat, 0, 0, 0,
&gdi->palette))
{
_aligned_free(data);
ret = FALSE;
goto out_error;
}
}
else
{
data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16);
if (!data)
if (!freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
brush->data, backColor, foreColor, &gdi->palette))
{
_aligned_free(data);
ret = FALSE;
goto out_error;
}
freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
brush->data, backColor, foreColor, &gdi->palette);
}
hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
@ -740,9 +740,11 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
gdi->drawing->hdc->brush = originalBrush;
}
else
{
break;
default:
WLog_ERR(TAG, "unimplemented brush style:%d", brush->style);
break;
}
out_error:
@ -871,9 +873,8 @@ static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
static BOOL gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
{
gdiBitmap* bitmap;
gdiBitmap* bitmap = (gdiBitmap*) memblt->bitmap;
rdpGdi* gdi = context->gdi;
bitmap = (gdiBitmap*) memblt->bitmap;
return gdi_BitBlt(gdi->drawing->hdc, memblt->nLeftRect, memblt->nTopRect,
memblt->nWidth, memblt->nHeight, bitmap->hdc,
memblt->nXSrc, memblt->nYSrc, gdi_rop3_code(memblt->bRop),
@ -882,26 +883,22 @@ static BOOL gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{
BYTE* data;
const rdpBrush* brush;
UINT32 foreColor;
UINT32 backColor;
gdiBitmap* bitmap;
UINT32 originalColor;
HGDI_BRUSH originalBrush;
rdpGdi* gdi = context->gdi;
BOOL ret = TRUE;
UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
brush = &mem3blt->brush;
bitmap = (gdiBitmap*) mem3blt->bitmap;
foreColor = ConvertColor(mem3blt->foreColor, SrcFormat,
const UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth,
FALSE);
const rdpBrush* brush = &mem3blt->brush;
gdiBitmap* bitmap = (gdiBitmap*) mem3blt->bitmap;
const UINT32 foreColor = ConvertColor(mem3blt->foreColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
backColor = ConvertColor(mem3blt->backColor, SrcFormat,
const UINT32 backColor = ConvertColor(mem3blt->backColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
const UINT32 originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
if (brush->style == GDI_BS_SOLID)
switch (brush->style)
{
case GDI_BS_SOLID:
originalBrush = gdi->drawing->hdc->brush;
gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);
@ -911,22 +908,20 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
goto out_fail;
}
gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop),
&gdi->palette);
gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
gdi->drawing->hdc->brush = originalBrush;
}
else if (brush->style == GDI_BS_PATTERN)
break;
case GDI_BS_PATTERN:
{
HGDI_BITMAP hBmp;
UINT32 brushFormat;
if (brush->bpp > 1)
{
brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);
data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16);
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat),
16);
if (!data)
{
@ -934,33 +929,37 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
goto out_fail;
}
if (brush->bpp > 1)
{
brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);
if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0,
8, 8, brush->data, brushFormat, 0, 0, 0, &gdi->palette))
8, 8, brush->data, brushFormat,
0, 0, 0, &gdi->palette))
{
ret = FALSE;
_aligned_free(data);
goto out_fail;
}
}
else
{
data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), 16);
if (!data)
if (!freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
brush->data, backColor, foreColor,
&gdi->palette))
{
ret = FALSE;
_aligned_free(data);
goto out_fail;
}
freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
brush->data, backColor, foreColor, &gdi->palette);
}
hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
if (!hBmp)
{
_aligned_free(data);
ret = FALSE;
_aligned_free(data);
goto out_fail;
}
@ -975,16 +974,18 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
gdi->drawing->hdc->brush->nXOrg = brush->x;
gdi->drawing->hdc->brush->nYOrg = brush->y;
gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop),
&gdi->palette);
gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
gdi->drawing->hdc->brush = originalBrush;
}
else
{
break;
default:
WLog_ERR(TAG, "Mem3Blt unimplemented brush style:%d", brush->style);
break;
}
out_fail:
@ -1309,6 +1310,7 @@ void gdi_free(freerdp* instance)
return;
gdi = instance->context->gdi;
if (gdi)
{
gdi_bitmap_free_ex(gdi->primary);
@ -1317,6 +1319,7 @@ void gdi_free(freerdp* instance)
}
context = instance->context;
if (context->cache)
{
cache_free(context->cache);

View File

@ -84,7 +84,6 @@ static BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
else
{
UINT32 format = bitmap->format;
gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width,
bitmap->height,
format, bitmap->data);
@ -115,10 +114,9 @@ static void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
static BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
{
int width, height;
gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;
width = bitmap->right - bitmap->left + 1;
height = bitmap->bottom - bitmap->top + 1;
UINT32 width = bitmap->right - bitmap->left + 1;
UINT32 height = bitmap->bottom - bitmap->top + 1;
return gdi_BitBlt(context->gdi->primary->hdc,
bitmap->left, bitmap->top,
width, height, gdi_bitmap->hdc,
@ -153,6 +151,7 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
FREERDP_CODEC_INTERLEAVED,
gdi->width, gdi->height))
return FALSE;
status = interleaved_decompress(context->codecs->interleaved,
pSrcData, SrcSize,
bpp,
@ -166,6 +165,7 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
FREERDP_CODEC_PLANAR,
gdi->width, gdi->height))
return FALSE;
status = planar_decompress(context->codecs->planar, pSrcData, SrcSize,
pDstData, gdi->dstFormat, 0, 0, 0,
width, height, TRUE);