~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to client/X11/xf_gdi.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.1.9) (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20141111122050-wyr8hrnwco9fcmum
Tags: 1.1.0~git20140921.1.440916e+dfsg1-2ubuntu1
* Merge with Debian unstable, remaining changes
  - Disable ffmpeg support
* Disable gstreamer support, this relies on gstreamer 0.10 and we don't want
  to add any more deps on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * FreeRDP: A Remote Desktop Protocol Client
 
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
3
 * X11 GDI
4
4
 *
5
5
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
17
17
 * limitations under the License.
18
18
 */
19
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include "config.h"
 
22
#endif
 
23
 
20
24
#include <X11/Xlib.h>
21
25
#include <X11/Xutil.h>
22
26
 
24
28
#include <freerdp/codec/rfx.h>
25
29
#include <freerdp/codec/nsc.h>
26
30
#include <freerdp/constants.h>
27
 
#include <freerdp/utils/memory.h>
28
31
#include <freerdp/codec/color.h>
29
32
#include <freerdp/codec/bitmap.h>
30
33
 
31
34
#include "xf_gdi.h"
32
35
 
33
 
static const uint8 xf_rop2_table[] =
 
36
static UINT8 GDI_BS_HATCHED_PATTERNS[] =
 
37
{
 
38
        0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* HS_HORIZONTAL */
 
39
        0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_VERTICAL */
 
40
        0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F, /* HS_FDIAGONAL */
 
41
        0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE, /* HS_BDIAGONAL */
 
42
        0xF7, 0xF7, 0xF7, 0x00, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_CROSS */
 
43
        0x7E, 0xBD, 0xDB, 0xE7, 0xE7, 0xDB, 0xBD, 0x7E /* HS_DIACROSS */
 
44
};
 
45
 
 
46
static const BYTE xf_rop2_table[] =
34
47
{
35
48
        0,
36
49
        GXclear,        /* 0 */
51
64
        GXset           /* 1 */
52
65
};
53
66
 
54
 
boolean xf_set_rop2(xfInfo* xfi, int rop2)
 
67
BOOL xf_set_rop2(xfContext* xfc, int rop2)
55
68
{
56
69
        if ((rop2 < 0x01) || (rop2 > 0x10))
57
70
        {
58
 
                printf("Unsupported ROP2: %d\n", rop2);
59
 
                return false;
 
71
                fprintf(stderr, "Unsupported ROP2: %d\n", rop2);
 
72
                return FALSE;
60
73
        }
61
74
 
62
 
        XSetFunction(xfi->display, xfi->gc, xf_rop2_table[rop2]);
63
 
        return true;
 
75
        XSetFunction(xfc->display, xfc->gc, xf_rop2_table[rop2]);
 
76
        return TRUE;
64
77
}
65
78
 
66
 
boolean xf_set_rop3(xfInfo* xfi, int rop3)
 
79
BOOL xf_set_rop3(xfContext* xfc, int rop3)
67
80
{
68
81
        int function = -1;
69
82
 
73
86
                        function = GXclear;
74
87
                        break;
75
88
 
76
 
                case 0x000500A9:
 
89
                case GDI_DPon:
77
90
                        function = GXnor;
78
91
                        break;
79
92
 
80
 
                case 0x000A0329:
 
93
                case GDI_DPna:
81
94
                        function = GXandInverted;
82
95
                        break;
83
96
 
84
 
                case 0x000F0001:
 
97
                case GDI_Pn:
85
98
                        function = GXcopyInverted;
86
99
                        break;
87
100
 
101
114
                        function = GXandReverse;
102
115
                        break;
103
116
 
104
 
                case 0x00500325:
 
117
                case GDI_PDna:
105
118
                        function = GXandReverse;
106
119
                        break;
107
120
 
113
126
                        function = GXxor;
114
127
                        break;
115
128
 
116
 
                case 0x005F00E9:
 
129
                case GDI_DPan:
117
130
                        function = GXnand;
118
131
                        break;
119
132
 
121
134
                        function = GXxor;
122
135
                        break;
123
136
 
124
 
                case 0x007700E6:
 
137
                case GDI_DSan:
125
138
                        function = GXnand;
126
139
                        break;
127
140
 
129
142
                        function = GXand;
130
143
                        break;
131
144
 
132
 
                case 0x00990066:
 
145
                case GDI_DSxn:
133
146
                        function = GXequiv;
134
147
                        break;
135
148
 
136
 
                case 0x00A000C9:
 
149
                case GDI_DPa:
137
150
                        function = GXand;
138
151
                        break;
139
152
 
141
154
                        function = GXequiv;
142
155
                        break;
143
156
 
144
 
                case 0x00AA0029:
 
157
                case GDI_D:
145
158
                        function = GXnoop;
146
159
                        break;
147
160
 
148
 
                case 0x00AF0229:
 
161
                case GDI_DPno:
149
162
                        function = GXorInverted;
150
163
                        break;
151
164
 
157
170
                        function = GXcopy;
158
171
                        break;
159
172
 
160
 
                case 0x00DD0228:
 
173
                case GDI_SDno:
161
174
                        function = GXorReverse;
162
175
                        break;
163
176
 
169
182
                        function = GXcopy;
170
183
                        break;
171
184
 
172
 
                case 0x00F50225:
 
185
                case GDI_PDno:
173
186
                        function = GXorReverse;
174
187
                        break;
175
188
 
176
 
                case 0x00FA0089:
 
189
                case GDI_DPo:
177
190
                        function = GXor;
178
191
                        break;
179
192
 
181
194
                        function = GXset;
182
195
                        break;
183
196
 
 
197
                case GDI_PSDPxax:
 
198
                        function = GXand;
 
199
                        break;
 
200
 
184
201
                default:
185
202
                        break;
186
203
        }
187
204
 
188
205
        if (function < 0)
189
206
        {
190
 
                printf("Unsupported ROP3: 0x%08X\n", rop3);
191
 
                XSetFunction(xfi->display, xfi->gc, GXclear);
192
 
                return false;
 
207
                fprintf(stderr, "Unsupported ROP3: 0x%08X\n", rop3);
 
208
                XSetFunction(xfc->display, xfc->gc, GXclear);
 
209
                return FALSE;
193
210
        }
194
211
 
195
 
        XSetFunction(xfi->display, xfi->gc, function);
 
212
        XSetFunction(xfc->display, xfc->gc, function);
196
213
 
197
 
        return true;
 
214
        return TRUE;
198
215
}
199
216
 
200
 
Pixmap xf_brush_new(xfInfo* xfi, int width, int height, int bpp, uint8* data)
 
217
Pixmap xf_brush_new(xfContext* xfc, int width, int height, int bpp, BYTE* data)
201
218
{
202
219
        Pixmap bitmap;
203
 
        uint8* cdata;
 
220
        BYTE* cdata;
204
221
        XImage* image;
205
222
 
206
 
        bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, xfi->depth);
 
223
        bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, xfc->depth);
207
224
 
208
 
        if(data != NULL)
 
225
        if (data != NULL)
209
226
        {
210
 
                GC gc;  // FIXME, should cache
211
 
 
212
 
                cdata = freerdp_image_convert(data, NULL, width, height, bpp, xfi->bpp, xfi->clrconv);
213
 
                image = XCreateImage(xfi->display, xfi->visual, xfi->depth,
214
 
                                                ZPixmap, 0, (char*) cdata, width, height, xfi->scanline_pad, 0);
215
 
 
216
 
                gc = XCreateGC(xfi->display, xfi->drawable, 0, NULL);
217
 
                XPutImage(xfi->display, bitmap, gc, image, 0, 0, 0, 0, width, height);
 
227
                GC gc;
 
228
 
 
229
                cdata = freerdp_image_convert(data, NULL, width, height, bpp, xfc->bpp, xfc->clrconv);
 
230
 
 
231
                image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
 
232
                                                ZPixmap, 0, (char*) cdata, width, height, xfc->scanline_pad, 0);
 
233
 
 
234
                gc = XCreateGC(xfc->display, xfc->drawable, 0, NULL);
 
235
                XPutImage(xfc->display, bitmap, gc, image, 0, 0, 0, 0, width, height);
218
236
                XFree(image);
 
237
 
219
238
                if (cdata != data)
220
 
                        xfree(cdata);
 
239
                        free(cdata);
221
240
 
222
 
                XFreeGC(xfi->display, gc);
 
241
                XFreeGC(xfc->display, gc);
223
242
        }
224
243
 
225
244
        return bitmap;
226
245
}
227
246
 
228
 
Pixmap xf_mono_bitmap_new(xfInfo* xfi, int width, int height, uint8* data)
229
 
{
230
 
        int scanline;
231
 
        XImage* image;
232
 
        Pixmap bitmap;
233
 
 
234
 
        scanline = (width + 7) / 8;
235
 
 
236
 
        bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, 1);
237
 
 
238
 
        image = XCreateImage(xfi->display, xfi->visual, 1,
239
 
                        ZPixmap, 0, (char*) data, width, height, 8, scanline);
240
 
 
241
 
        XPutImage(xfi->display, bitmap, xfi->gc_mono, image, 0, 0, 0, 0, width, height);
242
 
        XFree(image);
243
 
 
244
 
        return bitmap;
245
 
}
246
 
 
247
 
Pixmap xf_glyph_new(xfInfo* xfi, int width, int height, uint8* data)
248
 
{
249
 
        int scanline;
250
 
        Pixmap bitmap;
251
 
        XImage* image;
252
 
 
253
 
        scanline = (width + 7) / 8;
254
 
 
255
 
        bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, 1);
256
 
 
257
 
        image = XCreateImage(xfi->display, xfi->visual, 1,
258
 
                        ZPixmap, 0, (char*) data, width, height, 8, scanline);
259
 
 
260
 
        image->byte_order = MSBFirst;
261
 
        image->bitmap_bit_order = MSBFirst;
262
 
 
263
 
        XInitImage(image);
264
 
        XPutImage(xfi->display, bitmap, xfi->gc_mono, image, 0, 0, 0, 0, width, height);
 
247
Pixmap xf_mono_bitmap_new(xfContext* xfc, int width, int height, BYTE* data)
 
248
{
 
249
        int scanline;
 
250
        XImage* image;
 
251
        Pixmap bitmap;
 
252
 
 
253
        scanline = (width + 7) / 8;
 
254
 
 
255
        bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, 1);
 
256
 
 
257
        image = XCreateImage(xfc->display, xfc->visual, 1,
 
258
                        ZPixmap, 0, (char*) data, width, height, 8, scanline);
 
259
 
 
260
        XPutImage(xfc->display, bitmap, xfc->gc_mono, image, 0, 0, 0, 0, width, height);
265
261
        XFree(image);
266
262
 
267
263
        return bitmap;
269
265
 
270
266
void xf_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette)
271
267
{
272
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
273
 
        xfi->clrconv->palette->count = palette->number;
274
 
        xfi->clrconv->palette->entries = palette->entries;
 
268
        xfContext* xfc = (xfContext*) context;
 
269
 
 
270
        xf_lock_x11(xfc, FALSE);
 
271
 
 
272
        CopyMemory(xfc->clrconv->palette, palette, sizeof(rdpPalette));
 
273
 
 
274
        xf_unlock_x11(xfc, FALSE);
275
275
}
276
276
 
277
277
void xf_gdi_set_bounds(rdpContext* context, rdpBounds* bounds)
278
278
{
279
279
        XRectangle clip;
280
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
 
280
        xfContext* xfc = (xfContext*) context;
 
281
 
 
282
        xf_lock_x11(xfc, FALSE);
281
283
 
282
284
        if (bounds != NULL)
283
285
        {
285
287
                clip.y = bounds->top;
286
288
                clip.width = bounds->right - bounds->left + 1;
287
289
                clip.height = bounds->bottom - bounds->top + 1;
288
 
                XSetClipRectangles(xfi->display, xfi->gc, 0, 0, &clip, 1, YXBanded);
 
290
                XSetClipRectangles(xfc->display, xfc->gc, 0, 0, &clip, 1, YXBanded);
289
291
        }
290
292
        else
291
293
        {
292
 
                XSetClipMask(xfi->display, xfi->gc, None);
 
294
                XSetClipMask(xfc->display, xfc->gc, None);
293
295
        }
 
296
 
 
297
        xf_unlock_x11(xfc, FALSE);
294
298
}
295
299
 
296
300
void xf_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt)
297
301
{
298
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
299
 
 
300
 
        xf_set_rop3(xfi, gdi_rop3_code(dstblt->bRop));
301
 
 
302
 
        XSetFillStyle(xfi->display, xfi->gc, FillSolid);
303
 
        XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
302
        xfContext* xfc = (xfContext*) context;
 
303
 
 
304
        xf_lock_x11(xfc, FALSE);
 
305
 
 
306
        xf_set_rop3(xfc, gdi_rop3_code(dstblt->bRop));
 
307
 
 
308
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
309
        XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
304
310
                        dstblt->nLeftRect, dstblt->nTopRect,
305
311
                        dstblt->nWidth, dstblt->nHeight);
306
312
 
307
 
        if (xfi->drawing == xfi->primary)
 
313
        if (xfc->drawing == xfc->primary)
308
314
        {
309
 
                if (xfi->remote_app != true)
310
 
                {
311
 
                        XFillRectangle(xfi->display, xfi->drawable, xfi->gc,
312
 
                                dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight);
313
 
                }
314
 
 
315
 
                gdi_InvalidateRegion(xfi->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight);
 
315
                gdi_InvalidateRegion(xfc->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth, dstblt->nHeight);
316
316
        }
317
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
 
317
 
 
318
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
319
 
 
320
        xf_unlock_x11(xfc, FALSE);
318
321
}
319
322
 
320
323
void xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
321
324
{
322
325
        Pixmap pattern;
323
326
        rdpBrush* brush;
324
 
        uint32 foreColor;
325
 
        uint32 backColor;
326
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
 
327
        UINT32 foreColor;
 
328
        UINT32 backColor;
 
329
        xfContext* xfc = (xfContext*) context;
 
330
 
 
331
        xf_lock_x11(xfc, FALSE);
327
332
 
328
333
        brush = &patblt->brush;
329
 
        xf_set_rop3(xfi, gdi_rop3_code(patblt->bRop));
 
334
        xf_set_rop3(xfc, gdi_rop3_code(patblt->bRop));
330
335
 
331
 
        foreColor = freerdp_color_convert_rgb(patblt->foreColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
332
 
        backColor = freerdp_color_convert_rgb(patblt->backColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
 
336
        foreColor = freerdp_color_convert_var(patblt->foreColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
337
        backColor = freerdp_color_convert_var(patblt->backColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
333
338
 
334
339
        if (brush->style == GDI_BS_SOLID)
335
340
        {
336
 
                XSetFillStyle(xfi->display, xfi->gc, FillSolid);
337
 
                XSetForeground(xfi->display, xfi->gc, foreColor);
 
341
                XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
342
                XSetForeground(xfc->display, xfc->gc, foreColor);
338
343
 
339
 
                XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
344
                XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
340
345
                                patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
341
346
        }
 
347
        else if (brush->style == GDI_BS_HATCHED)
 
348
        {
 
349
                pattern = xf_mono_bitmap_new(xfc, 8, 8, GDI_BS_HATCHED_PATTERNS + 8 * brush->hatch);
 
350
 
 
351
                XSetForeground(xfc->display, xfc->gc, backColor);
 
352
                XSetBackground(xfc->display, xfc->gc, foreColor);
 
353
                XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
 
354
                XSetStipple(xfc->display, xfc->gc, pattern);
 
355
                XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
356
 
 
357
                XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
 
358
                patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
 
359
 
 
360
                XFreePixmap(xfc->display, pattern);
 
361
        }
342
362
        else if (brush->style == GDI_BS_PATTERN)
343
363
        {
344
364
                if (brush->bpp > 1)
345
365
                {
346
 
                        pattern = xf_brush_new(xfi, 8, 8, brush->bpp, brush->data);
347
 
 
348
 
                        XSetFillStyle(xfi->display, xfi->gc, FillTiled);
349
 
                        XSetTile(xfi->display, xfi->gc, pattern);
350
 
                        XSetTSOrigin(xfi->display, xfi->gc, brush->x, brush->y);
351
 
 
352
 
                        XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
366
                        pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data);
 
367
 
 
368
                        XSetFillStyle(xfc->display, xfc->gc, FillTiled);
 
369
                        XSetTile(xfc->display, xfc->gc, pattern);
 
370
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
371
 
 
372
                        XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
353
373
                                        patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
354
374
 
355
 
                        XSetTile(xfi->display, xfi->gc, xfi->primary);
 
375
                        XSetTile(xfc->display, xfc->gc, xfc->primary);
356
376
 
357
 
                        XFreePixmap(xfi->display, pattern);
 
377
                        XFreePixmap(xfc->display, pattern);
358
378
                }
359
379
                else
360
380
                {
361
 
                        pattern = xf_mono_bitmap_new(xfi, 8, 8, brush->data);
362
 
 
363
 
                        XSetForeground(xfi->display, xfi->gc, backColor);
364
 
                        XSetBackground(xfi->display, xfi->gc, foreColor);
365
 
                        XSetFillStyle(xfi->display, xfi->gc, FillOpaqueStippled);
366
 
                        XSetStipple(xfi->display, xfi->gc, pattern);
367
 
                        XSetTSOrigin(xfi->display, xfi->gc, brush->x, brush->y);
368
 
 
369
 
                        XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
381
                        pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
 
382
 
 
383
                        XSetForeground(xfc->display, xfc->gc, backColor);
 
384
                        XSetBackground(xfc->display, xfc->gc, foreColor);
 
385
                        XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
 
386
                        XSetStipple(xfc->display, xfc->gc, pattern);
 
387
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
388
 
 
389
                        XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
370
390
                                        patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
371
391
 
372
 
                        XFreePixmap(xfi->display, pattern);
 
392
                        XFreePixmap(xfc->display, pattern);
373
393
                }
374
394
        }
375
395
        else
376
396
        {
377
 
                printf("unimplemented brush style:%d\n", brush->style);
 
397
                fprintf(stderr, "unimplemented brush style:%d\n", brush->style);
378
398
        }
379
399
 
380
 
        if (xfi->drawing == xfi->primary)
 
400
        if (xfc->drawing == xfc->primary)
381
401
        {
382
 
                XSetFunction(xfi->display, xfi->gc, GXcopy);
383
 
 
384
 
                if (xfi->remote_app != true)
385
 
                {
386
 
                        XCopyArea(xfi->display, xfi->primary, xfi->drawable, xfi->gc, patblt->nLeftRect, patblt->nTopRect,
387
 
                                patblt->nWidth, patblt->nHeight, patblt->nLeftRect, patblt->nTopRect);
388
 
                }
389
 
 
390
 
                gdi_InvalidateRegion(xfi->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
 
402
                gdi_InvalidateRegion(xfc->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth, patblt->nHeight);
391
403
        }
392
404
 
393
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
 
405
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
406
 
 
407
        xf_unlock_x11(xfc, FALSE);
394
408
}
395
409
 
396
410
void xf_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt)
397
411
{
398
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
399
 
 
400
 
        xf_set_rop3(xfi, gdi_rop3_code(scrblt->bRop));
401
 
 
402
 
        XCopyArea(xfi->display, xfi->primary, xfi->drawing, xfi->gc, scrblt->nXSrc, scrblt->nYSrc,
 
412
        xfContext* xfc = (xfContext*) context;
 
413
 
 
414
        xf_lock_x11(xfc, FALSE);
 
415
 
 
416
        xf_set_rop3(xfc, gdi_rop3_code(scrblt->bRop));
 
417
 
 
418
        XCopyArea(xfc->display, xfc->primary, xfc->drawing, xfc->gc, scrblt->nXSrc, scrblt->nYSrc,
403
419
                        scrblt->nWidth, scrblt->nHeight, scrblt->nLeftRect, scrblt->nTopRect);
404
420
 
405
 
        if (xfi->drawing == xfi->primary)
 
421
        if (xfc->drawing == xfc->primary)
406
422
        {
407
 
                if (xfi->remote_app != true)
408
 
                {
409
 
                        if (xfi->unobscured)
410
 
                        {
411
 
                                XCopyArea(xfi->display, xfi->drawable, xfi->drawable, xfi->gc,
412
 
                                                scrblt->nXSrc, scrblt->nYSrc, scrblt->nWidth, scrblt->nHeight,
413
 
                                                scrblt->nLeftRect, scrblt->nTopRect);
414
 
                        }
415
 
                        else
416
 
                        {
417
 
                                XSetFunction(xfi->display, xfi->gc, GXcopy);
418
 
                                XCopyArea(xfi->display, xfi->primary, xfi->drawable, xfi->gc,
419
 
                                                scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight,
420
 
                                                scrblt->nLeftRect, scrblt->nTopRect);
421
 
                        }
422
 
                }
423
 
 
424
 
                gdi_InvalidateRegion(xfi->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight);
 
423
                gdi_InvalidateRegion(xfc->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth, scrblt->nHeight);
425
424
        }
426
425
 
427
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
 
426
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
427
 
 
428
        xf_unlock_x11(xfc, FALSE);
428
429
}
429
430
 
430
431
void xf_gdi_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect)
431
432
{
432
 
        uint32 color;
433
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
434
 
 
435
 
        color = freerdp_color_convert_var(opaque_rect->color, xfi->srcBpp, xfi->bpp, xfi->clrconv);
436
 
 
437
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
438
 
        XSetFillStyle(xfi->display, xfi->gc, FillSolid);
439
 
        XSetForeground(xfi->display, xfi->gc, color);
440
 
 
441
 
        XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
433
        UINT32 color;
 
434
        xfContext* xfc = (xfContext*) context;
 
435
 
 
436
        xf_lock_x11(xfc, FALSE);
 
437
 
 
438
        color = freerdp_color_convert_var(opaque_rect->color, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
439
 
 
440
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
441
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
442
        XSetForeground(xfc->display, xfc->gc, color);
 
443
 
 
444
        XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
442
445
                        opaque_rect->nLeftRect, opaque_rect->nTopRect,
443
446
                        opaque_rect->nWidth, opaque_rect->nHeight);
444
447
 
445
 
        if (xfi->drawing == xfi->primary)
 
448
        if (xfc->drawing == xfc->primary)
446
449
        {
447
 
                if (xfi->remote_app != true)
448
 
                {
449
 
                        XFillRectangle(xfi->display, xfi->drawable, xfi->gc,
450
 
                                opaque_rect->nLeftRect, opaque_rect->nTopRect, opaque_rect->nWidth, opaque_rect->nHeight);
451
 
                }
452
 
 
453
 
                gdi_InvalidateRegion(xfi->hdc, opaque_rect->nLeftRect, opaque_rect->nTopRect,
 
450
                gdi_InvalidateRegion(xfc->hdc, opaque_rect->nLeftRect, opaque_rect->nTopRect,
454
451
                                opaque_rect->nWidth, opaque_rect->nHeight);
455
452
        }
 
453
 
 
454
        xf_unlock_x11(xfc, FALSE);
456
455
}
457
456
 
458
457
void xf_gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
459
458
{
460
459
        int i;
461
 
        uint32 color;
 
460
        UINT32 color;
462
461
        DELTA_RECT* rectangle;
463
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
464
 
 
465
 
        color = freerdp_color_convert_var(multi_opaque_rect->color, xfi->srcBpp, xfi->bpp, xfi->clrconv);
466
 
 
467
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
468
 
        XSetFillStyle(xfi->display, xfi->gc, FillSolid);
469
 
        XSetForeground(xfi->display, xfi->gc, color);
 
462
        xfContext* xfc = (xfContext*) context;
 
463
 
 
464
        xf_lock_x11(xfc, FALSE);
 
465
 
 
466
        color = freerdp_color_convert_var(multi_opaque_rect->color, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
467
 
 
468
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
469
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
470
        XSetForeground(xfc->display, xfc->gc, color);
470
471
 
471
472
        for (i = 1; i < multi_opaque_rect->numRectangles + 1; i++)
472
473
        {
473
474
                rectangle = &multi_opaque_rect->rectangles[i];
474
475
 
475
 
                XFillRectangle(xfi->display, xfi->drawing, xfi->gc,
 
476
                XFillRectangle(xfc->display, xfc->drawing, xfc->gc,
476
477
                                rectangle->left, rectangle->top,
477
478
                                rectangle->width, rectangle->height);
478
479
 
479
 
                if (xfi->drawing == xfi->primary)
 
480
                if (xfc->drawing == xfc->primary)
480
481
                {
481
 
                        if (xfi->remote_app != true)
482
 
                        {
483
 
                                XFillRectangle(xfi->display, xfi->drawable, xfi->gc,
484
 
                                        rectangle->left, rectangle->top, rectangle->width, rectangle->height);
485
 
                        }
486
 
 
487
 
                        gdi_InvalidateRegion(xfi->hdc, rectangle->left, rectangle->top, rectangle->width, rectangle->height);
 
482
                        gdi_InvalidateRegion(xfc->hdc, rectangle->left, rectangle->top, rectangle->width, rectangle->height);
488
483
                }
489
484
        }
 
485
 
 
486
        xf_unlock_x11(xfc, FALSE);
 
487
}
 
488
 
 
489
void xf_gdi_draw_nine_grid(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid)
 
490
{
 
491
        fprintf(stderr, "DrawNineGrid\n");
490
492
}
491
493
 
492
494
void xf_gdi_line_to(rdpContext* context, LINE_TO_ORDER* line_to)
493
495
{
494
 
        uint32 color;
495
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
496
 
 
497
 
        xf_set_rop2(xfi, line_to->bRop2);
498
 
        color = freerdp_color_convert_rgb(line_to->penColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
499
 
 
500
 
        XSetFillStyle(xfi->display, xfi->gc, FillSolid);
501
 
        XSetForeground(xfi->display, xfi->gc, color);
502
 
 
503
 
        XDrawLine(xfi->display, xfi->drawing, xfi->gc,
 
496
        UINT32 color;
 
497
        xfContext* xfc = (xfContext*) context;
 
498
 
 
499
        xf_lock_x11(xfc, FALSE);
 
500
 
 
501
        xf_set_rop2(xfc, line_to->bRop2);
 
502
        color = freerdp_color_convert_var(line_to->penColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
503
 
 
504
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
505
        XSetForeground(xfc->display, xfc->gc, color);
 
506
 
 
507
        XDrawLine(xfc->display, xfc->drawing, xfc->gc,
504
508
                        line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd);
505
509
 
506
 
        if (xfi->drawing == xfi->primary)
 
510
        if (xfc->drawing == xfc->primary)
507
511
        {
508
512
                int width, height;
509
513
 
510
 
                if (xfi->remote_app != true)
511
 
                {
512
 
                        XDrawLine(xfi->display, xfi->drawable, xfi->gc,
513
 
                                line_to->nXStart, line_to->nYStart, line_to->nXEnd, line_to->nYEnd);
514
 
                }
515
 
 
516
514
                width = line_to->nXStart - line_to->nXEnd;
517
515
                height = line_to->nYStart - line_to->nYEnd;
518
516
 
522
520
                if (height < 0)
523
521
                        height *= (-1);
524
522
 
525
 
                gdi_InvalidateRegion(xfi->hdc, line_to->nXStart, line_to->nYStart, width, height);
 
523
                gdi_InvalidateRegion(xfc->hdc, line_to->nXStart, line_to->nYStart, width, height);
526
524
 
527
525
        }
528
526
 
529
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
 
527
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
528
 
 
529
        xf_unlock_x11(xfc, FALSE);
530
530
}
531
531
 
532
532
void xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline)
536
536
        int x1, y1;
537
537
        int x2, y2;
538
538
        int npoints;
539
 
        uint32 color;
 
539
        UINT32 color;
540
540
        XPoint* points;
541
541
        int width, height;
542
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
543
 
 
544
 
        xf_set_rop2(xfi, polyline->bRop2);
545
 
        color = freerdp_color_convert_rgb(polyline->penColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
546
 
 
547
 
        XSetFillStyle(xfi->display, xfi->gc, FillSolid);
548
 
        XSetForeground(xfi->display, xfi->gc, color);
 
542
        xfContext* xfc = (xfContext*) context;
 
543
 
 
544
        xf_lock_x11(xfc, FALSE);
 
545
 
 
546
        xf_set_rop2(xfc, polyline->bRop2);
 
547
        color = freerdp_color_convert_var(polyline->penColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
548
 
 
549
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
550
        XSetForeground(xfc->display, xfc->gc, color);
549
551
 
550
552
        npoints = polyline->numPoints + 1;
551
 
        points = xmalloc(sizeof(XPoint) * npoints);
 
553
        points = malloc(sizeof(XPoint) * npoints);
552
554
 
553
555
        points[0].x = polyline->xStart;
554
556
        points[0].y = polyline->yStart;
559
561
                points[i + 1].y = polyline->points[i].y;
560
562
        }
561
563
 
562
 
        XDrawLines(xfi->display, xfi->drawing, xfi->gc, points, npoints, CoordModePrevious);
 
564
        XDrawLines(xfc->display, xfc->drawing, xfc->gc, points, npoints, CoordModePrevious);
563
565
 
564
 
        if (xfi->drawing == xfi->primary)
 
566
        if (xfc->drawing == xfc->primary)
565
567
        {
566
 
                if (xfi->remote_app != true)
567
 
                        XDrawLines(xfi->display, xfi->drawable, xfi->gc, points, npoints, CoordModePrevious);
568
 
 
569
568
                x1 = points[0].x;
570
569
                y1 = points[0].y;
571
570
 
583
582
                        x1 = x2;
584
583
                        y1 = y2;
585
584
 
586
 
                        gdi_InvalidateRegion(xfi->hdc, x, y, width, height);
 
585
                        gdi_InvalidateRegion(xfc->hdc, x, y, width, height);
587
586
                }
588
587
        }
589
588
 
590
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
591
 
        xfree(points);
 
589
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
590
        free(points);
 
591
 
 
592
        xf_unlock_x11(xfc, FALSE);
592
593
}
593
594
 
594
595
void xf_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
595
596
{
596
597
        xfBitmap* bitmap;
597
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
 
598
        xfContext* xfc = (xfContext*) context;
 
599
 
 
600
        xf_lock_x11(xfc, FALSE);
598
601
 
599
602
        bitmap = (xfBitmap*) memblt->bitmap;
600
 
        xf_set_rop3(xfi, gdi_rop3_code(memblt->bRop));
 
603
        xf_set_rop3(xfc, gdi_rop3_code(memblt->bRop));
601
604
 
602
 
        XCopyArea(xfi->display, bitmap->pixmap, xfi->drawing, xfi->gc,
 
605
        XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc,
603
606
                        memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight,
604
607
                        memblt->nLeftRect, memblt->nTopRect);
605
608
 
606
 
        if (xfi->drawing == xfi->primary)
 
609
        if (xfc->drawing == xfc->primary)
607
610
        {
608
 
                if (xfi->remote_app != true)
609
 
                {
610
 
                        XCopyArea(xfi->display, bitmap->pixmap, xfi->drawable, xfi->gc,
611
 
                                memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight,
612
 
                                memblt->nLeftRect, memblt->nTopRect);
613
 
                }
614
 
 
615
 
                gdi_InvalidateRegion(xfi->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth, memblt->nHeight);
 
611
                gdi_InvalidateRegion(xfc->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth, memblt->nHeight);
616
612
        }
617
613
 
618
 
        XSetFunction(xfi->display, xfi->gc, GXcopy);
 
614
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
615
 
 
616
        xf_unlock_x11(xfc, FALSE);
619
617
}
620
618
 
621
619
void xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
622
620
{
623
 
 
 
621
        rdpBrush* brush;
 
622
        xfBitmap* bitmap;
 
623
        UINT32 foreColor;
 
624
        UINT32 backColor;
 
625
        Pixmap pattern = 0;
 
626
        xfContext* xfc = (xfContext*) context;
 
627
 
 
628
        xf_lock_x11(xfc, FALSE);
 
629
 
 
630
        brush = &mem3blt->brush;
 
631
        bitmap = (xfBitmap*) mem3blt->bitmap;
 
632
        xf_set_rop3(xfc, gdi_rop3_code(mem3blt->bRop));
 
633
        foreColor = freerdp_color_convert_var(mem3blt->foreColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
634
        backColor = freerdp_color_convert_var(mem3blt->backColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
635
 
 
636
        if (brush->style == GDI_BS_PATTERN)
 
637
        {
 
638
                if (brush->bpp > 1)
 
639
                {
 
640
                        pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data);
 
641
 
 
642
                        XSetFillStyle(xfc->display, xfc->gc, FillTiled);
 
643
                        XSetTile(xfc->display, xfc->gc, pattern);
 
644
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
645
                }
 
646
                else
 
647
                {
 
648
                        pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
 
649
 
 
650
                        XSetForeground(xfc->display, xfc->gc, backColor);
 
651
                        XSetBackground(xfc->display, xfc->gc, foreColor);
 
652
                        XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
 
653
                        XSetStipple(xfc->display, xfc->gc, pattern);
 
654
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
655
                }
 
656
        }
 
657
        else if (brush->style == GDI_BS_SOLID)
 
658
        {
 
659
                XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
660
                XSetForeground(xfc->display, xfc->gc, backColor);
 
661
                XSetBackground(xfc->display, xfc->gc, foreColor);
 
662
 
 
663
                XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
664
        }
 
665
        else
 
666
        {
 
667
                fprintf(stderr, "Mem3Blt unimplemented brush style:%d\n", brush->style);
 
668
        }
 
669
 
 
670
        XCopyArea(xfc->display, bitmap->pixmap, xfc->drawing, xfc->gc,
 
671
                        mem3blt->nXSrc, mem3blt->nYSrc, mem3blt->nWidth, mem3blt->nHeight,
 
672
                        mem3blt->nLeftRect, mem3blt->nTopRect);
 
673
 
 
674
        if (xfc->drawing == xfc->primary)
 
675
        {
 
676
                gdi_InvalidateRegion(xfc->hdc, mem3blt->nLeftRect, mem3blt->nTopRect, mem3blt->nWidth, mem3blt->nHeight);
 
677
        }
 
678
 
 
679
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
680
        XSetTSOrigin(xfc->display, xfc->gc, 0, 0);
 
681
 
 
682
        if (pattern != 0)
 
683
                XFreePixmap(xfc->display, pattern);
 
684
 
 
685
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
686
 
 
687
        xf_unlock_x11(xfc, FALSE);
 
688
}
 
689
 
 
690
void xf_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc)
 
691
{
 
692
        int i, npoints;
 
693
        XPoint* points;
 
694
        UINT32 brush_color;
 
695
        xfContext* xfc = (xfContext*) context;
 
696
 
 
697
        xf_lock_x11(xfc, FALSE);
 
698
 
 
699
        xf_set_rop2(xfc, polygon_sc->bRop2);
 
700
        brush_color = freerdp_color_convert_var(polygon_sc->brushColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
701
 
 
702
        npoints = polygon_sc->numPoints + 1;
 
703
        points = malloc(sizeof(XPoint) * npoints);
 
704
 
 
705
        points[0].x = polygon_sc->xStart;
 
706
        points[0].y = polygon_sc->yStart;
 
707
 
 
708
        for (i = 0; i < polygon_sc->numPoints; i++)
 
709
        {
 
710
                points[i + 1].x = polygon_sc->points[i].x;
 
711
                points[i + 1].y = polygon_sc->points[i].y;
 
712
        }
 
713
 
 
714
        switch (polygon_sc->fillMode)
 
715
        {
 
716
                case 1: /* alternate */
 
717
                        XSetFillRule(xfc->display, xfc->gc, EvenOddRule);
 
718
                        break;
 
719
 
 
720
                case 2: /* winding */
 
721
                        XSetFillRule(xfc->display, xfc->gc, WindingRule);
 
722
                        break;
 
723
 
 
724
                default:
 
725
                        fprintf(stderr, "PolygonSC unknown fillMode: %d\n", polygon_sc->fillMode);
 
726
                        break;
 
727
        }
 
728
 
 
729
        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
730
        XSetForeground(xfc->display, xfc->gc, brush_color);
 
731
 
 
732
        XFillPolygon(xfc->display, xfc->drawing, xfc->gc,
 
733
                        points, npoints, Complex, CoordModePrevious);
 
734
 
 
735
        if (xfc->drawing == xfc->primary)
 
736
        {
 
737
                XFillPolygon(xfc->display, xfc->drawable, xfc->gc,
 
738
                                points, npoints, Complex, CoordModePrevious);
 
739
        }
 
740
 
 
741
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
742
        free(points);
 
743
 
 
744
        xf_unlock_x11(xfc, FALSE);
 
745
}
 
746
 
 
747
void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
 
748
{
 
749
        int i, npoints;
 
750
        XPoint* points;
 
751
        Pixmap pattern;
 
752
        rdpBrush* brush;
 
753
        UINT32 foreColor;
 
754
        UINT32 backColor;
 
755
        xfContext* xfc = (xfContext*) context;
 
756
 
 
757
        xf_lock_x11(xfc, FALSE);
 
758
 
 
759
        brush = &(polygon_cb->brush);
 
760
        xf_set_rop2(xfc, polygon_cb->bRop2);
 
761
        foreColor = freerdp_color_convert_var(polygon_cb->foreColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
762
        backColor = freerdp_color_convert_var(polygon_cb->backColor, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);
 
763
 
 
764
        npoints = polygon_cb->numPoints + 1;
 
765
        points = malloc(sizeof(XPoint) * npoints);
 
766
 
 
767
        points[0].x = polygon_cb->xStart;
 
768
        points[0].y = polygon_cb->yStart;
 
769
 
 
770
        for (i = 0; i < polygon_cb->numPoints; i++)
 
771
        {
 
772
                points[i + 1].x = polygon_cb->points[i].x;
 
773
                points[i + 1].y = polygon_cb->points[i].y;
 
774
        }
 
775
 
 
776
        switch (polygon_cb->fillMode)
 
777
        {
 
778
                case 1: /* alternate */
 
779
                        XSetFillRule(xfc->display, xfc->gc, EvenOddRule);
 
780
                        break;
 
781
 
 
782
                case 2: /* winding */
 
783
                        XSetFillRule(xfc->display, xfc->gc, WindingRule);
 
784
                        break;
 
785
 
 
786
                default:
 
787
                        fprintf(stderr, "PolygonCB unknown fillMode: %d\n", polygon_cb->fillMode);
 
788
                        break;
 
789
        }
 
790
 
 
791
        if (brush->style == GDI_BS_PATTERN)
 
792
        {
 
793
                if (brush->bpp > 1)
 
794
                {
 
795
                        pattern = xf_brush_new(xfc, 8, 8, brush->bpp, brush->data);
 
796
 
 
797
                        XSetFillStyle(xfc->display, xfc->gc, FillTiled);
 
798
                        XSetTile(xfc->display, xfc->gc, pattern);
 
799
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
800
 
 
801
                        XFillPolygon(xfc->display, xfc->drawing, xfc->gc,
 
802
                                        points, npoints, Complex, CoordModePrevious);
 
803
 
 
804
                        if (xfc->drawing == xfc->primary)
 
805
                        {
 
806
                                XFillPolygon(xfc->display, xfc->drawable, xfc->gc,
 
807
                                                points, npoints, Complex, CoordModePrevious);
 
808
                        }
 
809
 
 
810
                        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
811
                        XSetTSOrigin(xfc->display, xfc->gc, 0, 0);
 
812
                        XFreePixmap(xfc->display, pattern);
 
813
                }
 
814
                else
 
815
                {
 
816
                        pattern = xf_mono_bitmap_new(xfc, 8, 8, brush->data);
 
817
 
 
818
                        XSetForeground(xfc->display, xfc->gc, backColor);
 
819
                        XSetBackground(xfc->display, xfc->gc, foreColor);
 
820
 
 
821
                        if (polygon_cb->backMode == BACKMODE_TRANSPARENT)
 
822
                                XSetFillStyle(xfc->display, xfc->gc, FillStippled);
 
823
                        else if (polygon_cb->backMode == BACKMODE_OPAQUE)
 
824
                                XSetFillStyle(xfc->display, xfc->gc, FillOpaqueStippled);
 
825
 
 
826
                        XSetStipple(xfc->display, xfc->gc, pattern);
 
827
                        XSetTSOrigin(xfc->display, xfc->gc, brush->x, brush->y);
 
828
 
 
829
                        XFillPolygon(xfc->display, xfc->drawing, xfc->gc,
 
830
                                        points, npoints, Complex, CoordModePrevious);
 
831
 
 
832
                        if (xfc->drawing == xfc->primary)
 
833
                        {
 
834
                                XFillPolygon(xfc->display, xfc->drawable, xfc->gc,
 
835
                                                points, npoints, Complex, CoordModePrevious);
 
836
                        }
 
837
 
 
838
                        XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
839
                        XSetTSOrigin(xfc->display, xfc->gc, 0, 0);
 
840
                        XFreePixmap(xfc->display, pattern);
 
841
                }
 
842
        }
 
843
        else
 
844
        {
 
845
                fprintf(stderr, "PolygonCB unimplemented brush style:%d\n", brush->style);
 
846
        }
 
847
 
 
848
        XSetFunction(xfc->display, xfc->gc, GXcopy);
 
849
        free(points);
 
850
 
 
851
        xf_unlock_x11(xfc, FALSE);
 
852
}
 
853
 
 
854
void xf_gdi_ellipse_sc(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc)
 
855
{
 
856
        fprintf(stderr, "EllipseSC\n");
 
857
}
 
858
 
 
859
void xf_gdi_ellipse_cb(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb)
 
860
{
 
861
        fprintf(stderr, "EllipseCB\n");
624
862
}
625
863
 
626
864
void xf_gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker)
627
865
{
628
 
 
 
866
        rdpSettings* settings;
 
867
        xfContext* xfc = (xfContext*) context;
 
868
 
 
869
        settings = xfc->instance->settings;
 
870
 
 
871
        xf_lock_x11(xfc, FALSE);
 
872
 
 
873
        switch (surface_frame_marker->frameAction)
 
874
        {
 
875
                case SURFACECMD_FRAMEACTION_BEGIN:
 
876
                        xfc->frame_begin = TRUE;
 
877
                        xfc->frame_x1 = 0;
 
878
                        xfc->frame_y1 = 0;
 
879
                        xfc->frame_x2 = 0;
 
880
                        xfc->frame_y2 = 0;
 
881
                        break;
 
882
 
 
883
                case SURFACECMD_FRAMEACTION_END:
 
884
                        xfc->frame_begin = FALSE;
 
885
                        if ((xfc->frame_x2 > xfc->frame_x1) && (xfc->frame_y2 > xfc->frame_y1))
 
886
                        {
 
887
                                gdi_InvalidateRegion(xfc->hdc, xfc->frame_x1, xfc->frame_y1,
 
888
                                        xfc->frame_x2 - xfc->frame_x1, xfc->frame_y2 - xfc->frame_y1);
 
889
                        }
 
890
                        if (settings->FrameAcknowledge > 0)
 
891
                        {
 
892
                                IFCALL(xfc->instance->update->SurfaceFrameAcknowledge, context, surface_frame_marker->frameId);
 
893
                        }
 
894
                        break;
 
895
        }
 
896
 
 
897
        xf_unlock_x11(xfc, FALSE);
 
898
}
 
899
 
 
900
static void xf_gdi_surface_update_frame(xfContext* xfc, UINT16 tx, UINT16 ty, UINT16 width, UINT16 height)
 
901
{
 
902
        if (!xfc->remote_app)
 
903
        {
 
904
                if (xfc->frame_begin)
 
905
                {
 
906
                        if (xfc->frame_x2 > xfc->frame_x1 && xfc->frame_y2 > xfc->frame_y1)
 
907
                        {
 
908
                                xfc->frame_x1 = MIN(xfc->frame_x1, tx);
 
909
                                xfc->frame_y1 = MIN(xfc->frame_y1, ty);
 
910
                                xfc->frame_x2 = MAX(xfc->frame_x2, tx + width);
 
911
                                xfc->frame_y2 = MAX(xfc->frame_y2, ty + height);
 
912
                        }
 
913
                        else
 
914
                        {
 
915
                                xfc->frame_x1 = tx;
 
916
                                xfc->frame_y1 = ty;
 
917
                                xfc->frame_x2 = tx + width;
 
918
                                xfc->frame_y2 = ty + height;
 
919
                        }
 
920
                }
 
921
                else
 
922
                {
 
923
                        gdi_InvalidateRegion(xfc->hdc, tx, ty, width, height);
 
924
                }
 
925
        }
 
926
        else
 
927
        {
 
928
                gdi_InvalidateRegion(xfc->hdc, tx, ty, width, height);
 
929
        }
629
930
}
630
931
 
631
932
void xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_command)
633
934
        int i, tx, ty;
634
935
        XImage* image;
635
936
        RFX_MESSAGE* message;
636
 
        xfInfo* xfi = ((xfContext*) context)->xfi;
637
 
        RFX_CONTEXT* rfx_context = (RFX_CONTEXT*) xfi->rfx_context;
638
 
        NSC_CONTEXT* nsc_context = (NSC_CONTEXT*) xfi->nsc_context;
639
 
 
640
 
        if (surface_bits_command->codecID == CODEC_ID_REMOTEFX)
 
937
        xfContext* xfc = (xfContext*) context;
 
938
        RFX_CONTEXT* rfx_context = (RFX_CONTEXT*) xfc->rfx_context;
 
939
        NSC_CONTEXT* nsc_context = (NSC_CONTEXT*) xfc->nsc_context;
 
940
 
 
941
        xf_lock_x11(xfc, FALSE);
 
942
 
 
943
        if (surface_bits_command->codecID == RDP_CODEC_ID_REMOTEFX)
641
944
        {
642
945
                message = rfx_process_message(rfx_context,
643
946
                                surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
644
947
 
645
 
                XSetFunction(xfi->display, xfi->gc, GXcopy);
646
 
                XSetFillStyle(xfi->display, xfi->gc, FillSolid);
 
948
                XSetFunction(xfc->display, xfc->gc, GXcopy);
 
949
                XSetFillStyle(xfc->display, xfc->gc, FillSolid);
647
950
 
648
 
                XSetClipRectangles(xfi->display, xfi->gc,
 
951
                XSetClipRectangles(xfc->display, xfc->gc,
649
952
                                surface_bits_command->destLeft, surface_bits_command->destTop,
650
953
                                (XRectangle*) message->rects, message->num_rects, YXBanded);
651
954
 
652
955
                /* Draw the tiles to primary surface, each is 64x64. */
653
956
                for (i = 0; i < message->num_tiles; i++)
654
957
                {
655
 
                        image = XCreateImage(xfi->display, xfi->visual, 24, ZPixmap, 0,
 
958
                        image = XCreateImage(xfc->display, xfc->visual, 24, ZPixmap, 0,
656
959
                                (char*) message->tiles[i]->data, 64, 64, 32, 0);
657
960
 
658
961
                        tx = message->tiles[i]->x + surface_bits_command->destLeft;
659
962
                        ty = message->tiles[i]->y + surface_bits_command->destTop;
660
963
 
661
 
                        XPutImage(xfi->display, xfi->primary, xfi->gc, image, 0, 0, tx, ty, 64, 64);
 
964
                        XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0, tx, ty, 64, 64);
662
965
                        XFree(image);
663
966
                }
664
967
 
668
971
                        tx = message->rects[i].x + surface_bits_command->destLeft;
669
972
                        ty = message->rects[i].y + surface_bits_command->destTop;
670
973
 
671
 
                        if (xfi->remote_app != true)
672
 
                        {
673
 
                                XCopyArea(xfi->display, xfi->primary, xfi->drawable, xfi->gc,
674
 
                                                tx, ty, message->rects[i].width, message->rects[i].height, tx, ty);
675
 
                        }
676
 
 
677
 
                        gdi_InvalidateRegion(xfi->hdc, tx, ty, message->rects[i].width, message->rects[i].height);
 
974
                        xf_gdi_surface_update_frame(xfc, tx, ty, message->rects[i].width, message->rects[i].height);
678
975
                }
679
976
 
680
 
                XSetClipMask(xfi->display, xfi->gc, None);
 
977
                XSetClipMask(xfc->display, xfc->gc, None);
681
978
                rfx_message_free(rfx_context, message);
682
979
        }
683
 
        else if (surface_bits_command->codecID == CODEC_ID_NSCODEC)
 
980
        else if (surface_bits_command->codecID == RDP_CODEC_ID_NSCODEC)
684
981
        {
685
 
                nsc_context->width = surface_bits_command->width;
686
 
                nsc_context->height = surface_bits_command->height;
687
 
                nsc_process_message(nsc_context, surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
688
 
                XSetFunction(xfi->display, xfi->gc, GXcopy);
689
 
                XSetFillStyle(xfi->display, xfi->gc, FillSolid);
690
 
 
691
 
                xfi->bmp_codec_nsc = (uint8*) xrealloc(xfi->bmp_codec_nsc,
 
982
                nsc_process_message(nsc_context, surface_bits_command->bpp, surface_bits_command->width, surface_bits_command->height,
 
983
                        surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
 
984
 
 
985
                XSetFunction(xfc->display, xfc->gc, GXcopy);
 
986
                XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
987
 
 
988
                xfc->bmp_codec_nsc = (BYTE*) realloc(xfc->bmp_codec_nsc,
692
989
                                surface_bits_command->width * surface_bits_command->height * 4);
693
990
 
694
 
                freerdp_image_flip(nsc_context->bmpdata, xfi->bmp_codec_nsc,
 
991
                freerdp_image_flip(nsc_context->bmpdata, xfc->bmp_codec_nsc,
695
992
                                surface_bits_command->width, surface_bits_command->height, 32);
696
993
 
697
 
                image = XCreateImage(xfi->display, xfi->visual, 24, ZPixmap, 0,
698
 
                        (char*) xfi->bmp_codec_nsc, surface_bits_command->width, surface_bits_command->height, 32, 0);
699
 
 
700
 
                XPutImage(xfi->display, xfi->primary, xfi->gc, image, 0, 0,
701
 
                                surface_bits_command->destLeft, surface_bits_command->destTop,
702
 
                                surface_bits_command->width, surface_bits_command->height);
703
 
 
704
 
                if (xfi->remote_app != true)
705
 
                {
706
 
                        XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc,
707
 
                                surface_bits_command->destLeft, surface_bits_command->destTop,
708
 
                                surface_bits_command->width, surface_bits_command->height,
709
 
                                surface_bits_command->destLeft, surface_bits_command->destTop);
710
 
                }
711
 
 
712
 
                gdi_InvalidateRegion(xfi->hdc, surface_bits_command->destLeft, surface_bits_command->destTop,
713
 
                                surface_bits_command->width, surface_bits_command->height);
714
 
 
715
 
                XSetClipMask(xfi->display, xfi->gc, None);
716
 
                nsc_context_destroy(nsc_context);
 
994
                image = XCreateImage(xfc->display, xfc->visual, 24, ZPixmap, 0,
 
995
                        (char*) xfc->bmp_codec_nsc, surface_bits_command->width, surface_bits_command->height, 32, 0);
 
996
 
 
997
                XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0,
 
998
                                surface_bits_command->destLeft, surface_bits_command->destTop,
 
999
                                surface_bits_command->width, surface_bits_command->height);
 
1000
                XFree(image);
 
1001
 
 
1002
                xf_gdi_surface_update_frame(xfc,
 
1003
                        surface_bits_command->destLeft, surface_bits_command->destTop,
 
1004
                        surface_bits_command->width, surface_bits_command->height);
 
1005
 
 
1006
                XSetClipMask(xfc->display, xfc->gc, None);
717
1007
        }
718
 
        else if (surface_bits_command->codecID == CODEC_ID_NONE)
 
1008
        else if (surface_bits_command->codecID == RDP_CODEC_ID_NONE)
719
1009
        {
720
 
                XSetFunction(xfi->display, xfi->gc, GXcopy);
721
 
                XSetFillStyle(xfi->display, xfi->gc, FillSolid);
722
 
 
723
 
                xfi->bmp_codec_none = (uint8*) xrealloc(xfi->bmp_codec_none,
724
 
                                surface_bits_command->width * surface_bits_command->height * 4);
725
 
 
726
 
                freerdp_image_flip(surface_bits_command->bitmapData, xfi->bmp_codec_none,
727
 
                                surface_bits_command->width, surface_bits_command->height, 32);
728
 
 
729
 
                image = XCreateImage(xfi->display, xfi->visual, 24, ZPixmap, 0,
730
 
                        (char*) xfi->bmp_codec_none, surface_bits_command->width, surface_bits_command->height, 32, 0);
731
 
 
732
 
                XPutImage(xfi->display, xfi->primary, xfi->gc, image, 0, 0,
733
 
                                surface_bits_command->destLeft, surface_bits_command->destTop,
734
 
                                surface_bits_command->width, surface_bits_command->height);
735
 
 
736
 
                if (xfi->remote_app != true)
737
 
                {
738
 
                        XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc,
739
 
                                surface_bits_command->destLeft, surface_bits_command->destTop,
740
 
                                surface_bits_command->width, surface_bits_command->height,
741
 
                                surface_bits_command->destLeft, surface_bits_command->destTop);
742
 
                }
743
 
 
744
 
                gdi_InvalidateRegion(xfi->hdc, surface_bits_command->destLeft, surface_bits_command->destTop,
745
 
                                surface_bits_command->width, surface_bits_command->height);
746
 
 
747
 
                XSetClipMask(xfi->display, xfi->gc, None);
 
1010
                XSetFunction(xfc->display, xfc->gc, GXcopy);
 
1011
                XSetFillStyle(xfc->display, xfc->gc, FillSolid);
 
1012
 
 
1013
                /* Validate that the data received is large enough */
 
1014
                if ((surface_bits_command->width * surface_bits_command->height * surface_bits_command->bpp / 8) <= (surface_bits_command->bitmapDataLength))
 
1015
                {
 
1016
                        xfc->bmp_codec_none = (BYTE*) realloc(xfc->bmp_codec_none,
 
1017
                                        surface_bits_command->width * surface_bits_command->height * 4);
 
1018
 
 
1019
                        freerdp_image_flip(surface_bits_command->bitmapData, xfc->bmp_codec_none,
 
1020
                                        surface_bits_command->width, surface_bits_command->height, 32);
 
1021
 
 
1022
                        image = XCreateImage(xfc->display, xfc->visual, 24, ZPixmap, 0,
 
1023
                                (char*) xfc->bmp_codec_none, surface_bits_command->width, surface_bits_command->height, 32, 0);
 
1024
 
 
1025
                        XPutImage(xfc->display, xfc->primary, xfc->gc, image, 0, 0,
 
1026
                                        surface_bits_command->destLeft, surface_bits_command->destTop,
 
1027
                                        surface_bits_command->width, surface_bits_command->height);
 
1028
                        XFree(image);
 
1029
 
 
1030
                        xf_gdi_surface_update_frame(xfc,
 
1031
                                surface_bits_command->destLeft, surface_bits_command->destTop,
 
1032
                                surface_bits_command->width, surface_bits_command->height);
 
1033
 
 
1034
                        XSetClipMask(xfc->display, xfc->gc, None);
 
1035
                }
 
1036
                else
 
1037
                {
 
1038
                        fprintf(stderr, "Invalid bitmap size - data is %d bytes for %dx%d\n update", surface_bits_command->bitmapDataLength, surface_bits_command->width, surface_bits_command->height);
 
1039
                }
748
1040
        }
749
1041
        else
750
1042
        {
751
 
                printf("Unsupported codecID %d\n", surface_bits_command->codecID);
 
1043
                fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID);
752
1044
        }
 
1045
 
 
1046
        xf_unlock_x11(xfc, FALSE);
753
1047
}
754
1048
 
755
1049
void xf_gdi_register_update_callbacks(rdpUpdate* update)
777
1071
        primary->GlyphIndex = NULL;
778
1072
        primary->FastIndex = NULL;
779
1073
        primary->FastGlyph = NULL;
780
 
        primary->PolygonSC = NULL;
781
 
        primary->PolygonCB = NULL;
782
 
        primary->EllipseSC = NULL;
783
 
        primary->EllipseCB = NULL;
 
1074
        primary->PolygonSC = xf_gdi_polygon_sc;
 
1075
        primary->PolygonCB = xf_gdi_polygon_cb;
 
1076
        primary->EllipseSC = xf_gdi_ellipse_sc;
 
1077
        primary->EllipseCB = xf_gdi_ellipse_cb;
784
1078
 
785
1079
        update->SurfaceBits = xf_gdi_surface_bits;
786
1080
        update->SurfaceFrameMarker = xf_gdi_surface_frame_marker;