1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
|
/*
* Remmina - The GTK+ Remote Desktop Client
* Copyright (C) 2010 Jay Sorg
* Copyright (C) 2010-2011 Vic Lee
* Copyright (C) 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
* Copyright (C) 2016-2021 Antenore Gatta, Giovanni Panozzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. * If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. * If you
* do not wish to do so, delete this exception statement from your
* version. * If you delete this exception statement from all source
* files in the program, then also delete it here.
*
*/
#include "rdp_plugin.h"
#include "rdp_event.h"
#include "rdp_graphics.h"
#include <freerdp/codec/color.h>
#include <freerdp/codec/bitmap.h>
#include <winpr/memory.h>
//#define RF_BITMAP
//#define RF_GLYPH
/* Bitmap Class */
BOOL rf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
{
TRACE_CALL(__func__);
#ifdef RF_BITMAP
UINT8* data;
Pixmap pixmap;
XImage* image;
rfContext* rfi = (rfContext*)context;
XSetFunction(rfi->display, rfi->gc, GXcopy);
pixmap = XCreatePixmap(rfi->display, rfi->drawable, bitmap->width, bitmap->height, rfi->depth);
if (bitmap->data != NULL) {
data = freerdp_image_convert(bitmap->data, NULL,
bitmap->width, bitmap->height, rfi->srcBpp, rfi->bpp, rfi->clrconv);
if (bitmap->ephemeral != TRUE) {
image = XCreateImage(rfi->display, rfi->visual, rfi->depth,
ZPixmap, 0, (char*)data, bitmap->width, bitmap->height, rfi->scanline_pad, 0);
XPutImage(rfi->display, pixmap, rfi->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height);
XFree(image);
if (data != bitmap->data) && (data != NULL)
free(data);
}else {
if (data != bitmap->data) && (data != NULL)
free(bitmap->data);
bitmap->data = data;
}
}
((rfBitmap*)bitmap)->pixmap = pixmap;
#endif
return TRUE;
}
void rf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
{
TRACE_CALL(__func__);
#ifdef RF_BITMAP
rfContext* rfi = (rfContext*)context;
printf("rf_Bitmap_Free\n");
if (((rfBitmap*)bitmap)->pixmap != 0)
XFreePixmap(rfi->display, ((rfBitmap*)bitmap)->pixmap);
#endif
}
BOOL rf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
{
TRACE_CALL(__func__);
#ifdef RF_BITMAP
XImage* image;
int width, height;
rfContext* rfi = (rfContext*)context;
printf("rf_Bitmap_Paint\n");
width = bitmap->right - bitmap->left + 1;
height = bitmap->bottom - bitmap->top + 1;
XSetFunction(rfi->display, rfi->gc, GXcopy);
image = XCreateImage(rfi->display, rfi->visual, rfi->depth,
ZPixmap, 0, (char*)bitmap->data, bitmap->width, bitmap->height, rfi->scanline_pad, 0);
XPutImage(rfi->display, rfi->primary, rfi->gc,
image, 0, 0, bitmap->left, bitmap->top, width, height);
XFree(image);
//XCopyArea(rfi->display, rfi->primary, rfi->drawable, rfi->gc,
// bitmap->left, bitmap->top, width, height, bitmap->left, bitmap->top);
//gdi_InvalidateRegion(rfi->hdc, bitmap->left, bitmap->top, width, height);
#endif
return FALSE;
}
BOOL rf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
const BYTE* data, UINT32 width, UINT32 height, UINT32 bpp, UINT32 length, BOOL compressed, UINT32 codec_id)
{
TRACE_CALL(__func__);
#ifdef RF_BITMAP
UINT16 size;
printf("rf_Bitmap_Decompress\n");
size = width * height * (bpp + 7) / 8;
if (bitmap->data == NULL)
bitmap->data = (UINT8*)xmalloc(size);
else
bitmap->data = (UINT8*)xrealloc(bitmap->data, size);
if (compressed) {
BOOL status;
status = bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
if (status != TRUE) {
printf("Bitmap Decompression Failed\n");
}
}else {
freerdp_image_flip(data, bitmap->data, width, height, bpp);
}
bitmap->compressed = FALSE;
bitmap->length = size;
bitmap->bpp = bpp;
#endif
return TRUE;
}
BOOL rf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, BOOL primary)
{
TRACE_CALL(__func__);
#ifdef RF_BITMAP
rfContext* rfi = (rfContext*)context;
if (primary)
rfi->drawing = rfi->primary;
else
rfi->drawing = ((rfBitmap*)bitmap)->pixmap;
#endif
return TRUE;
}
/* Pointer Class */
BOOL rf_Pointer_New(rdpContext* context, rdpPointer* pointer)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
if (pointer->xorMaskData != 0) {
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.context = context;
ui->cursor.pointer = (rfPointer*)pointer;
ui->cursor.type = REMMINA_RDP_POINTER_NEW;
return remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui) ? TRUE : FALSE;
}
return FALSE;
}
void rf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
if (G_IS_OBJECT(((rfPointer*)pointer)->cursor))
{
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.context = context;
ui->cursor.pointer = (rfPointer*)pointer;
ui->cursor.type = REMMINA_RDP_POINTER_FREE;
remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui);
}
}
BOOL rf_Pointer_Set(rdpContext* context, const rdpPointer* pointer)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.pointer = (rfPointer*)pointer;
ui->cursor.type = REMMINA_RDP_POINTER_SET;
return remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui) ? TRUE : FALSE;
}
BOOL rf_Pointer_SetNull(rdpContext* context)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.type = REMMINA_RDP_POINTER_NULL;
return remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui) ? TRUE : FALSE;
}
BOOL rf_Pointer_SetDefault(rdpContext* context)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.type = REMMINA_RDP_POINTER_DEFAULT;
return remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui) ? TRUE : FALSE;
}
BOOL rf_Pointer_SetPosition(rdpContext* context, UINT32 x, UINT32 y)
{
TRACE_CALL(__func__);
RemminaPluginRdpUiObject* ui;
rfContext* rfi = (rfContext*)context;
ui = g_new0(RemminaPluginRdpUiObject, 1);
ui->type = REMMINA_RDP_UI_CURSOR;
ui->cursor.type = REMMINA_RDP_POINTER_SETPOS;
ui->pos.x = x;
ui->pos.y = y;
return remmina_rdp_event_queue_ui_sync_retint(rfi->protocol_widget, ui) ? TRUE : FALSE;
}
/* Glyph Class */
BOOL rf_Glyph_New(rdpContext* context, const rdpGlyph* glyph)
{
TRACE_CALL(__func__);
#ifdef RF_GLYPH
int scanline;
XImage* image;
rfContext* rfi;
rfGlyph* rf_glyph;
rf_glyph = (rfGlyph*)glyph;
rfi = (rfContext*)context;
scanline = (glyph->cx + 7) / 8;
rf_glyph->pixmap = XCreatePixmap(rfi->display, rfi->drawing, glyph->cx, glyph->cy, 1);
image = XCreateImage(rfi->display, rfi->visual, 1,
ZPixmap, 0, (char*)glyph->aj, glyph->cx, glyph->cy, 8, scanline);
image->byte_order = MSBFirst;
image->bitmap_bit_order = MSBFirst;
XInitImage(image);
XPutImage(rfi->display, rf_glyph->pixmap, rfi->gc_mono, image, 0, 0, 0, 0, glyph->cx, glyph->cy);
XFree(image);
#endif
return TRUE;
}
void rf_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
{
TRACE_CALL(__func__);
#ifdef RF_GLYPH
rfContext* rfi = (rfContext*)context;
if (((rfGlyph*)glyph)->pixmap != 0)
XFreePixmap(rfi->display, ((rfGlyph*)glyph)->pixmap);
#endif
}
static BOOL rf_Glyph_Draw(rdpContext* context, const rdpGlyph* glyph, INT32 x,
INT32 y, INT32 w, INT32 h, INT32 sx, INT32 sy,
BOOL fOpRedundant)
{
TRACE_CALL(__func__);
#ifdef RF_GLYPH
rfGlyph* rf_glyph;
rfContext* rfi = (rfContext*)context;
rf_glyph = (rfGlyph*)glyph;
XSetStipple(rfi->display, rfi->gc, rf_glyph->pixmap);
XSetTSOrigin(rfi->display, rfi->gc, x, y);
XFillRectangle(rfi->display, rfi->drawing, rfi->gc, x, y, glyph->cx, glyph->cy);
XSetStipple(rfi->display, rfi->gc, rfi->bitmap_mono);
#endif
return TRUE;
}
static BOOL rf_Glyph_BeginDraw(rdpContext* context, INT32 x, INT32 y,
INT32 width, INT32 height, UINT32 bgcolor,
UINT32 fgcolor, BOOL fOpRedundant)
{
TRACE_CALL(__func__);
#ifdef RF_GLYPH
rfContext* rfi = (rfContext*)context;
bgcolor = (rfi->clrconv->invert) ?
freerdp_color_convert_var_bgr(bgcolor, rfi->srcBpp, 32, rfi->clrconv) :
freerdp_color_convert_var_rgb(bgcolor, rfi->srcBpp, 32, rfi->clrconv);
fgcolor = (rfi->clrconv->invert) ?
freerdp_color_convert_var_bgr(fgcolor, rfi->srcBpp, 32, rfi->clrconv) :
freerdp_color_convert_var_rgb(fgcolor, rfi->srcBpp, 32, rfi->clrconv);
XSetFunction(rfi->display, rfi->gc, GXcopy);
XSetFillStyle(rfi->display, rfi->gc, FillSolid);
XSetForeground(rfi->display, rfi->gc, fgcolor);
XFillRectangle(rfi->display, rfi->drawing, rfi->gc, x, y, width, height);
XSetForeground(rfi->display, rfi->gc, bgcolor);
XSetBackground(rfi->display, rfi->gc, fgcolor);
XSetFillStyle(rfi->display, rfi->gc, FillStippled);
#endif
return TRUE;
}
static BOOL rf_Glyph_EndDraw(rdpContext* context, INT32 x, INT32 y,
INT32 width, INT32 height,
UINT32 bgcolor, UINT32 fgcolor)
{
TRACE_CALL(__func__);
#ifdef RF_GLYPH
rfContext* rfi = (rfContext*)context;
if (rfi->drawing == rfi->primary) {
//XCopyArea(rfi->display, rfi->primary, rfi->drawable, rfi->gc, x, y, width, height, x, y);
//gdi_InvalidateRegion(rfi->hdc, x, y, width, height);
}
#endif
return TRUE;
}
/* Graphics Module */
void rf_register_graphics(rdpGraphics* graphics)
{
TRACE_CALL(__func__);
rdpBitmap* bitmap;
rdpPointer* pointer;
rdpGlyph* glyph;
bitmap = (rdpBitmap*)malloc(sizeof(rdpBitmap));
ZeroMemory(bitmap, sizeof(rdpBitmap));
bitmap->size = sizeof(rfBitmap);
bitmap->New = rf_Bitmap_New;
bitmap->Free = rf_Bitmap_Free;
bitmap->Paint = rf_Bitmap_Paint;
bitmap->Decompress = rf_Bitmap_Decompress;
bitmap->SetSurface = rf_Bitmap_SetSurface;
graphics_register_bitmap(graphics, bitmap);
free(bitmap);
pointer = (rdpPointer*)malloc(sizeof(rdpPointer));
ZeroMemory(pointer, sizeof(rdpPointer));
pointer->size = sizeof(rfPointer);
pointer->New = rf_Pointer_New;
pointer->Free = rf_Pointer_Free;
pointer->Set = rf_Pointer_Set;
pointer->SetNull = rf_Pointer_SetNull;
pointer->SetDefault = rf_Pointer_SetDefault;
pointer->SetPosition = rf_Pointer_SetPosition;
graphics_register_pointer(graphics, pointer);
free(pointer);
glyph = (rdpGlyph*)malloc(sizeof(rdpGlyph));
ZeroMemory(glyph, sizeof(rdpGlyph));
glyph->size = sizeof(rfGlyph);
glyph->New = rf_Glyph_New;
glyph->Free = rf_Glyph_Free;
glyph->Draw = rf_Glyph_Draw;
glyph->BeginDraw = rf_Glyph_BeginDraw;
glyph->EndDraw = rf_Glyph_EndDraw;
graphics_register_glyph(graphics, glyph);
free(glyph);
}
|