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
Provenance
- Commit
c6937be- Tree
47f2328- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
7d89025
4 files changed+34 added−26 removed
modified:render.c+12 added-26 removed
105 unmodified lines106 struct font *font = render->regular_font;107 const size_t prompt_len = wcslen(prompt->prompt);108 const size_t text_len = wcslen(prompt->text);109 110- cairo_surface_flush(buf->cairo_surface);111-112- 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);116-110 int x = render->options.border_size + render->options.x_margin;111 int y = render->options.border_size + render->options.y_margin + font->fextents.ascent;112 113 for (size_t i = 0; i < prompt_len + text_len; i++) {1 unmodified line115 const struct glyph *glyph = font_glyph_for_wc(font, wc);116 if (glyph == NULL)117 continue;118 126- 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;121 122 /* 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 }138-139- pixman_image_unref(pix);140- cairo_surface_mark_dirty(buf->cairo_surface);131 }132 133 static void134 render_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);152-153- 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);157-139 int x = *_x;140 int y = _y;141 142 for (size_t i = 0; i < wcslen(text); i++) {1 unmodified line144 if (glyph == NULL)145 continue;146 147 bool is_match = start >= 0 && i >= start && i < start + length;167- render_glyph(pix, glyph, x, y, is_match ? &match_color : ®ular_color);148+ render_glyph(buf->pix, glyph, x, y, is_match ? &match_color : ®ular_color);149 x += glyph->x_advance;150 }151 152 *_x = x;172- pixman_image_unref(pix);173- cairo_surface_mark_dirty(buf->cairo_surface);153 }154 155 void156 render_match_list(const struct render *render, struct buffer *buf,99 unmodified lines256 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);261 262 y += row_height;263 }264 }3 unmodified lines268 {269 struct render *render = calloc(1, sizeof(*render));270 render->options = options;271 render->regular_font = font;272+273+ /* 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 }281 282 void9 unmodified linesmodified:render.h+8 added
1 #pragma once2 3+#include <pixman.h>4 #include <cairo.h>5 6 #include "font.h"7 #include "shm.h"14 unmodified lines22 struct rgba border_color;23 struct rgba text_color;24 struct rgba match_color;25 struct rgba selection_color;26+27+ /* 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 };34 35 struct render;36 struct render *render_init(struct font *font, struct options options);11 unmodified linesmodified:shm.c+12 added
53 unmodified lines54 55 struct wl_shm_pool *pool = NULL;56 struct wl_buffer *buf = NULL;57 58+ pixman_image_t *pix = NULL;59 cairo_surface_t *cairo_surface = NULL;60 cairo_t *cairo = NULL;61 62 /* Backing memory for SHM */33 unmodified lines96 /* We use the entire pool for our single buffer */97 wl_shm_pool_destroy(pool); pool = NULL;98 close(pool_fd); pool_fd = -1;99 100+ 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+ }106+107 /* 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 lines130 .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 lines145 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 lines167 struct buffer *buf = &it->item;168 169 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);174 175 tll_remove(buffers, it);2 unmodified linesmodified:shm.h+2 added
1 unmodified line2 3 #include <stdbool.h>4 #include <stddef.h>5 6+#include <pixman.h>7 #include <cairo.h>8 #include <wayland-client.h>9 10 struct buffer {6 unmodified lines17 void *mmapped;18 19 struct wl_buffer *wl_buf;20 21+ pixman_image_t *pix;22 cairo_surface_t *cairo_surface;23 cairo_t *cairo;24 };25 2 unmodified lines