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
|
@ -11,7 +11,8 @@ struct backend {
|
|||
void (*expose)(const struct bar *bar),
|
||||
void (*on_mouse)(struct bar *bar, enum mouse_event event,
|
||||
int x, int y));
|
||||
void (*commit_surface)(const struct bar *bar);
|
||||
pixman_image_t *(*get_pixman_image)(const struct bar *bar);
|
||||
void (*commit_pixman)(const struct bar *bar, pixman_image_t *pix);
|
||||
void (*refresh)(const struct bar *bar);
|
||||
void (*set_cursor)(struct bar *bar, const char *cursor);
|
||||
};
|
||||
|
|
45
bar/bar.c
45
bar/bar.c
|
@ -61,33 +61,21 @@ static void
|
|||
expose(const struct bar *_bar)
|
||||
{
|
||||
const struct private *bar = _bar->private;
|
||||
pixman_image_t *pix = bar->backend.iface->get_pixman_image(_bar);
|
||||
|
||||
double r, g, b, a;
|
||||
r = bar->background.red;
|
||||
g = bar->background.green;
|
||||
b = bar->background.blue;
|
||||
a = bar->background.alpha;
|
||||
|
||||
cairo_set_source_rgba(bar->cairo, r, g, b, a);
|
||||
cairo_set_operator(bar->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint(bar->cairo);
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, pix, &bar->background, 1,
|
||||
&(pixman_rectangle16_t){0, 0, bar->width, bar->height_with_border});
|
||||
|
||||
if (bar->border.width > 0) {
|
||||
r = bar->border.color.red;
|
||||
g = bar->border.color.green;
|
||||
b = bar->border.color.blue;
|
||||
a = bar->border.color.alpha;
|
||||
|
||||
cairo_set_line_width(bar->cairo, bar->border.width);
|
||||
cairo_set_source_rgba(bar->cairo, r, g, b, a);
|
||||
cairo_set_operator(bar->cairo, CAIRO_OPERATOR_OVER);
|
||||
cairo_rectangle(
|
||||
bar->cairo,
|
||||
bar->border.width / 2.0,
|
||||
bar->border.width / 2.0,
|
||||
bar->width - bar->border.width,
|
||||
bar->height_with_border - bar->border.width);
|
||||
cairo_stroke(bar->cairo);
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_OVER, pix, &bar->border.color, 4,
|
||||
(pixman_rectangle16_t[]){
|
||||
{0, 0, bar->width, bar->border.width},
|
||||
{0, 0, bar->border.width, bar->height},
|
||||
{bar->width - bar->border.width, 0, bar->border.width, bar->height},
|
||||
{0, bar->height - bar->border.width, bar->width, bar->border.width},
|
||||
});
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bar->left.count; i++) {
|
||||
|
@ -127,14 +115,14 @@ expose(const struct bar *_bar)
|
|||
int x = bar->border.width + bar->left_margin - bar->left_spacing;
|
||||
for (size_t i = 0; i < bar->left.count; i++) {
|
||||
const struct exposable *e = bar->left.exps[i];
|
||||
e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height);
|
||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||
}
|
||||
|
||||
x = bar->width / 2 - center_width / 2 - bar->left_spacing;
|
||||
for (size_t i = 0; i < bar->center.count; i++) {
|
||||
const struct exposable *e = bar->center.exps[i];
|
||||
e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height);
|
||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||
}
|
||||
|
||||
|
@ -146,12 +134,11 @@ expose(const struct bar *_bar)
|
|||
|
||||
for (size_t i = 0; i < bar->right.count; i++) {
|
||||
const struct exposable *e = bar->right.exps[i];
|
||||
e->expose(e, bar->cairo, x + bar->left_spacing, y, bar->height);
|
||||
e->expose(e, pix, x + bar->left_spacing, y, bar->height);
|
||||
x += bar->left_spacing + e->width + bar->right_spacing;
|
||||
}
|
||||
|
||||
cairo_surface_flush(bar->cairo_surface);
|
||||
bar->backend.iface->commit_surface(_bar);
|
||||
bar->backend.iface->commit_pixman(_bar, pix);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ struct bar_config {
|
|||
int left_spacing, right_spacing;
|
||||
int left_margin, right_margin;
|
||||
|
||||
struct rgba background;
|
||||
pixman_color_t background;
|
||||
|
||||
struct {
|
||||
int width;
|
||||
struct rgba color;
|
||||
pixman_color_t color;
|
||||
int left_margin, right_margin;
|
||||
int top_margin, bottom_margin;
|
||||
} border;
|
||||
|
|
|
@ -14,11 +14,11 @@ struct private {
|
|||
int left_spacing, right_spacing;
|
||||
int left_margin, right_margin;
|
||||
|
||||
struct rgba background;
|
||||
pixman_color_t background;
|
||||
|
||||
struct {
|
||||
int width;
|
||||
struct rgba color;
|
||||
pixman_color_t color;
|
||||
int left_margin, right_margin;
|
||||
int top_margin, bottom_margin;
|
||||
} border;
|
||||
|
|
|
@ -901,12 +901,31 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da
|
|||
;//printf("nothing more to do\n");
|
||||
}
|
||||
|
||||
static pixman_image_t *
|
||||
get_pixman_image(const struct bar *_bar)
|
||||
{
|
||||
struct private *bar = _bar->private;
|
||||
|
||||
cairo_surface_t *surf = cairo_get_target(bar->cairo);
|
||||
cairo_surface_flush(surf);
|
||||
|
||||
return 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));
|
||||
}
|
||||
|
||||
static void
|
||||
commit_surface(const struct bar *_bar)
|
||||
commit_pixman(const struct bar *_bar, pixman_image_t *pix)
|
||||
{
|
||||
struct private *bar = _bar->private;
|
||||
struct wayland_backend *backend = bar->backend.data;
|
||||
|
||||
pixman_image_unref(pix);
|
||||
cairo_surface_mark_dirty(cairo_get_target(bar->cairo));
|
||||
|
||||
//printf("commit: %dxl%d\n", backend->width, backend->height);
|
||||
|
||||
assert(backend->next_buffer != NULL);
|
||||
|
@ -973,7 +992,8 @@ const struct backend wayland_backend_iface = {
|
|||
.setup = &setup,
|
||||
.cleanup = &cleanup,
|
||||
.loop = &loop,
|
||||
.commit_surface = &commit_surface,
|
||||
.get_pixman_image = &get_pixman_image,
|
||||
.commit_pixman = &commit_pixman,
|
||||
.refresh = &refresh,
|
||||
.set_cursor = &set_cursor,
|
||||
};
|
||||
|
|
51
bar/xcb.c
51
bar/xcb.c
|
@ -370,10 +370,56 @@ loop(struct bar *_bar,
|
|||
}
|
||||
|
||||
static void
|
||||
commit_surface(const struct bar *_bar)
|
||||
free_pixman_bits(pixman_image_t *pix, void *data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
static pixman_image_t *
|
||||
get_pixman_image(const struct bar *_bar)
|
||||
{
|
||||
const struct private *bar = _bar->private;
|
||||
uint32_t *bits = malloc(
|
||||
bar->width * bar->height_with_border * sizeof(uint32_t));
|
||||
|
||||
pixman_image_t *ret = pixman_image_create_bits_no_clear(
|
||||
PIXMAN_a8r8g8b8,
|
||||
bar->width,
|
||||
bar->height_with_border,
|
||||
bits,
|
||||
bar->width * sizeof(uint32_t));
|
||||
|
||||
if (ret == NULL) {
|
||||
free(bits);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pixman_image_set_destroy_function(ret, &free_pixman_bits, bits);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
commit_pixman(const struct bar *_bar, pixman_image_t *pix)
|
||||
{
|
||||
const struct private *bar = _bar->private;
|
||||
const struct xcb_backend *backend = bar->backend.data;
|
||||
|
||||
/* Blit pixman image to our XCB surface */
|
||||
cairo_surface_t *surf = cairo_image_surface_create_for_data(
|
||||
(unsigned char *)pixman_image_get_data(pix),
|
||||
CAIRO_FORMAT_ARGB32,
|
||||
bar->width,
|
||||
bar->height_with_border,
|
||||
cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bar->width));
|
||||
|
||||
cairo_set_source_surface(bar->cairo, surf, 0, 0);
|
||||
cairo_set_operator(bar->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint(bar->cairo);
|
||||
|
||||
cairo_surface_flush(bar->cairo_surface);
|
||||
cairo_surface_destroy(surf);
|
||||
pixman_image_unref(pix);
|
||||
|
||||
xcb_copy_area(backend->conn, backend->pixmap, backend->win, backend->gc,
|
||||
0, 0, 0, 0, bar->width, bar->height_with_border);
|
||||
xcb_flush(backend->conn);
|
||||
|
@ -430,7 +476,8 @@ const struct backend xcb_backend_iface = {
|
|||
.setup = &setup,
|
||||
.cleanup = &cleanup,
|
||||
.loop = &loop,
|
||||
.commit_surface = &commit_surface,
|
||||
.get_pixman_image = &get_pixman_image,
|
||||
.commit_pixman = &commit_pixman,
|
||||
.refresh = &refresh,
|
||||
.set_cursor = &set_cursor,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue