FreeRDP/client/Windows/wf_gdi.c

849 lines
22 KiB
C
Raw Normal View History

/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* Windows GDI
*
* Copyright 2009-2011 Jay Sorg
* Copyright 2010-2011 Vic Lee
* Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-02-16 13:20:38 +03:00
#include <freerdp/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
2014-09-12 19:13:01 +04:00
#include <freerdp/log.h>
#include <freerdp/gdi/gdi.h>
2011-11-12 11:35:18 +04:00
#include <freerdp/constants.h>
#include <freerdp/codec/color.h>
2011-10-05 00:05:09 +04:00
#include <freerdp/codec/bitmap.h>
2011-11-12 11:35:18 +04:00
#include <freerdp/codec/rfx.h>
#include <freerdp/codec/nsc.h>
2016-07-21 16:36:15 +03:00
#include <freerdp/gdi/gdi.h>
#include "wf_client.h"
2011-10-22 00:45:35 +04:00
#include "wf_graphics.h"
#include "wf_gdi.h"
2014-09-12 19:13:01 +04:00
#define TAG CLIENT_TAG("windows.gdi")
2019-11-06 17:24:51 +03:00
static const BYTE wf_rop2_table[] = {
2011-10-05 00:05:09 +04:00
R2_BLACK, /* 0 */
R2_NOTMERGEPEN, /* DPon */
R2_MASKNOTPEN, /* DPna */
R2_NOTCOPYPEN, /* Pn */
R2_MASKPENNOT, /* PDna */
R2_NOT, /* Dn */
R2_XORPEN, /* DPx */
R2_NOTMASKPEN, /* DPan */
R2_MASKPEN, /* DPa */
R2_NOTXORPEN, /* DPxn */
R2_NOP, /* D */
R2_MERGENOTPEN, /* DPno */
R2_COPYPEN, /* P */
R2_MERGEPENNOT, /* PDno */
R2_MERGEPEN, /* PDo */
R2_WHITE, /* 1 */
};
2019-11-06 17:24:51 +03:00
static BOOL wf_decode_color(wfContext* wfc, const UINT32 srcColor, COLORREF* color, UINT32* format)
2016-08-03 13:37:40 +03:00
{
2016-08-08 16:15:55 +03:00
rdpGdi* gdi;
rdpSettings* settings;
UINT32 SrcFormat, DstFormat;
if (!wfc)
return FALSE;
gdi = wfc->common.context.gdi;
settings = wfc->common.context.settings;
2016-08-08 16:15:55 +03:00
if (!gdi || !settings)
return FALSE;
SrcFormat = gdi_get_pixel_format(freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
2016-08-08 16:15:55 +03:00
if (format)
*format = SrcFormat;
switch (FreeRDPGetBitsPerPixel(gdi->dstFormat))
2016-08-08 16:15:55 +03:00
{
2016-08-10 14:33:34 +03:00
case 32:
DstFormat = PIXEL_FORMAT_ABGR32;
break;
case 24:
DstFormat = PIXEL_FORMAT_BGR24;
break;
case 16:
DstFormat = PIXEL_FORMAT_RGB16;
break;
default:
return FALSE;
2016-08-08 16:15:55 +03:00
}
2019-11-06 17:24:51 +03:00
*color = FreeRDPConvertColor(srcColor, SrcFormat, DstFormat, &gdi->palette);
2016-08-08 16:15:55 +03:00
return TRUE;
2016-08-03 13:37:40 +03:00
}
static BOOL wf_set_rop2(HDC hdc, int rop2)
2011-10-05 00:05:09 +04:00
{
if ((rop2 < 0x01) || (rop2 > 0x10))
{
2019-11-06 17:24:51 +03:00
WLog_ERR(TAG, "Unsupported ROP2: %d", rop2);
return FALSE;
2011-10-05 00:05:09 +04:00
}
SetROP2(hdc, wf_rop2_table[rop2 - 1]);
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-08-03 13:37:40 +03:00
static wfBitmap* wf_glyph_new(wfContext* wfc, GLYPH_DATA* glyph)
2011-10-05 00:05:09 +04:00
{
wfBitmap* glyph_bmp;
2019-11-06 17:24:51 +03:00
glyph_bmp = wf_image_new(wfc, glyph->cx, glyph->cy, PIXEL_FORMAT_MONO, glyph->aj);
2011-10-05 00:05:09 +04:00
return glyph_bmp;
}
2016-08-03 13:37:40 +03:00
static void wf_glyph_free(wfBitmap* glyph)
2011-10-05 00:05:09 +04:00
{
wf_image_free(glyph);
}
static BYTE* wf_glyph_convert(wfContext* wfc, int width, int height, const BYTE* data)
{
const int src_bytes_per_row = (width + 7) / 8;
const int dst_bytes_per_row = src_bytes_per_row + (src_bytes_per_row % 2);
BYTE* cdata = (BYTE*)malloc(dst_bytes_per_row * height);
const BYTE* src = data;
for (int indexy = 0; indexy < height; indexy++)
{
BYTE* dst = &cdata[1ull * indexy * dst_bytes_per_row];
for (int indexx = 0; indexx < dst_bytes_per_row; indexx++)
{
if (indexx < src_bytes_per_row)
*dst++ = *src++;
else
*dst++ = 0;
}
}
return cdata;
}
2019-11-06 17:24:51 +03:00
static HBRUSH wf_create_brush(wfContext* wfc, rdpBrush* brush, UINT32 color, UINT32 bpp)
{
HBRUSH br;
LOGBRUSH lbr;
BYTE* cdata;
BYTE ipattern[8];
HBITMAP pattern = NULL;
lbr.lbStyle = brush->style;
2019-11-06 17:24:51 +03:00
if (lbr.lbStyle == BS_DIBPATTERN || lbr.lbStyle == BS_DIBPATTERN8X8 ||
lbr.lbStyle == BS_DIBPATTERNPT)
lbr.lbColor = DIB_RGB_COLORS;
else
lbr.lbColor = color;
if (lbr.lbStyle == BS_PATTERN || lbr.lbStyle == BS_PATTERN8X8)
{
if (brush->bpp > 1)
{
UINT32 format = gdi_get_pixel_format(bpp);
2016-08-03 13:09:24 +03:00
pattern = wf_create_dib(wfc, 8, 8, format, brush->data, NULL);
2019-11-06 17:24:51 +03:00
lbr.lbHatch = (ULONG_PTR)pattern;
}
else
{
for (UINT32 i = 0; i != 8; i++)
ipattern[7 - i] = brush->data[i];
2013-06-16 06:57:21 +04:00
cdata = wf_glyph_convert(wfc, 8, 8, ipattern);
pattern = CreateBitmap(8, 8, 1, 1, cdata);
2019-11-06 17:24:51 +03:00
lbr.lbHatch = (ULONG_PTR)pattern;
free(cdata);
}
}
else if (lbr.lbStyle == BS_HATCHED)
{
lbr.lbHatch = brush->hatch;
}
else
{
lbr.lbHatch = 0;
}
br = CreateBrushIndirect(&lbr);
2013-06-16 06:57:21 +04:00
SetBrushOrgEx(wfc->drawing->hdc, brush->x, brush->y, NULL);
if (pattern != NULL)
DeleteObject(pattern);
return br;
}
BOOL wf_scale_rect(wfContext* wfc, RECT* source)
{
2016-08-03 13:09:24 +03:00
UINT32 ww, wh, dw, dh;
rdpSettings* settings;
2016-07-21 16:36:15 +03:00
if (!wfc || !source || !wfc->common.context.settings)
2016-08-03 13:09:24 +03:00
return FALSE;
2016-07-21 16:36:15 +03:00
settings = wfc->common.context.settings;
2016-08-03 13:09:24 +03:00
if (!settings)
return FALSE;
2023-10-13 10:48:44 +03:00
dw = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
dh = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
2013-06-16 06:57:21 +04:00
if (!wfc->client_width)
2016-08-03 13:09:24 +03:00
wfc->client_width = dw;
2013-06-16 06:57:21 +04:00
if (!wfc->client_height)
2016-08-03 13:09:24 +03:00
wfc->client_height = dh;
2013-06-16 06:57:21 +04:00
ww = wfc->client_width;
wh = wfc->client_height;
if (!ww)
ww = dw;
if (!wh)
wh = dh;
2023-10-13 10:48:44 +03:00
if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_SmartSizing) &&
(ww != dw || wh != dh))
{
2013-04-30 20:56:16 +04:00
source->bottom = source->bottom * wh / dh + 20;
source->top = source->top * wh / dh - 20;
source->left = source->left * ww / dw - 20;
source->right = source->right * ww / dw + 20;
}
2013-06-16 06:57:21 +04:00
source->bottom -= wfc->yCurrentScroll;
source->top -= wfc->yCurrentScroll;
source->left -= wfc->xCurrentScroll;
source->right -= wfc->xCurrentScroll;
2016-08-03 13:09:24 +03:00
return TRUE;
}
2019-11-06 17:24:51 +03:00
void wf_invalidate_region(wfContext* wfc, UINT32 x, UINT32 y, UINT32 width, UINT32 height)
2011-10-05 00:05:09 +04:00
{
RECT rect;
rdpGdi* gdi = wfc->common.context.gdi;
2013-06-16 06:57:21 +04:00
wfc->update_rect.left = x + wfc->offset_x;
wfc->update_rect.top = y + wfc->offset_y;
wfc->update_rect.right = wfc->update_rect.left + width;
wfc->update_rect.bottom = wfc->update_rect.top + height;
wf_scale_rect(wfc, &(wfc->update_rect));
InvalidateRect(wfc->hwnd, &(wfc->update_rect), FALSE);
rect.left = x;
rect.right = width;
rect.top = y;
rect.bottom = height;
2013-06-16 06:57:21 +04:00
wf_scale_rect(wfc, &rect);
2019-11-06 17:24:51 +03:00
gdi_InvalidateRegion(gdi->primary->hdc, rect.left, rect.top, rect.right, rect.bottom);
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_update_offset(wfContext* wfc)
{
2016-08-03 13:09:24 +03:00
rdpSettings* settings;
settings = wfc->common.context.settings;
2016-07-21 16:36:15 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2023-10-13 10:48:44 +03:00
if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_UseMultimon))
{
int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
2023-10-13 10:48:44 +03:00
wfc->offset_x = (w - freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)) / 2;
2013-06-16 06:57:21 +04:00
if (wfc->offset_x < x)
wfc->offset_x = x;
2016-08-03 13:09:24 +03:00
2023-10-13 10:48:44 +03:00
wfc->offset_y = (h - freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)) / 2;
2016-08-03 13:09:24 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->offset_y < y)
wfc->offset_y = y;
}
2016-08-03 13:09:24 +03:00
else
{
2023-10-13 10:48:44 +03:00
wfc->offset_x = (GetSystemMetrics(SM_CXSCREEN) -
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth)) /
2;
2016-08-03 13:09:24 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->offset_x < 0)
wfc->offset_x = 0;
2016-08-03 13:09:24 +03:00
2023-10-13 10:48:44 +03:00
wfc->offset_y = (GetSystemMetrics(SM_CYSCREEN) -
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight)) /
2;
2016-08-03 13:09:24 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->offset_y < 0)
wfc->offset_y = 0;
}
}
else
{
2013-06-16 06:57:21 +04:00
wfc->offset_x = 0;
wfc->offset_y = 0;
}
}
2013-06-16 06:57:21 +04:00
void wf_resize_window(wfContext* wfc)
{
2016-08-03 13:09:24 +03:00
rdpSettings* settings;
settings = wfc->common.context.settings;
2016-07-21 16:36:15 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2023-10-13 10:48:44 +03:00
if (freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_UseMultimon))
{
int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
2013-06-16 06:57:21 +04:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_POPUP);
SetWindowPos(wfc->hwnd, HWND_TOP, x, y, w, h, SWP_FRAMECHANGED);
}
else
{
2013-06-16 06:57:21 +04:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_POPUP);
2016-08-03 13:09:24 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN),
2016-08-10 14:33:34 +03:00
GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED);
}
}
2023-10-13 10:48:44 +03:00
else if (!freerdp_settings_get_bool(wfc->common.context.settings, FreeRDP_Decorations))
2016-08-03 13:09:24 +03:00
{
2013-06-16 06:57:21 +04:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_CHILD);
2023-10-13 10:48:44 +03:00
if (freerdp_settings_get_bool(settings, FreeRDP_EmbeddedWindow))
{
if (!wfc->client_height)
2023-10-13 10:48:44 +03:00
wfc->client_height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
if (!wfc->client_width)
2023-10-13 10:48:44 +03:00
wfc->client_width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
wf_update_canvas_diff(wfc);
/* Now resize to get full canvas size and room for caption and borders */
SetWindowPos(wfc->hwnd, HWND_TOP, wfc->client_x, wfc->client_y,
2019-11-06 17:24:51 +03:00
wfc->client_width + wfc->diff.x, wfc->client_height + wfc->diff.y,
0 /*SWP_FRAMECHANGED*/);
}
else
{
/* Now resize to get full canvas size and room for caption and borders */
2023-10-13 10:48:44 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0,
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
2019-11-06 17:24:51 +03:00
SWP_FRAMECHANGED);
wf_update_canvas_diff(wfc);
2023-10-13 10:48:44 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1,
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) + wfc->diff.x,
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) + wfc->diff.y,
SWP_NOMOVE | SWP_FRAMECHANGED);
}
}
else
{
2016-08-03 13:09:24 +03:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE,
2016-08-10 14:33:34 +03:00
WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX |
2019-11-06 17:24:51 +03:00
WS_MAXIMIZEBOX);
2013-06-16 06:57:21 +04:00
if (!wfc->client_height)
2023-10-13 10:48:44 +03:00
wfc->client_height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
2013-06-16 06:57:21 +04:00
if (!wfc->client_width)
2023-10-13 10:48:44 +03:00
wfc->client_width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
2013-06-16 06:57:21 +04:00
if (!wfc->client_x)
wfc->client_x = 10;
2013-06-16 06:57:21 +04:00
if (!wfc->client_y)
wfc->client_y = 10;
2016-08-03 13:09:24 +03:00
wf_update_canvas_diff(wfc);
/* Now resize to get full canvas size and room for caption and borders */
int width, height;
2023-10-13 10:48:44 +03:00
if (freerdp_settings_get_bool(settings, FreeRDP_SmartSizing) &&
freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth) &&
freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight))
{
2023-10-13 10:48:44 +03:00
width = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingWidth);
height = freerdp_settings_get_uint32(settings, FreeRDP_SmartSizingHeight);
}
else
{
width = wfc->client_width + wfc->diff.x;
height = wfc->client_height + wfc->diff.y;
}
int xpos, ypos;
2023-10-13 10:48:44 +03:00
if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX) != UINT32_MAX) &&
(freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY) != UINT32_MAX))
{
2023-10-13 10:48:44 +03:00
xpos = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosX);
ypos = freerdp_settings_get_uint32(settings, FreeRDP_DesktopPosY);
}
else
{
xpos = wfc->client_x;
ypos = wfc->client_y;
}
2022-09-06 19:30:08 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, xpos, ypos, width, height, 0 /*SWP_FRAMECHANGED*/);
2019-11-06 17:24:51 +03:00
// wf_size_scrollbars(wfc, wfc->client_width, wfc->client_height);
}
2016-08-03 13:09:24 +03:00
2013-06-16 06:57:21 +04:00
wf_update_offset(wfc);
}
2013-06-16 06:57:21 +04:00
void wf_toggle_fullscreen(wfContext* wfc)
{
2013-06-16 06:57:21 +04:00
ShowWindow(wfc->hwnd, SW_HIDE);
wfc->fullscreen = !wfc->fullscreen;
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2013-06-16 06:57:21 +04:00
wfc->disablewindowtracking = TRUE;
}
wf_floatbar_toggle_fullscreen(wfc->floatbar, wfc->fullscreen);
2013-06-16 06:57:21 +04:00
SetParent(wfc->hwnd, wfc->fullscreen ? NULL : wfc->hWndParent);
wf_resize_window(wfc);
ShowWindow(wfc->hwnd, SW_SHOW);
SetForegroundWindow(wfc->hwnd);
2013-06-16 06:57:21 +04:00
if (!wfc->fullscreen)
{
2019-11-06 17:24:51 +03:00
// Reenable window tracking AFTER resizing it back, otherwise it can lean to repositioning
// errors.
2013-06-16 06:57:21 +04:00
wfc->disablewindowtracking = FALSE;
}
}
2011-10-05 00:05:09 +04:00
2019-11-06 17:24:51 +03:00
static BOOL wf_gdi_palette_update(rdpContext* context, const PALETTE_UPDATE* palette)
2014-09-12 19:34:30 +04:00
{
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_set_null_clip_rgn(wfContext* wfc)
2011-11-12 11:35:18 +04:00
{
2013-06-16 06:57:21 +04:00
SelectClipRgn(wfc->drawing->hdc, NULL);
2011-11-12 11:35:18 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_set_clip_rgn(wfContext* wfc, int x, int y, int width, int height)
2011-11-12 11:35:18 +04:00
{
HRGN clip;
2011-12-16 23:43:14 +04:00
clip = CreateRectRgn(x, y, x + width, y + height);
2013-06-16 06:57:21 +04:00
SelectClipRgn(wfc->drawing->hdc, clip);
2011-11-12 11:35:18 +04:00
DeleteObject(clip);
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
2011-10-05 00:05:09 +04:00
{
HRGN hrgn;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !bounds)
return FALSE;
2011-10-05 00:05:09 +04:00
if (bounds != NULL)
{
2019-11-06 17:24:51 +03:00
hrgn = CreateRectRgn(bounds->left, bounds->top, bounds->right + 1, bounds->bottom + 1);
2013-06-16 06:57:21 +04:00
SelectClipRgn(wfc->drawing->hdc, hrgn);
2011-10-05 00:05:09 +04:00
DeleteObject(hrgn);
}
else
2013-06-16 06:57:21 +04:00
SelectClipRgn(wfc->drawing->hdc, NULL);
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
2011-10-05 00:05:09 +04:00
{
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !dstblt)
return FALSE;
2016-07-21 16:36:15 +03:00
2019-11-06 17:24:51 +03:00
if (!BitBlt(wfc->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth,
dstblt->nHeight, NULL, 0, 0, gdi_rop3_code(dstblt->bRop)))
2016-08-03 13:09:24 +03:00
return FALSE;
2011-10-05 00:05:09 +04:00
2019-11-06 17:24:51 +03:00
wf_invalidate_region(wfc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight);
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
2011-10-05 00:05:09 +04:00
{
HBRUSH brush;
HBRUSH org_brush;
int org_bkmode;
COLORREF fgcolor;
COLORREF bgcolor;
COLORREF org_bkcolor;
COLORREF org_textcolor;
2016-08-03 13:09:24 +03:00
BOOL rc;
wfContext* wfc = (wfContext*)context;
if (!context || !patblt)
return FALSE;
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, patblt->foreColor, &fgcolor, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, patblt->backColor, &bgcolor, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2016-07-21 16:36:15 +03:00
brush = wf_create_brush(wfc, &patblt->brush, fgcolor,
freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth));
2013-06-16 06:57:21 +04:00
org_bkmode = SetBkMode(wfc->drawing->hdc, OPAQUE);
org_bkcolor = SetBkColor(wfc->drawing->hdc, bgcolor);
org_textcolor = SetTextColor(wfc->drawing->hdc, fgcolor);
org_brush = (HBRUSH)SelectObject(wfc->drawing->hdc, brush);
2019-11-06 17:24:51 +03:00
rc = PatBlt(wfc->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
patblt->nHeight, gdi_rop3_code(patblt->bRop));
2013-06-16 06:57:21 +04:00
SelectObject(wfc->drawing->hdc, org_brush);
DeleteObject(brush);
2013-06-16 06:57:21 +04:00
SetBkMode(wfc->drawing->hdc, org_bkmode);
SetBkColor(wfc->drawing->hdc, org_bkcolor);
SetTextColor(wfc->drawing->hdc, org_textcolor);
2011-10-05 00:05:09 +04:00
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
2016-08-03 13:09:24 +03:00
wf_invalidate_region(wfc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
2016-08-10 14:33:34 +03:00
patblt->nHeight);
2016-08-03 13:09:24 +03:00
return rc;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
2011-10-05 00:05:09 +04:00
{
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !scrblt || !wfc->drawing)
return FALSE;
2016-07-21 16:36:15 +03:00
2019-11-06 17:24:51 +03:00
if (!BitBlt(wfc->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth,
scrblt->nHeight, wfc->primary->hdc, scrblt->nXSrc, scrblt->nYSrc,
gdi_rop3_code(scrblt->bRop)))
2016-08-03 13:09:24 +03:00
return FALSE;
2011-10-05 00:05:09 +04:00
2019-11-06 17:24:51 +03:00
wf_invalidate_region(wfc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight);
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2019-11-06 17:24:51 +03:00
static BOOL wf_gdi_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect)
2011-10-05 00:05:09 +04:00
{
RECT rect;
HBRUSH brush;
COLORREF brush_color;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !opaque_rect)
return FALSE;
2011-10-05 00:05:09 +04:00
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, opaque_rect->color, &brush_color, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2011-10-05 00:05:09 +04:00
rect.left = opaque_rect->nLeftRect;
rect.top = opaque_rect->nTopRect;
rect.right = opaque_rect->nLeftRect + opaque_rect->nWidth;
rect.bottom = opaque_rect->nTopRect + opaque_rect->nHeight;
brush = CreateSolidBrush(brush_color);
2013-06-16 06:57:21 +04:00
FillRect(wfc->drawing->hdc, &rect, brush);
2011-10-05 00:05:09 +04:00
DeleteObject(brush);
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
2016-08-03 13:09:24 +03:00
wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1,
2016-08-10 14:33:34 +03:00
rect.bottom - rect.top + 1);
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-08-03 13:09:24 +03:00
static BOOL wf_gdi_multi_opaque_rect(rdpContext* context,
2016-08-10 14:33:34 +03:00
const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
2011-10-05 00:05:09 +04:00
{
RECT rect;
HBRUSH brush;
COLORREF brush_color;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !multi_opaque_rect)
return FALSE;
2011-10-05 00:05:09 +04:00
2019-11-06 17:24:51 +03:00
if (!wf_decode_color(wfc, multi_opaque_rect->color, &brush_color, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2014-09-12 19:34:30 +04:00
for (UINT32 i = 0; i < multi_opaque_rect->numRectangles; i++)
2011-10-05 00:05:09 +04:00
{
2016-08-03 13:09:24 +03:00
const DELTA_RECT* rectangle = &multi_opaque_rect->rectangles[i];
2011-10-05 00:05:09 +04:00
rect.left = rectangle->left;
rect.top = rectangle->top;
rect.right = rectangle->left + rectangle->width;
rect.bottom = rectangle->top + rectangle->height;
brush = CreateSolidBrush(brush_color);
2013-06-16 06:57:21 +04:00
FillRect(wfc->drawing->hdc, &rect, brush);
2011-10-05 00:05:09 +04:00
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
2016-08-03 13:09:24 +03:00
wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1,
2016-08-10 14:33:34 +03:00
rect.bottom - rect.top + 1);
2011-10-05 00:05:09 +04:00
DeleteObject(brush);
}
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
2011-10-05 00:05:09 +04:00
{
HPEN pen;
HPEN org_pen;
int x, y, w, h;
COLORREF pen_color;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2011-10-05 00:05:09 +04:00
2016-08-03 13:09:24 +03:00
if (!context || !line_to)
return FALSE;
2011-10-05 00:05:09 +04:00
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, line_to->penColor, &pen_color, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2011-10-05 00:05:09 +04:00
2016-08-03 13:09:24 +03:00
pen = CreatePen(line_to->penStyle, line_to->penWidth, pen_color);
2013-06-16 06:57:21 +04:00
wf_set_rop2(wfc->drawing->hdc, line_to->bRop2);
2019-11-06 17:24:51 +03:00
org_pen = (HPEN)SelectObject(wfc->drawing->hdc, pen);
2013-06-16 06:57:21 +04:00
MoveToEx(wfc->drawing->hdc, line_to->nXStart, line_to->nYStart, NULL);
LineTo(wfc->drawing->hdc, line_to->nXEnd, line_to->nYEnd);
x = (line_to->nXStart < line_to->nXEnd) ? line_to->nXStart : line_to->nXEnd;
y = (line_to->nYStart < line_to->nYEnd) ? line_to->nYStart : line_to->nYEnd;
2016-08-03 13:09:24 +03:00
w = (line_to->nXStart < line_to->nXEnd) ? (line_to->nXEnd - line_to->nXStart)
2019-11-06 17:24:51 +03:00
: (line_to->nXStart - line_to->nXEnd);
2016-08-03 13:09:24 +03:00
h = (line_to->nYStart < line_to->nYEnd) ? (line_to->nYEnd - line_to->nYStart)
2019-11-06 17:24:51 +03:00
: (line_to->nYStart - line_to->nYEnd);
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
wf_invalidate_region(wfc, x, y, w, h);
2013-06-16 06:57:21 +04:00
SelectObject(wfc->drawing->hdc, org_pen);
2011-10-05 00:05:09 +04:00
DeleteObject(pen);
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
2011-10-05 00:05:09 +04:00
{
int org_rop2;
HPEN hpen;
HPEN org_hpen;
COLORREF pen_color;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
if (!context || !polyline)
return FALSE;
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, polyline->penColor, &pen_color, NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
hpen = CreatePen(0, 1, pen_color);
2013-06-16 06:57:21 +04:00
org_rop2 = wf_set_rop2(wfc->drawing->hdc, polyline->bRop2);
2019-11-06 17:24:51 +03:00
org_hpen = (HPEN)SelectObject(wfc->drawing->hdc, hpen);
2014-10-09 14:11:38 +04:00
if (polyline->numDeltaEntries > 0)
{
2019-11-06 17:24:51 +03:00
POINT* pts;
POINT temp;
int numPoints;
2014-10-09 14:11:38 +04:00
numPoints = polyline->numDeltaEntries + 1;
2019-11-06 17:24:51 +03:00
pts = (POINT*)malloc(sizeof(POINT) * numPoints);
2014-10-09 14:11:38 +04:00
pts[0].x = temp.x = polyline->xStart;
pts[0].y = temp.y = polyline->yStart;
for (UINT32 i = 0; i < polyline->numDeltaEntries; i++)
{
2014-02-10 10:43:58 +04:00
temp.x += polyline->points[i].x;
temp.y += polyline->points[i].y;
2014-10-09 14:11:38 +04:00
pts[i + 1].x = temp.x;
pts[i + 1].y = temp.y;
}
2016-08-03 13:09:24 +03:00
2014-10-09 14:11:38 +04:00
if (wfc->drawing == wfc->primary)
2016-08-03 13:09:24 +03:00
wf_invalidate_region(wfc, wfc->client_x, wfc->client_y, wfc->client_width,
2016-08-10 14:33:34 +03:00
wfc->client_height);
2016-08-03 13:09:24 +03:00
2014-10-09 14:11:38 +04:00
Polyline(wfc->drawing->hdc, pts, numPoints);
free(pts);
}
2011-10-05 00:05:09 +04:00
2013-06-16 06:57:21 +04:00
SelectObject(wfc->drawing->hdc, org_hpen);
wf_set_rop2(wfc->drawing->hdc, org_rop2);
DeleteObject(hpen);
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-07-21 16:36:15 +03:00
static BOOL wf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
2011-10-07 22:55:07 +04:00
{
wfBitmap* bitmap;
2016-08-03 13:09:24 +03:00
wfContext* wfc = (wfContext*)context;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !memblt)
return FALSE;
2011-10-07 22:55:07 +04:00
2019-11-06 17:24:51 +03:00
bitmap = (wfBitmap*)memblt->bitmap;
2016-08-03 13:09:24 +03:00
if (!bitmap || !wfc->drawing || !wfc->drawing->hdc)
return FALSE;
2011-10-07 22:55:07 +04:00
2019-11-06 17:24:51 +03:00
if (!BitBlt(wfc->drawing->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
memblt->nHeight, bitmap->hdc, memblt->nXSrc, memblt->nYSrc,
gdi_rop3_code(memblt->bRop)))
2016-08-10 14:33:34 +03:00
return FALSE;
2011-10-07 22:55:07 +04:00
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
2016-08-03 13:09:24 +03:00
wf_invalidate_region(wfc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
2016-08-10 14:33:34 +03:00
memblt->nHeight);
2011-12-16 23:43:14 +04:00
2016-08-03 13:09:24 +03:00
return TRUE;
2011-10-05 00:05:09 +04:00
}
2016-08-10 15:45:55 +03:00
static BOOL wf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{
BOOL rc = FALSE;
HDC hdc;
wfBitmap* bitmap;
wfContext* wfc = (wfContext*)context;
COLORREF fgcolor, bgcolor, orgColor;
HBRUSH orgBrush = NULL, brush = NULL;
if (!context || !mem3blt)
return FALSE;
2019-11-06 17:24:51 +03:00
bitmap = (wfBitmap*)mem3blt->bitmap;
2016-08-10 15:45:55 +03:00
if (!bitmap || !wfc->drawing || !wfc->drawing->hdc)
return FALSE;
hdc = wfc->drawing->hdc;
if (!wf_decode_color(wfc, mem3blt->foreColor, &fgcolor, NULL))
return FALSE;
if (!wf_decode_color(wfc, mem3blt->backColor, &bgcolor, NULL))
return FALSE;
orgColor = SetTextColor(hdc, fgcolor);
2016-10-04 10:00:00 +03:00
switch (mem3blt->brush.style)
2016-08-10 15:45:55 +03:00
{
2016-10-04 10:00:00 +03:00
case GDI_BS_SOLID:
brush = CreateSolidBrush(fgcolor);
break;
case GDI_BS_HATCHED:
case GDI_BS_PATTERN:
2019-11-06 17:24:51 +03:00
{
HBITMAP bmp = CreateBitmap(8, 8, 1, mem3blt->brush.bpp, mem3blt->brush.data);
brush = CreatePatternBrush(bmp);
}
break;
2016-10-04 10:00:00 +03:00
default:
goto fail;
2016-08-10 15:45:55 +03:00
}
orgBrush = SelectObject(hdc, brush);
2016-10-04 10:00:00 +03:00
2019-11-06 17:24:51 +03:00
if (!BitBlt(hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight,
bitmap->hdc, mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop)))
2016-08-10 15:45:55 +03:00
goto fail;
if (wfc->drawing == wfc->primary)
2019-11-06 17:24:51 +03:00
wf_invalidate_region(wfc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth,
2016-10-04 10:00:00 +03:00
mem3blt->nHeight);
2016-08-10 15:45:55 +03:00
rc = TRUE;
fail:
2016-10-04 10:00:00 +03:00
2016-08-10 15:45:55 +03:00
if (brush)
SelectObject(hdc, orgBrush);
2016-10-04 10:00:00 +03:00
2016-08-10 15:45:55 +03:00
SetTextColor(hdc, orgColor);
return rc;
}
2016-08-03 13:09:24 +03:00
static BOOL wf_gdi_surface_frame_marker(rdpContext* context,
2016-08-10 14:33:34 +03:00
const SURFACE_FRAME_MARKER* surface_frame_marker)
{
2016-08-03 13:09:24 +03:00
rdpSettings* settings;
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
if (!context || !surface_frame_marker || !context->instance)
return FALSE;
settings = context->settings;
2016-08-03 13:09:24 +03:00
if (!settings)
return FALSE;
2013-06-16 06:57:21 +04:00
2019-11-06 17:24:51 +03:00
if (surface_frame_marker->frameAction == SURFACECMD_FRAMEACTION_END &&
2023-10-13 10:48:44 +03:00
freerdp_settings_get_uint32(settings, FreeRDP_FrameAcknowledge) > 0)
{
IFCALL(context->update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId);
}
2016-07-21 16:36:15 +03:00
2016-08-03 13:09:24 +03:00
return TRUE;
}
2011-10-05 00:05:09 +04:00
void wf_gdi_register_update_callbacks(rdpUpdate* update)
{
2011-12-04 02:24:18 +04:00
rdpPrimaryUpdate* primary = update->primary;
2016-08-03 13:09:24 +03:00
update->Palette = wf_gdi_palette_update;
update->SetBounds = wf_gdi_set_bounds;
primary->DstBlt = wf_gdi_dstblt;
primary->PatBlt = wf_gdi_patblt;
primary->ScrBlt = wf_gdi_scrblt;
primary->OpaqueRect = wf_gdi_opaque_rect;
primary->MultiOpaqueRect = wf_gdi_multi_opaque_rect;
primary->LineTo = wf_gdi_line_to;
primary->Polyline = wf_gdi_polyline;
primary->MemBlt = wf_gdi_memblt;
2016-08-10 15:45:55 +03:00
primary->Mem3Blt = wf_gdi_mem3blt;
2016-08-03 13:09:24 +03:00
update->SurfaceFrameMarker = wf_gdi_surface_frame_marker;
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_update_canvas_diff(wfContext* wfc)
{
RECT rc_client, rc_wnd;
int dx, dy;
2013-06-16 06:57:21 +04:00
GetClientRect(wfc->hwnd, &rc_client);
GetWindowRect(wfc->hwnd, &rc_wnd);
dx = (rc_wnd.right - rc_wnd.left) - rc_client.right;
dy = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom;
2013-06-16 06:57:21 +04:00
if (!wfc->disablewindowtracking)
{
2013-06-16 06:57:21 +04:00
wfc->diff.x = dx;
wfc->diff.y = dy;
}
2013-06-16 06:57:21 +04:00
}