2D map: keep the land picture on the graphics card in Firefox on a computer

The 2D map paints its land into an offscreen picture. In Firefox that picture was a software canvas
(willReadFrequently), because Firefox on Android garbled big paths on its graphics card (#43). Firefox on a computer
had it too, and a software canvas is sent to the card again on every frame, at a cost that grows with the picture:
the whole world at mid zoom, four screens of it zoomed in.

Only Firefox on Android keeps it now (softCanvas()). Measured in Firefox 159 on Windows (RTX 4090, full screen
2560x1440), 2D map, frames per second at zoom 0.6 / 1.1 / 1.6 / 3.2:
- big-network fixture, main: 56 / 37 / 34 / 26; with this change: 64 / 49 / 51 / 78;
- the 183-POP save, main: 32 / 25 / 25 / 22; with this change: 36 / 26 / 33 / 55.
(Measured with the change injected into main's page; the land picture is the same code on this branch.)

tests/world-layer-firefox.test.js: which browsers get the software canvas, and that the land is an ordinary one
elsewhere.
This commit is contained in:
Antoine 2026-11-04 20:59:05 +01:00
parent cdc7c6d1eb
commit b03bec267c
No known key found for this signature in database
GPG key ID: 728FF1CE15732B05
3 changed files with 41 additions and 1 deletions

View file

@ -2,7 +2,10 @@
GPU canvas implementations (Firefox on Android) garble big paths (#43). It is painted into an offscreen image
instead: the whole world when that fits in MAXPX, otherwise the visible area plus a margin, repainted when you
pan out of it. While a zoom gesture is still moving, the last image is scaled rather than repainted. */
const SOFT_CANVAS=/Firefox\//.test(navigator.userAgent);
/* Only Firefox on Android gets that image as a software canvas (willReadFrequently). Firefox on a computer drew it
fine on the graphics card, and a software canvas there is sent to the card again on every frame, a cost that grows
with the image: zoomed in, the 2D map ran at half its speed. */
const softCanvas=ua=>/Android.*Firefox\//.test(ua),SOFT_CANVAS=softCanvas(navigator.userAgent);
function wlCovers(z){if(WL.full)return true;const hw=CW/2/z,hh=CH/2/z,w=WL.cv.width/WL.sc,h=WL.cv.height/WL.sc;
return cam.x-hw>=WL.ox&&cam.x+hw<=WL.ox+w&&cam.y-hh>=WL.oy&&cam.y+hh<=WL.oy+h;}
function worldLayer(z){