klipper: preserve encoded PNG when restoring history entries

Original commit message(s)

  • klipper: Preserve encoded PNG when restoring history entries

Reason for the change

Klipper stores image history entries as encoded PNG data. When restoring an entry, DatabaseRecordToMimeDataJob::mimeData() decoded those bytes into a QImage and exposed only the decoded representation.

When an application subsequently requests image/png, the clipboard backend has to encode the full QImage back into PNG synchronously. For large images, this can delay Ctrl+V by several seconds.

Steps to reproduce:

  1. Copy a PNG image or full-screen screenshot with a resolution of at least 3840×2160 so that it appears in Klipper history.
  2. Copy another item so that the image is no longer the current clipboard entry.
  3. Open the Clipboard widget and select the image again.
  4. Press Ctrl+V in an application that accepts pasted images, such as Telegram.

Before this change, the receiving application can remain unresponsive for several seconds while the image is encoded again. With this change, Klipper provides the stored PNG payload directly.

Test plan

Manual A/B testing was performed on the same laptop with a 3072×1920 display, using Plasma 6.7.3.

A separate benchmark was run in a virtual machine with Qt 6.10.3, 4 virtual CPUs, and 8 GiB of memory. The input was a 7680×4320 PNG with a size of 15.2 MiB. Five runs were performed for each path:

Measurement Before After
Median PNG send time 7118 ms <1 ms

The existing path took 7107-7151 ms to produce the PNG. The patched path returned the original 15.2 MiB payload in below 1 ms in every run. Both paths produced a valid PNG of the same size.

Screenshots or screen recordings

This change has no visual effect.

Bugs fixed

I didn't find it.

Merge request reports

Loading