Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wlr_render_pass #7552

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "sway/input/text_input.h"

struct sway_seat;
struct render_context;

struct sway_seatop_impl {
void (*button)(struct sway_seat *seat, uint32_t time_msec,
Expand Down Expand Up @@ -49,8 +50,7 @@ struct sway_seatop_impl {
uint32_t time_msec, enum wlr_tablet_tool_tip_state state);
void (*end)(struct sway_seat *seat);
void (*unref)(struct sway_seat *seat, struct sway_container *con);
void (*render)(struct sway_seat *seat, struct sway_output *output,
const pixman_region32_t *damage);
void (*render)(struct sway_seat *seat, struct render_context *ctx);
bool allow_set_cursor;
};

Expand Down Expand Up @@ -356,8 +356,7 @@ void seatop_unref(struct sway_seat *seat, struct sway_container *con);
* Instructs a seatop to render anything that it needs to render
* (eg. dropzone for move-tiling)
*/
void seatop_render(struct sway_seat *seat, struct sway_output *output,
const pixman_region32_t *damage);
void seatop_render(struct sway_seat *seat, struct render_context *ctx);

bool seatop_allows_set_cursor(struct sway_seat *seat);

Expand Down
13 changes: 10 additions & 3 deletions include/sway/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ struct sway_output_non_desktop {
struct wl_listener destroy;
};

struct render_context {
struct sway_output *output;
struct wlr_renderer *renderer;
const pixman_region32_t *output_damage;

struct wlr_render_pass *pass;
};

struct sway_output *output_create(struct wlr_output *wlr_output);

void output_destroy(struct sway_output *output);
Expand Down Expand Up @@ -115,7 +123,7 @@ bool output_has_opaque_overlay_layer_surface(struct sway_output *output);

struct sway_workspace *output_get_active_workspace(struct sway_output *output);

void output_render(struct sway_output *output, pixman_region32_t *damage);
void output_render(struct render_context *ctx);

void output_surface_for_each_surface(struct sway_output *output,
struct wlr_surface *surface, double ox, double oy,
Expand Down Expand Up @@ -168,8 +176,7 @@ void output_get_box(struct sway_output *output, struct wlr_box *box);
enum sway_container_layout output_get_default_layout(
struct sway_output *output);

void render_rect(struct sway_output *output,
const pixman_region32_t *output_damage, const struct wlr_box *_box,
void render_rect(struct render_context *ctx, const struct wlr_box *_box,
float color[static 4]);

void premultiply_alpha(float color[4], float opacity);
Expand Down
40 changes: 37 additions & 3 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <wayland-server-core.h>
#include <wlr/config.h>
#include <wlr/backend/headless.h>
#include <wlr/render/swapchain.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_matrix.h>
Expand Down Expand Up @@ -604,22 +605,55 @@ static int output_repaint_timer_handler(void *data) {
}
}

if (!wlr_output_configure_primary_swapchain(wlr_output, NULL, &wlr_output->swapchain)) {
return false;
}

int buffer_age;
if (!wlr_output_attach_render(output->wlr_output, &buffer_age)) {
return 0;
struct wlr_buffer *buffer = wlr_swapchain_acquire(wlr_output->swapchain, &buffer_age);
if (buffer == NULL) {
return false;
}

struct wlr_render_pass *render_pass = wlr_renderer_begin_buffer_pass(
wlr_output->renderer, buffer);
if (render_pass == NULL) {
wlr_buffer_unlock(buffer);
return false;
}

pixman_region32_t damage;
pixman_region32_init(&damage);
wlr_damage_ring_get_buffer_damage(&output->damage_ring, buffer_age, &damage);

if (debug.damage == DAMAGE_RERENDER) {
int width, height;
wlr_output_transformed_resolution(wlr_output, &width, &height);
pixman_region32_union_rect(&damage, &damage, 0, 0, width, height);
}

struct render_context ctx = {
.output_damage = &damage,
.renderer = wlr_output->renderer,
.output = output,
.pass = render_pass,
};

struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);

output_render(output, &damage);
output_render(&ctx);

pixman_region32_fini(&damage);

if (!wlr_render_pass_submit(render_pass)) {
wlr_buffer_unlock(buffer);
return false;
}

wlr_output_attach_buffer(wlr_output, buffer);
wlr_buffer_unlock(buffer);

if (!wlr_output_commit(wlr_output)) {
return 0;
}
Expand Down
Loading