Merge resize handling to single method

It also fits better in the core RFB object rather than as a helper
for the encoding handlers.
This commit is contained in:
Pierre Ossman 2017-09-07 16:51:04 +02:00
parent 1678bf860f
commit 91d5c62589
2 changed files with 25 additions and 30 deletions

View 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;
},

View 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);
});