From 48ebcdb1104362840560e8b65034208c9f6ef72a Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 14 Apr 2010 12:22:47 -0500 Subject: [PATCH] Rename canvas.js routines to not have "rfb" prefix. - Also, try making set fillStyle called less often. --- canvas.js | 14 +++++++++++--- vnc.js | 14 +++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/canvas.js b/canvas.js index cbf571b3..51f76411 100644 --- a/canvas.js +++ b/canvas.js @@ -6,6 +6,8 @@ c_wx : 0, c_wy : 0, ctx : null, +prevStyle: "", + mouseDown: function (e) { var evt = e.event || window.event; e.stop(); @@ -70,6 +72,8 @@ init: function (id, width, height, keyDown, keyUp, mouseDown, mouseUp) { if (! c.getContext) return; Canvas.ctx = c.getContext('2d'); + + Canvas.prevStyle = ""; console.log("<< init_canvas"); }, @@ -119,7 +123,7 @@ draw: function () { Canvas.ctx.putImageData(img, 100, 100); }, -rfbImage: function(x, y, width, height, arr) { +rgbxImage: function(x, y, width, height, arr) { var img = Canvas.ctx.createImageData(width, height); for (var i=0; i < (width * height); i++) { img.data[i*4 + 0] = arr[i*4 + 0]; @@ -131,8 +135,12 @@ rfbImage: function(x, y, width, height, arr) { }, -rfbRect: function(x, y, width, height, color) { - Canvas.ctx.fillStyle = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")"; +fillRect: function(x, y, width, height, color) { + var newStyle = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")"; + if (newStyle != Canvas.prevStyle) { + Canvas.ctx.fillStyle = newStyle; + prevStyle = newStyle; + } Canvas.ctx.fillRect(x, y, width, height); }, diff --git a/vnc.js b/vnc.js index 1f99126a..b5167ff8 100644 --- a/vnc.js +++ b/vnc.js @@ -338,7 +338,7 @@ normal_msg: function () { display_raw: function () { console.log(">> display_raw"); - Canvas.rfbImage(FBU.x, FBU.y, FBU.width, FBU.height, RFB.d); + Canvas.rgbxImage(FBU.x, FBU.y, FBU.width, FBU.height, RFB.d); RFB.d.shiftBytes(FBU.width * FBU.height * RFB.fb_Bpp); FBU.rects --; }, @@ -357,7 +357,7 @@ display_rre: function () { FBU.subrects = RFB.d.shift32(); console.log(">> display_rre " + "(" + FBU.subrects + " subrects)"); var color = RFB.d.shiftBytes(RFB.fb_Bpp); // Background - Canvas.rfbRect(FBU.x, FBU.y, FBU.width, FBU.height, color); + Canvas.fillRect(FBU.x, FBU.y, FBU.width, FBU.height, color); } while ((FBU.subrects > 0) && (RFB.d.length >= (RFB.fb_Bpp + 8))) { FBU.subrects --; @@ -366,7 +366,7 @@ display_rre: function () { var y = RFB.d.shift16(); var width = RFB.d.shift16(); var height = RFB.d.shift16(); - Canvas.rfbRect(FBU.x + x, FBU.y + y, width, height, color); + Canvas.fillRect(FBU.x + x, FBU.y + y, width, height, color); } //console.log(" display_rre: rects: " + FBU.rects + ", FBU.subrects: " + FBU.subrects); @@ -452,10 +452,10 @@ display_hextile: function() { //FBU.lastsubencoding = 0; continue; } else { - Canvas.rfbRect(x, y, w, h, FBU.background); + Canvas.fillRect(x, y, w, h, FBU.background); } } else if (FBU.subencoding & 0x01) { // Raw - Canvas.rfbImage(x, y, w, h, RFB.d); + Canvas.rgbxImage(x, y, w, h, RFB.d); } else { var idx = 0; if (FBU.subencoding & 0x02) { // Background @@ -468,7 +468,7 @@ display_hextile: function() { idx += RFB.fb_Bpp; //console.log(" foreground: " + FBU.foreground); } - Canvas.rfbRect(x, y, w, h, FBU.background); + Canvas.fillRect(x, y, w, h, FBU.background); if (FBU.subencoding & 0x08) { // AnySubrects subrects = RFB.d[idx]; idx++; @@ -490,7 +490,7 @@ display_hextile: function() { sw = (wh >> 4) + 1; sh = (wh & 0x0f) + 1; - Canvas.rfbRect(sx, sy, sw, sh, color); + Canvas.fillRect(sx, sy, sw, sh, color); } } }