Fixed log message.
authorArmin Novak <armin.novak@thincast.com>
Thu, 4 Aug 2016 14:28:38 +0000 (16:28 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:43:08 +0000 (13:43 +0200)
channels/rdpgfx/client/rdpgfx_main.c

index c20256e..23782db 100644 (file)
@@ -62,15 +62,11 @@ static UINT rdpgfx_send_caps_advertise_pdu(RDPGFX_CHANNEL_CALLBACK* callback)
        RDPGFX_CAPSET* capsSet;
        RDPGFX_CAPSET capsSets[3];
        RDPGFX_CAPS_ADVERTISE_PDU pdu;
-
        gfx = (RDPGFX_PLUGIN*) callback->plugin;
-
        header.flags = 0;
        header.cmdId = RDPGFX_CMDID_CAPSADVERTISE;
-
        pdu.capsSetCount = 0;
        pdu.capsSets = (RDPGFX_CAPSET*) capsSets;
-
        capsSet = &capsSets[pdu.capsSetCount++];
        capsSet->version = RDPGFX_CAPVERSION_8;
        capsSet->flags = 0;
@@ -107,11 +103,11 @@ static UINT rdpgfx_send_caps_advertise_pdu(RDPGFX_CHANNEL_CALLBACK* callback)
                        capsSet->flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
        }
 
-       header.pduLength = RDPGFX_HEADER_SIZE + 2 + (pdu.capsSetCount * RDPGFX_CAPSET_SIZE);
-
+       header.pduLength = RDPGFX_HEADER_SIZE + 2 + (pdu.capsSetCount *
+                          RDPGFX_CAPSET_SIZE);
        WLog_DBG(TAG, "SendCapsAdvertisePdu %d", pdu.capsSetCount);
-
        s = Stream_New(NULL, header.pduLength);
+
        if (!s)
        {
                WLog_ERR(TAG, "Stream_New failed!");
@@ -125,7 +121,6 @@ static UINT rdpgfx_send_caps_advertise_pdu(RDPGFX_CHANNEL_CALLBACK* callback)
        }
 
        /* RDPGFX_CAPS_ADVERTISE_PDU */
-
        Stream_Write_UINT16(s, pdu.capsSetCount); /* capsSetCount (2 bytes) */
 
        for (index = 0; index < pdu.capsSetCount; index++)
@@ -137,11 +132,9 @@ static UINT rdpgfx_send_caps_advertise_pdu(RDPGFX_CHANNEL_CALLBACK* callback)
        }
 
        Stream_SealLength(s);
-
-       error = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL);
-
+       error = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s),
+                                        Stream_Buffer(s), NULL);
        Stream_Free(s, TRUE);
-
        return error;
 }
 
@@ -150,12 +143,12 @@ static UINT rdpgfx_send_caps_advertise_pdu(RDPGFX_CHANNEL_CALLBACK* callback)
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_caps_confirm_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_caps_confirm_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_CAPSET capsSet;
        UINT32 capsDataLength;
        RDPGFX_CAPS_CONFIRM_PDU pdu;
-
        pdu.capsSet = &capsSet;
 
        if (Stream_GetRemainingLength(s) < 12)
@@ -167,10 +160,8 @@ static UINT rdpgfx_recv_caps_confirm_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStr
        Stream_Read_UINT32(s, capsSet.version); /* version (4 bytes) */
        Stream_Read_UINT32(s, capsDataLength); /* capsDataLength (4 bytes) */
        Stream_Read_UINT32(s, capsSet.flags); /* capsData (4 bytes) */
-
        WLog_DBG(TAG, "RecvCapsConfirmPdu: version: 0x%04X flags: 0x%04X",
-                       capsSet.version, capsSet.flags);
-
+                capsSet.version, capsSet.flags);
        return CHANNEL_RC_OK;
 }
 
@@ -179,19 +170,18 @@ static UINT rdpgfx_recv_caps_confirm_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStr
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_send_frame_acknowledge_pdu(RDPGFX_CHANNEL_CALLBACK* callback, RDPGFX_FRAME_ACKNOWLEDGE_PDU* pdu)
+static UINT rdpgfx_send_frame_acknowledge_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        RDPGFX_FRAME_ACKNOWLEDGE_PDU* pdu)
 {
        UINT error;
        wStream* s;
        RDPGFX_HEADER header;
-
        header.flags = 0;
        header.cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE;
        header.pduLength = RDPGFX_HEADER_SIZE + 12;
-
        WLog_DBG(TAG, "SendFrameAcknowledgePdu: %d", pdu->frameId);
-
        s = Stream_New(NULL, header.pduLength);
+
        if (!s)
        {
                WLog_ERR(TAG, "Stream_New failed!");
@@ -205,15 +195,13 @@ static UINT rdpgfx_send_frame_acknowledge_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
        }
 
        /* RDPGFX_FRAME_ACKNOWLEDGE_PDU */
-
        Stream_Write_UINT32(s, pdu->queueDepth); /* queueDepth (4 bytes) */
        Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */
-       Stream_Write_UINT32(s, pdu->totalFramesDecoded); /* totalFramesDecoded (4 bytes) */
-
-       error = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL);
-
+       Stream_Write_UINT32(s,
+                           pdu->totalFramesDecoded); /* totalFramesDecoded (4 bytes) */
+       error = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s),
+                                        Stream_Buffer(s), NULL);
        Stream_Free(s, TRUE);
-
        return error;
 }
 
@@ -222,7 +210,8 @@ static UINT rdpgfx_send_frame_acknowledge_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_reset_graphics_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_reset_graphics_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        int pad;
        UINT32 index;
@@ -248,7 +237,8 @@ static UINT rdpgfx_recv_reset_graphics_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
                return ERROR_INVALID_DATA;
        }
 
-       pdu.monitorDefArray = (MONITOR_DEF*) calloc(pdu.monitorCount, sizeof(MONITOR_DEF));
+       pdu.monitorDefArray = (MONITOR_DEF*) calloc(pdu.monitorCount,
+                             sizeof(MONITOR_DEF));
 
        if (!pdu.monitorDefArray)
        {
@@ -276,19 +266,18 @@ static UINT rdpgfx_recv_reset_graphics_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
        }
 
        Stream_Seek(s, pad); /* pad (total size is 340 bytes) */
-
        WLog_DBG(TAG, "RecvResetGraphicsPdu: width: %d height: %d count: %d",
-                       pdu.width, pdu.height, pdu.monitorCount);
+                pdu.width, pdu.height, pdu.monitorCount);
 
        if (context)
        {
                IFCALLRET(context->ResetGraphics, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->ResetGraphics failed with error %lu", error);
        }
 
        free(pdu.monitorDefArray);
-
        return error;
 }
 
@@ -297,7 +286,8 @@ static UINT rdpgfx_recv_reset_graphics_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_evict_cache_entry_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_evict_cache_entry_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_EVICT_CACHE_ENTRY_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -311,12 +301,12 @@ static UINT rdpgfx_recv_evict_cache_entry_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
        }
 
        Stream_Read_UINT16(s, pdu.cacheSlot); /* cacheSlot (2 bytes) */
-
        WLog_DBG(TAG, "RecvEvictCacheEntryPdu: cacheSlot: %d", pdu.cacheSlot);
 
        if (context)
        {
                IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->EvictCacheEntry failed with error %lu", error);
        }
@@ -329,7 +319,8 @@ static UINT rdpgfx_recv_evict_cache_entry_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-UINT rdpgfx_recv_cache_import_reply_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+UINT rdpgfx_recv_cache_import_reply_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+                                        wStream* s)
 {
        UINT16 index;
        RDPGFX_CACHE_IMPORT_REPLY_PDU pdu;
@@ -345,7 +336,7 @@ UINT rdpgfx_recv_cache_import_reply_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStre
 
        Stream_Read_UINT16(s, pdu.importedEntriesCount); /* cacheSlot (2 bytes) */
 
-       if (Stream_GetRemainingLength(s) < (size_t) (pdu.importedEntriesCount * 2))
+       if (Stream_GetRemainingLength(s) < (size_t)(pdu.importedEntriesCount * 2))
        {
                WLog_ERR(TAG, "not enough data!");
                return ERROR_INVALID_DATA;
@@ -365,17 +356,17 @@ UINT rdpgfx_recv_cache_import_reply_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStre
        }
 
        WLog_DBG(TAG, "RecvCacheImportReplyPdu: importedEntriesCount: %d",
-                       pdu.importedEntriesCount);
+                pdu.importedEntriesCount);
 
        if (context)
        {
                IFCALLRET(context->CacheImportReply, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->CacheImportReply failed with error %lu", error);
        }
 
        free(pdu.cacheSlots);
-
        return error;
 }
 
@@ -384,7 +375,8 @@ UINT rdpgfx_recv_cache_import_reply_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStre
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_create_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_create_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_CREATE_SURFACE_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -401,13 +393,14 @@ static UINT rdpgfx_recv_create_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
        Stream_Read_UINT16(s, pdu.width); /* width (2 bytes) */
        Stream_Read_UINT16(s, pdu.height); /* height (2 bytes) */
        Stream_Read_UINT8(s, pdu.pixelFormat); /* RDPGFX_PIXELFORMAT (1 byte) */
-
-       WLog_DBG(TAG, "RecvCreateSurfacePdu: surfaceId: %d width: %d height: %d pixelFormat: 0x%02X",
-                       pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
+       WLog_DBG(TAG,
+                "RecvCreateSurfacePdu: surfaceId: %d width: %d height: %d pixelFormat: 0x%02X",
+                pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
 
        if (context)
        {
                IFCALLRET(context->CreateSurface, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->CreateSurface failed with error %lu", error);
        }
@@ -420,7 +413,8 @@ static UINT rdpgfx_recv_create_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-UINT rdpgfx_recv_delete_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+UINT rdpgfx_recv_delete_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+                                    wStream* s)
 {
        RDPGFX_DELETE_SURFACE_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -434,12 +428,12 @@ UINT rdpgfx_recv_delete_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream*
        }
 
        Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
-
        WLog_DBG(TAG, "RecvDeleteSurfacePdu: surfaceId: %d", pdu.surfaceId);
 
        if (context)
        {
                IFCALLRET(context->DeleteSurface, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->DeleteSurface failed with error %lu", error);
        }
@@ -452,7 +446,8 @@ UINT rdpgfx_recv_delete_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream*
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_start_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_start_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+                                        wStream* s)
 {
        RDPGFX_START_FRAME_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -467,19 +462,18 @@ static UINT rdpgfx_recv_start_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStre
 
        Stream_Read_UINT32(s, pdu.timestamp); /* timestamp (4 bytes) */
        Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */
-
        WLog_DBG(TAG, "RecvStartFramePdu: frameId: %d timestamp: 0x%04X",
-                       pdu.frameId, pdu.timestamp);
+                pdu.frameId, pdu.timestamp);
 
        if (context)
        {
                IFCALLRET(context->StartFrame, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->StartFrame failed with error %lu", error);
        }
 
        gfx->UnacknowledgedFrames++;
-
        return error;
 }
 
@@ -488,7 +482,8 @@ static UINT rdpgfx_recv_start_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStre
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+                                      wStream* s)
 {
        RDPGFX_END_FRAME_PDU pdu;
        RDPGFX_FRAME_ACKNOWLEDGE_PDU ack;
@@ -503,12 +498,12 @@ static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
        }
 
        Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */
-
        WLog_DBG(TAG, "RecvEndFramePdu: frameId: %d", pdu.frameId);
 
        if (context)
        {
                IFCALLRET(context->EndFrame, error, context, &pdu);
+
                if (error)
                {
                        WLog_ERR(TAG, "context->EndFrame failed with error %lu", error);
@@ -518,7 +513,6 @@ static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
 
        gfx->UnacknowledgedFrames--;
        gfx->TotalDecodedFrames++;
-
        ack.frameId = pdu.frameId;
        ack.totalFramesDecoded = gfx->TotalDecodedFrames;
 
@@ -527,12 +521,13 @@ static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
                ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT;
 
                if (gfx->TotalDecodedFrames == 1)
-               if ((error = rdpgfx_send_frame_acknowledge_pdu(callback, &ack)))
-                       WLog_ERR(TAG, "rdpgfx_send_frame_acknowledge_pdu failed with error %lu", error);
+                       if ((error = rdpgfx_send_frame_acknowledge_pdu(callback, &ack)))
+                               WLog_ERR(TAG, "rdpgfx_send_frame_acknowledge_pdu failed with error %lu", error);
        }
        else
        {
                ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE;
+
                if ((error = rdpgfx_send_frame_acknowledge_pdu(callback, &ack)))
                        WLog_ERR(TAG, "rdpgfx_send_frame_acknowledge_pdu failed with error %lu", error);
        }
@@ -545,7 +540,8 @@ static UINT rdpgfx_recv_end_frame_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_wire_to_surface_1_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_wire_to_surface_1_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_SURFACE_COMMAND cmd;
        RDPGFX_WIRE_TO_SURFACE_PDU_1 pdu;
@@ -578,26 +574,29 @@ static UINT rdpgfx_recv_wire_to_surface_1_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
 
        pdu.bitmapData = Stream_Pointer(s);
        Stream_Seek(s, pdu.bitmapDataLength);
-
-       WLog_DBG(TAG, "RecvWireToSurface1Pdu: surfaceId: %d codecId: %s (0x%04X) pixelFormat: 0x%04X "
-                       "destRect: left: %d top: %d right: %d bottom: %d bitmapDataLength: %d",
-                       (int) pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, pdu.pixelFormat,
-                       pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
-                       pdu.bitmapDataLength);
-
+       WLog_DBG(TAG,
+                "RecvWireToSurface1Pdu: surfaceId: %lu codecId: %s (0x%04lX) pixelFormat: 0x%04lX "
+                "destRect: left: %lu top: %lu right: %lu bottom: %lu bitmapDataLength: %lu",
+                pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
+                pdu.pixelFormat,
+                pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
+                pdu.bitmapDataLength);
        cmd.surfaceId = pdu.surfaceId;
        cmd.codecId = pdu.codecId;
        cmd.contextId = 0;
-       switch(pdu.pixelFormat)
-       {
-       case GFX_PIXEL_FORMAT_XRGB_8888:
-               cmd.format = PIXEL_FORMAT_BGRX32;
-               break;
-       case GFX_PIXEL_FORMAT_ARGB_8888:
-               cmd.format = PIXEL_FORMAT_BGRA32;
-               break;
-       default:
-               return ERROR_INVALID_DATA;
+
+       switch (pdu.pixelFormat)
+       {
+               case GFX_PIXEL_FORMAT_XRGB_8888:
+                       cmd.format = PIXEL_FORMAT_BGRX32;
+                       break;
+
+               case GFX_PIXEL_FORMAT_ARGB_8888:
+                       cmd.format = PIXEL_FORMAT_BGRA32;
+                       break;
+
+               default:
+                       return ERROR_INVALID_DATA;
        }
 
        cmd.left = pdu.destRect.left;
@@ -620,7 +619,8 @@ static UINT rdpgfx_recv_wire_to_surface_1_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_wire_to_surface_2_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_wire_to_surface_2_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_SURFACE_COMMAND cmd;
        RDPGFX_WIRE_TO_SURFACE_PDU_2 pdu;
@@ -638,17 +638,13 @@ static UINT rdpgfx_recv_wire_to_surface_2_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
        Stream_Read_UINT16(s, pdu.codecId); /* codecId (2 bytes) */
        Stream_Read_UINT32(s, pdu.codecContextId); /* codecContextId (4 bytes) */
        Stream_Read_UINT8(s, pdu.pixelFormat); /* pixelFormat (1 byte) */
-
        Stream_Read_UINT32(s, pdu.bitmapDataLength); /* bitmapDataLength (4 bytes) */
-
        pdu.bitmapData = Stream_Pointer(s);
        Stream_Seek(s, pdu.bitmapDataLength);
-
        WLog_DBG(TAG, "RecvWireToSurface2Pdu: surfaceId: %d codecId: %s (0x%04X) "
-                       "codecContextId: %d pixelFormat: 0x%04X bitmapDataLength: %d",
-                       (int) pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
-                       pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
-
+                "codecContextId: %d pixelFormat: 0x%04X bitmapDataLength: %d",
+                (int) pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
+                pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
        cmd.surfaceId = pdu.surfaceId;
        cmd.codecId = pdu.codecId;
        cmd.contextId = pdu.codecContextId;
@@ -665,6 +661,7 @@ static UINT rdpgfx_recv_wire_to_surface_2_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
        if (context)
        {
                IFCALLRET(context->SurfaceCommand, error, context, &cmd);
+
                if (error)
                        WLog_ERR(TAG, "context->SurfaceCommand failed with error %lu", error);
        }
@@ -677,7 +674,8 @@ static UINT rdpgfx_recv_wire_to_surface_2_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_delete_encoding_context_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_delete_encoding_context_pdu(RDPGFX_CHANNEL_CALLBACK*
+        callback, wStream* s)
 {
        RDPGFX_DELETE_ENCODING_CONTEXT_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -692,13 +690,13 @@ static UINT rdpgfx_recv_delete_encoding_context_pdu(RDPGFX_CHANNEL_CALLBACK* cal
 
        Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
        Stream_Read_UINT32(s, pdu.codecContextId); /* codecContextId (4 bytes) */
-
        WLog_DBG(TAG, "RecvDeleteEncodingContextPdu: surfaceId: %d codecContextId: %d",
-                       pdu.surfaceId, pdu.codecContextId);
+                pdu.surfaceId, pdu.codecContextId);
 
        if (context)
        {
                IFCALLRET(context->DeleteEncodingContext, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->DeleteEncodingContext failed with error %lu", error);
        }
@@ -727,14 +725,17 @@ UINT rdpgfx_recv_solid_fill_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        }
 
        Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
-       if ((error = rdpgfx_read_color32(s, &(pdu.fillPixel)))) /* fillPixel (4 bytes) */
+
+       if ((error = rdpgfx_read_color32(s,
+                                        &(pdu.fillPixel)))) /* fillPixel (4 bytes) */
        {
                WLog_ERR(TAG, "rdpgfx_read_color32 failed with error %lu!", error);
                return error;
        }
+
        Stream_Read_UINT16(s, pdu.fillRectCount); /* fillRectCount (2 bytes) */
 
-       if (Stream_GetRemainingLength(s) < (size_t) (pdu.fillRectCount * 8))
+       if (Stream_GetRemainingLength(s) < (size_t)(pdu.fillRectCount * 8))
        {
                WLog_ERR(TAG, "not enough data!");
                return ERROR_INVALID_DATA;
@@ -751,6 +752,7 @@ UINT rdpgfx_recv_solid_fill_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        for (index = 0; index < pdu.fillRectCount; index++)
        {
                fillRect = &(pdu.fillRects[index]);
+
                if ((error = rdpgfx_read_rect16(s, fillRect)))
                {
                        WLog_ERR(TAG, "rdpgfx_read_rect16 failed with error %lu!", error);
@@ -760,17 +762,17 @@ UINT rdpgfx_recv_solid_fill_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        }
 
        WLog_DBG(TAG, "RecvSolidFillPdu: surfaceId: %d fillRectCount: %d",
-                       pdu.surfaceId, pdu.fillRectCount);
+                pdu.surfaceId, pdu.fillRectCount);
 
        if (context)
        {
                IFCALLRET(context->SolidFill, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->SolidFill failed with error %lu", error);
        }
 
        free(pdu.fillRects);
-
        return error;
 }
 
@@ -779,7 +781,8 @@ UINT rdpgfx_recv_solid_fill_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK*
+        callback, wStream* s)
 {
        UINT16 index;
        RDPGFX_POINT16* destPt;
@@ -796,6 +799,7 @@ static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback
 
        Stream_Read_UINT16(s, pdu.surfaceIdSrc); /* surfaceIdSrc (2 bytes) */
        Stream_Read_UINT16(s, pdu.surfaceIdDest); /* surfaceIdDest (2 bytes) */
+
        if ((error = rdpgfx_read_rect16(s, &(pdu.rectSrc)))) /* rectSrc (8 bytes ) */
        {
                WLog_ERR(TAG, "rdpgfx_read_rect16 failed with error %lu!", error);
@@ -804,13 +808,14 @@ static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback
 
        Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */
 
-       if (Stream_GetRemainingLength(s) < (size_t) (pdu.destPtsCount * 4))
+       if (Stream_GetRemainingLength(s) < (size_t)(pdu.destPtsCount * 4))
        {
                WLog_ERR(TAG, "not enough data!");
                return ERROR_INVALID_DATA;
        }
 
-       pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16));
+       pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount,
+                                              sizeof(RDPGFX_POINT16));
 
        if (!pdu.destPts)
        {
@@ -821,6 +826,7 @@ static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback
        for (index = 0; index < pdu.destPtsCount; index++)
        {
                destPt = &(pdu.destPts[index]);
+
                if ((error = rdpgfx_read_point16(s, destPt)))
                {
                        WLog_ERR(TAG, "rdpgfx_read_point16 failed with error %lu!", error);
@@ -830,20 +836,20 @@ static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback
        }
 
        WLog_DBG(TAG, "RecvSurfaceToSurfacePdu: surfaceIdSrc: %d surfaceIdDest: %d "
-                       "left: %d top: %d right: %d bottom: %d destPtsCount: %d",
-                       pdu.surfaceIdSrc, pdu.surfaceIdDest,
-                       pdu.rectSrc.left, pdu.rectSrc.top, pdu.rectSrc.right, pdu.rectSrc.bottom,
-                       pdu.destPtsCount);
+                "left: %d top: %d right: %d bottom: %d destPtsCount: %d",
+                pdu.surfaceIdSrc, pdu.surfaceIdDest,
+                pdu.rectSrc.left, pdu.rectSrc.top, pdu.rectSrc.right, pdu.rectSrc.bottom,
+                pdu.destPtsCount);
 
        if (context)
        {
                IFCALLRET(context->SurfaceToSurface, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->SurfaceToSurface failed with error %lu", error);
        }
 
        free(pdu.destPts);
-
        return error;
 }
 
@@ -852,7 +858,8 @@ static UINT rdpgfx_recv_surface_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_surface_to_cache_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_surface_to_cache_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_SURFACE_TO_CACHE_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -868,21 +875,24 @@ static UINT rdpgfx_recv_surface_to_cache_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
        Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
        Stream_Read_UINT64(s, pdu.cacheKey); /* cacheKey (8 bytes) */
        Stream_Read_UINT16(s, pdu.cacheSlot); /* cacheSlot (2 bytes) */
+
        if ((error = rdpgfx_read_rect16(s, &(pdu.rectSrc)))) /* rectSrc (8 bytes ) */
        {
                WLog_ERR(TAG, "rdpgfx_read_rect16 failed with error %lu!", error);
                return error;
        }
 
-       WLog_DBG(TAG, "RecvSurfaceToCachePdu: surfaceId: %d cacheKey: 0x%08X cacheSlot: %d "
-                       "left: %d top: %d right: %d bottom: %d",
-                       pdu.surfaceId, (int) pdu.cacheKey, pdu.cacheSlot,
-                       pdu.rectSrc.left, pdu.rectSrc.top,
-                       pdu.rectSrc.right, pdu.rectSrc.bottom);
+       WLog_DBG(TAG,
+                "RecvSurfaceToCachePdu: surfaceId: %d cacheKey: 0x%08X cacheSlot: %d "
+                "left: %d top: %d right: %d bottom: %d",
+                pdu.surfaceId, (int) pdu.cacheKey, pdu.cacheSlot,
+                pdu.rectSrc.left, pdu.rectSrc.top,
+                pdu.rectSrc.right, pdu.rectSrc.bottom);
 
        if (context)
        {
                IFCALLRET(context->SurfaceToCache, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->SurfaceToCache failed with error %lu", error);
        }
@@ -895,7 +905,8 @@ static UINT rdpgfx_recv_surface_to_cache_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+                                      wStream* s)
 {
        UINT16 index;
        RDPGFX_POINT16* destPt;
@@ -914,13 +925,14 @@ UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
        Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */
        Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */
 
-       if (Stream_GetRemainingLength(s) < (size_t) (pdu.destPtsCount * 4))
+       if (Stream_GetRemainingLength(s) < (size_t)(pdu.destPtsCount * 4))
        {
                WLog_ERR(TAG, "not enough data!");
                return ERROR_INVALID_DATA;
        }
 
-       pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16));
+       pdu.destPts = (RDPGFX_POINT16*) calloc(pdu.destPtsCount,
+                                              sizeof(RDPGFX_POINT16));
 
        if (!pdu.destPts)
        {
@@ -931,6 +943,7 @@ UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
        for (index = 0; index < pdu.destPtsCount; index++)
        {
                destPt = &(pdu.destPts[index]);
+
                if ((error = rdpgfx_read_point16(s, destPt)))
                {
                        WLog_ERR(TAG, "rdpgfx_read_point16 failed with error %lu", error);
@@ -939,18 +952,19 @@ UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
                }
        }
 
-       WLog_DBG(TAG, "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %d surfaceId: %d destPtsCount: %d",
-                       pdu.cacheSlot, (int) pdu.surfaceId, pdu.destPtsCount);
+       WLog_DBG(TAG,
+                "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %d surfaceId: %d destPtsCount: %d",
+                pdu.cacheSlot, (int) pdu.surfaceId, pdu.destPtsCount);
 
        if (context)
        {
                IFCALLRET(context->CacheToSurface, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->CacheToSurface failed with error %lu", error);
        }
 
        free(pdu.destPts);
-
        return error;
 }
 
@@ -959,7 +973,8 @@ UINT rdpgfx_recv_cache_to_surface_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_recv_map_surface_to_output_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+static UINT rdpgfx_recv_map_surface_to_output_pdu(RDPGFX_CHANNEL_CALLBACK*
+        callback, wStream* s)
 {
        RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -976,13 +991,14 @@ static UINT rdpgfx_recv_map_surface_to_output_pdu(RDPGFX_CHANNEL_CALLBACK* callb
        Stream_Read_UINT16(s, pdu.reserved); /* reserved (2 bytes) */
        Stream_Read_UINT32(s, pdu.outputOriginX); /* outputOriginX (4 bytes) */
        Stream_Read_UINT32(s, pdu.outputOriginY); /* outputOriginY (4 bytes) */
-
-       WLog_DBG(TAG, "RecvMapSurfaceToOutputPdu: surfaceId: %d outputOriginX: %d outputOriginY: %d",
-                       (int) pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
+       WLog_DBG(TAG,
+                "RecvMapSurfaceToOutputPdu: surfaceId: %d outputOriginX: %d outputOriginY: %d",
+                (int) pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
 
        if (context)
        {
                IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->MapSurfaceToOutput failed with error %lu", error);
        }
@@ -995,7 +1011,8 @@ static UINT rdpgfx_recv_map_surface_to_output_pdu(RDPGFX_CHANNEL_CALLBACK* callb
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-UINT rdpgfx_recv_map_surface_to_window_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
+UINT rdpgfx_recv_map_surface_to_window_pdu(RDPGFX_CHANNEL_CALLBACK* callback,
+        wStream* s)
 {
        RDPGFX_MAP_SURFACE_TO_WINDOW_PDU pdu;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
@@ -1012,13 +1029,14 @@ UINT rdpgfx_recv_map_surface_to_window_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wS
        Stream_Read_UINT64(s, pdu.windowId); /* windowId (8 bytes) */
        Stream_Read_UINT32(s, pdu.mappedWidth); /* mappedWidth (4 bytes) */
        Stream_Read_UINT32(s, pdu.mappedHeight); /* mappedHeight (4 bytes) */
-
-       WLog_DBG(TAG, "RecvMapSurfaceToWindowPdu: surfaceId: %d windowId: 0x%04X mappedWidth: %d mappedHeight: %d",
-                       pdu.surfaceId, (int) pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
+       WLog_DBG(TAG,
+                "RecvMapSurfaceToWindowPdu: surfaceId: %d windowId: 0x%04X mappedWidth: %d mappedHeight: %d",
+                pdu.surfaceId, (int) pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
 
        if (context && context->MapSurfaceToWindow)
        {
                IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu);
+
                if (error)
                        WLog_ERR(TAG, "context->MapSurfaceToWindow failed with error %lu", error);
        }
@@ -1036,7 +1054,6 @@ static UINT rdpgfx_recv_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        int beg, end;
        RDPGFX_HEADER header;
        UINT error;
-
        beg = Stream_GetPosition(s);
 
        if ((error = rdpgfx_read_header(s, &header)))
@@ -1047,94 +1064,120 @@ static UINT rdpgfx_recv_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
 
 #if 1
        WLog_DBG(TAG, "cmdId: %s (0x%04X) flags: 0x%04X pduLength: %d",
-                       rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags, header.pduLength);
+                rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags,
+                header.pduLength);
 #endif
 
        switch (header.cmdId)
        {
                case RDPGFX_CMDID_WIRETOSURFACE_1:
                        if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_wire_to_surface_1_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_wire_to_surface_1_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_WIRETOSURFACE_2:
                        if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_wire_to_surface_2_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_wire_to_surface_2_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_DELETEENCODINGCONTEXT:
                        if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_delete_encoding_context_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_delete_encoding_context_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_SOLIDFILL:
                        if ((error = rdpgfx_recv_solid_fill_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_solid_fill_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_SURFACETOSURFACE:
                        if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_surface_to_surface_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_surface_to_surface_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_SURFACETOCACHE:
                        if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_surface_to_cache_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_CACHETOSURFACE:
                        if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_cache_to_surface_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_EVICTCACHEENTRY:
                        if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_evict_cache_entry_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_evict_cache_entry_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_CREATESURFACE:
                        if ((error = rdpgfx_recv_create_surface_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_create_surface_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_DELETESURFACE:
                        if ((error = rdpgfx_recv_delete_surface_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_delete_surface_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_STARTFRAME:
                        if ((error = rdpgfx_recv_start_frame_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_start_frame_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_ENDFRAME:
                        if ((error = rdpgfx_recv_end_frame_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_end_frame_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_RESETGRAPHICS:
                        if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_reset_graphics_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_MAPSURFACETOOUTPUT:
                        if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_map_surface_to_output_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_map_surface_to_output_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_CACHEIMPORTREPLY:
                        if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_cache_import_reply_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_cache_import_reply_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                case RDPGFX_CMDID_CAPSCONFIRM:
                        if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s)))
                                WLog_ERR(TAG, "rdpgfx_recv_caps_confirm_pdu failed with error %lu!", error);
+
                        break;
 
                case RDPGFX_CMDID_MAPSURFACETOWINDOW:
                        if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s)))
-                               WLog_ERR(TAG, "rdpgfx_recv_map_surface_to_window_pdu failed with error %lu!", error);
+                               WLog_ERR(TAG, "rdpgfx_recv_map_surface_to_window_pdu failed with error %lu!",
+                                        error);
+
                        break;
 
                default:
@@ -1145,7 +1188,7 @@ static UINT rdpgfx_recv_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        if (error)
        {
                WLog_ERR(TAG,  "Error while parsing GFX cmdId: %s (0x%04X)",
-                                rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
+                        rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
                return error;
        }
 
@@ -1154,7 +1197,7 @@ static UINT rdpgfx_recv_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
        if (end != (beg + header.pduLength))
        {
                WLog_ERR(TAG,  "Unexpected gfx pdu end: Actual: %d, Expected: %d",
-                                end, (beg + header.pduLength));
+                        end, (beg + header.pduLength));
                Stream_SetPosition(s, (beg + header.pduLength));
        }
 
@@ -1166,7 +1209,8 @@ static UINT rdpgfx_recv_pdu(RDPGFX_CHANNEL_CALLBACK* callback, wStream* s)
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
+static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback*
+                                    pChannelCallback, wStream* data)
 {
        wStream* s;
        int status = 0;
@@ -1175,8 +1219,8 @@ static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback
        RDPGFX_CHANNEL_CALLBACK* callback = (RDPGFX_CHANNEL_CALLBACK*) pChannelCallback;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
        UINT error = CHANNEL_RC_OK;
-
-       status = zgfx_decompress(gfx->zgfx, Stream_Pointer(data), Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
+       status = zgfx_decompress(gfx->zgfx, Stream_Pointer(data),
+                                Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
 
        if (status < 0)
        {
@@ -1185,6 +1229,7 @@ static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback
        }
 
        s = Stream_New(pDstData, DstSize);
+
        if (!s)
        {
                WLog_ERR(TAG, "calloc failed!");
@@ -1201,7 +1246,6 @@ static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback
        }
 
        Stream_Free(s, TRUE);
-
        return error;
 }
 
@@ -1213,9 +1257,7 @@ static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback
 static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback)
 {
        RDPGFX_CHANNEL_CALLBACK* callback = (RDPGFX_CHANNEL_CALLBACK*) pChannelCallback;
-
        WLog_DBG(TAG, "OnOpen");
-
        return rdpgfx_send_caps_advertise_pdu(callback);
 }
 
@@ -1232,11 +1274,8 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
        RDPGFX_CHANNEL_CALLBACK* callback = (RDPGFX_CHANNEL_CALLBACK*) pChannelCallback;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin;
        RdpgfxClientContext* context = (RdpgfxClientContext*) gfx->iface.pInterface;
-
        WLog_DBG(TAG, "OnClose");
-
        free(callback);
-
        gfx->UnacknowledgedFrames = 0;
        gfx->TotalDecodedFrames = 0;
 
@@ -1254,7 +1293,6 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
        for (index = 0; index < count; index++)
        {
                RDPGFX_DELETE_SURFACE_PDU pdu;
-
                pdu.surfaceId = ((UINT16) pKeys[index]) - 1;
 
                if (context && context->DeleteSurface)
@@ -1270,7 +1308,6 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
                if (gfx->CacheSlots[index])
                {
                        RDPGFX_EVICT_CACHE_ENTRY_PDU pdu;
-
                        pdu.cacheSlot = (UINT16) index;
 
                        if (context && context->EvictCacheEntry)
@@ -1290,14 +1327,16 @@ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
-       IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept,
-       IWTSVirtualChannelCallback** ppCallback)
+static UINT rdpgfx_on_new_channel_connection(IWTSListenerCallback*
+        pListenerCallback,
+        IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept,
+        IWTSVirtualChannelCallback** ppCallback)
 {
        RDPGFX_CHANNEL_CALLBACK* callback;
-       RDPGFX_LISTENER_CALLBACK* listener_callback = (RDPGFX_LISTENER_CALLBACK*) pListenerCallback;
-
-       callback = (RDPGFX_CHANNEL_CALLBACK*) calloc(1, sizeof(RDPGFX_CHANNEL_CALLBACK));
+       RDPGFX_LISTENER_CALLBACK* listener_callback = (RDPGFX_LISTENER_CALLBACK*)
+               pListenerCallback;
+       callback = (RDPGFX_CHANNEL_CALLBACK*) calloc(1,
+                  sizeof(RDPGFX_CHANNEL_CALLBACK));
 
        if (!callback)
        {
@@ -1312,9 +1351,7 @@ static UINT rdpgfx_on_new_channel_connection(IWTSListenerCallback* pListenerCall
        callback->channel_mgr = listener_callback->channel_mgr;
        callback->channel = pChannel;
        listener_callback->channel_callback = callback;
-
        *ppCallback = (IWTSVirtualChannelCallback*) callback;
-
        return CHANNEL_RC_OK;
 }
 
@@ -1323,12 +1360,13 @@ static UINT rdpgfx_on_new_channel_connection(IWTSListenerCallback* pListenerCall
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
+static UINT rdpgfx_plugin_initialize(IWTSPlugin* pPlugin,
+                                     IWTSVirtualChannelManager* pChannelMgr)
 {
        UINT error;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) pPlugin;
-
-       gfx->listener_callback = (RDPGFX_LISTENER_CALLBACK*) calloc(1, sizeof(RDPGFX_LISTENER_CALLBACK));
+       gfx->listener_callback = (RDPGFX_LISTENER_CALLBACK*) calloc(1,
+                                sizeof(RDPGFX_LISTENER_CALLBACK));
 
        if (!gfx->listener_callback)
        {
@@ -1336,17 +1374,14 @@ static UINT rdpgfx_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelMana
                return CHANNEL_RC_NO_MEMORY;
        }
 
-       gfx->listener_callback->iface.OnNewChannelConnection = rdpgfx_on_new_channel_connection;
+       gfx->listener_callback->iface.OnNewChannelConnection =
+           rdpgfx_on_new_channel_connection;
        gfx->listener_callback->plugin = pPlugin;
        gfx->listener_callback->channel_mgr = pChannelMgr;
-
        error = pChannelMgr->CreateListener(pChannelMgr, RDPGFX_DVC_CHANNEL_NAME, 0,
-               (IWTSListenerCallback*) gfx->listener_callback, &(gfx->listener));
-
+                                           (IWTSListenerCallback*) gfx->listener_callback, &(gfx->listener));
        gfx->listener->pInterface = gfx->iface.pInterface;
-
        WLog_DBG(TAG, "Initialize");
-
        return error;
 }
 
@@ -1363,7 +1398,6 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) pPlugin;
        RdpgfxClientContext* context = (RdpgfxClientContext*) gfx->iface.pInterface;
        UINT error = CHANNEL_RC_OK;
-
        WLog_DBG(TAG, "Terminated");
 
        if (gfx->listener_callback)
@@ -1383,12 +1417,12 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
        for (index = 0; index < count; index++)
        {
                RDPGFX_DELETE_SURFACE_PDU pdu;
-
                pdu.surfaceId = ((UINT16) pKeys[index]) - 1;
 
                if (context)
                {
                        IFCALLRET(context->DeleteSurface, error, context, &pdu);
+
                        if (error)
                        {
                                WLog_ERR(TAG, "context->DeleteSurface failed with error %lu", error);
@@ -1401,7 +1435,6 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
        }
 
        free(pKeys);
-
        HashTable_Free(gfx->SurfaceTable);
 
        for (index = 0; index < gfx->MaxCacheSlot; index++)
@@ -1409,12 +1442,12 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
                if (gfx->CacheSlots[index])
                {
                        RDPGFX_EVICT_CACHE_ENTRY_PDU pdu;
-
                        pdu.cacheSlot = (UINT16) index;
 
                        if (context)
                        {
                                IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
+
                                if (error)
                                {
                                        WLog_ERR(TAG, "context->EvictCacheEntry failed with error %lu", error);
@@ -1429,9 +1462,7 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
        }
 
        free(context);
-
        free(gfx);
-
        return CHANNEL_RC_OK;
 }
 
@@ -1440,11 +1471,11 @@ static UINT rdpgfx_plugin_terminated(IWTSPlugin* pPlugin)
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId, void* pData)
+static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context,
+                                    UINT16 surfaceId, void* pData)
 {
        ULONG_PTR key;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) context->handle;
-
        key = ((ULONG_PTR) surfaceId) + 1;
 
        if (pData)
@@ -1460,14 +1491,14 @@ static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surface
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds, UINT16* count_out)
+static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context,
+                                   UINT16** ppSurfaceIds, UINT16* count_out)
 {
        int count;
        int index;
        UINT16* pSurfaceIds;
        ULONG_PTR* pKeys = NULL;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) context->handle;
-
        count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys);
 
        if (count < 1)
@@ -1492,20 +1523,17 @@ static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurf
        free(pKeys);
        *ppSurfaceIds = pSurfaceIds;
        *count_out = (UINT16)count;
-
        return CHANNEL_RC_OK;
 }
 
-static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId)
+static void* rdpgfx_get_surface_data(RdpgfxClientContext* context,
+                                     UINT16 surfaceId)
 {
        ULONG_PTR key;
        void* pData = NULL;
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) context->handle;
-
        key = ((ULONG_PTR) surfaceId) + 1;
-
        pData = HashTable_GetItemValue(gfx->SurfaceTable, (void*) key);
-
        return pData;
 }
 
@@ -1514,7 +1542,8 @@ static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfac
  *
  * @return 0 on success, otherwise a Win32 error code
  */
-static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot, void* pData)
+static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context,
+                                       UINT16 cacheSlot, void* pData)
 {
        RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) context->handle;
 
@@ -1522,7 +1551,6 @@ static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cach
                return ERROR_INVALID_INDEX;
 
        gfx->CacheSlots[cacheSlot] = pData;
-
        return CHANNEL_RC_OK;
 }
 
@@ -1535,7 +1563,6 @@ void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot)
                return NULL;
 
        pData = gfx->CacheSlots[cacheSlot];
-
        return pData;
 }
 
@@ -1555,7 +1582,6 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
        UINT error = CHANNEL_RC_OK;
        RDPGFX_PLUGIN* gfx;
        RdpgfxClientContext* context;
-
        gfx = (RDPGFX_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpgfx");
 
        if (!gfx)
@@ -1569,17 +1595,15 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
                }
 
                gfx->settings = (rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints);
-
                gfx->iface.Initialize = rdpgfx_plugin_initialize;
                gfx->iface.Connected = NULL;
                gfx->iface.Disconnected = NULL;
                gfx->iface.Terminated = rdpgfx_plugin_terminated;
-
                gfx->SurfaceTable = HashTable_New(TRUE);
 
                if (!gfx->SurfaceTable)
                {
-                       free (gfx);
+                       free(gfx);
                        WLog_ERR(TAG, "HashTable_New failed!");
                        return CHANNEL_RC_NO_MEMORY;
                }
@@ -1598,7 +1622,6 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
                        gfx->ThinClient = FALSE;
 
                gfx->MaxCacheSlot = (gfx->ThinClient) ? 4096 : 25600;
-
                context = (RdpgfxClientContext*) calloc(1, sizeof(RdpgfxClientContext));
 
                if (!context)
@@ -1609,15 +1632,12 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
                }
 
                context->handle = (void*) gfx;
-
                context->GetSurfaceIds = rdpgfx_get_surface_ids;
                context->SetSurfaceData = rdpgfx_set_surface_data;
                context->GetSurfaceData = rdpgfx_get_surface_data;
                context->SetCacheSlotData = rdpgfx_set_cache_slot_data;
                context->GetCacheSlotData = rdpgfx_get_cache_slot_data;
-
                gfx->iface.pInterface = (void*) context;
-
                gfx->zgfx = zgfx_context_new(FALSE);
 
                if (!gfx->zgfx)