backend: turn max_buffer_age into a function

We want to change the backend interface as little as possible once we
release it as a public interface, so while we still can, we should try
to give it maximum flexibility.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-05-23 15:13:37 +01:00
parent f5bebb3e2e
commit 5c1b0ba7a1
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
7 changed files with 30 additions and 10 deletions

View File

@ -450,7 +450,7 @@ struct backend_operations {
bool (*last_render_time)(backend_t *backend_data, struct timespec *ts);
/// The maximum number buffer_age might return.
int max_buffer_age;
int (*max_buffer_age)(backend_t *backend_data);
// =========== Post-processing ============
/// Create a blur context that can be used to call `blur` for images with a

View File

@ -204,6 +204,10 @@ bool dummy_is_format_supported(struct backend_base *base attr_unused,
return true;
}
static int dummy_max_buffer_age(struct backend_base *base attr_unused) {
return 5;
}
struct backend_operations dummy_ops = {
.apply_alpha = dummy_apply_alpha,
.back_buffer = dummy_back_buffer,
@ -222,7 +226,7 @@ struct backend_operations dummy_ops = {
.init = dummy_init,
.deinit = dummy_deinit,
.buffer_age = dummy_buffer_age,
.max_buffer_age = 5,
.max_buffer_age = dummy_max_buffer_age,
.create_blur_context = dummy_create_blur_context,
.destroy_blur_context = dummy_destroy_blur_context,

View File

@ -339,6 +339,14 @@ static void egl_diagnostics(backend_t *base) {
}
}
static int egl_max_buffer_age(backend_t *base attr_unused) {
if (!eglext.has_EGL_EXT_buffer_age) {
return 0;
}
return 5; // Why?
}
struct backend_operations egl_ops = {
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
@ -369,7 +377,7 @@ struct backend_operations egl_ops = {
.create_shader = gl_create_window_shader,
.destroy_shader = gl_destroy_window_shader,
.get_shader_attributes = gl_get_shader_attributes,
.max_buffer_age = 5, // Why?
.max_buffer_age = egl_max_buffer_age,
};
struct eglext_info eglext = {0};

View File

@ -517,6 +517,10 @@ static void glx_diagnostics(backend_t *base) {
}
}
static int glx_max_buffer_age(struct backend_base *base attr_unused) {
return 5; // Why?
}
struct backend_operations glx_ops = {
.apply_alpha = gl_apply_alpha,
.back_buffer = gl_back_buffer,
@ -547,7 +551,7 @@ struct backend_operations glx_ops = {
.create_shader = gl_create_window_shader,
.destroy_shader = gl_destroy_window_shader,
.get_shader_attributes = gl_get_shader_attributes,
.max_buffer_age = 5, // Why?
.max_buffer_age = glx_max_buffer_age,
};
struct glxext_info glxext = {0};

View File

@ -1020,6 +1020,10 @@ uint32_t xrender_quirks(struct backend_base *base) {
return ((struct xrender_data *)base)->quirks;
}
static int xrender_max_buffer_age(struct backend_base *base) {
return ((struct xrender_data *)base)->vsync ? 2 : 1;
}
struct backend_operations xrender_ops = {
.apply_alpha = xrender_apply_alpha,
.back_buffer = xrender_back_buffer,
@ -1042,7 +1046,7 @@ struct backend_operations xrender_ops = {
// `render_shadow`, and `backend_compat_shadow_from_mask` for
// `shadow_from_mask`
.buffer_age = xrender_buffer_age,
.max_buffer_age = 2,
.max_buffer_age = xrender_max_buffer_age,
.create_blur_context = xrender_create_blur_context,
.destroy_blur_context = xrender_destroy_blur_context,
.get_blur_size = xrender_get_blur_size

View File

@ -437,7 +437,7 @@ void add_damage(session_t *ps, const region_t *damage) {
return;
}
if (!damage) {
if (!damage || ps->damage_ring.count <= 0) {
return;
}
log_trace("Adding damage: ");
@ -1418,9 +1418,9 @@ static bool redirect_start(session_t *ps) {
if (!ps->o.use_legacy_backends) {
assert(ps->backend_data);
ps->damage_ring.count = ps->backend_data->ops->max_buffer_age;
ps->layout_manager =
layout_manager_new((unsigned)ps->backend_data->ops->max_buffer_age);
ps->damage_ring.count =
ps->backend_data->ops->max_buffer_age(ps->backend_data);
ps->layout_manager = layout_manager_new((unsigned)ps->damage_ring.count);
} else {
ps->damage_ring.count = maximum_buffer_age(ps);
}

View File

@ -154,7 +154,7 @@ renderer_init(struct renderer *renderer, struct backend_base *backend,
}
sum_kernel_preprocess(renderer->shadow_kernel);
}
renderer->max_buffer_age = backend->ops->max_buffer_age + 1;
renderer->max_buffer_age = backend->ops->max_buffer_age(backend) + 1;
return true;
}