Skip to content

Commit

Permalink
Disable cairo antialiasing with Wayland fractional scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
stacyharper authored and Cloudef committed Jul 14, 2024
1 parent bd62fb3 commit 6c7c6b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/renderers/cairo_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct cairo {
cairo_surface_t *surface;
PangoContext *pango;
double scale;
bool antialiasing;
};

struct cairo_color {
Expand Down Expand Up @@ -67,7 +68,8 @@ bm_cairo_create_for_surface(struct cairo *cairo, cairo_surface_t *surface)
if (!(cairo->pango = pango_cairo_create_context(cairo->cr)))
goto fail;

cairo_set_antialias(cairo->cr, CAIRO_ANTIALIAS_DEFAULT);
if (!cairo->antialiasing)
cairo_set_antialias(cairo->cr, CAIRO_ANTIALIAS_NONE);

cairo->surface = surface;
assert(cairo->scale > 0);
Expand Down
10 changes: 8 additions & 2 deletions lib/renderers/wayland/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ destroy_buffer(struct buffer *buffer)
}

static bool
create_buffer(struct wl_shm *shm, struct buffer *buffer, int32_t width, int32_t height, uint32_t format, double scale)
create_buffer(struct wl_shm *shm, struct buffer *buffer, int32_t width, int32_t height, uint32_t format, double scale, bool antialiasing)
{
int fd = -1;
struct wl_shm_pool *pool = NULL;
Expand Down Expand Up @@ -154,6 +154,12 @@ create_buffer(struct wl_shm *shm, struct buffer *buffer, int32_t width, int32_t
buffer->cairo.scale = scale;
}

if (antialiasing) {
buffer->cairo.antialiasing = true;
} else {
buffer->cairo.antialiasing = false;
}

if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) {
cairo_surface_destroy(surf);
goto fail;
Expand Down Expand Up @@ -192,7 +198,7 @@ next_buffer(struct window *window)
if ((uint32_t) ceil(window->width * window->scale) != buffer->width || (uint32_t) ceil(window->height * window->scale) != buffer->height)
destroy_buffer(buffer);

if (!buffer->buffer && !create_buffer(window->shm, buffer, ceil(window->width * window->scale), ceil(window->height * window->scale), WL_SHM_FORMAT_ARGB8888, window->scale))
if (!buffer->buffer && !create_buffer(window->shm, buffer, ceil(window->width * window->scale), ceil(window->height * window->scale), WL_SHM_FORMAT_ARGB8888, window->scale, !window->wayland->fractional_scaling))
return NULL;

return buffer;
Expand Down
2 changes: 2 additions & 0 deletions lib/renderers/x11/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ create_buffer(struct window *window, struct buffer *buffer, int32_t width, int32
buffer->cairo.scale = 1;
}

buffer->cairo.antialiasing = true;

if (!bm_cairo_create_for_surface(&buffer->cairo, surf)) {
cairo_surface_destroy(surf);
goto fail;
Expand Down

0 comments on commit 6c7c6b8

Please sign in to comment.