Repository navigation
Web GUI: replace Leaflet with deck.gl in the layout viewer - #11712
jorge-ferreira-pii wants to merge 13 commits into
Conversation
|
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
There was a problem hiding this comment.
Code Review
This pull request replaces Leaflet.js with deck.gl (WebGL) for the 2D layout view, introducing a new layout view architecture (including layout-view.js, view-math.js, tile-grid.js, tile-sources.js, zoom-swap.js, and view-input.js) and updating the C++ backend to support server-side composited tile groups and optimized caching. The review feedback highlights a critical out-of-bounds read vulnerability in TileGenerator::generateGroupTile when handling empty layer buffers, potential memory leaks in main.js from undisposed view and input listener instances during panel recreation, and cross-platform path separator issues on Windows in embed_report_assets.py.
| // Transparent pixels come back all-zero, so the bottom layer is already | ||
| // its own composite onto an empty tile. | ||
| if (composite.empty()) { | ||
| dim = bufferDim(layer_buffer); | ||
| composite = std::move(layer_buffer); | ||
| } else { | ||
| compositeTile(layer_buffer, dim, composite.data(), dim, 0, 0); | ||
| } |
There was a problem hiding this comment.
If renderTileBuffer returns an empty vector (which happens when a layer has nothing to draw in the requested tile), layer_buffer will be empty. If composite is already non-empty, the code proceeds to the else branch and calls compositeTile(layer_buffer, dim, composite.data(), dim, 0, 0). Since layer_buffer is empty but dim is non-zero, compositeTile will attempt to read from layer_buffer out of bounds, leading to a segmentation fault or undefined behavior. Checking layer_buffer.empty() and skipping the iteration prevents this crash.
| // Transparent pixels come back all-zero, so the bottom layer is already | |
| // its own composite onto an empty tile. | |
| if (composite.empty()) { | |
| dim = bufferDim(layer_buffer); | |
| composite = std::move(layer_buffer); | |
| } else { | |
| compositeTile(layer_buffer, dim, composite.data(), dim, 0, 0); | |
| } | |
| if (layer_buffer.empty()) { | |
| continue; | |
| } | |
| // Transparent pixels come back all-zero, so the bottom layer is already | |
| // its own composite onto an empty tile. | |
| if (composite.empty()) { | |
| dim = bufferDim(layer_buffer); | |
| composite = std::move(layer_buffer); | |
| } else { | |
| compositeTile(layer_buffer, dim, composite.data(), dim, 0, 0); | |
| } |
| // boundaries mid-device-pixel and they show as dark hairlines; this nudges | ||
| // each tile container back onto the grid after every move. | ||
| installDeviceGridSnapping(app.map); | ||
| app.view = createLayoutView(mapDiv, { |
There was a problem hiding this comment.
When createLayoutViewer is called (e.g., when the panel is recreated), a new LayoutView is instantiated and assigned to app.view. However, the previous app.view is never destroyed, which leaves its ResizeObserver active, its ZoomSwap undisposed, and its deck.gl instance finalized only when garbage collected (or potentially leaked if referenced elsewhere). Calling app.view?.destroy() before creating a new view ensures proper cleanup of WebGL contexts and observers.
| app.view = createLayoutView(mapDiv, { | |
| app.view?.destroy(); | |
| app.view = createLayoutView(mapDiv, { |
| coordBar.textContent = ''; | ||
| syncHud(); | ||
| // Pointer input: wheel, keys, clicks, boxes. Drag-panning is the view's. | ||
| installViewInput(app.view, { |
There was a problem hiding this comment.
The installViewInput function adds multiple event listeners to the global window object. Since createLayoutViewer is called every time the panel is recreated, these listeners will leak and accumulate on window over time, keeping old view instances alive in memory. Disposing of the previous viewInput instance before installing a new one prevents this memory leak.
| installViewInput(app.view, { | |
| app.viewInput?.dispose(); | |
| app.viewInput = installViewInput(app.view, { |
| def dependency_order(sources): | ||
| """`sources` ([(path, content)]) with each file after the files it imports, | ||
| else in the given order: a file's top-level code runs as it is reached.""" | ||
| by_name = {path.split("/")[-1]: (path, content) for path, content in sources} | ||
| done, visiting, ordered = set(), [], [] | ||
|
|
||
| def visit(name): | ||
| if name in done: | ||
| return | ||
| if name in visiting: | ||
| cycle = visiting[visiting.index(name) :] + [name] | ||
| sys.exit("embed_report_assets: import cycle " + " -> ".join(cycle)) | ||
| visiting.append(name) | ||
| for dep in local_imports(by_name[name][1]): | ||
| if dep not in by_name: | ||
| sys.exit( | ||
| f"embed_report_assets: {name} imports {dep}, " | ||
| "which is not in --js" | ||
| ) | ||
| visit(dep) | ||
| visiting.pop() | ||
| done.add(name) | ||
| ordered.append(by_name[name]) | ||
|
|
||
| for path, _ in sources: | ||
| visit(path.split("/")[-1]) | ||
| return ordered |
There was a problem hiding this comment.
Using path.split("/")[-1] to extract the filename can fail on Windows where the path separator is \\. This will cause by_name keys to contain backslashes, while local_imports returns filenames with forward slashes, leading to key mismatches and build failures on Windows. Normalizing the path separators by replacing backslashes with forward slashes before splitting ensures cross-platform compatibility.
def dependency_order(sources):
"""`sources` ([(path, content)]) with each file after the files it imports,
else in the given order: a file's top-level code runs as it is reached."""
def get_basename(p):
return p.replace('\\', '/').split('/')[-1]
by_name = {get_basename(path): (path, content) for path, content in sources}
done, visiting, ordered = set(), [], []
def visit(name):
if name in done:
return
if name in visiting:
cycle = visiting[visiting.index(name) :] + [name]
sys.exit('embed_report_assets: import cycle ' + ' -> '.join(cycle))
visiting.append(name)
for dep in local_imports(by_name[name][1]):
if dep not in by_name:
sys.exit(
f'embed_report_assets: {name} imports {dep}, '
'which is not in --js'
)
visit(dep)
visiting.pop()
done.add(name)
ordered.append(by_name[name])
for path, _ in sources:
visit(get_basename(path))
return ordered| sources.append((path, f.read())) | ||
| js_parts = [] | ||
| for path, content in dependency_order(sources): | ||
| js_parts.append(f'// ── {path.split("/")[-1]} ──') |
| const app = { | ||
| map: null, | ||
| // Zoom-to-fit box in latlng, Qt's 5% margin per dimension already added | ||
| // (computeBoundsTransforms). Anything wanting the design's own extent | ||
| // has to work from the DBU rects, not from this. | ||
| fitBounds: null, | ||
| lastSelectionBounds: null, // Leaflet bounds of the last selected object | ||
| view: null, // the layout view (layout-view.js) |
There was a problem hiding this comment.
Add a placeholder for viewInput to the app state object to track the active input listener instance and prevent memory leaks on panel recreation.
| const app = { | |
| map: null, | |
| // Zoom-to-fit box in latlng, Qt's 5% margin per dimension already added | |
| // (computeBoundsTransforms). Anything wanting the design's own extent | |
| // has to work from the DBU rects, not from this. | |
| fitBounds: null, | |
| lastSelectionBounds: null, // Leaflet bounds of the last selected object | |
| view: null, // the layout view (layout-view.js) | |
| const app = { | |
| view: null, // the layout view (layout-view.js) | |
| viewInput: null, |
Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Also catches Mesa software renderers and missing WebGL. The warning stays in the bottom-right corner until closed, and can be silenced. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
luma.gl names a GPU maker the private repository's hook rejects; rename it at build time without changing behavior. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
a15dd11 to
62c64fc
Compare
Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Brings in master and the tile-cache, generator-lifetimes and ws-replies branches, drops tile_group, fixes the viewer and panel issues found since the review, and regenerates dist. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Ports the per-die layer rows of The-OpenROAD-Project#12061 to the deck.gl viewer and keys cached tiles by die; drops the checked-in dist that master removed. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Signed-off-by: Matt Liberty <mliberty@precisioninno.com> # Conflicts: # src/web/src/main.js # src/web/src/ui-utils.js # src/web/test/js/test-ui-utils.js
Ports master's gated pseudo layers and cluster overlay to the deck.gl viewer, and keys cached tiles by their owner colors. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Fixes stale tiles in saved reports, jumps in anchored zooms, label-mode clicks and tiles requested before the per-die state is restored. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Use std::scoped_lock, drop a nested conditional and add a trailing comma to the tile key initializer. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Follows master's src/ to openroad/ rename; the Leaflet files the viewer replaced stay deleted. Signed-off-by: Jorge Ferreira <jorge.ferreira@precisioninno.com>
Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
The layout viewer now renders with deck.gl instead of Leaflet.js and removes Leaflet entirely.
Zoom and pan are smoother: the previous view stays on screen until the new one is ready, so the layout no longer flashes or shows blank areas. Fit glides to the whole design instead of jumping, and trackpad pinch and scroll zoom follow the fingers.
It also fixes the saved HTML report, clicks on the zoom buttons, and the mouse wheel on macOS. On the server side, there is an optional mode that sends several layers in one tile, and the tile cache is now limited in size.
Fix #11340