From a6e52f9a73a6c4f7e46e1ba463b532f4b459fad9 Mon Sep 17 00:00:00 2001 From: Pierre Ossman <ossman@cendio.se> Date: Fri, 3 Feb 2017 11:56:02 +0100 Subject: [PATCH] Merge display scale changes --- core/display.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/core/display.js b/core/display.js index ac2e1e5..5eab796 100644 --- a/core/display.js +++ b/core/display.js @@ -573,37 +573,22 @@ }, autoscale: function (containerWidth, containerHeight, downscaleOnly) { + var vp = this._viewportLoc; var targetAspectRatio = containerWidth / containerHeight; - var fbAspectRatio = this._fb_width / this._fb_height; + var fbAspectRatio = vp.w / vp.h; var scaleRatio; if (fbAspectRatio >= targetAspectRatio) { - scaleRatio = containerWidth / this._fb_width; + scaleRatio = containerWidth / vp.w; } else { - scaleRatio = containerHeight / this._fb_height; + scaleRatio = containerHeight / vp.h; } - var targetW, targetH; if (scaleRatio > 1.0 && downscaleOnly) { - targetW = this._fb_width; - targetH = this._fb_height; scaleRatio = 1.0; - } else if (fbAspectRatio >= targetAspectRatio) { - targetW = containerWidth; - targetH = Math.round(containerWidth / fbAspectRatio); - } else { - targetW = Math.round(containerHeight * fbAspectRatio); - targetH = containerHeight; } - // NB(directxman12): If you set the width directly, or set the - // style width to a number, the canvas is cleared. - // However, if you set the style width to a string - // ('NNNpx'), the canvas is scaled without clearing. - this._target.style.width = targetW + 'px'; - this._target.style.height = targetH + 'px'; - - this._scale = scaleRatio; + this._rescale(scaleRatio); return scaleRatio; // so that the mouse, etc scale can be set }, @@ -612,6 +597,11 @@ _rescale: function (factor) { this._scale = factor; var vp = this._viewportLoc; + + // NB(directxman12): If you set the width directly, or set the + // style width to a number, the canvas is cleared. + // However, if you set the style width to a string + // ('NNNpx'), the canvas is scaled without clearing. this._target.style.width = Math.round(factor * vp.w) + 'px'; this._target.style.height = Math.round(factor * vp.h) + 'px'; }, -- GitLab