meson: make cairo an optional dependency
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add meson option -Denable-cairo=auto|enabled|disabled * #define FUZZEL_ENABLE_CAIRO when cairo is enabled * Wrap all cairo calls in #ifdef FUZZEL_ENABLE_CAIRO * Remove cairo-ft dependency (we don’t use it) * SVG support requires cairo
authored by Daniel Eklöf · committed by Daniel Eklöf · parent b614317 · Browse files · 9 files·+63 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+63 added−18 removed
- other:+63 added−18 removed
Provenance
- Commit
28f65cf- Tree
e5b2986- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
b614317
9 files changed+63 added−18 removed
modified:application.h+2 added-3 removed
1 unmodified line2 3 #include <stdbool.h>4 #include <pixman.h>5 6-#include <cairo.h>7-#ifdef FUZZEL_ENABLE_SVG8-#include <librsvg/rsvg.h>6+#if defined(FUZZEL_ENABLE_SVG)7+ #include <librsvg/rsvg.h>8 #endif9 10 #include "prompt.h"11 37 unmodified linesmodified:main.c+2 added
435 unmodified lines436 fdm_destroy(fdm);437 applications_destroy(apps);438 icon_themes_destroy(themes);439 440+#if defined(FUZZEL_ENABLE_CAIRO)441 cairo_debug_reset_static_data();442+#endif443 log_deinit();444 return ret;445 }modified:meson_options.txt+3 added-2 removed
1-option('enable-png', type: 'feature')2-option('enable-svg', type: 'feature')1+option('enable-cairo', type: 'feature', description: 'use cairo; required for rounded corners and SVG icons')2+option('enable-png', type: 'feature', description: 'enables support for PNG icons')3+option('enable-svg', type: 'feature', description: 'enables support for SVG icons (note: also requires cairo)')modified:meson.build+14 added-7 removed
46 unmodified lines47 endif48 49 math = cc.find_library('m')50 pixman = dependency('pixman-1')51-cairo = dependency('cairo')52-cairo_ft = dependency('cairo-ft')51+cairo = dependency('cairo', required: get_option('enable-cairo'))52 libpng = dependency('libpng', required: get_option('enable-png'))53+if cairo.found()54-librsvg = dependency('librsvg-2.0', required: get_option('enable-svg'))54+ librsvg = dependency('librsvg-2.0', required: get_option('enable-svg'))55+else56+ librsvg = declare_dependency()57+endif58 wayland_protocols = dependency('wayland-protocols')59 wayland_client = dependency('wayland-client')60 wayland_cursor = dependency('wayland-cursor')61 xkb = dependency('xkbcommon')62 60-if (libpng.found())63+if cairo.found()64+ add_project_arguments('-DFUZZEL_ENABLE_CAIRO=1', language: 'c')65+endif66+67+if libpng.found()68 add_project_arguments('-DFUZZEL_ENABLE_PNG=1', language: 'c')69 endif70 64-if librsvg.found()71+if librsvg.found() and cairo.found()72 add_project_arguments('-DFUZZEL_ENABLE_SVG=1', language: 'c')73 endif74 75 tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')51 unmodified lines127 wl_proto_src + wl_proto_headers, version,128 dependencies: [math,129 pixman,130 cairo,124- cairo_ft,131 libpng,132 librsvg,133 wayland_client,134 wayland_cursor,10 unmodified lines145 subdir('doc')146 147 summary(148 {149+ 'Cairo': cairo.found(),150 'PNG icons': libpng.found(),144- 'SVG icons': librsvg.found(),151+ 'SVG icons': librsvg.found() and cairo.found(),152 },153 bool_yn: true154 )modified:render.c+17 added-1 removed
40 unmodified lines41 42 void43 render_background(const struct render *render, struct buffer *buf)44 {45- if (render->options.border_radius == 0) {45+ bool use_pixman =46+#if defined(FUZZEL_ENABLE_CAIRO)47+ render->options.border_radius == 048+#else49+ true50+#endif51+ ;52+53+ if (use_pixman) {54 pixman_color_t bg = rgba2pixman(render->options.background_color);55 pixman_image_fill_rectangles(56 PIXMAN_OP_SRC, buf->pix, &bg, 1, &(pixman_rectangle16_t){0, 0, buf->width, buf->height}57 );58 } else {59+#if defined(FUZZEL_ENABLE_CAIRO)60 /*61 * Lines in cairo are *between* pixels.62 *63 * To get a sharp 1px line, we need to draw it with30 unmodified lines94 /* Background */95 const struct rgba *bg = &render->options.background_color;96 cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);97 cairo_fill(buf->cairo);98+#else99+ assert(false);100+#endif101 }102 }103 104 static void191 unmodified lines296 break;297 298 case ICON_PNG: {299 #if defined(FUZZEL_ENABLE_PNG)300+ #if defined(FUZZEL_ENABLE_CAIRO)301 cairo_surface_flush(buf->cairo_surface);302+ #endif303 304 pixman_image_t *png = icon->png.pix;305 int height = pixman_image_get_height(png);306 int width = pixman_image_get_width(png);42 unmodified lines349 0, 0, 0, 0,350 cur_x, first_row + i * row_height + (row_height - height) / 2,351 width, height);352 353+ #if defined(FUZZEL_ENABLE_CAIRO)354 cairo_surface_mark_dirty(buf->cairo_surface);355+ #endif356 #endif /* FUZZEL_ENABLE_PNG */357 break;358 }359 123 unmodified linesmodified:render.h-1 removed
1 #pragma once2 3 #include <pixman.h>4-#include <cairo.h>4 5 #include <fcft/fcft.h>6 7 #include "shm.h"42 unmodified linesmodified:shm.c+17 added-3 removed
9 unmodified lines10 #include <tllist.h>11 12 #define LOG_MODULE "shm"13 #include "log.h"14+#include "stride.h"15 16 static tll(struct buffer) buffers;17 18 static void41 unmodified lines60 struct wl_shm_pool *pool = NULL;61 struct wl_buffer *buf = NULL;62 63 pixman_image_t *pix = NULL;64+65+#if defined(FUZZEL_ENABLE_CAIRO)66 cairo_surface_t *cairo_surface = NULL;67 cairo_t *cairo = NULL;68+#endif69 70 /* Backing memory for SHM */71 pool_fd = memfd_create("fuzzel-wayland-shm-buffer-pool", MFD_CLOEXEC);72 if (pool_fd == -1) {1 unmodified line74 goto err;75 }76 77 /* Total size */74- const uint32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);78+ const uint32_t stride = stride_for_format_and_width(PIXMAN_a8r8g8b8, width);79 size = stride * height;80 if (ftruncate(pool_fd, size) == -1) {81 LOG_ERRNO("failed to truncate SHM pool");82 goto err;28 unmodified lines111 LOG_ERR("failed to create pixman image");112 goto err;113 }114 115+#if defined(FUZZEL_ENABLE_CAIRO)116 /* Create a cairo surface around the mmapped memory */117 cairo_surface = cairo_image_surface_create_for_data(118 mmapped, CAIRO_FORMAT_ARGB32, width, height, stride);119 if (cairo_surface_status(cairo_surface) != CAIRO_STATUS_SUCCESS) {7 unmodified lines127 LOG_ERR("failed to create cairo context: %s",128 cairo_status_to_string(cairo_status(cairo)));129 goto err;130 }131+#endif132 133 /* Push to list of available buffers, but marked as 'busy' */134 tll_push_back(135 buffers,5 unmodified lines141 .size = size,142 .mmapped = mmapped,143 .wl_buf = buf,144 .pix = pix,145+146+#if defined(FUZZEL_ENABLE_CAIRO)147 .cairo_surface = cairo_surface,140- .cairo = cairo}141- )148+ .cairo = cairo149+#endif150+ })151 );152 153 struct buffer *ret = &tll_back(buffers);154 wl_buffer_add_listener(ret->wl_buf, &buffer_listener, ret);155 return ret;156 157 err:158+#if defined(FUZZEL_ENABLE_CAIRO)159 if (cairo != NULL)160 cairo_destroy(cairo);161 if (cairo_surface != NULL)162 cairo_surface_destroy(cairo_surface);163+#endif164 if (pix != NULL)165 pixman_image_unref(pix);166 if (buf != NULL)167 wl_buffer_destroy(buf);12 unmodified lines180 {181 tll_foreach(buffers, it) {182 struct buffer *buf = &it->item;183 184+#if defined(FUZZEL_ENABLE_CAIRO)185 cairo_destroy(buf->cairo);186 cairo_surface_destroy(buf->cairo_surface);187+#endif188+189 pixman_image_unref(buf->pix);190 wl_buffer_destroy(buf->wl_buf);191 munmap(buf->mmapped, buf->size);192 3 unmodified linesmodified:shm.h+6 added-1 removed
2 unmodified lines3 #include <stdbool.h>4 #include <stddef.h>5 6 #include <pixman.h>7+#if defined(FUZZEL_ENABLE_CAIRO)7-#include <cairo.h>8+ #include <cairo.h>9+#endif10 #include <wayland-client.h>11 12 struct buffer {13 int width;6 unmodified lines20 21 struct wl_buffer *wl_buf;22 23 pixman_image_t *pix;24+25+#if defined(FUZZEL_ENABLE_CAIRO)26 cairo_surface_t *cairo_surface;27 cairo_t *cairo;28+#endif29 };30 31 struct buffer *shm_get_buffer(struct wl_shm *shm, int width, int height);32 void shm_fini(void);modified:wayland.c+2 added
1299 unmodified lines1300 /* Window content */1301 render_prompt(wayl->render, buf, wayl->prompt);1302 render_match_list(wayl->render, buf, wayl->prompt, wayl->matches);1303 1304+#if defined(FUZZEL_ENABLE_CAIRO)1305 cairo_surface_flush(buf->cairo_surface);1306+#endif1307 1308 if (wayl->frame_is_scheduled) {1309 /* There's already a frame being drawn - delay current frame1310 * (overwriting any previous pending frame) */264 unmodified lines