19#include <freerdp/config.h>
21#include <winpr/assert.h>
23#include "shadow_surface.h"
25#include "shadow_screen.h"
26#include "shadow_lobby.h"
28rdpShadowScreen* shadow_screen_new(rdpShadowServer* server)
31 WINPR_ASSERT(server->subsystem);
33 rdpShadowScreen* screen = (rdpShadowScreen*)calloc(1,
sizeof(rdpShadowScreen));
38 screen->server = server;
41 rdpShadowSubsystem* subsystem = server->subsystem;
42 if (!InitializeCriticalSectionAndSpinCount(&(screen->lock), 4000))
45 region16_init(&(screen->invalidRegion));
48 WINPR_ASSERT(subsystem->selectedMonitor < ARRAYSIZE(subsystem->monitors));
49 const MONITOR_DEF* primary = &(subsystem->monitors[subsystem->selectedMonitor]);
50 WINPR_ASSERT(primary);
52 const INT64 x = primary->left;
53 const INT64 y = primary->top;
54 const INT64 width = primary->right - primary->left + 1;
55 const INT64 height = primary->bottom - primary->top + 1;
58 WINPR_ASSERT(x <= UINT16_MAX);
60 WINPR_ASSERT(y <= UINT16_MAX);
61 WINPR_ASSERT(width >= 0);
62 WINPR_ASSERT(width <= UINT16_MAX);
63 WINPR_ASSERT(height >= 0);
64 WINPR_ASSERT(height <= UINT16_MAX);
66 screen->width = (UINT16)width;
67 screen->height = (UINT16)height;
70 shadow_surface_new(server, (UINT16)x, (UINT16)y, (UINT16)width, (UINT16)height);
75 server->surface = screen->primary;
78 shadow_surface_new(server, (UINT16)x, (UINT16)y, (UINT16)width, (UINT16)height);
85 server->lobby = screen->lobby;
87 if (!shadow_client_init_lobby(server))
93 WINPR_PRAGMA_DIAG_PUSH
94 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
95 shadow_screen_free(screen);
101void shadow_screen_free(rdpShadowScreen* screen)
106 DeleteCriticalSection(&(screen->lock));
108 region16_uninit(&(screen->invalidRegion));
112 shadow_surface_free(screen->primary);
113 screen->primary = NULL;
118 shadow_surface_free(screen->lobby);
119 screen->lobby = NULL;
125BOOL shadow_screen_resize(rdpShadowScreen* screen)
130 WINPR_ASSERT(screen->server);
132 rdpShadowSubsystem* subsystem = screen->server->subsystem;
133 WINPR_ASSERT(subsystem);
134 WINPR_ASSERT(subsystem->monitors);
136 MONITOR_DEF* primary = &(subsystem->monitors[subsystem->selectedMonitor]);
137 WINPR_ASSERT(primary);
139 const INT32 x = primary->left;
140 const INT32 y = primary->top;
141 const INT32 width = primary->right - primary->left + 1;
142 const INT32 height = primary->bottom - primary->top + 1;
144 WINPR_ASSERT(x >= 0);
145 WINPR_ASSERT(x <= UINT16_MAX);
146 WINPR_ASSERT(y >= 0);
147 WINPR_ASSERT(y <= UINT16_MAX);
148 WINPR_ASSERT(width >= 0);
149 WINPR_ASSERT(width <= UINT16_MAX);
150 WINPR_ASSERT(height >= 0);
151 WINPR_ASSERT(height <= UINT16_MAX);
153 if (shadow_surface_resize(screen->primary, (UINT16)x, (UINT16)y, (UINT16)width,
155 shadow_surface_resize(screen->lobby, (UINT16)x, (UINT16)y, (UINT16)width, (UINT16)height))
157 if (((UINT32)width != screen->width) || ((UINT32)height != screen->height))
160 screen->width = (UINT32)width;
161 screen->height = (UINT32)height;
162 shadow_client_init_lobby(screen->server);