Bug fixes, refactoring.

This commit is contained in:
Armin Novak 2016-07-15 16:23:00 +02:00
parent 960bc26e9a
commit f9a89ae6b4
9 changed files with 612 additions and 565 deletions

View File

@ -43,10 +43,6 @@ struct rdp_cache
rdpOffscreenCache* offscreen; /* 4 */
rdpPaletteCache* palette; /* 5 */
rdpNineGridCache* nine_grid; /* 6 */
/* internal */
rdpSettings* settings;
};
#ifdef __cplusplus

View File

@ -526,23 +526,27 @@ static INLINE void SplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g,
tmp = palette->palette[color];
SplitColor(tmp, palette->format, _r, _g, _b, _a, NULL);
}
break;
/* 1bpp formats */
case PIXEL_FORMAT_MONO:
if (_r)
*_r = (color) ? 0xFF : 0x00;
if (_g)
*_g = (color) ? 0xFF : 0x00;
if (_b)
*_b = (color) ? 0xFF : 0x00;
if (_a)
*_a = (color) ? 0xFF : 0x00;
break;
/* 4 bpp formats */
case PIXEL_FORMAT_A4:
default:
WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format));
break;

View File

@ -30,50 +30,49 @@
rdpCache* cache_new(rdpSettings* settings)
{
rdpCache* cache;
cache = (rdpCache*) calloc(1, sizeof(rdpCache));
if (!cache)
return NULL;
cache->settings = settings;
cache->glyph = glyph_cache_new(settings);
if (!cache->glyph)
goto error_glyph;
goto error;
cache->brush = brush_cache_new(settings);
if (!cache->brush)
goto error_brush;
goto error;
cache->pointer = pointer_cache_new(settings);
if (!cache->pointer)
goto error_pointer;
goto error;
cache->bitmap = bitmap_cache_new(settings);
if (!cache->bitmap)
goto error_bitmap;
goto error;
cache->offscreen = offscreen_cache_new(settings);
if (!cache->offscreen)
goto error_offscreen;
goto error;
cache->palette = palette_cache_new(settings);
if (!cache->palette)
goto error_palette;
goto error;
cache->nine_grid = nine_grid_cache_new(settings);
if (!cache->nine_grid)
goto error_ninegrid;
goto error;
return cache;
error_ninegrid:
palette_cache_free(cache->palette);
error_palette:
offscreen_cache_free(cache->offscreen);
error_offscreen:
bitmap_cache_free(cache->bitmap);
error_bitmap:
pointer_cache_free(cache->pointer);
error_pointer:
brush_cache_free(cache->brush);
error_brush:
glyph_cache_free(cache->glyph);
error_glyph:
free(cache);
error:
cache_free(cache);
return NULL;
}

View File

@ -32,18 +32,19 @@
#define TAG FREERDP_TAG("cache.offscreen")
static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, UINT32 index, rdpBitmap* bitmap);
static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache,
UINT32 index, rdpBitmap* bitmap);
static void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index);
static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context,
const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap)
{
int i;
UINT32 i;
UINT16 index;
rdpBitmap* bitmap;
rdpCache* cache = context->cache;
bitmap = Bitmap_Alloc(context);
if (!bitmap)
return FALSE;
@ -59,14 +60,15 @@ static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context,
offscreen_cache_delete(cache->offscreen, createOffscreenBitmap->id);
offscreen_cache_put(cache->offscreen, createOffscreenBitmap->id, bitmap);
if(cache->offscreen->currentSurface == createOffscreenBitmap->id)
if (cache->offscreen->currentSurface == createOffscreenBitmap->id)
Bitmap_SetSurface(context, bitmap, FALSE);
for (i = 0; i < (int) createOffscreenBitmap->deleteList.cIndices; i++)
for (i = 0; i < createOffscreenBitmap->deleteList.cIndices; i++)
{
index = createOffscreenBitmap->deleteList.indices[i];
offscreen_cache_delete(cache->offscreen, index);
}
return TRUE;
}
@ -111,7 +113,8 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index)
return bitmap;
}
void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap)
void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index,
rdpBitmap* bitmap)
{
if (index >= offscreenCache->maxEntries)
{
@ -150,7 +153,6 @@ void offscreen_cache_register_callbacks(rdpUpdate* update)
rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings)
{
rdpOffscreenCache* offscreenCache;
offscreenCache = (rdpOffscreenCache*) calloc(1, sizeof(rdpOffscreenCache));
if (!offscreenCache)
@ -158,20 +160,20 @@ rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings)
offscreenCache->settings = settings;
offscreenCache->update = ((freerdp*) settings->instance)->update;
offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE;
offscreenCache->maxSize = 7680;
offscreenCache->maxEntries = 2000;
settings->OffscreenCacheSize = offscreenCache->maxSize;
settings->OffscreenCacheEntries = offscreenCache->maxEntries;
offscreenCache->entries = (rdpBitmap**) calloc(offscreenCache->maxEntries,
sizeof(rdpBitmap*));
offscreenCache->entries = (rdpBitmap**) calloc(offscreenCache->maxEntries, sizeof(rdpBitmap*));
if (!offscreenCache->entries)
{
free(offscreenCache);
return NULL;
}
return offscreenCache;
}

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,6 @@ set(${MODULE_PREFIX}_SRCS
freerdp_module_add(${${MODULE_PREFIX}_SRCS})
if(BUILD_TESTING)
# add_subdirectory(test)
add_subdirectory(test)
endif()

View File

@ -585,9 +585,10 @@ static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
UINT32 color;
UINT32 colorA = ReadColor(srcp, hdcSrc->format);
UINT32 colorB = ReadColor(patp, hdcDest->format);
colorA = ConvertColor(colorA, hdcSrc->format,
hdcDest->format, palette);
colorB = ConvertColor(colorB, hdcDest->format,
hdcSrc->format, palette);
color = colorA & ~colorB;
color = ConvertColor(color, hdcSrc->format, hdcDest->format, palette);
WriteColor(dstp, hdcDest->format, color);
}
}
@ -740,6 +741,8 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight))
return FALSE;
WLog_DBG(TAG, "%s [%s]", __FUNCTION__, gdi_rop_to_string(rop));
switch (rop)
{
case GDI_SRCCOPY:

View File

@ -584,9 +584,9 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
UINT32 nXSrc = 0;
UINT32 nYSrc = 0;
foreColor = ConvertColor(patblt->foreColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
backColor = ConvertColor(patblt->backColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
switch (brush->style)
@ -616,7 +616,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
const BYTE* hatched;
HGDI_BITMAP hBmp;
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat),
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(
gdi->drawing->hdc->format),
16);
if (!data)
@ -626,7 +627,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
}
hatched = GDI_BS_HATCHED_PATTERNS + (8 * brush->hatch);
freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8,
8,
hatched, backColor, foreColor, &gdi->palette);
hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
@ -665,7 +667,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
HGDI_BITMAP hBmp;
UINT32 brushFormat;
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat),
BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(
gdi->drawing->hdc->format),
16);
if (!data)
@ -678,7 +681,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);
if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0,
if (!freerdp_image_copy(data, gdi->drawing->hdc->format, 0, 0, 0,
8, 8, brush->data, brushFormat, 0, 0, 0,
&gdi->palette))
{
@ -689,7 +692,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
}
else
{
if (!freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0,
0, 8, 8,
brush->data, backColor, foreColor, &gdi->palette))
{
_aligned_free(data);
@ -762,8 +766,8 @@ static BOOL gdi_opaque_rect(rdpContext* context,
UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect,
opaque_rect->nWidth, opaque_rect->nHeight, &rect);
brush_color = ConvertColor(opaque_rect->color, SrcFormat,
gdi->dstFormat, &gdi->palette);
brush_color = ConvertColor(opaque_rect->color, PIXEL_FORMAT_RGB16,
gdi->drawing->hdc->format, &gdi->palette);
if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
return FALSE;
@ -791,7 +795,7 @@ static BOOL gdi_multi_opaque_rect(rdpContext* context,
gdi_CRgnToRect(rectangle->left, rectangle->top,
rectangle->width, rectangle->height, &rect);
brush_color = ConvertColor(multi_opaque_rect->color, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
hBrush = gdi_CreateSolidBrush(brush_color);
if (!hBrush)
@ -881,9 +885,9 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
const rdpBrush* brush = &mem3blt->brush;
gdiBitmap* bitmap = (gdiBitmap*) mem3blt->bitmap;
const UINT32 foreColor = ConvertColor(mem3blt->foreColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
const UINT32 backColor = ConvertColor(mem3blt->backColor, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
const UINT32 originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
switch (brush->style)
@ -1263,11 +1267,8 @@ BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
if (!gdi_init_primary(gdi, stride, buffer, pfree))
goto fail;
if (!context->cache)
{
if (!(context->cache = cache_new(instance->settings)))
goto fail;
}
if (!freerdp_client_codecs_prepare(context->codecs, FREERDP_CODEC_ALL,
gdi->width, gdi->height))
@ -1309,13 +1310,8 @@ void gdi_free(freerdp* instance)
}
context = instance->context;
if (context->cache)
{
cache_free(context->cache);
context->cache = NULL;
}
instance->context->gdi = (rdpGdi*) NULL;
}

View File

@ -124,24 +124,26 @@ static BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
}
static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
const BYTE* data, UINT32 width, UINT32 height,
const BYTE* pSrcData, UINT32 width, UINT32 height,
UINT32 bpp, UINT32 length, BOOL compressed,
UINT32 codecId)
{
int status;
UINT16 size;
const BYTE* pSrcData;
BYTE* pDstData;
UINT32 SrcSize;
UINT32 SrcSize = length;
UINT32 SrcFormat;
UINT32 bytesPerPixel;
rdpGdi* gdi = context->gdi;
bytesPerPixel = (bpp + 7) / 8;
size = width * height * 4;
bitmap->data = (BYTE*) _aligned_malloc(size, 16);
pSrcData = data;
SrcSize = (UINT32) length;
pDstData = bitmap->data;
if (!bitmap->data)
return FALSE;
bitmap->compressed = FALSE;
bitmap->length = size;
bitmap->format = gdi->dstFormat;
if (compressed)
{
@ -150,14 +152,14 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
status = interleaved_decompress(context->codecs->interleaved,
pSrcData, SrcSize,
bpp,
pDstData, gdi->dstFormat,
bitmap->data, bitmap->format,
0, 0, 0, width, height,
&gdi->palette);
}
else
{
status = planar_decompress(context->codecs->planar, pSrcData, SrcSize,
pDstData, gdi->dstFormat, 0, 0, 0,
bitmap->data, bitmap->format, 0, 0, 0,
width, height, TRUE);
}
@ -170,14 +172,11 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
else
{
SrcFormat = gdi_get_pixel_format(bpp, FALSE);
status = freerdp_image_copy(pDstData, gdi->dstFormat, 0, 0, 0,
status = freerdp_image_copy(bitmap->data, bitmap->format, 0, 0, 0,
width, height, pSrcData, SrcFormat,
0, 0, 0, &gdi->palette);
}
bitmap->compressed = FALSE;
bitmap->length = size;
bitmap->format = gdi->dstFormat;
return TRUE;
}
@ -264,8 +263,10 @@ static BOOL gdi_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
BOOL ret = FALSE;
UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
/* TODO: handle fOpRedundant! See xf_Glyph_BeginDraw() */
bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->dstFormat, &gdi->palette);
fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->dstFormat, &gdi->palette);
bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->drawing->hdc->format,
&gdi->palette);
fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->drawing->hdc->format,
&gdi->palette);
if (!(brush = gdi_CreateSolidBrush(fgcolor)))
goto out;
@ -284,7 +285,7 @@ static BOOL gdi_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y,
rdpGdi* gdi = context->gdi;
UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
bgcolor = ConvertColor(bgcolor, SrcFormat,
gdi->dstFormat, &gdi->palette);
gdi->drawing->hdc->format, &gdi->palette);
gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
return TRUE;
}