2
* Remmina - The GTK+ Remote Desktop Client
3
* Copyright (C) 2010 Jay Sorg
4
* Copyright (C) 2010-2011 Vic Lee
5
* Copyright (C) 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330,
20
* Boston, MA 02111-1307, USA.
23
#include "rdp_plugin.h"
24
#include "rdp_event.h"
25
#include "rdp_graphics.h"
27
#include <freerdp/utils/memory.h>
28
#include <freerdp/codec/color.h>
29
#include <freerdp/codec/bitmap.h>
36
void rf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
42
rfContext* rfi = (rfContext*) context;
44
XSetFunction(rfi->display, rfi->gc, GXcopy);
45
pixmap = XCreatePixmap(rfi->display, rfi->drawable, bitmap->width, bitmap->height, rfi->depth);
47
if (bitmap->data != NULL)
49
data = freerdp_image_convert(bitmap->data, NULL,
50
bitmap->width, bitmap->height, rfi->srcBpp, rfi->bpp, rfi->clrconv);
52
if (bitmap->ephemeral != true)
54
image = XCreateImage(rfi->display, rfi->visual, rfi->depth,
55
ZPixmap, 0, (char*) data, bitmap->width, bitmap->height, rfi->scanline_pad, 0);
57
XPutImage(rfi->display, pixmap, rfi->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height);
60
if (data != bitmap->data)
65
if (data != bitmap->data)
72
((rfBitmap*) bitmap)->pixmap = pixmap;
76
void rf_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
79
rfContext* rfi = (rfContext*) context;
81
printf("rf_Bitmap_Free\n");
83
if (((rfBitmap*) bitmap)->pixmap != 0)
84
XFreePixmap(rfi->display, ((rfBitmap*) bitmap)->pixmap);
88
void rf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
93
rfContext* rfi = (rfContext*) context;
95
printf("rf_Bitmap_Paint\n");
97
width = bitmap->right - bitmap->left + 1;
98
height = bitmap->bottom - bitmap->top + 1;
100
XSetFunction(rfi->display, rfi->gc, GXcopy);
102
image = XCreateImage(rfi->display, rfi->visual, rfi->depth,
103
ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height, rfi->scanline_pad, 0);
105
XPutImage(rfi->display, rfi->primary, rfi->gc,
106
image, 0, 0, bitmap->left, bitmap->top, width, height);
110
//XCopyArea(rfi->display, rfi->primary, rfi->drawable, rfi->gc,
111
// bitmap->left, bitmap->top, width, height, bitmap->left, bitmap->top);
113
//gdi_InvalidateRegion(rfi->hdc, bitmap->left, bitmap->top, width, height);
117
void rf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
118
uint8* data, int width, int height, int bpp, int length, boolean compressed)
123
printf("rf_Bitmap_Decompress\n");
125
size = width * height * (bpp + 7) / 8;
127
if (bitmap->data == NULL)
128
bitmap->data = (uint8*) xmalloc(size);
130
bitmap->data = (uint8*) xrealloc(bitmap->data, size);
136
status = bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
140
printf("Bitmap Decompression Failed\n");
145
freerdp_image_flip(data, bitmap->data, width, height, bpp);
148
bitmap->compressed = false;
149
bitmap->length = size;
154
void rf_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
157
rfContext* rfi = (rfContext*) context;
160
rfi->drawing = rfi->primary;
162
rfi->drawing = ((rfBitmap*) bitmap)->pixmap;
168
void rf_Pointer_New(rdpContext* context, rdpPointer* pointer)
173
void rf_Pointer_Free(rdpContext* context, rdpPointer* pointer)
178
void rf_Pointer_Set(rdpContext* context, rdpPointer* pointer)
185
void rf_Glyph_New(rdpContext* context, rdpGlyph* glyph)
193
rf_glyph = (rfGlyph*) glyph;
194
rfi = (rfContext*) context;
196
scanline = (glyph->cx + 7) / 8;
198
rf_glyph->pixmap = XCreatePixmap(rfi->display, rfi->drawing, glyph->cx, glyph->cy, 1);
200
image = XCreateImage(rfi->display, rfi->visual, 1,
201
ZPixmap, 0, (char*) glyph->aj, glyph->cx, glyph->cy, 8, scanline);
203
image->byte_order = MSBFirst;
204
image->bitmap_bit_order = MSBFirst;
207
XPutImage(rfi->display, rf_glyph->pixmap, rfi->gc_mono, image, 0, 0, 0, 0, glyph->cx, glyph->cy);
212
void rf_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
215
rfContext* rfi = (rfContext*) context;
217
if (((rfGlyph*) glyph)->pixmap != 0)
218
XFreePixmap(rfi->display, ((rfGlyph*) glyph)->pixmap);
222
void rf_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
226
rfContext* rfi = (rfContext*) context;
228
rf_glyph = (rfGlyph*) glyph;
230
XSetStipple(rfi->display, rfi->gc, rf_glyph->pixmap);
231
XSetTSOrigin(rfi->display, rfi->gc, x, y);
232
XFillRectangle(rfi->display, rfi->drawing, rfi->gc, x, y, glyph->cx, glyph->cy);
233
XSetStipple(rfi->display, rfi->gc, rfi->bitmap_mono);
237
void rf_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
240
rfContext* rfi = (rfContext*) context;
242
bgcolor = (rfi->clrconv->invert)?
243
freerdp_color_convert_var_bgr(bgcolor, rfi->srcBpp, 32, rfi->clrconv):
244
freerdp_color_convert_var_rgb(bgcolor, rfi->srcBpp, 32, rfi->clrconv);
246
fgcolor = (rfi->clrconv->invert)?
247
freerdp_color_convert_var_bgr(fgcolor, rfi->srcBpp, 32, rfi->clrconv):
248
freerdp_color_convert_var_rgb(fgcolor, rfi->srcBpp, 32, rfi->clrconv);
250
XSetFunction(rfi->display, rfi->gc, GXcopy);
251
XSetFillStyle(rfi->display, rfi->gc, FillSolid);
252
XSetForeground(rfi->display, rfi->gc, fgcolor);
253
XFillRectangle(rfi->display, rfi->drawing, rfi->gc, x, y, width, height);
255
XSetForeground(rfi->display, rfi->gc, bgcolor);
256
XSetBackground(rfi->display, rfi->gc, fgcolor);
257
XSetFillStyle(rfi->display, rfi->gc, FillStippled);
261
void rf_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
264
rfContext* rfi = (rfContext*) context;
266
if (rfi->drawing == rfi->primary)
268
//XCopyArea(rfi->display, rfi->primary, rfi->drawable, rfi->gc, x, y, width, height, x, y);
269
//gdi_InvalidateRegion(rfi->hdc, x, y, width, height);
274
/* Graphics Module */
276
void rf_register_graphics(rdpGraphics* graphics)
282
bitmap = xnew(rdpBitmap);
283
bitmap->size = sizeof(rfBitmap);
285
bitmap->New = rf_Bitmap_New;
286
bitmap->Free = rf_Bitmap_Free;
287
bitmap->Paint = rf_Bitmap_Paint;
288
bitmap->Decompress = rf_Bitmap_Decompress;
289
bitmap->SetSurface = rf_Bitmap_SetSurface;
291
graphics_register_bitmap(graphics, bitmap);
294
pointer = xnew(rdpPointer);
295
pointer->size = sizeof(rfPointer);
297
pointer->New = rf_Pointer_New;
298
pointer->Free = rf_Pointer_Free;
299
pointer->Set = rf_Pointer_Set;
301
graphics_register_pointer(graphics, pointer);
304
glyph = xnew(rdpGlyph);
305
glyph->size = sizeof(rfGlyph);
307
glyph->New = rf_Glyph_New;
308
glyph->Free = rf_Glyph_Free;
309
glyph->Draw = rf_Glyph_Draw;
310
glyph->BeginDraw = rf_Glyph_BeginDraw;
311
glyph->EndDraw = rf_Glyph_EndDraw;
313
graphics_register_glyph(graphics, glyph);