libweston: move gl-borders up to weston_renderer

This just moves gl-borders up to libweston weston_renderer as-is,
with no change in functionality.
This is a preparation step so that other renderers can use the
same interface.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
This commit is contained in:
Erico Nunes 2025-05-18 17:43:27 +02:00
parent f71db77341
commit 4ab8d6d2c4
10 changed files with 101 additions and 101 deletions

View file

@ -42,7 +42,7 @@
#include "pixel-formats.h"
#include "pixman-renderer.h"
#include "renderer-gl/gl-renderer.h"
#include "gl-borders.h"
#include "renderer-borders.h"
#include "shared/weston-drm-fourcc.h"
#include "shared/weston-egl-ext.h"
#include "shared/cairo-util.h"
@ -84,9 +84,7 @@ struct headless_output {
weston_renderbuffer_t renderbuffer;
struct frame *frame;
struct {
struct weston_gl_borders borders;
} gl;
struct weston_renderer_borders borders;
};
static const uint32_t headless_formats[] = {
@ -144,15 +142,15 @@ finish_frame_handler(void *data)
}
static void
headless_output_update_gl_border(struct headless_output *output)
headless_output_update_renderer_border(struct headless_output *output)
{
if (!output->frame)
return;
if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
return;
weston_gl_borders_update(&output->gl.borders, output->frame,
&output->base);
weston_renderer_borders_update(&output->borders, output->frame,
&output->base);
}
static int
@ -166,7 +164,7 @@ headless_output_repaint(struct weston_output *output_base)
ec = output->base.compositor;
headless_output_update_gl_border(output);
headless_output_update_renderer_border(output);
pixman_region32_init(&damage);
@ -188,7 +186,7 @@ headless_output_disable_gl(struct headless_output *output)
struct weston_compositor *compositor = output->base.compositor;
const struct weston_renderer *renderer = compositor->renderer;
weston_gl_borders_fini(&output->gl.borders, &output->base);
weston_renderer_borders_fini(&output->borders, &output->base);
renderer->destroy_renderbuffer(output->renderbuffer);
output->renderbuffer = NULL;

View file

@ -17,7 +17,7 @@ plugin_headless = shared_library(
dep_libweston_private,
dep_libdrm_headers,
dep_lib_cairo_shared,
dep_lib_gl_borders,
dep_lib_renderer_borders,
],
name_prefix: '',
install: true,

View file

@ -21,7 +21,7 @@ deps_wlwl = [
dep_libweston_private,
dep_libdrm_headers,
dep_lib_cairo_shared,
dep_lib_gl_borders,
dep_lib_renderer_borders,
]
if get_option('renderer-gl')

View file

@ -48,7 +48,7 @@
#include <libweston/libweston.h>
#include <libweston/backend-wayland.h>
#include "renderer-gl/gl-renderer.h"
#include "gl-borders.h"
#include "renderer-borders.h"
#include "shared/weston-drm-fourcc.h"
#include "shared/weston-egl-ext.h"
#include "pixman-renderer.h"
@ -135,7 +135,6 @@ struct wayland_output {
struct {
struct wl_egl_window *egl_window;
struct weston_gl_borders borders;
} gl;
struct {
@ -143,6 +142,8 @@ struct wayland_output {
struct wl_list free_buffers;
} shm;
struct weston_renderer_borders borders;
struct weston_mode mode;
struct weston_mode native_mode;
@ -471,15 +472,15 @@ draw_initial_frame(struct wayland_output *output)
#ifdef ENABLE_EGL
static void
wayland_output_update_gl_border(struct wayland_output *output)
wayland_output_update_renderer_border(struct wayland_output *output)
{
if (!output->frame)
return;
if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
return;
weston_gl_borders_update(&output->gl.borders, output->frame,
&output->base);
weston_renderer_borders_update(&output->borders, output->frame,
&output->base);
}
#endif
@ -519,7 +520,7 @@ wayland_output_repaint_gl(struct weston_output *output_base)
output->frame_cb = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(output->frame_cb, &frame_listener, output);
wayland_output_update_gl_border(output);
wayland_output_update_renderer_border(output);
ec->renderer->repaint_output(&output->base, &damage, NULL);
@ -703,7 +704,7 @@ wayland_output_disable(struct weston_output *base)
break;
#ifdef ENABLE_EGL
case WESTON_RENDERER_GL:
weston_gl_borders_fini(&output->gl.borders, &output->base);
weston_renderer_borders_fini(&output->borders, &output->base);
renderer->gl->output_destroy(&output->base);
wl_egl_window_destroy(output->gl.egl_window);
@ -858,7 +859,7 @@ wayland_output_resize_surface(struct wayland_output *output)
weston_renderer_resize_output(&output->base, &fb_size, &area);
/* These will need to be re-created due to the resize */
weston_gl_borders_fini(&output->gl.borders, &output->base);
weston_renderer_borders_fini(&output->borders, &output->base);
} else
#endif
{

View file

@ -76,6 +76,13 @@ struct linux_dmabuf_memory {
void (*destroy)(struct linux_dmabuf_memory *dmabuf);
};
enum weston_renderer_border_side {
WESTON_RENDERER_BORDER_TOP = 0,
WESTON_RENDERER_BORDER_LEFT = 1,
WESTON_RENDERER_BORDER_RIGHT = 2,
WESTON_RENDERER_BORDER_BOTTOM = 3,
};
struct weston_renderer {
int (*read_pixels)(struct weston_output *output,
const struct pixel_format_info *format, void *pixels,
@ -202,6 +209,39 @@ struct weston_renderer {
enum weston_renderer_type type;
const struct gl_renderer_interface *gl;
const struct pixman_renderer_interface *pixman;
/* Sets the output border.
*
* The side specifies the side for which we are setting the border.
* The width and height are the width and height of the border.
* The tex_width patemeter specifies the width of the actual
* texture; this may be larger than width if the data is not
* tightly packed.
*
* The top and bottom textures will extend over the sides to the
* full width of the bordered window. The right and left edges,
* however, will extend only to the top and bottom of the
* compositor surface. This is demonstrated by the picture below:
*
* +-----------------------+
* | TOP |
* +-+-------------------+-+
* | | | |
* |L| |R|
* |E| |I|
* |F| |G|
* |T| |H|
* | | |T|
* | | | |
* +-+-------------------+-+
* | BOTTOM |
* +-----------------------+
*/
void (*output_set_border)(struct weston_output *output,
enum weston_renderer_border_side side,
int32_t width, int32_t height,
int32_t tex_width, unsigned char *data);
};
struct weston_tearing_control {

View file

@ -223,9 +223,9 @@ dep_vertex_clipping = declare_dependency(
include_directories: include_directories('.')
)
lib_gl_borders = static_library(
'gl-borders',
'gl-borders.c',
lib_renderer_borders = static_library(
'renderer-borders',
'renderer-borders.c',
include_directories: common_inc,
dependencies: [
dep_lib_cairo_shared,
@ -235,8 +235,8 @@ lib_gl_borders = static_library(
build_by_default: false,
install: false
)
dep_lib_gl_borders = declare_dependency(
link_with: lib_gl_borders,
dep_lib_renderer_borders = declare_dependency(
link_with: lib_renderer_borders,
dependencies: dep_lib_cairo_shared
)

View file

@ -28,16 +28,16 @@
#include "config.h"
#include "gl-borders.h"
#include "renderer-borders.h"
#include "shared/helpers.h"
void
weston_gl_borders_update(struct weston_gl_borders *borders,
weston_renderer_borders_update(struct weston_renderer_borders *borders,
struct frame *frame,
struct weston_output *output)
{
const struct gl_renderer_interface *glri =
output->compositor->renderer->gl;
const struct weston_renderer *renderer =
output->compositor->renderer;
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
fwidth = frame_width(frame);
@ -45,19 +45,19 @@ weston_gl_borders_update(struct weston_gl_borders *borders,
frame_interior(frame, &ix, &iy, &iwidth, &iheight);
struct weston_geometry border_area[4] = {
[GL_RENDERER_BORDER_TOP] = {
[WESTON_RENDERER_BORDER_TOP] = {
.x = 0, .y = 0,
.width = fwidth, .height = iy
},
[GL_RENDERER_BORDER_LEFT] = {
[WESTON_RENDERER_BORDER_LEFT] = {
.x = 0, .y = iy,
.width = ix, .height = 1
},
[GL_RENDERER_BORDER_RIGHT] = {
[WESTON_RENDERER_BORDER_RIGHT] = {
.x = iwidth + ix, .y = iy,
.width = fwidth - (ix + iwidth), .height = 1
},
[GL_RENDERER_BORDER_BOTTOM] = {
[WESTON_RENDERER_BORDER_BOTTOM] = {
.x = 0, .y = iy + iheight,
.width = fwidth, .height = fheight - (iy + iheight)
},
@ -80,20 +80,20 @@ weston_gl_borders_update(struct weston_gl_borders *borders,
cairo_translate(cr, -g->x, -g->y);
frame_repaint(frame, cr);
cairo_destroy(cr);
glri->output_set_border(output, i, g->width, g->height, tex_width,
cairo_image_surface_get_data(borders->tile[i]));
renderer->output_set_border(output, i, g->width, g->height, tex_width,
cairo_image_surface_get_data(borders->tile[i]));
}
}
void
weston_gl_borders_fini(struct weston_gl_borders *borders,
weston_renderer_borders_fini(struct weston_renderer_borders *borders,
struct weston_output *output)
{
const struct gl_renderer_interface *glri =
output->compositor->renderer->gl;
const struct weston_renderer *renderer =
output->compositor->renderer;
for (unsigned i = 0; i < ARRAY_LENGTH(borders->tile); i++) {
glri->output_set_border(output, i, 0, 0, 0, NULL);
renderer->output_set_border(output, i, 0, 0, 0, NULL);
cairo_surface_destroy(borders->tile[i]);
borders->tile[i] = NULL;
}

View file

@ -25,18 +25,18 @@
#pragma once
#include "renderer-gl/gl-renderer.h"
#include "libweston-internal.h"
#include "shared/cairo-util.h"
struct weston_gl_borders {
cairo_surface_t *tile[4]; /* enum gl_renderer_border_side */
struct weston_renderer_borders {
cairo_surface_t *tile[4];
};
void
weston_gl_borders_update(struct weston_gl_borders *borders,
struct frame *frame,
struct weston_output *output);
weston_renderer_borders_update(struct weston_renderer_borders *borders,
struct frame *frame,
struct weston_output *output);
void
weston_gl_borders_fini(struct weston_gl_borders *borders,
struct weston_output *output);
weston_renderer_borders_fini(struct weston_renderer_borders *borders,
struct weston_output *output);

View file

@ -97,10 +97,10 @@ enum gl_debug_mode {
enum gl_border_status {
BORDER_STATUS_CLEAN = 0,
BORDER_TOP_DIRTY = 1 << GL_RENDERER_BORDER_TOP,
BORDER_LEFT_DIRTY = 1 << GL_RENDERER_BORDER_LEFT,
BORDER_RIGHT_DIRTY = 1 << GL_RENDERER_BORDER_RIGHT,
BORDER_BOTTOM_DIRTY = 1 << GL_RENDERER_BORDER_BOTTOM,
BORDER_TOP_DIRTY = 1 << WESTON_RENDERER_BORDER_TOP,
BORDER_LEFT_DIRTY = 1 << WESTON_RENDERER_BORDER_LEFT,
BORDER_RIGHT_DIRTY = 1 << WESTON_RENDERER_BORDER_RIGHT,
BORDER_BOTTOM_DIRTY = 1 << WESTON_RENDERER_BORDER_BOTTOM,
BORDER_ALL_DIRTY = 0xf,
};
@ -2129,7 +2129,7 @@ static void
draw_output_border_texture(struct gl_renderer *gr,
struct gl_output_state *go,
struct gl_shader_config *sconf,
enum gl_renderer_border_side side,
enum weston_renderer_border_side side,
int32_t x, int32_t y,
int32_t width, int32_t height)
{
@ -2167,42 +2167,42 @@ output_has_borders(struct weston_output *output)
{
struct gl_output_state *go = get_output_state(output);
return go->borders_current[GL_RENDERER_BORDER_TOP].data ||
go->borders_current[GL_RENDERER_BORDER_RIGHT].data ||
go->borders_current[GL_RENDERER_BORDER_BOTTOM].data ||
go->borders_current[GL_RENDERER_BORDER_LEFT].data;
return go->borders_current[WESTON_RENDERER_BORDER_TOP].data ||
go->borders_current[WESTON_RENDERER_BORDER_RIGHT].data ||
go->borders_current[WESTON_RENDERER_BORDER_BOTTOM].data ||
go->borders_current[WESTON_RENDERER_BORDER_LEFT].data;
}
static struct weston_geometry
output_get_border_area(const struct gl_output_state *go,
enum gl_renderer_border_side side)
enum weston_renderer_border_side side)
{
const struct weston_size *fb = &go->fb_size;
const struct weston_geometry *area = &go->area;
switch (side) {
case GL_RENDERER_BORDER_TOP:
case WESTON_RENDERER_BORDER_TOP:
return (struct weston_geometry){
.x = 0,
.y = 0,
.width = fb->width,
.height = area->y
};
case GL_RENDERER_BORDER_LEFT:
case WESTON_RENDERER_BORDER_LEFT:
return (struct weston_geometry){
.x = 0,
.y = area->y,
.width = area->x,
.height = area->height
};
case GL_RENDERER_BORDER_RIGHT:
case WESTON_RENDERER_BORDER_RIGHT:
return (struct weston_geometry){
.x = area->x + area->width,
.y = area->y,
.width = fb->width - area->x - area->width,
.height = area->height
};
case GL_RENDERER_BORDER_BOTTOM:
case WESTON_RENDERER_BORDER_BOTTOM:
return (struct weston_geometry){
.x = 0,
.y = area->y + area->height,
@ -4133,7 +4133,7 @@ log_gl_info(struct gl_renderer *gr)
static void
gl_renderer_output_set_border(struct weston_output *output,
enum gl_renderer_border_side side,
enum weston_renderer_border_side side,
int32_t width, int32_t height,
int32_t tex_width, unsigned char *data)
{
@ -4637,6 +4637,7 @@ gl_renderer_display_create(struct weston_compositor *ec,
gr->base.surface_copy_content = gl_renderer_surface_copy_content;
gr->base.fill_buffer_info = gl_renderer_fill_buffer_info;
gr->base.buffer_init = gl_renderer_buffer_init;
gr->base.output_set_border = gl_renderer_output_set_border;
gr->base.type = WESTON_RENDERER_GL;
if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0)
@ -5085,6 +5086,5 @@ WL_EXPORT struct gl_renderer_interface gl_renderer_interface = {
.output_window_create = gl_renderer_output_window_create,
.output_fbo_create = gl_renderer_output_fbo_create,
.output_destroy = gl_renderer_output_destroy,
.output_set_border = gl_renderer_output_set_border,
.create_fence_fd = gl_renderer_create_fence_fd,
};

View file

@ -53,13 +53,6 @@ typedef intptr_t EGLNativeWindowType;
#endif /* ENABLE_EGL */
enum gl_renderer_border_side {
GL_RENDERER_BORDER_TOP = 0,
GL_RENDERER_BORDER_LEFT = 1,
GL_RENDERER_BORDER_RIGHT = 2,
GL_RENDERER_BORDER_BOTTOM = 3,
};
/**
* Options passed to the \c display_create method of the GL renderer interface.
*
@ -176,38 +169,6 @@ struct gl_renderer_interface {
void (*output_destroy)(struct weston_output *output);
/* Sets the output border.
*
* The side specifies the side for which we are setting the border.
* The width and height are the width and height of the border.
* The tex_width patemeter specifies the width of the actual
* texture; this may be larger than width if the data is not
* tightly packed.
*
* The top and bottom textures will extend over the sides to the
* full width of the bordered window. The right and left edges,
* however, will extend only to the top and bottom of the
* compositor surface. This is demonstrated by the picture below:
*
* +-----------------------+
* | TOP |
* +-+-------------------+-+
* | | | |
* |L| |R|
* |E| |I|
* |F| |G|
* |T| |H|
* | | |T|
* | | | |
* +-+-------------------+-+
* | BOTTOM |
* +-----------------------+
*/
void (*output_set_border)(struct weston_output *output,
enum gl_renderer_border_side side,
int32_t width, int32_t height,
int32_t tex_width, unsigned char *data);
/* Create fence sync FD to wait for GPU rendering.
*
* Return FD on success, -1 on failure or unsupported