mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
scaled-scene-buffer: restructure source files
Some checks failed
labwc.github.io / notify (push) Has been cancelled
Some checks failed
labwc.github.io / notify (push) Has been cancelled
- Rename `scaled_scene_buffer` to `scaled_buffer`. This makes it clear
that `scaled_{font,img,icon}_buffers` are implementations of it.
- Move the files from `src/common` to `src/scaled-buffer` as
`scaled_icon_buffer` heavily depends on `server` and `view` etc.
This commit is contained in:
parent
02be24bf59
commit
074b27fd47
22 changed files with 128 additions and 125 deletions
146
include/scaled-buffer/scaled-buffer.h
Normal file
146
include/scaled-buffer/scaled-buffer.h
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_SCALED_BUFFER_H
|
||||
#define LABWC_SCALED_BUFFER_H
|
||||
|
||||
#include <wayland-server-core.h>
|
||||
|
||||
#define LAB_SCALED_BUFFER_MAX_CACHE 2
|
||||
|
||||
struct wlr_buffer;
|
||||
struct wlr_scene_tree;
|
||||
struct lab_data_buffer;
|
||||
struct scaled_buffer;
|
||||
|
||||
struct scaled_buffer_impl {
|
||||
/* Return a new buffer optimized for the new scale */
|
||||
struct lab_data_buffer *(*create_buffer)
|
||||
(struct scaled_buffer *scaled_buffer, double scale);
|
||||
/* Might be NULL or used for cleaning up */
|
||||
void (*destroy)(struct scaled_buffer *scaled_buffer);
|
||||
/* Returns true if the two buffers are visually the same */
|
||||
bool (*equal)(struct scaled_buffer *scaled_buffer_a,
|
||||
struct scaled_buffer *scaled_buffer_b);
|
||||
};
|
||||
|
||||
struct scaled_buffer {
|
||||
struct wlr_scene_buffer *scene_buffer;
|
||||
int width; /* unscaled, read only */
|
||||
int height; /* unscaled, read only */
|
||||
void *data; /* opaque user data */
|
||||
|
||||
/* Private */
|
||||
bool drop_buffer;
|
||||
double active_scale;
|
||||
/* cached wlr_buffers for each scale */
|
||||
struct wl_list cache; /* struct scaled_buffer_cache_entry.link */
|
||||
struct wl_listener destroy;
|
||||
struct wl_listener outputs_update;
|
||||
const struct scaled_buffer_impl *impl;
|
||||
struct wl_list link; /* all_scaled_buffers */
|
||||
};
|
||||
|
||||
/*
|
||||
* | |
|
||||
* .------------------. .------------.
|
||||
* scaled_buffer | new_output_scale | | set_buffer |
|
||||
* architecture ´------------------` ´------------`
|
||||
* | ^
|
||||
* .-----------------------------|----------------|-----------.
|
||||
* | v | |
|
||||
* | .---------------. .-------------------------. |
|
||||
* | | scaled_buffer |----| wlr_buffer LRU cache(2) |<---, |
|
||||
* | ´---------------` ´-------------------------` | |
|
||||
* | | | | |
|
||||
* | .------. .--------------------------. | |
|
||||
* | | impl | | wlr_buffer LRU cache of | | |
|
||||
* | ´------` | other scaled_buffers | | |
|
||||
* | | with impl->equal() | | |
|
||||
* | ´--------------------------` | |
|
||||
* | / | | |
|
||||
* | not found found | |
|
||||
* | .-----------------------. .-----------. | |
|
||||
* | | impl->create_buffer() |--->| wlr_buffer |------` |
|
||||
* | ´-----------------------` ´------------` |
|
||||
* | |
|
||||
* ´----------------------------------------------------------`
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create an auto scaling buffer that creates a wlr_scene_buffer
|
||||
* and subscribes to its output_enter and output_leave signals.
|
||||
*
|
||||
* If the maximal scale changes, it either sets an already existing buffer
|
||||
* that was rendered for the current scale or - if there is none - calls
|
||||
* implementation->create_buffer(self, scale) to get a new lab_data_buffer
|
||||
* optimized for the new scale.
|
||||
*
|
||||
* Up to LAB_SCALED_BUFFER_MAX_CACHE (2) buffers are cached in an LRU fashion
|
||||
* to handle the majority of use cases where a view is moved between no more
|
||||
* than two different scales.
|
||||
*
|
||||
* scaled_buffer will clean up automatically once the internal
|
||||
* wlr_scene_buffer is being destroyed. If implementation->destroy is set
|
||||
* it will also get called so a consumer of this API may clean up its own
|
||||
* allocations.
|
||||
*
|
||||
* Besides caching buffers for each scale per scaled_buffer, we also
|
||||
* store all the scaled_buffers from all the implementers in a list
|
||||
* in order to reuse backing buffers for visually duplicated
|
||||
* scaled_buffers found via impl->equal().
|
||||
*
|
||||
* All requested lab_data_buffers via impl->create_buffer() will be locked
|
||||
* during the lifetime of the buffer in the internal cache and unlocked
|
||||
* when being evacuated from the cache (due to LAB_SCALED_BUFFER_MAX_CACHE
|
||||
* or the internal wlr_scene_buffer being destroyed).
|
||||
*
|
||||
* If drop_buffer was set during creation of the scaled_buffer, the
|
||||
* backing wlr_buffer behind a lab_data_buffer will also get dropped
|
||||
* (via wlr_buffer_drop). If there are no more locks (consumers) of the
|
||||
* respective buffer this will then cause the lab_data_buffer to be free'd.
|
||||
*
|
||||
* In the case of the buffer provider dropping the buffer itself (due to
|
||||
* for example a Reconfigure event) the lock prevents the buffer from being
|
||||
* destroyed until the buffer is evacuated from the internal cache and thus
|
||||
* unlocked.
|
||||
*
|
||||
* This allows using scaled_buffer for an autoscaling font_buffer
|
||||
* (which gets free'd automatically) and also for theme components like
|
||||
* rounded corner images or button icons whose buffers only exist once but
|
||||
* are references by multiple windows with their own scaled_buffers.
|
||||
*
|
||||
* The rough idea is: use drop_buffer = true for one-shot buffers and false
|
||||
* for buffers that should outlive the scaled_buffer instance itself.
|
||||
*/
|
||||
struct scaled_buffer *scaled_buffer_create(
|
||||
struct wlr_scene_tree *parent,
|
||||
const struct scaled_buffer_impl *implementation,
|
||||
bool drop_buffer);
|
||||
|
||||
/**
|
||||
* scaled_buffer_request_update - mark the buffer that needs to be
|
||||
* updated
|
||||
* @width: the width of the buffer to be rendered, in scene coordinates
|
||||
* @height: the height of the buffer to be rendered, in scene coordinates
|
||||
*
|
||||
* This function should be called when the states bound to the buffer are
|
||||
* updated and ready for rendering.
|
||||
*/
|
||||
void scaled_buffer_request_update(struct scaled_buffer *self,
|
||||
int width, int height);
|
||||
|
||||
/**
|
||||
* scaled_buffer_invalidate_sharing - clear the list of entire cached
|
||||
* scaled_buffers used to share visually dupliated buffers. This should
|
||||
* be called on Reconfigure to force updates of newly created
|
||||
* scaled_buffers rather than reusing ones created before Reconfigure.
|
||||
*/
|
||||
void scaled_buffer_invalidate_sharing(void);
|
||||
|
||||
/* Private */
|
||||
struct scaled_buffer_cache_entry {
|
||||
struct wl_list link; /* struct scaled_buffer.cache */
|
||||
struct wlr_buffer *buffer;
|
||||
double scale;
|
||||
};
|
||||
|
||||
#endif /* LABWC_SCALED_BUFFER_H */
|
||||
84
include/scaled-buffer/scaled-font-buffer.h
Normal file
84
include/scaled-buffer/scaled-font-buffer.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_SCALED_FONT_BUFFER_H
|
||||
#define LABWC_SCALED_FONT_BUFFER_H
|
||||
|
||||
#include "common/font.h"
|
||||
|
||||
struct wlr_scene_tree;
|
||||
struct wlr_scene_buffer;
|
||||
struct scaled_buffer;
|
||||
|
||||
struct scaled_font_buffer {
|
||||
struct wlr_scene_buffer *scene_buffer;
|
||||
int width; /* unscaled, read only */
|
||||
int height; /* unscaled, read only */
|
||||
|
||||
/* Private */
|
||||
char *text;
|
||||
int max_width;
|
||||
float color[4];
|
||||
float bg_color[4];
|
||||
struct font font;
|
||||
struct scaled_buffer *scaled_buffer;
|
||||
|
||||
/*
|
||||
* The following fields are used only for the titlebar, where
|
||||
* the font buffer can be rendered with a pattern background to
|
||||
* support gradients. In this case, the font buffer is also
|
||||
* padded to a fixed height (with the text centered vertically)
|
||||
* in order to align the pattern with the rest of the titlebar.
|
||||
*/
|
||||
int fixed_height;
|
||||
cairo_pattern_t *bg_pattern; /* overrides bg_color if set */
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an auto scaling font buffer, providing a wlr_scene_buffer node for
|
||||
* display. It gets destroyed automatically when the backing scaled_buffer
|
||||
* is being destroyed which in turn happens automatically when the backing
|
||||
* wlr_scene_buffer (or one of its parents) is being destroyed.
|
||||
*
|
||||
* To actually show some text, scaled_font_buffer_update() has to be called.
|
||||
*
|
||||
*/
|
||||
struct scaled_font_buffer *scaled_font_buffer_create(struct wlr_scene_tree *parent);
|
||||
|
||||
/**
|
||||
* Create an auto scaling font buffer for titlebar text.
|
||||
* The font buffer takes a new reference to bg_pattern.
|
||||
*
|
||||
* @param fixed_height Fixed height for the buffer (logical pixels)
|
||||
* @param bg_pattern Background pattern (solid color or gradient)
|
||||
*/
|
||||
struct scaled_font_buffer *
|
||||
scaled_font_buffer_create_for_titlebar(struct wlr_scene_tree *parent,
|
||||
int fixed_height, cairo_pattern_t *bg_pattern);
|
||||
|
||||
/**
|
||||
* Update an existing auto scaling font buffer.
|
||||
*
|
||||
* No steps are taken to detect if its actually required to render a new buffer.
|
||||
* This should be done by the caller to prevent useless recreation of the same
|
||||
* buffer in case nothing actually changed.
|
||||
*
|
||||
* Some basic checks could be something like
|
||||
* - truncated = buffer->width == max_width
|
||||
* - text_changed = strcmp(old_text, new_text)
|
||||
* - font and color the same
|
||||
*
|
||||
* bg_color is ignored for font buffers created with
|
||||
* scaled_font_buffer_create_for_titlebar().
|
||||
*/
|
||||
void scaled_font_buffer_update(struct scaled_font_buffer *self, const char *text,
|
||||
int max_width, struct font *font, const float *color,
|
||||
const float *bg_color);
|
||||
|
||||
/**
|
||||
* Update the max width of an existing auto scaling font buffer
|
||||
* and force a new render.
|
||||
*
|
||||
* No steps are taken to detect if its actually required to render a new buffer.
|
||||
*/
|
||||
void scaled_font_buffer_set_max_width(struct scaled_font_buffer *self, int max_width);
|
||||
|
||||
#endif /* LABWC_SCALED_FONT_BUFFER_H */
|
||||
54
include/scaled-buffer/scaled-icon-buffer.h
Normal file
54
include/scaled-buffer/scaled-icon-buffer.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_SCALED_ICON_BUFFER_H
|
||||
#define LABWC_SCALED_ICON_BUFFER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server-core.h>
|
||||
|
||||
struct wlr_scene_tree;
|
||||
struct wlr_scene_node;
|
||||
struct wlr_scene_buffer;
|
||||
|
||||
struct scaled_icon_buffer {
|
||||
struct scaled_buffer *scaled_buffer;
|
||||
struct wlr_scene_buffer *scene_buffer;
|
||||
struct server *server;
|
||||
/* for window icon */
|
||||
struct view *view;
|
||||
char *view_app_id;
|
||||
char *view_icon_name;
|
||||
bool view_icon_prefer_client;
|
||||
struct wl_array view_icon_buffers;
|
||||
struct {
|
||||
struct wl_listener new_app_id;
|
||||
struct wl_listener new_title;
|
||||
struct wl_listener set_icon;
|
||||
struct wl_listener destroy;
|
||||
} on_view;
|
||||
/* for general icon (e.g. in menus) */
|
||||
char *icon_name;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
/*
|
||||
* Create an auto scaling icon buffer, providing a wlr_scene_buffer node for
|
||||
* display. It gets destroyed automatically when the backing scaled_buffer
|
||||
* is being destroyed which in turn happens automatically when the backing
|
||||
* wlr_scene_buffer (or one of its parents) is being destroyed.
|
||||
*/
|
||||
struct scaled_icon_buffer *scaled_icon_buffer_create(
|
||||
struct wlr_scene_tree *parent, struct server *server,
|
||||
int width, int height);
|
||||
|
||||
void scaled_icon_buffer_set_view(struct scaled_icon_buffer *self,
|
||||
struct view *view);
|
||||
|
||||
void scaled_icon_buffer_set_icon_name(struct scaled_icon_buffer *self,
|
||||
const char *icon_name);
|
||||
|
||||
/* Obtain scaled_icon_buffer from wlr_scene_node */
|
||||
struct scaled_icon_buffer *scaled_icon_buffer_from_node(struct wlr_scene_node *node);
|
||||
|
||||
#endif /* LABWC_SCALED_ICON_BUFFER_H */
|
||||
72
include/scaled-buffer/scaled-img-buffer.h
Normal file
72
include/scaled-buffer/scaled-img-buffer.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_SCALED_IMG_BUFFER_H
|
||||
#define LABWC_SCALED_IMG_BUFFER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wlr_scene_tree;
|
||||
struct wlr_scene_node;
|
||||
struct wlr_scene_buffer;
|
||||
struct lab_img;
|
||||
|
||||
struct scaled_img_buffer {
|
||||
struct scaled_buffer *scaled_buffer;
|
||||
struct wlr_scene_buffer *scene_buffer;
|
||||
struct lab_img *img;
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
/*
|
||||
* | |
|
||||
* .------------------. .------------.
|
||||
* scaled_img_buffer | new_output_scale | | set_buffer |
|
||||
* architecture ´------------------` ´------------`
|
||||
* | ^
|
||||
* .--------------------------------|----------------|-------------.
|
||||
* | v | |
|
||||
* | .-------------------. .-------------------------. |
|
||||
* | | scaled_img_buffer |----| wlr_buffer LRU cache(2) |<----, |
|
||||
* | ´-------------------` ´-------------------------` | |
|
||||
* | | | | |
|
||||
* | | .--------------------------. | |
|
||||
* | | | wlr_buffer LRU cache of | | |
|
||||
* .-------. | | | other scaled_img_buffers | | |
|
||||
* | theme | | | | with lab_img_equal() | | |
|
||||
* ´-------` | | ´--------------------------` | |
|
||||
* | | | / | | |
|
||||
* | | | not found found | |
|
||||
* .---------. | .---------. .----------. .------------. | |
|
||||
* | lab_img |-img_copy-->| lab_img |-----| render() |--->| wlr_buffer |-----` |
|
||||
* ´---------` | ´---------` ´----------` ´------------` |
|
||||
* \ | / |
|
||||
* \ ´----------/----------------------------------------------------`
|
||||
* \ /
|
||||
* .----------------. lab_img provides:
|
||||
* | lab_img_data | - render function
|
||||
* | refcount=2 | - list of modification functions
|
||||
* | `-----------------. to apply on top of lib_img_data
|
||||
* | | when rendering
|
||||
* | provides (depending on backend): | - lab_img_equal() comparing the
|
||||
* | - librsvg handle | lab_img_data reference and
|
||||
* | - cairo surface | modification function pointers
|
||||
* ´----------------------------------` of two given lab_img instances
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create an auto scaling image buffer, providing a wlr_scene_buffer node for
|
||||
* display. It gets destroyed automatically when the backing scaled_buffer
|
||||
* is being destroyed which in turn happens automatically when the backing
|
||||
* wlr_scene_buffer (or one of its parents) is being destroyed.
|
||||
*
|
||||
* This function clones the lab_img passed as the image source, so callers are
|
||||
* free to destroy it.
|
||||
*/
|
||||
struct scaled_img_buffer *scaled_img_buffer_create(struct wlr_scene_tree *parent,
|
||||
struct lab_img *img, int width, int height);
|
||||
|
||||
/* Obtain scaled_img_buffer from wlr_scene_node */
|
||||
struct scaled_img_buffer *scaled_img_buffer_from_node(struct wlr_scene_node *node);
|
||||
|
||||
#endif /* LABWC_SCALED_IMG_BUFFER_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue