Skip to content
Myr

Merge branch 'pixman'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #10

authored by Daniel Eklöf · committed by Daniel Eklöf · parents e899892, edabc3e · Browse files · 11 files+129 added−73 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+129 added−73 removed

  • other:+129 added−73 removed

11 files+129 added−73 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:CHANGELOG.md+4 added
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:README.md+10 added-1 removed
modified:render.c+69 added-55 removed
21 unmodified lines
22 unsigned border_size;23 unsigned row_height;24};2526static pixman_color_t27rgba2pixman(struct rgba rgba)28{29 uint16_t r = rgba.r * 65535.0;30 uint16_t g = rgba.g * 65535.0;31 uint16_t b = rgba.b * 65535.0;32 uint16_t a = rgba.a * 65535.0;3334 return (pixman_color_t){35 .red = r * a / 0xffff,36 .green = g * a / 0xffff,37 .blue = b * a / 0xffff,38 .alpha = a,39 };40}4142void43render_background(const struct render *render, struct buffer *buf)44{29 /*30 * Lines in cairo are *between* pixels.31 *32 * To get a sharp 1px line, we need to draw it with33 * line-width=2.34 *35 * Thus, we need to draw the path offset:ed with half that36 * (=actual border width).37 */38 const double b = render->border_size;39 const double w = max(buf->width - 2 * b, 0.);40 const double h = max(buf->height - 2 * b, 0.);45 bool use_pixman =46#if defined(FUZZEL_ENABLE_CAIRO)47 render->options.border_radius == 048#else49 true50#endif51 ;5242 if (w == 0. || h == 0.)43 return;4445 if (render->options.border_radius == 0) {46 cairo_rectangle(buf->cairo, b, b, w, h);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 with64 * line-width=2.65 *66 * Thus, we need to draw the path offset:ed with half that67 * (=actual border width).68 */69 const double b = render->border_size;70 const double w = max(buf->width - 2 * b, 0.);71 const double h = max(buf->height - 2 * b, 0.);7273 const double from_degree = M_PI / 180;74 const double radius = render->options.border_radius;755176 /* Path describing an arc:ed rectangle */77 cairo_arc(buf->cairo, b + w - radius, b + h - radius, radius,78 0.0 * from_degree, 90.0 * from_degree);79 cairo_arc(buf->cairo, b + radius, b + h - radius, radius,
2 unmodified lines
82 180.0 * from_degree, 270.0 * from_degree);83 cairo_arc(buf->cairo, b + w - radius, b + radius, radius,84 270.0 * from_degree, 360.0 * from_degree);85 cairo_close_path(buf->cairo);62 }8664 /* Border */65 const struct rgba *bc = &render->options.border_color;66 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);67 cairo_set_line_width(buf->cairo, 2 * b);68 cairo_set_source_rgba(buf->cairo, bc->r, bc->g, bc->b, bc->a);69 cairo_stroke_preserve(buf->cairo);87 /* Border */88 const struct rgba *bc = &render->options.border_color;89 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);90 cairo_set_line_width(buf->cairo, 2 * b);91 cairo_set_source_rgba(buf->cairo, bc->r, bc->g, bc->b, bc->a);92 cairo_stroke_preserve(buf->cairo);9371 /* Background */72 const struct rgba *bg = &render->options.background_color;73 cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);74 cairo_fill(buf->cairo);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}10377static pixman_color_t78rgba2pixman(struct rgba rgba)79{80 uint16_t r = rgba.r * 65535.0;81 uint16_t g = rgba.g * 65535.0;82 uint16_t b = rgba.b * 65535.0;83 uint16_t a = rgba.a * 65535.0;8485 return (pixman_color_t){86 .red = r * a / 0xffff,87 .green = g * a / 0xffff,88 .blue = b * a / 0xffff,89 .alpha = a,90 };91}92104static void105render_glyph(pixman_image_t *pix, const struct fcft_glyph *glyph, int x, int y, const pixman_color_t *color)106{107 if (pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8) {
168 unmodified lines
276 }277#endif /* FUZZEL_ENABLE_SVG */278 }279269 /* Hightlight selected entry */270 const struct rgba *sc = &render->options.selection_color;271 cairo_set_source_rgba(buf->cairo, sc->r, sc->g, sc->b, sc->a);272 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);273 cairo_rectangle(buf->cairo,274 x_margin - sel_margin,275 first_row + i * row_height,276 buf->width - 2 * (x_margin - sel_margin),277 row_height);278 cairo_fill(buf->cairo);280 pixman_color_t sc = rgba2pixman(render->options.selection_color);281 pixman_image_fill_rectangles(282 PIXMAN_OP_SRC, buf->pix, &sc, 1,283 &(pixman_rectangle16_t){284 x_margin - sel_margin,285 first_row + i * row_height,286 buf->width - 2 * (x_margin - sel_margin),287 row_height}288 );289 }290291 double cur_x = border_size + x_margin;292 struct icon *icon = &match->application->icon;
3 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