/src/FreeRDP/libfreerdp/core/display.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * FreeRDP: A Remote Desktop Protocol Implementation  | 
3  |  |  * Display update notifications  | 
4  |  |  *  | 
5  |  |  * Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>  | 
6  |  |  *  | 
7  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
8  |  |  * you may not use this file except in compliance with the License.  | 
9  |  |  * You may obtain a copy of the License at  | 
10  |  |  *  | 
11  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
12  |  |  *  | 
13  |  |  * Unless required by applicable law or agreed to in writing, software  | 
14  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
15  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
16  |  |  * See the License for the specific language governing permissions and  | 
17  |  |  * limitations under the License.  | 
18  |  |  */  | 
19  |  |  | 
20  |  | #include "display.h"  | 
21  |  |  | 
22  |  | static BOOL display_write_monitor_layout_pdu(wStream* s, UINT32 monitorCount,  | 
23  |  |                                              const MONITOR_DEF* monitorDefArray)  | 
24  | 0  | { | 
25  | 0  |   if (!Stream_EnsureRemainingCapacity(s, 4 + (monitorCount * 20)))  | 
26  | 0  |     return FALSE;  | 
27  |  |  | 
28  | 0  |   Stream_Write_UINT32(s, monitorCount); /* monitorCount (4 bytes) */  | 
29  |  | 
  | 
30  | 0  |   for (UINT32 index = 0; index < monitorCount; index++)  | 
31  | 0  |   { | 
32  | 0  |     const MONITOR_DEF* monitor = &monitorDefArray[index];  | 
33  |  | 
  | 
34  | 0  |     Stream_Write_INT32(s, monitor->left);   /* left (4 bytes) */  | 
35  | 0  |     Stream_Write_INT32(s, monitor->top);    /* top (4 bytes) */  | 
36  | 0  |     Stream_Write_INT32(s, monitor->right);  /* right (4 bytes) */  | 
37  | 0  |     Stream_Write_INT32(s, monitor->bottom); /* bottom (4 bytes) */  | 
38  | 0  |     Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */  | 
39  | 0  |   }  | 
40  |  | 
  | 
41  | 0  |   return TRUE;  | 
42  | 0  | }  | 
43  |  |  | 
44  |  | BOOL display_convert_rdp_monitor_to_monitor_def(UINT32 monitorCount,  | 
45  |  |                                                 const rdpMonitor* monitorDefArray,  | 
46  |  |                                                 MONITOR_DEF** result)  | 
47  | 0  | { | 
48  | 0  |   MONITOR_DEF* mdef = NULL;  | 
49  |  | 
  | 
50  | 0  |   if (!monitorDefArray || !result || (*result))  | 
51  | 0  |     return FALSE;  | 
52  |  |  | 
53  | 0  |   mdef = (MONITOR_DEF*)calloc(monitorCount, sizeof(MONITOR_DEF));  | 
54  |  | 
  | 
55  | 0  |   if (!mdef)  | 
56  | 0  |     return FALSE;  | 
57  |  |  | 
58  | 0  |   for (UINT32 index = 0; index < monitorCount; index++)  | 
59  | 0  |   { | 
60  | 0  |     const rdpMonitor* monitor = &monitorDefArray[index];  | 
61  | 0  |     MONITOR_DEF* current = &mdef[index];  | 
62  |  | 
  | 
63  | 0  |     current->left = monitor->x;                                   /* left (4 bytes) */  | 
64  | 0  |     current->top = monitor->y;                                    /* top (4 bytes) */  | 
65  | 0  |     current->right = monitor->x + monitor->width - 1;             /* right (4 bytes) */  | 
66  | 0  |     current->bottom = monitor->y + monitor->height - 1;           /* bottom (4 bytes) */  | 
67  | 0  |     current->flags = monitor->is_primary ? MONITOR_PRIMARY : 0x0; /* flags (4 bytes) */  | 
68  | 0  |   }  | 
69  |  | 
  | 
70  | 0  |   *result = mdef;  | 
71  | 0  |   return TRUE;  | 
72  | 0  | }  | 
73  |  |  | 
74  |  | BOOL freerdp_display_send_monitor_layout(rdpContext* context, UINT32 monitorCount,  | 
75  |  |                                          const MONITOR_DEF* monitorDefArray)  | 
76  | 0  | { | 
77  | 0  |   rdpRdp* rdp = context->rdp;  | 
78  | 0  |   wStream* st = rdp_data_pdu_init(rdp);  | 
79  |  | 
  | 
80  | 0  |   if (!st)  | 
81  | 0  |     return FALSE;  | 
82  |  |  | 
83  | 0  |   if (!display_write_monitor_layout_pdu(st, monitorCount, monitorDefArray))  | 
84  | 0  |   { | 
85  | 0  |     Stream_Release(st);  | 
86  | 0  |     return FALSE;  | 
87  | 0  |   }  | 
88  |  |  | 
89  | 0  |   return rdp_send_data_pdu(rdp, st, DATA_PDU_TYPE_MONITOR_LAYOUT, 0);  | 
90  | 0  | }  |