Skip to content
Myr

shm: buffer now provides a pixman image reference in addition to cairo

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

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 7d89025 · Browse files · 4 files+34 added−26 removed
This commit

State

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

Diff stats

4 files+34 added−26 removed

  • other:+34 added−26 removed

4 files+34 added−26 removed

modified:render.c+12 added-26 removed
105 unmodified lines
106 struct font *font = render->regular_font;107 const size_t prompt_len = wcslen(prompt->prompt);108 const size_t text_len = wcslen(prompt->text);109110 cairo_surface_flush(buf->cairo_surface);111112 pixman_color_t fg = rgba2pixman(render->options.text_color);113 pixman_image_t *pix = pixman_image_create_bits_no_clear(114 PIXMAN_a8r8g8b8, buf->width, buf->height, buf->mmapped, buf->stride);115 assert(pix != NULL);116110 int x = render->options.border_size + render->options.x_margin;111 int y = render->options.border_size + render->options.y_margin + font->fextents.ascent;112113 for (size_t i = 0; i < prompt_len + text_len; i++) {
1 unmodified line
115 const struct glyph *glyph = font_glyph_for_wc(font, wc);116 if (glyph == NULL)117 continue;118126 render_glyph(pix, glyph, x, y, &fg);119 render_glyph(buf->pix, glyph, x, y, &render->options.pix_text_color);120 x += glyph->x_advance;121122 /* Cursor */123 if (prompt->cursor + prompt_len - 1 == i) {124 pixman_image_fill_rectangles(132 PIXMAN_OP_SRC, pix, &fg,125 PIXMAN_OP_SRC, buf->pix, &render->options.pix_text_color,126 1, &(pixman_rectangle16_t){127 x, y - font->fextents.ascent,128 font->underline.thickness, font->fextents.ascent + font->fextents.descent});129 }130 }138139 pixman_image_unref(pix);140 cairo_surface_mark_dirty(buf->cairo_surface);131}132133static void134render_match_text(struct buffer *buf, double *_x, double _y,135 const wchar_t *text, ssize_t start, size_t length,136 struct font *font,147 struct rgba _regular_color,148 struct rgba _match_color)137 pixman_color_t regular_color, pixman_color_t match_color)138{150 pixman_color_t regular_color = rgba2pixman(_regular_color);151 pixman_color_t match_color = rgba2pixman(_match_color);152153 cairo_surface_flush(buf->cairo_surface);154 pixman_image_t *pix = pixman_image_create_bits_no_clear(155 PIXMAN_a8r8g8b8, buf->width, buf->height, buf->mmapped, buf->stride);156 assert(pix != NULL);157139 int x = *_x;140 int y = _y;141142 for (size_t i = 0; i < wcslen(text); i++) {
1 unmodified line
144 if (glyph == NULL)145 continue;146147 bool is_match = start >= 0 && i >= start && i < start + length;167 render_glyph(pix, glyph, x, y, is_match ? &match_color : &regular_color);148 render_glyph(buf->pix, glyph, x, y, is_match ? &match_color : &regular_color);149 x += glyph->x_advance;150 }151152 *_x = x;172 pixman_image_unref(pix);173 cairo_surface_mark_dirty(buf->cairo_surface);153}154155void156render_match_list(const struct render *render, struct buffer *buf,
99 unmodified lines
256 render_match_text(257 buf, &cur_x, y,258 match->application->title, match->start_title, match_length,259 render->regular_font,281 render->options.text_color, render->options.match_color);260 render->options.pix_text_color, render->options.pix_match_color);261262 y += row_height;263 }264}
3 unmodified lines
268{269 struct render *render = calloc(1, sizeof(*render));270 render->options = options;271 render->regular_font = font;272273 /* TODO: the one providing the options should calculate these */274 render->options.pix_background_color = rgba2pixman(render->options.background_color);275 render->options.pix_border_color = rgba2pixman(render->options.border_color);276 render->options.pix_text_color = rgba2pixman(render->options.text_color);277 render->options.pix_match_color = rgba2pixman(render->options.match_color);278 render->options.pix_selection_color = rgba2pixman(render->options.selection_color);279 return render;280}281282void
9 unmodified lines
modified:render.h+8 added
1#pragma once23#include <pixman.h>4#include <cairo.h>56#include "font.h"7#include "shm.h"
14 unmodified lines
22 struct rgba border_color;23 struct rgba text_color;24 struct rgba match_color;25 struct rgba selection_color;2627 /* Filled in by render, for now */28 pixman_color_t pix_background_color;29 pixman_color_t pix_border_color;30 pixman_color_t pix_text_color;31 pixman_color_t pix_match_color;32 pixman_color_t pix_selection_color;33};3435struct render;36struct render *render_init(struct font *font, struct options options);
11 unmodified lines
modified:shm.c+12 added
53 unmodified lines
5455 struct wl_shm_pool *pool = NULL;56 struct wl_buffer *buf = NULL;5758 pixman_image_t *pix = NULL;59 cairo_surface_t *cairo_surface = NULL;60 cairo_t *cairo = NULL;6162 /* Backing memory for SHM */
33 unmodified lines
96 /* We use the entire pool for our single buffer */97 wl_shm_pool_destroy(pool); pool = NULL;98 close(pool_fd); pool_fd = -1;99100 pix = pixman_image_create_bits_no_clear(101 PIXMAN_a8r8g8b8, width, height, mmapped, stride);102 if (pix == NULL) {103 LOG_ERR("failed to create pixman image");104 goto err;105 }106107 /* Create a cairo surface around the mmapped memory */108 cairo_surface = cairo_image_surface_create_for_data(109 mmapped, CAIRO_FORMAT_ARGB32, width, height, stride);110 if (cairo_surface_status(cairo_surface) != CAIRO_STATUS_SUCCESS) {
19 unmodified lines
130 .busy = true,131 .size = size,132 .mmapped = mmapped,133 .wl_buf = buf,134 .pix = pix,135 .cairo_surface = cairo_surface,136 .cairo = cairo}137 )138 );
6 unmodified lines
145 if (cairo != NULL)146 cairo_destroy(cairo);147 if (cairo_surface != NULL)148 cairo_surface_destroy(cairo_surface);149 if (pix != NULL)150 pixman_image_unref(pix);151 if (buf != NULL)152 wl_buffer_destroy(buf);153 if (pool != NULL)154 wl_shm_pool_destroy(pool);
12 unmodified lines
167 struct buffer *buf = &it->item;168169 cairo_destroy(buf->cairo);170 cairo_surface_destroy(buf->cairo_surface);171 pixman_image_unref(buf->pix);172 wl_buffer_destroy(buf->wl_buf);173 munmap(buf->mmapped, buf->size);174175 tll_remove(buffers, it);
2 unmodified lines
modified:shm.h+2 added
1 unmodified line
23#include <stdbool.h>4#include <stddef.h>56#include <pixman.h>7#include <cairo.h>8#include <wayland-client.h>910struct buffer {
6 unmodified lines
17 void *mmapped;1819 struct wl_buffer *wl_buf;2021 pixman_image_t *pix;22 cairo_surface_t *cairo_surface;23 cairo_t *cairo;24};25
2 unmodified lines