Lag due to huge image size on zoom with canvas grid
Description When opening a mid-size image (eg. 800x600) and zooming in fully the canvas becomes huge (28800 x 21600), when canvas grid is enabled this lags and sometimes even crashes. #1020 had a similar issue, the applied fix (#1485) did not seem to help when canvas grid is enabled.
To Reproduce
- Open a mid sized image (the default 800x600 white image works, but is hard to see)
- Verify canvas grid is enabled (View => Canvas Grid => ✔️ Show grid, width and height 1 pixel)
- Zoom in fully
- Try to pan around and notice the lag, or crash on higher resolution images
Additional Info I have verified this happens on master, and verified that commenting out the BuildCanvasGridPath method stops the lag. No info appears in the console on crash.
Version Arch Linux x86_64 Wayland/KDE Plasma 6.5.3 Pinta 3.1/ Build from commit 5b4f3e76a59f1c8c16fd3e802bc6e4006bbe1250
AMD Ryzen 9 9950X3D AMD Radeon RX 9070 XT 16 GB Memory
Also having this issue on Linux Mint
The problem is that we are rendering the grid to the entire canvas, instead of just the lines inside the view, and that the grid is rebuilt on every redraw. This was discussed briefly in https://github.com/PintaProject/Pinta/pull/1541#issuecomment-2993247149.
Yeah, it'd be good to figure out if we can draw within just the current view. I'm not sure offhand how easy that is since the canvas is wrapped in a Gtk.Viewport which adds the scrolling, so the canvas isn't really aware of it ..
Another idea to test out would be splitting the grid path into many separate paths for smaller tiles. I'm not super familiar with the internals of GTK's widget rendering, but if it does some culling based on bounds then this could be more efficient