19 #include <freerdp/config.h>
23 #include "shadow_subsystem.h"
25 static pfnShadowSubsystemEntry pSubsystemEntry = NULL;
27 void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry)
29 pSubsystemEntry = pEntry;
32 static int shadow_subsystem_load_entry_points(RDP_SHADOW_ENTRY_POINTS* pEntryPoints)
34 WINPR_ASSERT(pEntryPoints);
35 ZeroMemory(pEntryPoints,
sizeof(RDP_SHADOW_ENTRY_POINTS));
40 if (pSubsystemEntry(pEntryPoints) < 0)
46 rdpShadowSubsystem* shadow_subsystem_new(
void)
48 RDP_SHADOW_ENTRY_POINTS ep;
49 rdpShadowSubsystem* subsystem = NULL;
51 shadow_subsystem_load_entry_points(&ep);
61 CopyMemory(&(subsystem->ep), &ep,
sizeof(RDP_SHADOW_ENTRY_POINTS));
66 void shadow_subsystem_free(rdpShadowSubsystem* subsystem)
68 if (subsystem && subsystem->ep.Free)
69 subsystem->ep.Free(subsystem);
72 int shadow_subsystem_init(rdpShadowSubsystem* subsystem, rdpShadowServer* server)
76 if (!subsystem || !subsystem->ep.Init)
79 subsystem->server = server;
80 subsystem->selectedMonitor = server->selectedMonitor;
82 if (!(subsystem->MsgPipe = MessagePipe_New()))
85 if (!(subsystem->updateEvent = shadow_multiclient_new()))
88 if ((status = subsystem->ep.Init(subsystem)) >= 0)
92 if (subsystem->MsgPipe)
94 MessagePipe_Free(subsystem->MsgPipe);
95 subsystem->MsgPipe = NULL;
98 if (subsystem->updateEvent)
100 shadow_multiclient_free(subsystem->updateEvent);
101 subsystem->updateEvent = NULL;
107 static void shadow_subsystem_free_queued_message(
void* obj)
109 wMessage* message = (wMessage*)obj;
112 message->Free(message);
113 message->Free = NULL;
117 void shadow_subsystem_uninit(rdpShadowSubsystem* subsystem)
122 if (subsystem->ep.Uninit)
123 subsystem->ep.Uninit(subsystem);
125 if (subsystem->MsgPipe)
130 obj1 = MessageQueue_Object(subsystem->MsgPipe->In);
132 obj1->fnObjectFree = shadow_subsystem_free_queued_message;
133 MessageQueue_Clear(subsystem->MsgPipe->In);
135 obj2 = MessageQueue_Object(subsystem->MsgPipe->Out);
136 obj2->fnObjectFree = shadow_subsystem_free_queued_message;
137 MessageQueue_Clear(subsystem->MsgPipe->Out);
138 MessagePipe_Free(subsystem->MsgPipe);
139 subsystem->MsgPipe = NULL;
142 if (subsystem->updateEvent)
144 shadow_multiclient_free(subsystem->updateEvent);
145 subsystem->updateEvent = NULL;
149 int shadow_subsystem_start(rdpShadowSubsystem* subsystem)
153 if (!subsystem || !subsystem->ep.Start)
156 status = subsystem->ep.Start(subsystem);
161 int shadow_subsystem_stop(rdpShadowSubsystem* subsystem)
165 if (!subsystem || !subsystem->ep.Stop)
168 status = subsystem->ep.Stop(subsystem);
173 UINT32 shadow_enum_monitors(
MONITOR_DEF* monitors, UINT32 maxMonitors)
175 UINT32 numMonitors = 0;
176 RDP_SHADOW_ENTRY_POINTS ep;
178 if (shadow_subsystem_load_entry_points(&ep) < 0)
181 numMonitors = ep.EnumMonitors(monitors, maxMonitors);
192 int shadow_subsystem_pointer_convert_alpha_pointer_data(
193 const BYTE* WINPR_RESTRICT pixels, BOOL premultiplied, UINT32 width, UINT32 height,
196 return shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
197 pixels, PIXEL_FORMAT_BGRX32, premultiplied, width, height, pointerColor);
200 int shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
201 const BYTE* pixels, UINT32 format, BOOL premultiplied, UINT32 width, UINT32 height,
207 BYTE* andBits = NULL;
209 const size_t bpp = FreeRDPGetBytesPerPixel(format);
211 xorStep = (width * 3);
212 xorStep += (xorStep % 2);
214 andStep = ((width + 7) / 8);
215 andStep += (andStep % 2);
217 pointerColor->lengthXorMask = height * xorStep;
218 pointerColor->xorMaskData = (BYTE*)calloc(1, pointerColor->lengthXorMask);
220 if (!pointerColor->xorMaskData)
223 pointerColor->lengthAndMask = height * andStep;
224 pointerColor->andMaskData = (BYTE*)calloc(1, pointerColor->lengthAndMask);
226 if (!pointerColor->andMaskData)
228 free(pointerColor->xorMaskData);
229 pointerColor->xorMaskData = NULL;
233 for (
size_t y = 0; y < height; y++)
235 const BYTE* pSrc8 = &pixels[(width * bpp) * (height - 1 - y)];
236 BYTE* pDst8 = &(pointerColor->xorMaskData[y * xorStep]);
239 andBits = &(pointerColor->andMaskData[andStep * y]);
241 for (
size_t x = 0; x < width; x++)
248 const UINT32 color = FreeRDPReadColor(&pSrc8[x * bpp], format);
249 FreeRDPSplitColor(color, format, &R, &G, &B, &A, NULL);
289 void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem)
291 shadow_multiclient_publish_and_wait(subsystem->updateEvent);
This struct contains function pointer to initialize/free objects.