Skip to content

meta/selection-source-memory: Use memfd instead of GBytes

Following the discussions on #3525, this MR will modify MetaSelectionSourceMemory to use MetaAnonymousFile instead of GBytes.

Motivation

Following the suggestion to support multiple mimetypes in #3525, @carlosg raised the issue of memory overhead for storing multiple versions of large items such as images. To circumvent this issue, he proposed to use Memfd instead of storing the contents in the gnome-shell heap. This MR is meant to be the first stage to supporting multiple mimetypes for MetaSelectionSourceMemory.

Implementation details

I hope the changes are pretty straight forward, but a quick overview might still be warranted.
The data struct now contains a pointer to a MetaAnonymousFile instead of GBytes. In the constructor, we take the provided bytes, get their uint8 * value & size, and create a new MetaAnonymousFile. In read_async() we then open the file via meta_anonymous_file_open_fd() and create a Gio.UnixInputStream from the file descriptor.


Let me know if these changes seem OK. I have tested this locally against the latest versions of mutter:main and gnome-shell:main and it seems to work just fine. Tried it for both text and images.

cc @andyholmes who helped me with the original MR

Edited by Yotam Bar-On

Merge request reports