aboutsummaryrefslogtreecommitdiff
path: root/shm.c (follow)
Commit message (Collapse)AuthorAgeLines
* shm: clang 23 complains max_pool_size is unused on x86 (which it is)Daniel Eklöf2026-09-18-0/+1
|
* shm: don't bother with xrgb surfaces, always use argbDaniel Eklöf2026-01-04-58/+26
| | | | | | | | | | | | | | | 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.
* shm: revert part of 299186a6547f6e038ee6f3822caf9a0fdfabceefDaniel Eklöf2025-12-17-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* render: when double-buffering, pre-apply previous frame's damage earlyDaniel Eklöf2025-10-10-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* shm: page-align the memfd size (also needed for GPU direct import)Daniel Eklöf2025-10-05-4/+8
|
* config: add tweak.min-stride-alignmentDaniel Eklöf2025-10-05-1/+16
| | | | | | | | | | | | 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
* shm: don't set pixman_fmt_without_alpha twiceDaniel Eklöf2025-07-21-1/+1
| | | | | | | | 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.
* config: tweak.surface-bit-depth: add support for 16-bit surfacesDaniel Eklöf2025-05-03-8/+45
| | | | | | | | | 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.
* config: tweak.surface-bit-depth now defaults to 'auto'Daniel Eklöf2025-05-01-3/+12
| | | | | | | | | | | 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
* render: gamma-correct blendingDaniel Eklöf2025-03-05-4/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 >= 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 >= 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
* shm: codespell: re-using -> reusingDaniel Eklöf2025-01-22-1/+1
|
* shm: fix compilation when FORCED_DOUBLE_BUFFERING is enabledDaniel Eklöf2024-09-21-2/+2
|
* notify: don't close FD 0Daniel Eklöf2024-07-30-1/+1
| | | | | | | | | | | | | | | 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.
* shm: discard shm buffers with mis-matching alpha-settingDaniel Eklöf2024-06-24-1/+3
|
* shm: minor optimizationDaniel Eklöf2024-05-22-1/+1
| | | | | | | | | | | | | | | 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.
* shm: use XRGB surfaces when we know we wont be using transparencyDaniel Eklöf2024-02-21-8/+13
|
* Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf2024-02-06-4/+4
|
* Replace unchecked allocations with calls to xmalloc.h functionsCraig Barnes2024-01-25-1/+1
|
* shm: memfd_create: fallback to not using MFD_NOEXEC_SEALDaniel Eklöf2023-10-12-5/+16
| | | | | | | | | | | | | | | | 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 >= 6.3, but run on linux < 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 >= 6.3. To handle all cases, first try *with* MFD_NOEXEC_SEAL. If that fails with EINVAL, retry *without* it. Closes #1514
* render: more fine-grained wayland surface damage trackingDaniel Eklöf2023-10-10-3/+11
| | | | | | | | | 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.
* shm: move definition of FOOT_MFD_FLAGS to the topDaniel Eklöf2023-10-08-5/+6
|
* shm: if defined, set MFD_NOEXEC_SEAL flag for memfd_create6t8k2023-10-05-1/+6
| | | | | | | | | | Effective from Linux 6.3.0 onward, this creates the memfd without execute permissions and prevents that setting from ever being changed. This is a defense-in-depth security measure and prevents a respective kernel warning from being emitted. See https://lwn.net/Articles/918106/ for more information.
* Codespell fixesDaniel Eklöf2023-10-03-1/+1
|
* Codespell fixesDaniel Eklöf2023-10-03-1/+1
|
* render: fix application of old scroll damage when double bufferingDaniel Eklöf2022-09-23-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | On compositors that forces us to double buffer, we need to re-apply the last frame’s damage to the current frame (which uses the buffer from the next-to-last frame). General cell updates are handled by simply copying from the last frame’s pixman buffer to the current frame’s. In an attempt to improve performance, scroll damage were up until now handled by re-playing the last frame’s scroll damage (on the current frame’s buffer). This does not work, and resulted in glitches when scrolling in the scrollback. This patch does the following: * grid_render_scroll{,_reverse}() now update the buffer’s "dirty" region. This means the generic copy-old-frames-buffer handles the scroll damage (albeit in, potentially, a less efficient way). * Tracking of, and re-applying old scroll damage is completely removed. Closes #1173
* shm: add shm_did_not_use_buffer()Daniel Eklöf2022-04-16-0/+7
| | | | | | | | This allows a caller to return a buffer (obtained with shm_get_buffer()) to the pool, The buffer must not have been used. I.e. it must not have been attached and committed to a wayland surface.
* replace gettimeofday with clock_gettimePranjal Kole2022-01-15-40/+43
| | | | | | | | | | | | | POSIX.1-2008 has marked gettimeofday(2) as obsolete, recommending the use of clock_gettime(2) instead. CLOCK_MONOTONIC has been used instead of CLOCK_REALTIME because it is unaffected by manual changes in the system clock. This makes it better for our purposes, namely, measuring the difference between two points in time. tv_sec has been casted to long in most places since POSIX does not define the actual type of time_t.
* shm: get_buffer(): make sure buffer->busy is setDaniel Eklöf2021-12-18-10/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | When going through the cached buffers, we only set buffer->busy on the *first* re-usable buffer we found. In some cases, we will find more than one re-usable buffer. In this case, we select the “youngest” one (i.e the one most recently used, in the hopes that we can use damage tracking instead of re-rendering the entire buffer). If the “current” buffer is younger than the previously detected, re-usable, buffer, then we unref:ed the previously selected buffer, and replaced it with the current one. But, we did not sanitize it. That is, we did not: * set buffer->busy * clear its dirty region * clear its scroll damage That buffer would eventually get rendered to, and committed to the compositor. Later, the compositor would free it. And there, in our buffer_release() callback, we’d assert that buffer->busy was set. And fail. Closes #844
* fix crashes when resizing after CSD enabled at runtime with csd.size = 0feeptr2021-10-04-1/+3
|
* shm: get_many(): allow “NULL” buffers - buffers where width or height is 0Daniel Eklöf2021-07-18-0/+4
| | | | | | | | 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.
* shm: chain_free: BUG() if there are buffers remaining after purgeDaniel Eklöf2021-07-17-0/+11
| | | | | | | | | 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().
* shm: get_buffer: purge mismatching buffers in first buffer iterationDaniel Eklöf2021-07-17-26/+6
| | | | | | 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.
* shm: refactor: move away from a single, global, buffer listDaniel Eklöf2021-07-17-103/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* shm: remove deferred buffers from main list immediatelyDaniel Eklöf2021-07-17-53/+90
| | | | | | | | | | | | | 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.
* shm: replace 'locked' attribute with a ref-counterDaniel Eklöf2021-07-17-44/+50
| | | | | | | | | | | | | | | | | 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.
* shm: we may exit with busy buffers remaining (seen on KDE)Daniel Eklöf2021-07-17-7/+21
|
* shm: move ‘size’ to the private buffer structDaniel Eklöf2021-07-17-15/+16
|
* shm: rename buffer.mmapped to buffer.dataDaniel Eklöf2021-07-17-8/+10
|
* shm: split up buffer struct into internal/private and public partsDaniel Eklöf2021-07-17-79/+126
|
* shm: codespellDaniel Eklöf2021-07-15-1/+1
|
* shm: auto-purge when we have multiple buffers eligible for re-useDaniel Eklöf2021-07-15-0/+9
| | | | | | | | | | | | | | 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.
* shm: add shm_get_many() - allows buffers to share a single poolDaniel Eklöf2021-07-15-120/+218
| | | | | | | | | | | | | | 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.
* shm: reset buffer pool FD when we close itDaniel Eklöf2021-07-14-0/+1
| | | | | | | | | | | | | | 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.
* shm: close pool FD if buffer doesn’t support SHM scrollingDaniel Eklöf2021-07-11-1/+6
| | | | | | | | | 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.
* shm: clear buffer’s dirty region before returning a cached bufferDaniel Eklöf2021-05-12-0/+1
| | | | A non-busy buffer should always have an empty dirty region
* shm: set ‘age’ in newly allocated buffers to something largeDaniel Eklöf2021-05-12-1/+1
| | | | This ensures we don’t try to do a partial update of fresh buffer.
* shm: free scroll damage before returning cached bufferDaniel Eklöf2021-05-12-0/+2
|
* render: code cleanup, log double buffering timeDaniel Eklöf2021-05-12-1/+1
| | | | | | | | | | | * Break out cursor cell dirtying to separate functions * Break out handling of double buffering * Handle buffers with age > 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.
* shm: add damage tracking to bufferDaniel Eklöf2021-05-12-0/+5
|
* shm: track busy buffers’ age, and add compile-time option to force double bufferingDaniel Eklöf2021-05-12-11/+26
| | | | | | | | | 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).
* shm: don’t check for __i386__ and __x86_64__ - there are other architectures out thereDaniel Eklöf2021-01-23-11/+11
| | | | | Instead, check for __SIZEOF_POINTER__ == 8, since what we’re really interested in is whether we have enough virtual address space or not.
* shm: unbreak build without memfd_createJan Beich2021-01-23-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New FreeBSD versions have memfd_create but other BSDs don't. pgo/pgo.c:260:22: error: implicit declaration of function 'memfd_create' is invalid in C99 [-Werror,-Wimplicit-function-declaration] int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC); ^ pgo/pgo.c:260:52: error: use of undeclared identifier 'MFD_CLOEXEC' int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC); ^ shm.c:13:10: fatal error: 'linux/mman.h' file not found #include <linux/mman.h> ^~~~~~~~~~~~~~ shm.c:277:15: error: implicit declaration of function 'memfd_create' is invalid in C99 [-Werror,-Wimplicit-function-declaration] pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:277:60: error: use of undeclared identifier 'MFD_CLOEXEC' pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:277:74: error: use of undeclared identifier 'MFD_ALLOW_SEALING' pool_fd = memfd_create("foot-wayland-shm-buffer-pool", MFD_CLOEXEC | MFD_ALLOW_SEALING); ^ shm.c:339:15: error: use of undeclared identifier 'F_SEAL_GROW' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:339:29: error: use of undeclared identifier 'F_SEAL_SHRINK' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:339:71: error: use of undeclared identifier 'F_SEAL_SEAL' F_SEAL_GROW | F_SEAL_SHRINK | /*F_SEAL_FUTURE_WRITE |*/ F_SEAL_SEAL) < 0) ^ shm.c:338:24: error: use of undeclared identifier 'F_ADD_SEALS' if (fcntl(pool_fd, F_ADD_SEALS, ^
* shm: disable fallocate optimization if not supportedJan Beich2021-01-23-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | shm.c:301:26: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] can_punch_hole = fallocate( ^ shm.c:302:22: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0; ^ shm.c:302:45: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0; ^ shm.c:432:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:434:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:434:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:501:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:503:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:503:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:597:9: error: implicit declaration of function 'fallocate' is invalid in C99 [-Werror,-Wimplicit-function-declaration] if (fallocate( ^ shm.c:599:13: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^ shm.c:599:36: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, ^
* shm: silence -Wunused-function on i386Jan Beich2021-01-23-0/+2
| | | | | | shm.c:134:1: error: unused function 'page_size' [-Werror,-Wunused-function] page_size(void) ^
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-24/+24
|
* Print stack trace on assert() failure or when calling fatal_error()Craig Barnes2021-01-16-1/+1
| | | | | | Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
* shm: fix badly indented function return typeDaniel Eklöf2020-12-07-1/+1
|
* shm: MAP_UNINITIALIZED is a linux only mmap flagDaniel Eklöf2020-10-10-0/+4
|
* fix some buggy comparisons relating to signed/unsigned typesCraig Barnes2020-08-25-2/+4
|
* Cast printf formatter %p arguments to void*Daniel Eklöf2020-08-23-4/+4
|
* shm: don't even try to punch a memfd hole in 32-bitDaniel Eklöf2020-08-11-0/+6
| | | | | This ensures we don't issue a warning if we fail, something that will just confuse users, as SHM scrolling is disabled in 32-bit anyway.
* Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes2020-08-08-1/+2
|
* Replace GCC "unused" and "format" attributes with portable macrosCraig Barnes2020-08-07-1/+2
|
* render: re-write cell clipping to use pixman destination clippingDaniel Eklöf2020-06-04-11/+23
| | | | | | | | | | | | 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.
* shm: #ifdef conditional code to measure total size of SHM allocationsDaniel Eklöf2020-04-18-0/+20
|
* shm: memfd seal failures are not fatal errorsDaniel Eklöf2020-04-03-1/+1
|
* conf: max-shm-pool-size-mb=0 now disables SHM scrollingDaniel Eklöf2020-03-26-7/+6
|
* shm: make max pool size user configurable (via a 'tweak' setting)Daniel Eklöf2020-03-25-11/+21
|
* shm: handle ftruncate failureDaniel Eklöf2020-03-25-1/+5
|
* shm: seal the memfdDaniel Eklöf2020-03-25-0/+9
| | | | | | This both prevents accidental resizing of the memfd, and allows the Wayland server to optimze reads from the buffer - it no longer has to setup SIGBUS handlers.
* shm: scroll: keep shm pool around, and fix its size at max allowedDaniel Eklöf2020-03-25-124/+129
| | | | | | | | | | | | | | | | | 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.
* shm: scroll: implement offset wrap-aroundDaniel Eklöf2020-03-24-41/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* shm: shm_scroll(): initial implementation of reverse scrollingDaniel Eklöf2020-03-23-8/+92
| | | | | | | | | Implemented by truncating the file size and moving the offset backwards. This means we can only reverse scroll when we've previously scrolled forward. TODO: figure out if we can somehow do fast reverse scrolling even though offset is 0 (or well, less than required for scrolling).
* shm: scroll: move top/bottom region handling from renderer into shmDaniel Eklöf2020-03-23-6/+43
| | | | | This allows us to restore the regions without copying the contents to temporary memory.
* shm: add shm_can_scroll()Daniel Eklöf2020-03-23-0/+7
|
* shm: print performance warning when FALLOC_FL_PUNCH_HOLE isn't supportedDaniel Eklöf2020-03-22-3/+6
|
* shm: verify the system supports FALLOC_FL_PUNCH_HOLEDaniel Eklöf2020-03-22-0/+12
|
* shm: scroll: no need to instantiate a new buffer when ftruncate() failsDaniel Eklöf2020-03-22-21/+1
|
* shm: new function, shm_scroll()Daniel Eklöf2020-03-22-68/+199
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* shm: log size of purged bufferDaniel Eklöf2020-03-18-2/+3
|
* shm: we don't really handle SHM failures, so just abort()Daniel Eklöf2020-03-10-0/+2
|
* shm: mmap returns MAP_FAILED, so use that as guard valueDaniel Eklöf2020-03-10-2/+2
|
* shm: set pool_fd=1 after closing it, to avoid double-closing on errorDaniel Eklöf2020-03-10-1/+1
|
* shm: try to mmap with MAP_UNINITIALIZEDDaniel Eklöf2020-03-10-1/+2
| | | | | This flag is expected to be ignored on most systems, but can't hurt to try.
* shm: log errno error message tooDaniel Eklöf2020-03-10-1/+1
|
* shm: log 'size' when failing to fallocate()Daniel Eklöf2020-03-01-1/+1
|
* shm: handle EINTR in posix_fallocate()Daniel Eklöf2020-02-25-1/+4
|
* shm: prefer posix_fallocate over ftruncateDaniel Eklöf2020-02-15-3/+14
|
* fcft: include <fcft/fcft.h>, and use fcft/stride.h instead of local copyDaniel Eklöf2019-12-01-1/+1
|
* tllist: is now an external "library", so use <> includesDaniel Eklöf2019-11-17-1/+2
|
* scan-build: fix a couple of minor warnings from a scan-build runDaniel Eklöf2019-11-05-1/+1
|
* shm: purge buffers *before* we (maybe) return one from the cacheDaniel Eklöf2019-11-02-16/+16
|
* shm: automatic buffer purging is now delayed one cycleDaniel Eklöf2019-11-02-5/+20
| | | | | This ensures we don't purge a buffer that a user is holding a reference to.
* shm: add shm_purge()Daniel Eklöf2019-11-01-0/+17
| | | | Destroys *all* buffers associated with the specified cookie.
* shm: purge unused buffersDaniel Eklöf2019-11-01-7/+28
| | | | | | When we need to create a new buffer (because the cache doesn't have any buffers of correct size, or because they're all busy), purge buffers with a size mismatch.
* shm: associate a 'cookie' with each bufferDaniel Eklöf2019-11-01-4/+10
| | | | | | | When re-using a buffer from cache, only re-use ones with a matching cookie. This prevents contention between multiple terminal windows.
* shm: get_buffer(): remove 'copies' argument; it's not usedDaniel Eklöf2019-11-01-3/+1
|
* shm: add debug logging of how large the allocated memory buffer isDaniel Eklöf2019-11-01-0/+3
|
* shm: fix name of memfdDaniel Eklöf2019-11-01-1/+1
|
* refactor: break out stride calculation to new functionDaniel Eklöf2019-08-18-4/+2
|