Chromium Code Reviews| Index: Source/devtools/front_end/ScreencastView.js |
| diff --git a/Source/devtools/front_end/ScreencastView.js b/Source/devtools/front_end/ScreencastView.js |
| index 3344a14fa7a0e4fd710194dd44f2a423134705e7..397f82b223c77c25ccecc03bcba818dafaebb09d 100644 |
| --- a/Source/devtools/front_end/ScreencastView.js |
| +++ b/Source/devtools/front_end/ScreencastView.js |
| @@ -123,14 +123,14 @@ WebInspector.ScreencastView.prototype = { |
| return; |
| this._isCasting = true; |
| - const maxImageDimension = 1024; |
| + const maxImageDimension = 2048; |
| var dimensions = this._viewportDimensions(); |
| if (dimensions.width < 0 || dimensions.height < 0) { |
| this._isCasting = false; |
| return; |
| } |
| - dimensions.width *= WebInspector.zoomManager.zoomFactor(); |
| - dimensions.height *= WebInspector.zoomManager.zoomFactor(); |
| + dimensions.width *= WebInspector.zoomManager.zoomFactor() * window.devicePixelRatio; |
|
dgozman
2014/06/25 13:31:35
window.devicePixelRatio already includes zoom fact
vkuzkokov
2014/06/25 17:56:58
Done.
|
| + dimensions.height *= WebInspector.zoomManager.zoomFactor() * window.devicePixelRatio; |
| this._target.pageAgent().startScreencast("jpeg", 80, Math.min(maxImageDimension, dimensions.width), Math.min(maxImageDimension, dimensions.height)); |
| this._target.domModel.setHighlighter(this); |
| }, |
| @@ -150,28 +150,33 @@ WebInspector.ScreencastView.prototype = { |
| _screencastFrame: function(event) |
| { |
| var metadata = /** type {PageAgent.ScreencastFrameMetadata} */(event.data.metadata); |
| - |
| - if (!metadata.deviceScaleFactor) { |
| - console.log(event.data.data); |
| - return; |
| - } |
| - |
| var base64Data = /** type {string} */(event.data.data); |
| this._imageElement.src = "data:image/jpg;base64," + base64Data; |
| this._deviceScaleFactor = metadata.deviceScaleFactor; |
| this._pageScaleFactor = metadata.pageScaleFactor; |
| - this._viewport = metadata.viewport; |
| + this._viewport = metadata.viewport |
| if (!this._viewport) |
| return; |
| - var offsetTop = metadata.offsetTop || 0; |
| - var offsetBottom = metadata.offsetBottom || 0; |
| + var offsetTopDIP = metadata.offsetTop || 0; |
| + var offsetBottomDIP = metadata.offsetBottom || 0; |
| + this._screenOffsetTop = offsetTopDIP; |
| + |
| + var totalBarHeightDIP = offsetTopDIP + offsetBottomDIP; |
| + var deviceWidthDIP = metadata.device.width |
|
dgozman
2014/06/25 13:31:34
not: semicolon
|
| + var deviceHeightDIP = metadata.device.height |
|
dgozman
2014/06/25 13:31:35
ditto
|
| + var deviceSizeRatio = deviceHeightDIP / deviceWidthDIP; |
| - var screenWidthDIP = this._viewport.width * this._pageScaleFactor; |
| - var screenHeightDIP = this._viewport.height * this._pageScaleFactor + offsetTop + offsetBottom; |
| - this._screenOffsetTop = offsetTop; |
| - this._resizeViewport(screenWidthDIP, screenHeightDIP); |
| + var dimensionsCSS = this._viewportDimensions(); |
| + |
| + this._imageZoom = Math.min(dimensionsCSS.width / this._imageElement.naturalWidth, dimensionsCSS.height / (this._imageElement.naturalWidth * deviceSizeRatio)); |
| + this._viewportElement.classList.remove("hidden"); |
| + var bordersSize = WebInspector.ScreencastView._bordersSize; |
| + if (this._imageZoom < 1.01 / window.devicePixelRatio) |
| + this._imageZoom = 1 / window.devicePixelRatio; |
| + this._screenZoom = this._imageElement.naturalWidth * this._imageZoom / deviceWidthDIP; |
| + this._viewportElement.style.width = deviceWidthDIP * this._screenZoom + bordersSize + "px"; |
| + this._viewportElement.style.height = deviceHeightDIP * this._screenZoom + bordersSize + "px"; |
| - this._imageZoom = this._imageElement.naturalWidth ? this._canvasElement.offsetWidth / this._imageElement.naturalWidth : 1; |
| this.highlightDOMNode(this._highlightNode, this._highlightConfig); |
| }, |
| @@ -234,21 +239,6 @@ WebInspector.ScreencastView.prototype = { |
| }, |
| /** |
| - * @param {number} screenWidthDIP |
| - * @param {number} screenHeightDIP |
| - */ |
| - _resizeViewport: function(screenWidthDIP, screenHeightDIP) |
| - { |
| - var dimensions = this._viewportDimensions(); |
| - this._screenZoom = Math.min(dimensions.width / screenWidthDIP, dimensions.height / screenHeightDIP); |
| - |
| - var bordersSize = WebInspector.ScreencastView._bordersSize; |
| - this._viewportElement.classList.remove("hidden"); |
| - this._viewportElement.style.width = screenWidthDIP * this._screenZoom + bordersSize + "px"; |
| - this._viewportElement.style.height = screenHeightDIP * this._screenZoom + bordersSize + "px"; |
| - }, |
| - |
| - /** |
| * @param {?Event} event |
| */ |
| _handleMouseEvent: function(event) |
| @@ -494,7 +484,7 @@ WebInspector.ScreencastView.prototype = { |
| */ |
| _zoomIntoScreenSpace: function(event) |
| { |
| - var zoom = this._canvasElement.offsetWidth / this._viewport.width / this._pageScaleFactor; |
| + var zoom = this._canvasElement.offsetWidth / this._viewport.width; |
| var position = {}; |
| position.x = Math.round(event.offsetX / zoom); |
| position.y = Math.round(event.offsetY / zoom); |
| @@ -568,7 +558,7 @@ WebInspector.ScreencastView.prototype = { |
| */ |
| function callback(model) |
| { |
| - if (!model) { |
| + if (!model || !this._viewport) { |
| this._repaint(); |
| return; |
| } |
| @@ -584,7 +574,7 @@ WebInspector.ScreencastView.prototype = { |
| */ |
| _scaleModel: function(model) |
| { |
| - var scale = this._canvasElement.offsetWidth / this._viewport.width; |
| + var scale = this._canvasElement.offsetWidth * this._pageScaleFactor / this._viewport.width; |
| /** |
| * @param {!DOMAgent.Quad} quad |
| @@ -653,9 +643,13 @@ WebInspector.ScreencastView.prototype = { |
| this._context.globalCompositeOperation = "destination-over"; |
| } |
| - this._context.drawImage(this._imageElement, 0, this._screenOffsetTop * this._screenZoom, this._imageElement.naturalWidth * this._imageZoom, this._imageElement.naturalHeight * this._imageZoom); |
| - |
| + this._context.scale(1 / window.devicePixelRatio, 1 / window.devicePixelRatio); |
|
dgozman
2014/06/25 13:31:35
This may be wrong with zoom != 1. Please double ch
vkuzkokov
2014/06/25 17:56:58
Done.
|
| + this._context.drawImage(this._imageElement, 0, |
| + this._screenOffsetTop * this._screenZoom * window.devicePixelRatio, |
| + this._imageElement.naturalWidth * this._imageZoom * window.devicePixelRatio, |
|
dgozman
2014/06/25 13:31:35
Again, devicePixelRatio includes zoom.
|
| + this._imageElement.naturalHeight * this._imageZoom * window.devicePixelRatio); |
| this._context.restore(); |
| + |
| }, |
| @@ -817,8 +811,9 @@ WebInspector.ScreencastView.prototype = { |
| { |
| const gutterSize = 30; |
| const bordersSize = WebInspector.ScreencastView._bordersSize; |
| - return { width: this.element.offsetWidth - bordersSize - gutterSize, |
| - height: this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight}; |
| + var width = Math.floor(this.element.offsetWidth - bordersSize - gutterSize); |
| + var height = Math.floor(this.element.offsetHeight - bordersSize - gutterSize - WebInspector.ScreencastView._navBarHeight); |
| + return { width: width, height: height }; |
| }, |
| /** |