]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Merge resize handling to single method
authorPierre Ossman <ossman@cendio.se>
Thu, 7 Sep 2017 14:51:04 +0000 (16:51 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 7 Sep 2017 15:18:25 +0000 (17:18 +0200)
It also fits better in the core RFB object rather than as a helper
for the encoding handlers.

core/rfb.js
tests/test.rfb.js

index ece0f00813034be45561646eaf3b47bf38da3c6d..57f3a8e50e65e1a01de5d0c3f578b0d4ff076c24 100644 (file)
@@ -1020,9 +1020,8 @@ RFB.prototype = {
         if (this._sock.rQwait("server initialization", 24)) { return false; }
 
         /* Screen size */
-        this._fb_width  = this._sock.rQshift16();
-        this._fb_height = this._sock.rQshift16();
-        this._destBuff = new Uint8Array(this._fb_width * this._fb_height * 4);
+        var width = this._sock.rQshift16();
+        var height = this._sock.rQshift16();
 
         /* PIXEL_FORMAT */
         var bpp         = this._sock.rQshift8();
@@ -1072,7 +1071,7 @@ RFB.prototype = {
 
         // NB(directxman12): these are down here so that we don't run them multiple times
         //                   if we backtrack
-        Log.Info("Screen: " + this._fb_width + "x" + this._fb_height +
+        Log.Info("Screen: " + width + "x" + height +
                   ", bpp: " + bpp + ", depth: " + depth +
                   ", big_endian: " + big_endian +
                   ", true_color: " + true_color +
@@ -1098,8 +1097,7 @@ RFB.prototype = {
         // we're past the point where we could backtrack, so it's safe to call this
         this._onDesktopName(this, this._fb_name);
 
-        this._display.resize(this._fb_width, this._fb_height);
-        this._onFBResize(this, this._fb_width, this._fb_height);
+        this._resize(width, height);
 
         if (!this._view_only) { this._keyboard.grab(); }
         if (!this._view_only) { this._mouse.grab(); }
@@ -1417,6 +1415,19 @@ RFB.prototype = {
 
         RFB.messages.enableContinuousUpdates(this._sock, true, 0, 0,
                                              this._fb_width, this._fb_height);
+    },
+
+    _resize: function(width, height) {
+        this._fb_width = width;
+        this._fb_height = height;
+
+        this._destBuff = new Uint8Array(this._fb_width * this._fb_height * 4);
+
+        this._display.resize(this._fb_width, this._fb_height);
+        this._onFBResize(this, this._fb_width, this._fb_height);
+
+        this._timing.fbu_rt_start = (new Date()).getTime();
+        this._updateContinuousUpdates();
     }
 };
 
@@ -2294,20 +2305,6 @@ RFB.encodingHandlers = {
         return true;
     },
 
-    handle_FB_resize: function () {
-        this._fb_width = this._FBU.width;
-        this._fb_height = this._FBU.height;
-        this._destBuff = new Uint8Array(this._fb_width * this._fb_height * 4);
-        this._display.resize(this._fb_width, this._fb_height);
-        this._onFBResize(this, this._fb_width, this._fb_height);
-        this._timing.fbu_rt_start = (new Date()).getTime();
-        this._updateContinuousUpdates();
-
-        this._FBU.bytes = 0;
-        this._FBU.rects -= 1;
-        return true;
-    },
-
     ExtendedDesktopSize: function () {
         this._FBU.bytes = 1;
         if (this._sock.rQwait("ExtendedDesktopSize", this._FBU.bytes)) { return false; }
@@ -2366,12 +2363,16 @@ RFB.encodingHandlers = {
             return true;
         }
 
-        this._encHandlers.handle_FB_resize();
+        this._resize(this._FBU.width, this._FBU.height);
+        this._FBU.bytes = 0;
+        this._FBU.rects -= 1;
         return true;
     },
 
     DesktopSize: function () {
-        this._encHandlers.handle_FB_resize();
+        this._resize(this._FBU.width, this._FBU.height);
+        this._FBU.bytes = 0;
+        this._FBU.rects -= 1;
         return true;
     },
 
index 99b93b5759efb143bda5816d461eefb028f27cfb..b9e7cd66abe8ec3bd2d8d46c66c02498523745cf 100644 (file)
@@ -1845,19 +1845,13 @@ describe('Remote Frame Buffer Protocol Client', function() {
             var expected_msg = {_sQ: new Uint8Array(10), _sQlen: 0, flush: function() {}};
             RFB.messages.enableContinuousUpdates(expected_msg, true, 0, 0, 90, 700);
 
-            client._FBU.width = 450;
-            client._FBU.height = 160;
-
-            client._encHandlers.handle_FB_resize();
+            client._resize(450, 160);
 
             expect(client._sock._websocket._get_sent_data()).to.have.length(0);
 
             client._enabledContinuousUpdates = true;
 
-            client._FBU.width = 90;
-            client._FBU.height = 700;
-
-            client._encHandlers.handle_FB_resize();
+            client._resize(90, 700);
 
             expect(client._sock).to.have.sent(expected_msg._sQ);
         });