Merge branch 'shm-mmap-offset' into 'main'

Add extended shared memory attach support

Closes #217

See merge request wayland/wayland!161
This commit is contained in:
Demi Marie Obenour 2026-01-25 23:18:02 -05:00
commit e432b519bf
4 changed files with 144 additions and 42 deletions

View file

@ -105,8 +105,10 @@ formats = {}
for ident, val in idents.items():
formats[drm_format_to_wl(ident)] = val.lower()
# Special case for ARGB8888 and XRGB8888
formats["argb8888"] = "0"
formats["xrgb8888"] = "1"
for (i, j) in enumerate(("argb8888", "xrgb8888")):
formats[j + "_new"] = formats[j]
descriptions[j + "_new"] = descriptions[j]
formats[j] = str(i)
print("Loaded {} formats from drm_fourcc.h".format(len(formats)), file=sys.stderr)

View file

@ -212,7 +212,7 @@
</request>
</interface>
<interface name="wl_shm_pool" version="2">
<interface name="wl_shm_pool" version="3">
<description summary="a shared memory pool">
The wl_shm_pool object encapsulates a piece of memory shared
between the compositor and client. Through the wl_shm_pool
@ -233,9 +233,16 @@
of the next. The format is the pixel format of the buffer and
must be one of those advertised through the wl_shm.format event.
A buffer will keep a reference to the pool it was created from
A buffer will keep a reference to the pool it was created from,
so it is valid to destroy the pool immediately after creating
a buffer from it.
The offset must not be negative. If it is negative, an
invalid_stride error is raised. This limits offsets to a
maximum of 2^31 - 1 bytes.
The version of the returned buffer is 1, regardless of the
version of the pool from which it was created.
</description>
<arg name="id" type="new_id" interface="wl_buffer" summary="buffer to create"/>
<arg name="offset" type="int" summary="buffer byte offset within the pool"/>
@ -267,6 +274,11 @@
file descriptor passed at creation time. It is the client's
responsibility to ensure that the file is at least as big as
the new pool size.
If the pool was created using version 3 or later of the wl_shm
interface, this request cannot be called once any buffers have
been created. Attempting to do so will result in an
already_mapped error.
</description>
<arg name="size" type="int" summary="new size of the pool, in bytes"/>
</request>
@ -292,27 +304,35 @@
<entry name="invalid_format" value="0" summary="buffer format is not known"/>
<entry name="invalid_stride" value="1" summary="invalid size or stride during pool or buffer creation"/>
<entry name="invalid_fd" value="2" summary="mmapping the file descriptor failed"/>
<entry name="already_mapped" value="3"
summary="a pool was created with version 3 or later of wl_shm, and an attempt was made to resize it after it had already been mapped"/>
</enum>
<enum name="format">
<description summary="pixel formats">
This describes the memory layout of an individual pixel.
All renderers should support argb8888 and xrgb8888 but any other
All compositors must support argb8888 and xrgb8888. Compositors
supporting wl_shm v3 must support argb8888_new and xrgb8888_new
as well, even with version 1 wl_shm_pool objects. All other
formats are optional and may not be supported by the particular
renderer in use.
The drm format codes match the macros defined in drm_fourcc.h, except
argb8888 and xrgb8888. The formats actually supported by the compositor
will be reported by the format event.
will be reported by the format event, and are not limited to those in
this enum. Starting with version 2, argb8888_new and xrgb8888_new values
are provided, which match the corresponding values in drm_fourcc.h.
For all wl_shm formats and unless specified in another protocol
extension, pre-multiplied alpha is used for pixel values.
All wl_shm formats use pre-multiplied alpha for pixel values, unless
another protocol extension states otherwise.
</description>
<!-- Note to protocol writers: don't update this list manually, instead
run the automated script that keeps it in sync with drm_fourcc.h. -->
<entry name="argb8888" value="0" summary="32-bit ARGB format, [31:0] A:R:G:B 8:8:8:8 little endian"/>
<entry name="xrgb8888" value="1" summary="32-bit RGB format, [31:0] x:R:G:B 8:8:8:8 little endian"/>
<entry name="argb8888_new" value="0x34325241" summary="[31:0] A:R:G:B 8:8:8:8 little endian"/>
<entry name="xrgb8888_new" value="0x34325258" summary="[31:0] x:R:G:B 8:8:8:8 little endian"/>
<entry name="c8" value="0x20203843" summary="8-bit color index format, [7:0] C"/>
<entry name="rgb332" value="0x38424752" summary="8-bit RGB format, [7:0] R:G:B 3:3:2"/>
<entry name="bgr233" value="0x38524742" summary="8-bit BGR format, [7:0] B:G:R 2:3:3"/>
@ -462,7 +482,12 @@
The pool can be used to create shared memory based buffer
objects. The server will mmap size bytes of the passed file
descriptor, to use as backing memory for the pool.
descriptor, to use as backing memory for the pool. If it is
unable to do so, an invalid_fd error is raised.
The size must be greater than zero. Sizes less or equal to zero
raise an invalid_stride error. This prevents the creation of
pools larger than 2^31 - 1 bytes.
</description>
<arg name="id" type="new_id" interface="wl_shm_pool" summary="pool to create"/>
<arg name="fd" type="fd" summary="file descriptor for the pool"/>
@ -488,6 +513,35 @@
Objects created via this interface remain unaffected.
</description>
</request>
<!-- Version 3 additions -->
<request name="create_pool2" since="3">
<description summary="create a shm pool">
Create a new wl_shm_pool object.
The pool can be used to create shared memory based buffer
objects. The server will mmap size bytes of the passed file
descriptor at the provided offset to use as backing memory for
the pool. If it is unable to do so, an invalid_fd error is
raised.
This request provides a strict superset of the functionality
provided by create_pool. In particular, calling this request
with offset_lo and offset_hi set to 0 is equivalent to calling
create_pool.
If the size is zero or greater than 2^31 - 1, an invalid_stride
error is raised. Compositors are not allowed to impose
arbitrary limits on the offset, beyond those imposed by the
operating system. In particular, the offset may be negative
when cast to an off_t, and may be larger than 2^32 - 1.
</description>
<arg name="id" type="new_id" interface="wl_shm_pool" summary="pool to create"/>
<arg name="fd" type="fd" summary="file descriptor for the pool"/>
<arg name="size" type="uint" summary="pool size, in bytes"/>
<arg name="offset_lo" type="uint" summary="low-order 32 bits of offset for mmap, in bytes"/>
<arg name="offset_hi" type="uint" summary="high-order 32 bits of offset for mmap, in bytes"/>
</request>
</interface>
<interface name="wl_buffer" version="1">