mirror of
https://github.com/labwc/labwc.git
synced 2025-10-31 22:25:34 -04:00
After a roundabout discussion[1] with wlroots devs, it's become apparent that subpixel text rendering (a.k.a. "ClearType") does not work properly when rendering over a transparent background, as labwc currently does. Basically it comes down to the fact that the color of semi-transparent pixels (which is adjusted redder or bluer to compensate for RGB subpixel alignment) depends somewhat on background color. When rendering over transparency, the text engine doesn't know the intended background color and can't adjust the pixel colors correctly. With Pango/Cairo, the end result can range from grayscale rendering (no subpixel rendering at all) to wrong/oversaturated colors (for example, bright pink pixels when rendering white text on blue background). This change solves the issue by first filling the text buffer with an opaque background color before rendering the text over it. Currently, this is easy since the background is always a solid color. It may be a little more complex (but doable) if we implement gradients in future. Note that GTK 4 (and to some degree, recent versions of Microsoft Windows) avoid this issue by disabling subpixel rendering altogether. I would much prefer that labwc NOT do this -- it results in noticeably blurrier text on non-retina LCD screens, which are still common. [1] https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3822
60 lines
1.6 KiB
C
60 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#ifndef LABWC_GRAPHIC_HELPERS_H
|
|
#define LABWC_GRAPHIC_HELPERS_H
|
|
|
|
#include <cairo.h>
|
|
#include <wayland-server-core.h>
|
|
|
|
struct wlr_scene_tree;
|
|
struct wlr_scene_rect;
|
|
struct wlr_fbox;
|
|
|
|
struct multi_rect {
|
|
struct wlr_scene_tree *tree;
|
|
int line_width; /* read-only */
|
|
|
|
/* Private */
|
|
struct wlr_scene_rect *top[3];
|
|
struct wlr_scene_rect *bottom[3];
|
|
struct wlr_scene_rect *left[3];
|
|
struct wlr_scene_rect *right[3];
|
|
struct wl_listener destroy;
|
|
};
|
|
|
|
/**
|
|
* Create a new multi_rect.
|
|
* A multi_rect consists of 3 nested rectangular outlines.
|
|
* Each of the rectangular outlines is using the same @line_width
|
|
* but its own color based on the @colors argument.
|
|
*
|
|
* The multi-rect can be positioned by positioning multi_rect->tree->node.
|
|
*
|
|
* It can be destroyed by destroying its tree node (or one of its
|
|
* parent nodes). Once the tree node has been destroyed the struct
|
|
* will be free'd automatically.
|
|
*/
|
|
struct multi_rect *multi_rect_create(struct wlr_scene_tree *parent,
|
|
float *colors[3], int line_width);
|
|
|
|
void multi_rect_set_size(struct multi_rect *rect, int width, int height);
|
|
|
|
/**
|
|
* Sets the cairo color.
|
|
* Splits a float[4] single color array into its own arguments
|
|
*/
|
|
void set_cairo_color(cairo_t *cairo, const float *color);
|
|
|
|
/* Draws a border with a specified line width */
|
|
void draw_cairo_border(cairo_t *cairo, struct wlr_fbox fbox, double line_width);
|
|
|
|
struct lab_data_buffer;
|
|
|
|
struct surface_context {
|
|
bool is_duplicate;
|
|
cairo_surface_t *surface;
|
|
};
|
|
|
|
struct surface_context get_cairo_surface_from_lab_data_buffer(
|
|
struct lab_data_buffer *buffer);
|
|
|
|
#endif /* LABWC_GRAPHIC_HELPERS_H */
|