FreeRDP/client/Windows/wf_gdi.c

714 lines
20 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>
#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>
#include "wf_interface.h"
2011-10-22 00:45:35 +04:00
#include "wf_graphics.h"
#include "wf_gdi.h"
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 */
};
BOOL wf_set_rop2(HDC hdc, int rop2)
2011-10-05 00:05:09 +04:00
{
if ((rop2 < 0x01) || (rop2 > 0x10))
{
fprintf(stderr, "Unsupported ROP2: %d\n", 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
}
2013-06-16 06:57:21 +04:00
wfBitmap* wf_glyph_new(wfContext* wfc, GLYPH_DATA* glyph)
2011-10-05 00:05:09 +04:00
{
wfBitmap* glyph_bmp;
2013-06-16 06:57:21 +04:00
glyph_bmp = wf_image_new(wfc, glyph->cx, glyph->cy, 1, glyph->aj);
2011-10-05 00:05:09 +04:00
return glyph_bmp;
}
void wf_glyph_free(wfBitmap* glyph)
2011-10-05 00:05:09 +04:00
{
wf_image_free(glyph);
}
2013-06-16 06:57:21 +04:00
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);
cdata = (BYTE *) malloc(dst_bytes_per_row * height);
src = data;
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;
}
2013-06-16 06:57:21 +04:00
HBRUSH wf_create_brush(wfContext* wfc, rdpBrush* brush, UINT32 color, int bpp)
{
int i;
HBRUSH br;
LOGBRUSH lbr;
BYTE* cdata;
BYTE ipattern[8];
HBITMAP pattern = NULL;
lbr.lbStyle = brush->style;
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)
{
2013-06-16 06:57:21 +04:00
pattern = wf_create_dib(wfc, 8, 8, bpp, 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;
}
2013-06-16 06:57:21 +04:00
void wf_scale_rect(wfContext* wfc, RECT* source)
{
int ww, wh, dw, dh;
2013-06-16 06:57:21 +04:00
if (!wfc->client_width)
wfc->client_width = wfc->width;
2013-06-16 06:57:21 +04:00
if (!wfc->client_height)
wfc->client_height = wfc->height;
2013-06-16 06:57:21 +04:00
ww = wfc->client_width;
wh = wfc->client_height;
dw = wfc->instance->settings->DesktopWidth;
dh = wfc->instance->settings->DesktopHeight;
if (!ww)
ww = dw;
if (!wh)
wh = dh;
2013-06-16 06:57:21 +04:00
if (wfc->instance->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;
}
2013-06-16 06:57:21 +04:00
void wf_invalidate_region(wfContext* wfc, int x, int y, int width, int height)
2011-10-05 00:05:09 +04:00
{
RECT rect;
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;
2013-06-16 06:57:21 +04:00
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);
gdi_InvalidateRegion(wfc->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)
{
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2013-06-16 06:57:21 +04:00
if (wfc->instance->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
wfc->offset_x = (w - wfc->width) / 2;
if (wfc->offset_x < x)
wfc->offset_x = x;
wfc->offset_y = (h - wfc->height) / 2;
if (wfc->offset_y < y)
wfc->offset_y = y;
}
else
{
2013-06-16 06:57:21 +04:00
wfc->offset_x = (GetSystemMetrics(SM_CXSCREEN) - wfc->width) / 2;
if (wfc->offset_x < 0)
wfc->offset_x = 0;
wfc->offset_y = (GetSystemMetrics(SM_CYSCREEN) - wfc->height) / 2;
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)
{
2013-06-16 06:57:21 +04:00
if (wfc->fullscreen)
{
2013-06-16 06:57:21 +04:00
if(wfc->instance->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);
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED);
}
}
2013-06-16 06:57:21 +04:00
else if (!wfc->instance->settings->Decorations)
{
RECT rc_wnd;
RECT rc_client;
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 */
2013-06-16 06:57:21 +04:00
SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, wfc->width, wfc->height, SWP_FRAMECHANGED);
2013-06-16 06:57:21 +04:00
wf_update_canvas_diff(wfc);
SetWindowPos(wfc->hwnd, HWND_TOP, -1, -1, wfc->width + wfc->diff.x, wfc->height + wfc->diff.y, SWP_NOMOVE | SWP_FRAMECHANGED);
}
else
{
RECT rc_wnd;
RECT rc_client;
2013-06-16 06:57:21 +04:00
SetWindowLongPtr(wfc->hwnd, GWL_STYLE, WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX);
2013-06-16 06:57:21 +04:00
if (!wfc->client_height)
wfc->client_height = wfc->height;
2013-06-16 06:57:21 +04:00
if (!wfc->client_width)
wfc->client_width = wfc->width;
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;
2013-06-16 06:57:21 +04:00
wf_update_canvas_diff(wfc);
/* Now resize to get full canvas size and room for caption and borders */
2013-06-16 06:57:21 +04:00
SetWindowPos(wfc->hwnd, HWND_TOP, wfc->client_x, wfc->client_y, wfc->client_width + wfc->diff.x, wfc->client_height + wfc->diff.y, 0 /*SWP_FRAMECHANGED*/);
//wf_size_scrollbars(wfc, wfc->client_width, wfc->client_height);
}
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;
}
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
2013-06-16 06:57:21 +04:00
void wf_gdi_palette_update(wfContext* wfc, PALETTE_UPDATE* palette)
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);
}
2013-06-16 06:57:21 +04:00
void wf_gdi_set_bounds(wfContext* wfc, rdpBounds* bounds)
2011-10-05 00:05:09 +04:00
{
HRGN hrgn;
if (bounds != NULL)
{
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);
2011-10-05 00:05:09 +04:00
}
}
2013-06-16 06:57:21 +04:00
void wf_gdi_dstblt(wfContext* wfc, DSTBLT_ORDER* dstblt)
2011-10-05 00:05:09 +04:00
{
2013-06-16 06:57:21 +04:00
BitBlt(wfc->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect,
2011-10-05 00:05:09 +04:00
dstblt->nWidth, dstblt->nHeight, NULL, 0, 0, gdi_rop3_code(dstblt->bRop));
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, dstblt->nLeftRect, dstblt->nTopRect,
2011-10-05 00:05:09 +04:00
dstblt->nWidth, dstblt->nHeight);
}
2013-06-16 06:57:21 +04:00
void wf_gdi_patblt(wfContext* wfc, 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;
2013-06-16 06:57:21 +04:00
fgcolor = freerdp_color_convert_bgr(patblt->foreColor, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
bgcolor = freerdp_color_convert_bgr(patblt->backColor, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
2013-06-16 06:57:21 +04:00
brush = wf_create_brush(wfc, &patblt->brush, fgcolor, wfc->srcBpp);
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);
2013-06-16 06:57:21 +04:00
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)
wf_invalidate_region(wfc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_gdi_scrblt(wfContext* wfc, SCRBLT_ORDER* scrblt)
2011-10-05 00:05:09 +04:00
{
2013-06-16 06:57:21 +04:00
BitBlt(wfc->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect,
scrblt->nWidth, scrblt->nHeight, wfc->primary->hdc,
2011-10-05 00:05:09 +04:00
scrblt->nXSrc, scrblt->nYSrc, gdi_rop3_code(scrblt->bRop));
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, scrblt->nLeftRect, scrblt->nTopRect,
2011-10-05 00:05:09 +04:00
scrblt->nWidth, scrblt->nHeight);
}
2013-06-16 06:57:21 +04:00
void wf_gdi_opaque_rect(wfContext* wfc, 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;
2011-10-05 00:05:09 +04:00
2013-06-16 06:57:21 +04:00
brush_color = freerdp_color_convert_var_bgr(opaque_rect->color, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
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)
wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1);
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_gdi_multi_opaque_rect(wfContext* wfc, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
2011-10-05 00:05:09 +04:00
{
int i;
RECT rect;
HBRUSH brush;
2012-10-09 11:26:39 +04:00
UINT32 brush_color;
2011-10-05 00:05:09 +04:00
DELTA_RECT* rectangle;
2011-12-04 02:24:18 +04:00
for (i = 1; i < (int) multi_opaque_rect->numRectangles + 1; i++)
2011-10-05 00:05:09 +04:00
{
rectangle = &multi_opaque_rect->rectangles[i];
2013-06-16 06:57:21 +04:00
brush_color = freerdp_color_convert_var_bgr(multi_opaque_rect->color, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
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);
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)
wf_invalidate_region(wfc, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1);
2011-10-05 00:05:09 +04:00
DeleteObject(brush);
}
}
2013-06-16 06:57:21 +04:00
void wf_gdi_line_to(wfContext* wfc, 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;
2011-10-05 00:05:09 +04:00
2013-06-16 06:57:21 +04:00
pen_color = freerdp_color_convert_bgr(line_to->penColor, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
2011-10-05 00:05:09 +04: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);
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);
2011-10-05 00:05:09 +04:00
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;
w = (line_to->nXStart < line_to->nXEnd) ? (line_to->nXEnd - line_to->nXStart) : (line_to->nXStart - line_to->nXEnd);
h = (line_to->nYStart < line_to->nYEnd) ? (line_to->nYEnd - line_to->nYStart) : (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);
}
2013-06-16 06:57:21 +04:00
void wf_gdi_polyline(wfContext* wfc, POLYLINE_ORDER* polyline)
2011-10-05 00:05:09 +04:00
{
int i;
POINT* pts;
int org_rop2;
HPEN hpen;
HPEN org_hpen;
2012-10-09 11:26:39 +04:00
UINT32 pen_color;
2013-06-16 06:57:21 +04:00
pen_color = freerdp_color_convert_bgr(polyline->penColor, wfc->srcBpp, wfc->dstBpp, wfc->clrconv);
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);
if (polyline->numPoints > 0)
{
pts = (POINT*) malloc(sizeof(POINT) * polyline->numPoints);
2011-12-04 02:24:18 +04:00
for (i = 0; i < (int) polyline->numPoints; i++)
{
pts[i].x = polyline->points[i].x;
pts[i].y = polyline->points[i].y;
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
wf_invalidate_region(wfc, pts[i].x, pts[i].y, pts[i].x + 1, pts[i].y + 1);
}
2013-06-16 06:57:21 +04:00
Polyline(wfc->drawing->hdc, pts, polyline->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);
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_gdi_memblt(wfContext* wfc, MEMBLT_ORDER* memblt)
2011-10-07 22:55:07 +04:00
{
wfBitmap* bitmap;
2011-10-07 22:55:07 +04:00
bitmap = (wfBitmap*) memblt->bitmap;
2011-10-07 22:55:07 +04:00
2013-06-16 06:57:21 +04:00
BitBlt(wfc->drawing->hdc, memblt->nLeftRect, memblt->nTopRect,
memblt->nWidth, memblt->nHeight, bitmap->hdc,
2011-10-07 22:55:07 +04:00
memblt->nXSrc, memblt->nYSrc, gdi_rop3_code(memblt->bRop));
2013-06-16 06:57:21 +04:00
if (wfc->drawing == wfc->primary)
wf_invalidate_region(wfc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth, memblt->nHeight);
2011-10-07 22:55:07 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_gdi_surface_bits(wfContext* wfc, SURFACE_BITS_COMMAND* surface_bits_command)
2011-10-05 00:05:09 +04:00
{
2011-11-12 11:35:18 +04:00
int i, j;
int tx, ty;
char* tile_bitmap;
RFX_MESSAGE* message;
2012-12-21 10:46:39 +04:00
BITMAPINFO bitmap_info;
2011-11-12 11:35:18 +04:00
2013-06-16 06:57:21 +04:00
RFX_CONTEXT* rfx_context = (RFX_CONTEXT*) wfc->rfx_context;
NSC_CONTEXT* nsc_context = (NSC_CONTEXT*) wfc->nsc_context;
2011-11-12 11:35:18 +04:00
tile_bitmap = (char*) malloc(32);
ZeroMemory(tile_bitmap, 32);
2011-11-12 11:35:18 +04:00
if (surface_bits_command->codecID == RDP_CODEC_ID_REMOTEFX)
2011-11-12 11:35:18 +04:00
{
2011-12-04 02:24:18 +04:00
message = rfx_process_message(rfx_context, surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
2011-11-12 11:35:18 +04:00
/* blit each tile */
2013-08-14 01:18:59 +04:00
for (i = 0; i < message->numTiles; i++)
2011-11-12 11:35:18 +04:00
{
tx = message->tiles[i]->x + surface_bits_command->destLeft;
ty = message->tiles[i]->y + surface_bits_command->destTop;
2013-06-16 06:57:21 +04:00
freerdp_image_convert(message->tiles[i]->data, wfc->tile->pdata, 64, 64, 32, 32, wfc->clrconv);
2011-11-12 11:35:18 +04:00
2013-08-14 01:18:59 +04:00
for (j = 0; j < message->numRects; j++)
2011-11-12 11:35:18 +04:00
{
2013-06-16 06:57:21 +04:00
wf_set_clip_rgn(wfc,
2011-11-12 11:35:18 +04:00
surface_bits_command->destLeft + message->rects[j].x,
surface_bits_command->destTop + message->rects[j].y,
message->rects[j].width, message->rects[j].height);
2013-06-16 06:57:21 +04:00
BitBlt(wfc->primary->hdc, tx, ty, 64, 64, wfc->tile->hdc, 0, 0, SRCCOPY);
2011-11-12 11:35:18 +04:00
}
}
2013-06-16 06:57:21 +04:00
wf_set_null_clip_rgn(wfc);
2011-12-16 23:43:14 +04:00
/* invalidate regions */
2013-08-14 01:18:59 +04:00
for (i = 0; i < message->numRects; i++)
2011-12-16 23:43:14 +04:00
{
tx = surface_bits_command->destLeft + message->rects[i].x;
ty = surface_bits_command->destTop + message->rects[i].y;
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, tx, ty, message->rects[i].width, message->rects[i].height);
2011-12-16 23:43:14 +04:00
}
2011-12-04 02:24:18 +04:00
rfx_message_free(rfx_context, message);
2011-11-12 11:35:18 +04:00
}
else if (surface_bits_command->codecID == RDP_CODEC_ID_NSCODEC)
2011-11-12 11:35:18 +04:00
{
nsc_process_message(nsc_context, surface_bits_command->bpp, surface_bits_command->width, surface_bits_command->height,
surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
2012-12-21 10:46:39 +04:00
ZeroMemory(&bitmap_info, sizeof(bitmap_info));
bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmap_info.bmiHeader.biWidth = surface_bits_command->width;
bitmap_info.bmiHeader.biHeight = surface_bits_command->height;
bitmap_info.bmiHeader.biPlanes = 1;
bitmap_info.bmiHeader.biBitCount = surface_bits_command->bpp;
bitmap_info.bmiHeader.biCompression = BI_RGB;
2013-06-16 06:57:21 +04:00
SetDIBitsToDevice(wfc->primary->hdc, surface_bits_command->destLeft, surface_bits_command->destTop,
2012-12-21 10:46:39 +04:00
surface_bits_command->width, surface_bits_command->height, 0, 0, 0, surface_bits_command->height,
nsc_context->BitmapData, &bitmap_info, DIB_RGB_COLORS);
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, surface_bits_command->destLeft, surface_bits_command->destTop,
surface_bits_command->width, surface_bits_command->height);
}
2013-01-15 00:19:51 +04:00
else if (surface_bits_command->codecID == RDP_CODEC_ID_NONE)
2011-11-12 11:35:18 +04:00
{
2012-12-21 10:46:39 +04:00
ZeroMemory(&bitmap_info, sizeof(bitmap_info));
bitmap_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmap_info.bmiHeader.biWidth = surface_bits_command->width;
bitmap_info.bmiHeader.biHeight = surface_bits_command->height;
bitmap_info.bmiHeader.biPlanes = 1;
bitmap_info.bmiHeader.biBitCount = surface_bits_command->bpp;
bitmap_info.bmiHeader.biCompression = BI_RGB;
2013-06-16 06:57:21 +04:00
SetDIBitsToDevice(wfc->primary->hdc, surface_bits_command->destLeft, surface_bits_command->destTop,
2012-12-21 10:46:39 +04:00
surface_bits_command->width, surface_bits_command->height, 0, 0, 0, surface_bits_command->height,
surface_bits_command->bitmapData, &bitmap_info, DIB_RGB_COLORS);
2013-06-16 06:57:21 +04:00
wf_invalidate_region(wfc, surface_bits_command->destLeft, surface_bits_command->destTop,
2012-12-21 10:46:39 +04:00
surface_bits_command->width, surface_bits_command->height);
2011-11-12 11:35:18 +04:00
}
else
{
fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID);
2011-11-12 11:35:18 +04:00
}
2011-10-05 00:05:09 +04:00
2011-11-12 11:35:18 +04:00
if (tile_bitmap != NULL)
free(tile_bitmap);
2011-10-05 00:05:09 +04:00
}
2013-06-16 06:57:21 +04:00
void wf_gdi_surface_frame_marker(wfContext* wfc, SURFACE_FRAME_MARKER* surface_frame_marker)
{
2013-06-16 06:57:21 +04:00
rdpContext* context;
rdpSettings* settings;
2013-06-16 08:51:48 +04:00
context = (rdpContext*) wfc;
2013-06-16 06:57:21 +04:00
settings = wfc->instance->settings;
if (surface_frame_marker->frameAction == SURFACECMD_FRAMEACTION_END && settings->FrameAcknowledge > 0)
{
2013-06-16 08:51:48 +04:00
IFCALL(context->instance->update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId);
}
}
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;
2013-07-26 23:43:55 +04:00
update->Palette = (pPalette) wf_gdi_palette_update;
update->SetBounds = (pSetBounds) wf_gdi_set_bounds;
2011-12-04 02:24:18 +04:00
2013-06-16 08:51:48 +04:00
primary->DstBlt = (pDstBlt) wf_gdi_dstblt;
primary->PatBlt = (pPatBlt) wf_gdi_patblt;
primary->ScrBlt = (pScrBlt) wf_gdi_scrblt;
primary->OpaqueRect = (pOpaqueRect) wf_gdi_opaque_rect;
2011-12-04 02:24:18 +04:00
primary->DrawNineGrid = NULL;
primary->MultiDstBlt = NULL;
primary->MultiPatBlt = NULL;
primary->MultiScrBlt = NULL;
2013-06-16 08:51:48 +04:00
primary->MultiOpaqueRect = (pMultiOpaqueRect) wf_gdi_multi_opaque_rect;
2011-12-04 02:24:18 +04:00
primary->MultiDrawNineGrid = NULL;
2013-06-16 08:51:48 +04:00
primary->LineTo = (pLineTo) wf_gdi_line_to;
primary->Polyline = (pPolyline) wf_gdi_polyline;
primary->MemBlt = (pMemBlt) wf_gdi_memblt;
2011-12-04 02:24:18 +04:00
primary->Mem3Blt = NULL;
primary->SaveBitmap = NULL;
primary->GlyphIndex = NULL;
primary->FastIndex = NULL;
primary->FastGlyph = NULL;
primary->PolygonSC = NULL;
primary->PolygonCB = NULL;
primary->EllipseSC = NULL;
primary->EllipseCB = NULL;
2011-10-05 00:05:09 +04:00
2013-07-26 23:43:55 +04:00
update->SurfaceBits = (pSurfaceBits) wf_gdi_surface_bits;
update->SurfaceFrameMarker = (pSurfaceFrameMarker) 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
}