aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-03-22 19:36:15 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-03-22 20:05:00 +0000
commit7404ace40c1b54db14a95f3f64b9f92104e8024a (patch)
treed4cae50fc6e683cb9e269d98a7e36949017c3921
parentshm: scroll: no need to instantiate a new buffer when ftruncate() fails (diff)
shm: verify the system supports FALLOC_FL_PUNCH_HOLE
-rw-r--r--shm.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/shm.c b/shm.c
index 1d36137b..2f74fc0b 100644
--- a/shm.c
+++ b/shm.c
@@ -25,6 +25,9 @@
static tll(struct buffer) buffers;
+static bool can_punch_hole = false;
+static bool can_punch_hole_initialized = false;
+
static void
buffer_destroy(struct buffer *buf)
{
@@ -226,6 +229,12 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie)
goto err;
}
+ if (!can_punch_hole_initialized) {
+ can_punch_hole_initialized = true;
+ can_punch_hole = fallocate(
+ pool_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 1) == 0;
+ }
+
/* Push to list of available buffers, but marked as 'busy' */
tll_push_back(
buffers,
@@ -274,6 +283,9 @@ shm_scroll(struct wl_shm *shm, struct buffer *buf, int rows)
assert(buf->real_mmapped);
assert(buf->fd >= 0);
+ if (!can_punch_hole)
+ return false;
+
LOG_DBG("scrolling %d rows (%d bytes)", rows, rows * buf->stride);
assert(rows > 0);