<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/shm.c, branch 1.9.2</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.2</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.2'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-07-18T14:44:49Z</updated>
<entry>
<title>shm: get_many(): allow “NULL” buffers - buffers where width or height is 0</title>
<updated>2021-07-18T14:44:49Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-18T14:44:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5b6a2b0eaff1ffef84d728a6c76c044c7f01a1d8'/>
<id>urn:sha1:5b6a2b0eaff1ffef84d728a6c76c044c7f01a1d8</id>
<content type='text'>
When a zero-sized buffer is requested, simply return a NULL buffer,
instead of crashing with a Wayland protocol error.

This makes it easier to request many buffers, where some may be
zero-sized, without having to pack the width/height and bufs arrays.
</content>
</entry>
<entry>
<title>shm: chain_free: BUG() if there are buffers remaining after purge</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:49:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=6657146a207834ac44425c01703935dee6d61d41'/>
<id>urn:sha1:6657146a207834ac44425c01703935dee6d61d41</id>
<content type='text'>
There may be buffers left, if their destruction has been
deferred. However, they should be on the 'deferred' list, not the
chain's buffer list.

If there are buffers left on the chain's list, that means someone
forgot to call shm_unref().
</content>
</entry>
<entry>
<title>shm: get_buffer: purge mismatching buffers in first buffer iteration</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:49:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0751172b922e32a9c6d54b52e721c934cb88fe9f'/>
<id>urn:sha1:0751172b922e32a9c6d54b52e721c934cb88fe9f</id>
<content type='text'>
There's no longer any need to defer purging of mismatching buffer
(i.e. buffers whose width/height doesn't match the requested ones) to
after the cache lookup loop.
</content>
</entry>
<entry>
<title>shm: refactor: move away from a single, global, buffer list</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:48:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=53851e13ec976001cdec2077d7963c292bcd6d20'/>
<id>urn:sha1:53851e13ec976001cdec2077d7963c292bcd6d20</id>
<content type='text'>
Up until now, *all* buffers have been tracked in a single, global
buffer list. We've used 'cookies' to separate buffers from different
contexts (so that shm_get_buffer() doesn't try to re-use e.g. a
search-box buffer for the main grid).

This patch refactors this, and completely removes the global
list.

Instead of cookies, we now use 'chains'. A chain tracks both the
properties to apply to newly created buffers (scrollable, number of
pixman instances to instantiate etc), as well as the instantiated
buffers themselves.

This means there's strictly speaking not much use for shm_fini()
anymore, since its up to the chain owner to call shm_chain_free(),
which will also purge all buffers.

However, since purging a buffer may be deferred, if the buffer is
owned by the compositor at the time of the call to shm_purge() or
shm_chain_free(), we still keep a global 'deferred' list, on to which
deferred buffers are pushed. shm_fini() iterates this list and
destroys the buffers _even_ if they are still owned by the
compositor. This only happens at program termination, and not when
destroying a terminal instance. I.e. closing a window in a “foot
--server” does *not* trigger this.

Each terminal instatiates a number of chains, and these chains are
destroyed when the terminal instance is destroyed. Note that some
buffers may be put on the deferred list, as mentioned above.
</content>
</entry>
<entry>
<title>shm: remove deferred buffers from main list immediately</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:48:18Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=4efb34927eb46d8b12fc0d5638653cf23839d7dc'/>
<id>urn:sha1:4efb34927eb46d8b12fc0d5638653cf23839d7dc</id>
<content type='text'>
When unref:ing a "busy" buffer, destruction is (still) deferred to the
buffer release event.

However, we now move the buffer off the buffer list immediately, and
instead push it to a 'deferred' list. This prevents buffer re-use of
buffers scheduled for destruction.

It also means less buffers to iterate through when trying to find a
re-usable buffer in shm_get_buffer(), since we no longer have to wade
through a potentially long list of to-be-deleted buffers.
</content>
</entry>
<entry>
<title>shm: replace 'locked' attribute with a ref-counter</title>
<updated>2021-07-17T17:14:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:47:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=232fb20269b68157874f57d676c1b0b95c2386aa'/>
<id>urn:sha1:232fb20269b68157874f57d676c1b0b95c2386aa</id>
<content type='text'>
The initial ref-count is either 1 or 0, depending on whether the
buffer is supposed to be released "immeidately" (meaning, as soon as
the compositor releases it).

Two new user facing functions have been added: shm_addref() and
shm_unref().

Our renderer now uses these two functions instead of manually setting
and clearing the 'locked' attribute.

shm_unref() will decrement the ref-counter, and destroy the buffer
when the counter reaches zero. Except if the buffer is currently
"busy" (compositor owned), in which case destruction is deferred to
the release event. The buffer is still removed from the list though.
</content>
</entry>
<entry>
<title>shm: we may exit with busy buffers remaining (seen on KDE)</title>
<updated>2021-07-17T17:14:41Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-16T14:47:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=69260dd9604f39f5e7270ac44502c7e60618500b'/>
<id>urn:sha1:69260dd9604f39f5e7270ac44502c7e60618500b</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: move ‘size’ to the private buffer struct</title>
<updated>2021-07-17T17:14:41Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T20:30:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=99ea47c97ac6884e469d1d2cdb76220f3398a737'/>
<id>urn:sha1:99ea47c97ac6884e469d1d2cdb76220f3398a737</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: rename buffer.mmapped to buffer.data</title>
<updated>2021-07-17T17:14:41Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T20:18:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=9b6cee825beb927ec24ef28f0f162623db218fe2'/>
<id>urn:sha1:9b6cee825beb927ec24ef28f0f162623db218fe2</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: split up buffer struct into internal/private and public parts</title>
<updated>2021-07-17T17:14:41Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T20:17:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=75f7f21a48f3c4054cae024ff769b781481786a7'/>
<id>urn:sha1:75f7f21a48f3c4054cae024ff769b781481786a7</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: codespell</title>
<updated>2021-07-15T17:40:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T17:40:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=931595bda573588d8529565869aafa3574179011'/>
<id>urn:sha1:931595bda573588d8529565869aafa3574179011</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: auto-purge when we have multiple buffers eligible for re-use</title>
<updated>2021-07-15T17:19:31Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T17:19:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a486851bdd6bbf2fee9a5009c30770f22ca102ed'/>
<id>urn:sha1:a486851bdd6bbf2fee9a5009c30770f22ca102ed</id>
<content type='text'>
It may happen that we end up with multiple non-busy, same-sized
buffers for the same cookie (context), and thus eligible for re-use.

Before this patch, we would keep all those buffers around. This is
completely unnecessary. Under normal circumstances, we’ll either be
re-using a single buffer, or swap between two. In the second case, the
“other” buffer is always busy, and thus not eligible for re-use.

So, if we _do_ detect multiple, re-usable buffers, pick the one with
the lowest “age” (increasing the chance of applying damage tracking,
instead of re-drawing everything), and mark the other one for purging.
</content>
</entry>
<entry>
<title>shm: add shm_get_many() - allows buffers to share a single pool</title>
<updated>2021-07-15T16:39:23Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T16:32:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=7533684d8fa85c33756d18841f2bac5379f40f8b'/>
<id>urn:sha1:7533684d8fa85c33756d18841f2bac5379f40f8b</id>
<content type='text'>
shm_get_many() always returns new buffers (i.e. never old, cached
ones). The newly allocated buffers are also marked for immediate
purging, meaning they’ll be destroyed on the next call to either
shm_get_buffer(), or shm_get_many().

Furthermore, we add a new attribute, ‘locked’, to the buffer
struct. When auto purging buffers, look at this instead of comparing
cookies.

Buffer consumers are expected to set ‘locked’ while they hold a
reference to it, and don’t want it destroyed behind their back.
</content>
</entry>
<entry>
<title>shm: reset buffer pool FD when we close it</title>
<updated>2021-07-14T18:51:42Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-14T18:51:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=22651ed2217632a34bb9045306fac6ab9a2b3414'/>
<id>urn:sha1:22651ed2217632a34bb9045306fac6ab9a2b3414</id>
<content type='text'>
This fixes an issue where we ended up "double closing" buffer FDs.

In many cases (especially on compositors with SSDs) this was pretty
rare. And even when it did happen, the FD was normally unused, and
thus nothing bad happened.

However, by quickly resizing the window while using CSDs, it was
fairly easy to trigger this. We sometimes ended up closing the
TIOCSWINCH timer FD while thinking it was a buffer FD, but most of the
times we just ended up closing _another_ buffer’s pool FD, leading to
an immediate disconnect by the compositor.
</content>
</entry>
<entry>
<title>shm: close pool FD if buffer doesn’t support SHM scrolling</title>
<updated>2021-07-11T08:22:47Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-11T08:22:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=107cbb10157b165e19ed2f7fb747c60c670fe6c5'/>
<id>urn:sha1:107cbb10157b165e19ed2f7fb747c60c670fe6c5</id>
<content type='text'>
The only reason to keep the pool FD open is if we’re going to SHM
scroll the buffer; we need the FD for fallocate(FALLOC_FL_PUNCH_HOLE).

In all other cases, there’s absolutely no need to keep the FD
open. Thus, close it as soon as we’ve instantiated the buffer. This
frees up FDs, and help keep foot from FD ulimit.
</content>
</entry>
<entry>
<title>shm: clear buffer’s dirty region before returning a cached buffer</title>
<updated>2021-05-12T18:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-10T15:49:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=945a346596b163e459d7bd4896258f8546c861b2'/>
<id>urn:sha1:945a346596b163e459d7bd4896258f8546c861b2</id>
<content type='text'>
A non-busy buffer should always have an empty dirty region
</content>
</entry>
<entry>
<title>shm: set ‘age’ in newly allocated buffers to something large</title>
<updated>2021-05-12T18:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-10T15:48:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=37bbf44f6da1d273af718c504e1aeab5e39be493'/>
<id>urn:sha1:37bbf44f6da1d273af718c504e1aeab5e39be493</id>
<content type='text'>
This ensures we don’t try to do a partial update of fresh buffer.
</content>
</entry>
<entry>
<title>shm: free scroll damage before returning cached buffer</title>
<updated>2021-05-12T18:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-08T22:06:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0433ba8477792f01d8a501d572967efb69b10d69'/>
<id>urn:sha1:0433ba8477792f01d8a501d572967efb69b10d69</id>
<content type='text'>
</content>
</entry>
<entry>
<title>render: code cleanup, log double buffering time</title>
<updated>2021-05-12T18:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-08T08:25:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=34becf0df0915b3ed9534057c6e8c96d88625789'/>
<id>urn:sha1:34becf0df0915b3ed9534057c6e8c96d88625789</id>
<content type='text'>
* Break out cursor cell dirtying to separate functions
* Break out handling of double buffering
* Handle buffers with age &gt; 1 (we’re swapping between more than 2
  buffers)
* Detect full screen repaints, and skip re-applying old frame’s damage
* Use an allocated array insted of a tll list for old frame’s scroll damage
* When logging frame rendering time, including the amount used for
  double buffering.
</content>
</entry>
<entry>
<title>shm: add damage tracking to buffer</title>
<updated>2021-05-12T18:06:15Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-07T18:20:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=434c9c3a347e3afc96a6f2e1e8f2dae9379efcc3'/>
<id>urn:sha1:434c9c3a347e3afc96a6f2e1e8f2dae9379efcc3</id>
<content type='text'>
</content>
</entry>
</feed>
