Skip to content
Myr

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

9 files+63 added−18 removed

modified:application.h+2 added-3 removed
1 unmodified line
23#include <stdbool.h>4#include <pixman.h>56#include <cairo.h>7#ifdef FUZZEL_ENABLE_SVG8#include <librsvg/rsvg.h>6#if defined(FUZZEL_ENABLE_SVG)7 #include <librsvg/rsvg.h>8#endif910#include "prompt.h"11
37 unmodified lines
modified:main.c+2 added
435 unmodified lines
436 fdm_destroy(fdm);437 applications_destroy(apps);438 icon_themes_destroy(themes);439440#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
1option('enable-png', type: 'feature')2option('enable-svg', type: 'feature')1option('enable-cairo', type: 'feature', description: 'use cairo; required for rounded corners and SVG icons')2option('enable-png', type: 'feature', description: 'enables support for PNG icons')3option('enable-svg', type: 'feature', description: 'enables support for SVG icons (note: also requires cairo)')
modified:meson.build+14 added-7 removed
46 unmodified lines
47endif4849math = cc.find_library('m')50pixman = dependency('pixman-1')51cairo = dependency('cairo')52cairo_ft = dependency('cairo-ft')51cairo = dependency('cairo', required: get_option('enable-cairo'))52libpng = dependency('libpng', required: get_option('enable-png'))53if cairo.found()54librsvg = dependency('librsvg-2.0', required: get_option('enable-svg'))54 librsvg = dependency('librsvg-2.0', required: get_option('enable-svg'))55else56 librsvg = declare_dependency()57endif58wayland_protocols = dependency('wayland-protocols')59wayland_client = dependency('wayland-client')60wayland_cursor = dependency('wayland-cursor')61xkb = dependency('xkbcommon')6260if (libpng.found())63if cairo.found()64 add_project_arguments('-DFUZZEL_ENABLE_CAIRO=1', language: 'c')65endif6667if libpng.found()68 add_project_arguments('-DFUZZEL_ENABLE_PNG=1', language: 'c')69endif7064if librsvg.found()71if librsvg.found() and cairo.found()72 add_project_arguments('-DFUZZEL_ENABLE_SVG=1', language: 'c')73endif7475tllist = dependency('tllist', version: '>=1.0.1', fallback: 'tllist')
51 unmodified lines
127 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 lines
145subdir('doc')146147summary(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 lines
4142void43render_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 ;5253 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 with
30 unmodified lines
94 /* 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}103104static void
191 unmodified lines
296 break;297298 case ICON_PNG: {299#if defined(FUZZEL_ENABLE_PNG)300 #if defined(FUZZEL_ENABLE_CAIRO)301 cairo_surface_flush(buf->cairo_surface);302 #endif303304 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 lines
349 0, 0, 0, 0,350 cur_x, first_row + i * row_height + (row_height - height) / 2,351 width, height);352353 #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 lines
modified:render.h-1 removed
1#pragma once23#include <pixman.h>4#include <cairo.h>45#include <fcft/fcft.h>67#include "shm.h"
42 unmodified lines
modified:shm.c+17 added-3 removed
9 unmodified lines
10#include <tllist.h>1112#define LOG_MODULE "shm"13#include "log.h"14#include "stride.h"1516static tll(struct buffer) buffers;1718static void
41 unmodified lines
60 struct wl_shm_pool *pool = NULL;61 struct wl_buffer *buf = NULL;6263 pixman_image_t *pix = NULL;6465#if defined(FUZZEL_ENABLE_CAIRO)66 cairo_surface_t *cairo_surface = NULL;67 cairo_t *cairo = NULL;68#endif6970 /* Backing memory for SHM */71 pool_fd = memfd_create("fuzzel-wayland-shm-buffer-pool", MFD_CLOEXEC);72 if (pool_fd == -1) {
1 unmodified line
74 goto err;75 }7677 /* 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 lines
111 LOG_ERR("failed to create pixman image");112 goto err;113 }114115#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 lines
127 LOG_ERR("failed to create cairo context: %s",128 cairo_status_to_string(cairo_status(cairo)));129 goto err;130 }131#endif132133 /* Push to list of available buffers, but marked as 'busy' */134 tll_push_back(135 buffers,
5 unmodified lines
141 .size = size,142 .mmapped = mmapped,143 .wl_buf = buf,144 .pix = pix,145146#if defined(FUZZEL_ENABLE_CAIRO)147 .cairo_surface = cairo_surface,140 .cairo = cairo}141 )148 .cairo = cairo149#endif150 })151 );152153 struct buffer *ret = &tll_back(buffers);154 wl_buffer_add_listener(ret->wl_buf, &buffer_listener, ret);155 return ret;156157err: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 lines
180{181 tll_foreach(buffers, it) {182 struct buffer *buf = &it->item;183184#if defined(FUZZEL_ENABLE_CAIRO)185 cairo_destroy(buf->cairo);186 cairo_surface_destroy(buf->cairo_surface);187#endif188189 pixman_image_unref(buf->pix);190 wl_buffer_destroy(buf->wl_buf);191 munmap(buf->mmapped, buf->size);192
3 unmodified lines
modified:shm.h+6 added-1 removed
2 unmodified lines
3#include <stdbool.h>4#include <stddef.h>56#include <pixman.h>7#if defined(FUZZEL_ENABLE_CAIRO)7#include <cairo.h>8 #include <cairo.h>9#endif10#include <wayland-client.h>1112struct buffer {13 int width;
6 unmodified lines
2021 struct wl_buffer *wl_buf;2223 pixman_image_t *pix;2425#if defined(FUZZEL_ENABLE_CAIRO)26 cairo_surface_t *cairo_surface;27 cairo_t *cairo;28#endif29};3031struct buffer *shm_get_buffer(struct wl_shm *shm, int width, int height);32void shm_fini(void);
modified:wayland.c+2 added
1299 unmodified lines
1300 /* Window content */1301 render_prompt(wayl->render, buf, wayl->prompt);1302 render_match_list(wayl->render, buf, wayl->prompt, wayl->matches);13031304#if defined(FUZZEL_ENABLE_CAIRO)1305 cairo_surface_flush(buf->cairo_surface);1306#endif13071308 if (wayl->frame_is_scheduled) {1309 /* There's already a frame being drawn - delay current frame1310 * (overwriting any previous pending frame) */
264 unmodified lines