Add two workarounds for the slow layer thumbnails problem

The patch adds two workarounds for BUG:510627

Automatic switch to "coarse" layer thumbnail generation

When a layer has vast areas of empty pixels, it may be slow to calculate its exactBounds(). In this case, if thumbnail generation takes more than 40ms, Krita will automatically switch the layer into "coarse thumbnail generation mode" and use extent() instead.

The status bar will also show a warning symbol and list the "slow layers" in a tooltip.

Screenshot_20251225_152808

Image->Purge Unused Image Data

A new action was added to remove these areas of empty pixels. It basically iterates through all the layers and cleans-up all paint devices it could find. Just mere calling to the action fixes the slow thumbnails issue for me in my testing images.

image

WARNING: this action can theoretically break undo/redo functionality of the image. Please test if it doesn't!

Test plan

  1. Enable logging in the logging docker (or open Krita in a terminal)
  2. Open Undo History docker
  3. Open some huge image (4k+) with sparse data on the layers
  4. Check log for messages like this:
    krita.ui: WARNING: thumbnail generation for "HSVFilter" took longer than expected: 202 (timeout: 40 )
    krita.ui:          This layer's thumbnail will be rendered in imprecise mode from now on
  5. A warning icon should appear in the status bar, telling that some layers now use "coarse" thumbnail mode
  6. Draw something on the image, verify there is no delay before the stroke (since "slow" layers now use coarse thumbnail mode)
  7. Click Image->Purge Unused Image Data
  8. Try to paint something again
  9. Verify three things:
    • the warning icon disappeared from the status bar
    • no new warnings appeared in the log
    • no delay when painting appeared
  10. Try to undo/redo on the image past "Purge Unused Image Data". Undo should still work.

Merge request reports

Loading