Fix DPR changes in interleaved mode by leveraging onResize callback#9887
Merged
chrisgervang merged 6 commits intomasterfrom Dec 2, 2025
Merged
Fix DPR changes in interleaved mode by leveraging onResize callback#9887chrisgervang merged 6 commits intomasterfrom
chrisgervang merged 6 commits intomasterfrom
Conversation
…eate paths - Add onResize and onDevicePixelRatioChange callbacks to attach path - Manually sync drawing buffer dimensions when callbacks fire - Add onDevicePixelRatioChange callback to create path - Remove incorrect autoResize override in MapboxOverlay - Add console logs for debugging resize events
- Remove onDevicePixelRatioChange from attach path - Remove onDevicePixelRatioChange from create path - Remove debug console.logs - Remove unused variable declarations Testing confirmed that onResize callback alone handles both window resize and DPR changes, making the separate DPR callback redundant.
Collaborator
Author
|
Ran this on noodles.gl as well and had great results when changing resolution with it's UI controls. |
Collaborator
|
Nice fix! |
felixpalmer
approved these changes
Dec 2, 2025
Collaborator
felixpalmer
left a comment
There was a problem hiding this comment.
Looks great :) Be sure to also give it a spin on the website - I just did and appears to work without issue
Collaborator
Author
|
Tested the website - works without issues there as well. I'd like to make this basemap test matrix faster to get through for future changes.. I'm generating a "basemap-browser" similar to layer-browser and am interested in setting up an automatic staging environment for the website, similar to what we're doing in noodles |
felixpalmer
added a commit
that referenced
this pull request
Dec 3, 2025
…9887) * fix(core): Correctly resize drawing buffer on resize * fix(core,mapbox): Handle resize and DPR changes in both attach and create paths - Add onResize and onDevicePixelRatioChange callbacks to attach path - Manually sync drawing buffer dimensions when callbacks fire - Add onDevicePixelRatioChange callback to create path - Remove incorrect autoResize override in MapboxOverlay - Add console logs for debugging resize events * Remove manual drawing buffer sync from setProps * Clean up: Remove redundant onDevicePixelRatioChange callbacks - Remove onDevicePixelRatioChange from attach path - Remove onDevicePixelRatioChange from create path - Remove debug console.logs - Remove unused variable declarations Testing confirmed that onResize callback alone handles both window resize and DPR changes, making the separate DPR callback redundant. --------- Co-authored-by: Felix Palmer <felixpalmer@gmail.com>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes device pixel ratio (DPR) changes when moving windows between displays with different pixel ratios, building on top of #9886.
Key Discovery: The
onResizecallback is sufficient for handling both window resize AND DPR changes. TheonDevicePixelRatioChangecallback is redundant because luma.gl's ResizeObserver firesonResizewhenever DPR changes.Changes
modules/core/src/lib/deck.ts
onResizecallback to attach path (interleaved mode) that:onResizecallback in create path (standalone mode)setDrawingBufferSize()immediately modifies the canvas, but in attach mode the external library (Mapbox/Maplibre/Google Maps) manages canvas sizemodules/mapbox/src/mapbox-overlay.ts
autoResize: trueoverrideautoResize: falseTest Matrix Results ✅
Tested all scenarios with window resize, DPR changes (moving between displays), and where applicable, fullscreen mode.
Google Maps (4/4) ✅
Maplibre (4/4) ✅
Mapbox (4/4) ✅
Maplibre Globe (2/2) ✅
Test Apps (2/2) ✅
Total: 15/15 scenarios passed
Known Issues
Technical Details
Why does onResize handle DPR changes?
Luma.gl's
CanvasContextuses aResizeObserverto monitor the canvas. When DPR changes (e.g., moving window to a display with different pixel ratio), the browser fires the ResizeObserver because the device pixel dimensions of the canvas change. This triggers theonResizecallback with the new dimensions, making a separateonDevicePixelRatioChangecallback redundant.Why manual drawing buffer sync in attach mode?
In attach mode (interleaved rendering), the external mapping library (Mapbox/Maplibre/Google Maps) manages the canvas element and its size. When luma detects a resize, we need to manually sync the drawing buffer dimensions to match the canvas, because:
autoResizeis forced tofalsein attach mode (the external library controls canvas size)setDrawingBufferSize()as it would fight with the external libraryFuture Improvements
When upgrading to luma 9.3+, we can use
canvasContext.setDrawingBufferSize(width, height)instead of direct property assignment (see TODO comments in code).Note
Sync drawing buffer on onResize for attached WebGL contexts and drop Mapbox interleaved autoResize override to ensure correct DPR/resize behavior.
modules/core/src/lib/deck.ts):deviceProps.onResizeto synccanvasContext.drawingBufferWidth/Heightfromcanvas, set redraw, and preserve user callback.setPropswhenautoResize === false.modules/mapbox/src/mapbox-overlay.ts):createCanvasContext: {autoResize: true}; only setparametersalongsidegl.Written by Cursor Bugbot for commit 73ee11d. This will update automatically on new commits. Configure here.