-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): conflicting resize logic when using non-default useDevicePixels #9326
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some background.
- There is an improved ResizeObserver API in browsers which allows the canvas context's ResizeObserver to determine the actual device pixel size of the canvas.
- This hasn't been possible in the past, as CSS width * dpr is just an approximation (because of rounding errors) which can result in very noticeable and undesirable moire effects.
- I recommend reading https://webgpufundamentals.org/webgpu/lessons/webgpu-resizing-the-canvas.html if interested.
CanvasContext now adopts this new method (at the cost of reduced support for arbitrary user specified DPRs in useDevicePixelRatio
).
Even if the app does not use CanvasContext auto resize, the resize observer should update the pixelSize
field on the canvas context, so that the app has access to the perfect size information for its own resizing calculations.
Longer term, I would avoid relying on any residual resize logic in the AnimationLoop. It is duplicative and confusing if resize is done (differently) in two places.
0b8a8b0
to
f469aee
Compare
My take away from reviewing luma.gl branches and discussion with @ibgreen:
return new AnimationLoop({
device: deviceOrPromise,
- useDevicePixels, // v9.1
- autoResizeDrawingBuffer: !gl, // v9.1
+ autoResizeDrawingBuffer: false, // v9.2
autoResizeViewport: false, deviceOrPromise = luma.createDevice({
createCanvasContext: {
canvas: this._createCanvas(props),
useDevicePixels: this.props.useDevicePixels,
- autoResize: false // v9.1
+ autoResize: true // v9.2
}
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with the approach 👍
Background
Canvas resize events are being responded to by two independent code paths:
CanvasContext
withautoResize: true
sets up resize observer which callsresize
without the correctuseDevicePixels
settingAnimationLoop
withautoResizeDrawingBuffer: true
checks canvas size before each render frame with the correctuseDevicePixels
settingIf the user sets
useDevicePixels
to a value that is notwindow.devicePixelRatio
the canvas ends up getting resized twice to different dimensions.Change List
autoResize
when creating the context