aboutsummaryrefslogtreecommitdiff
path: root/shm.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-10-04 07:29:56 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-10-05 07:40:20 +0000
commitfac399415452edba6f20986e5f8fa479863582fe (patch)
treeab7cd95c8fd2af7d3ca36c727191a9dac0dfa77d /shm.c
parentterm: osc8: tag *all* cells in a multi-column character as an URI (diff)
config: add tweak.min-stride-alignment
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
Diffstat (limited to 'shm.c')
-rw-r--r--shm.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/shm.c b/shm.c
index 4680c12c..7b13db9b 100644
--- a/shm.c
+++ b/shm.c
@@ -13,7 +13,6 @@
#include <pixman.h>
-#include <fcft/stride.h>
#include <tllist.h>
#define LOG_MODULE "shm"
@@ -21,6 +20,7 @@
#include "log.h"
#include "debug.h"
#include "macros.h"
+#include "stride.h"
#include "xmalloc.h"
#if !defined(MAP_UNINITIALIZED)
@@ -61,6 +61,8 @@ static off_t max_pool_size = 512 * 1024 * 1024;
static bool can_punch_hole = false;
static bool can_punch_hole_initialized = false;
+static size_t min_stride_alignment = 0;
+
struct buffer_pool {
int fd; /* memfd */
struct wl_shm_pool *wl_pool;
@@ -113,6 +115,12 @@ shm_set_max_pool_size(off_t _max_pool_size)
max_pool_size = _max_pool_size;
}
+void
+shm_set_min_stride_alignment(size_t _min_stride_alignment)
+{
+ min_stride_alignment = _min_stride_alignment;
+}
+
static void
buffer_destroy_dont_close(struct buffer *buf)
{
@@ -342,6 +350,13 @@ get_new_buffers(struct buffer_chain *chain, size_t count,
? chain->pixman_fmt_with_alpha
: chain->pixman_fmt_without_alpha,
widths[i]);
+
+ if (min_stride_alignment > 0) {
+ const size_t m = min_stride_alignment;
+ stride[i] = (stride[i] + m - 1) / m * m;
+ }
+
+ xassert(min_stride_alignment == 0 || stride[i] % min_stride_alignment == 0);
sizes[i] = stride[i] * heights[i];
total_size += sizes[i];
}