Commit fb99d81c authored by Joel Martin's avatar Joel Martin

Better hextile performance: index subrects instead of slicing/shifting.

- Many times better performance. Before this, browser was spending all
  it's time garbage collecting or doing something. Now the bottleneck
  is in set fillStyle and fillRect which is probably where it should
  be.
parent 410960ba
...@@ -227,7 +227,7 @@ init_msg: function () { ...@@ -227,7 +227,7 @@ init_msg: function () {
display_raw: function () { display_raw: function () {
console.log(">> display_raw"); console.log(">> display_raw");
Canvas.rfbImage(FBU.x, FBU.y, FBU.width, FBU.height, RFB.d); Canvas.rfbImage(FBU.x, FBU.y, FBU.width, FBU.height, RFB.d);
RFB.d.splice(0, FBU.width * FBU.height * RFB.fb_Bpp); RFB.d.shiftBytes(FBU.width * FBU.height * RFB.fb_Bpp);
FBU.rects --; FBU.rects --;
}, },
...@@ -331,6 +331,7 @@ display_hextile: function() { ...@@ -331,6 +331,7 @@ display_hextile: function() {
if (subencoding > -1) { if (subencoding > -1) {
/* We know the encoding and have a whole tile */ /* We know the encoding and have a whole tile */
FBU.subencoding = RFB.d.shift8(); FBU.subencoding = RFB.d.shift8();
FBU.bytes--;
if (FBU.subencoding == 0) { if (FBU.subencoding == 0) {
if (FBU.lastsubencoding & 0x01) { if (FBU.lastsubencoding & 0x01) {
/* Weird: ignore blanks after RAW */ /* Weird: ignore blanks after RAW */
...@@ -343,37 +344,45 @@ display_hextile: function() { ...@@ -343,37 +344,45 @@ display_hextile: function() {
} }
} else if (FBU.subencoding & 0x01) { // Raw } else if (FBU.subencoding & 0x01) { // Raw
Canvas.rfbImage(x, y, w, h, RFB.d); Canvas.rfbImage(x, y, w, h, RFB.d);
RFB.d.splice(0, FBU.bytes - 1);
} else { } else {
var idx = 0;
if (FBU.subencoding & 0x02) { // Background if (FBU.subencoding & 0x02) { // Background
FBU.background = RFB.d.shiftBytes(RFB.fb_Bpp); FBU.background = RFB.d.slice(idx, idx + RFB.fb_Bpp);
idx += RFB.fb_Bpp;
//console.log(" background: " + FBU.background); //console.log(" background: " + FBU.background);
} }
if (FBU.subencoding & 0x04) { // Foreground if (FBU.subencoding & 0x04) { // Foreground
FBU.foreground = RFB.d.shiftBytes(RFB.fb_Bpp); FBU.foreground = RFB.d.slice(idx, idx + RFB.fb_Bpp);
idx += RFB.fb_Bpp;
//console.log(" foreground: " + FBU.foreground); //console.log(" foreground: " + FBU.foreground);
} }
Canvas.rfbRect(x, y, w, h, FBU.background); Canvas.rfbRect(x, y, w, h, FBU.background);
if (FBU.subencoding & 0x08) { // AnySubrects if (FBU.subencoding & 0x08) { // AnySubrects
subrects = RFB.d.shift8(); subrects = RFB.d[idx];
idx++;
var color, xy, sx, sy, wh, sw, sh;
for (var i = 0; i < subrects; i ++) { for (var i = 0; i < subrects; i ++) {
if (FBU.subencoding & 0x10) { // SubrectsColoured if (FBU.subencoding & 0x10) { // SubrectsColoured
var color = RFB.d.shiftBytes(RFB.fb_Bpp); color = RFB.d.slice(idx, idx + RFB.fb_Bpp);
idx += RFB.fb_Bpp;
} else { } else {
var color = FBU.foreground; color = FBU.foreground;
} }
var xy = RFB.d.shift8(); xy = RFB.d[idx];
var sx = x + (xy >> 4); idx++;
var sy = y + (xy & 0x0f); sx = x + (xy >> 4);
sy = y + (xy & 0x0f);
var wh = RFB.d.shift8(); wh = RFB.d[idx];
var sw = (wh >> 4) + 1; idx++;
var sh = (wh & 0x0f) + 1; sw = (wh >> 4) + 1;
sh = (wh & 0x0f) + 1;
Canvas.rfbRect(sx, sy, sw, sh, color); Canvas.rfbRect(sx, sy, sw, sh, color);
} }
} }
} }
if (FBU.bytes > 0) RFB.d.shiftBytes(FBU.bytes);
FBU.lastsubencoding = FBU.subencoding; FBU.lastsubencoding = FBU.subencoding;
FBU.subencoding = -1; FBU.subencoding = -1;
FBU.tiles --; FBU.tiles --;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment