23#include <freerdp/config.h>
30#include <winpr/assert.h>
31#include <winpr/synch.h>
32#include <winpr/print.h>
33#include <winpr/thread.h>
34#include <winpr/stream.h>
35#include <winpr/sysinfo.h>
36#include <winpr/cmdline.h>
37#include <winpr/collections.h>
39#include <freerdp/addin.h>
40#include <freerdp/utils/string.h>
41#include <freerdp/client/channels.h>
44#include "../disp_common.h"
50 DispClientContext* context;
51 UINT32 MaxNumMonitors;
52 UINT32 MaxMonitorAreaFactorA;
53 UINT32 MaxMonitorAreaFactorB;
66 const DWORD level = WLOG_DEBUG;
69 WINPR_ASSERT(callback);
70 WINPR_ASSERT(Monitors || (NumMonitors == 0));
72 DISP_PLUGIN* disp = (DISP_PLUGIN*)callback->plugin;
75 const UINT32 MonitorLayoutSize = DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE;
77 .type = DISPLAY_CONTROL_PDU_TYPE_MONITOR_LAYOUT };
79 wStream* s = Stream_New(
nullptr, header.length);
83 WLog_Print(disp->base.log, WLOG_ERROR,
"Stream_New failed!");
84 return CHANNEL_RC_NO_MEMORY;
87 if ((status = disp_write_header(s, &header)))
89 WLog_Print(disp->base.log, WLOG_ERROR,
"Failed to write header with error %" PRIu32
"!",
94 if (NumMonitors > disp->MaxNumMonitors)
95 NumMonitors = disp->MaxNumMonitors;
97 Stream_Write_UINT32(s, MonitorLayoutSize);
98 Stream_Write_UINT32(s, NumMonitors);
99 WLog_Print(disp->base.log, level,
"NumMonitors=%" PRIu32
"", NumMonitors);
101 for (UINT32 index = 0; index < NumMonitors; index++)
104 current.Width -= (current.Width % 2);
106 if (current.Width < 200)
109 if (current.Width > 8192)
110 current.Width = 8192;
112 if (current.Width % 2)
115 if (current.Height < 200)
116 current.Height = 200;
118 if (current.Height > 8192)
119 current.Height = 8192;
121 Stream_Write_UINT32(s, current.Flags);
122 Stream_Write_INT32(s, current.Left);
123 Stream_Write_INT32(s, current.Top);
124 Stream_Write_UINT32(s, current.Width);
125 Stream_Write_UINT32(s, current.Height);
126 Stream_Write_UINT32(s, current.PhysicalWidth);
127 Stream_Write_UINT32(s, current.PhysicalHeight);
128 Stream_Write_UINT32(s, current.Orientation);
129 Stream_Write_UINT32(s, current.DesktopScaleFactor);
130 Stream_Write_UINT32(s, current.DeviceScaleFactor);
131 WLog_Print(disp->base.log, level,
132 "\t%" PRIu32
" : Flags: 0x%08" PRIX32
" Left/Top: (%" PRId32
",%" PRId32
133 ") W/H=%" PRIu32
"x%" PRIu32
")",
134 index, current.Flags, current.Left, current.Top, current.Width, current.Height);
135 WLog_Print(disp->base.log, level,
136 "\t PhysicalWidth: %" PRIu32
" PhysicalHeight: %" PRIu32
137 " Orientation: %s DesktopScaleFactor=%" PRIu32
" DeviceScaleFactor=%" PRIu32
"",
138 current.PhysicalWidth, current.PhysicalHeight,
139 freerdp_desktop_rotation_flags_to_string(current.Orientation),
140 current.DesktopScaleFactor, current.DeviceScaleFactor);
144 Stream_SealLength(s);
145 status = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
147 Stream_Free(s, TRUE);
158 DISP_PLUGIN* disp =
nullptr;
159 DispClientContext* context =
nullptr;
160 UINT ret = CHANNEL_RC_OK;
162 WINPR_ASSERT(callback);
165 disp = (DISP_PLUGIN*)callback->plugin;
168 context = disp->context;
169 WINPR_ASSERT(context);
171 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
172 return ERROR_INVALID_DATA;
174 Stream_Read_UINT32(s, disp->MaxNumMonitors);
175 Stream_Read_UINT32(s, disp->MaxMonitorAreaFactorA);
176 Stream_Read_UINT32(s, disp->MaxMonitorAreaFactorB);
178 if (context->DisplayControlCaps)
179 ret = context->DisplayControlCaps(context, disp->MaxNumMonitors,
180 disp->MaxMonitorAreaFactorA, disp->MaxMonitorAreaFactorB);
195 WINPR_ASSERT(callback);
198 DISP_PLUGIN* disp = (DISP_PLUGIN*)callback->plugin;
201 if ((error = disp_read_header(s, &header,
nullptr)))
203 WLog_Print(disp->base.log, WLOG_ERROR,
"disp_read_header failed with error %" PRIu32
"!",
210 case DISPLAY_CONTROL_PDU_TYPE_CAPS:
211 return disp_recv_display_control_caps_pdu(callback, s);
214 WLog_Print(disp->base.log, WLOG_ERROR,
"Type %" PRIu32
" not recognized!", header.type);
215 return ERROR_INTERNAL_ERROR;
224static UINT disp_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
227 return disp_recv_pdu(callback, data);
235static UINT disp_on_close(IWTSVirtualChannelCallback* pChannelCallback)
241 DISP_PLUGIN* disp = (DISP_PLUGIN*)callback->plugin;
245 EnterCriticalSection(&disp->lock);
246 if (disp->base.listener_callback->channel_callback == callback)
247 disp->base.listener_callback->channel_callback =
nullptr;
249 LeaveCriticalSection(&disp->lock);
251 return CHANNEL_RC_OK;
263static UINT disp_send_monitor_layout(DispClientContext* context, UINT32 NumMonitors,
266 DISP_PLUGIN* disp =
nullptr;
269 WINPR_ASSERT(context);
271 disp = (DISP_PLUGIN*)context->handle;
274 UINT rc = CHANNEL_RC_NOT_OPEN;
275 EnterCriticalSection(&disp->lock);
276 callback = disp->base.listener_callback->channel_callback;
279 rc = disp_send_display_control_monitor_layout_pdu(callback, NumMonitors, Monitors);
280 LeaveCriticalSection(&disp->lock);
290 WINPR_ATTR_UNUSED rdpContext* rcontext,
291 WINPR_ATTR_UNUSED rdpSettings* settings)
293 DispClientContext* context =
nullptr;
294 DISP_PLUGIN* disp = (DISP_PLUGIN*)base;
297 disp->MaxNumMonitors = 16;
298 disp->MaxMonitorAreaFactorA = 8192;
299 disp->MaxMonitorAreaFactorB = 8192;
300 InitializeCriticalSection(&disp->lock);
302 context = (DispClientContext*)calloc(1,
sizeof(DispClientContext));
305 WLog_Print(base->log, WLOG_ERROR,
"unable to allocate DispClientContext");
306 return CHANNEL_RC_NO_MEMORY;
309 context->handle = (
void*)disp;
310 context->SendMonitorLayout = disp_send_monitor_layout;
312 disp->base.iface.pInterface = disp->context = context;
314 return CHANNEL_RC_OK;
319 DISP_PLUGIN* disp = (DISP_PLUGIN*)base;
323 DeleteCriticalSection(&disp->lock);
327static const IWTSVirtualChannelCallback disp_callbacks = { disp_on_data_received,
329 disp_on_close,
nullptr };
336FREERDP_ENTRY_POINT(UINT VCAPITYPE disp_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
338 return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, DISP_DVC_CHANNEL_NAME,
340 &disp_callbacks, disp_plugin_initialize,
341 disp_plugin_terminated);