]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/decoders/hextile.js
Move tile handling to Hextile decoder
[mirror_novnc.git] / core / decoders / hextile.js
index 8dbe809222c707d5aac380857ec73f18eedc6a96..f12e7f6a09b928232abd7bcd590eba7453d0527f 100644 (file)
@@ -13,6 +13,7 @@ export default class HextileDecoder {
     constructor() {
         this._tiles = 0;
         this._lastsubencoding = 0;
+        this._tileBuffer = new Uint8Array(16 * 16 * 4);
     }
 
     decodeRect(x, y, width, height, sock, display, depth) {
@@ -99,7 +100,7 @@ export default class HextileDecoder {
                     rQi += 4;
                 }
 
-                display.startTile(tx, ty, tw, th, this._background);
+                this._startTile(tx, ty, tw, th, this._background);
                 if (subencoding & 0x08) {  // AnySubrects
                     let subrects = rQ[rQi];
                     rQi++;
@@ -122,10 +123,10 @@ export default class HextileDecoder {
                         const sw = (wh >> 4) + 1;
                         const sh = (wh & 0x0f) + 1;
 
-                        display.subTile(sx, sy, sw, sh, color);
+                        this._subTile(sx, sy, sw, sh, color);
                     }
                 }
-                display.finishTile();
+                this._finishTile(display);
             }
             sock.rQi = rQi;
             this._lastsubencoding = subencoding;
@@ -134,4 +135,52 @@ export default class HextileDecoder {
 
         return true;
     }
+
+    // start updating a tile
+    _startTile(x, y, width, height, color) {
+        this._tileX = x;
+        this._tileY = y;
+        this._tileW = width;
+        this._tileH = height;
+
+        const red = color[2];
+        const green = color[1];
+        const blue = color[0];
+
+        const data = this._tileBuffer;
+        for (let i = 0; i < width * height * 4; i += 4) {
+            data[i]     = blue;
+            data[i + 1] = green;
+            data[i + 2] = red;
+            data[i + 3] = 255;
+        }
+    }
+
+    // update sub-rectangle of the current tile
+    _subTile(x, y, w, h, color) {
+        const red = color[2];
+        const green = color[1];
+        const blue = color[0];
+        const xend = x + w;
+        const yend = y + h;
+
+        const data = this._tileBuffer;
+        const width = this._tileW;
+        for (let j = y; j < yend; j++) {
+            for (let i = x; i < xend; i++) {
+                const p = (i + (j * width)) * 4;
+                data[p]     = blue;
+                data[p + 1] = green;
+                data[p + 2] = red;
+                data[p + 3] = 255;
+            }
+        }
+    }
+
+    // draw the current tile to the screen
+    _finishTile(display) {
+        display.blitImage(this._tileX, this._tileY,
+                          this._tileW, this._tileH,
+                          this._tileBuffer, 0);
+    }
 }