OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Session class that handles creation and teardown of a remoting session. | 7 * Session class that handles creation and teardown of a remoting session. |
8 * | 8 * |
9 * This abstracts a <embed> element and controls the plugin which does the | 9 * This abstracts a <embed> element and controls the plugin which does the |
10 * actual remoting work. There should be no UI code inside this class. It | 10 * actual remoting work. There should be no UI code inside this class. It |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 }; | 360 }; |
361 | 361 |
362 /** | 362 /** |
363 * Informs the plugin that it should scale itself. | 363 * Informs the plugin that it should scale itself. |
364 * | 364 * |
365 * @param {boolean} shouldScale If the plugin should scale itself. | 365 * @param {boolean} shouldScale If the plugin should scale itself. |
366 * @return {void} Nothing. | 366 * @return {void} Nothing. |
367 */ | 367 */ |
368 remoting.ClientSession.prototype.toggleScaleToFit = function(shouldScale) { | 368 remoting.ClientSession.prototype.toggleScaleToFit = function(shouldScale) { |
369 if (shouldScale) { | 369 if (shouldScale) { |
370 remoting.debug.log('scale to fit is turned on.'); | |
371 | |
372 if (this.plugin.desktopWidth == 0 || | 370 if (this.plugin.desktopWidth == 0 || |
373 this.plugin.desktopHeight == 0) { | 371 this.plugin.desktopHeight == 0) { |
374 remoting.debug.log('desktop size is not known yet.'); | 372 remoting.debug.log('desktop size is not known yet.'); |
375 return; | 373 return; |
376 } | 374 } |
377 | 375 |
378 // Make sure both width and height are multiples of two. | 376 // Make sure both width and height are multiples of two. |
379 var width = window.innerWidth; | 377 var width = window.innerWidth; |
380 var height = window.innerHeight; | 378 var height = window.innerHeight; |
381 if (width % 2 == 1) | 379 if (width % 2 == 1) |
382 --width; | 380 --width; |
383 if (height % 2 == 1) | 381 if (height % 2 == 1) |
384 --height; | 382 --height; |
385 | 383 |
386 var scale = 1.0; | 384 var scaleFitHeight = 1.0 * height / this.plugin.desktopHeight; |
387 if (width < height) | 385 var scaleFitWidth = 1.0 * width / this.plugin.desktopWidth; |
Jamie
2011/08/13 02:24:51
I'd be tempted to guard against either width or he
Lambros
2011/08/15 20:03:45
Already covered by line 370, I think?
| |
388 scale = 1.0 * height / this.plugin.desktopHeight; | 386 var scale = Math.min(scaleFitHeight, scaleFitWidth); |
389 else | |
390 scale = 1.0 * width / this.plugin.desktopWidth; | |
391 | |
392 if (scale > 1.0) { | 387 if (scale > 1.0) { |
393 remoting.debug.log('scale up is not supported'); | 388 remoting.debug.log('scale up is not supported'); |
394 return; | 389 scale = 1.0; |
395 } | 390 } |
396 | 391 |
397 this.plugin.width = this.plugin.desktopWidth * scale; | 392 this.plugin.width = this.plugin.desktopWidth * scale; |
398 this.plugin.height = this.plugin.desktopHeight * scale; | 393 this.plugin.height = this.plugin.desktopHeight * scale; |
399 } else { | 394 } else { |
400 remoting.debug.log('scale to fit is turned off.'); | |
401 this.plugin.width = this.plugin.desktopWidth; | 395 this.plugin.width = this.plugin.desktopWidth; |
402 this.plugin.height = this.plugin.desktopHeight; | 396 this.plugin.height = this.plugin.desktopHeight; |
403 } | 397 } |
404 remoting.debug.log('plugin size is now: ' + | 398 remoting.debug.log('plugin size is now: ' + |
405 this.plugin.width + ' x ' + this.plugin.height + '.'); | 399 this.plugin.width + ' x ' + this.plugin.height + '.'); |
406 this.plugin.setScaleToFit(shouldScale); | 400 this.plugin.setScaleToFit(shouldScale); |
401 remoting.debug.log('scale to fit is now: ' + shouldScale); | |
407 }; | 402 }; |
408 | 403 |
409 /** | 404 /** |
410 * Returns an associative array with a set of stats for this connection. | 405 * Returns an associative array with a set of stats for this connection. |
411 * | 406 * |
412 * @return {Object} The connection statistics. | 407 * @return {Object} The connection statistics. |
413 */ | 408 */ |
414 remoting.ClientSession.prototype.stats = function() { | 409 remoting.ClientSession.prototype.stats = function() { |
415 return { | 410 return { |
416 'video_bandwidth': this.plugin.videoBandwidth, | 411 'video_bandwidth': this.plugin.videoBandwidth, |
417 'capture_latency': this.plugin.videoCaptureLatency, | 412 'capture_latency': this.plugin.videoCaptureLatency, |
418 'encode_latency': this.plugin.videoEncodeLatency, | 413 'encode_latency': this.plugin.videoEncodeLatency, |
419 'decode_latency': this.plugin.videoDecodeLatency, | 414 'decode_latency': this.plugin.videoDecodeLatency, |
420 'render_latency': this.plugin.videoRenderLatency, | 415 'render_latency': this.plugin.videoRenderLatency, |
421 'roundtrip_latency': this.plugin.roundTripLatency | 416 'roundtrip_latency': this.plugin.roundTripLatency |
422 }; | 417 }; |
423 }; | 418 }; |
424 | 419 |
425 }()); | 420 }()); |
OLD | NEW |