<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/shm.c, branch 1.28.0</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.28.0</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.28.0'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2026-01-04T17:59:20Z</updated>
<entry>
<title>shm: don't bother with xrgb surfaces, always use argb</title>
<updated>2026-01-04T17:59:20Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2026-01-04T06:57:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=b78cc92322dd2ae431dbbb70bc681b4d603d844d'/>
<id>urn:sha1:b78cc92322dd2ae431dbbb70bc681b4d603d844d</id>
<content type='text'>
Before this patch, foot used xrgb surfaces for all fully opaque
surfaces, and only used argb surfaces for the main window when the
user enabled translucency.

However, several compositors have damage-like issues when we switch
between opaque and non-opaque surfaces (for example, when switching
color theme, or when toggling fullscreen).

Since the performance benefit of using non-alpha aware surfaces are
likely minor (if there's any measurable performance difference at
all!), lets workaround these compositor issues by always using argb
surfaces.
</content>
</entry>
<entry>
<title>shm: revert part of 299186a6547f6e038ee6f3822caf9a0fdfabceef</title>
<updated>2025-12-17T07:09:23Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-12-16T13:56:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=4e96780eef048baa7370499c64a33210b4e0406d'/>
<id>urn:sha1:4e96780eef048baa7370499c64a33210b4e0406d</id>
<content type='text'>
299186a6547f6e038ee6f3822caf9a0fdfabceef introduced a regression,
where we don't handle SHM buffer "hiccups" correctly.

If foot, for some reason is forced to render a frame "too soon", we
might end up having multiple buffers "in flight" (i.e. committed to
the compositor). This could happen if the compositor pushes multiple
configure events rapidly, for example. Or anything else that forces
foot to render something "immediately", without waiting for a frame
callback.

The compositor typically releases both buffers at the same time (or
close to it), so the _next_ time we want to render a frame, we
have *two* buffers to pick between. The problem here is that after
299186a6547f6e038ee6f3822caf9a0fdfabceef, foot no longer purges the
additional buffer(s), but keeps all of them around. This messes up
foot's age tracking, and the _next_ time we're forced to pull two
buffers (without the compositor releasing the first one in between),
we try to apply damage tracking that is no longer valid. This results
in visual glitches. This never self-repairs, and we're stuck with
visual glitches until the window is resized, and we're forced to
allocate completely new buffers.

It is unclear why 299186a6547f6e038ee6f3822caf9a0fdfabceef stopped
removing the buffers. It was likely done early in the development, and
is no longer needed. So far, I haven't noticed any bugs by
re-introducing the buffer purging, but further testing is needed.
</content>
</entry>
<entry>
<title>render: when double-buffering, pre-apply previous frame's damage early</title>
<updated>2025-10-10T08:23:17Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-10-05T08:48:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=299186a6547f6e038ee6f3822caf9a0fdfabceef'/>
<id>urn:sha1:299186a6547f6e038ee6f3822caf9a0fdfabceef</id>
<content type='text'>
Foot likes it when compositor releases buffer immediately, as that
means we only have to re-render the cells that have changed since the
last frame.

For various reasons, not all compositors do this. In this case, foot
is typically forced to switch between two buffers, i.e. double-buffer.

In this case, each frame starts with copying over the damage from the
previous frame, to the new frame. Then we start rendering the updated
cells.

Bringing over the previous frame's damage can be slow, if the changed
area was large (e.g. when scrolling one or a few lines, or on full
screen updates). It's also done single-threaded. Thus it not only
slows down frame rendering, but pauses everything else (i.e. input
processing). All in all, it reduces performance and increases input
latency.

But we don't have to wait until it's time to render a frame to copy
over the previous frame's damage. We can do that as soon as the
compositor has released the buffer (for the frame _before_ the
previous frame). And we can do this in a thread.

This frees up foot to continue processing input, and reduces frame
rendering time since we can now start rendering the modified cells
immediately, without first doing a large memcpy(3).

In worst case scenarios (or perhaps we should consider them best case
scenarios...), I've seen up to a 10x performance increase in frame
rendering times (this obviously does *not* include the time it takes
to copy over the previous frame's damage, since that doesn't affect
neither input processing nor frame rendering).

Implemented by adding a callback mechanism to the shm abstraction
layer. Use it for the grid buffers, and kick off a thread that copies
the previous frame's damage, and resets the buffers age to 0 (so that
foot understands it can start render to it immediately when it later
needs to render a frame).

Since we have certain way of knowing if a compositor releases buffers
immediately or not, use a bit of heuristics; if we see 10 consecutive
non-immediate releases (that is, we reset the counter as soon as we do
see an immediate release), this new "pre-apply damage" logic is
enabled. It can be force-disabled with tweak.pre-apply-damage=no.

We also need to take care to wait for the thread before resetting the
render's "last_buf" pointer (or we'll SEGFAULT in the thread...).

We must also ensure we wait for the thread to finish before we start
rendering a new frame. Under normal circumstances, the wait time is
always 0, the thread has almost always finished long before we need to
render the next frame. But it _can_ happen.

Closes #2188
</content>
</entry>
<entry>
<title>shm: page-align the memfd size (also needed for GPU direct import)</title>
<updated>2025-10-05T07:40:51Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-10-04T08:50:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=bd994eda1c816d5430a9c4cdb7089e43c47d74ae'/>
<id>urn:sha1:bd994eda1c816d5430a9c4cdb7089e43c47d74ae</id>
<content type='text'>
</content>
</entry>
<entry>
<title>config: add tweak.min-stride-alignment</title>
<updated>2025-10-05T07:40:20Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-10-04T07:29:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=fac399415452edba6f20986e5f8fa479863582fe'/>
<id>urn:sha1:fac399415452edba6f20986e5f8fa479863582fe</id>
<content type='text'>
This allows the user to configure the value by which a surface
buffer's stride must be an even multiple of.

This can be used to ensure the stride meets the GPU driver's
requirements for direct import.

Defaults to 256. Set to 0 to disable.

Closes #2182
</content>
</entry>
<entry>
<title>shm: don't set pixman_fmt_without_alpha twice</title>
<updated>2025-07-21T11:49:57Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-07-21T11:49:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7ab43ebf7464ab72e2041de0a1112feaa81ea89e'/>
<id>urn:sha1:7ab43ebf7464ab72e2041de0a1112feaa81ea89e</id>
<content type='text'>
When selecting 16-bit surfaces, we set pixman_fmt_without_alpha twice,
and never set pixman_fmt_with_alpha.

This caused 10-bit surfaces to be used instead, since it checks if
pixman_fmt_with_alpha has been overridden or not.
</content>
</entry>
<entry>
<title>config: tweak.surface-bit-depth: add support for 16-bit surfaces</title>
<updated>2025-05-03T07:04:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-05-01T07:37:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=970e13db8deebf6c7542c7aede4f34703fa86769'/>
<id>urn:sha1:970e13db8deebf6c7542c7aede4f34703fa86769</id>
<content type='text'>
This adds supports for 16-bit surfaces, using the new
PIXMAN_a16b16g16r16 buffer format. This maps to
WL_SHM_FORMAT_ABGR16161616 (little-endian).

Use the new 16-bit surfaces by default, when
gamma-correct-blending=yes.
</content>
</entry>
<entry>
<title>config: tweak.surface-bit-depth now defaults to 'auto'</title>
<updated>2025-05-01T06:54:30Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-05-01T06:34:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e5a0755451b736c635be58764799ef8d7b536e8d'/>
<id>urn:sha1:e5a0755451b736c635be58764799ef8d7b536e8d</id>
<content type='text'>
When set to 'auto', use 10-bit surfaces if gamma-correct blending is
enabled, and 8-bit surfaces otherwise.

Note that we may still fallback to 8-bit surfaces (without disabling
gamma-correct blending) if the compositor does not support 10-bit
surfaces.

Closes #2082
</content>
</entry>
<entry>
<title>render: gamma-correct blending</title>
<updated>2025-03-05T17:45:01Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-02-21T10:01:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=ccf625b9914917e131beb83379c526bab1927edc'/>
<id>urn:sha1:ccf625b9914917e131beb83379c526bab1927edc</id>
<content type='text'>
This implements gamma-correct blending, which mainly affects font
rendering.

The implementation requires compile-time availability of the new
color-management protocol (available in wayland-protocols &gt;= 1.41),
and run-time support for the same in the compositor (specifically, the
EXT_LINEAR TF function and sRGB primaries).

How it works: all colors are decoded from sRGB to linear (using a
lookup table, generated in the exact same way pixman generates it's
internal conversion tables) before being used by pixman. The resulting
image buffer is thus in decoded/linear format. We use the
color-management protocol to inform the compositor of this, by tagging
the wayland surfaces with the 'ext_linear' image attribute.

Sixes: all colors are sRGB internally, and decoded to linear before
being used in any sixels. Thus, the image buffers will contain linear
colors. This is important, since otherwise there would be a
decode/encode penalty every time a sixel is blended to the grid.

Emojis: we require fcft &gt;= 3.2, which adds support for sRGB decoding
color glyphs. Meaning, the emoji pixman surfaces can be blended
directly to the grid, just like sixels.

Gamma-correct blending is enabled by default *when the compositor
supports it*. There's a new option to explicitly enable/disable it:
gamma-correct-blending=no|yes. If set to 'yes', and the compositor
does not implement the required color-management features, warning
logs are emitted.

There's a loss of precision when storing linear pixels in 8-bit
channels. For this reason, this patch also adds supports for 10-bit
surfaces. For now, this is disabled by default since such surfaces
only have 2 bits for alpha. It can be enabled with
tweak.surface-bit-depth=10-bit.

Perhaps, in the future, we can enable it by default if:

* gamma-correct blending is enabled
* the user has not enabled a transparent background
</content>
</entry>
<entry>
<title>shm: codespell: re-using -&gt; reusing</title>
<updated>2025-01-22T07:04:17Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2025-01-22T06:50:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5e65f3f07e41065a6fbd1af74e43acd553e1d5b5'/>
<id>urn:sha1:5e65f3f07e41065a6fbd1af74e43acd553e1d5b5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: fix compilation when FORCED_DOUBLE_BUFFERING is enabled</title>
<updated>2024-09-21T07:11:07Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-09-20T15:06:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=046d9596575c2dfac5db0d151179711f89b52661'/>
<id>urn:sha1:046d9596575c2dfac5db0d151179711f89b52661</id>
<content type='text'>
</content>
</entry>
<entry>
<title>notify: don't close FD 0</title>
<updated>2024-07-30T14:33:19Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-07-30T14:33:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0a5ba708e4a8448a0d29d4e263f939c9d1d2b953'/>
<id>urn:sha1:0a5ba708e4a8448a0d29d4e263f939c9d1d2b953</id>
<content type='text'>
This fixes a regression where closing a terminal instance, or hard- or
soft-resetting a terminal caused FD 0 to be closed.

This meant it became re-usable. Usually, by memfd_create() when
allocating a new surface buffer. So far nothing _really_ bad has
happened.

But what if FD 0 is now used by a memfd, and we close _another_
terminal instance?

This causes our memfd to be closed. And then, when e.g. trying to
scroll the terminal content: fallocate() fails with bad FD.
</content>
</entry>
<entry>
<title>shm: discard shm buffers with mis-matching alpha-setting</title>
<updated>2024-06-24T18:09:37Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-06-24T15:55:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=795e39de1a187f6a09aad02410f69f19781bd3c1'/>
<id>urn:sha1:795e39de1a187f6a09aad02410f69f19781bd3c1</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: minor optimization</title>
<updated>2024-05-22T12:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-05-22T12:06:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=f64cc04fe6822d4efe27d85bebb9d46477be4815'/>
<id>urn:sha1:f64cc04fe6822d4efe27d85bebb9d46477be4815</id>
<content type='text'>
Don't retry memfd_create() without MFD_NOEXEC_SEAL is 0.

The overall logic is this:

* Try memfd_create() with MFD_NOEXEC_SEAL
* If that fails (which it does, on older kernels), try without the flag

If compiling against an older kernel, or on a system that doesn't
support the noexec seal, MFD_NOEXEC_SEAL is 0.

In this case, there's little point in retrying memfd_create a second
time, with the exact same set of flags.
</content>
</entry>
<entry>
<title>shm: use XRGB surfaces when we know we wont be using transparency</title>
<updated>2024-02-21T15:29:10Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-02-21T15:29:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=67f97cbca1d9c1396537d0f04afb5a336ac46855'/>
<id>urn:sha1:67f97cbca1d9c1396537d0f04afb5a336ac46855</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Don't use fancy Unicode quotes, stick to ASCII</title>
<updated>2024-02-06T11:36:45Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2024-02-06T11:36:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7999975016a57cc0a2c2e20bc55f29de32df7044'/>
<id>urn:sha1:7999975016a57cc0a2c2e20bc55f29de32df7044</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Replace unchecked allocations with calls to xmalloc.h functions</title>
<updated>2024-01-25T07:03:50Z</updated>
<author>
<name>Craig Barnes</name>
<email>craigbarnes@protonmail.com</email>
</author>
<published>2024-01-25T07:03:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=91b22ae21acd0b3171814b47b0dead027f8da779'/>
<id>urn:sha1:91b22ae21acd0b3171814b47b0dead027f8da779</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: memfd_create: fallback to not using MFD_NOEXEC_SEAL</title>
<updated>2023-10-12T14:16:11Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2023-10-12T14:16:11Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=c006ac3a079d00e30f9d1cd7986d8112724629b4'/>
<id>urn:sha1:c006ac3a079d00e30f9d1cd7986d8112724629b4</id>
<content type='text'>
MFD_NOEXEC_SEAL was introduced in linux 6.3. Kernels before that
will *reject* memfd_create() calls that set it.

This caused foot to exit (i.e. not start at all), when compiled on
linux &gt;= 6.3, but run on linux &lt; 6.3.

We _do_ want to use MFD_NOEXEC_SEAL, since a) our memory mapped really
shouldn't be executable, and b) to silence a warning on linux &gt;= 6.3.

To handle all cases, first try *with* MFD_NOEXEC_SEAL. If that fails
with EINVAL, retry *without* it.

Closes #1514
</content>
</entry>
<entry>
<title>render: more fine-grained wayland surface damage tracking</title>
<updated>2023-10-10T05:56:27Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2023-10-07T14:23:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=c50b1f990093a2a453288b976ef7f6d9a303f793'/>
<id>urn:sha1:c50b1f990093a2a453288b976ef7f6d9a303f793</id>
<content type='text'>
Before this patch. Wayland surface damage tracking was done on a
per-row basis. That is, even if just one cell was updated, the entire
row was "damaged".

Now, damage is per cell. This hopefully results in lower latencies in
many use cases, and especially on high DPI monitors.
</content>
</entry>
<entry>
<title>shm: move definition of FOOT_MFD_FLAGS to the top</title>
<updated>2023-10-08T09:03:13Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2023-10-08T09:03:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=e41555fe0ff0882b79b49c1f00c6b23caa1eaf70'/>
<id>urn:sha1:e41555fe0ff0882b79b49c1f00c6b23caa1eaf70</id>
<content type='text'>
</content>
</entry>
</feed>
