Fixed shadow server color encoding.
authorArmin Novak <armin.novak@thincast.com>
Tue, 20 Sep 2016 07:25:13 +0000 (09:25 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:12 +0000 (13:43 +0200)
include/freerdp/server/shadow.h
libfreerdp/codec/rfx.c
server/shadow/Mac/mac_shadow.c
server/shadow/Win/win_shadow.c
server/shadow/X11/x11_shadow.c
server/shadow/shadow_client.c
server/shadow/shadow_encoder.c
server/shadow/shadow_surface.c

index 20c6115..94bfc7a 100644 (file)
@@ -65,19 +65,30 @@ typedef int (*pfnShadowSubsystemStop)(rdpShadowSubsystem* subsystem);
 
 typedef int (*pfnShadowEnumMonitors)(MONITOR_DEF* monitors, int maxMonitors);
 
-typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem, rdpShadowClient* client,
-               const char* user, const char* domain, const char* password);
-typedef BOOL (*pfnShadowClientConnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client);
-typedef void (*pfnShadowClientDisconnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client);
-typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem, rdpShadowClient* client);
-
-typedef int (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags);
-typedef int (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code);
-typedef int (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code);
-typedef int (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y);
-typedef int (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y);
-
-typedef void (*pfnShadowChannelAudinServerReceiveSamples)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, const void* buf, int nframes);
+typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem,
+                                     rdpShadowClient* client,
+                                     const char* user, const char* domain, const char* password);
+typedef BOOL (*pfnShadowClientConnect)(rdpShadowSubsystem* subsystem,
+                                       rdpShadowClient* client);
+typedef void (*pfnShadowClientDisconnect)(rdpShadowSubsystem* subsystem,
+        rdpShadowClient* client);
+typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem,
+        rdpShadowClient* client);
+
+typedef int (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem,
+        rdpShadowClient* client, UINT32 flags);
+typedef int (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem,
+                                      rdpShadowClient* client, UINT16 flags, UINT16 code);
+typedef int (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem,
+        rdpShadowClient* client, UINT16 flags, UINT16 code);
+typedef int (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem,
+                                   rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y);
+typedef int (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem,
+        rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y);
+
+typedef void (*pfnShadowChannelAudinServerReceiveSamples)(
+    rdpShadowSubsystem* subsystem, rdpShadowClient* client, const void* buf,
+    int nframes);
 
 struct rdp_shadow_client
 {
@@ -152,6 +163,7 @@ struct rdp_shadow_surface
        int width;
        int height;
        int scanline;
+       DWORD format;
        BYTE* data;
 
        CRITICAL_SECTION lock;
@@ -218,7 +230,8 @@ struct rdp_shadow_subsystem
 #define SHADOW_MSG_IN_REFRESH_REQUEST_ID               1001
 
 typedef struct _SHADOW_MSG_OUT SHADOW_MSG_OUT;
-typedef void (*MSG_OUT_FREE_FN)(UINT32 id, SHADOW_MSG_OUT* msg); /* function to free SHADOW_MSG_OUT */
+typedef void (*MSG_OUT_FREE_FN)(UINT32 id,
+                                SHADOW_MSG_OUT* msg); /* function to free SHADOW_MSG_OUT */
 #define RDP_SHADOW_MSG_OUT_COMMON() \
        int refCount; \
        MSG_OUT_FREE_FN Free
@@ -239,7 +252,8 @@ struct _SHADOW_MSG_OUT_POINTER_POSITION_UPDATE
        UINT32 xPos;
        UINT32 yPos;
 };
-typedef struct _SHADOW_MSG_OUT_POINTER_POSITION_UPDATE SHADOW_MSG_OUT_POINTER_POSITION_UPDATE;
+typedef struct _SHADOW_MSG_OUT_POINTER_POSITION_UPDATE
+               SHADOW_MSG_OUT_POINTER_POSITION_UPDATE;
 
 struct _SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE
 {
@@ -253,7 +267,8 @@ struct _SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE
        BYTE* xorMaskData;
        BYTE* andMaskData;
 };
-typedef struct _SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE;
+typedef struct _SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE
+               SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE;
 
 struct _SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES
 {
@@ -263,7 +278,8 @@ struct _SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES
        int nFrames;
        UINT16 wTimestamp;
 };
-typedef struct _SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES;
+typedef struct _SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES
+               SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES;
 
 struct _SHADOW_MSG_OUT_AUDIO_OUT_VOLUME
 {
@@ -280,11 +296,14 @@ extern "C" {
 FREERDP_API void shadow_subsystem_set_entry_builtin(const char* name);
 FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry);
 
-FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data(BYTE* pixels, BOOL premultiplied,
-               UINT32 width, UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* pointerColor);
+FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data(
+    BYTE* pixels, BOOL premultiplied,
+    UINT32 width, UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* pointerColor);
 
-FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** argv);
-FREERDP_API int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, char** argv, int status);
+FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server,
+        int argc, char** argv);
+FREERDP_API int shadow_server_command_line_status_print(rdpShadowServer* server,
+        int argc, char** argv, int status);
 
 FREERDP_API int shadow_server_start(rdpShadowServer* server);
 FREERDP_API int shadow_server_stop(rdpShadowServer* server);
@@ -297,14 +316,19 @@ FREERDP_API int shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors);
 FREERDP_API rdpShadowServer* shadow_server_new();
 FREERDP_API void shadow_server_free(rdpShadowServer* server);
 
-FREERDP_API int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip);
-FREERDP_API int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BYTE* pData2, int nStep2, RECTANGLE_16* rect);
+FREERDP_API int shadow_capture_align_clip_rect(RECTANGLE_16* rect,
+        RECTANGLE_16* clip);
+FREERDP_API int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth,
+                                       int nHeight, BYTE* pData2, int nStep2, RECTANGLE_16* rect);
 
 FREERDP_API void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem);
 
-FREERDP_API BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam);
-FREERDP_API int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam);
-FREERDP_API int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode);
+FREERDP_API BOOL shadow_client_post_msg(rdpShadowClient* client, void* context,
+                                        UINT32 type, SHADOW_MSG_OUT* msg, void* lParam);
+FREERDP_API int shadow_client_boardcast_msg(rdpShadowServer* server,
+        void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam);
+FREERDP_API int shadow_client_boardcast_quit(rdpShadowServer* server,
+        int nExitCode);
 
 FREERDP_API int shadow_encoder_preferred_fps(rdpShadowEncoder* encoder);
 FREERDP_API UINT32 shadow_encoder_inflight_frames(rdpShadowEncoder* encoder);
index d099e98..203ce89 100644 (file)
@@ -83,28 +83,28 @@ static void rfx_profiler_create(RFX_CONTEXT* context)
 {
        PROFILER_CREATE(context->priv->prof_rfx_decode_rgb, "rfx_decode_rgb");
        PROFILER_CREATE(context->priv->prof_rfx_decode_component,
-                       "rfx_decode_component");
+                       "rfx_decode_component");
        PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode");
        PROFILER_CREATE(context->priv->prof_rfx_differential_decode,
-                       "rfx_differential_decode");
+                       "rfx_differential_decode");
        PROFILER_CREATE(context->priv->prof_rfx_quantization_decode,
-                       "rfx_quantization_decode");
+                       "rfx_quantization_decode");
        PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode");
        PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB");
        PROFILER_CREATE(context->priv->prof_rfx_decode_format_rgb,
-                       "rfx_decode_format_rgb");
+                       "rfx_decode_format_rgb");
        PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb");
        PROFILER_CREATE(context->priv->prof_rfx_encode_component,
-                       "rfx_encode_component");
+                       "rfx_encode_component");
        PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode");
        PROFILER_CREATE(context->priv->prof_rfx_differential_encode,
-                       "rfx_differential_encode");
+                       "rfx_differential_encode");
        PROFILER_CREATE(context->priv->prof_rfx_quantization_encode,
-                       "rfx_quantization_encode");
+                       "rfx_quantization_encode");
        PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode");
        PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr");
        PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb,
-                       "rfx_encode_format_rgb");
+                       "rfx_encode_format_rgb");
 }
 
 static void rfx_profiler_free(RFX_CONTEXT* context)
@@ -275,7 +275,7 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder)
                verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
                GetVersionExA(&verinfo);
                isVistaOrLater = ((verinfo.dwMajorVersion >= 6)
-                                 && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE;
+                                 && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE;
                priv->UseThreads = isVistaOrLater;
        }
 #else
@@ -285,22 +285,22 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder)
        priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
        priv->MaxThreadCount = 0;
        status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0,
-                              KEY_READ | KEY_WOW64_64KEY, &hKey);
+                              KEY_READ | KEY_WOW64_64KEY, &hKey);
 
        if (status == ERROR_SUCCESS)
        {
                dwSize = sizeof(dwValue);
 
                if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*) &dwValue,
-                                   &dwSize) == ERROR_SUCCESS)
+                                   &dwSize) == ERROR_SUCCESS)
                        priv->UseThreads = dwValue ? 1 : 0;
 
                if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*) &dwValue,
-                                   &dwSize) == ERROR_SUCCESS)
+                                   &dwSize) == ERROR_SUCCESS)
                        priv->MinThreadCount = dwValue;
 
                if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*) &dwValue,
-                                   &dwSize) == ERROR_SUCCESS)
+                                   &dwSize) == ERROR_SUCCESS)
                        priv->MaxThreadCount = dwValue;
 
                RegCloseKey(hKey);
@@ -378,7 +378,7 @@ void rfx_context_free(RFX_CONTEXT* context)
                free(priv->tileWorkParams);
 #ifdef WITH_PROFILER
                WLog_VRB(TAG,
-                        "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
+                        "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
 #endif
        }
 
@@ -436,7 +436,7 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s)
        }
 
        Stream_Read_UINT16(s,
-                          context->version); /* version (2 bytes), WF_VERSION_1_0 (0x0100) */
+                          context->version); /* version (2 bytes), WF_VERSION_1_0 (0x0100) */
 
        if (context->version != WF_VERSION_1_0)
        {
@@ -462,9 +462,9 @@ static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s)
 
        Stream_Read_UINT8(s, numCodecs); /* numCodecs (1 byte), must be set to 0x01 */
        Stream_Read_UINT8(s,
-                         context->codec_id); /* codecId (1 byte), must be set to 0x01 */
+                         context->codec_id); /* codecId (1 byte), must be set to 0x01 */
        Stream_Read_UINT16(s,
-                          context->codec_version); /* version (2 bytes), must be set to WF_VERSION_1_0 (0x0100)  */
+                          context->codec_version); /* version (2 bytes), must be set to WF_VERSION_1_0 (0x0100)  */
 
        if (numCodecs != 1)
        {
@@ -481,12 +481,12 @@ static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s)
        if (context->codec_version != WF_VERSION_1_0)
        {
                WLog_ERR(TAG, "%s: invalid codec version (0x%04X)", __FUNCTION__,
-                        context->codec_version);
+                        context->codec_version);
                return FALSE;
        }
 
        WLog_Print(context->priv->log, WLOG_DEBUG, "id %d version 0x%X.",
-                  context->codec_id, context->codec_version);
+                  context->codec_id, context->codec_version);
        context->decodedHeaderBlocks |= _RFX_DECODED_VERSIONS;
        return TRUE;
 }
@@ -504,7 +504,7 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s)
        }
 
        Stream_Read_UINT8(s,
-                         numChannels); /* numChannels (1 byte), must bet set to 0x01 */
+                         numChannels); /* numChannels (1 byte), must bet set to 0x01 */
 
        /* In RDVH sessions, numChannels will represent the number of virtual monitors
         * configured and does not always be set to 0x01 as [MS-RDPRFX] said.
@@ -518,7 +518,7 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s)
        if (Stream_GetRemainingLength(s) < (size_t)(numChannels * 5))
        {
                WLog_ERR(TAG, "RfxMessageChannels packet too small for numChannels=%d",
-                        numChannels);
+                        numChannels);
                return FALSE;
        }
 
@@ -537,14 +537,14 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s)
        if (!context->width || !context->height)
        {
                WLog_ERR(TAG, "%s: invalid channel with/height: %ux%u", __FUNCTION__,
-                        context->width, context->height);
+                        context->width, context->height);
                return FALSE;
        }
 
        /* Now, only the first monitor can be used, therefore the other channels will be ignored. */
        Stream_Seek(s, 5 * (numChannels - 1));
        WLog_Print(context->priv->log, WLOG_DEBUG, "numChannels %d id %d, %dx%d.",
-                  numChannels, channelId, context->width, context->height);
+                  numChannels, channelId, context->width, context->height);
        context->decodedHeaderBlocks |= _RFX_DECODED_CHANNELS;
        return TRUE;
 }
@@ -564,11 +564,11 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s)
 
        Stream_Read_UINT8(s, ctxId); /* ctxId (1 byte), must be set to 0x00 */
        Stream_Read_UINT16(s,
-                          tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */
+                          tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */
        Stream_Read_UINT16(s, properties); /* properties (2 bytes) */
        WLog_Print(context->priv->log, WLOG_DEBUG,
-                  "ctxId %d tileSize %d properties 0x%X.",
-                  ctxId, tileSize, properties);
+                  "ctxId %d tileSize %d properties 0x%X.",
+                  ctxId, tileSize, properties);
        context->properties = properties;
        context->flags = (properties & 0x0007);
 
@@ -603,7 +603,7 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s)
 }
 
 static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context,
-       RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
+        RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
 {
        UINT32 frameIdx;
        UINT16 numRegions;
@@ -623,15 +623,15 @@ static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context,
        }
 
        Stream_Read_UINT32(s,
-                          frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */
+                          frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */
        Stream_Read_UINT16(s, numRegions); /* numRegions (2 bytes) */
        WLog_Print(context->priv->log, WLOG_DEBUG,
-                  "RFX_FRAME_BEGIN: frameIdx: %d numRegions: %d", frameIdx, numRegions);
+                  "RFX_FRAME_BEGIN: frameIdx: %d numRegions: %d", frameIdx, numRegions);
        return TRUE;
 }
 
 static BOOL rfx_process_message_frame_end(RFX_CONTEXT* context,
-       RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
+        RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
 {
        if (*pExpectedBlockType != WBT_FRAME_END)
        {
@@ -645,7 +645,7 @@ static BOOL rfx_process_message_frame_end(RFX_CONTEXT* context,
 }
 
 static BOOL rfx_process_message_region(RFX_CONTEXT* context,
-                                      RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
+                                       RFX_MESSAGE* message, wStream* s, UINT16* pExpectedBlockType)
 {
        int i;
        UINT16 regionType;
@@ -690,7 +690,7 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context,
        if (Stream_GetRemainingLength(s) < (size_t)(8 * message->numRects))
        {
                WLog_ERR(TAG, "%s: packet too small for num_rects=%d", __FUNCTION__,
-                        message->numRects);
+                        message->numRects);
                return FALSE;
        }
 
@@ -701,15 +701,14 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context,
        for (i = 0; i < message->numRects; i++)
        {
                RFX_RECT* rect = rfx_message_get_rect(message, i);
-
                /* RFX_RECT */
                Stream_Read_UINT16(s, rect->x); /* x (2 bytes) */
                Stream_Read_UINT16(s, rect->y); /* y (2 bytes) */
                Stream_Read_UINT16(s, rect->width); /* width (2 bytes) */
                Stream_Read_UINT16(s, rect->height); /* height (2 bytes) */
                WLog_Print(context->priv->log, WLOG_DEBUG, "rect %d (x,y=%d,%d w,h=%d %d).", i,
-                          rect->x, rect->y,
-                          rect->width, rect->height);
+                          rect->x, rect->y,
+                          rect->width, rect->height);
        }
 
        if (Stream_GetRemainingLength(s) < 4)
@@ -719,9 +718,9 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context,
        }
 
        Stream_Read_UINT16(s,
-                          regionType); /* regionType (2 bytes): MUST be set to CBT_REGION (0xCAC1) */
+                          regionType); /* regionType (2 bytes): MUST be set to CBT_REGION (0xCAC1) */
        Stream_Read_UINT16(s,
-                          numTileSets); /* numTilesets (2 bytes): MUST be set to 0x0001. */
+                          numTileSets); /* numTilesets (2 bytes): MUST be set to 0x0001. */
 
        if (regionType != CBT_REGION)
        {
@@ -754,7 +753,7 @@ static void CALLBACK rfx_process_message_tile_work_callback(
 }
 
 static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
-                                       RFX_MESSAGE* message, wStream* s, UINT16* pExpecedBlockType)
+                                        RFX_MESSAGE* message, wStream* s, UINT16* pExpecedBlockType)
 {
        BOOL rc;
        int i, close_cnt;
@@ -785,7 +784,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
        }
 
        Stream_Read_UINT16(s,
-                          subtype); /* subtype (2 bytes) must be set to CBT_TILESET (0xCAC2) */
+                          subtype); /* subtype (2 bytes) must be set to CBT_TILESET (0xCAC2) */
 
        if (subtype != CBT_TILESET)
        {
@@ -815,7 +814,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
        Stream_Read_UINT32(s, tilesDataSize); /* tilesDataSize (4 bytes) */
 
        if (!(pmem = realloc((void*) context->quants,
-                            context->numQuant * 10 * sizeof(UINT32))))
+                            context->numQuant * 10 * sizeof(UINT32))))
                return FALSE;
 
        quants = context->quants = (UINT32*) pmem;
@@ -824,7 +823,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
        if (Stream_GetRemainingLength(s) < (size_t)(context->numQuant * 5))
        {
                WLog_ERR(TAG, "RfxMessageTileSet packet too small for num_quants=%d",
-                        context->numQuant);
+                        context->numQuant);
                return FALSE;
        }
 
@@ -847,16 +846,16 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
                *quants++ = (quant & 0x0F);
                *quants++ = (quant >> 4);
                WLog_Print(context->priv->log, WLOG_DEBUG,
-                          "quant %d (%d %d %d %d %d %d %d %d %d %d).",
-                          i, context->quants[i * 10], context->quants[i * 10 + 1],
-                          context->quants[i * 10 + 2], context->quants[i * 10 + 3],
-                          context->quants[i * 10 + 4], context->quants[i * 10 + 5],
-                          context->quants[i * 10 + 6], context->quants[i * 10 + 7],
-                          context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
+                          "quant %d (%d %d %d %d %d %d %d %d %d %d).",
+                          i, context->quants[i * 10], context->quants[i * 10 + 1],
+                          context->quants[i * 10 + 2], context->quants[i * 10 + 3],
+                          context->quants[i * 10 + 4], context->quants[i * 10 + 5],
+                          context->quants[i * 10 + 6], context->quants[i * 10 + 7],
+                          context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
        }
 
        if (!(message->tiles = (RFX_TILE**) calloc(message->numTiles,
-                              sizeof(RFX_TILE*))))
+                              sizeof(RFX_TILE*))))
        {
                message->numTiles = 0;
                return FALSE;
@@ -866,7 +865,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
        {
                work_objects = (PTP_WORK*) calloc(message->numTiles, sizeof(PTP_WORK));
                params = (RFX_TILE_PROCESS_WORK_PARAM*) calloc(message->numTiles,
-                        sizeof(RFX_TILE_PROCESS_WORK_PARAM));
+                        sizeof(RFX_TILE_PROCESS_WORK_PARAM));
 
                if (!work_objects)
                {
@@ -900,20 +899,20 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
                if (Stream_GetRemainingLength(s) < 6)
                {
                        WLog_ERR(TAG, "RfxMessageTileSet packet too small to read tile %d/%d", i,
-                                message->numTiles);
+                                message->numTiles);
                        rc = FALSE;
                        break;
                }
 
                Stream_Read_UINT16(s,
-                                  blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
+                                  blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
                Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */
 
                if (Stream_GetRemainingLength(s) < blockLen - 6)
                {
                        WLog_ERR(TAG,
-                                "RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d",
-                                i, message->numTiles, blockLen);
+                                "RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d",
+                                i, message->numTiles, blockLen);
                        rc = FALSE;
                        break;
                }
@@ -923,7 +922,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
                if (blockType != CBT_TILE)
                {
                        WLog_ERR(TAG, "unknown block type 0x%X, expected CBT_TILE (0xCAC3).",
-                                blockType);
+                                blockType);
                        rc = FALSE;
                        break;
                }
@@ -952,8 +951,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
                        params[i].tile = message->tiles[i];
 
                        if (!(work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK)
-                                               rfx_process_message_tile_work_callback,
-                                               (void*) &params[i], &context->priv->ThreadPoolEnv)))
+                                               rfx_process_message_tile_work_callback,
+                                               (void*) &params[i], &context->priv->ThreadPoolEnv)))
                        {
                                WLog_ERR(TAG, "CreateThreadpoolWork failed.");
                                rc = FALSE;
@@ -996,11 +995,11 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context,
 }
 
 BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
-                        UINT32 format, UINT32 length,
-                        UINT32 left, UINT32 top,
-                        BYTE* dst, UINT32 dstFormat,
-                        UINT32 dstStride, UINT32 dstHeight,
-                        REGION16* invalidRegion)
+                         UINT32 format, UINT32 length,
+                         UINT32 left, UINT32 top,
+                         BYTE* dst, UINT32 dstFormat,
+                         UINT32 dstStride, UINT32 dstHeight,
+                         REGION16* invalidRegion)
 {
        int pos;
        REGION16 updateRegion;
@@ -1028,7 +1027,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                Stream_Read_UINT16(s, blockType); /* blockType (2 bytes) */
                Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */
                WLog_Print(context->priv->log, WLOG_DEBUG, "blockType 0x%X blockLen %d",
-                          blockType, blockLen);
+                          blockType, blockLen);
 
                if (blockLen == 0)
                {
@@ -1062,7 +1061,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
 
                        Stream_Read_UINT8(s, codecId); /* codecId (1 byte) must be set to 0x01 */
                        Stream_Read_UINT8(s,
-                                         channelId); /* channelId (1 byte) 0xFF or 0x00, see below */
+                                         channelId); /* channelId (1 byte) 0xFF or 0x00, see below */
 
                        if (codecId != 0x01)
                        {
@@ -1076,7 +1075,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                                if (channelId != 0xFF)
                                {
                                        WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType 0x%04X", __FUNCTION__,
-                                                channelId, blockType);
+                                                channelId, blockType);
                                        goto fail;
                                }
                        }
@@ -1086,7 +1085,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                                if (channelId != 0x00)
                                {
                                        WLog_ERR(TAG, "%s: invalid channelId 0x%02X for blockType WBT_CONTEXT",
-                                                __FUNCTION__, channelId);
+                                                __FUNCTION__, channelId);
                                        goto fail;
                                }
                        }
@@ -1123,7 +1122,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
 
                        case WBT_FRAME_BEGIN:
                                ok = rfx_process_message_frame_begin(context, message, s,
-                                                                    &expectedDataBlockType);
+                                                                    &expectedDataBlockType);
                                break;
 
                        case WBT_REGION:
@@ -1152,7 +1151,6 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                UINT32 nbUpdateRects;
                REGION16 clippingRects;
                const RECTANGLE_16* updateRects;
-
                region16_init(&clippingRects);
 
                for (i = 0; i < message->numRects; i++)
@@ -1170,7 +1168,6 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                {
                        RECTANGLE_16 updateRect;
                        const RFX_TILE* tile = rfx_message_get_tile(message, i);
-
                        updateRect.left = left + tile->x;
                        updateRect.top = top + tile->y;
                        updateRect.right = updateRect.left + 64;
@@ -1185,9 +1182,10 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data,
                                UINT32 nYDst = updateRects[j].top;
                                UINT32 nWidth = updateRects[j].right - updateRects[j].left;
                                UINT32 nHeight = updateRects[j].bottom - updateRects[j].top;
+
                                if (!freerdp_image_copy(dst, dstFormat, dstStride,
-                                                  nXDst, nYDst, nWidth, nHeight,
-                                                  tile->data, format, 64 * GetBytesPerPixel(format), 0, 0, NULL))
+                                                       nXDst, nYDst, nWidth, nHeight,
+                                                       tile->data, format, 64 * GetBytesPerPixel(format), 0, 0, NULL))
                                        goto fail;
 
                                if (invalidRegion)
@@ -1265,7 +1263,7 @@ static void rfx_update_context_properties(RFX_CONTEXT* context)
        properties |= (COL_CONV_ICT << 4); /* cct */
        properties |= (CLW_XFORM_DWT_53_A << 6); /* xft */
        properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3)
-                      << 10); /* et */
+                      << 10); /* et */
        properties |= (SCALAR_QUANTIZATION << 14); /* qt */
        context->properties = properties;
 }
@@ -1311,7 +1309,7 @@ static void rfx_write_message_context(RFX_CONTEXT* context, wStream* s)
        properties |= (COL_CONV_ICT << 3); /* cct */
        properties |= (CLW_XFORM_DWT_53_A << 5); /* xft */
        properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3)
-                      << 9); /* et */
+                      << 9); /* et */
        properties |= (SCALAR_QUANTIZATION << 13); /* qt */
        Stream_Write_UINT16(s, properties); /* properties (2 bytes) */
        rfx_update_context_properties(context);
@@ -1365,7 +1363,7 @@ struct _RFX_TILE_COMPOSE_WORK_PARAM
 };
 
 void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE
-       instance, void* context, PTP_WORK work)
+        instance, void* context, PTP_WORK work)
 {
        RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*) context;
        rfx_encode_rgb(param->context, param->tile);
@@ -1373,7 +1371,7 @@ void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE
 
 
 static BOOL computeRegion(const RFX_RECT* rects, int numRects, REGION16* region,
-                         int width, int height)
+                          int width, int height)
 {
        int i;
        const RFX_RECT* rect = rects;
@@ -1410,7 +1408,7 @@ BOOL setupWorkers(RFX_CONTEXT* context, int nbTiles)
        priv->workObjects = (PTP_WORK*) pmem;
 
        if (!(pmem = realloc((void*) priv->tileWorkParams,
-                            sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles)))
+                            sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles)))
                return FALSE;
 
        priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*) pmem;
@@ -1418,8 +1416,8 @@ BOOL setupWorkers(RFX_CONTEXT* context, int nbTiles)
 }
 
 RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects,
-                               int numRects,
-                               BYTE* data, int width, int height, int scanline)
+                                int numRects,
+                                BYTE* data, int width, int height, int scanline)
 {
        UINT32 i, maxNbTiles, maxTilesX, maxTilesY;
        UINT32 xIdx, yIdx, regionNbRects;
@@ -1455,11 +1453,11 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects,
        if (!context->numQuant)
        {
                if (!(context->quants = (UINT32*) malloc(sizeof(
-                                           rfx_default_quantization_values))))
+                                           rfx_default_quantization_values))))
                        goto skip_encoding_loop;
 
                CopyMemory(context->quants, &rfx_default_quantization_values,
-                          sizeof(rfx_default_quantization_values));
+                          sizeof(rfx_default_quantization_values));
                context->numQuant = 1;
                context->quantIdxY = 0;
                context->quantIdxCb = 0;
@@ -1577,9 +1575,9 @@ RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects,
                                        workParam->tile = tile;
 
                                        if (!(*workObject = CreateThreadpoolWork(
-                                                               (PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback,
-                                                               (void*) workParam,
-                                                               &context->priv->ThreadPoolEnv)))
+                                                               (PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback,
+                                                               (void*) workParam,
+                                                               &context->priv->ThreadPoolEnv)))
                                        {
                                                goto skip_encoding_loop;
                                        }
@@ -1607,7 +1605,7 @@ skip_encoding_loop:
                if (message->numTiles > 0)
                {
                        void* pmem = realloc((void*) message->tiles,
-                                            sizeof(RFX_TILE*) * message->numTiles);
+                                            sizeof(RFX_TILE*) * message->numTiles);
 
                        if (pmem)
                                message->tiles = (RFX_TILE**) pmem;
@@ -1656,7 +1654,7 @@ skip_encoding_loop:
 }
 
 RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message,
-                              int* numMessages, int maxDataSize)
+                               int* numMessages, int maxDataSize)
 {
        int i, j;
        UINT32 tileDataSize;
@@ -1687,7 +1685,7 @@ RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message,
                        messages[j].freeArray = TRUE;
 
                        if (!(messages[j].tiles = (RFX_TILE**) calloc(message->numTiles,
-                                                 sizeof(RFX_TILE*))))
+                                                 sizeof(RFX_TILE*))))
                                goto free_messages;
                }
 
@@ -1710,19 +1708,19 @@ free_messages:
 }
 
 RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects,
-                                int numRects,
-                                BYTE* data, int width, int height, int scanline, int* numMessages,
-                                int maxDataSize)
+                                 int numRects,
+                                 BYTE* data, int width, int height, int scanline, int* numMessages,
+                                 int maxDataSize)
 {
        RFX_MESSAGE* message;
        RFX_MESSAGE* messageList;
 
        if (!(message = rfx_encode_message(context, rects, numRects, data, width,
-                                          height, scanline)))
+                                          height, scanline)))
                return NULL;
 
        if (!(messageList = rfx_split_message(context, message, numMessages,
-                                             maxDataSize)))
+                                             maxDataSize)))
        {
                message->freeRects = TRUE;
                rfx_message_free(context, message);
@@ -1734,7 +1732,7 @@ RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects,
 }
 
 static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s,
-                                     RFX_MESSAGE* message)
+                                      RFX_MESSAGE* message)
 {
        int i;
        RFX_TILE* tile;
@@ -1775,14 +1773,14 @@ static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s,
 
 #ifdef WITH_DEBUG_RFX
        WLog_Print(context->priv->log, WLOG_DEBUG,
-                  "numQuant: %d numTiles: %d tilesDataSize: %d",
-                  message->numQuant, message->numTiles, message->tilesDataSize);
+                  "numQuant: %d numTiles: %d tilesDataSize: %d",
+                  message->numQuant, message->numTiles, message->tilesDataSize);
 #endif
        return TRUE;
 }
 
 static BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s,
-                                  RFX_MESSAGE* message)
+        RFX_MESSAGE* message)
 {
        if (!Stream_EnsureRemainingCapacity(s, 14))
                return FALSE;
@@ -1797,7 +1795,7 @@ static BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s,
 }
 
 static BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s,
-                             RFX_MESSAGE* message)
+                                     RFX_MESSAGE* message)
 {
        int i;
        UINT32 blockLen;
@@ -1816,7 +1814,6 @@ static BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s,
        for (i = 0; i < message->numRects; i++)
        {
                const RFX_RECT* rect = rfx_message_get_rect(message, i);
-
                /* Clipping rectangles are relative to destLeft, destTop */
                Stream_Write_UINT16(s, rect->x); /* x (2 bytes) */
                Stream_Write_UINT16(s, rect->y); /* y (2 bytes) */
@@ -1830,7 +1827,7 @@ static BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s,
 }
 
 BOOL rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s,
-                                RFX_MESSAGE* message)
+                                 RFX_MESSAGE* message)
 {
        if (!Stream_EnsureRemainingCapacity(s, 8))
                return FALSE;
@@ -1864,14 +1861,14 @@ BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
 }
 
 BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s,
-                        const RFX_RECT* rects, int numRects, BYTE* data, int width, int height,
-                        int scanline)
+                         const RFX_RECT* rects, int numRects, BYTE* data, int width, int height,
+                         int scanline)
 {
        RFX_MESSAGE* message;
        BOOL ret = TRUE;
 
        if (!(message = rfx_encode_message(context, rects, numRects, data, width,
-                                          height, scanline)))
+                                          height, scanline)))
                return FALSE;
 
        ret = rfx_write_message(context, s, message);
index 5cccc60..4884e93 100644 (file)
@@ -35,7 +35,6 @@ static macShadowSubsystem* g_Subsystem = NULL;
 static void mac_shadow_input_synchronize_event(macShadowSubsystem* subsystem,
         rdpShadowClient* client, UINT32 flags)
 {
-
 }
 
 static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
@@ -46,26 +45,24 @@ static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
        BOOL extended;
        CGEventRef kbdEvent;
        CGEventSourceRef source;
-       
        extended = (flags & KBD_FLAGS_EXTENDED) ? TRUE : FALSE;
-       
+
        if (extended)
                code |= KBDEXT;
-       
+
        vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4);
-       
+
        if (extended)
                vkcode |= KBDEXT;
-       
+
        keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_APPLE);
-       
+
        if (keycode < 8)
                return;
-       
-       keycode -= 8;
 
+       keycode -= 8;
        source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
-       
+
        if (flags & KBD_FLAGS_DOWN)
        {
                kbdEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode) keycode, TRUE);
@@ -78,14 +75,13 @@ static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
                CGEventPost(kCGHIDEventTap, kbdEvent);
                CFRelease(kbdEvent);
        }
-       
+
        CFRelease(source);
 }
 
 static void mac_shadow_input_unicode_keyboard_event(macShadowSubsystem*
         subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
 {
-
 }
 
 static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
@@ -94,11 +90,11 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
        UINT32 scrollX = 0;
        UINT32 scrollY = 0;
        CGWheelCount wheelCount = 2;
-       
+
        if (flags & PTR_FLAGS_WHEEL)
        {
                scrollY = flags & WheelRotationMask;
-               
+
                if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
                {
                        scrollY = -(flags & WheelRotationMask) / 392;
@@ -107,21 +103,23 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
                {
                        scrollY = (flags & WheelRotationMask) / 120;
                }
-               
-               CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
-               CGEventRef scroll = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitLine,
-                                                                 wheelCount, scrollY, scrollX);
+
+               CGEventSourceRef source = CGEventSourceCreate(
+                                             kCGEventSourceStateHIDSystemState);
+               CGEventRef scroll = CGEventCreateScrollWheelEvent(source,
+                                   kCGScrollEventUnitLine,
+                                   wheelCount, scrollY, scrollX);
                CGEventPost(kCGHIDEventTap, scroll);
-               
                CFRelease(scroll);
                CFRelease(source);
        }
        else
        {
-               CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
+               CGEventSourceRef source = CGEventSourceCreate(
+                                             kCGEventSourceStateHIDSystemState);
                CGEventType mouseType = kCGEventNull;
                CGMouseButton mouseButton = kCGMouseButtonLeft;
-               
+
                if (flags & PTR_FLAGS_MOVE)
                {
                        if (subsystem->mouseDownLeft)
@@ -132,16 +130,17 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
                                mouseType = kCGEventOtherMouseDragged;
                        else
                                mouseType = kCGEventMouseMoved;
-                       
-                       CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton);
+
+                       CGEventRef move = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y),
+                                         mouseButton);
                        CGEventPost(kCGHIDEventTap, move);
                        CFRelease(move);
                }
-               
+
                if (flags & PTR_FLAGS_BUTTON1)
                {
                        mouseButton = kCGMouseButtonLeft;
-                       
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                mouseType = kCGEventLeftMouseDown;
@@ -156,7 +155,7 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
                else if (flags & PTR_FLAGS_BUTTON2)
                {
                        mouseButton = kCGMouseButtonRight;
-                       
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                mouseType = kCGEventRightMouseDown;
@@ -167,12 +166,11 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
                                mouseType = kCGEventRightMouseUp;
                                subsystem->mouseDownRight = FALSE;
                        }
-                       
                }
                else if (flags & PTR_FLAGS_BUTTON3)
                {
                        mouseButton = kCGMouseButtonCenter;
-                       
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                mouseType = kCGEventOtherMouseDown;
@@ -184,10 +182,10 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
                                subsystem->mouseDownOther = FALSE;
                        }
                }
-               
-               CGEventRef mouseEvent = CGEventCreateMouseEvent(source, mouseType, CGPointMake(x, y), mouseButton);
+
+               CGEventRef mouseEvent = CGEventCreateMouseEvent(source, mouseType,
+                                       CGPointMake(x, y), mouseButton);
                CGEventPost(kCGHIDEventTap, mouseEvent);
-               
                CFRelease(mouseEvent);
                CFRelease(source);
        }
@@ -196,7 +194,6 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
 static void mac_shadow_input_extended_mouse_event(macShadowSubsystem* subsystem,
         rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
 {
-
 }
 
 static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
@@ -204,21 +201,15 @@ static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
        size_t wide, high;
        MONITOR_DEF* monitor;
        CGDirectDisplayID displayId;
-       
        displayId = CGMainDisplayID();
-       
        CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
-       
        subsystem->pixelWidth = CGDisplayModeGetPixelWidth(mode);
        subsystem->pixelHeight = CGDisplayModeGetPixelHeight(mode);
-       
        wide = CGDisplayPixelsWide(displayId);
        high = CGDisplayPixelsHigh(displayId);
-       
        CGDisplayModeRelease(mode);
-       
        subsystem->retina = ((subsystem->pixelWidth / wide) == 2) ? TRUE : FALSE;
-       
+
        if (subsystem->retina)
        {
                subsystem->width = wide;
@@ -229,41 +220,36 @@ static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
                subsystem->width = subsystem->pixelWidth;
                subsystem->height = subsystem->pixelHeight;
        }
-       
+
        subsystem->numMonitors = 1;
-       
        monitor = &(subsystem->monitors[0]);
-       
        monitor->left = 0;
        monitor->top = 0;
        monitor->right = subsystem->width;
        monitor->bottom = subsystem->height;
        monitor->flags = 1;
-       
        return 1;
 }
 
 static int mac_shadow_capture_start(macShadowSubsystem* subsystem)
 {
        CGError err;
-       
        err = CGDisplayStreamStart(subsystem->stream);
-       
+
        if (err != kCGErrorSuccess)
                return -1;
-       
+
        return 1;
 }
 
 static int mac_shadow_capture_stop(macShadowSubsystem* subsystem)
 {
        CGError err;
-       
        err = CGDisplayStreamStop(subsystem->stream);
-       
+
        if (err != kCGErrorSuccess)
                return -1;
-       
+
        return 1;
 }
 
@@ -274,19 +260,19 @@ static int mac_shadow_capture_get_dirty_region(macShadowSubsystem* subsystem)
        const CGRect* rects;
        RECTANGLE_16 invalidRect;
        rdpShadowSurface* surface = subsystem->server->surface;
-       
-       rects = CGDisplayStreamUpdateGetRects(subsystem->lastUpdate, kCGDisplayStreamUpdateDirtyRects, &numRects);
-       
+       rects = CGDisplayStreamUpdateGetRects(subsystem->lastUpdate,
+                                             kCGDisplayStreamUpdateDirtyRects, &numRects);
+
        if (!numRects)
                return -1;
-       
+
        for (index = 0; index < numRects; index++)
        {
                invalidRect.left = (UINT16) rects[index].origin.x;
                invalidRect.top = (UINT16) rects[index].origin.y;
                invalidRect.right = invalidRect.left + (UINT16) rects[index].size.width;
                invalidRect.bottom = invalidRect.top + (UINT16) rects[index].size.height;
-               
+
                if (subsystem->retina)
                {
                        /* scale invalid rect */
@@ -295,10 +281,11 @@ static int mac_shadow_capture_get_dirty_region(macShadowSubsystem* subsystem)
                        invalidRect.right /= 2;
                        invalidRect.bottom /= 2;
                }
-               
-               region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
+
+               region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                                   &invalidRect);
        }
-       
+
        return 0;
 }
 
@@ -374,86 +361,77 @@ static void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t,
        macShadowSubsystem* subsystem = g_Subsystem;
        rdpShadowServer* server = subsystem->server;
        rdpShadowSurface* surface = server->surface;
-       
        count = ArrayList_Count(server->clients);
-       
+
        if (count < 1)
                return;
 
        mac_shadow_capture_get_dirty_region(subsystem);
-               
        surfaceRect.left = 0;
        surfaceRect.top = 0;
        surfaceRect.right = surface->width;
        surfaceRect.bottom = surface->height;
-               
-       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect);
-       
+       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                               &surfaceRect);
+
        if (!region16_is_empty(&(surface->invalidRegion)))
        {
                extents = region16_extents(&(surface->invalidRegion));
-
                x = extents->left;
                y = extents->top;
                width = extents->right - extents->left;
                height = extents->bottom - extents->top;
-                       
                IOSurfaceLock(frameSurface, kIOSurfaceLockReadOnly, NULL);
-               
                pSrcData = (BYTE*) IOSurfaceGetBaseAddress(frameSurface);
                nSrcStep = (int) IOSurfaceGetBytesPerRow(frameSurface);
 
                if (subsystem->retina)
                {
-                       freerdp_image_copy_from_retina(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline,
-                                              x, y, width, height, pSrcData, nSrcStep, x, y);
+                       freerdp_image_copy_from_retina(surface->data, surface->format,
+                                                      surface->scanline,
+                                                      x, y, width, height, pSrcData, nSrcStep, x, y);
                }
                else
                {
-                       freerdp_image_copy(surface->data, PIXEL_FORMAT_XRGB32, surface->scanline,
-                                               x, y, width, height, pSrcData, PIXEL_FORMAT_XRGB32, nSrcStep, x, y, NULL);
+                       freerdp_image_copy(surface->data, surface->format, surface->scanline,
+                                          x, y, width, height, pSrcData, PIXEL_FORMAT_BGRX32, nSrcStep, x, y, NULL);
                }
-               
+
                IOSurfaceUnlock(frameSurface, kIOSurfaceLockReadOnly, NULL);
-                       
                ArrayList_Lock(server->clients);
-                       
                count = ArrayList_Count(server->clients);
-                       
                EnterCriticalSection(&(surface->lock));
-               shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem);
+               shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
                LeaveCriticalSection(&(surface->lock));
-               
+
                if (count == 1)
                {
                        rdpShadowClient* client;
-                       
                        client = (rdpShadowClient*) ArrayList_GetItem(server->clients, 0);
-                       
+
                        if (client)
                        {
                                subsystem->captureFrameRate = shadow_encoder_preferred_fps(client->encoder);
                        }
                }
-               
+
                ArrayList_Unlock(server->clients);
-                       
                region16_clear(&(surface->invalidRegion));
        }
-       
+
        if (status != kCGDisplayStreamFrameStatusFrameComplete)
        {
                switch (status)
                {
                        case kCGDisplayStreamFrameStatusFrameIdle:
                                break;
-                               
+
                        case kCGDisplayStreamFrameStatusStopped:
                                break;
-                               
+
                        case kCGDisplayStreamFrameStatusFrameBlank:
                                break;
-                               
+
                        default:
                                break;
                }
@@ -466,7 +444,8 @@ static void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t,
        else
        {
                CGDisplayStreamUpdateRef tmpRef = subsystem->lastUpdate;
-               subsystem->lastUpdate = CGDisplayStreamUpdateCreateMergedUpdate(tmpRef, updateRef);
+               subsystem->lastUpdate = CGDisplayStreamUpdateCreateMergedUpdate(tmpRef,
+                                       updateRef);
                CFRelease(tmpRef);
        }
 };
@@ -477,26 +456,22 @@ static int mac_shadow_capture_init(macShadowSubsystem* subsystem)
        void* values[2];
        CFDictionaryRef opts;
        CGDirectDisplayID displayId;
-       
        displayId = CGMainDisplayID();
-       
-       subsystem->updateBuffer = (BYTE*) malloc(subsystem->pixelWidth * subsystem->pixelHeight * 4);
-       
+       subsystem->updateBuffer = (BYTE*) malloc(subsystem->pixelWidth *
+                                 subsystem->pixelHeight * 4);
+
        if (!subsystem->updateBuffer)
                return -1;
-       
+
        subsystem->captureQueue = dispatch_queue_create("mac.shadow.capture", NULL);
-       
        keys[0] = (void*) kCGDisplayStreamShowCursor;
        values[0] = (void*) kCFBooleanFalse;
-       
-       opts = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys, (const void**) values, 1, NULL, NULL);
-       
-       subsystem->stream = CGDisplayStreamCreateWithDispatchQueue(displayId, subsystem->pixelWidth, subsystem->pixelHeight,
-                                                       'BGRA', opts, subsystem->captureQueue, mac_capture_stream_handler);
-       
+       opts = CFDictionaryCreate(kCFAllocatorDefault, (const void**) keys,
+                                 (const void**) values, 1, NULL, NULL);
+       subsystem->stream = CGDisplayStreamCreateWithDispatchQueue(displayId,
+                           subsystem->pixelWidth, subsystem->pixelHeight,
+                           'BGRA', opts, subsystem->captureQueue, mac_capture_stream_handler);
        CFRelease(opts);
-       
        return 1;
 }
 
@@ -508,13 +483,14 @@ static int mac_shadow_screen_grab(macShadowSubsystem* subsystem)
 static int mac_shadow_subsystem_process_message(macShadowSubsystem* subsystem,
         wMessage* message)
 {
-       switch(message->id)
+       switch (message->id)
        {
                case SHADOW_MSG_IN_REFRESH_REQUEST_ID:
                        EnterCriticalSection(&(surface->lock));
-                       shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem);
+                       shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
                        LeaveCriticalSection(&(surface->lock));
                        break;
+
                default:
                        WLog_ERR(TAG, "Unknown message id: %u", message->id);
                        break;
@@ -537,43 +513,38 @@ static void* mac_shadow_subsystem_thread(macShadowSubsystem* subsystem)
        HANDLE events[32];
        wMessage message;
        wMessagePipe* MsgPipe;
-       
        MsgPipe = subsystem->MsgPipe;
-       
        nCount = 0;
        events[nCount++] = MessageQueue_Event(MsgPipe->In);
-       
        subsystem->captureFrameRate = 16;
        dwInterval = 1000 / subsystem->captureFrameRate;
        frameTime = GetTickCount64() + dwInterval;
-       
+
        while (1)
        {
                cTime = GetTickCount64();
                dwTimeout = (cTime > frameTime) ? 0 : frameTime - cTime;
-               
                status = WaitForMultipleObjects(nCount, events, FALSE, dwTimeout);
-               
+
                if (WaitForSingleObject(MessageQueue_Event(MsgPipe->In), 0) == WAIT_OBJECT_0)
                {
                        if (MessageQueue_Peek(MsgPipe->In, &message, TRUE))
                        {
                                if (message.id == WMQ_QUIT)
                                        break;
-                               
+
                                mac_shadow_subsystem_process_message(subsystem, &message);
                        }
                }
-               
+
                if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
                {
                        mac_shadow_screen_grab(subsystem);
-                       
                        dwInterval = 1000 / subsystem->captureFrameRate;
                        frameTime += dwInterval;
                }
        }
-       
+
        ExitThread(0);
        return NULL;
 }
@@ -585,37 +556,27 @@ static int mac_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
        int numMonitors = 0;
        MONITOR_DEF* monitor;
        CGDirectDisplayID displayId;
-
        displayId = CGMainDisplayID();
        CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
-
        wide = CGDisplayPixelsWide(displayId);
        high = CGDisplayPixelsHigh(displayId);
-
        CGDisplayModeRelease(mode);
-
        index = 0;
        numMonitors = 1;
-
        monitor = &monitors[index];
-
        monitor->left = 0;
        monitor->top = 0;
        monitor->right = (int) wide;
        monitor->bottom = (int) high;
        monitor->flags = 1;
-
        return numMonitors;
 }
 
 static int mac_shadow_subsystem_init(macShadowSubsystem* subsystem)
 {
        g_Subsystem = subsystem;
-       
        mac_shadow_detect_monitors(subsystem);
-       
        mac_shadow_capture_init(subsystem);
-       
        return 1;
 }
 
@@ -623,7 +584,7 @@ static int mac_shadow_subsystem_uninit(macShadowSubsystem* subsystem)
 {
        if (!subsystem)
                return -1;
-       
+
        if (subsystem->lastUpdate)
        {
                CFRelease(subsystem->lastUpdate);
@@ -641,10 +602,10 @@ static int mac_shadow_subsystem_start(macShadowSubsystem* subsystem)
                return -1;
 
        mac_shadow_capture_start(subsystem);
-       
+
        if (!(thread = CreateThread(NULL, 0,
-                       (LPTHREAD_START_ROUTINE) mac_shadow_subsystem_thread,
-                       (void*) subsystem, 0, NULL)))
+                                   (LPTHREAD_START_ROUTINE) mac_shadow_subsystem_thread,
+                                   (void*) subsystem, 0, NULL)))
        {
                WLog_ERR(TAG, "Failed to create thread");
                return -1;
@@ -667,25 +628,26 @@ static void mac_shadow_subsystem_free(macShadowSubsystem* subsystem)
                return;
 
        mac_shadow_subsystem_uninit(subsystem);
-
        free(subsystem);
 }
 
 static macShadowSubsystem* mac_shadow_subsystem_new(void)
 {
        macShadowSubsystem* subsystem;
-
        subsystem = (macShadowSubsystem*) calloc(1, sizeof(macShadowSubsystem));
 
        if (!subsystem)
                return NULL;
 
-       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent) mac_shadow_input_synchronize_event;
-       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent) mac_shadow_input_keyboard_event;
-       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent) mac_shadow_input_unicode_keyboard_event;
+       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent)
+                                     mac_shadow_input_synchronize_event;
+       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent)
+                                  mac_shadow_input_keyboard_event;
+       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent)
+                                         mac_shadow_input_unicode_keyboard_event;
        subsystem->MouseEvent = (pfnShadowMouseEvent) mac_shadow_input_mouse_event;
-       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent) mac_shadow_input_extended_mouse_event;
-
+       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent)
+                                       mac_shadow_input_extended_mouse_event;
        return subsystem;
 }
 
@@ -693,14 +655,10 @@ FREERDP_API int Mac_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints)
 {
        pEntryPoints->New = (pfnShadowSubsystemNew) mac_shadow_subsystem_new;
        pEntryPoints->Free = (pfnShadowSubsystemFree) mac_shadow_subsystem_free;
-
        pEntryPoints->Init = (pfnShadowSubsystemInit) mac_shadow_subsystem_init;
        pEntryPoints->Uninit = (pfnShadowSubsystemInit) mac_shadow_subsystem_uninit;
-
        pEntryPoints->Start = (pfnShadowSubsystemStart) mac_shadow_subsystem_start;
        pEntryPoints->Stop = (pfnShadowSubsystemStop) mac_shadow_subsystem_stop;
-
        pEntryPoints->EnumMonitors = (pfnShadowEnumMonitors) mac_shadow_enum_monitors;
-
        return 1;
 }
index 4cc86cc..c9358a5 100644 (file)
 
 #define TAG SERVER_TAG("shadow.win")
 
-void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags)
+void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem,
+                                        rdpShadowClient* client, UINT32 flags)
 {
-
 }
 
-void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
+void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem,
+                                     rdpShadowClient* client, UINT16 flags, UINT16 code)
 {
        INPUT event;
-
        event.type = INPUT_KEYBOARD;
        event.ki.wVk = 0;
        event.ki.wScan = code;
@@ -53,10 +53,10 @@ void win_shadow_input_keyboard_event(winShadowSubsystem* subsystem, rdpShadowCli
        SendInput(1, &event, sizeof(INPUT));
 }
 
-void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
+void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem,
+        rdpShadowClient* client, UINT16 flags, UINT16 code)
 {
        INPUT event;
-
        event.type = INPUT_KEYBOARD;
        event.ki.wVk = 0;
        event.ki.wScan = code;
@@ -70,14 +70,13 @@ void win_shadow_input_unicode_keyboard_event(winShadowSubsystem* subsystem, rdpS
        SendInput(1, &event, sizeof(INPUT));
 }
 
-void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
+void win_shadow_input_mouse_event(winShadowSubsystem* subsystem,
+                                  rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
 {
        INPUT event;
        float width;
        float height;
-
        ZeroMemory(&event, sizeof(INPUT));
-
        event.type = INPUT_MOUSE;
 
        if (flags & PTR_FLAGS_WHEEL)
@@ -94,9 +93,8 @@ void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient
        {
                width = (float) GetSystemMetrics(SM_CXSCREEN);
                height = (float) GetSystemMetrics(SM_CYSCREEN);
-
-               event.mi.dx = (LONG) ((float) x * (65535.0f / width));
-               event.mi.dy = (LONG) ((float) y * (65535.0f / height));
+               event.mi.dx = (LONG)((float) x * (65535.0f / width));
+               event.mi.dy = (LONG)((float) y * (65535.0f / height));
                event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
 
                if (flags & PTR_FLAGS_MOVE)
@@ -137,12 +135,12 @@ void win_shadow_input_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient
        }
 }
 
-void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
+void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem,
+        rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
 {
        INPUT event;
        float width;
        float height;
-
        ZeroMemory(&event, sizeof(INPUT));
 
        if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
@@ -153,11 +151,9 @@ void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, rdpSha
                {
                        width = (float) GetSystemMetrics(SM_CXSCREEN);
                        height = (float) GetSystemMetrics(SM_CYSCREEN);
-
                        event.mi.dx = (LONG)((float) x * (65535.0f / width));
                        event.mi.dy = (LONG)((float) y * (65535.0f / height));
                        event.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
-
                        SendInput(1, &event, sizeof(INPUT));
                }
 
@@ -178,24 +174,22 @@ void win_shadow_input_extended_mouse_event(winShadowSubsystem* subsystem, rdpSha
 }
 
 
-int win_shadow_invalidate_region(winShadowSubsystem* subsystem, int x, int y, int width, int height)
+int win_shadow_invalidate_region(winShadowSubsystem* subsystem, int x, int y,
+                                 int width, int height)
 {
        rdpShadowServer* server;
        rdpShadowSurface* surface;
        RECTANGLE_16 invalidRect;
-
        server = subsystem->server;
        surface = server->surface;
-
        invalidRect.left = x;
        invalidRect.top = y;
        invalidRect.right = x + width;
        invalidRect.bottom = y + height;
-
        EnterCriticalSection(&(surface->lock));
-       region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
+       region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                           &invalidRect);
        LeaveCriticalSection(&(surface->lock));
-
        return 1;
 }
 
@@ -207,13 +201,13 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem)
        int count;
        int status = 1;
        int nDstStep = 0;
+       DWORD DstFormat;
        BYTE* pDstData = NULL;
        rdpShadowServer* server;
        rdpShadowSurface* surface;
        RECTANGLE_16 surfaceRect;
        RECTANGLE_16 invalidRect;
        const RECTANGLE_16* extents;
-
        server = subsystem->server;
        surface = server->surface;
 
@@ -227,17 +221,15 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem)
        surfaceRect.top = surface->y;
        surfaceRect.right = surface->x + surface->width;
        surfaceRect.bottom = surface->y + surface->height;
-
-       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect);
+       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                               &surfaceRect);
 
        if (region16_is_empty(&(surface->invalidRegion)))
                return 1;
 
        extents = region16_extents(&(surface->invalidRegion));
        CopyMemory(&invalidRect, extents, sizeof(RECTANGLE_16));
-
        shadow_capture_align_clip_rect(&invalidRect, &surfaceRect);
-
        x = invalidRect.left;
        y = invalidRect.top;
        width = invalidRect.right - invalidRect.left;
@@ -251,43 +243,38 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem)
                height = surface->height;
        }
 
-       WLog_INFO(TAG, "SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d",
-               x, y, width, height, x + width, y + height);
-
+       WLog_INFO(TAG,
+                 "SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d",
+                 x, y, width, height, x + width, y + height);
 #if defined(WITH_WDS_API)
        {
                rdpGdi* gdi;
                shwContext* shw;
                rdpContext* context;
-
                shw = subsystem->shw;
                context = (rdpContext*) shw;
                gdi = context->gdi;
-
                pDstData = gdi->primary_buffer;
                nDstStep = gdi->width * 4;
+               DstFormat = gdi->dstFormat;
        }
 #elif defined(WITH_DXGI_1_2)
-       status = win_shadow_dxgi_fetch_frame_data(subsystem, &pDstData, &nDstStep, x, y, width, height);
+       DstFormat = PIXEL_FORMAT_BGRX32;
+       status = win_shadow_dxgi_fetch_frame_data(subsystem, &pDstData, &nDstStep, x, y,
+                width, height);
 #endif
 
        if (status <= 0)
                return status;
 
-       freerdp_image_copy(surface->data, PIXEL_FORMAT_XRGB32,
-                       surface->scanline, x - surface->x, y - surface->y, width, height,
-                       pDstData, PIXEL_FORMAT_XRGB32, nDstStep, 0, 0, NULL);
-
+       freerdp_image_copy(surface->data, surface->format,
+                          surface->scanline, x - surface->x, y - surface->y, width, height,
+                          pDstData, DstFormat, nDstStep, 0, 0, NULL);
        ArrayList_Lock(server->clients);
-
        count = ArrayList_Count(server->clients);
-
-       shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem);
-
+       shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
        ArrayList_Unlock(server->clients);
-
        region16_clear(&(surface->invalidRegion));
-
        return 1;
 }
 
@@ -299,9 +286,7 @@ void* win_shadow_subsystem_thread(winShadowSubsystem* subsystem)
        DWORD nCount;
        HANDLE events[32];
        HANDLE StopEvent;
-
        StopEvent = subsystem->server->StopEvent;
-
        nCount = 0;
        events[nCount++] = StopEvent;
        events[nCount++] = subsystem->RdpUpdateEnterEvent;
@@ -340,12 +325,9 @@ void* win_shadow_subsystem_thread(winShadowSubsystem* subsystem)
        UINT64 frameTime;
        HANDLE events[32];
        HANDLE StopEvent;
-
        StopEvent = subsystem->server->StopEvent;
-
        nCount = 0;
        events[nCount++] = StopEvent;
-
        fps = 16;
        dwInterval = 1000 / fps;
        frameTime = GetTickCount64() + dwInterval;
@@ -353,10 +335,8 @@ void* win_shadow_subsystem_thread(winShadowSubsystem* subsystem)
        while (1)
        {
                dwTimeout = INFINITE;
-
                cTime = GetTickCount64();
-               dwTimeout = (DWORD) ((cTime > frameTime) ? 0 : frameTime - cTime);
-
+               dwTimeout = (DWORD)((cTime > frameTime) ? 0 : frameTime - cTime);
                status = WaitForMultipleObjects(nCount, events, FALSE, dwTimeout);
 
                if (WaitForSingleObject(StopEvent, 0) == WAIT_OBJECT_0)
@@ -367,9 +347,8 @@ void* win_shadow_subsystem_thread(winShadowSubsystem* subsystem)
                if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
                {
                        int dxgi_status;
-
                        dxgi_status = win_shadow_dxgi_get_next_frame(subsystem);
-                       
+
                        if (dxgi_status > 0)
                                dxgi_status = win_shadow_dxgi_get_invalid_region(subsystem);
 
@@ -397,28 +376,22 @@ int win_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
        int numMonitors = 0;
        MONITOR_DEF* monitor;
        DISPLAY_DEVICE displayDevice;
-
        ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE));
        displayDevice.cb = sizeof(DISPLAY_DEVICE);
 
        if (EnumDisplayDevices(NULL, iDevNum, &displayDevice, 0))
        {
                hdc = CreateDC(displayDevice.DeviceName, NULL, NULL, NULL);
-
                desktopWidth = GetDeviceCaps(hdc, HORZRES);
                desktopHeight = GetDeviceCaps(hdc, VERTRES);
-
                index = 0;
                numMonitors = 1;
-
                monitor = &monitors[index];
-
                monitor->left = 0;
                monitor->top = 0;
                monitor->right = desktopWidth;
                monitor->bottom = desktopHeight;
                monitor->flags = 1;
-
                DeleteDC(hdc);
        }
 
@@ -429,25 +402,19 @@ int win_shadow_subsystem_init(winShadowSubsystem* subsystem)
 {
        int status;
        MONITOR_DEF* virtualScreen;
-
        subsystem->numMonitors = win_shadow_enum_monitors(subsystem->monitors, 16);
-
 #if defined(WITH_WDS_API)
        status = win_shadow_wds_init(subsystem);
 #elif defined(WITH_DXGI_1_2)
        status = win_shadow_dxgi_init(subsystem);
 #endif
-
        virtualScreen = &(subsystem->virtualScreen);
-
        virtualScreen->left = 0;
        virtualScreen->top = 0;
        virtualScreen->right = subsystem->width;
        virtualScreen->bottom = subsystem->height;
        virtualScreen->flags = 1;
-
        WLog_INFO(TAG, "width: %d height: %d", subsystem->width, subsystem->height);
-
        return 1;
 }
 
@@ -461,7 +428,6 @@ int win_shadow_subsystem_uninit(winShadowSubsystem* subsystem)
 #elif defined(WITH_DXGI_1_2)
        win_shadow_dxgi_uninit(subsystem);
 #endif
-
        return 1;
 }
 
@@ -473,8 +439,8 @@ int win_shadow_subsystem_start(winShadowSubsystem* subsystem)
                return -1;
 
        if (!(thread = CreateThread(NULL, 0,
-                       (LPTHREAD_START_ROUTINE) win_shadow_subsystem_thread,
-                       (void*) subsystem, 0, NULL)))
+                                   (LPTHREAD_START_ROUTINE) win_shadow_subsystem_thread,
+                                   (void*) subsystem, 0, NULL)))
        {
                WLog_ERR(TAG, "Failed to create thread");
                return -1;
@@ -497,25 +463,26 @@ void win_shadow_subsystem_free(winShadowSubsystem* subsystem)
                return;
 
        win_shadow_subsystem_uninit(subsystem);
-
        free(subsystem);
 }
 
 winShadowSubsystem* win_shadow_subsystem_new()
 {
        winShadowSubsystem* subsystem;
-
        subsystem = (winShadowSubsystem*) calloc(1, sizeof(winShadowSubsystem));
 
        if (!subsystem)
                return NULL;
 
-       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent) win_shadow_input_synchronize_event;
-       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent) win_shadow_input_keyboard_event;
-       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent) win_shadow_input_unicode_keyboard_event;
+       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent)
+                                     win_shadow_input_synchronize_event;
+       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent)
+                                  win_shadow_input_keyboard_event;
+       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent)
+                                         win_shadow_input_unicode_keyboard_event;
        subsystem->MouseEvent = (pfnShadowMouseEvent) win_shadow_input_mouse_event;
-       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent) win_shadow_input_extended_mouse_event;
-
+       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent)
+                                       win_shadow_input_extended_mouse_event;
        return subsystem;
 }
 
@@ -523,14 +490,10 @@ FREERDP_API int Win_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints)
 {
        pEntryPoints->New = (pfnShadowSubsystemNew) win_shadow_subsystem_new;
        pEntryPoints->Free = (pfnShadowSubsystemFree) win_shadow_subsystem_free;
-
        pEntryPoints->Init = (pfnShadowSubsystemInit) win_shadow_subsystem_init;
        pEntryPoints->Uninit = (pfnShadowSubsystemInit) win_shadow_subsystem_uninit;
-
        pEntryPoints->Start = (pfnShadowSubsystemStart) win_shadow_subsystem_start;
        pEntryPoints->Stop = (pfnShadowSubsystemStop) win_shadow_subsystem_stop;
-
        pEntryPoints->EnumMonitors = (pfnShadowEnumMonitors) win_shadow_enum_monitors;
-
        return 1;
 }
index 0d0f624..445894c 100644 (file)
@@ -44,7 +44,7 @@
 
 #define TAG SERVER_TAG("shadow.x11")
 
-int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors);
+static int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors);
 
 #ifdef WITH_PAM
 
@@ -67,16 +67,17 @@ struct _SHADOW_PAM_AUTH_INFO
 };
 typedef struct _SHADOW_PAM_AUTH_INFO SHADOW_PAM_AUTH_INFO;
 
-int x11_shadow_pam_conv(int num_msg, const struct pam_message** msg, struct pam_response** resp, void* appdata_ptr)
+static int x11_shadow_pam_conv(int num_msg, const struct pam_message** msg,
+                              struct pam_response** resp, void* appdata_ptr)
 {
        int index;
        int pam_status = PAM_BUF_ERR;
        SHADOW_PAM_AUTH_DATA* appdata;
        struct pam_response* response;
-
        appdata = (SHADOW_PAM_AUTH_DATA*) appdata_ptr;
 
-       if (!(response = (struct pam_response*) calloc(num_msg, sizeof(struct pam_response))))
+       if (!(response = (struct pam_response*) calloc(num_msg,
+                        sizeof(struct pam_response))))
                return PAM_BUF_ERR;
 
        for (index = 0; index < num_msg; index++)
@@ -85,15 +86,19 @@ int x11_shadow_pam_conv(int num_msg, const struct pam_message** msg, struct pam_
                {
                        case PAM_PROMPT_ECHO_ON:
                                response[index].resp = _strdup(appdata->user);
+
                                if (!response[index].resp)
                                        goto out_fail;
+
                                response[index].resp_retcode = PAM_SUCCESS;
                                break;
 
                        case PAM_PROMPT_ECHO_OFF:
                                response[index].resp = _strdup(appdata->password);
+
                                if (!response[index].resp)
                                        goto out_fail;
+
                                response[index].resp_retcode = PAM_SUCCESS;
                                break;
 
@@ -105,8 +110,8 @@ int x11_shadow_pam_conv(int num_msg, const struct pam_message** msg, struct pam_
 
        *resp = response;
        return PAM_SUCCESS;
-
 out_fail:
+
        for (index = 0; index < num_msg; ++index)
        {
                if (response[index].resp)
@@ -115,13 +120,14 @@ out_fail:
                        free(response[index].resp);
                }
        }
+
        memset(response, 0, sizeof(struct pam_response) * num_msg);
        free(response);
        *resp = NULL;
        return PAM_CONV_ERR;
 }
 
-int x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info)
+static int x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info)
 {
        if (PathFileExistsA("/etc/pam.d/lightdm"))
        {
@@ -154,11 +160,12 @@ int x11_shadow_pam_get_service_name(SHADOW_PAM_AUTH_INFO* info)
        return 1;
 }
 
-int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, rdpShadowClient* client, const char* user, const char* domain, const char* password)
+static int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem,
+                                      rdpShadowClient* client, const char* user, const char* domain,
+                                      const char* password)
 {
        int pam_status;
        SHADOW_PAM_AUTH_INFO* info;
-
        info = calloc(1, sizeof(SHADOW_PAM_AUTH_INFO));
 
        if (!info)
@@ -173,10 +180,8 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, rdpShadowClient*
        info->appdata.user = user;
        info->appdata.domain = domain;
        info->appdata.password = password;
-
        info->pamc.conv = &x11_shadow_pam_conv;
        info->pamc.appdata_ptr = &(info->appdata);
-
        pam_status = pam_start(info->service_name, 0, &(info->pamc), &(info->handle));
 
        if (pam_status != PAM_SUCCESS)
@@ -190,7 +195,8 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, rdpShadowClient*
 
        if (pam_status != PAM_SUCCESS)
        {
-               WLog_ERR(TAG, "pam_authenticate failure: %s", pam_strerror(info->handle, pam_status));
+               WLog_ERR(TAG, "pam_authenticate failure: %s", pam_strerror(info->handle,
+                        pam_status));
                free(info);
                return -1;
        }
@@ -199,24 +205,25 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, rdpShadowClient*
 
        if (pam_status != PAM_SUCCESS)
        {
-               WLog_ERR(TAG, "pam_acct_mgmt failure: %s", pam_strerror(info->handle, pam_status));
+               WLog_ERR(TAG, "pam_acct_mgmt failure: %s", pam_strerror(info->handle,
+                        pam_status));
                free(info);
                return -1;
        }
 
        free(info);
-
        return 1;
 }
 
 #endif
 
-void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT32 flags)
+static void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem,
+       rdpShadowClient* client, UINT32 flags)
 {
-
 }
 
-void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
+static void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem,
+       rdpShadowClient* client, UINT16 flags, UINT16 code)
 {
 #ifdef WITH_XTEST
        DWORD vkcode;
@@ -239,7 +246,6 @@ void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowCli
        if (keycode != 0)
        {
                XLockDisplay(subsystem->display);
-
                XTestGrabControl(subsystem->display, True);
 
                if (flags & KBD_FLAGS_DOWN)
@@ -248,36 +254,33 @@ void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowCli
                        XTestFakeKeyEvent(subsystem->display, keycode, False, CurrentTime);
 
                XTestGrabControl(subsystem->display, False);
-
                XFlush(subsystem->display);
-
                XUnlockDisplay(subsystem->display);
        }
+
 #endif
 }
 
-void x11_shadow_input_unicode_keyboard_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
+static void x11_shadow_input_unicode_keyboard_event(x11ShadowSubsystem*
+       subsystem,
+       rdpShadowClient* client, UINT16 flags, UINT16 code)
 {
-
 }
 
-void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
+static void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem,
+       rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
 {
 #ifdef WITH_XTEST
        int button = 0;
        BOOL down = FALSE;
        rdpShadowServer* server;
        rdpShadowSurface* surface;
-
        server = subsystem->server;
        surface = server->surface;
        subsystem->lastMouseClient = client;
-
        x += surface->x;
        y += surface->y;
-
        XLockDisplay(subsystem->display);
-
        XTestGrabControl(subsystem->display, True);
 
        if (flags & PTR_FLAGS_WHEEL)
@@ -288,7 +291,6 @@ void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient
                        negative = TRUE;
 
                button = (negative) ? 5 : 4;
-
                XTestFakeButtonEvent(subsystem->display, button, True, CurrentTime);
                XTestFakeButtonEvent(subsystem->display, button, False, CurrentTime);
        }
@@ -312,32 +314,26 @@ void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient
        }
 
        XTestGrabControl(subsystem->display, False);
-
        XFlush(subsystem->display);
-
        XUnlockDisplay(subsystem->display);
 #endif
 }
 
-void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem, rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
+static void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem,
+       rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
 {
 #ifdef WITH_XTEST
        int button = 0;
        BOOL down = FALSE;
        rdpShadowServer* server;
        rdpShadowSurface* surface;
-
        server = subsystem->server;
        surface = server->surface;
        subsystem->lastMouseClient = client;
-
        x += surface->x;
        y += surface->y;
-
        XLockDisplay(subsystem->display);
-
        XTestGrabControl(subsystem->display, True);
-
        XTestFakeMotionEvent(subsystem->display, 0, x, y, CurrentTime);
 
        if (flags & PTR_XFLAGS_BUTTON1)
@@ -352,16 +348,14 @@ void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem, rdpSha
                XTestFakeButtonEvent(subsystem->display, button, down, CurrentTime);
 
        XTestGrabControl(subsystem->display, False);
-
        XFlush(subsystem->display);
-
        XUnlockDisplay(subsystem->display);
 #endif
 }
 
 static void x11_shadow_message_free(UINT32 id, SHADOW_MSG_OUT* msg)
 {
-       switch(id)
+       switch (id)
        {
                case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
                        free(msg);
@@ -380,7 +374,7 @@ static void x11_shadow_message_free(UINT32 id, SHADOW_MSG_OUT* msg)
        }
 }
 
-int x11_shadow_pointer_position_update(x11ShadowSubsystem* subsystem)
+static int x11_shadow_pointer_position_update(x11ShadowSubsystem* subsystem)
 {
        SHADOW_MSG_OUT_POINTER_POSITION_UPDATE* msg;
        UINT32 msgId = SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID;
@@ -388,8 +382,8 @@ int x11_shadow_pointer_position_update(x11ShadowSubsystem* subsystem)
        rdpShadowServer* server;
        int count = 0;
        int index = 0;
-
-       msg = (SHADOW_MSG_OUT_POINTER_POSITION_UPDATE*) calloc(1, sizeof(SHADOW_MSG_OUT_POINTER_POSITION_UPDATE));
+       msg = (SHADOW_MSG_OUT_POINTER_POSITION_UPDATE*) calloc(1,
+               sizeof(SHADOW_MSG_OUT_POINTER_POSITION_UPDATE));
 
        if (!msg)
                return -1;
@@ -397,32 +391,31 @@ int x11_shadow_pointer_position_update(x11ShadowSubsystem* subsystem)
        msg->xPos = subsystem->pointerX;
        msg->yPos = subsystem->pointerY;
        msg->Free = x11_shadow_message_free;
-
        server = subsystem->server;
-
        ArrayList_Lock(server->clients);
+
        for (index = 0; index < ArrayList_Count(server->clients); index++)
        {
                client = (rdpShadowClient*)ArrayList_GetItem(server->clients, index);
 
                /* Skip the client which send us the latest mouse event */
                if (client == subsystem->lastMouseClient)
-                       continue; 
+                       continue;
 
                if (shadow_client_post_msg(client, NULL, msgId, (SHADOW_MSG_OUT*) msg, NULL))
                        count++;
        }
-       ArrayList_Unlock(server->clients);
 
+       ArrayList_Unlock(server->clients);
        return count;
 }
 
-int x11_shadow_pointer_alpha_update(x11ShadowSubsystem* subsystem)
+static int x11_shadow_pointer_alpha_update(x11ShadowSubsystem* subsystem)
 {
        SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* msg;
        UINT32 msgId = SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID;
-
-       msg = (SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE*) calloc(1, sizeof(SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE));
+       msg = (SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE*) calloc(1,
+               sizeof(SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE));
 
        if (!msg)
                return -1;
@@ -432,24 +425,24 @@ int x11_shadow_pointer_alpha_update(x11ShadowSubsystem* subsystem)
        msg->width = subsystem->cursorWidth;
        msg->height = subsystem->cursorHeight;
 
-       if (shadow_subsystem_pointer_convert_alpha_pointer_data(subsystem->cursorPixels, TRUE,
-                       msg->width, msg->height, msg) < 0)
+       if (shadow_subsystem_pointer_convert_alpha_pointer_data(subsystem->cursorPixels,
+               TRUE,
+               msg->width, msg->height, msg) < 0)
        {
-               free (msg);
+               free(msg);
                return -1;
        }
 
        msg->Free = x11_shadow_message_free;
-
-       return shadow_client_boardcast_msg(subsystem->server, NULL, msgId, (SHADOW_MSG_OUT*) msg, NULL) ? 1 : -1;
+       return shadow_client_boardcast_msg(subsystem->server, NULL, msgId,
+                                          (SHADOW_MSG_OUT*) msg, NULL) ? 1 : -1;
 }
 
-int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
+static int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
 {
        int x, y, n, k;
        rdpShadowServer* server;
        rdpShadowSurface* surface;
-
        server = subsystem->server;
        surface = server->surface;
 
@@ -458,7 +451,6 @@ int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
 #ifdef WITH_XFIXES
                UINT32* pDstPixel;
                XFixesCursorImage* ci;
-
                XLockDisplay(subsystem->display);
                ci = XFixesGetCursorImage(subsystem->display);
                XUnlockDisplay(subsystem->display);
@@ -477,12 +469,9 @@ int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
 
                subsystem->cursorHotX = ci->xhot;
                subsystem->cursorHotY = ci->yhot;
-
                subsystem->cursorWidth = ci->width;
                subsystem->cursorHeight = ci->height;
-
                subsystem->cursorId = ci->cursor_serial;
-
                n = ci->width * ci->height;
                pDstPixel = (UINT32*) subsystem->cursorPixels;
 
@@ -493,7 +482,6 @@ int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
                }
 
                XFree(ci);
-
                x11_shadow_pointer_alpha_update(subsystem);
 #endif
        }
@@ -503,18 +491,16 @@ int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
                int win_x, win_y;
                int root_x, root_y;
                Window root, child;
-
                XLockDisplay(subsystem->display);
 
                if (!XQueryPointer(subsystem->display, subsystem->root_window,
-                               &root, &child, &root_x, &root_y, &win_x, &win_y, &mask))
+                                  &root, &child, &root_x, &root_y, &win_x, &win_y, &mask))
                {
                        XUnlockDisplay(subsystem->display);
                        return -1;
                }
 
                XUnlockDisplay(subsystem->display);
-
                x = root_x;
                y = root_y;
        }
@@ -530,34 +516,36 @@ int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
        {
                subsystem->pointerX = x;
                subsystem->pointerY = y;
-
                x11_shadow_pointer_position_update(subsystem);
        }
 
        return 1;
 }
 
-int x11_shadow_handle_xevent(x11ShadowSubsystem* subsystem, XEvent* xevent)
+static int x11_shadow_handle_xevent(x11ShadowSubsystem* subsystem,
+                                   XEvent* xevent)
 {
        if (xevent->type == MotionNotify)
        {
-
        }
+
 #ifdef WITH_XFIXES
        else if (xevent->type == subsystem->xfixes_cursor_notify_event)
        {
                x11_shadow_query_cursor(subsystem, TRUE);
        }
+
 #endif
        else
        {
-
        }
 
        return 1;
 }
 
-void x11_shadow_validate_region(x11ShadowSubsystem* subsystem, int x, int y, int width, int height)
+static void x11_shadow_validate_region(x11ShadowSubsystem* subsystem, int x,
+                                      int y,
+                                      int width, int height)
 {
        XRectangle region;
 
@@ -568,16 +556,16 @@ void x11_shadow_validate_region(x11ShadowSubsystem* subsystem, int x, int y, int
        region.y = y;
        region.width = width;
        region.height = height;
-
 #ifdef WITH_XFIXES
        XLockDisplay(subsystem->display);
        XFixesSetRegion(subsystem->display, subsystem->xdamage_region, &region, 1);
-       XDamageSubtract(subsystem->display, subsystem->xdamage, subsystem->xdamage_region, None);
+       XDamageSubtract(subsystem->display, subsystem->xdamage,
+                       subsystem->xdamage_region, None);
        XUnlockDisplay(subsystem->display);
 #endif
 }
 
-int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
+static int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
 {
        int x, y;
        int nXSrc;
@@ -596,15 +584,11 @@ int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
        BYTE* pDstPixel;
        BYTE A, R, G, B;
        rdpShadowSurface* surface;
-
        surface = subsystem->server->surface;
-
        nXSrc = 0;
        nYSrc = 0;
-
        nWidth = subsystem->cursorWidth;
        nHeight = subsystem->cursorHeight;
-
        nXDst = subsystem->pointerX - subsystem->cursorHotX;
        nYDst = subsystem->pointerY - subsystem->cursorHotY;
 
@@ -646,13 +630,10 @@ int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
 
        pSrcData = subsystem->cursorPixels;
        nSrcStep = subsystem->cursorWidth * 4;
-
        pDstData = surface->data;
        nDstStep = surface->scanline;
-
        nSrcPad = (nSrcStep - (nWidth * 4));
        nDstPad = (nDstStep - (nWidth * 4));
-
        pSrcPixel = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)];
        pDstPixel = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
 
@@ -692,11 +673,10 @@ int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
        return 1;
 }
 
-BOOL x11_shadow_check_resize(x11ShadowSubsystem* subsystem)
+static BOOL x11_shadow_check_resize(x11ShadowSubsystem* subsystem)
 {
        MONITOR_DEF* virtualScreen;
        XWindowAttributes attr;
-
        XLockDisplay(subsystem->display);
        XGetWindowAttributes(subsystem->display, subsystem->root_window, &attr);
        XUnlockDisplay(subsystem->display);
@@ -705,31 +685,28 @@ BOOL x11_shadow_check_resize(x11ShadowSubsystem* subsystem)
        {
                /* Screen size changed. Refresh monitor definitions and trigger screen resize */
                subsystem->numMonitors = x11_shadow_enum_monitors(subsystem->monitors, 16);
-
                shadow_screen_resize(subsystem->server->screen);
-
                subsystem->width = attr.width;
                subsystem->height = attr.height;
-
                virtualScreen = &(subsystem->virtualScreen);
                virtualScreen->left = 0;
                virtualScreen->top = 0;
                virtualScreen->right = subsystem->width;
                virtualScreen->bottom = subsystem->height;
                virtualScreen->flags = 1;
-
                return TRUE;
        }
 
        return FALSE;
 }
 
-static int x11_shadow_error_handler_for_capture(Display * display, XErrorEvent * event)
+static int x11_shadow_error_handler_for_capture(Display* display,
+       XErrorEvent* event)
 {
-    char msg[256];
-    XGetErrorText(display, event->error_code, (char *) &msg, sizeof(msg));
-       WLog_ERR(TAG, "X11 error: %s Error code: %x, request code: %x, minor code: %x", 
-                       msg, event->error_code, event->request_code, event->minor_code);
+       char msg[256];
+       XGetErrorText(display, event->error_code, (char*) &msg, sizeof(msg));
+       WLog_ERR(TAG, "X11 error: %s Error code: %x, request code: %x, minor code: %x",
+                msg, event->error_code, event->request_code, event->minor_code);
 
        /* Ignore BAD MATCH error during image capture. Abort in other case */
        if (event->error_code != BadMatch)
@@ -740,7 +717,7 @@ static int x11_shadow_error_handler_for_capture(Display * display, XErrorEvent *
        return 0;
 }
 
-int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
+static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
 {
        int count;
        int status;
@@ -752,12 +729,10 @@ int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
        rdpShadowSurface* surface;
        RECTANGLE_16 invalidRect;
        RECTANGLE_16 surfaceRect;
-       const RECTANGLE_16 *extents;
-
+       const RECTANGLE_16* extents;
        server = subsystem->server;
        surface = server->surface;
        screen = server->screen;
-
        count = ArrayList_Count(server->clients);
 
        if (count < 1)
@@ -767,11 +742,9 @@ int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
        surfaceRect.top = 0;
        surfaceRect.right = surface->width;
        surfaceRect.bottom = surface->height;
-
        XLockDisplay(subsystem->display);
-
        /*
-        * Ignore BadMatch error during image capture. The screen size may be 
+        * Ignore BadMatch error during image capture. The screen size may be
         * changed outside. We will resize to correct resolution at next frame
         */
        XSetErrorHandler(x11_shadow_error_handler_for_capture);
@@ -779,65 +752,59 @@ int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
        if (subsystem->use_xshm)
        {
                image = subsystem->fb_image;
-
                XCopyArea(subsystem->display, subsystem->root_window, subsystem->fb_pixmap,
-                               subsystem->xshm_gc, 0, 0, subsystem->width, subsystem->height, 0, 0);
-
-               status = shadow_capture_compare(surface->data, surface->scanline, surface->width, surface->height,
-                               (BYTE*) &(image->data[surface->width * 4]), image->bytes_per_line, &invalidRect);
+                         subsystem->xshm_gc, 0, 0, subsystem->width, subsystem->height, 0, 0);
+               status = shadow_capture_compare(surface->data, surface->scanline,
+                                               surface->width, surface->height,
+                                               (BYTE*) & (image->data[surface->width * 4]), image->bytes_per_line,
+                                               &invalidRect);
        }
        else
        {
                image = XGetImage(subsystem->display, subsystem->root_window,
-                                       surface->x, surface->y, surface->width, surface->height, AllPlanes, ZPixmap);
+                                 surface->x, surface->y, surface->width, surface->height, AllPlanes, ZPixmap);
 
                if (!image)
                {
                        /*
                         * BadMatch error happened. The size may have been changed again.
-                        * Give up this frame and we will resize again in next frame 
+                        * Give up this frame and we will resize again in next frame
                         */
                        goto fail_capture;
                }
 
-               status = shadow_capture_compare(surface->data, surface->scanline, surface->width, surface->height,
-                               (BYTE*) image->data, image->bytes_per_line, &invalidRect);
+               status = shadow_capture_compare(surface->data, surface->scanline,
+                                               surface->width, surface->height,
+                                               (BYTE*) image->data, image->bytes_per_line, &invalidRect);
        }
 
        /* Restore the default error handler */
        XSetErrorHandler(NULL);
-
        XSync(subsystem->display, False);
-
        XUnlockDisplay(subsystem->display);
-
-       region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect);
-       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion), &surfaceRect);
+       region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                           &invalidRect);
+       region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
+                               &surfaceRect);
 
        if (!region16_is_empty(&(surface->invalidRegion)))
        {
                extents = region16_extents(&(surface->invalidRegion));
-
                x = extents->left;
                y = extents->top;
                width = extents->right - extents->left;
                height = extents->bottom - extents->top;
-
-               freerdp_image_copy(surface->data, PIXEL_FORMAT_XRGB32,
-                               surface->scanline, x, y, width, height,
-                               (BYTE*) image->data, PIXEL_FORMAT_XRGB32,
-                               image->bytes_per_line, x, y, NULL);
-
+               freerdp_image_copy(surface->data, surface->format,
+                                  surface->scanline, x, y, width, height,
+                                  (BYTE*) image->data, PIXEL_FORMAT_BGRX32,
+                                  image->bytes_per_line, x, y, NULL);
                //x11_shadow_blend_cursor(subsystem);
-
                count = ArrayList_Count(server->clients);
-
-               shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem);
+               shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
 
                if (count == 1)
                {
                        rdpShadowClient* client;
-
                        client = (rdpShadowClient*) ArrayList_GetItem(server->clients, 0);
 
                        if (client)
@@ -853,7 +820,6 @@ int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
                XDestroyImage(image);
 
        return 1;
-
 fail_capture:
        XSetErrorHandler(NULL);
        XSync(subsystem->display, False);
@@ -861,13 +827,15 @@ fail_capture:
        return 0;
 }
 
-int x11_shadow_subsystem_process_message(x11ShadowSubsystem* subsystem, wMessage* message)
+static int x11_shadow_subsystem_process_message(x11ShadowSubsystem* subsystem,
+       wMessage* message)
 {
-       switch(message->id)
+       switch (message->id)
        {
                case SHADOW_MSG_IN_REFRESH_REQUEST_ID:
-                       shadow_subsystem_frame_update((rdpShadowSubsystem *)subsystem);
+                       shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem);
                        break;
+
                default:
                        WLog_ERR(TAG, "Unknown message id: %u", message->id);
                        break;
@@ -879,7 +847,7 @@ int x11_shadow_subsystem_process_message(x11ShadowSubsystem* subsystem, wMessage
        return 1;
 }
 
-void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
+static void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
 {
        XEvent xevent;
        DWORD status;
@@ -891,13 +859,10 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
        HANDLE events[32];
        wMessage message;
        wMessagePipe* MsgPipe;
-
        MsgPipe = subsystem->MsgPipe;
-
        nCount = 0;
        events[nCount++] = subsystem->event;
        events[nCount++] = MessageQueue_Event(MsgPipe->In);
-
        subsystem->captureFrameRate = 16;
        dwInterval = 1000 / subsystem->captureFrameRate;
        frameTime = GetTickCount64() + dwInterval;
@@ -906,7 +871,6 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
        {
                cTime = GetTickCount64();
                dwTimeout = (cTime > frameTime) ? 0 : frameTime - cTime;
-
                status = WaitForMultipleObjects(nCount, events, FALSE, dwTimeout);
 
                if (WaitForSingleObject(MessageQueue_Event(MsgPipe->In), 0) == WAIT_OBJECT_0)
@@ -938,7 +902,6 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
                        x11_shadow_check_resize(subsystem);
                        x11_shadow_screen_grab(subsystem);
                        x11_shadow_query_cursor(subsystem, FALSE);
-
                        dwInterval = 1000 / subsystem->captureFrameRate;
                        frameTime += dwInterval;
                }
@@ -948,7 +911,7 @@ void* x11_shadow_subsystem_thread(x11ShadowSubsystem* subsystem)
        return NULL;
 }
 
-int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
+static int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
 {
        if (subsystem->display)
                return 1; /* initialize once */
@@ -974,7 +937,6 @@ int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
        subsystem->width = WidthOfScreen(subsystem->screen);
        subsystem->height = HeightOfScreen(subsystem->screen);
        subsystem->root_window = RootWindow(subsystem->display, subsystem->number);
-
        return 1;
 }
 
@@ -992,10 +954,8 @@ static int x11_shadow_xfixes_init(x11ShadowSubsystem* subsystem)
                return -1;
 
        subsystem->xfixes_cursor_notify_event = xfixes_event + XFixesCursorNotify;
-
        XFixesSelectCursorInput(subsystem->display, subsystem->root_window,
-                       XFixesDisplayCursorNotifyMask);
-
+                               XFixesDisplayCursorNotifyMask);
        return 1;
 #else
        return -1;
@@ -1008,10 +968,10 @@ static int x11_shadow_xinerama_init(x11ShadowSubsystem* subsystem)
        int major, minor;
        int xinerama_event;
        int xinerama_error;
-
        x11_shadow_subsystem_base_init(subsystem);
 
-       if (!XineramaQueryExtension(subsystem->display, &xinerama_event, &xinerama_error))
+       if (!XineramaQueryExtension(subsystem->display, &xinerama_event,
+                                   &xinerama_error))
                return -1;
 
        if (!XDamageQueryVersion(subsystem->display, &major, &minor))
@@ -1046,7 +1006,8 @@ static int x11_shadow_xdamage_init(x11ShadowSubsystem* subsystem)
                return -1;
 
        subsystem->xdamage_notify_event = damage_event + XDamageNotify;
-       subsystem->xdamage = XDamageCreate(subsystem->display, subsystem->root_window, XDamageReportDeltaRectangles);
+       subsystem->xdamage = XDamageCreate(subsystem->display, subsystem->root_window,
+                                          XDamageReportDeltaRectangles);
 
        if (!subsystem->xdamage)
                return -1;
@@ -1056,8 +1017,8 @@ static int x11_shadow_xdamage_init(x11ShadowSubsystem* subsystem)
 
        if (!subsystem->xdamage_region)
                return -1;
-#endif
 
+#endif
        return 1;
 #else
        return -1;
@@ -1080,11 +1041,11 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
                return -1;
 
        subsystem->fb_shm_info.shmid = -1;
-       subsystem->fb_shm_info.shmaddr = (char*) -1;
+       subsystem->fb_shm_info.shmaddr = (char*) - 1;
        subsystem->fb_shm_info.readOnly = False;
-
-       subsystem->fb_image = XShmCreateImage(subsystem->display, subsystem->visual, subsystem->depth,
-                       ZPixmap, NULL, &(subsystem->fb_shm_info), subsystem->width, subsystem->height);
+       subsystem->fb_image = XShmCreateImage(subsystem->display, subsystem->visual,
+                                             subsystem->depth,
+                                             ZPixmap, NULL, &(subsystem->fb_shm_info), subsystem->width, subsystem->height);
 
        if (!subsystem->fb_image)
        {
@@ -1093,7 +1054,8 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
        }
 
        subsystem->fb_shm_info.shmid = shmget(IPC_PRIVATE,
-                       subsystem->fb_image->bytes_per_line * subsystem->fb_image->height, IPC_CREAT | 0600);
+                                             subsystem->fb_image->bytes_per_line * subsystem->fb_image->height,
+                                             IPC_CREAT | 0600);
 
        if (subsystem->fb_shm_info.shmid == -1)
        {
@@ -1104,7 +1066,7 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
        subsystem->fb_shm_info.shmaddr = shmat(subsystem->fb_shm_info.shmid, 0, 0);
        subsystem->fb_image->data = subsystem->fb_shm_info.shmaddr;
 
-       if (subsystem->fb_shm_info.shmaddr == ((char*) -1))
+       if (subsystem->fb_shm_info.shmaddr == ((char*) - 1))
        {
                WLog_ERR(TAG, "shmat failed");
                return -1;
@@ -1114,13 +1076,11 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
                return -1;
 
        XSync(subsystem->display, False);
-
        shmctl(subsystem->fb_shm_info.shmid, IPC_RMID, 0);
-
        subsystem->fb_pixmap = XShmCreatePixmap(subsystem->display,
-                       subsystem->root_window, subsystem->fb_image->data, &(subsystem->fb_shm_info),
-                       subsystem->fb_image->width, subsystem->fb_image->height, subsystem->fb_image->depth);
-
+                                               subsystem->root_window, subsystem->fb_image->data, &(subsystem->fb_shm_info),
+                                               subsystem->fb_image->width, subsystem->fb_image->height,
+                                               subsystem->fb_image->depth);
        XSync(subsystem->display, False);
 
        if (!subsystem->fb_pixmap)
@@ -1128,13 +1088,10 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
 
        values.subwindow_mode = IncludeInferiors;
        values.graphics_exposures = False;
-
        subsystem->xshm_gc = XCreateGC(subsystem->display, subsystem->root_window,
-                       GCSubwindowMode | GCGraphicsExposures, &values);
-
+                                      GCSubwindowMode | GCGraphicsExposures, &values);
        XSetFunction(subsystem->display, subsystem->xshm_gc, GXcopy);
        XSync(subsystem->display, False);
-
        return 1;
 }
 
@@ -1160,7 +1117,6 @@ int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
 
        displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
        displayHeight = HeightOfScreen(DefaultScreenOfDisplay(display));
-
 #ifdef WITH_XINERAMA
        {
                int major, minor;
@@ -1170,7 +1126,7 @@ int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
                XineramaScreenInfo* screens;
 
                if (XineramaQueryExtension(display, &xinerama_event, &xinerama_error) &&
-                               XDamageQueryVersion(display, &major, &minor) && XineramaIsActive(display))
+                   XDamageQueryVersion(display, &major, &minor) && XineramaIsActive(display))
                {
                        screens = XineramaQueryScreens(display, &numMonitors);
 
@@ -1183,7 +1139,6 @@ int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
                                {
                                        screen = &screens[index];
                                        monitor = &monitors[index];
-
                                        monitor->left = screen->x_org;
                                        monitor->top = screen->y_org;
                                        monitor->right = monitor->left + screen->width;
@@ -1196,16 +1151,13 @@ int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
                }
        }
 #endif
-
        XCloseDisplay(display);
 
        if (numMonitors < 1)
        {
                index = 0;
                numMonitors = 1;
-
                monitor = &monitors[index];
-
                monitor->left = 0;
                monitor->top = 0;
                monitor->right = displayWidth;
@@ -1216,7 +1168,7 @@ int x11_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors)
        return numMonitors;
 }
 
-int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
+static int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
 {
        int i;
        int pf_count;
@@ -1229,9 +1181,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
        XPixmapFormatValues* pf;
        XPixmapFormatValues* pfs;
        MONITOR_DEF* virtualScreen;
-
        subsystem->numMonitors = x11_shadow_enum_monitors(subsystem->monitors, 16);
-
        x11_shadow_subsystem_base_init(subsystem);
 
        if ((subsystem->depth != 24) && (subsystem->depth != 32))
@@ -1243,7 +1193,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
        extensions = XListExtensions(subsystem->display, &nextensions);
 
        if (!extensions || (nextensions < 0))
-               return -1;
+                   return -1;
 
        for (i = 0; i < nextensions; i++)
        {
@@ -1275,13 +1225,13 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
                        break;
                }
        }
-       XFree(pfs);
 
+       XFree(pfs);
        ZeroMemory(&template, sizeof(template));
        template.class = TrueColor;
        template.screen = subsystem->number;
-
-       vis = XGetVisualInfo(subsystem->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
+       vis = XGetVisualInfo(subsystem->display, VisualClassMask | VisualScreenMask,
+                            &template, &vi_count);
 
        if (!vis)
        {
@@ -1299,13 +1249,14 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
                        break;
                }
        }
-       XFree(vis);
-
-       XSelectInput(subsystem->display, subsystem->root_window, SubstructureNotifyMask);
 
+       XFree(vis);
+       XSelectInput(subsystem->display, subsystem->root_window,
+                    SubstructureNotifyMask);
        subsystem->cursorMaxWidth = 256;
        subsystem->cursorMaxHeight = 256;
-       subsystem->cursorPixels = _aligned_malloc(subsystem->cursorMaxWidth * subsystem->cursorMaxHeight * 4, 16);
+       subsystem->cursorPixels = _aligned_malloc(subsystem->cursorMaxWidth *
+               subsystem->cursorMaxHeight * 4, 16);
 
        if (!subsystem->cursorPixels)
                return -1;
@@ -1315,46 +1266,44 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
        if (subsystem->use_xfixes)
        {
                if (x11_shadow_xfixes_init(subsystem) < 0)
-                       subsystem->use_xfixes = FALSE;
+                           subsystem->use_xfixes = FALSE;
        }
 
        if (subsystem->use_xinerama)
        {
                if (x11_shadow_xinerama_init(subsystem) < 0)
-                       subsystem->use_xinerama = FALSE;
+                           subsystem->use_xinerama = FALSE;
        }
 
        if (subsystem->use_xshm)
        {
                if (x11_shadow_xshm_init(subsystem) < 0)
-                       subsystem->use_xshm = FALSE;
+                           subsystem->use_xshm = FALSE;
        }
 
        if (subsystem->use_xdamage)
        {
                if (x11_shadow_xdamage_init(subsystem) < 0)
-                       subsystem->use_xdamage = FALSE;
+                           subsystem->use_xdamage = FALSE;
        }
 
        if (!(subsystem->event = CreateFileDescriptorEvent(NULL, FALSE, FALSE,
-                                                       subsystem->xfds, WINPR_FD_READ)))
+               subsystem->xfds, WINPR_FD_READ)))
                return -1;
 
        virtualScreen = &(subsystem->virtualScreen);
-
        virtualScreen->left = 0;
        virtualScreen->top = 0;
        virtualScreen->right = subsystem->width;
        virtualScreen->bottom = subsystem->height;
        virtualScreen->flags = 1;
-
        WLog_INFO(TAG, "X11 Extensions: XFixes: %d Xinerama: %d XDamage: %d XShm: %d",
-                       subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage, subsystem->use_xshm);
-
+                 subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage,
+                 subsystem->use_xshm);
        return 1;
 }
 
-int x11_shadow_subsystem_uninit(x11ShadowSubsystem* subsystem)
+static int x11_shadow_subsystem_uninit(x11ShadowSubsystem* subsystem)
 {
        if (!subsystem)
                return -1;
@@ -1380,14 +1329,14 @@ int x11_shadow_subsystem_uninit(x11ShadowSubsystem* subsystem)
        return 1;
 }
 
-int x11_shadow_subsystem_start(x11ShadowSubsystem* subsystem)
+static int x11_shadow_subsystem_start(x11ShadowSubsystem* subsystem)
 {
        if (!subsystem)
                return -1;
 
        if (!(subsystem->thread = CreateThread(NULL, 0,
-                       (LPTHREAD_START_ROUTINE) x11_shadow_subsystem_thread,
-                       (void*) subsystem, 0, NULL)))
+                                              (LPTHREAD_START_ROUTINE) x11_shadow_subsystem_thread,
+                                              (void*) subsystem, 0, NULL)))
        {
                WLog_ERR(TAG, "Failed to create thread");
                return -1;
@@ -1396,7 +1345,7 @@ int x11_shadow_subsystem_start(x11ShadowSubsystem* subsystem)
        return 1;
 }
 
-int x11_shadow_subsystem_stop(x11ShadowSubsystem* subsystem)
+static int x11_shadow_subsystem_stop(x11ShadowSubsystem* subsystem)
 {
        if (!subsystem)
                return -1;
@@ -1405,6 +1354,7 @@ int x11_shadow_subsystem_stop(x11ShadowSubsystem* subsystem)
        {
                if (MessageQueue_PostQuit(subsystem->MsgPipe->In, 0))
                        WaitForSingleObject(subsystem->thread, INFINITE);
+
                CloseHandle(subsystem->thread);
                subsystem->thread = NULL;
        }
@@ -1412,10 +1362,9 @@ int x11_shadow_subsystem_stop(x11ShadowSubsystem* subsystem)
        return 1;
 }
 
-x11ShadowSubsystem* x11_shadow_subsystem_new()
+static x11ShadowSubsystem* x11_shadow_subsystem_new(void)
 {
        x11ShadowSubsystem* subsystem;
-
        subsystem = (x11ShadowSubsystem*) calloc(1, sizeof(x11ShadowSubsystem));
 
        if (!subsystem)
@@ -1424,29 +1373,29 @@ x11ShadowSubsystem* x11_shadow_subsystem_new()
 #ifdef WITH_PAM
        subsystem->Authenticate = (pfnShadowAuthenticate) x11_shadow_pam_authenticate;
 #endif
-
-       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent) x11_shadow_input_synchronize_event;
-       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent) x11_shadow_input_keyboard_event;
-       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent) x11_shadow_input_unicode_keyboard_event;
+       subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent)
+       x11_shadow_input_synchronize_event;
+       subsystem->KeyboardEvent = (pfnShadowKeyboardEvent)
+       x11_shadow_input_keyboard_event;
+       subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent)
+       x11_shadow_input_unicode_keyboard_event;
        subsystem->MouseEvent = (pfnShadowMouseEvent) x11_shadow_input_mouse_event;
-       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent) x11_shadow_input_extended_mouse_event;
-
+       subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent)
+       x11_shadow_input_extended_mouse_event;
        subsystem->composite = FALSE;
        subsystem->use_xshm = FALSE; /* temporarily disabled */
        subsystem->use_xfixes = TRUE;
        subsystem->use_xdamage = FALSE;
        subsystem->use_xinerama = TRUE;
-
        return subsystem;
 }
 
-void x11_shadow_subsystem_free(x11ShadowSubsystem* subsystem)
+static void x11_shadow_subsystem_free(x11ShadowSubsystem* subsystem)
 {
        if (!subsystem)
                return;
 
        x11_shadow_subsystem_uninit(subsystem);
-
        free(subsystem);
 }
 
@@ -1454,14 +1403,10 @@ FREERDP_API int X11_ShadowSubsystemEntry(RDP_SHADOW_ENTRY_POINTS* pEntryPoints)
 {
        pEntryPoints->New = (pfnShadowSubsystemNew) x11_shadow_subsystem_new;
        pEntryPoints->Free = (pfnShadowSubsystemFree) x11_shadow_subsystem_free;
-
        pEntryPoints->Init = (pfnShadowSubsystemInit) x11_shadow_subsystem_init;
        pEntryPoints->Uninit = (pfnShadowSubsystemInit) x11_shadow_subsystem_uninit;
-
        pEntryPoints->Start = (pfnShadowSubsystemStart) x11_shadow_subsystem_start;
        pEntryPoints->Stop = (pfnShadowSubsystemStop) x11_shadow_subsystem_stop;
-
        pEntryPoints->EnumMonitors = (pfnShadowEnumMonitors) x11_shadow_enum_monitors;
-
        return 1;
 }
index 2a51e79..7de8e67 100644 (file)
@@ -41,25 +41,23 @@ struct _SHADOW_GFX_STATUS
 };
 typedef struct _SHADOW_GFX_STATUS SHADOW_GFX_STATUS;
 
-static INLINE BOOL shadow_client_rdpgfx_new_surface(rdpShadowClient *client)
+static INLINE BOOL shadow_client_rdpgfx_new_surface(rdpShadowClientclient)
 {
        UINT error = CHANNEL_RC_OK;
        RDPGFX_CREATE_SURFACE_PDU createSurface;
        RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU surfaceToOutput;
        RdpgfxServerContext* context = client->rdpgfx;
        rdpSettings* settings = ((rdpContext*) client)->settings;
-
        createSurface.width = settings->DesktopWidth;
        createSurface.height = settings->DesktopHeight;
        createSurface.pixelFormat = GFX_PIXEL_FORMAT_XRGB_8888;
        createSurface.surfaceId = 0;
-
        surfaceToOutput.outputOriginX = 0;
        surfaceToOutput.outputOriginY = 0;
        surfaceToOutput.surfaceId = 0;
        surfaceToOutput.reserved = 0;
-
        IFCALLRET(context->CreateSurface, error, context, &createSurface);
+
        if (error)
        {
                WLog_ERR(TAG, "CreateSurface failed with error %lu", error);
@@ -67,6 +65,7 @@ static INLINE BOOL shadow_client_rdpgfx_new_surface(rdpShadowClient *client)
        }
 
        IFCALLRET(context->MapSurfaceToOutput, error, context, &surfaceToOutput);
+
        if (error)
        {
                WLog_ERR(TAG, "MapSurfaceToOutput failed with error %lu", error);
@@ -76,14 +75,14 @@ static INLINE BOOL shadow_client_rdpgfx_new_surface(rdpShadowClient *client)
        return TRUE;
 }
 
-static INLINE BOOL shadow_client_rdpgfx_release_surface(rdpShadowClient *client)
+static INLINE BOOL shadow_client_rdpgfx_release_surface(rdpShadowClientclient)
 {
        UINT error = CHANNEL_RC_OK;
        RDPGFX_DELETE_SURFACE_PDU pdu;
        RdpgfxServerContext* context = client->rdpgfx;
-
        pdu.surfaceId = 0;
        IFCALLRET(context->DeleteSurface, error, context, &pdu);
+
        if (error)
        {
                WLog_ERR(TAG, "DeleteSurface failed with error %lu", error);
@@ -93,19 +92,18 @@ static INLINE BOOL shadow_client_rdpgfx_release_surface(rdpShadowClient *client)
        return TRUE;
 }
 
-static INLINE BOOL shadow_client_rdpgfx_reset_graphic(rdpShadowClient *client)
+static INLINE BOOL shadow_client_rdpgfx_reset_graphic(rdpShadowClientclient)
 {
        UINT error = CHANNEL_RC_OK;
        RDPGFX_RESET_GRAPHICS_PDU pdu;
        RdpgfxServerContext* context = client->rdpgfx;
        rdpSettings* settings = ((rdpContext*) client)->settings;
-
        pdu.width = settings->DesktopWidth;
        pdu.height = settings->DesktopHeight;
        pdu.monitorCount = client->subsystem->numMonitors;
        pdu.monitorDefArray = client->subsystem->monitors;
-
        IFCALLRET(context->ResetGraphics, error, context, &pdu);
+
        if (error)
        {
                WLog_ERR(TAG, "ResetGraphics failed with error %lu", error);
@@ -115,9 +113,10 @@ static INLINE BOOL shadow_client_rdpgfx_reset_graphic(rdpShadowClient *client)
        return TRUE;
 }
 
-static INLINE void shadow_client_free_queued_message(void *obj)
+static INLINE void shadow_client_free_queued_message(voidobj)
 {
-       wMessage *message = (wMessage*)obj;
+       wMessage* message = (wMessage*)obj;
+
        if (message->Free)
        {
                message->Free(message);
@@ -125,18 +124,16 @@ static INLINE void shadow_client_free_queued_message(void *obj)
        }
 }
 
-static BOOL shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* client)
+static BOOL shadow_client_context_new(freerdp_peer* peer,
+                                      rdpShadowClient* client)
 {
        rdpSettings* settings;
        rdpShadowServer* server;
        const wObject cb = { NULL, NULL, NULL, shadow_client_free_queued_message, NULL };
-
        server = (rdpShadowServer*) peer->ContextExtra;
        client->server = server;
        client->subsystem = server->subsystem;
-
        settings = peer->settings;
-
        settings->ColorDepth = 32;
        settings->NSCodec = TRUE;
        settings->RemoteFxCodec = TRUE;
@@ -145,21 +142,20 @@ static BOOL shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* clien
        settings->SurfaceFrameMarkerEnabled = TRUE;
        settings->SupportGraphicsPipeline = TRUE;
        settings->GfxH264 = FALSE;
-
        settings->DrawAllowSkipAlpha = TRUE;
        settings->DrawAllowColorSubsampling = TRUE;
        settings->DrawAllowDynamicColorFidelity = TRUE;
-
        settings->CompressionLevel = PACKET_COMPR_TYPE_RDP6;
 
        if (!(settings->CertificateFile = _strdup(server->CertificateFile)))
                goto fail_cert_file;
+
        if (!(settings->PrivateKeyFile = _strdup(server->PrivateKeyFile)))
                goto fail_privkey_file;
+
        if (!(settings->RdpKeyFile = _strdup(settings->PrivateKeyFile)))
                goto fail_rdpkey_file;
 
-
        if (server->ipcSocket)
        {
                settings->LyncRdpMode = TRUE;
@@ -174,8 +170,8 @@ static BOOL shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* clien
                goto fail_client_lock;
 
        region16_init(&(client->invalidRegion));
-
        client->vcm = WTSOpenServerA((LPSTR) peer->context);
+
        if (!client->vcm || client->vcm == INVALID_HANDLE_VALUE)
                goto fail_open_server;
 
@@ -208,14 +204,13 @@ fail_privkey_file:
        free(settings->CertificateFile);
        settings->CertificateFile = NULL;
 fail_cert_file:
-
        return FALSE;
 }
 
-static void shadow_client_context_free(freerdp_peer* peer, rdpShadowClient* client)
+static void shadow_client_context_free(freerdp_peer* peer,
+                                       rdpShadowClient* client)
 {
        rdpShadowServer* server = client->server;
-
        ArrayList_Remove(server->clients, (void*) client);
 
        if (client->encoder)
@@ -224,21 +219,18 @@ static void shadow_client_context_free(freerdp_peer* peer, rdpShadowClient* clie
                client->encoder = NULL;
        }
 
-    /* Clear queued messages and free resource */
+       /* Clear queued messages and free resource */
        MessageQueue_Clear(client->MsgQueue);
        MessageQueue_Free(client->MsgQueue);
-
        WTSCloseServer((HANDLE) client->vcm);
        client->vcm = NULL;
-
        region16_uninit(&(client->invalidRegion));
-
        DeleteCriticalSection(&(client->lock));
 }
 
-void shadow_client_message_free(wMessage* message)
+static void shadow_client_message_free(wMessage* message)
 {
-       switch(message->id)
+       switch (message->id)
        {
                case SHADOW_MSG_IN_REFRESH_REQUEST_ID:
                        /* Refresh request do not have message to free */
@@ -251,12 +243,12 @@ void shadow_client_message_free(wMessage* message)
        }
 }
 
-static INLINE void shadow_client_mark_invalid(rdpShadowClient* client, int numRects, const RECTANGLE_16* rects)
+static INLINE void shadow_client_mark_invalid(rdpShadowClient* client,
+        int numRects, const RECTANGLE_16* rects)
 {
        int index;
        RECTANGLE_16 screenRegion;
        rdpSettings* settings = ((rdpContext*) client)->settings;
-
        EnterCriticalSection(&(client->lock));
 
        /* Mark client invalid region. No rectangle means full screen */
@@ -264,7 +256,8 @@ static INLINE void shadow_client_mark_invalid(rdpShadowClient* client, int numRe
        {
                for (index = 0; index < numRects; index++)
                {
-                       region16_union_rect(&(client->invalidRegion), &(client->invalidRegion), &rects[index]);
+                       region16_union_rect(&(client->invalidRegion), &(client->invalidRegion),
+                                           &rects[index]);
                }
        }
        else
@@ -273,9 +266,8 @@ static INLINE void shadow_client_mark_invalid(rdpShadowClient* client, int numRe
                screenRegion.top = 0;
                screenRegion.right = settings->DesktopWidth;
                screenRegion.bottom = settings->DesktopHeight;
-
                region16_union_rect(&(client->invalidRegion),
-                                   &(client->invalidRegion), &screenRegion);
+                                   &(client->invalidRegion), &screenRegion);
        }
 
        LeaveCriticalSection(&(client->lock));
@@ -292,7 +284,6 @@ static INLINE BOOL shadow_client_recalc_desktop_size(rdpShadowClient* client)
        int width, height;
        rdpShadowServer* server = client->server;
        rdpSettings* settings = client->context.settings;
-
        RECTANGLE_16 viewport = {0, 0, server->surface->width, server->surface->height};
 
        if (server->shareSubRect)
@@ -303,7 +294,8 @@ static INLINE BOOL shadow_client_recalc_desktop_size(rdpShadowClient* client)
        width = viewport.right - viewport.left;
        height = viewport.bottom - viewport.top;
 
-       if (settings->DesktopWidth != (UINT32)width || settings->DesktopHeight != (UINT32)height)
+       if (settings->DesktopWidth != (UINT32)width
+           || settings->DesktopHeight != (UINT32)height)
        {
                settings->DesktopWidth = width;
                settings->DesktopHeight = height;
@@ -318,18 +310,16 @@ static BOOL shadow_client_capabilities(freerdp_peer* peer)
        rdpShadowSubsystem* subsystem;
        rdpShadowClient* client;
        BOOL ret = TRUE;
-
        client = (rdpShadowClient*) peer->context;
        subsystem = client->server->subsystem;
-
        IFCALLRET(subsystem->ClientCapabilities, ret, subsystem, client);
+
        if (!ret)
                WLog_WARN(TAG, "subsystem->ClientCapabilities failed");
 
        /* Recalculate desktop size regardless whether previous call fail
         * or not. Make sure we send correct width/height to client */
        (void)shadow_client_recalc_desktop_size(client);
-
        return ret;
 }
 
@@ -340,7 +330,6 @@ static BOOL shadow_client_post_connect(freerdp_peer* peer)
        rdpShadowClient* client;
        rdpShadowServer* server;
        rdpShadowSubsystem* subsystem;
-
        client = (rdpShadowClient*) peer->context;
        settings = peer->settings;
        server = client->server;
@@ -350,26 +339,26 @@ static BOOL shadow_client_post_connect(freerdp_peer* peer)
                settings->ColorDepth = 16; /* disable 24bpp */
 
        if (settings->MultifragMaxRequestSize < 0x3F0000)
-               settings->NSCodec = FALSE; /* NSCodec compressor does not support fragmentation yet */
+               settings->NSCodec =
+                   FALSE; /* NSCodec compressor does not support fragmentation yet */
 
        WLog_INFO(TAG, "Client from %s is activated (%dx%d@%d)",
-                 peer->hostname, settings->DesktopWidth,
-                 settings->DesktopHeight, settings->ColorDepth);
+                 peer->hostname, settings->DesktopWidth,
+                 settings->DesktopHeight, settings->ColorDepth);
 
        /* Resize client if necessary */
        if (shadow_client_recalc_desktop_size(client))
        {
                peer->update->DesktopResize(peer->update->context);
                WLog_INFO(TAG, "Client from %s is resized (%dx%d@%d)",
-                         peer->hostname, settings->DesktopWidth,
-                         settings->DesktopHeight, settings->ColorDepth);
+                         peer->hostname, settings->DesktopWidth,
+                         settings->DesktopHeight, settings->ColorDepth);
        }
 
        if (shadow_client_channels_post_connect(client) != CHANNEL_RC_OK)
                return FALSE;
 
        shadow_client_mark_invalid(client, 0, NULL);
-
        authStatus = -1;
 
        if (settings->Username && settings->Password)
@@ -380,7 +369,7 @@ static BOOL shadow_client_post_connect(freerdp_peer* peer)
                if (subsystem->Authenticate)
                {
                        authStatus = subsystem->Authenticate(subsystem, client,
-                                       settings->Username, settings->Domain, settings->Password);
+                                                            settings->Username, settings->Domain, settings->Password);
                }
 
                if (authStatus < 0)
@@ -400,7 +389,7 @@ static BOOL shadow_client_post_connect(freerdp_peer* peer)
 
 /* Convert rects in sub rect coordinate to client/surface coordinate */
 static INLINE void shadow_client_convert_rects(rdpShadowClient* client,
-               RECTANGLE_16* dst, const RECTANGLE_16* src, UINT32 numRects)
+        RECTANGLE_16* dst, const RECTANGLE_16* src, UINT32 numRects)
 {
        if (client->server->shareSubRect)
        {
@@ -429,17 +418,16 @@ static BOOL shadow_client_refresh_request(rdpShadowClient* client)
 {
        wMessage message = { 0 };
        wMessagePipe* MsgPipe = client->subsystem->MsgPipe;
-
        message.id = SHADOW_MSG_IN_REFRESH_REQUEST_ID;
        message.wParam = NULL;
        message.lParam = NULL;
        message.context = (void*) client;
        message.Free = NULL;
-
        return MessageQueue_Dispatch(MsgPipe->In, &message);
 }
 
-static BOOL shadow_client_refresh_rect(rdpShadowClient* client, BYTE count, RECTANGLE_16* areas)
+static BOOL shadow_client_refresh_rect(rdpShadowClient* client, BYTE count,
+                                       RECTANGLE_16* areas)
 {
        RECTANGLE_16* rects;
 
@@ -457,9 +445,7 @@ static BOOL shadow_client_refresh_rect(rdpShadowClient* client, BYTE count, RECT
                }
 
                shadow_client_convert_rects(client, rects, areas, count);
-
                shadow_client_mark_invalid(client, count, rects);
-
                free(rects);
        }
        else
@@ -470,11 +456,12 @@ static BOOL shadow_client_refresh_rect(rdpShadowClient* client, BYTE count, RECT
        return shadow_client_refresh_request(client);
 }
 
-static BOOL shadow_client_suppress_output(rdpShadowClient* client, BYTE allow, RECTANGLE_16* area)
+static BOOL shadow_client_suppress_output(rdpShadowClient* client, BYTE allow,
+        RECTANGLE_16* area)
 {
        RECTANGLE_16 region;
-
        client->suppressOutput = allow ? FALSE : TRUE;
+
        if (allow)
        {
                if (area)
@@ -487,6 +474,7 @@ static BOOL shadow_client_suppress_output(rdpShadowClient* client, BYTE allow, R
                        shadow_client_mark_invalid(client, 0, NULL);
                }
        }
+
        return shadow_client_refresh_request(client);
 }
 
@@ -498,12 +486,9 @@ static BOOL shadow_client_activate(freerdp_peer* peer)
        if (settings->ClientDir && (strcmp(settings->ClientDir, "librdp") == 0))
        {
                /* Hack for Mac/iOS/Android Microsoft RDP clients */
-
                settings->RemoteFxCodec = FALSE;
-
                settings->NSCodec = FALSE;
                settings->NSCodecAllowSubsampling = FALSE;
-
                settings->SurfaceFrameMarkerEnabled = FALSE;
        }
 
@@ -520,7 +505,9 @@ static BOOL shadow_client_activate(freerdp_peer* peer)
        return shadow_client_refresh_rect(client, 0, NULL);
 }
 
-BOOL shadow_client_logon(freerdp_peer* peer, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic)
+static BOOL shadow_client_logon(freerdp_peer* peer,
+                                SEC_WINNT_AUTH_IDENTITY* identity,
+                                BOOL automatic)
 {
        char* user = NULL;
        char* domain = NULL;
@@ -530,13 +517,16 @@ BOOL shadow_client_logon(freerdp_peer* peer, SEC_WINNT_AUTH_IDENTITY* identity,
        if (identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
        {
                if (identity->User)
-                       ConvertFromUnicode(CP_UTF8, 0, identity->User, identity->UserLength, &user, 0, NULL, NULL);
+                       ConvertFromUnicode(CP_UTF8, 0, identity->User, identity->UserLength, &user, 0,
+                                          NULL, NULL);
 
                if (identity->Domain)
-                       ConvertFromUnicode(CP_UTF8, 0, identity->Domain, identity->DomainLength, &domain, 0, NULL, NULL);
+                       ConvertFromUnicode(CP_UTF8, 0, identity->Domain, identity->DomainLength,
+                                          &domain, 0, NULL, NULL);
 
                if (identity->Password)
-                       ConvertFromUnicode(CP_UTF8, 0, identity->Password, identity->PasswordLength, &user, 0, NULL, NULL);
+                       ConvertFromUnicode(CP_UTF8, 0, identity->Password, identity->PasswordLength,
+                                          &user, 0, NULL, NULL);
        }
        else
        {
@@ -550,7 +540,8 @@ BOOL shadow_client_logon(freerdp_peer* peer, SEC_WINNT_AUTH_IDENTITY* identity,
                        password = _strdup((char*) identity->Password);
        }
 
-       if ((identity->User && !user) || (identity->Domain && !domain) || (identity->Password && !password))
+       if ((identity->User && !user) || (identity->Domain && !domain)
+           || (identity->Password && !password))
                return FALSE;
 
        if (user)
@@ -577,39 +568,42 @@ BOOL shadow_client_logon(freerdp_peer* peer, SEC_WINNT_AUTH_IDENTITY* identity,
        free(user);
        free(domain);
        free(password);
-
        return TRUE;
 }
 
-static INLINE void shadow_client_common_frame_acknowledge(rdpShadowClient* client, UINT32 frameId)
+static INLINE void shadow_client_common_frame_acknowledge(
+    rdpShadowClient* client, UINT32 frameId)
 {
        /*
-     * Record the last client acknowledged frame id to
+        * Record the last client acknowledged frame id to
         * calculate how much frames are in progress.
         * Some rdp clients (win7 mstsc) skips frame ACK if it is
         * inactive, we should not expect ACK for each frame.
         * So it is OK to calculate inflight frame count according to
         * a latest acknowledged frame id.
-     */
+        */
        client->encoder->lastAckframeId = frameId;
 }
 
-static BOOL shadow_client_surface_frame_acknowledge(rdpShadowClient* client, UINT32 frameId)
+static BOOL shadow_client_surface_frame_acknowledge(rdpShadowClient* client,
+        UINT32 frameId)
 {
        shadow_client_common_frame_acknowledge(client, frameId);
        return TRUE;
 }
 
-static UINT shadow_client_rdpgfx_frame_acknowledge(RdpgfxServerContext* context, RDPGFX_FRAME_ACKNOWLEDGE_PDU* frameAcknowledge)
+static UINT shadow_client_rdpgfx_frame_acknowledge(RdpgfxServerContext* context,
+        RDPGFX_FRAME_ACKNOWLEDGE_PDU* frameAcknowledge)
 {
-       shadow_client_common_frame_acknowledge((rdpShadowClient *)context->custom,
-                                              frameAcknowledge->frameId);
+       shadow_client_common_frame_acknowledge((rdpShadowClient*)context->custom,
+                                              frameAcknowledge->frameId);
        return CHANNEL_RC_OK;
 }
-static UINT shadow_client_rdpgfx_qoe_frame_acknowledge(RdpgfxServerContext* context, RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU* qoeFrameAcknowledge)
+static UINT shadow_client_rdpgfx_qoe_frame_acknowledge(RdpgfxServerContext*
+        context, RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU* qoeFrameAcknowledge)
 {
-       shadow_client_common_frame_acknowledge((rdpShadowClient *)context->custom,
-                                              qoeFrameAcknowledge->frameId);
+       shadow_client_common_frame_acknowledge((rdpShadowClient*)context->custom,
+                                              qoeFrameAcknowledge->frameId);
        return CHANNEL_RC_OK;
 }
 
@@ -619,7 +613,7 @@ static UINT shadow_client_rdpgfx_qoe_frame_acknowledge(RdpgfxServerContext* cont
  * @return TRUE on success
  */
 static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client,
-               BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
+        BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
 {
        UINT error = CHANNEL_RC_OK;
        rdpUpdate* update;
@@ -631,25 +625,19 @@ static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client,
        RDPGFX_START_FRAME_PDU cmdstart;
        RDPGFX_END_FRAME_PDU cmdend;
        SYSTEMTIME sTime;
-
        context = (rdpContext*) client;
        update = context->update;
        settings = context->settings;
-
        server = client->server;
        encoder = client->encoder;
-
        cmdstart.frameId = shadow_encoder_create_frame_id(encoder);
-
        GetSystemTime(&sTime);
        cmdstart.timestamp = sTime.wHour << 22 | sTime.wMinute << 16 |
-                            sTime.wSecond << 10 | sTime.wMilliseconds;
-
+                            sTime.wSecond << 10 | sTime.wMilliseconds;
        cmdend.frameId = cmdstart.frameId;
-
        cmd.surfaceId = 0;
        cmd.contextId = 0;
-       cmd.format = PIXEL_FORMAT_XRGB32;
+       cmd.format = PIXEL_FORMAT_BGRX32;
        cmd.left = nXSrc;
        cmd.top = nYSrc;
        cmd.right = cmd.left + nWidth;
@@ -669,11 +657,10 @@ static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client,
                        return FALSE;
                }
 
-               avc420_compress(encoder->h264, pSrcData, PIXEL_FORMAT_XRGB32, nSrcStep,
-                               nWidth, nHeight, &avc420.data, &avc420.length);
-
+               avc420_compress(encoder->h264, pSrcData, cmd.format, nSrcStep,
+                               nWidth, nHeight, &avc420.data, &avc420.length);
                cmd.codecId = RDPGFX_CODECID_AVC420;
-               cmd.extra = (void *)&avc420;
+               cmd.extra = (void*)&avc420;
                regionRect.left = cmd.left;
                regionRect.top = cmd.top;
                regionRect.right = cmd.right;
@@ -685,8 +672,9 @@ static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client,
                avc420.meta.numRegionRects = 1;
                avc420.meta.regionRects = &regionRect;
                avc420.meta.quantQualityVals = &quantQualityVal;
+               IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd,
+                         &cmdstart, &cmdend);
 
-               IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart, &cmdend);
                if (error)
                {
                        WLog_ERR(TAG, "SurfaceFrameCommand failed with error %lu", error);
@@ -703,7 +691,7 @@ static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client,
  * @return TRUE on success
  */
 static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
-               BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
+        BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
 {
        BOOL ret = TRUE;
        int i;
@@ -718,11 +706,9 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
        rdpShadowServer* server;
        rdpShadowEncoder* encoder;
        SURFACE_BITS_COMMAND cmd;
-
        context = (rdpContext*) client;
        update = context->update;
        settings = context->settings;
-
        server = client->server;
        encoder = client->encoder;
 
@@ -733,7 +719,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
        {
                RFX_RECT rect;
                RFX_MESSAGE* messages;
-               RFX_RECT *messageRects = NULL;
+               RFX_RECTmessageRects = NULL;
 
                if (shadow_encoder_prepare(encoder, FREERDP_CODEC_REMOTEFX) < 0)
                {
@@ -742,27 +728,24 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
                }
 
                s = encoder->bs;
-
                rect.x = nXSrc;
                rect.y = nYSrc;
                rect.width = nWidth;
                rect.height = nHeight;
 
                if (!(messages = rfx_encode_messages(encoder->rfx, &rect, 1, pSrcData,
-                               settings->DesktopWidth, settings->DesktopHeight, nSrcStep, &numMessages,
-                               settings->MultifragMaxRequestSize)))
+                                                    settings->DesktopWidth, settings->DesktopHeight, nSrcStep, &numMessages,
+                                                    settings->MultifragMaxRequestSize)))
                {
                        WLog_ERR(TAG, "rfx_encode_messages failed");
                        return FALSE;
                }
 
                cmd.codecID = settings->RemoteFxCodecId;
-
                cmd.destLeft = 0;
                cmd.destTop = 0;
                cmd.destRight = settings->DesktopWidth;
                cmd.destBottom = settings->DesktopHeight;
-
                cmd.bpp = 32;
                cmd.width = settings->DesktopWidth;
                cmd.height = settings->DesktopHeight;
@@ -774,28 +757,30 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
                for (i = 0; i < numMessages; i++)
                {
                        Stream_SetPosition(s, 0);
+
                        if (!rfx_write_message(encoder->rfx, s, &messages[i]))
                        {
                                while (i < numMessages)
                                {
                                        rfx_message_free(encoder->rfx, &messages[i++]);
                                }
+
                                WLog_ERR(TAG, "rfx_write_message failed");
                                ret = FALSE;
                                break;
                        }
-                       rfx_message_free(encoder->rfx, &messages[i]);
 
+                       rfx_message_free(encoder->rfx, &messages[i]);
                        cmd.bitmapDataLength = Stream_GetPosition(s);
                        cmd.bitmapData = Stream_Buffer(s);
-
                        first = (i == 0) ? TRUE : FALSE;
                        last = ((i + 1) == numMessages) ? TRUE : FALSE;
 
                        if (!encoder->frameAck)
                                IFCALLRET(update->SurfaceBits, ret, update->context, &cmd);
                        else
-                               IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last, frameId);
+                               IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last,
+                                         frameId);
 
                        if (!ret)
                        {
@@ -817,11 +802,8 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
 
                s = encoder->bs;
                Stream_SetPosition(s, 0);
-
                pSrcData = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)];
-
                nsc_compose_message(encoder->nsc, s, pSrcData, nWidth, nHeight, nSrcStep);
-
                cmd.bpp = 32;
                cmd.codecID = settings->NSCodecId;
                cmd.destLeft = nXSrc;
@@ -830,17 +812,16 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
                cmd.destBottom = cmd.destTop + nHeight;
                cmd.width = nWidth;
                cmd.height = nHeight;
-
                cmd.bitmapDataLength = Stream_GetPosition(s);
                cmd.bitmapData = Stream_Buffer(s);
-
                first = TRUE;
                last = TRUE;
 
                if (!encoder->frameAck)
                        IFCALLRET(update->SurfaceBits, ret, update->context, &cmd);
                else
-                       IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last, frameId);
+                       IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last,
+                                 frameId);
 
                if (!ret)
                {
@@ -857,7 +838,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client,
  * @return TRUE on success
  */
 static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
-               BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
+        BYTE* pSrcData, int nSrcStep, int nXSrc, int nYSrc, int nWidth, int nHeight)
 {
        BOOL ret = TRUE;
        BYTE* data;
@@ -877,14 +858,11 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
        BITMAP_UPDATE bitmapUpdate;
        rdpShadowServer* server;
        rdpShadowEncoder* encoder;
-
        context = (rdpContext*) client;
        update = context->update;
        settings = context->settings;
-
        server = client->server;
        encoder = client->encoder;
-
        maxUpdateSize = settings->MultifragMaxRequestSize;
 
        if (settings->ColorDepth < 32)
@@ -904,7 +882,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
                }
        }
 
-       SrcFormat = PIXEL_FORMAT_XRGB32;
+       SrcFormat = PIXEL_FORMAT_BGRX32;
 
        if ((nXSrc % 4) != 0)
        {
@@ -920,13 +898,14 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
 
        rows = (nHeight / 64) + ((nHeight % 64) ? 1 : 0);
        cols = (nWidth / 64) + ((nWidth % 64) ? 1 : 0);
-
        k = 0;
        totalBitmapSize = 0;
-
        bitmapUpdate.count = bitmapUpdate.number = rows * cols;
-       if (!(bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * bitmapUpdate.number)))
+
+       if (!(bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) *
+                          bitmapUpdate.number)))
                return FALSE;
+
        bitmapUpdate.rectangles = bitmapData;
 
        if ((nWidth % 4) != 0)
@@ -944,7 +923,6 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
                for (xIdx = 0; xIdx < cols; xIdx++)
                {
                        bitmap = &bitmapData[k];
-
                        bitmap->width = 64;
                        bitmap->height = 64;
                        bitmap->destLeft = nXSrc + (xIdx * 64);
@@ -967,13 +945,12 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
                        {
                                int bitsPerPixel = settings->ColorDepth;
                                int bytesPerPixel = (bitsPerPixel + 7) / 8;
-
                                DstSize = 64 * 64 * 4;
                                buffer = encoder->grid[k];
-
-                               interleaved_compress(encoder->interleaved, buffer, &DstSize, bitmap->width, bitmap->height,
-                                               pSrcData, SrcFormat, nSrcStep, bitmap->destLeft, bitmap->destTop, NULL, bitsPerPixel);
-
+                               interleaved_compress(encoder->interleaved, buffer, &DstSize, bitmap->width,
+                                                    bitmap->height,
+                                                    pSrcData, SrcFormat, nSrcStep, bitmap->destLeft, bitmap->destTop, NULL,
+                                                    bitsPerPixel);
                                bitmap->bitmapDataStream = buffer;
                                bitmap->bitmapLength = DstSize;
                                bitmap->bitsPerPixel = bitsPerPixel;
@@ -983,13 +960,10 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
                        else
                        {
                                UINT32 dstSize;
-
                                buffer = encoder->grid[k];
                                data = &pSrcData[(bitmap->destTop * nSrcStep) + (bitmap->destLeft * 4)];
-
                                buffer = freerdp_bitmap_compress_planar(encoder->planar, data, SrcFormat,
-                                               bitmap->width, bitmap->height, nSrcStep, buffer, &dstSize);
-
+                                                                       bitmap->width, bitmap->height, nSrcStep, buffer, &dstSize);
                                bitmap->bitmapDataStream = buffer;
                                bitmap->bitmapLength = dstSize;
                                bitmap->bitsPerPixel = 32;
@@ -999,14 +973,12 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
 
                        bitmap->cbCompFirstRowSize = 0;
                        bitmap->cbCompMainBodySize = bitmap->bitmapLength;
-
                        totalBitmapSize += bitmap->bitmapLength;
                        k++;
                }
        }
 
        bitmapUpdate.count = bitmapUpdate.number = k;
-
        updateSizeEstimate = totalBitmapSize + (k * bitmapUpdate.count) + 16;
 
        if (updateSizeEstimate > maxUpdateSize)
@@ -1025,8 +997,8 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
                        ret = FALSE;
                        goto out;
                }
-               bitmapUpdate.rectangles = fragBitmapData;
 
+               bitmapUpdate.rectangles = fragBitmapData;
                i = j = 0;
                updateSize = 1024;
 
@@ -1049,6 +1021,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
 
                                bitmapUpdate.count = bitmapUpdate.number = j;
                                IFCALLRET(update->BitmapUpdate, ret, context, &bitmapUpdate);
+
                                if (!ret)
                                {
                                        WLog_ERR(TAG, "BitmapUpdate failed");
@@ -1065,6 +1038,7 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
        else
        {
                IFCALLRET(update->BitmapUpdate, ret, context, &bitmapUpdate);
+
                if (!ret)
                {
                        WLog_ERR(TAG, "BitmapUpdate failed");
@@ -1073,7 +1047,6 @@ static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client,
 
 out:
        free(bitmapData);
-
        return ret;
 }
 
@@ -1082,7 +1055,8 @@ out:
  *
  * @return TRUE on success (or nothing need to be updated)
  */
-static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GFX_STATUS* pStatus)
+static BOOL shadow_client_send_surface_update(rdpShadowClient* client,
+        SHADOW_GFX_STATUS* pStatus)
 {
        BOOL ret = TRUE;
        int nXSrc, nYSrc;
@@ -1100,23 +1074,18 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GF
        int index;
        UINT32 numRects = 0;
        const RECTANGLE_16* rects;
-
        context = (rdpContext*) client;
        settings = context->settings;
        server = client->server;
        encoder = client->encoder;
-
        surface = client->inLobby ? server->lobby : server->surface;
-
        EnterCriticalSection(&(client->lock));
-
        region16_init(&invalidRegion);
        region16_copy(&invalidRegion, &(client->invalidRegion));
        region16_clear(&(client->invalidRegion));
-
        LeaveCriticalSection(&(client->lock));
-
        rects = region16_rects(&(surface->invalidRegion), &numRects);
+
        for (index = 0; index < numRects; index++)
        {
                region16_union_rect(&invalidRegion, &invalidRegion, &rects[index]);
@@ -1126,7 +1095,6 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GF
        surfaceRect.top = 0;
        surfaceRect.right = surface->width;
        surfaceRect.bottom = surface->height;
-
        region16_intersect_rect(&invalidRegion, &invalidRegion, &surfaceRect);
 
        if (server->shareSubRect)
@@ -1141,12 +1109,10 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GF
        }
 
        extents = region16_extents(&invalidRegion);
-
        nXSrc = extents->left;
        nYSrc = extents->top;
        nWidth = extents->right - extents->left;
        nHeight = extents->bottom - extents->top;
-
        pSrcData = surface->data;
        nSrcStep = surface->scanline;
 
@@ -1154,10 +1120,8 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GF
        if (server->shareSubRect)
        {
                int subX, subY;
-
                subX = server->subRect.left;
                subY = server->subRect.top;
-
                nXSrc -= subX;
                nYSrc -= subY;
                pSrcData = &pSrcData[(subY * nSrcStep) + (subX * 4)];
@@ -1187,20 +1151,22 @@ static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GF
                        pStatus->gfxSurfaceCreated = TRUE;
                }
 
-               ret = shadow_client_send_surface_gfx(client, pSrcData, nSrcStep, 0, 0, nWidth, nHeight);
+               ret = shadow_client_send_surface_gfx(client, pSrcData, nSrcStep, 0, 0, nWidth,
+                                                    nHeight);
        }
        else if (settings->RemoteFxCodec || settings->NSCodec)
        {
-               ret = shadow_client_send_surface_bits(client, pSrcData, nSrcStep, nXSrc, nYSrc, nWidth, nHeight);
+               ret = shadow_client_send_surface_bits(client, pSrcData, nSrcStep, nXSrc, nYSrc,
+                                                     nWidth, nHeight);
        }
        else
        {
-               ret = shadow_client_send_bitmap_update(client, pSrcData, nSrcStep, nXSrc, nYSrc, nWidth, nHeight);
+               ret = shadow_client_send_bitmap_update(client, pSrcData, nSrcStep, nXSrc, nYSrc,
+                                                      nWidth, nHeight);
        }
 
 out:
        region16_uninit(&invalidRegion);
-
        return ret;
 }
 
@@ -1211,18 +1177,17 @@ out:
  *
  * @return TRUE on success
  */
-static BOOL shadow_client_send_resize(rdpShadowClient* client, SHADOW_GFX_STATUS* pStatus)
+static BOOL shadow_client_send_resize(rdpShadowClient* client,
+                                      SHADOW_GFX_STATUS* pStatus)
 {
        rdpContext* context;
        rdpSettings* settings;
        rdpShadowServer* server;
        freerdp_peer* peer;
-
        server = client->server;
        context = (rdpContext*) client;
        peer = context->peer;
        settings = context->settings;
-
        /**
         * Unset client activated flag to avoid sending update message during
         * resize. DesktopResize will reactive the client and
@@ -1250,10 +1215,9 @@ static BOOL shadow_client_send_resize(rdpShadowClient* client, SHADOW_GFX_STATUS
        EnterCriticalSection(&(client->lock));
        region16_clear(&(client->invalidRegion));
        LeaveCriticalSection(&(client->lock));
-
        WLog_INFO(TAG, "Client from %s is resized (%dx%d@%d)",
-                       peer->hostname, settings->DesktopWidth, settings->DesktopHeight, settings->ColorDepth);
-
+                 peer->hostname, settings->DesktopWidth, settings->DesktopHeight,
+                 settings->ColorDepth);
        return TRUE;
 }
 
@@ -1267,10 +1231,8 @@ BOOL shadow_client_surface_update(rdpShadowClient* client, REGION16* region)
 {
        UINT32 numRects = 0;
        const RECTANGLE_16* rects;
-
        rects = region16_rects(region, &numRects);
        shadow_client_mark_invalid(client, numRects, rects);
-
        return TRUE;
 }
 
@@ -1280,109 +1242,117 @@ BOOL shadow_client_surface_update(rdpShadowClient* client, REGION16* region)
  *
  * @return TRUE on success
  */
-static INLINE BOOL shadow_client_no_surface_update(rdpShadowClient* client, SHADOW_GFX_STATUS* pStatus)
+static INLINE BOOL shadow_client_no_surface_update(rdpShadowClient* client,
+        SHADOW_GFX_STATUS* pStatus)
 {
        rdpShadowServer* server;
        rdpShadowSurface* surface;
-
        server = client->server;
        surface = client->inLobby ? server->lobby : server->surface;
-
        return shadow_client_surface_update(client, &(surface->invalidRegion));
 }
 
-static int shadow_client_subsystem_process_message(rdpShadowClient* client, wMessage* message)
+static int shadow_client_subsystem_process_message(rdpShadowClient* client,
+        wMessage* message)
 {
        rdpContext* context = (rdpContext*) client;
        rdpUpdate* update = context->update;
 
        /* FIXME: the pointer updates appear to be broken when used with bulk compression and mstsc */
 
-       switch(message->id)
+       switch (message->id)
        {
                case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
-               {
-                       POINTER_POSITION_UPDATE pointerPosition;
-                       SHADOW_MSG_OUT_POINTER_POSITION_UPDATE* msg = (SHADOW_MSG_OUT_POINTER_POSITION_UPDATE*) message->wParam;
-
-                       pointerPosition.xPos = msg->xPos;
-                       pointerPosition.yPos = msg->yPos;
-
-                       if (client->server->shareSubRect)
                        {
-                               pointerPosition.xPos -= client->server->subRect.left;
-                               pointerPosition.yPos -= client->server->subRect.top;
-                       }
+                               POINTER_POSITION_UPDATE pointerPosition;
+                               SHADOW_MSG_OUT_POINTER_POSITION_UPDATE* msg =
+                                   (SHADOW_MSG_OUT_POINTER_POSITION_UPDATE*) message->wParam;
+                               pointerPosition.xPos = msg->xPos;
+                               pointerPosition.yPos = msg->yPos;
 
-                       if (client->activated)
-                       {
-                               if ((msg->xPos != client->pointerX) || (msg->yPos != client->pointerY))
+                               if (client->server->shareSubRect)
                                {
-                                       IFCALL(update->pointer->PointerPosition, context, &pointerPosition);
-
-                                       client->pointerX = msg->xPos;
-                                       client->pointerY = msg->yPos;
+                                       pointerPosition.xPos -= client->server->subRect.left;
+                                       pointerPosition.yPos -= client->server->subRect.top;
                                }
-                       }
-                       break;
-               }
-               case SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID:
-               {
-                       POINTER_NEW_UPDATE pointerNew;
-                       POINTER_COLOR_UPDATE* pointerColor;
-                       POINTER_CACHED_UPDATE pointerCached;
-                       SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* msg = (SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE*) message->wParam;
 
-                       ZeroMemory(&pointerNew, sizeof(POINTER_NEW_UPDATE));
-
-                       pointerNew.xorBpp = 24;
-                       pointerColor = &(pointerNew.colorPtrAttr);
-
-                       pointerColor->cacheIndex = 0;
-                       pointerColor->xPos = msg->xHot;
-                       pointerColor->yPos = msg->yHot;
-                       pointerColor->width = msg->width;
-                       pointerColor->height = msg->height;
-                       pointerColor->lengthAndMask = msg->lengthAndMask;
-                       pointerColor->lengthXorMask = msg->lengthXorMask;
-                       pointerColor->xorMaskData = msg->xorMaskData;
-                       pointerColor->andMaskData = msg->andMaskData;
+                               if (client->activated)
+                               {
+                                       if ((msg->xPos != client->pointerX) || (msg->yPos != client->pointerY))
+                                       {
+                                               IFCALL(update->pointer->PointerPosition, context, &pointerPosition);
+                                               client->pointerX = msg->xPos;
+                                               client->pointerY = msg->yPos;
+                                       }
+                               }
 
-                       pointerCached.cacheIndex = pointerColor->cacheIndex;
+                               break;
+                       }
 
-                       if (client->activated)
+               case SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID:
                        {
-                               IFCALL(update->pointer->PointerNew, context, &pointerNew);
-                               IFCALL(update->pointer->PointerCached, context, &pointerCached);
+                               POINTER_NEW_UPDATE pointerNew;
+                               POINTER_COLOR_UPDATE* pointerColor;
+                               POINTER_CACHED_UPDATE pointerCached;
+                               SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* msg =
+                                   (SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE*) message->wParam;
+                               ZeroMemory(&pointerNew, sizeof(POINTER_NEW_UPDATE));
+                               pointerNew.xorBpp = 24;
+                               pointerColor = &(pointerNew.colorPtrAttr);
+                               pointerColor->cacheIndex = 0;
+                               pointerColor->xPos = msg->xHot;
+                               pointerColor->yPos = msg->yHot;
+                               pointerColor->width = msg->width;
+                               pointerColor->height = msg->height;
+                               pointerColor->lengthAndMask = msg->lengthAndMask;
+                               pointerColor->lengthXorMask = msg->lengthXorMask;
+                               pointerColor->xorMaskData = msg->xorMaskData;
+                               pointerColor->andMaskData = msg->andMaskData;
+                               pointerCached.cacheIndex = pointerColor->cacheIndex;
+
+                               if (client->activated)
+                               {
+                                       IFCALL(update->pointer->PointerNew, context, &pointerNew);
+                                       IFCALL(update->pointer->PointerCached, context, &pointerCached);
+                               }
+
+                               break;
                        }
-                       break;
-               }
+
                case SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES_ID:
-               {
-                       SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES* msg = (SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES*) message->wParam;
-                       if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
                        {
-                               client->rdpsnd->src_format = msg->audio_format;
-                               IFCALL(client->rdpsnd->SendSamples, client->rdpsnd, msg->buf, msg->nFrames, msg->wTimestamp);
+                               SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES* msg = (SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES*)
+                                                                       message->wParam;
+
+                               if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
+                               {
+                                       client->rdpsnd->src_format = msg->audio_format;
+                                       IFCALL(client->rdpsnd->SendSamples, client->rdpsnd, msg->buf, msg->nFrames,
+                                              msg->wTimestamp);
+                               }
+
+                               break;
                        }
-                       break;
-               }
+
                case SHADOW_MSG_OUT_AUDIO_OUT_VOLUME_ID:
-               {
-                       SHADOW_MSG_OUT_AUDIO_OUT_VOLUME* msg = (SHADOW_MSG_OUT_AUDIO_OUT_VOLUME*) message->wParam;
-                       if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
                        {
-                               IFCALL(client->rdpsnd->SetVolume, client->rdpsnd, msg->left, msg->right);
+                               SHADOW_MSG_OUT_AUDIO_OUT_VOLUME* msg = (SHADOW_MSG_OUT_AUDIO_OUT_VOLUME*)
+                                                                      message->wParam;
+
+                               if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
+                               {
+                                       IFCALL(client->rdpsnd->SetVolume, client->rdpsnd, msg->left, msg->right);
+                               }
+
+                               break;
                        }
-                       break;
-               }
+
                default:
                        WLog_ERR(TAG, "Unknown message id: %u", message->id);
                        break;
        }
 
        shadow_client_free_queued_message(message);
-
        return 1;
 }
 
@@ -1409,36 +1379,31 @@ static void* shadow_client_thread(rdpShadowClient* client)
        wMessageQueue* MsgQueue = client->MsgQueue;
        /* This should only be visited in client thread */
        SHADOW_GFX_STATUS gfxstatus;
-
        gfxstatus.gfxOpened = FALSE;
        gfxstatus.gfxSurfaceCreated = FALSE;
-
        server = client->server;
        screen = server->screen;
        encoder = client->encoder;
        subsystem = server->subsystem;
-
        context = (rdpContext*) client;
        peer = context->peer;
        settings = peer->settings;
-
        peer->Capabilities = shadow_client_capabilities;
        peer->PostConnect = shadow_client_post_connect;
        peer->Activate = shadow_client_activate;
        peer->Logon = shadow_client_logon;
-
        shadow_input_register_callbacks(peer->input);
-
        peer->Initialize(peer);
-
        peer->update->RefreshRect = (pRefreshRect)shadow_client_refresh_rect;
        peer->update->SuppressOutput = (pSuppressOutput)shadow_client_suppress_output;
-       peer->update->SurfaceFrameAcknowledge = (pSurfaceFrameAcknowledge)shadow_client_surface_frame_acknowledge;
+       peer->update->SurfaceFrameAcknowledge = (pSurfaceFrameAcknowledge)
+                                               shadow_client_surface_frame_acknowledge;
 
        if ((!client->vcm) || (!subsystem->updateEvent))
                goto out;
 
        UpdateSubscriber = shadow_multiclient_get_subscriber(subsystem->updateEvent);
+
        if (!UpdateSubscriber)
                goto out;
 
@@ -1453,7 +1418,6 @@ static void* shadow_client_thread(rdpShadowClient* client)
                events[nCount++] = ClientEvent;
                events[nCount++] = ChannelEvent;
                events[nCount++] = MessageQueue_Event(MsgQueue);
-
                status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
 
                if (WaitForSingleObject(UpdateEvent, 0) == WAIT_OBJECT_0)
@@ -1465,7 +1429,6 @@ static void* shadow_client_thread(rdpShadowClient* client)
                         * (at shadow_multiclient_consume). As best practice, subsystem
                         * implementation should invoke shadow_subsystem_frame_update which
                         * triggers the event and then wait for completion */
-
                        if (client->activated && !client->suppressOutput)
                        {
                                /* Send screen update or resize to this client */
@@ -1527,7 +1490,8 @@ static void* shadow_client_thread(rdpShadowClient* client)
                                                break;
                                        }
                                }
-                               else if (WTSVirtualChannelManagerGetDrdynvcState(client->vcm) == DRDYNVC_STATE_READY)
+                               else if (WTSVirtualChannelManagerGetDrdynvcState(client->vcm) ==
+                                        DRDYNVC_STATE_READY)
                                {
                                        /* Init RDPGFX dynamic channel */
                                        if (settings->SupportGraphicsPipeline && client->rdpgfx &&
@@ -1540,8 +1504,8 @@ static void* shadow_client_thread(rdpShadowClient* client)
                                                }
 
                                                client->rdpgfx->FrameAcknowledge = shadow_client_rdpgfx_frame_acknowledge;
-                                               client->rdpgfx->QoeFrameAcknowledge = shadow_client_rdpgfx_qoe_frame_acknowledge;
-
+                                               client->rdpgfx->QoeFrameAcknowledge =
+                                                   shadow_client_rdpgfx_qoe_frame_acknowledge;
                                                gfxstatus.gfxOpened = TRUE;
                                                WLog_INFO(TAG, "Gfx Pipeline Opened");
                                        }
@@ -1562,11 +1526,12 @@ static void* shadow_client_thread(rdpShadowClient* client)
                {
                        /* Drain messages. Pointer update could be accumulated. */
                        pointerPositionMsg.id = 0;
-                       pointerPositionMsg.Free= NULL;
+                       pointerPositionMsg.Free = NULL;
                        pointerAlphaMsg.id = 0;
                        pointerAlphaMsg.Free = NULL;
                        audioVolumeMsg.id = 0;
                        audioVolumeMsg.Free = NULL;
+
                        while (MessageQueue_Peek(MsgQueue, &message, TRUE))
                        {
                                if (message.id == WMQ_QUIT)
@@ -1574,7 +1539,7 @@ static void* shadow_client_thread(rdpShadowClient* client)
                                        break;
                                }
 
-                               switch(message.id)
+                               switch (message.id)
                                {
                                        case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
                                                /* Abandon previous message */
@@ -1615,10 +1580,12 @@ static void* shadow_client_thread(rdpShadowClient* client)
                                {
                                        shadow_client_subsystem_process_message(client, &pointerPositionMsg);
                                }
+
                                if (pointerAlphaMsg.id)
                                {
                                        shadow_client_subsystem_process_message(client, &pointerAlphaMsg);
                                }
+
                                if (audioVolumeMsg.id)
                                {
                                        shadow_client_subsystem_process_message(client, &audioVolumeMsg);
@@ -1635,8 +1602,10 @@ static void* shadow_client_thread(rdpShadowClient* client)
                        if (!shadow_client_rdpgfx_release_surface(client))
                                WLog_WARN(TAG, "GFX release surface failure!");
                }
+
                (void)client->rdpgfx->Close(client->rdpgfx);
        }
+
        shadow_client_channels_free(client);
 
        if (UpdateSubscriber)
@@ -1652,7 +1621,6 @@ static void* shadow_client_thread(rdpShadowClient* client)
 
 out:
        peer->Disconnect(peer);
-
        freerdp_peer_context_free(peer);
        freerdp_peer_free(peer);
        ExitThread(0);
@@ -1663,14 +1631,11 @@ BOOL shadow_client_accepted(freerdp_listener* listener, freerdp_peer* peer)
 {
        rdpShadowClient* client;
        rdpShadowServer* server;
-
        server = (rdpShadowServer*) listener->info;
-
        peer->ContextExtra = (void*) server;
        peer->ContextSize = sizeof(rdpShadowClient);
        peer->ContextNew = (psPeerContextNew) shadow_client_context_new;
        peer->ContextFree = (psPeerContextFree) shadow_client_context_free;
-
        peer->settings = freerdp_settings_clone(server->settings);
 
        if (!freerdp_peer_context_new(peer))
@@ -1679,7 +1644,7 @@ BOOL shadow_client_accepted(freerdp_listener* listener, freerdp_peer* peer)
        client = (rdpShadowClient*) peer->context;
 
        if (!(client->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
-                       shadow_client_thread, client, 0, NULL)))
+                                           shadow_client_thread, client, 0, NULL)))
        {
                freerdp_peer_context_free(peer);
                return FALSE;
@@ -1690,13 +1655,14 @@ BOOL shadow_client_accepted(freerdp_listener* listener, freerdp_peer* peer)
 
 static void shadow_msg_out_addref(wMessage* message)
 {
-       SHADOW_MSG_OUT* msg = (SHADOW_MSG_OUT *)message->wParam;
+       SHADOW_MSG_OUT* msg = (SHADOW_MSG_OUT*)message->wParam;
        InterlockedIncrement(&(msg->refCount));
 }
 
 static void shadow_msg_out_release(wMessage* message)
 {
-       SHADOW_MSG_OUT* msg = (SHADOW_MSG_OUT *)message->wParam;
+       SHADOW_MSG_OUT* msg = (SHADOW_MSG_OUT*)message->wParam;
+
        if (InterlockedDecrement(&(msg->refCount)) <= 0)
        {
                if (msg->Free)
@@ -1704,10 +1670,12 @@ static void shadow_msg_out_release(wMessage* message)
        }
 }
 
-static BOOL shadow_client_dispatch_msg(rdpShadowClient* client, wMessage* message)
+static BOOL shadow_client_dispatch_msg(rdpShadowClient* client,
+                                       wMessage* message)
 {
        /* Add reference when it is posted */
        shadow_msg_out_addref(message);
+
        if (MessageQueue_Dispatch(client->MsgQueue, message))
        {
                return TRUE;
@@ -1720,50 +1688,48 @@ static BOOL shadow_client_dispatch_msg(rdpShadowClient* client, wMessage* messag
        }
 }
 
-BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam)
+BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type,
+                            SHADOW_MSG_OUT* msg, void* lParam)
 {
        wMessage message = {0};
-
        message.context = context;
        message.id = type;
-       message.wParam = (void *)msg;
+       message.wParam = (void*)msg;
        message.lParam = lParam;
        message.Free = shadow_msg_out_release;
-
        return shadow_client_dispatch_msg(client, &message);
 }
 
-int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type, SHADOW_MSG_OUT* msg, void* lParam)
+int shadow_client_boardcast_msg(rdpShadowServer* server, void* context,
+                                UINT32 type, SHADOW_MSG_OUT* msg, void* lParam)
 {
        wMessage message = {0};
        rdpShadowClient* client = NULL;
        int count = 0;
        int index = 0;
-
        message.context = context;
        message.id = type;
-       message.wParam = (void *)msg;
+       message.wParam = (void*)msg;
        message.lParam = lParam;
        message.Free = shadow_msg_out_release;
-
        /* First add reference as we reference it in this function.
-     * Therefore it would not be free'ed during post. */
+        * Therefore it would not be free'ed during post. */
        shadow_msg_out_addref(&message);
-
        ArrayList_Lock(server->clients);
+
        for (index = 0; index < ArrayList_Count(server->clients); index++)
        {
                client = (rdpShadowClient*)ArrayList_GetItem(server->clients, index);
+
                if (shadow_client_dispatch_msg(client, &message))
                {
                        count++;
                }
        }
-       ArrayList_Unlock(server->clients);
 
-    /* Release the reference for this function */
+       ArrayList_Unlock(server->clients);
+       /* Release the reference for this function */
        shadow_msg_out_release(&message);
-
        return count;
 }
 
@@ -1772,17 +1738,18 @@ int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode)
        wMessageQueue* queue = NULL;
        int count = 0;
        int index = 0;
-
        ArrayList_Lock(server->clients);
+
        for (index = 0; index < ArrayList_Count(server->clients); index++)
        {
                queue = ((rdpShadowClient*)ArrayList_GetItem(server->clients, index))->MsgQueue;
+
                if (MessageQueue_PostQuit(queue, nExitCode))
                {
                        count++;
                }
        }
-       ArrayList_Unlock(server->clients);
 
+       ArrayList_Unlock(server->clients);
        return count;
 }
index 00725de..8fc77ef 100644 (file)
@@ -46,14 +46,13 @@ UINT32 shadow_encoder_create_frame_id(rdpShadowEncoder* encoder)
 {
        UINT32 frameId;
        int inFlightFrames;
-
        inFlightFrames = shadow_encoder_inflight_frames(encoder);
 
-    /*
-     * Calculate preferred fps according to how much frames are
+       /*
+        * Calculate preferred fps according to how much frames are
         * in-progress. Note that it only works when subsytem implementation
         * calls shadow_encoder_preferred_fps and takes the suggestion.
-     */
+        */
        if (inFlightFrames > 1)
        {
                encoder->fps = (100 / (inFlightFrames + 1) * encoder->maxFps) / 100;
@@ -70,22 +69,20 @@ UINT32 shadow_encoder_create_frame_id(rdpShadowEncoder* encoder)
                encoder->fps = 1;
 
        frameId = ++encoder->frameId;
-
        return frameId;
 }
 
-int shadow_encoder_init_grid(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_grid(rdpShadowEncoder* encoder)
 {
        int i, j, k;
        int tileSize;
        int tileCount;
-
-       encoder->gridWidth = ((encoder->width + (encoder->maxTileWidth - 1)) / encoder->maxTileWidth);
-       encoder->gridHeight = ((encoder->height + (encoder->maxTileHeight - 1)) / encoder->maxTileHeight);
-
+       encoder->gridWidth = ((encoder->width + (encoder->maxTileWidth - 1)) /
+                             encoder->maxTileWidth);
+       encoder->gridHeight = ((encoder->height + (encoder->maxTileHeight - 1)) /
+                              encoder->maxTileHeight);
        tileSize = encoder->maxTileWidth * encoder->maxTileHeight * 4;
        tileCount = encoder->gridWidth * encoder->gridHeight;
-
        encoder->gridBuffer = (BYTE*) malloc(tileSize * tileCount);
 
        if (!encoder->gridBuffer)
@@ -108,7 +105,7 @@ int shadow_encoder_init_grid(rdpShadowEncoder* encoder)
        return 0;
 }
 
-int shadow_encoder_uninit_grid(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_grid(rdpShadowEncoder* encoder)
 {
        if (encoder->gridBuffer)
        {
@@ -124,11 +121,10 @@ int shadow_encoder_uninit_grid(rdpShadowEncoder* encoder)
 
        encoder->gridWidth = 0;
        encoder->gridHeight = 0;
-
        return 0;
 }
 
-int shadow_encoder_init_rfx(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_rfx(rdpShadowEncoder* encoder)
 {
        if (!encoder->rfx)
                encoder->rfx = rfx_context_new(TRUE);
@@ -140,19 +136,15 @@ int shadow_encoder_init_rfx(rdpShadowEncoder* encoder)
                goto fail;
 
        encoder->rfx->mode = encoder->server->rfxMode;
-
-       rfx_context_set_pixel_format(encoder->rfx, PIXEL_FORMAT_BGR24);
-
+       rfx_context_set_pixel_format(encoder->rfx, PIXEL_FORMAT_BGRX32);
        encoder->codecs |= FREERDP_CODEC_REMOTEFX;
-
        return 1;
-
 fail:
        rfx_context_free(encoder->rfx);
        return -1;
 }
 
-int shadow_encoder_init_nsc(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_nsc(rdpShadowEncoder* encoder)
 {
        rdpContext* context = (rdpContext*) encoder->client;
        rdpSettings* settings = context->settings;
@@ -167,21 +159,18 @@ int shadow_encoder_init_nsc(rdpShadowEncoder* encoder)
                goto fail;
 
        encoder->nsc->ColorLossLevel = settings->NSCodecColorLossLevel;
-       encoder->nsc->ChromaSubsamplingLevel = settings->NSCodecAllowSubsampling ? 1 : 0;
+       encoder->nsc->ChromaSubsamplingLevel = settings->NSCodecAllowSubsampling ? 1 :
+                                              0;
        encoder->nsc->DynamicColorFidelity = settings->NSCodecAllowDynamicColorFidelity;
-
-       nsc_context_set_pixel_format(encoder->nsc, PIXEL_FORMAT_BGR24);
-
+       nsc_context_set_pixel_format(encoder->nsc, PIXEL_FORMAT_BGRX32);
        encoder->codecs |= FREERDP_CODEC_NSCODEC;
-
        return 1;
-
 fail:
        nsc_context_free(encoder->nsc);
        return -1;
 }
 
-int shadow_encoder_init_planar(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_planar(rdpShadowEncoder* encoder)
 {
        DWORD planarFlags = 0;
        rdpContext* context = (rdpContext*) encoder->client;
@@ -195,27 +184,25 @@ int shadow_encoder_init_planar(rdpShadowEncoder* encoder)
        if (!encoder->planar)
        {
                encoder->planar = freerdp_bitmap_planar_context_new(planarFlags,
-                               encoder->maxTileWidth, encoder->maxTileHeight);
+                                 encoder->maxTileWidth, encoder->maxTileHeight);
        }
 
        if (!encoder->planar)
                goto fail;
 
        if (!freerdp_bitmap_planar_context_reset(encoder->planar,
-                                                encoder->maxTileWidth,
-                                                encoder->maxTileHeight))
+               encoder->maxTileWidth,
+               encoder->maxTileHeight))
                goto fail;
 
        encoder->codecs |= FREERDP_CODEC_PLANAR;
-
        return 1;
-
 fail:
        freerdp_bitmap_planar_context_free(encoder->planar);
        return -1;
 }
 
-int shadow_encoder_init_interleaved(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_interleaved(rdpShadowEncoder* encoder)
 {
        if (!encoder->interleaved)
                encoder->interleaved = bitmap_interleaved_context_new(TRUE);
@@ -227,15 +214,13 @@ int shadow_encoder_init_interleaved(rdpShadowEncoder* encoder)
                goto fail;
 
        encoder->codecs |= FREERDP_CODEC_INTERLEAVED;
-
        return 1;
-
 fail:
        bitmap_interleaved_context_free(encoder->interleaved);
        return -1;
 }
 
-int shadow_encoder_init_h264(rdpShadowEncoder* encoder)
+static int shadow_encoder_init_h264(rdpShadowEncoder* encoder)
 {
        if (!encoder->h264)
                encoder->h264 = h264_context_new(TRUE);
@@ -250,28 +235,24 @@ int shadow_encoder_init_h264(rdpShadowEncoder* encoder)
        encoder->h264->BitRate = encoder->server->h264BitRate;
        encoder->h264->FrameRate = encoder->server->h264FrameRate;
        encoder->h264->QP = encoder->server->h264QP;
-
        encoder->codecs |= FREERDP_CODEC_AVC420;
-
        return 1;
-
 fail:
        h264_context_free(encoder->h264);
        return -1;
 }
 
-int shadow_encoder_init(rdpShadowEncoder* encoder)
+static int shadow_encoder_init(rdpShadowEncoder* encoder)
 {
        encoder->width = encoder->server->screen->width;
        encoder->height = encoder->server->screen->height;
-
        encoder->maxTileWidth = 64;
        encoder->maxTileHeight = 64;
-
        shadow_encoder_init_grid(encoder);
 
        if (!encoder->bs)
-               encoder->bs = Stream_New(NULL, encoder->maxTileWidth * encoder->maxTileHeight * 4);
+               encoder->bs = Stream_New(NULL,
+                                        encoder->maxTileWidth * encoder->maxTileHeight * 4);
 
        if (!encoder->bs)
                return -1;
@@ -279,7 +260,7 @@ int shadow_encoder_init(rdpShadowEncoder* encoder)
        return 1;
 }
 
-int shadow_encoder_uninit_rfx(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_rfx(rdpShadowEncoder* encoder)
 {
        if (encoder->rfx)
        {
@@ -288,11 +269,10 @@ int shadow_encoder_uninit_rfx(rdpShadowEncoder* encoder)
        }
 
        encoder->codecs &= ~FREERDP_CODEC_REMOTEFX;
-
        return 1;
 }
 
-int shadow_encoder_uninit_nsc(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_nsc(rdpShadowEncoder* encoder)
 {
        if (encoder->nsc)
        {
@@ -301,11 +281,10 @@ int shadow_encoder_uninit_nsc(rdpShadowEncoder* encoder)
        }
 
        encoder->codecs &= ~FREERDP_CODEC_NSCODEC;
-
        return 1;
 }
 
-int shadow_encoder_uninit_planar(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_planar(rdpShadowEncoder* encoder)
 {
        if (encoder->planar)
        {
@@ -314,11 +293,10 @@ int shadow_encoder_uninit_planar(rdpShadowEncoder* encoder)
        }
 
        encoder->codecs &= ~FREERDP_CODEC_PLANAR;
-
        return 1;
 }
 
-int shadow_encoder_uninit_interleaved(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_interleaved(rdpShadowEncoder* encoder)
 {
        if (encoder->interleaved)
        {
@@ -327,24 +305,22 @@ int shadow_encoder_uninit_interleaved(rdpShadowEncoder* encoder)
        }
 
        encoder->codecs &= ~FREERDP_CODEC_INTERLEAVED;
-
        return 1;
 }
 
-int shadow_encoder_uninit_h264(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit_h264(rdpShadowEncoder* encoder)
 {
        if (encoder->h264)
        {
                h264_context_free(encoder->h264);
-               encoder->h264= NULL;
+               encoder->h264 = NULL;
        }
 
        encoder->codecs &= ~FREERDP_CODEC_AVC420;
-
        return 1;
 }
 
-int shadow_encoder_uninit(rdpShadowEncoder* encoder)
+static int shadow_encoder_uninit(rdpShadowEncoder* encoder)
 {
        shadow_encoder_uninit_grid(encoder);
 
@@ -388,7 +364,6 @@ int shadow_encoder_reset(rdpShadowEncoder* encoder)
        UINT32 codecs = encoder->codecs;
        rdpContext* context = (rdpContext*) encoder->client;
        rdpSettings* settings = context->settings;
-
        status = shadow_encoder_uninit(encoder);
 
        if (status < 0)
@@ -409,7 +384,6 @@ int shadow_encoder_reset(rdpShadowEncoder* encoder)
        encoder->frameId = 0;
        encoder->lastAckframeId = 0;
        encoder->frameAck = settings->SurfaceFrameMarkerEnabled;
-
        return 1;
 }
 
@@ -417,7 +391,8 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
 {
        int status;
 
-       if ((codecs & FREERDP_CODEC_REMOTEFX) && !(encoder->codecs & FREERDP_CODEC_REMOTEFX))
+       if ((codecs & FREERDP_CODEC_REMOTEFX)
+           && !(encoder->codecs & FREERDP_CODEC_REMOTEFX))
        {
                status = shadow_encoder_init_rfx(encoder);
 
@@ -425,7 +400,8 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
                        return -1;
        }
 
-       if ((codecs & FREERDP_CODEC_NSCODEC) && !(encoder->codecs & FREERDP_CODEC_NSCODEC))
+       if ((codecs & FREERDP_CODEC_NSCODEC)
+           && !(encoder->codecs & FREERDP_CODEC_NSCODEC))
        {
                status = shadow_encoder_init_nsc(encoder);
 
@@ -433,7 +409,8 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
                        return -1;
        }
 
-       if ((codecs & FREERDP_CODEC_PLANAR) && !(encoder->codecs & FREERDP_CODEC_PLANAR))
+       if ((codecs & FREERDP_CODEC_PLANAR)
+           && !(encoder->codecs & FREERDP_CODEC_PLANAR))
        {
                status = shadow_encoder_init_planar(encoder);
 
@@ -441,7 +418,8 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
                        return -1;
        }
 
-       if ((codecs & FREERDP_CODEC_INTERLEAVED) && !(encoder->codecs & FREERDP_CODEC_INTERLEAVED))
+       if ((codecs & FREERDP_CODEC_INTERLEAVED)
+           && !(encoder->codecs & FREERDP_CODEC_INTERLEAVED))
        {
                status = shadow_encoder_init_interleaved(encoder);
 
@@ -449,7 +427,8 @@ int shadow_encoder_prepare(rdpShadowEncoder* encoder, UINT32 codecs)
                        return -1;
        }
 
-       if ((codecs & FREERDP_CODEC_AVC420) && !(encoder->codecs & FREERDP_CODEC_AVC420))
+       if ((codecs & FREERDP_CODEC_AVC420)
+           && !(encoder->codecs & FREERDP_CODEC_AVC420))
        {
                status = shadow_encoder_init_h264(encoder);
 
@@ -464,7 +443,6 @@ rdpShadowEncoder* shadow_encoder_new(rdpShadowClient* client)
 {
        rdpShadowEncoder* encoder;
        rdpShadowServer* server = client->server;
-
        encoder = (rdpShadowEncoder*) calloc(1, sizeof(rdpShadowEncoder));
 
        if (!encoder)
@@ -472,13 +450,12 @@ rdpShadowEncoder* shadow_encoder_new(rdpShadowClient* client)
 
        encoder->client = client;
        encoder->server = server;
-
        encoder->fps = 16;
        encoder->maxFps = 32;
 
        if (shadow_encoder_init(encoder) < 0)
        {
-               free (encoder);
+               free(encoder);
                return NULL;
        }
 
@@ -491,6 +468,5 @@ void shadow_encoder_free(rdpShadowEncoder* encoder)
                return;
 
        shadow_encoder_uninit(encoder);
-
        free(encoder);
 }
index 53d05a9..e3d1f8c 100644 (file)
 
 #include "shadow_surface.h"
 #define ALIGN_SCREEN_SIZE(size, align) ((size + align - 1) & (~(align - 1)))
-rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y, int width, int height)
+rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y,
+                                     int width, int height)
 {
        rdpShadowSurface* surface;
-
        surface = (rdpShadowSurface*) calloc(1, sizeof(rdpShadowSurface));
 
        if (!surface)
                return NULL;
 
        surface->server = server;
-
        surface->x = x;
        surface->y = y;
        surface->width = width;
        surface->height = height;
        surface->scanline = ALIGN_SCREEN_SIZE(surface->width, 4) * 4;
+       surface->format = PIXEL_FORMAT_BGRX32;
+       surface->data = (BYTE*) calloc(1,
+                                      surface->scanline * ALIGN_SCREEN_SIZE(surface->height, 4));
 
-       surface->data = (BYTE*) calloc(1, surface->scanline * ALIGN_SCREEN_SIZE(surface->height, 4));
        if (!surface->data)
        {
-               free (surface);
+               free(surface);
                return NULL;
        }
 
        if (!InitializeCriticalSectionAndSpinCount(&(surface->lock), 4000))
        {
-               free (surface->data);
-               free (surface);
+               free(surface->data);
+               free(surface);
                return NULL;
        }
 
        region16_init(&(surface->invalidRegion));
-
        return surface;
 }
 
@@ -66,15 +66,13 @@ void shadow_surface_free(rdpShadowSurface* surface)
                return;
 
        free(surface->data);
-
        DeleteCriticalSection(&(surface->lock));
-
        region16_uninit(&(surface->invalidRegion));
-
        free(surface);
 }
 
-BOOL shadow_surface_resize(rdpShadowSurface *surface, int x, int y, int width, int height)
+BOOL shadow_surface_resize(rdpShadowSurface* surface, int x, int y, int width,
+                           int height)
 {
        BYTE* buffer = NULL;
        int scanline =  ALIGN_SCREEN_SIZE(width, 4) * 4;
@@ -90,7 +88,9 @@ BOOL shadow_surface_resize(rdpShadowSurface *surface, int x, int y, int width, i
                return TRUE;
        }
 
-       buffer = (BYTE*) realloc(surface->data, scanline * ALIGN_SCREEN_SIZE(height, 4));
+       buffer = (BYTE*) realloc(surface->data, scanline * ALIGN_SCREEN_SIZE(height,
+                                4));
+
        if (buffer)
        {
                surface->x = x;
@@ -99,7 +99,6 @@ BOOL shadow_surface_resize(rdpShadowSurface *surface, int x, int y, int width, i
                surface->height = height;
                surface->scanline = scanline;
                surface->data = buffer;
-
                return TRUE;
        }