libweston: move gl-borders code into helper lib

Move this code from headless-backend to a helper library, so it can be
shared with wayland-backend.

gl-renderer.h was missing #pragma once, which made the build fail.

Unfortunately gl-borders needs gl-renderer.h which will attempt to
include EGL headers if gl-renderer is enabled in the build, so we must
get the EGL build flags too, just for the headers.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2022-12-08 17:15:21 +02:00 committed by Pekka Paalanen
parent c57112a40a
commit e619a65b09
6 changed files with 161 additions and 69 deletions

View File

@ -42,6 +42,7 @@
#include "pixel-formats.h"
#include "pixman-renderer.h"
#include "renderer-gl/gl-renderer.h"
#include "gl-borders.h"
#include "shared/weston-drm-fourcc.h"
#include "shared/weston-egl-ext.h"
#include "shared/cairo-util.h"
@ -64,10 +65,6 @@ struct headless_head {
struct weston_head base;
};
struct weston_gl_borders {
cairo_surface_t *tile[4]; /* enum gl_renderer_border_side */
};
struct headless_output {
struct weston_output base;
@ -137,59 +134,6 @@ finish_frame_handler(void *data)
return 1;
}
static void
weston_gl_borders_update(struct weston_gl_borders *borders,
struct frame *frame,
struct weston_output *output,
struct gl_renderer_interface *glri)
{
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
fwidth = frame_width(frame);
fheight = frame_height(frame);
frame_interior(frame, &ix, &iy, &iwidth, &iheight);
struct weston_geometry border_area[4] = {
[GL_RENDERER_BORDER_TOP] = {
.x = 0, .y = 0,
.width = fwidth, .height = iy
},
[GL_RENDERER_BORDER_LEFT] = {
.x = 0, .y = iy,
.width = ix, .height = 1
},
[GL_RENDERER_BORDER_RIGHT] = {
.x = iwidth + ix, .y = iy,
.width = fwidth - (ix + iwidth), .height = 1
},
[GL_RENDERER_BORDER_BOTTOM] = {
.x = 0, .y = iy + iheight,
.width = fwidth, .height = fheight - (iy + iheight)
},
};
for (unsigned i = 0; i < ARRAY_LENGTH(border_area); i++) {
const struct weston_geometry *g = &border_area[i];
int tex_width;
cairo_t *cr;
if (!borders->tile[i]) {
borders->tile[i] =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
g->width, g->height);
}
tex_width = cairo_image_surface_get_stride(borders->tile[i]) / 4;
cr = cairo_create(borders->tile[i]);
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]));
}
}
static void
headless_output_update_gl_border(struct headless_output *output)
{
@ -227,18 +171,6 @@ headless_output_repaint(struct weston_output *output_base,
return 0;
}
static void
weston_gl_borders_fini(struct weston_gl_borders *borders,
struct weston_output *output,
struct gl_renderer_interface *glri)
{
for (unsigned i = 0; i < ARRAY_LENGTH(borders->tile); i++) {
glri->output_set_border(output, i, 0, 0, 0, NULL);
cairo_surface_destroy(borders->tile[i]);
borders->tile[i] = NULL;
}
}
static void
headless_output_disable_gl(struct headless_output *output)
{

View File

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

97
libweston/gl-borders.c Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright © 2010-2011 Benjamin Franzke
* Copyright © 2012 Intel Corporation
* Copyright © 2013 Jason Ekstrand
* Copyright 2022 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "config.h"
#include "gl-borders.h"
#include "shared/helpers.h"
void
weston_gl_borders_update(struct weston_gl_borders *borders,
struct frame *frame,
struct weston_output *output,
struct gl_renderer_interface *glri)
{
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
fwidth = frame_width(frame);
fheight = frame_height(frame);
frame_interior(frame, &ix, &iy, &iwidth, &iheight);
struct weston_geometry border_area[4] = {
[GL_RENDERER_BORDER_TOP] = {
.x = 0, .y = 0,
.width = fwidth, .height = iy
},
[GL_RENDERER_BORDER_LEFT] = {
.x = 0, .y = iy,
.width = ix, .height = 1
},
[GL_RENDERER_BORDER_RIGHT] = {
.x = iwidth + ix, .y = iy,
.width = fwidth - (ix + iwidth), .height = 1
},
[GL_RENDERER_BORDER_BOTTOM] = {
.x = 0, .y = iy + iheight,
.width = fwidth, .height = fheight - (iy + iheight)
},
};
for (unsigned i = 0; i < ARRAY_LENGTH(border_area); i++) {
const struct weston_geometry *g = &border_area[i];
int tex_width;
cairo_t *cr;
if (!borders->tile[i]) {
borders->tile[i] =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
g->width, g->height);
}
tex_width = cairo_image_surface_get_stride(borders->tile[i]) / 4;
cr = cairo_create(borders->tile[i]);
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]));
}
}
void
weston_gl_borders_fini(struct weston_gl_borders *borders,
struct weston_output *output,
struct gl_renderer_interface *glri)
{
for (unsigned i = 0; i < ARRAY_LENGTH(borders->tile); i++) {
glri->output_set_border(output, i, 0, 0, 0, NULL);
cairo_surface_destroy(borders->tile[i]);
borders->tile[i] = NULL;
}
}

44
libweston/gl-borders.h Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright 2022 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include "renderer-gl/gl-renderer.h"
#include "shared/cairo-util.h"
struct weston_gl_borders {
cairo_surface_t *tile[4]; /* enum gl_renderer_border_side */
};
void
weston_gl_borders_update(struct weston_gl_borders *borders,
struct frame *frame,
struct weston_output *output,
struct gl_renderer_interface *glri);
void
weston_gl_borders_fini(struct weston_gl_borders *borders,
struct weston_output *output,
struct gl_renderer_interface *glri);

View File

@ -242,6 +242,22 @@ dep_vertex_clipping = declare_dependency(
include_directories: include_directories('.')
)
lib_gl_borders = static_library(
'gl-borders',
'gl-borders.c',
include_directories: common_inc,
dependencies: [
dep_lib_cairo_shared,
dep_egl, # for gl-renderer.h
],
build_by_default: false,
install: false
)
dep_lib_gl_borders = declare_dependency(
link_with: lib_gl_borders,
dependencies: dep_lib_cairo_shared
)
subdir('color-lcms')
subdir('renderer-gl')
subdir('backend-drm')

View File

@ -23,6 +23,8 @@
* SOFTWARE.
*/
#pragma once
#include "config.h"
#include <stdint.h>