From bed7b34c2857ebac8028e8b7a00b0bef0d831df0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 16 Aug 2019 20:40:32 +0200 Subject: wip: render background and glyphs using pixman --- shm.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'shm.c') diff --git a/shm.c b/shm.c index ca078544..19ec66db 100644 --- a/shm.c +++ b/shm.c @@ -7,6 +7,8 @@ #include #include +#include + #define LOG_MODULE "shm" #include "log.h" #include "tllist.h" @@ -61,6 +63,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) cairo_surface_t **cairo_surface = NULL; cairo_t **cairo = NULL; + pixman_image_t **pix = NULL; /* Backing memory for SHM */ pool_fd = memfd_create("f00sel-wayland-shm-buffer-pool", MFD_CLOEXEC); @@ -103,6 +106,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) /* Create a cairo surface around the mmapped memory */ cairo_surface = calloc(copies, sizeof(cairo_surface[0])); cairo = calloc(copies, sizeof(cairo[0])); + pix = calloc(copies, sizeof(pix[0])); for (size_t i = 0; i < copies; i++) { cairo_surface[i] = cairo_image_surface_create_for_data( @@ -120,6 +124,14 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) cairo_status_to_string(cairo_status(cairo[i]))); goto err; } + + pix[i] = pixman_image_create_bits_no_clear( + PIXMAN_a8r8g8b8, width, height, (uint32_t *)mmapped, stride); + + if (pix[i] == NULL) { + LOG_ERR("failed to create pixman image"); + goto err; + } } /* Push to list of available buffers, but marked as 'busy' */ @@ -128,13 +140,15 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) ((struct buffer){ .width = width, .height = height, + .stride = stride, .busy = true, .size = size, .mmapped = mmapped, .wl_buf = buf, .copies = copies, .cairo_surface = cairo_surface, - .cairo = cairo} + .cairo = cairo, + .pix = pix} ) ); @@ -155,6 +169,12 @@ err: cairo_surface_destroy(cairo_surface[i]); free(cairo_surface); } + if (pix != NULL) { + for (size_t i = 0; i < copies; i++) + if (pix[i] != NULL) + pixman_image_unref(pix[i]); + free(pix); + } if (buf != NULL) wl_buffer_destroy(buf); if (pool != NULL) @@ -185,6 +205,12 @@ shm_fini(void) cairo_surface_destroy(buf->cairo_surface[i]); free(buf->cairo_surface); } + if (buf->pix != NULL) { + for (size_t i = 0; i < buf->copies; i++) + if (buf->pix[i] != NULL) + pixman_image_unref(buf->pix[i]); + free(buf->pix); + } wl_buffer_destroy(buf->wl_buf); munmap(buf->mmapped, buf->size); -- cgit v1.3 From f45e5c6aef2a1d44286982e47f6b559c9f2cc4a0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 16 Aug 2019 22:11:22 +0200 Subject: Remove all references to cairo; we now use pixman only --- PKGBUILD | 3 +-- README.md | 2 +- font.c | 2 +- main.c | 2 -- meson.build | 3 +-- shm.c | 60 ++++++++---------------------------------------------------- shm.h | 7 ++----- terminal.h | 1 - 8 files changed, 14 insertions(+), 66 deletions(-) (limited to 'shm.c') diff --git a/PKGBUILD b/PKGBUILD index b3b4352c..9ddead79 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -9,7 +9,7 @@ makedepends=('meson' 'ninja' 'scdoc') depends=( 'libxkbcommon' 'wayland' - 'freetype2' 'fontconfig' 'cairo') + 'freetype2' 'fontconfig' 'pixman') source=() pkgver() { @@ -25,4 +25,3 @@ build() { package() { DESTDIR="${pkgdir}/" ninja install } - diff --git a/README.md b/README.md index d8656f0d..e338c51a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ * fontconfig * freetype -* cairo +* pixman * wayland (_client_ and _cursor_ libraries) * wayland protocols * xkbcommon diff --git a/font.c b/font.c index 85c54bbd..df1581ac 100644 --- a/font.c +++ b/font.c @@ -386,7 +386,7 @@ glyph_for_wchar(struct font *font, wchar_t wc, struct glyph *glyph) uint8_t *data = malloc(bitmap->rows * stride); assert(bitmap->pitch >= 0); - /* Convert FT bitmap to cairo surface (well, the backing image) */ + /* Convert FT bitmap to pixman image */ switch (bitmap->pixel_mode) { case FT_PIXEL_MODE_MONO: for (size_t r = 0; r < bitmap->rows; r++) { diff --git a/main.c b/main.c index 7fd2b2de..9f90caf8 100644 --- a/main.c +++ b/main.c @@ -1085,8 +1085,6 @@ out: tll_free(term.render.workers.queue); config_free(conf); - - cairo_debug_reset_static_data(); return ret; } diff --git a/meson.build b/meson.build index 8174f2a5..cc344a87 100644 --- a/meson.build +++ b/meson.build @@ -45,7 +45,6 @@ threads = dependency('threads') freetype = dependency('freetype2') fontconfig = dependency('fontconfig') pixman = dependency('pixman-1') -cairo = dependency('cairo') wayland_protocols = dependency('wayland-protocols') wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') @@ -101,7 +100,7 @@ executable( 'tllist.h', 'vt.c', 'vt.h', wl_proto_src + wl_proto_headers, - dependencies: [threads, math, freetype, fontconfig, pixman, cairo, wayland_client, wayland_cursor, xkb], + dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb], install: true) custom_target( diff --git a/shm.c b/shm.c index 19ec66db..0ae46f90 100644 --- a/shm.c +++ b/shm.c @@ -47,11 +47,10 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) * No existing buffer available. Create a new one by: * * 1. open a memory backed "file" with memfd_create() - * 2. mmap() the memory file, to be used by the cairo surface + * 2. mmap() the memory file, to be used by the pixman image * 3. create a wayland shm buffer for the same memory file * - * The cairo surface and the wayland buffer are now sharing - * memory. + * The pixman image and the wayland buffer are now sharing memory. */ int pool_fd = -1; @@ -61,8 +60,6 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) struct wl_shm_pool *pool = NULL; struct wl_buffer *buf = NULL; - cairo_surface_t **cairo_surface = NULL; - cairo_t **cairo = NULL; pixman_image_t **pix = NULL; /* Backing memory for SHM */ @@ -72,8 +69,12 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) goto err; } + /* TODO: copied from font.c */ + /* Calculate stride. Copied from cairoint.h:CAIRO_STRIDE_FOR_WIDTH_BPP */ + int bpp = 32; + const int stride = (((bpp * width + 7) / 8 + 4 - 1) & -4); + /* Total size */ - const uint32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); size = stride * height; if (ftruncate(pool_fd, size) == -1) { LOG_ERRNO("failed to truncate SHM pool"); @@ -103,28 +104,9 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) wl_shm_pool_destroy(pool); pool = NULL; close(pool_fd); pool_fd = -1; - /* Create a cairo surface around the mmapped memory */ - cairo_surface = calloc(copies, sizeof(cairo_surface[0])); - cairo = calloc(copies, sizeof(cairo[0])); + /* One pixman image for each worker thread (do we really need multiple?) */ pix = calloc(copies, sizeof(pix[0])); - for (size_t i = 0; i < copies; i++) { - cairo_surface[i] = cairo_image_surface_create_for_data( - mmapped, CAIRO_FORMAT_ARGB32, width, height, stride); - - if (cairo_surface_status(cairo_surface[i]) != CAIRO_STATUS_SUCCESS) { - LOG_ERR("failed to create cairo surface: %s", - cairo_status_to_string(cairo_surface_status(cairo_surface[i]))); - goto err; - } - - cairo[i] = cairo_create(cairo_surface[i]); - if (cairo_status(cairo[i]) != CAIRO_STATUS_SUCCESS) { - LOG_ERR("failed to create cairo context: %s", - cairo_status_to_string(cairo_status(cairo[i]))); - goto err; - } - pix[i] = pixman_image_create_bits_no_clear( PIXMAN_a8r8g8b8, width, height, (uint32_t *)mmapped, stride); @@ -146,8 +128,6 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) .mmapped = mmapped, .wl_buf = buf, .copies = copies, - .cairo_surface = cairo_surface, - .cairo = cairo, .pix = pix} ) ); @@ -157,18 +137,6 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) return ret; err: - if (cairo != NULL) { - for (size_t i = 0; i < copies; i++) - if (cairo[i] != NULL) - cairo_destroy(cairo[i]); - free(cairo); - } - if (cairo_surface != NULL) { - for (size_t i = 0; i < copies; i++) - if (cairo_surface[i] != NULL) - cairo_surface_destroy(cairo_surface[i]); - free(cairo_surface); - } if (pix != NULL) { for (size_t i = 0; i < copies; i++) if (pix[i] != NULL) @@ -193,18 +161,6 @@ shm_fini(void) tll_foreach(buffers, it) { struct buffer *buf = &it->item; - if (buf->cairo != NULL) { - for (size_t i = 0; i < buf->copies; i++) - if (buf->cairo[i] != NULL) - cairo_destroy(buf->cairo[i]); - free(buf->cairo); - } - if (buf->cairo_surface != NULL) { - for (size_t i = 0; i < buf->copies; i++) - if (buf->cairo_surface[i] != NULL) - cairo_surface_destroy(buf->cairo_surface[i]); - free(buf->cairo_surface); - } if (buf->pix != NULL) { for (size_t i = 0; i < buf->copies; i++) if (buf->pix[i] != NULL) diff --git a/shm.h b/shm.h index 668b26b8..7006ab3a 100644 --- a/shm.h +++ b/shm.h @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -19,11 +18,9 @@ struct buffer { struct wl_buffer *wl_buf; size_t copies; - cairo_surface_t **cairo_surface; - cairo_t **cairo; - pixman_image_t **pix; }; -struct buffer *shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies); +struct buffer *shm_get_buffer( + struct wl_shm *shm, int width, int height, size_t copies); void shm_fini(void); diff --git a/terminal.h b/terminal.h index 2baa5f59..fde5ba7d 100644 --- a/terminal.h +++ b/terminal.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include -- cgit v1.3 From 72d3cbca268334fd5b7431c56121c570f6e0e90f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 16 Aug 2019 22:54:05 +0200 Subject: shm/render: there's no need to have one pixman image per thread --- render.c | 4 ++-- shm.c | 31 +++++++------------------------ shm.h | 4 +--- 3 files changed, 10 insertions(+), 29 deletions(-) (limited to 'shm.c') diff --git a/render.c b/render.c index cefff04b..e2ed46b1 100644 --- a/render.c +++ b/render.c @@ -367,7 +367,7 @@ render_worker_thread(void *_ctx) switch (row_no) { default: assert(buf != NULL); - render_row(term, buf->pix[my_id], grid_row_in_view(term->grid, row_no), row_no); + render_row(term, buf->pix, grid_row_in_view(term->grid, row_no), row_no); break; case -1: @@ -405,7 +405,7 @@ grid_render(struct terminal *term) assert(term->height > 0); struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height, 1 + term->render.workers.count); - pixman_image_t *pix = buf->pix[0]; + pixman_image_t *pix = buf->pix; bool all_clean = tll_length(term->grid->scroll_damage) == 0; diff --git a/shm.c b/shm.c index 0ae46f90..ebff8a1a 100644 --- a/shm.c +++ b/shm.c @@ -60,7 +60,7 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) struct wl_shm_pool *pool = NULL; struct wl_buffer *buf = NULL; - pixman_image_t **pix = NULL; + pixman_image_t *pix = NULL; /* Backing memory for SHM */ pool_fd = memfd_create("f00sel-wayland-shm-buffer-pool", MFD_CLOEXEC); @@ -105,16 +105,8 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) close(pool_fd); pool_fd = -1; /* One pixman image for each worker thread (do we really need multiple?) */ - pix = calloc(copies, sizeof(pix[0])); - for (size_t i = 0; i < copies; i++) { - pix[i] = pixman_image_create_bits_no_clear( - PIXMAN_a8r8g8b8, width, height, (uint32_t *)mmapped, stride); - - if (pix[i] == NULL) { - LOG_ERR("failed to create pixman image"); - goto err; - } - } + pix = pixman_image_create_bits_no_clear( + PIXMAN_a8r8g8b8, width, height, (uint32_t *)mmapped, stride); /* Push to list of available buffers, but marked as 'busy' */ tll_push_back( @@ -127,7 +119,6 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) .size = size, .mmapped = mmapped, .wl_buf = buf, - .copies = copies, .pix = pix} ) ); @@ -137,12 +128,8 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, size_t copies) return ret; err: - if (pix != NULL) { - for (size_t i = 0; i < copies; i++) - if (pix[i] != NULL) - pixman_image_unref(pix[i]); - free(pix); - } + if (pix != NULL) + pixman_image_unref(pix); if (buf != NULL) wl_buffer_destroy(buf); if (pool != NULL) @@ -161,12 +148,8 @@ shm_fini(void) tll_foreach(buffers, it) { struct buffer *buf = &it->item; - if (buf->pix != NULL) { - for (size_t i = 0; i < buf->copies; i++) - if (buf->pix[i] != NULL) - pixman_image_unref(buf->pix[i]); - free(buf->pix); - } + if (buf->pix != NULL) + pixman_image_unref(buf->pix); wl_buffer_destroy(buf->wl_buf); munmap(buf->mmapped, buf->size); diff --git a/shm.h b/shm.h index 7006ab3a..68013888 100644 --- a/shm.h +++ b/shm.h @@ -16,9 +16,7 @@ struct buffer { void *mmapped; struct wl_buffer *wl_buf; - - size_t copies; - pixman_image_t **pix; + pixman_image_t *pix; }; struct buffer *shm_get_buffer( -- cgit v1.3