ssd: rework titlebar button rendering

- fix that icons for normal/hovered/rounded buttons are not placed
  exactly the same position
- fix blurry window button icons in scaled outputs

This commit introduces lab_img and scaled_img_buffer and uses them for
rendering icons in the window titlebar. Now the process of rendering
button icons are split into 2 phases: loading with lab_img_load() and
creating scene-nodes for them with scaled_img_buffer_create(). This
might incur some additional overhead since we no longer preload icon
textures, but the rendering of icon only happens for the first window
as backing buffers are shared and the overhead won't be noticeable.
This commit also simplifies the process of centering icon buffer in the
button, by creating icon buffers in a fixed geometry via
lab_img_render().
This commit is contained in:
tokyo4j 2024-11-28 19:21:18 +09:00 committed by Hiroaki Yamamoto
parent 9a3412324d
commit 16dbdc64e5
25 changed files with 647 additions and 391 deletions

View file

@ -29,7 +29,6 @@
#include <drm_fourcc.h>
#include <wlr/interfaces/wlr_buffer.h>
#include "buffer.h"
#include "common/box.h"
#include "common/mem.h"
static const struct wlr_buffer_impl data_buffer_impl;
@ -130,59 +129,6 @@ buffer_create_cairo(uint32_t logical_width, uint32_t logical_height, float scale
return buffer;
}
struct lab_data_buffer *
buffer_convert_cairo_surface_for_icon(cairo_surface_t *surface,
uint32_t icon_size, float scale)
{
assert(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE);
/*
* Compute logical size for display and decide whether we can
* use the image data directly (fast path). Requirements are:
*
* - The pixel format must be ARGB32.
* - The image must not be so large as to need downsampling by
* more than 2x when displayed at the target scale. wlr_scene
* uses linear interpolation without pixel averaging, which
* starts to skip samples if downsampling more than 2x,
* resulting in a grainy look.
*/
int width = cairo_image_surface_get_width(surface);
int height = cairo_image_surface_get_height(surface);
struct wlr_box logical =
box_fit_within(width, height, icon_size, icon_size);
struct lab_data_buffer *buffer;
if (cairo_image_surface_get_format(surface) == CAIRO_FORMAT_ARGB32
&& width <= 2 * logical.width * scale
&& height <= 2 * logical.height * scale) {
buffer = buffer_adopt_cairo_surface(surface);
/* set logical size for display */
buffer->logical_width = logical.width;
buffer->logical_height = logical.height;
} else {
/* convert to ARGB32 and scale for display (slow path) */
buffer = buffer_create_cairo(logical.width,
logical.height, scale);
cairo_t *cairo = cairo_create(buffer->surface);
cairo_scale(cairo, (double)logical.width / width,
(double)logical.height / height);
cairo_set_source_surface(cairo, surface, 0, 0);
cairo_pattern_set_filter(cairo_get_source(cairo),
CAIRO_FILTER_GOOD);
cairo_paint(cairo);
/* ensure pixel data is updated */
cairo_surface_flush(buffer->surface);
/* destroy original cairo surface & context */
cairo_surface_destroy(surface);
cairo_destroy(cairo);
}
return buffer;
}
struct lab_data_buffer *
buffer_create_from_data(void *pixel_data, uint32_t width, uint32_t height,
uint32_t stride)