From 95a3144b34d848171e9742f53d7cd38476c76998 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 31 Oct 2016 07:56:10 +0100 Subject: [PATCH] Scanline alignment for GFX cache. --- libfreerdp/gdi/gfx.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 94b78e0ea..65d913eb9 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -29,6 +29,18 @@ #define TAG FREERDP_TAG("gdi") +static DWORD gfx_align_scanline(DWORD widthInBytes, DWORD alignment) +{ + const UINT32 align = 16; + const UINT32 pad = align - (widthInBytes % alignment); + UINT32 scanline = widthInBytes; + + if (align != pad) + scanline += pad; + + return scanline; +} + /** * Function description * @@ -698,16 +710,8 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context, return ERROR_INTERNAL_ERROR; } - surface->scanline = surface->width * 4; - { - const UINT32 align = 16; - const UINT32 pad = align - (surface->scanline % align); - - if (align != pad) - surface->scanline += pad; - - surface->data = (BYTE*) calloc(1, surface->scanline * surface->height); - } + surface->scanline = gfx_align_scanline(surface->width * 4, 16); + surface->data = (BYTE*) calloc(1, surface->scanline * surface->height); if (!surface->data) { @@ -895,7 +899,7 @@ static UINT gdi_SurfaceToCache(RdpgfxClientContext* context, cacheEntry->width = (UINT32)(rect->right - rect->left); cacheEntry->height = (UINT32)(rect->bottom - rect->top); cacheEntry->format = surface->format; - cacheEntry->scanline = (cacheEntry->width + (cacheEntry->width % 4)) * 4; + cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16); cacheEntry->data = (BYTE*) calloc(1, cacheEntry->scanline * cacheEntry->height); if (!cacheEntry->data)