mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
output: add initial renderer
This will only render the clearing for now as there is no damage tracking yet.
This commit is contained in:
parent
ab1eac11df
commit
9b1641aa14
7 changed files with 212 additions and 1 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#include <wlr/util/region.h>
|
||||
|
||||
#include "output.h"
|
||||
#include "renderer.h"
|
||||
#include "view.h"
|
||||
|
||||
struct send_frame_done_data {
|
||||
|
|
@ -74,7 +75,7 @@ handle_output_damage_frame(struct wl_listener *listener, void *user_data)
|
|||
goto damage_finish;
|
||||
}
|
||||
|
||||
// cage_renderer_render_output(output->wlr_output, &damage);
|
||||
cage_renderer_render_output(output, &damage);
|
||||
|
||||
damage_finish:
|
||||
pixman_region32_fini(&damage);
|
||||
|
|
|
|||
191
desktop/renderer.c
Normal file
191
desktop/renderer.c
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
/*
|
||||
* Cage: A Wayland kiosk.
|
||||
*
|
||||
* Copyright (C) 2018-2020 Jente Hidskes
|
||||
* Copyright (C) 2019 The Sway authors
|
||||
*
|
||||
* See the LICENSE file accompanying this file.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/util/region.h>
|
||||
|
||||
#include "output.h"
|
||||
#include "renderer.h"
|
||||
#include "util.h"
|
||||
#include "view.h"
|
||||
|
||||
struct render_data {
|
||||
struct wlr_output *wlr_output;
|
||||
pixman_region32_t *damage;
|
||||
};
|
||||
|
||||
static void
|
||||
renderer_scissor(struct wlr_output *wlr_output, pixman_box32_t *rect)
|
||||
{
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
struct wlr_box box = {
|
||||
.x = rect->x1,
|
||||
.y = rect->y1,
|
||||
.width = rect->x2 - rect->x1,
|
||||
.height = rect->y2 - rect->y1,
|
||||
};
|
||||
|
||||
int output_width, output_height;
|
||||
wlr_output_transformed_resolution(wlr_output, &output_width, &output_height);
|
||||
enum wl_output_transform transform = wlr_output_transform_invert(wlr_output->transform);
|
||||
wlr_box_transform(&box, &box, transform, output_width, output_height);
|
||||
|
||||
wlr_renderer_scissor(renderer, &box);
|
||||
}
|
||||
|
||||
static void
|
||||
render_texture(struct wlr_output *wlr_output, pixman_region32_t *output_damage, struct wlr_texture *texture,
|
||||
const struct wlr_box *box, const float matrix[static 9])
|
||||
{
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
pixman_region32_t damage;
|
||||
pixman_region32_init(&damage);
|
||||
pixman_region32_union_rect(&damage, &damage, box->x, box->y, box->width, box->height);
|
||||
pixman_region32_intersect(&damage, &damage, output_damage);
|
||||
if (!pixman_region32_not_empty(&damage)) {
|
||||
goto damage_finish;
|
||||
}
|
||||
|
||||
int nrects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
|
||||
for (int i = 0; i < nrects; i++) {
|
||||
renderer_scissor(wlr_output, &rects[i]);
|
||||
wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0f);
|
||||
}
|
||||
|
||||
damage_finish:
|
||||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
static void
|
||||
render_surface_iterator(struct wlr_surface *surface, int sx, int sy, void *user_data)
|
||||
{
|
||||
struct render_data *data = user_data;
|
||||
|
||||
assert(data->wlr_output);
|
||||
assert(data->damage);
|
||||
|
||||
struct wlr_output *wlr_output = data->wlr_output;
|
||||
pixman_region32_t *output_damage = data->damage;
|
||||
|
||||
struct wlr_box geometry = {0};
|
||||
wlr_output_transformed_resolution(wlr_output, &geometry.width, &geometry.height);
|
||||
|
||||
struct wlr_texture *texture = wlr_surface_get_texture(surface);
|
||||
if (!texture) {
|
||||
wlr_log(WLR_DEBUG, "Cannot obtain surface texture");
|
||||
return;
|
||||
}
|
||||
|
||||
scale_box(&geometry, wlr_output->scale);
|
||||
|
||||
float matrix[9];
|
||||
enum wl_output_transform transform = wlr_output_transform_invert(surface->current.transform);
|
||||
wlr_matrix_project_box(matrix, &geometry, transform, 0.0f, wlr_output->transform_matrix);
|
||||
|
||||
render_texture(wlr_output, output_damage, texture, &geometry, matrix);
|
||||
}
|
||||
|
||||
static void
|
||||
clear_output(struct wlr_output *wlr_output, pixman_region32_t *damage)
|
||||
{
|
||||
static float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
#ifdef DEBUG_DAMAGE_TRACKING
|
||||
wlr_renderer_clear(renderer, (float[]){1.0f, 0.0f, 0.0f, 1.0f});
|
||||
#endif
|
||||
|
||||
int nrects;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects);
|
||||
for (int i = 0; i < nrects; i++) {
|
||||
renderer_scissor(wlr_output, &rects[i]);
|
||||
wlr_renderer_clear(renderer, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
render_view(struct cg_view *view, struct wlr_output *wlr_output, pixman_region32_t *damage)
|
||||
{
|
||||
struct render_data data = {
|
||||
.wlr_output = wlr_output,
|
||||
.damage = damage,
|
||||
};
|
||||
cage_view_for_each_surface(view, render_surface_iterator, &data);
|
||||
}
|
||||
|
||||
static void
|
||||
renderer_end(struct cg_output *output, pixman_region32_t *damage)
|
||||
{
|
||||
struct wlr_output *wlr_output = output->wlr_output;
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
/* Draw software cursor in case hardware cursors aren't
|
||||
available. This is a no-op when they are. */
|
||||
wlr_output_render_software_cursors(wlr_output, damage);
|
||||
wlr_renderer_scissor(renderer, NULL);
|
||||
wlr_renderer_end(renderer);
|
||||
|
||||
int output_width, output_height;
|
||||
wlr_output_transformed_resolution(wlr_output, &output_width, &output_height);
|
||||
|
||||
pixman_region32_t frame_damage;
|
||||
pixman_region32_init(&frame_damage);
|
||||
|
||||
enum wl_output_transform transform = wlr_output_transform_invert(wlr_output->transform);
|
||||
wlr_region_transform(&frame_damage, &output->damage->current, transform, output_width, output_height);
|
||||
|
||||
#ifdef DEBUG_DAMAGE_TRACKING
|
||||
pixman_region32_union_rect(&frame_damage, &frame_damage, 0, 0, output_width, output_height);
|
||||
#endif
|
||||
|
||||
wlr_output_set_damage(wlr_output, &frame_damage);
|
||||
pixman_region32_fini(&frame_damage);
|
||||
|
||||
if (!wlr_output_commit(wlr_output)) {
|
||||
wlr_log(WLR_ERROR, "Could not commit output");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cage_renderer_render_output(struct cg_output *output, pixman_region32_t *damage)
|
||||
{
|
||||
assert(output != NULL);
|
||||
assert(damage != NULL);
|
||||
struct wlr_output *wlr_output = output->wlr_output;
|
||||
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend);
|
||||
|
||||
wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height);
|
||||
|
||||
if (!pixman_region32_not_empty(damage)) {
|
||||
wlr_log(WLR_DEBUG, "Output isn't damaged but needs a buffer swap");
|
||||
goto renderer_end;
|
||||
}
|
||||
|
||||
clear_output(wlr_output, damage);
|
||||
|
||||
// TODO: render only top view, possibly use focused view for this, see #35.
|
||||
struct cg_view *view;
|
||||
wl_list_for_each_reverse (view, &output->views, link) {
|
||||
render_view(view, wlr_output, damage);
|
||||
}
|
||||
|
||||
renderer_end:
|
||||
renderer_end(output, damage);
|
||||
}
|
||||
8
desktop/renderer.h
Normal file
8
desktop/renderer.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef CG_RENDERER_H
|
||||
#define CG_RENDERER_H
|
||||
|
||||
#include "output.h"
|
||||
|
||||
void cage_renderer_render_output(struct cg_output *output, pixman_region32_t *damage);
|
||||
|
||||
#endif
|
||||
10
meson.build
10
meson.build
|
|
@ -21,6 +21,10 @@ if get_option('buildtype').startswith('debug')
|
|||
add_project_arguments('-DDEBUG', language : 'c')
|
||||
endif
|
||||
|
||||
if get_option('debug-damage-tracking')
|
||||
add_project_arguments('-DDEBUG_DAMAGE_TRACKING', language : 'c')
|
||||
endif
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
is_freebsd = host_machine.system().startswith('freebsd')
|
||||
|
|
@ -121,6 +125,8 @@ endif
|
|||
|
||||
cageng_sources = [
|
||||
'desktop/output.c',
|
||||
'desktop/renderer.c',
|
||||
'desktop/util.c',
|
||||
'desktop/view.c',
|
||||
'desktop/xdg_shell.c',
|
||||
'cageng.c',
|
||||
|
|
@ -131,6 +137,8 @@ cageng_headers = [
|
|||
output: 'config.h',
|
||||
configuration: conf_data),
|
||||
'desktop/output.h',
|
||||
'desktop/renderer.h',
|
||||
'desktop/util.h',
|
||||
'desktop/view.h',
|
||||
'desktop/xdg_shell.h',
|
||||
'serverng.h',
|
||||
|
|
@ -159,6 +167,8 @@ summary = [
|
|||
'',
|
||||
'Cage @0@'.format(version),
|
||||
'',
|
||||
' debug: @0@'.format(get_option('buildtype').startswith('debug')),
|
||||
' debug damage tracking: @0@'.format(get_option('debug-damage-tracking')),
|
||||
' xwayland: @0@'.format(have_xwayland),
|
||||
''
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
option('debug-damage-tracking', type: 'boolean', value: 'false', description: 'Debug damage tracking')
|
||||
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
||||
option('xwayland', type: 'boolean', value: 'false', description: 'Enable support for X11 applications')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue