<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mirrors/foot.git/shm.h, branch 1.9.1</title>
<subtitle>A fast, lightweight and minimalistic Wayland terminal emulator</subtitle>
<id>https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.1</id>
<link rel='self' href='https://git.0x0f.dev/mirrors/foot.git/atom?h=1.9.1'/>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/'/>
<updated>2021-07-17T17:14:42Z</updated>
<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: 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: 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: replace inclusion of terminal.h with a forward declaration of damage</title>
<updated>2021-07-17T17:14:41Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-07-15T20:21:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=f5da62c462430551869d830ef6c4302d4c3b4fea'/>
<id>urn:sha1:f5da62c462430551869d830ef6c4302d4c3b4fea</id>
<content type='text'>
It’s the only thing we “need” from terminal.h
</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: 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>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>
<entry>
<title>shm: track busy buffers’ age, and add compile-time option to force double buffering</title>
<updated>2021-05-12T18:06:04Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-05-07T16:18:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=c8b342ae51cba357f21a3f6c77f6a527981101b8'/>
<id>urn:sha1:c8b342ae51cba357f21a3f6c77f6a527981101b8</id>
<content type='text'>
By default, age all matching buffers that are busy (i.e. in use by the
compositor).

This allows us to detect whether we can apply the current frame’s
damage directly, or if we need to prepare the buffer first (e.g. copy
old buffer, or re-apply last frame’s damage etc).
</content>
</entry>
<entry>
<title>urls: initial support for detecting URLs and rendering jump-labels</title>
<updated>2021-02-07T15:33:31Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2021-01-31T10:12:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=2cc84db97978388475504592c88911046bcd2eb6'/>
<id>urn:sha1:2cc84db97978388475504592c88911046bcd2eb6</id>
<content type='text'>
The jump labels work, but is currently hardcoded to use xdg-open
</content>
</entry>
<entry>
<title>config: add tweak.render-timer option</title>
<updated>2020-08-13T16:35:17Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-08-13T16:35:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=17070a0d54e66641839805c68cfe1670c7012525'/>
<id>urn:sha1:17070a0d54e66641839805c68cfe1670c7012525</id>
<content type='text'>
This can be set to 'none' (the default), 'osd', 'log' or 'both'.

When 'osd' is enabled, we'll render the frame rendering time to a
sub-surface after each frame.

When 'log' is enabled, the frame rendering time is logged on stderr.
</content>
</entry>
<entry>
<title>shm: add shm_cookie_scrollback_indicator()</title>
<updated>2020-07-26T08:00:21Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-07-26T08:00:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=a39c490d9b1d82700dcd48cc9ac28d58051197f7'/>
<id>urn:sha1:a39c490d9b1d82700dcd48cc9ac28d58051197f7</id>
<content type='text'>
</content>
</entry>
<entry>
<title>render: re-write cell clipping to use pixman destination clipping</title>
<updated>2020-06-04T13:39:19Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-06-04T13:39:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=8b320ed29630e75c058bbf368ea5e2e9a68d0143'/>
<id>urn:sha1:8b320ed29630e75c058bbf368ea5e2e9a68d0143</id>
<content type='text'>
Our home rolled clip-to-cell code was, obviously, not correct.

The original problem was that we couldn't use pixman clipping since we
have multiple threads writing to the same pixman image, and thus there
would be races between the threads setting clipping.

The fix is actually simple - just instantiate one pixman
image (referencing the same backing image data) for each rendering
thread.
</content>
</entry>
<entry>
<title>shm: make max pool size user configurable (via a 'tweak' setting)</title>
<updated>2020-03-25T19:48:02Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-25T19:48:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0baa249d8b59007913dbf7db8aa8d94e6c2b9d44'/>
<id>urn:sha1:0baa249d8b59007913dbf7db8aa8d94e6c2b9d44</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: scroll: keep shm pool around, and fix its size at max allowed</title>
<updated>2020-03-25T17:26:58Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-25T17:26:58Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=03319560f5c7c908b1c1d229b3ba53ed1ac6b692'/>
<id>urn:sha1:03319560f5c7c908b1c1d229b3ba53ed1ac6b692</id>
<content type='text'>
This lessens the burden on (primarily) the compositor, since we no
longer tear down and re-create the SHM pool when scrolling.

The SHM pool is setup once, and its size is fixed at the maximum
allowed (512MB for now, 2GB would be possible).

This also allows us to mmap() the memfd once. The exposed raw pointer
is simply an offset from the memfd mmapping.

Note that this means e.g. rouge rendering code will be able to write
outside the buffer.

Finally, only do this if the caller explicitly wants to enable
scrolling. The memfd of other buffers are sized to the requested size.
</content>
</entry>
<entry>
<title>shm: scroll: implement offset wrap-around</title>
<updated>2020-03-24T16:46:48Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-24T16:46:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5c5f1d096c3a2a6cb8fb3dc5cb3efad5782c1d78'/>
<id>urn:sha1:5c5f1d096c3a2a6cb8fb3dc5cb3efad5782c1d78</id>
<content type='text'>
* Impose a maximum memfd size limit. In theory, this can be
  2GB (wl_shm_create_pool() is the limiting factor - its size argument
  is an int32_t). For now, use 256MB.

  This is mainly to reduce the amount of virtual address space used by
  the compositor, which keeps at least one mmapping (of the entire
  memfd) around. One mmapping *per terminal window* that is.

  Given that we have 128TB with 48-bit virtual addresses, we could
  probably bump this to 2GB without any issues. However, 256MB should
  be enough.

  TODO: check how much we typically move the offset when scrolling in
  a fullscreen window on a 4K monitor. 256MB may turn out to be too
  small.

  On 32-bit shm_scroll() is completely disabled. There simply isn't
  enough address space.

* Wrapping is done by moving the offset to "the other end" of the
  memfd, and copying the buffer contents to the new, wrapped offset.

  The "normal" scrolling code then does the actual scrolling. This
  means we'll re-instantiate all objects twice when wrapping.
</content>
</entry>
<entry>
<title>shm: scroll: move top/bottom region handling from renderer into shm</title>
<updated>2020-03-23T19:45:27Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-23T19:45:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=0de3701984ff3b09a804d8369dafc3cd5baefdcc'/>
<id>urn:sha1:0de3701984ff3b09a804d8369dafc3cd5baefdcc</id>
<content type='text'>
This allows us to restore the regions without copying the contents to
temporary memory.
</content>
</entry>
<entry>
<title>shm: add shm_can_scroll()</title>
<updated>2020-03-23T18:31:05Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-23T18:31:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=5ffee087481ddf3ad6e3b8e74c6acd3f0d736d82'/>
<id>urn:sha1:5ffee087481ddf3ad6e3b8e74c6acd3f0d736d82</id>
<content type='text'>
</content>
</entry>
<entry>
<title>shm: new function, shm_scroll()</title>
<updated>2020-03-22T19:06:44Z</updated>
<author>
<name>Daniel Eklöf</name>
<email>daniel@ekloef.se</email>
</author>
<published>2020-03-22T19:06:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0x0f.dev/mirrors/foot.git/commit/?id=1224807f503cf6aaef33388af682f754dcbbc3df'/>
<id>urn:sha1:1224807f503cf6aaef33388af682f754dcbbc3df</id>
<content type='text'>
This function "scrolls" the buffer by the specified number of (pixel)
rows.

The idea is move the image offset by re-sizing the underlying memfd
object. I.e. to scroll forward, increase the size of the memfd file,
and move the pixman image offset forward (and the Wayland SHM buffer
as well).

Only increasing the file size would, obviously, cause the memfd file
to grow indefinitely. To deal with this, we "punch" a whole from the
beginning of the file to the new offset. This frees the associated
memory.

Thus, while we have a memfd file whose size is (as seen by
e.g. fstat()) is ever growing, the actual file size is always the
original buffer size.

Some notes:

* FALLOC_FL_PUNCH_HOLE can be quite slow when the number of used pages
  to drop is large.

* all normal fallocate() usages have been replaced with ftruncate(),
  as this is *much* faster. fallocate() guarantees subsequent writes
  wont fail. I.e. it actually reserves (disk) space. While it doesn't
  allocate on-disk blocks for on-disk files, it *does* zero-initialize
  the in-memory blocks. And this is slow. ftruncate() doesn't do this.

TODO: implement reverse scrolling (i.e. a negative row count).
</content>
</entry>
</feed>
