Use transfer, not copy.
[libguac-client-rdp.git] / src / rdp_gdi.c
index 1b65574..0b1300e 100644 (file)
 #include "client.h"
 #include "rdp_bitmap.h"
 
+guac_transfer_function guac_rdp_rop3_transfer_function(guac_client* client,
+        int rop3) {
+
+    /* Translate supported ROP3 opcodes into composite modes */
+    switch (rop3) {
+
+        /* "SRCINVERT" (src ^ dest) */
+        case 0x66: return GUAC_TRANSFER_BINARY_SRC;
+
+        /* "SRCAND" (src & dest) */
+        case 0x88: return GUAC_TRANSFER_BINARY_AND;
+
+        /* "MERGEPAINT" !(src | dest)*/
+        case 0xBB: return GUAC_TRANSFER_BINARY_NOR;
+
+        /* "SRCCOPY" (src) */
+        case 0xCC: return GUAC_TRANSFER_BINARY_SRC;
+
+        /* "SRCPAINT" (src | dest) */
+        case 0xEE: return GUAC_TRANSFER_BINARY_OR;
+
+    }
+
+    /* Log warning if ROP3 opcode not supported */
+    guac_client_log_info (client, "guac_rdp_rop3_transfer_function: "
+            "UNSUPPORTED opcode = 0x%02X", rop3);
+
+    /* Default to BINARY_SRC */
+    return GUAC_TRANSFER_BINARY_SRC;
+
+}
+
 void guac_rdp_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) {
 
     guac_client* client = ((rdp_freerdp_context*) context)->client;
@@ -97,25 +129,28 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) {
     guac_socket* socket = client->socket;
     guac_rdp_bitmap* bitmap = (guac_rdp_bitmap*) memblt->bitmap;
 
-    guac_composite_mode cmode = GUAC_COMP_OVER;
+    if (bitmap->layer != NULL) {
+
+        /* If operation is just SRC, simply copy */
+        if (memblt->bRop == 0xCC)
+            guac_protocol_send_copy(socket,
+                    bitmap->layer,
+                    memblt->nXSrc, memblt->nYSrc,
+                    memblt->nWidth, memblt->nHeight,
+                    GUAC_COMP_OVER,
+                    current_layer, memblt->nLeftRect, memblt->nTopRect);
+
+        /* Otherwise, use transfer */
+        else
+            guac_protocol_send_transfer(socket,
+                    bitmap->layer,
+                    memblt->nXSrc, memblt->nYSrc,
+                    memblt->nWidth, memblt->nHeight,
+                    guac_rdp_rop3_transfer_function(client, memblt->bRop),
+                    current_layer, memblt->nLeftRect, memblt->nTopRect);
 
-    if (memblt->bRop == 204) cmode = GUAC_COMP_OVER;
-    else if (memblt->bRop == 238) cmode = GUAC_COMP_OR;
-    else if (memblt->bRop == 136) cmode = GUAC_COMP_AND;
-    else if (memblt->bRop == 102) cmode = GUAC_COMP_XOR2;
-    else if (memblt->bRop == 187) cmode = GUAC_COMP_NOR;
-    else
-    {
-        guac_client_log_info (client, "guac_rdp_gdi_memblt: UNSUPPORTED opcode = %d (0x%02X)", memblt->bRop, memblt->bRop);
     }
 
-    if (bitmap->layer != NULL)
-        guac_protocol_send_copy(socket,
-                bitmap->layer,
-                memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight,
-                cmode,
-                current_layer, memblt->nLeftRect, memblt->nTopRect);
-
 }
 
 void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) {