FreeRDP/client/Windows/wf_gdi.c

830 lines
21 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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")
2016-08-03 13:37:40 +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 */
};
2016-08-03 13:37:40 +03:00
static BOOL wf_decode_color(wfContext* wfc, const UINT32 srcColor,
2016-10-04 10:00:00 +03:00
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->context.gdi;
settings = wfc->context.settings;
if (!gdi || !settings)
return FALSE;
SrcFormat = gdi_get_pixel_format(gdi->context->settings->ColorDepth,
2016-08-10 14:33:34 +03:00
FALSE);
2016-08-08 16:15:55 +03:00
if (format)
*format = SrcFormat;
2016-08-10 14:33:34 +03:00
switch (GetBitsPerPixel(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
}
*color = ConvertColor(srcColor, SrcFormat,
2016-08-10 14:33:34 +03:00
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))
{
2014-09-12 19:13:01 +04: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;
2016-08-03 13:09:24 +03:00
glyph_bmp = wf_image_new(wfc, glyph->cx, glyph->cy, PIXEL_FORMAT_MONO,
2016-08-10 14:33:34 +03:00
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);
}
2016-08-03 13:37:40 +03:00
static BYTE* wf_glyph_convert(wfContext* wfc, int width, int height, BYTE* data)
{
int indexx;
int indexy;
BYTE* src;
BYTE* dst;
BYTE* cdata;
int src_bytes_per_row;
int dst_bytes_per_row;
src_bytes_per_row = (width + 7) / 8;
dst_bytes_per_row = src_bytes_per_row + (src_bytes_per_row % 2);
2016-08-03 13:09:24 +03:00
cdata = (BYTE*) malloc(dst_bytes_per_row * height);
src = data;
2016-08-03 13:09:24 +03:00
for (indexy = 0; indexy < height; indexy++)
{
dst = cdata + indexy * dst_bytes_per_row;
for (indexx = 0; indexx < dst_bytes_per_row; indexx++)
{
if (indexx < src_bytes_per_row)
*dst++ = *src++;
else
*dst++ = 0;
}
}
return cdata;
}
2016-08-03 13:09:24 +03:00
static HBRUSH wf_create_brush(wfContext* wfc, rdpBrush* brush, UINT32 color,
2016-08-10 14:33:34 +03:00
UINT32 bpp)
{
2016-08-03 13:09:24 +03:00
UINT32 i;
HBRUSH br;
LOGBRUSH lbr;
BYTE* cdata;
BYTE ipattern[8];
HBITMAP pattern = NULL;
lbr.lbStyle = brush->style;
2016-08-03 13:09:24 +03:00
if (lbr.lbStyle == BS_DIBPATTERN || lbr.lbStyle == BS_DIBPATTERN8X8
2016-08-10 14:33:34 +03:00
|| 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)
{
2016-08-03 13:09:24 +03:00
UINT32 format = gdi_get_pixel_format(bpp, FALSE);
pattern = wf_create_dib(wfc, 8, 8, format, brush->data, NULL);
lbr.lbHatch = (ULONG_PTR) pattern;
}
else
{
for (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);
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;
}
2016-07-21 16:36:15 +03:00
static 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
2016-08-03 13:37:40 +03:00
if (!wfc || !source || !wfc->context.settings)
2016-08-03 13:09:24 +03:00
return FALSE;
2016-07-21 16:36:15 +03:00
2016-08-03 13:37:40 +03:00
settings = wfc->context.settings;
2016-08-03 13:09:24 +03:00
if (!settings)
return FALSE;
dw = settings->DesktopWidth;
dh = settings->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;
2016-08-03 13:37:40 +03:00
if (wfc->context.settings->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;
}
2016-08-03 13:09:24 +03:00
void wf_invalidate_region(wfContext* wfc, UINT32 x, UINT32 y, UINT32 width,
2016-08-10 14:33:34 +03:00
UINT32 height)
2011-10-05 00:05:09 +04:00
{
RECT rect;
2016-08-03 13:09:24 +03:00
rdpGdi* gdi = wfc->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);
2016-08-03 13:09:24 +03:00
gdi_InvalidateRegion(gdi->primary->hdc, rect.left, rect.top, rect.right,
2016-08-10 14:33:34 +03:00
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;
2016-08-03 13:37:40 +03:00
settings = wfc->context.settings;
2016-07-21 16:36:15 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2016-08-03 13:37:40 +03:00
if (wfc->context.settings->UseMultimon)
{
int x = GetSystemMetrics(SM_XVIRTUALSCREEN);
int y = GetSystemMetrics(SM_YVIRTUALSCREEN);
int w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
2016-08-03 13:09:24 +03:00
wfc->offset_x = (w - settings->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
wfc->offset_y = (h - settings->DesktopHeight) / 2;
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
{
2016-08-03 13:09:24 +03:00
wfc->offset_x = (GetSystemMetrics(SM_CXSCREEN) - settings->DesktopWidth) / 2;
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
wfc->offset_y = (GetSystemMetrics(SM_CYSCREEN) - settings->DesktopHeight) / 2;
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;
2016-08-03 13:37:40 +03:00
settings = wfc->context.settings;
2016-07-21 16:36:15 +03:00
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2016-08-03 13:37:40 +03:00
if (wfc->context.settings->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);
}
}
2016-08-03 13:37:40 +03:00
else if (!wfc->context.settings->Decorations)
2016-08-03 13:09:24 +03:00
{
2013-06-16 06:57:21 +04:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_CHILD);
/* Now resize to get full canvas size and room for caption and borders */
2016-08-03 13:09:24 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, settings->DesktopWidth,
2016-08-10 14:33:34 +03:00
settings->DesktopHeight, SWP_FRAMECHANGED);
2013-06-16 06:57:21 +04:00
wf_update_canvas_diff(wfc);
2016-08-03 13:09:24 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1, settings->DesktopWidth + wfc->diff.x,
2016-08-10 14:33:34 +03:00
settings->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 |
WS_MAXIMIZEBOX);
2013-06-16 06:57:21 +04:00
if (!wfc->client_height)
2016-08-03 13:09:24 +03:00
wfc->client_height = settings->DesktopHeight;
2013-06-16 06:57:21 +04:00
if (!wfc->client_width)
2016-08-03 13:09:24 +03:00
wfc->client_width = settings->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 */
2016-08-03 13:09:24 +03:00
SetWindowPos(wfc->hwnd, HWND_TOP, wfc->client_x, wfc->client_y,
2016-08-10 14:33:34 +03:00
wfc->client_width + wfc->diff.x, wfc->client_height + wfc->diff.y,
0 /*SWP_FRAMECHANGED*/);
2013-06-16 06:57:21 +04: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;
}
2014-02-27 07:43:52 +04:00
if (wfc->fullscreen)
floatbar_show(wfc->floatbar);
else
floatbar_hide(wfc->floatbar);
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)
{
// 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
2016-08-03 13:09:24 +03:00
static BOOL wf_gdi_palette_update(rdpContext* context,
2016-08-10 14:33:34 +03:00
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)
{
2016-08-03 13:09:24 +03:00
hrgn = CreateRectRgn(bounds->left, bounds->top, bounds->right + 1,
2016-08-10 14:33:34 +03:00
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
2016-08-03 13:09:24 +03:00
if (!BitBlt(wfc->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect,
2016-08-10 14:33:34 +03:00
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
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, dstblt->nLeftRect, dstblt->nTopRect,
2016-08-10 14:33:34 +03:00
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;
2012-10-09 11:26:39 +04:00
UINT32 fgcolor;
UINT32 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
2016-08-03 13:09:24 +03:00
brush = wf_create_brush(wfc, &patblt->brush, fgcolor,
2016-08-10 14:33:34 +03:00
context->settings->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);
2016-08-03 13:09:24 +03:00
rc = PatBlt(wfc->drawing->hdc, patblt->nLeftRect, patblt->nTopRect,
2016-08-10 14:33:34 +03:00
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
2016-08-03 13:09:24 +03:00
if (!BitBlt(wfc->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect,
2016-08-10 14:33:34 +03:00
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
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, scrblt->nLeftRect, scrblt->nTopRect,
2016-08-10 14:33:34 +03:00
scrblt->nWidth, scrblt->nHeight);
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_opaque_rect(rdpContext* context,
2016-08-10 14:33:34 +03:00
const OPAQUE_RECT_ORDER* opaque_rect)
2011-10-05 00:05:09 +04:00
{
RECT rect;
HBRUSH brush;
2012-10-09 11:26:39 +04:00
UINT32 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
{
2016-08-03 13:09:24 +03:00
UINT32 i;
2011-10-05 00:05:09 +04:00
RECT rect;
HBRUSH brush;
2016-08-03 13:09:24 +03:00
UINT32 brush_color;
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
2016-08-03 13:37:40 +03:00
if (!wf_decode_color(wfc, multi_opaque_rect->color, &brush_color,
2016-08-10 14:33:34 +03:00
NULL))
2016-08-03 13:09:24 +03:00
return FALSE;
2014-09-12 19:34:30 +04:00
2016-08-03 13:09:24 +03:00
for (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;
2012-10-09 11:26:39 +04:00
UINT32 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);
org_pen = (HPEN) SelectObject(wfc->drawing->hdc, pen);
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)
2016-08-10 14:33:34 +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)
2016-08-10 14:33:34 +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;
2012-10-09 11:26:39 +04:00
UINT32 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);
org_hpen = (HPEN) SelectObject(wfc->drawing->hdc, hpen);
2014-10-09 14:11:38 +04:00
if (polyline->numDeltaEntries > 0)
{
2016-08-03 13:09:24 +03:00
POINT* pts;
2014-10-09 14:11:38 +04:00
POINT temp;
int numPoints;
int i;
numPoints = polyline->numDeltaEntries + 1;
pts = (POINT*) malloc(sizeof(POINT) * numPoints);
pts[0].x = temp.x = polyline->xStart;
pts[0].y = temp.y = polyline->yStart;
2014-10-09 14:11:38 +04:00
for (i = 0; i < (int) 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
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
2016-08-10 14:33:34 +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)))
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;
bitmap = (wfBitmap*) mem3blt->bitmap;
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:
{
HBITMAP bmp = CreateBitmap(8, 8, 1, mem3blt->brush.bpp, mem3blt->brush.data);
brush = CreatePatternBrush(bmp);
}
break;
default:
goto fail;
2016-08-10 15:45:55 +03:00
}
orgBrush = SelectObject(hdc, brush);
2016-10-04 10:00:00 +03:00
2016-08-10 15:45:55 +03:00
if (!BitBlt(hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
2016-10-04 10:00:00 +03:00
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)
2016-10-04 10:00:00 +03:00
wf_invalidate_region(wfc, mem3blt->nLeftRect, mem3blt->nTopRect,
mem3blt->nWidth,
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;
2016-08-03 13:09:24 +03:00
settings = context->instance->settings;
if (!settings)
return FALSE;
2013-06-16 06:57:21 +04:00
2016-08-03 13:09:24 +03:00
if (surface_frame_marker->frameAction == SURFACECMD_FRAMEACTION_END
2016-08-10 14:33:34 +03:00
&& settings->FrameAcknowledge > 0)
{
2016-08-03 13:09:24 +03:00
IFCALL(context->instance->update->SurfaceFrameAcknowledge, context,
2016-08-10 14:33:34 +03:00
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
}