Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dfb_win.c « dfb - github.com/FreeRDP/FreeRDP-old.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac92c57265387413dead831657210e89d0462c78 (plain)
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/*
   FreeRDP: A Remote Desktop Protocol client.
   DirectFB UI Main Window

   Copyright 2010 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.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <directfb.h>
#include <freerdp/chanman.h>
#include <freerdp/types/ui.h>
#include <freerdp/utils/memory.h>
#include "gdi.h"
#include "dfbfreerdp.h"
#include "dfb_win.h"
#include "dfb_keyboard.h"

static void
l_ui_error(struct rdp_inst * inst, const char * text)
{
	printf("ui_error: %s", text);
}

static void
l_ui_warning(struct rdp_inst * inst, const char * text)
{
	printf("ui_warning: %s\n", text);
}

static void
l_ui_unimpl(struct rdp_inst * inst, const char * text)
{
	printf("ui_unimpl: %s\n", text);
}

/* GDI callbacks registered in libfreerdp */

static void
l_ui_gdi_begin_update(struct rdp_inst * inst)
{
	GDI *gdi = GET_GDI(inst);
	gdi->primary->hdc->hwnd->invalid->null = 1;
}

static void
l_ui_gdi_end_update(struct rdp_inst * inst)
{
	dfbInfo *dfbi = GET_DFBI(inst);
	GDI *gdi = GET_GDI(inst);

	if (gdi->primary->hdc->hwnd->invalid->null)
		return;

	dfbi->update_rect.x = gdi->primary->hdc->hwnd->invalid->x;
	dfbi->update_rect.y = gdi->primary->hdc->hwnd->invalid->y;
	dfbi->update_rect.w = gdi->primary->hdc->hwnd->invalid->w;
	dfbi->update_rect.h = gdi->primary->hdc->hwnd->invalid->h;

	dfbi->primary->Blit(dfbi->primary, dfbi->surface, &(dfbi->update_rect), dfbi->update_rect.x, dfbi->update_rect.y);
}

static void
l_ui_begin_update(struct rdp_inst * inst)
{

}

static void
l_ui_end_update(struct rdp_inst * inst)
{

}

static void
l_ui_desktop_save(struct rdp_inst * inst, int offset, int x, int y, int cx, int cy)
{

}

static void
l_ui_desktop_restore(struct rdp_inst * inst, int offset, int x, int y, int cx, int cy)
{

}

static RD_HGLYPH
l_ui_create_glyph(struct rdp_inst * inst, int width, int height, uint8 * data)
{
	return (RD_HGLYPH) NULL;
}

static void
l_ui_destroy_glyph(struct rdp_inst * inst, RD_HGLYPH glyph)
{

}

static RD_HBITMAP
l_ui_create_bitmap(struct rdp_inst * inst, int width, int height, uint8* data)
{
	return (RD_HBITMAP) NULL;
}

static void
l_ui_paint_bitmap(struct rdp_inst * inst, int x, int y, int cx, int cy, int width, int height, uint8 * data)
{

}

static void
l_ui_destroy_bitmap(struct rdp_inst * inst, RD_HBITMAP bmp)
{

}

static void
l_ui_line(struct rdp_inst * inst, uint8 opcode, int startx, int starty, int endx, int endy, RD_PEN * pen)
{

}

static void
l_ui_rect(struct rdp_inst * inst, int x, int y, int cx, int cy, uint32 color)
{

}

static void
l_ui_polygon(struct rdp_inst * inst, uint8 opcode, uint8 fillmode, RD_POINT * point, int npoints, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{

}

static void
l_ui_polyline(struct rdp_inst * inst, uint8 opcode, RD_POINT * points, int npoints, RD_PEN * pen)
{

}

static void
l_ui_ellipse(struct rdp_inst * inst, uint8 opcode, uint8 fillmode, int x, int y, int cx, int cy, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{

}

static void
l_ui_start_draw_glyphs(struct rdp_inst * inst, uint32 bgcolor, uint32 fgcolor)
{

}

static void
l_ui_draw_glyph(struct rdp_inst * inst, int x, int y, int cx, int cy, RD_HGLYPH glyph)
{

}

static void
l_ui_end_draw_glyphs(struct rdp_inst * inst, int x, int y, int cx, int cy)
{

}

static void
l_ui_destblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy)
{

}

static void
l_ui_patblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{

}

static void
l_ui_screenblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy)
{

}

static void
l_ui_memblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src, int srcx, int srcy)
{

}

static void
l_ui_mem3blt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy,
	RD_HBITMAP src, int srcx, int srcy, RD_BRUSH * brush, uint32 bgcolor, uint32 fgcolor)
{

}

static RD_HPALETTE
l_ui_create_palette(struct rdp_inst * inst, RD_PALETTE * palette)
{
	return (RD_HPALETTE) NULL;
}

static void
l_ui_set_palette(struct rdp_inst * inst, RD_HPALETTE palette)
{

}

static void
l_ui_set_clipping_region(struct rdp_inst * inst, int x, int y, int cx, int cy)
{

}

static void
l_ui_reset_clipping_region(struct rdp_inst * inst)
{

}

static RD_HBITMAP
l_ui_create_surface(struct rdp_inst * inst, int width, int height, RD_HBITMAP old_surface)
{
	return (RD_HBITMAP) NULL;
}

static void
l_ui_switch_surface(struct rdp_inst * inst, RD_HBITMAP surface)
{

}

static void
l_ui_destroy_surface(struct rdp_inst * inst, RD_HBITMAP surface)
{

}

static int
l_ui_decode(struct rdp_inst * inst, uint8 * data, int size)
{
	return 0;
}

static uint32
l_ui_get_toggle_keys_state(struct rdp_inst * inst)
{
	return 0;
}

static void
l_ui_bell(struct rdp_inst * inst)
{
}

static int
l_ui_select(struct rdp_inst * inst, int rdp_socket)
{
	return 1;
}

static void
l_ui_resize_window(struct rdp_inst * inst)
{
}

static void
l_ui_set_cursor(struct rdp_inst * inst, RD_HCURSOR cur)
{
	CursorInfo *cursor = (CursorInfo*) cur;
	dfbInfo *dfbi = GET_DFBI(inst);
	dfbi->layer->SetCooperativeLevel(dfbi->layer, DLSCL_ADMINISTRATIVE);
	DFBResult ret = dfbi->layer->SetCursorShape(dfbi->layer, cursor->surface, cursor->hotx, cursor->hoty);

	if (ret != DFB_OK)
		DirectFBErrorFatal("Error SetCursorShape", ret);

	dfbi->layer->SetCooperativeLevel(dfbi->layer, DLSCL_SHARED);
}

static void
l_ui_destroy_cursor(struct rdp_inst * inst, RD_HCURSOR cur)
{
	CursorInfo *cursor = (CursorInfo*) cur;

	if (cursor == NULL)
		return;

	cursor->surface->Release(cursor->surface);
	free(cursor);
}

static RD_HCURSOR
l_ui_create_cursor(struct rdp_inst * inst, uint32 x, uint32 y, int width, int height, uint8 * andmask, uint8 * xormask, int bpp)
{
	DFBResult ret;
	CursorInfo *cursor;
	DFBSurfaceDescription dsc;
	dfbInfo *dfbi = GET_DFBI(inst);
	GDI *gdi = GET_GDI(inst);

	cursor = (CursorInfo*) xmalloc(sizeof(CursorInfo));
	dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
	dsc.caps = DSCAPS_SYSTEMONLY;
	dsc.width = width;
	dsc.height = height;
	dsc.pixelformat = DSPF_ARGB;

	ret = dfbi->dfb->CreateSurface(dfbi->dfb, &dsc, &cursor->surface);

	if (ret == DFB_OK)
	{
		int pitch;
		uint8* point = NULL;

		cursor->hotx = x;
		cursor->hoty = y;

		/* copy the data */
		ret = cursor->surface->Lock(cursor->surface, DSLF_WRITE, (void**) &point, &pitch);

		if (ret != DFB_OK)
			goto out;
    
		gdi_alpha_cursor_convert(point, xormask, andmask, width, height, bpp, gdi->clrconv);
		cursor->surface->Unlock(cursor->surface);
	}

out:
	if (ret != DFB_OK)
	{
		DirectFBErrorFatal("Error create cursor surface", ret);
		return (RD_HCURSOR) NULL;
	}

	return (RD_HCURSOR) cursor;
}

static void
l_ui_set_null_cursor(struct rdp_inst * inst)
{
	dfbInfo *dfbi = GET_DFBI(inst);
	dfbi->layer->EnableCursor(dfbi->layer, 0);
}

static void
l_ui_set_default_cursor(struct rdp_inst * inst)
{
	dfbInfo *dfbi = GET_DFBI(inst);
	dfbi->layer->SetCooperativeLevel(dfbi->layer, DLSCL_ADMINISTRATIVE);
	DFBResult ret = dfbi->layer->SetCursorShape(dfbi->layer, NULL, 0, 0);

	if (ret != DFB_OK)
		DirectFBErrorFatal("Error SetCursorShape", ret);

	dfbi->layer->SetCooperativeLevel(dfbi->layer, DLSCL_SHARED);
}

static void
l_ui_move_pointer(struct rdp_inst * inst, int x, int y)
{
	GDI *gdi = GET_GDI(inst);

	gdi->cursor_x = x;
	gdi->cursor_y = y;

	inst->rdp_send_input_mouse(inst, PTRFLAGS_MOVE, x, y);
}

static void
l_ui_channel_data(struct rdp_inst * inst, int chan_id, char * data, int data_size, int flags, int total_size)
{
	freerdp_chanman_data(inst, chan_id, data, data_size, flags, total_size);
}

static RD_BOOL
l_ui_authenticate(struct rdp_inst * inst)
{
	char * pass;
	int l;

	printf("Please enter credentials for network level authentication.\n");

	printf("User name:");
	if (inst->settings->username[0] == 0)
	{
		if (fgets(inst->settings->username, sizeof(inst->settings->username), stdin) == NULL)
		{
		}
		l = strlen(inst->settings->username);
		if (l > 0 && inst->settings->username[l - 1] == '\n')
			inst->settings->username[l - 1] = 0;
	}
	else
		printf("%s\n", inst->settings->username);

	printf("Domain:");
	if (inst->settings->domain[0] == 0)
	{
		if (fgets(inst->settings->domain, sizeof(inst->settings->domain), stdin) == NULL)
		{
		}
		l = strlen(inst->settings->domain);
		if (l > 0 && inst->settings->domain[l - 1] == '\n')
			inst->settings->domain[l - 1] = 0;
	}
	else
		printf("%s\n", inst->settings->domain);

	if (!inst->settings->password[0])
	{
		pass = getpass("Password:");
		strncpy(inst->settings->password, pass, sizeof(inst->settings->password) - 1);
	}
	return 1;
}

RD_BOOL
l_ui_check_certificate(rdpInst * inst, const char * fingerprint,
	const char * subject, const char * issuer, RD_BOOL verified)
{
	printf("certificate details:\n");
	printf("  Subject:\n    %s\n", subject);
	printf("  Issued by:\n    %s\n", issuer);
	printf("  Fingerprint:\n    %s\n",  fingerprint);

	if (!verified)
		printf("The server could not be authenticated. Connection security may be compromised!\n");

	return 1;
}

static int
dfb_register_callbacks(rdpInst * inst)
{
	inst->ui_begin_update = l_ui_begin_update;
	inst->ui_end_update = l_ui_end_update;
	inst->ui_desktop_save = l_ui_desktop_save;
	inst->ui_desktop_restore = l_ui_desktop_restore;
	inst->ui_create_bitmap = l_ui_create_bitmap;
	inst->ui_paint_bitmap = l_ui_paint_bitmap;
	inst->ui_destroy_bitmap = l_ui_destroy_bitmap;
	inst->ui_line = l_ui_line;
	inst->ui_rect = l_ui_rect;
	inst->ui_polygon = l_ui_polygon;
	inst->ui_polyline = l_ui_polyline;
	inst->ui_ellipse = l_ui_ellipse;
	inst->ui_start_draw_glyphs = l_ui_start_draw_glyphs;
	inst->ui_draw_glyph = l_ui_draw_glyph;
	inst->ui_end_draw_glyphs = l_ui_end_draw_glyphs;
	inst->ui_destblt = l_ui_destblt;
	inst->ui_patblt = l_ui_patblt;
	inst->ui_screenblt = l_ui_screenblt;
	inst->ui_memblt = l_ui_memblt;
	inst->ui_triblt = l_ui_mem3blt;
	inst->ui_create_palette = l_ui_create_palette;
	inst->ui_set_palette = l_ui_set_palette;
	inst->ui_create_glyph = l_ui_create_glyph;
	inst->ui_destroy_glyph = l_ui_destroy_glyph;
	inst->ui_set_clip = l_ui_set_clipping_region;
	inst->ui_reset_clip = l_ui_reset_clipping_region;
	inst->ui_create_surface = l_ui_create_surface;
	inst->ui_set_surface = l_ui_switch_surface;
	inst->ui_destroy_surface = l_ui_destroy_surface;
	inst->ui_error = l_ui_error;
	inst->ui_warning = l_ui_warning;
	inst->ui_unimpl = l_ui_unimpl;
	inst->ui_end_update = l_ui_end_update;
	inst->ui_get_toggle_keys_state = l_ui_get_toggle_keys_state;
	inst->ui_bell = l_ui_bell;
	inst->ui_select = l_ui_select;
	inst->ui_resize_window = l_ui_resize_window;
	inst->ui_set_cursor = l_ui_set_cursor;
	inst->ui_destroy_cursor = l_ui_destroy_cursor;
	inst->ui_create_cursor = l_ui_create_cursor;
	inst->ui_set_null_cursor = l_ui_set_null_cursor;
	inst->ui_set_default_cursor = l_ui_set_default_cursor;
	inst->ui_move_pointer = l_ui_move_pointer;
	inst->ui_channel_data = l_ui_channel_data;
	inst->ui_authenticate = l_ui_authenticate;
	inst->ui_decode = l_ui_decode;
	inst->ui_check_certificate = l_ui_check_certificate;
	return 0;
}

void
dfb_init(int *argc, char *(*argv[]))
{
	DFBResult err;
	err = DirectFBInit(argc, argv);
}

int
dfb_pre_connect(rdpInst * inst)
{
	dfbInfo *dfbi = (dfbInfo *) xmalloc(sizeof(dfbInfo));
	memset(dfbi, 0, sizeof(dfbInfo));
	dfb_register_callbacks(inst);
	SET_DFBI(inst, dfbi);

	return 0;
}

int
dfb_post_connect(rdpInst * inst)
{
	dfbInfo *dfbi = GET_DFBI(inst);

	if (inst->settings->software_gdi == 1)
	{
		GDI *gdi;
		gdi_init(inst, CLRCONV_ALPHA | CLRBUF_16BPP | CLRBUF_32BPP);
		gdi = GET_GDI(inst);

		dfbi->err = DirectFBCreate(&(dfbi->dfb));

		dfbi->dsc.flags = DSDESC_CAPS;
		dfbi->dsc.caps = DSCAPS_PRIMARY;
		dfbi->err = dfbi->dfb->CreateSurface(dfbi->dfb, &(dfbi->dsc), &(dfbi->primary));
		dfbi->err = dfbi->primary->GetSize(dfbi->primary, &(gdi->width), &(gdi->height));
		dfbi->dfb->SetVideoMode(dfbi->dfb, gdi->width, gdi->height, gdi->dstBpp);
		dfbi->dfb->CreateInputEventBuffer(dfbi->dfb, DICAPS_ALL, DFB_TRUE, &(dfbi->event_buffer));
		dfbi->event_buffer->CreateFileDescriptor(dfbi->event_buffer, &(dfbi->read_fds));

		dfbi->dfb->GetDisplayLayer(dfbi->dfb, 0, &(dfbi->layer));
		dfbi->layer->EnableCursor(dfbi->layer, 1);

		dfbi->dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PREALLOCATED | DSDESC_PIXELFORMAT;
		dfbi->dsc.caps = DSCAPS_SYSTEMONLY;
		dfbi->dsc.width = gdi->width;
		dfbi->dsc.height = gdi->height;

		if (gdi->dstBpp == 32 || gdi->dstBpp == 24)
			dfbi->dsc.pixelformat = DSPF_AiRGB;
		else if (gdi->dstBpp == 16 || gdi->dstBpp == 15)
			dfbi->dsc.pixelformat = DSPF_RGB16;
		else if (gdi->dstBpp == 8)
			dfbi->dsc.pixelformat = DSPF_RGB332;
		else
			dfbi->dsc.pixelformat = DSPF_AiRGB;

		dfbi->dsc.preallocated[0].data = gdi->primary_buffer;
		dfbi->dsc.preallocated[0].pitch = gdi->width * gdi->bytesPerPixel;
		dfbi->dfb->CreateSurface(dfbi->dfb, &(dfbi->dsc), &(dfbi->surface));

		inst->ui_begin_update = l_ui_gdi_begin_update;
		inst->ui_end_update = l_ui_gdi_end_update;
	}
	else
	{
		/* DirectFB-specific GDI Implementation */
	}

	return 0;
}

void
dfb_uninit(rdpInst * inst)
{
	dfbInfo *dfbi = GET_DFBI(inst);

	if (inst->settings->software_gdi == 1)
	{
		gdi_free(inst);
		dfbi->primary->Release(dfbi->primary);
		dfbi->dfb->Release(dfbi->dfb);
	}
}

int
dfb_get_fds(rdpInst * inst, void ** read_fds, int * read_count, void ** write_fds, int * write_count)
{
	dfbInfo *dfbi = GET_DFBI(inst);

	read_fds[*read_count] = (void *)(long)(dfbi->read_fds);
	(*read_count)++;

	return 0;
}

int
dfb_check_fds(rdpInst * inst, fd_set *set)
{
	dfbInfo *dfbi = GET_DFBI(inst);

	if (!FD_ISSET(dfbi->read_fds, set))
		return 0;

	if (read(dfbi->read_fds, &(dfbi->event), sizeof(dfbi->event)) > 0)
		dfb_process_event(inst, &(dfbi->event));

	return 0;
}