Drop wlr_client_buffer usage

This commit is contained in:
Alexander Orzechowski 2023-04-19 15:17:31 +02:00
parent 33cfdbe886
commit 4bec692734
7 changed files with 42 additions and 13 deletions

View file

@ -1,10 +1,13 @@
#ifndef _SWAY_SURFACE_H
#define _SWAY_SURFACE_H
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_raster.h>
struct sway_surface {
struct wlr_surface *wlr_surface;
struct wlr_raster *raster;
struct wl_listener commit;
struct wl_listener destroy;
/**

View file

@ -2,6 +2,7 @@
#define _SWAY_VIEW_H
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_raster.h>
#include "sway/config.h"
#if HAVE_XWAYLAND
#include <wlr/xwayland.h>
@ -57,7 +58,7 @@ struct sway_view_impl {
};
struct sway_saved_buffer {
struct wlr_client_buffer *buffer;
struct wlr_raster *raster;
int x, y;
int width, height;
enum wl_output_transform transform;

View file

@ -7,7 +7,7 @@
#include <wlr/config.h>
#include <wlr/backend/headless.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_raster.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
@ -509,7 +509,8 @@ static bool scan_out_fullscreen_view(struct sway_output *output,
return false;
}
if (surface->buffer == NULL) {
struct wlr_raster *raster = wlr_raster_from_surface(surface);
if (raster == NULL || raster->buffer == NULL) {
return false;
}
@ -522,7 +523,7 @@ static bool scan_out_fullscreen_view(struct sway_output *output,
return false;
}
wlr_output_attach_buffer(wlr_output, &surface->buffer->base);
wlr_output_attach_buffer(wlr_output, raster->buffer);
if (!wlr_output_test(wlr_output)) {
return false;
}

View file

@ -6,7 +6,7 @@
#include <wayland-server-core.h>
#include <wlr/config.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_raster.h>
#include <wlr/types/wlr_damage_ring.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
@ -142,7 +142,13 @@ static void render_surface_iterator(struct sway_output *output,
const pixman_region32_t *output_damage = data->damage;
float alpha = data->alpha;
struct wlr_texture *texture = wlr_surface_get_texture(surface);
struct wlr_raster *raster = wlr_raster_from_surface(surface);
if (!raster) {
return;
}
struct wlr_texture *texture = wlr_raster_create_texture(
raster, wlr_output->renderer);
if (!texture) {
return;
}
@ -303,7 +309,9 @@ static void render_saved_view(struct sway_view *view,
struct sway_saved_buffer *saved_buf;
wl_list_for_each(saved_buf, &view->saved_buffers, link) {
if (!saved_buf->buffer->texture) {
struct wlr_texture *texture = wlr_raster_create_texture(
saved_buf->raster, wlr_output->renderer);
if (!texture) {
continue;
}
@ -343,7 +351,7 @@ static void render_saved_view(struct sway_view *view,
}
scale_box(&dst_box, wlr_output->scale);
render_texture(wlr_output, damage, saved_buf->buffer->texture,
render_texture(wlr_output, damage, texture,
&saved_buf->source_box, &dst_box, matrix, alpha);
}

View file

@ -11,15 +11,28 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_surface *surface = wl_container_of(listener, surface, destroy);
surface->wlr_surface->data = NULL;
wl_list_remove(&surface->commit.link);
wl_list_remove(&surface->destroy.link);
if (surface->frame_done_timer) {
wl_event_source_remove(surface->frame_done_timer);
}
wlr_raster_unlock(surface->raster);
free(surface);
}
static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_surface *surface = wl_container_of(listener, surface, commit);
// update the surface raster every surface commit
struct wlr_raster *raster = wlr_raster_from_surface(surface->wlr_surface);
wlr_raster_unlock(surface->raster);
surface->raster = raster;
}
static int surface_frame_done_timer_handler(void *data) {
struct sway_surface *surface = data;
@ -40,11 +53,16 @@ void handle_compositor_new_surface(struct wl_listener *listener, void *data) {
surface->destroy.notify = handle_destroy;
wl_signal_add(&wlr_surface->events.destroy, &surface->destroy);
surface->commit.notify = handle_commit;
wl_signal_add(&wlr_surface->events.commit, &surface->commit);
surface->frame_done_timer = wl_event_loop_add_timer(server.wl_event_loop,
surface_frame_done_timer_handler, surface);
if (!surface->frame_done_timer) {
wl_resource_post_no_memory(wlr_surface->resource);
}
surface->raster = wlr_raster_from_surface(wlr_surface);
}
void surface_update_outputs(struct wlr_surface *surface) {

View file

@ -103,8 +103,7 @@ bool server_init(struct sway_server *server) {
return false;
}
server->compositor = wlr_compositor_create(server->wl_display, 5,
server->renderer);
server->compositor = wlr_compositor_create(server->wl_display, 5, NULL);
server->compositor_new_surface.notify = handle_compositor_new_surface;
wl_signal_add(&server->compositor->events.new_surface,
&server->compositor_new_surface);

View file

@ -1412,7 +1412,7 @@ void view_remove_saved_buffer(struct sway_view *view) {
}
struct sway_saved_buffer *saved_buf, *tmp;
wl_list_for_each_safe(saved_buf, tmp, &view->saved_buffers, link) {
wlr_buffer_unlock(&saved_buf->buffer->base);
wlr_raster_unlock(saved_buf->raster);
wl_list_remove(&saved_buf->link);
free(saved_buf);
}
@ -1423,9 +1423,8 @@ static void view_save_buffer_iterator(struct wlr_surface *surface,
struct sway_view *view = data;
if (surface && wlr_surface_has_buffer(surface)) {
wlr_buffer_lock(&surface->buffer->base);
struct sway_saved_buffer *saved_buffer = calloc(1, sizeof(struct sway_saved_buffer));
saved_buffer->buffer = surface->buffer;
saved_buffer->raster = wlr_raster_from_surface(surface);
saved_buffer->width = surface->current.width;
saved_buffer->height = surface->current.height;
saved_buffer->x = view->container->surface_x + sx;