forked from external/yambar
cairo: replace cairo with pixman in decos, particles and modules
All decoration, particle and module interfaces now takes a pixman_image_t parameter, and all drawing is done using pixman APIs. The wayland/xcb backends implement a new interface functions, get_pixman_image(), that should return a pixman image instance that is suitable for rendering. In the wayland backend, the image uses the same backing data as the cairo surface. In the XCB backend, we create a new image each time, and then blit it to the cairo surface at commit time.
This commit is contained in:
parent
95385863ae
commit
c11fee4ce3
24 changed files with 162 additions and 141 deletions
|
@ -49,7 +49,7 @@ dynlist_begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
dynlist_expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
dynlist_expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
const struct private *e = exposable->private;
|
||||
|
||||
|
@ -60,7 +60,7 @@ dynlist_expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int
|
|||
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
const struct exposable *ee = e->exposables[i];
|
||||
ee->expose(ee, cr, x + left_spacing, y, height);
|
||||
ee->expose(ee, pix, x + left_spacing, y, height);
|
||||
x += left_spacing + e->widths[i] + right_spacing;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
}
|
||||
|
||||
static struct exposable *
|
||||
|
|
|
@ -55,11 +55,11 @@ begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
const struct eprivate *e = exposable->private;
|
||||
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
|
||||
int left_margin = exposable->particle->left_margin;
|
||||
int left_spacing = e->left_spacing;
|
||||
|
@ -68,7 +68,7 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
|||
x += left_margin - left_spacing;
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
const struct exposable *ee = e->exposables[i];
|
||||
ee->expose(ee, cr, x + left_spacing, y, height);
|
||||
ee->expose(ee, pix, x + left_spacing, y, height);
|
||||
x += left_spacing + e->widths[i] + right_spacing;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,13 @@ begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
struct eprivate *e = exposable->private;
|
||||
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
e->exposable->expose(
|
||||
e->exposable, cr, x + exposable->particle->left_margin, y, height);
|
||||
e->exposable, pix, x + exposable->particle->left_margin, y, height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
particle_sdk = declare_dependency(dependencies: [cairo, cairo_ft])
|
||||
particle_sdk = declare_dependency(dependencies: [freetype, fontconfig, pixman])
|
||||
|
||||
particles = []
|
||||
foreach particle : ['empty', 'list', 'map', 'progress-bar', 'ramp', 'string']
|
||||
|
|
|
@ -70,15 +70,15 @@ begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
const struct eprivate *e = exposable->private;
|
||||
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
|
||||
x += exposable->particle->left_margin;
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
e->exposables[i]->expose(e->exposables[i], cr, x, y, height);
|
||||
e->exposables[i]->expose(e->exposables[i], pix, x, y, height);
|
||||
x += e->exposables[i]->width;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ begin_expose(struct exposable *exposable)
|
|||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
struct eprivate *e = exposable->private;
|
||||
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
e->exposable->expose(
|
||||
e->exposable, cr, x + exposable->particle->left_margin, y, height);
|
||||
e->exposable, pix, x + exposable->particle->left_margin, y, height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -70,22 +70,10 @@ begin_expose(struct exposable *exposable)
|
|||
return exposable->width;
|
||||
}
|
||||
|
||||
static inline pixman_color_t
|
||||
color_hex_to_pixman_with_alpha(uint32_t color, uint16_t alpha)
|
||||
{
|
||||
int alpha_div = 0xffff / alpha;
|
||||
return (pixman_color_t){
|
||||
.red = ((color >> 16 & 0xff) | (color >> 8 & 0xff00)) / alpha_div,
|
||||
.green = ((color >> 8 & 0xff) | (color >> 0 & 0xff00)) / alpha_div,
|
||||
.blue = ((color >> 0 & 0xff) | (color << 8 & 0xff00)) / alpha_div,
|
||||
.alpha = alpha,
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
||||
expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int height)
|
||||
{
|
||||
exposable_render_deco(exposable, cr, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
|
||||
const struct eprivate *e = exposable->private;
|
||||
const struct font *font = exposable->particle->font;
|
||||
|
@ -112,24 +100,6 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
|||
(double)(height + font->fextents.ascent + font->fextents.descent) / 2.0 -
|
||||
(font->fextents.descent > 0 ? font->fextents.descent : 0);
|
||||
|
||||
/* TODO: get rid of cairo?... */
|
||||
cairo_surface_t *surf = cairo_get_target(cr);
|
||||
cairo_surface_flush(surf);
|
||||
|
||||
pixman_image_t *pix = pixman_image_create_bits_no_clear(
|
||||
PIXMAN_a8r8g8b8,
|
||||
cairo_image_surface_get_width(surf),
|
||||
cairo_image_surface_get_height(surf),
|
||||
(uint32_t *)cairo_image_surface_get_data(surf),
|
||||
cairo_image_surface_get_stride(surf));
|
||||
|
||||
uint32_t hex_color =
|
||||
(uint32_t)(uint8_t)(exposable->particle->foreground.red * 255) << 16 |
|
||||
(uint32_t)(uint8_t)(exposable->particle->foreground.green * 255) << 8 |
|
||||
(uint32_t)(uint8_t)(exposable->particle->foreground.blue * 255) << 0;
|
||||
uint16_t alpha = exposable->particle->foreground.alpha * 65535;
|
||||
pixman_color_t fg = color_hex_to_pixman_with_alpha(hex_color, alpha);
|
||||
|
||||
x += exposable->particle->left_margin;
|
||||
|
||||
/* Loop glyphs and render them, one by one */
|
||||
|
@ -145,7 +115,7 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
|||
glyph->width, glyph->height);
|
||||
} else {
|
||||
/* Glyph surface is an alpha mask */
|
||||
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
|
||||
pixman_image_t *src = pixman_image_create_solid_fill(&exposable->particle->foreground);
|
||||
pixman_image_composite32(
|
||||
PIXMAN_OP_OVER, src, glyph->pix, pix, 0, 0, 0, 0,
|
||||
x + glyph->x, baseline - glyph->y,
|
||||
|
@ -155,9 +125,6 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
|
|||
|
||||
x += glyph->x_advance;
|
||||
}
|
||||
|
||||
pixman_image_unref(pix);
|
||||
cairo_surface_mark_dirty(surf);
|
||||
}
|
||||
|
||||
static struct exposable *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue