From d1a3362a8f476a06196ad94c9943db5b606f7dbf Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Aug 2016 11:20:57 +0200 Subject: [PATCH] Fixed windows software GDI issues. --- client/Windows/wf_client.c | 16 ++++--- client/Windows/wf_graphics.c | 101 +++++++++++++++++++++++++++---------------- libfreerdp/gdi/gdi.c | 6 +-- 3 files changed, 76 insertions(+), 47 deletions(-) diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index d6fc5d5..168e2b7 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -197,7 +197,7 @@ static BOOL wf_hw_desktop_resize(rdpContext* context) wfc->primary = wf_image_new(wfc, settings->DesktopWidth, settings->DesktopHeight, format, NULL); if (same) - wfc->drawing = wfc->primary; + wfc->drawing = wfc->primary; } if (wfc->fullscreen != TRUE) @@ -364,7 +364,7 @@ static BOOL wf_post_connect(freerdp* instance) cache = instance->context->cache; UINT32 format = gdi_get_pixel_format(settings->ColorDepth, FALSE); - wfc->format = PIXEL_FORMAT_RGBX32; + wfc->format = PIXEL_FORMAT_BGRX32; wfc->primary = wf_image_new(wfc,settings->DesktopWidth, settings->DesktopHeight, format, NULL); if (!gdi_init_ex(instance, wfc->format, 0, wfc->primary->pdata, wf_image_free)) @@ -373,7 +373,7 @@ static BOOL wf_post_connect(freerdp* instance) gdi = instance->context->gdi; if (!settings->SoftwareGdi) { - UINT32 format = gdi_get_pixel_format(settings->ColorDepth, FALSE); + UINT32 format = gdi_get_pixel_format(settings->ColorDepth, FALSE); wf_gdi_register_update_callbacks(instance->update); wfc->primary = wf_image_new(wfc, settings->DesktopWidth, settings->DesktopHeight, format, NULL); } @@ -436,10 +436,14 @@ static BOOL wf_post_connect(freerdp* instance) if (!settings->SoftwareGdi) { - brush_cache_register_callbacks(instance->update); - bitmap_cache_register_callbacks(instance->update); - offscreen_cache_register_callbacks(instance->update); wf_register_graphics(context->graphics); + + wf_gdi_register_update_callbacks(instance->update); + brush_cache_register_callbacks(instance->update); + glyph_cache_register_callbacks(instance->update); + bitmap_cache_register_callbacks(instance->update); + offscreen_cache_register_callbacks(instance->update); + palette_cache_register_callbacks(instance->update); } if (freerdp_channels_post_connect(context->channels, instance) != CHANNEL_RC_OK) diff --git a/client/Windows/wf_graphics.c b/client/Windows/wf_graphics.c index 683aabc..f4ddbb5 100644 --- a/client/Windows/wf_graphics.c +++ b/client/Windows/wf_graphics.c @@ -160,13 +160,45 @@ static BOOL wf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) return rc; } +static BOOL wf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, + BOOL primary) +{ + wfContext* wfc = (wfContext*)context; + wfBitmap* bmp = (wfBitmap*) bitmap; + rdpGdi* gdi = context->gdi; + + if (!gdi || !wfc) + return FALSE; + + if (primary) + wfc->drawing = wfc->primary; + else if (!bmp) + return FALSE; + else + wfc->drawing = bmp; + + return TRUE; +} + /* Pointer Class */ +static BOOL flip_bitmap(const BYTE* src, BYTE* dst, UINT32 scanline, UINT32 nHeight) +{ + UINT32 x; + BYTE* bottomLine = dst + scanline * (nHeight - 1); + + for (x=0; xxPos; info.yHotspot = pointer->yPos; - data = _aligned_malloc(GetBytesPerPixel(gdi->dstFormat) * pointer->width * pointer->height, 16); - if (!data) - return FALSE; - - if (!freerdp_image_copy_from_pointer_data(data, gdi->dstFormat, - 0, 0, 0, pointer->width, pointer->height, - pointer->xorMaskData, pointer->lengthXorMask, - pointer->andMaskData, pointer->lengthAndMask, - pointer->xorBpp, &context->gdi->palette)) + if (pointer->xorBpp == 1) { - _aligned_free(data); - return FALSE; + BYTE* pdata = (BYTE*) _aligned_malloc(pointer->lengthAndMask + pointer->lengthXorMask, 16); + CopyMemory(pdata, pointer->andMaskData, pointer->lengthAndMask); + CopyMemory(pdata + pointer->lengthAndMask, pointer->xorMaskData, pointer->lengthXorMask); + info.hbmMask = CreateBitmap(pointer->width, pointer->height * 2, 1, 1, pdata); + _aligned_free(pdata); + info.hbmColor = NULL; + } + else + { + BYTE* pdata = (BYTE*) _aligned_malloc(pointer->lengthAndMask, 16); + flip_bitmap(pointer->andMaskData, pdata, (pointer->width + 7) / 8, pointer->height); + info.hbmMask = CreateBitmap(pointer->width, pointer->height, 1, 1, pdata); + _aligned_free(pdata); + + pdata = (BYTE*) _aligned_malloc(pointer->lengthXorMask, 16); + flip_bitmap(pointer->xorMaskData, pdata, (pointer->width + 7) / 8, pointer->height); + info.hbmColor = CreateBitmap(pointer->width, pointer->height, 1, pointer->xorBpp, pdata); + _aligned_free(pdata); } - - if (pointer->xorBpp == 1) - { - data = (BYTE*) malloc(pointer->lengthAndMask + pointer->lengthXorMask); - CopyMemory(data, pointer->andMaskData, pointer->lengthAndMask); - CopyMemory(data + pointer->lengthAndMask, pointer->xorMaskData, pointer->lengthXorMask); - info.hbmMask = CreateBitmap(pointer->width, pointer->height * 2, 1, 1, data); - free(data); - info.hbmColor = NULL; - } - else - { - data = (BYTE*) malloc(pointer->lengthAndMask); -// freerdp_bitmap_flip(pointer->andMaskData, data, (pointer->width + 7) / 8, pointer->height); - info.hbmMask = CreateBitmap(pointer->width, pointer->height, 1, 1, data); - free(data); - data = (BYTE*) malloc(pointer->lengthXorMask); -// freerdp_image_flip(pointer->xorMaskData, data, pointer->width, pointer->height, pointer->xorBpp); - info.hbmColor = CreateBitmap(pointer->width, pointer->height, 1, pointer->xorBpp, data); - free(data); - } hCur = CreateIconIndirect(&info); - ((wfPointer*) pointer)->cursor = hCur; + ((wfPointer*) pointer)->cursor = hCur; - _aligned_free(data); if (info.hbmMask) DeleteObject(info.hbmMask); if (info.hbmColor) @@ -300,19 +318,26 @@ BOOL wf_register_pointer(rdpGraphics* graphics) BOOL wf_register_graphics(rdpGraphics* graphics) { wfContext* wfc; + rdpGlyph glyph; rdpBitmap bitmap; + if (!graphics) return FALSE; wfc = (wfContext*) graphics->context; - ZeroMemory(&bitmap, sizeof(rdpBitmap)); + bitmap = *graphics->Bitmap_Prototype; bitmap.size = sizeof(wfBitmap); bitmap.New = wf_Bitmap_New; bitmap.Free = wf_Bitmap_Free; bitmap.Paint = wf_Bitmap_Paint; + bitmap.SetSurface = wf_Bitmap_SetSurface; + + graphics_register_bitmap(graphics, &bitmap); + + glyph = *graphics->Glyph_Prototype; - graphics_register_bitmap(graphics, &bitmap); + graphics_register_glyph(graphics, &glyph); return TRUE; } diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 2173eee..5e91153 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -328,7 +328,7 @@ INLINE BOOL gdi_decode_color(rdpGdi* gdi, const UINT32 srcColor, *format = SrcFormat; *color = ConvertColor(srcColor, SrcFormat, - gdi->drawing->hdc->format, &gdi->palette); + gdi->dstFormat, &gdi->palette); return TRUE; } @@ -1194,11 +1194,11 @@ static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, gdi->hdc, gdi->width, gdi->height); } else - { + { gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstFormat, gdi->stride, - gdi->primary_buffer, pfree); + buffer, pfree); } gdi->stride = gdi->primary->bitmap->scanline; -- 2.7.4