Skip to content

Conversation

1chandu
Copy link
Contributor

@1chandu 1chandu commented Jul 6, 2017

@ibgreen @Pessimistress : not ready to merge, have some open questions

modelViewMatrix: new Float32Array(modelViewMatrix),

// Screen size
// _Q2# : Verify and remove multiplicaiton with devicePixelRatio (assuming
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibgreen @Pessimistress , is multiplication with devicePixelRation needed here? Who sets these viewport bounds?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. DeckGL defined viewport from user provided props. The uniform is used by layers to project pixel size to clipspace, which requires the actual canvas size.

// for clean logging, only calls gl.viewport if props have changed
_updateGLViewport() {
/*
let {viewport: {x, y, width: w, height: h}} = this.props;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pessimistress @ibgreen , how are these props set? Can we ignore this and alway use [0, 0, canvas.width, canvas.height] , given canvas width/height matches device framebuffer size? If need to use this.props, is it guranteed the size provided by props updated with devicePixelRatio?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size in props is not multiplied by devicePixelRatio. It is the width and height that users pass to the DeckGL component.

}

// Gets current size of canvas in css (logical/window) coordinates
_getCSSSize(canvas) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these added methods are copy pasted from luma, we can import from luma once we finalize the fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientWidth and clientHeight have perf impacts. Since we already know the canvas' width and height styles (set in the render method) we don't need the work around here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is one of trickiest aspects of the canvas API. Namely that width and height control the size of the drawing buffer, not the DOM element, and are set independently from the style.width, height (which are read back as clientWidth and clientHeight). We can't keep reading width and height since they will be multiplied by DPR, we'll keep multiplying the drawing buffer size. If there is a reflow issue with clientWidth and clientHeight we could use the props.width and props.height here as they are intended to be in logical coordinates.

// Lookup the size the browser is displaying the canvas in CSS pixels
// and compute a size needed to make our drawingbuffer match it in
// device pixels.
const cssSize = this._getCSSSize(canvas);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use this.props.width and this.props.height.

// for clean logging, only calls gl.viewport if props have changed
_updateGLViewport() {
/*
let {viewport: {x, y, width: w, height: h}} = this.props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size in props is not multiplied by devicePixelRatio. It is the width and height that users pass to the DeckGL component.

if (newBufferSize.width !== canvas.width || newBufferSize.height !== canvas.height) {
// Make the canvas render buffer the same size as
canvas.width = newBufferSize.width;
canvas.height = newBufferSize.height;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are overwriting what's set in the render() method. Should remove the width and height assignment in render to avoid confusion.

@Pessimistress
Copy link
Collaborator

Remove the pixelRatio prop if it's not used?

@Pessimistress
Copy link
Collaborator

After this change we still have multiple copies of this line in the code:
const devicePixelRatio = (window && window.devicePixelRatio) || 1;
Can we consolidate it to either DeckGL or LayerManager and pass down to WebGLRenderer, draw-and-pick and viewport-uniforms?

@1chandu 1chandu force-pushed the CanvasSize branch 2 times, most recently from 20c1771 to 6229ffd Compare July 6, 2017 23:33
@1chandu
Copy link
Contributor Author

1chandu commented Jul 6, 2017

@ibgreen @Pessimistress , created this #760 to track remaining issues.

// device pixels.
return {
width: Math.floor(canvas.clientWidth * cssToDevicePixels),
height: Math.floor(canvas.clientHeight * cssToDevicePixels),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use this.props.width and this.props.height?
clientWidth and clientHeight causes page reflow. We already know the canvas css size since we set it here in render().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is page reflow, is it because clientWidth/clientHeight can be different than props.width/height?

Based on discussion with @ibgreen (also I verified changing window size), the width and height extracted from props and set to style object in render(), will be set to canvas.clientWidth and canvas.clientHeight, so they should identical.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browser attempts to recalculate the layout of the whole page when you access certain layout properties. It triggers a lot more action under the hood than just reading the props object.

@1chandu 1chandu merged commit f680d7f into master Jul 7, 2017
@1chandu 1chandu deleted the CanvasSize branch July 7, 2017 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants