mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-22 06:47:12 -04:00
Merge branch 'single-pixel-optimize' into 'master'
Draft: wlr_renderer: Add single pixel optimization See merge request wlroots/wlroots!3650
This commit is contained in:
commit
e3cc1dda94
39 changed files with 1149 additions and 972 deletions
|
|
@ -58,6 +58,7 @@ wlr_files += files(
|
|||
'wlr_presentation_time.c',
|
||||
'wlr_primary_selection_v1.c',
|
||||
'wlr_primary_selection.c',
|
||||
'wlr_raster.c',
|
||||
'wlr_region.c',
|
||||
'wlr_relative_pointer_v1.c',
|
||||
'wlr_screencopy_v1.c',
|
||||
|
|
|
|||
|
|
@ -93,11 +93,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
|||
struct wlr_renderer *renderer = cursor->output->renderer;
|
||||
assert(renderer);
|
||||
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
texture = wlr_surface_get_texture(cursor->surface);
|
||||
}
|
||||
if (texture == NULL) {
|
||||
if (!cursor->raster) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +117,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
|||
pixman_box32_t *rects = pixman_region32_rectangles(&surface_damage, &nrects);
|
||||
for (int i = 0; i < nrects; ++i) {
|
||||
output_scissor(cursor->output, &rects[i]);
|
||||
wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0f);
|
||||
wlr_render_raster_with_matrix(renderer, cursor->raster, matrix, 1.0f);
|
||||
}
|
||||
wlr_renderer_scissor(renderer, NULL);
|
||||
|
||||
|
|
@ -234,29 +230,28 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
|
||||
float scale = output->scale;
|
||||
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
texture = wlr_surface_get_texture(cursor->surface);
|
||||
scale = cursor->surface->current.scale;
|
||||
transform = cursor->surface->current.transform;
|
||||
}
|
||||
if (texture == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_allocator *allocator = output->allocator;
|
||||
struct wlr_renderer *renderer = output->renderer;
|
||||
assert(allocator != NULL && renderer != NULL);
|
||||
|
||||
int width = texture->width;
|
||||
int height = texture->height;
|
||||
if (!cursor->raster) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int width = cursor->raster->width;
|
||||
int height = cursor->raster->height;
|
||||
if (output->impl->get_cursor_size) {
|
||||
// Apply hardware limitations on buffer size
|
||||
output->impl->get_cursor_size(cursor->output, &width, &height);
|
||||
if ((int)texture->width > width || (int)texture->height > height) {
|
||||
wlr_log(WLR_DEBUG, "Cursor texture too large (%dx%d), "
|
||||
"exceeds hardware limitations (%dx%d)", texture->width,
|
||||
texture->height, width, height);
|
||||
if ((int)cursor->raster->width > width || (int)cursor->raster->height > height) {
|
||||
wlr_log(WLR_DEBUG, "Cursor raster too large (%dx%d), "
|
||||
"exceeds hardware limitations (%dx%d)", cursor->raster->width,
|
||||
cursor->raster->height, width, height);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -288,8 +283,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
}
|
||||
|
||||
struct wlr_box cursor_box = {
|
||||
.width = texture->width * output->scale / scale,
|
||||
.height = texture->height * output->scale / scale,
|
||||
.width = cursor->raster->width * output->scale / scale,
|
||||
.height = cursor->raster->height * output->scale / scale,
|
||||
};
|
||||
|
||||
float output_matrix[9];
|
||||
|
|
@ -317,7 +312,7 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor)
|
|||
}
|
||||
|
||||
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
|
||||
wlr_render_texture_with_matrix(renderer, texture, matrix, 1.0);
|
||||
wlr_render_raster_with_matrix(renderer, cursor->raster, matrix, 1.0);
|
||||
|
||||
wlr_renderer_end(renderer);
|
||||
|
||||
|
|
@ -337,24 +332,16 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
|
|||
return false;
|
||||
}
|
||||
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
// TODO: try using the surface buffer directly
|
||||
texture = wlr_surface_get_texture(cursor->surface);
|
||||
}
|
||||
|
||||
// If the cursor was hidden or was a software cursor, the hardware
|
||||
// cursor position is outdated
|
||||
output->impl->move_cursor(cursor->output,
|
||||
(int)cursor->x, (int)cursor->y);
|
||||
|
||||
struct wlr_buffer *buffer = NULL;
|
||||
if (texture != NULL) {
|
||||
buffer = render_cursor_buffer(cursor);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to render cursor buffer");
|
||||
return false;
|
||||
}
|
||||
buffer = render_cursor_buffer(cursor);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to render cursor buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_box hotspot = {
|
||||
|
|
@ -376,24 +363,20 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
|
|||
bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
|
||||
const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height,
|
||||
int32_t hotspot_x, int32_t hotspot_y) {
|
||||
struct wlr_buffer *buffer = NULL;
|
||||
struct wlr_raster *raster = NULL;
|
||||
|
||||
if (pixels) {
|
||||
struct wlr_readonly_data_buffer *ro_buffer = readonly_data_buffer_create(
|
||||
DRM_FORMAT_ARGB8888, stride, width, height, pixels);
|
||||
if (ro_buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
buffer = &ro_buffer->base;
|
||||
raster = wlr_raster_from_pixels(DRM_FORMAT_ARGB8888,
|
||||
stride, width, height, pixels);
|
||||
}
|
||||
bool ok = wlr_output_cursor_set_buffer(cursor, buffer, hotspot_x, hotspot_y);
|
||||
bool ok = wlr_output_cursor_set_raster(cursor, raster, hotspot_x, hotspot_y);
|
||||
|
||||
wlr_buffer_drop(buffer);
|
||||
wlr_raster_unlock(raster);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
|
||||
struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
bool wlr_output_cursor_set_raster(struct wlr_output_cursor *cursor,
|
||||
struct wlr_raster *raster, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
struct wlr_renderer *renderer = cursor->output->renderer;
|
||||
if (!renderer) {
|
||||
return false;
|
||||
|
|
@ -401,9 +384,9 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
|
|||
|
||||
output_cursor_reset(cursor);
|
||||
|
||||
if (buffer != NULL) {
|
||||
cursor->width = buffer->width;
|
||||
cursor->height = buffer->height;
|
||||
if (raster) {
|
||||
cursor->width = raster->width;
|
||||
cursor->height = raster->height;
|
||||
} else {
|
||||
cursor->width = 0;
|
||||
cursor->height = 0;
|
||||
|
|
@ -414,16 +397,12 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
|
|||
|
||||
output_cursor_update_visible(cursor);
|
||||
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
cursor->texture = NULL;
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
cursor->raster = NULL;
|
||||
|
||||
cursor->enabled = false;
|
||||
if (buffer != NULL) {
|
||||
cursor->texture = wlr_texture_from_buffer(renderer, buffer);
|
||||
if (cursor->texture == NULL) {
|
||||
return false;
|
||||
}
|
||||
cursor->enabled = true;
|
||||
cursor->enabled = raster;
|
||||
if (raster) {
|
||||
cursor->raster = wlr_raster_lock(raster);
|
||||
}
|
||||
|
||||
if (output_cursor_attempt_hardware(cursor)) {
|
||||
|
|
@ -442,9 +421,16 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor,
|
|||
output_cursor_damage_whole(cursor);
|
||||
}
|
||||
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
cursor->raster = NULL;
|
||||
|
||||
struct wlr_surface *surface = cursor->surface;
|
||||
assert(surface != NULL);
|
||||
|
||||
if (surface->raster) {
|
||||
cursor->raster = wlr_raster_lock(surface->raster);
|
||||
}
|
||||
|
||||
// Some clients commit a cursor surface with a NULL buffer to hide it.
|
||||
cursor->enabled = wlr_surface_has_buffer(surface);
|
||||
cursor->width = surface->current.width * cursor->output->scale;
|
||||
|
|
@ -589,7 +575,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
|
|||
output_set_hardware_cursor(cursor->output, NULL, 0, 0);
|
||||
cursor->output->hardware_cursor = NULL;
|
||||
}
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
wlr_raster_unlock(cursor->raster);
|
||||
wl_list_remove(&cursor->link);
|
||||
free(cursor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,9 +81,9 @@ static void subsurface_tree_reconfigure(
|
|||
}
|
||||
|
||||
if (prev != NULL) {
|
||||
wlr_scene_node_place_above(&subsurface_tree->scene_surface->buffer->node, prev);
|
||||
wlr_scene_node_place_above(&subsurface_tree->scene_surface->raster->node, prev);
|
||||
}
|
||||
prev = &subsurface_tree->scene_surface->buffer->node;
|
||||
prev = &subsurface_tree->scene_surface->raster->node;
|
||||
|
||||
wl_list_for_each(subsurface, &surface->current.subsurfaces_above,
|
||||
current.link) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <wlr/types/wlr_presentation_time.h>
|
||||
#include "types/wlr_scene.h"
|
||||
|
||||
static void handle_scene_buffer_output_enter(
|
||||
static void handle_scene_raster_output_enter(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, output_enter);
|
||||
|
|
@ -12,7 +12,7 @@ static void handle_scene_buffer_output_enter(
|
|||
wlr_surface_send_enter(surface->surface, output->output);
|
||||
}
|
||||
|
||||
static void handle_scene_buffer_output_leave(
|
||||
static void handle_scene_raster_output_leave(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, output_leave);
|
||||
|
|
@ -21,14 +21,14 @@ static void handle_scene_buffer_output_leave(
|
|||
wlr_surface_send_leave(surface->surface, output->output);
|
||||
}
|
||||
|
||||
static void handle_scene_buffer_output_present(
|
||||
static void handle_scene_raster_output_present(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, output_present);
|
||||
struct wlr_scene_output *scene_output = data;
|
||||
|
||||
if (surface->buffer->primary_output == scene_output) {
|
||||
struct wlr_scene *root = scene_node_get_root(&surface->buffer->node);
|
||||
if (surface->raster->primary_output == scene_output) {
|
||||
struct wlr_scene *root = scene_node_get_root(&surface->raster->node);
|
||||
struct wlr_presentation *presentation = root->presentation;
|
||||
|
||||
if (presentation) {
|
||||
|
|
@ -38,7 +38,7 @@ static void handle_scene_buffer_output_present(
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_scene_buffer_frame_done(
|
||||
static void handle_scene_raster_frame_done(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, frame_done);
|
||||
|
|
@ -52,25 +52,27 @@ static void scene_surface_handle_surface_destroy(
|
|||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, surface_destroy);
|
||||
|
||||
wlr_scene_node_destroy(&surface->buffer->node);
|
||||
wlr_scene_node_destroy(&surface->raster->node);
|
||||
}
|
||||
|
||||
static void set_buffer_with_surface_state(struct wlr_scene_buffer *scene_buffer,
|
||||
static void set_raster_with_surface_state(struct wlr_scene_raster *scene_raster,
|
||||
struct wlr_surface *surface) {
|
||||
struct wlr_surface_state *state = &surface->current;
|
||||
|
||||
struct wlr_fbox src_box;
|
||||
wlr_surface_get_buffer_source_box(surface, &src_box);
|
||||
wlr_scene_buffer_set_source_box(scene_buffer, &src_box);
|
||||
wlr_scene_raster_set_source_box(scene_raster, &src_box);
|
||||
|
||||
wlr_scene_buffer_set_dest_size(scene_buffer, state->width, state->height);
|
||||
wlr_scene_buffer_set_transform(scene_buffer, state->transform);
|
||||
wlr_scene_raster_set_dest_size(scene_raster, state->width, state->height);
|
||||
wlr_scene_raster_set_transform(scene_raster, state->transform);
|
||||
|
||||
if (surface->buffer) {
|
||||
wlr_scene_buffer_set_buffer_with_damage(scene_buffer,
|
||||
&surface->buffer->base, &surface->buffer_damage);
|
||||
struct wlr_raster *raster = surface->raster;
|
||||
|
||||
if (raster) {
|
||||
wlr_scene_raster_set_raster_with_damage(scene_raster,
|
||||
raster, &surface->buffer_damage);
|
||||
} else {
|
||||
wlr_scene_buffer_set_buffer(scene_buffer, NULL);
|
||||
wlr_scene_raster_set_raster(scene_raster, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -78,27 +80,27 @@ static void handle_scene_surface_surface_commit(
|
|||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_surface *surface =
|
||||
wl_container_of(listener, surface, surface_commit);
|
||||
struct wlr_scene_buffer *scene_buffer = surface->buffer;
|
||||
struct wlr_scene_raster *scene_raster = surface->raster;
|
||||
|
||||
set_buffer_with_surface_state(scene_buffer, surface->surface);
|
||||
set_raster_with_surface_state(scene_raster, surface->surface);
|
||||
|
||||
// Even if the surface hasn't submitted damage, schedule a new frame if
|
||||
// the client has requested a wl_surface.frame callback. Check if the node
|
||||
// is visible. If not, the client will never receive a frame_done event
|
||||
// anyway so it doesn't make sense to schedule here.
|
||||
int lx, ly;
|
||||
bool enabled = wlr_scene_node_coords(&scene_buffer->node, &lx, &ly);
|
||||
bool enabled = wlr_scene_node_coords(&scene_raster->node, &lx, &ly);
|
||||
|
||||
if (!wl_list_empty(&surface->surface->current.frame_callback_list) &&
|
||||
surface->buffer->primary_output != NULL && enabled) {
|
||||
wlr_output_schedule_frame(surface->buffer->primary_output->output);
|
||||
surface->raster->primary_output != NULL && enabled) {
|
||||
wlr_output_schedule_frame(surface->raster->primary_output->output);
|
||||
}
|
||||
}
|
||||
|
||||
static bool scene_buffer_point_accepts_input(struct wlr_scene_buffer *scene_buffer,
|
||||
static bool scene_raster_point_accepts_input(struct wlr_scene_raster *scene_raster,
|
||||
int sx, int sy) {
|
||||
struct wlr_scene_surface *scene_surface =
|
||||
wlr_scene_surface_from_buffer(scene_buffer);
|
||||
wlr_scene_surface_from_raster(scene_raster);
|
||||
|
||||
return wlr_surface_point_accepts_input(scene_surface->surface, sx, sy);
|
||||
}
|
||||
|
|
@ -123,10 +125,10 @@ static const struct wlr_addon_interface surface_addon_impl = {
|
|||
.destroy = surface_addon_destroy,
|
||||
};
|
||||
|
||||
struct wlr_scene_surface *wlr_scene_surface_from_buffer(
|
||||
struct wlr_scene_buffer *scene_buffer) {
|
||||
struct wlr_addon *addon = wlr_addon_find(&scene_buffer->node.addons,
|
||||
scene_buffer, &surface_addon_impl);
|
||||
struct wlr_scene_surface *wlr_scene_surface_from_raster(
|
||||
struct wlr_scene_raster *scene_raster) {
|
||||
struct wlr_addon *addon = wlr_addon_find(&scene_raster->node.addons,
|
||||
scene_raster, &surface_addon_impl);
|
||||
if (!addon) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -142,27 +144,27 @@ struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_tree *parent
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_create(parent, NULL);
|
||||
if (!scene_buffer) {
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_create(parent, NULL);
|
||||
if (!scene_raster) {
|
||||
free(surface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
surface->buffer = scene_buffer;
|
||||
surface->raster = scene_raster;
|
||||
surface->surface = wlr_surface;
|
||||
scene_buffer->point_accepts_input = scene_buffer_point_accepts_input;
|
||||
scene_raster->point_accepts_input = scene_raster_point_accepts_input;
|
||||
|
||||
surface->output_enter.notify = handle_scene_buffer_output_enter;
|
||||
wl_signal_add(&scene_buffer->events.output_enter, &surface->output_enter);
|
||||
surface->output_enter.notify = handle_scene_raster_output_enter;
|
||||
wl_signal_add(&scene_raster->events.output_enter, &surface->output_enter);
|
||||
|
||||
surface->output_leave.notify = handle_scene_buffer_output_leave;
|
||||
wl_signal_add(&scene_buffer->events.output_leave, &surface->output_leave);
|
||||
surface->output_leave.notify = handle_scene_raster_output_leave;
|
||||
wl_signal_add(&scene_raster->events.output_leave, &surface->output_leave);
|
||||
|
||||
surface->output_present.notify = handle_scene_buffer_output_present;
|
||||
wl_signal_add(&scene_buffer->events.output_present, &surface->output_present);
|
||||
surface->output_present.notify = handle_scene_raster_output_present;
|
||||
wl_signal_add(&scene_raster->events.output_present, &surface->output_present);
|
||||
|
||||
surface->frame_done.notify = handle_scene_buffer_frame_done;
|
||||
wl_signal_add(&scene_buffer->events.frame_done, &surface->frame_done);
|
||||
surface->frame_done.notify = handle_scene_raster_frame_done;
|
||||
wl_signal_add(&scene_raster->events.frame_done, &surface->frame_done);
|
||||
|
||||
surface->surface_destroy.notify = scene_surface_handle_surface_destroy;
|
||||
wl_signal_add(&wlr_surface->events.destroy, &surface->surface_destroy);
|
||||
|
|
@ -170,10 +172,10 @@ struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_tree *parent
|
|||
surface->surface_commit.notify = handle_scene_surface_surface_commit;
|
||||
wl_signal_add(&wlr_surface->events.commit, &surface->surface_commit);
|
||||
|
||||
wlr_addon_init(&surface->addon, &scene_buffer->node.addons,
|
||||
scene_buffer, &surface_addon_impl);
|
||||
wlr_addon_init(&surface->addon, &scene_raster->node.addons,
|
||||
scene_raster, &surface_addon_impl);
|
||||
|
||||
set_buffer_with_surface_state(scene_buffer, wlr_surface);
|
||||
set_raster_with_surface_state(scene_raster, wlr_surface);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ static struct wlr_scene_rect *scene_rect_from_node(
|
|||
return (struct wlr_scene_rect *)node;
|
||||
}
|
||||
|
||||
struct wlr_scene_buffer *wlr_scene_buffer_from_node(
|
||||
struct wlr_scene_raster *wlr_scene_raster_from_node(
|
||||
struct wlr_scene_node *node) {
|
||||
assert(node->type == WLR_SCENE_NODE_BUFFER);
|
||||
return (struct wlr_scene_buffer *)node;
|
||||
assert(node->type == WLR_SCENE_NODE_RASTER);
|
||||
return (struct wlr_scene_raster *)node;
|
||||
}
|
||||
|
||||
struct wlr_scene *scene_node_get_root(struct wlr_scene_node *node) {
|
||||
|
|
@ -87,22 +87,21 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) {
|
|||
wlr_signal_emit_safe(&node->events.destroy, NULL);
|
||||
|
||||
struct wlr_scene *scene = scene_node_get_root(node);
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
|
||||
uint64_t active = scene_buffer->active_outputs;
|
||||
uint64_t active = scene_raster->active_outputs;
|
||||
if (active) {
|
||||
struct wlr_scene_output *scene_output;
|
||||
wl_list_for_each(scene_output, &scene->outputs, link) {
|
||||
if (active & (1ull << scene_output->index)) {
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_leave,
|
||||
wlr_signal_emit_safe(&scene_raster->events.output_leave,
|
||||
scene_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
wlr_buffer_unlock(scene_buffer->buffer);
|
||||
wlr_raster_unlock(scene_raster->raster);
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
|
||||
|
||||
|
|
@ -196,16 +195,16 @@ struct wlr_scene_tree *wlr_scene_tree_create(struct wlr_scene_tree *parent) {
|
|||
static void scene_node_get_size(struct wlr_scene_node *node, int *lx, int *ly);
|
||||
|
||||
// This function must be called whenever the coordinates/dimensions of a scene
|
||||
// buffer or scene output change. It is not necessary to call when a scene
|
||||
// buffer's node is enabled/disabled or obscured by other nodes.
|
||||
static void scene_buffer_update_outputs(struct wlr_scene_buffer *scene_buffer,
|
||||
// raster or scene output change. It is not necessary to call when a scene
|
||||
// raster's node is enabled/disabled or obscured by other nodes.
|
||||
static void scene_raster_update_outputs(struct wlr_scene_raster *scene_raster,
|
||||
int lx, int ly, struct wlr_scene *scene,
|
||||
struct wlr_scene_output *ignore) {
|
||||
struct wlr_box buffer_box = { .x = lx, .y = ly };
|
||||
scene_node_get_size(&scene_buffer->node, &buffer_box.width, &buffer_box.height);
|
||||
struct wlr_box raster_box = { .x = lx, .y = ly };
|
||||
scene_node_get_size(&scene_raster->node, &raster_box.width, &raster_box.height);
|
||||
|
||||
int largest_overlap = 0;
|
||||
scene_buffer->primary_output = NULL;
|
||||
scene_raster->primary_output = NULL;
|
||||
|
||||
uint64_t active_outputs = 0;
|
||||
|
||||
|
|
@ -229,21 +228,21 @@ static void scene_buffer_update_outputs(struct wlr_scene_buffer *scene_buffer,
|
|||
&output_box.width, &output_box.height);
|
||||
|
||||
struct wlr_box intersection;
|
||||
bool intersects = wlr_box_intersection(&intersection, &buffer_box, &output_box);
|
||||
bool intersects = wlr_box_intersection(&intersection, &raster_box, &output_box);
|
||||
|
||||
if (intersects) {
|
||||
int overlap = intersection.width * intersection.height;
|
||||
if (overlap > largest_overlap) {
|
||||
largest_overlap = overlap;
|
||||
scene_buffer->primary_output = scene_output;
|
||||
scene_raster->primary_output = scene_output;
|
||||
}
|
||||
|
||||
active_outputs |= 1ull << scene_output->index;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t old_active = scene_buffer->active_outputs;
|
||||
scene_buffer->active_outputs = active_outputs;
|
||||
uint64_t old_active = scene_raster->active_outputs;
|
||||
scene_raster->active_outputs = active_outputs;
|
||||
|
||||
wl_list_for_each(scene_output, &scene->outputs, link) {
|
||||
uint64_t mask = 1ull << scene_output->index;
|
||||
|
|
@ -251,9 +250,9 @@ static void scene_buffer_update_outputs(struct wlr_scene_buffer *scene_buffer,
|
|||
bool intersects_before = old_active & mask;
|
||||
|
||||
if (intersects && !intersects_before) {
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_enter, scene_output);
|
||||
wlr_signal_emit_safe(&scene_raster->events.output_enter, scene_output);
|
||||
} else if (!intersects && intersects_before) {
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_leave, scene_output);
|
||||
wlr_signal_emit_safe(&scene_raster->events.output_leave, scene_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,10 +260,10 @@ static void scene_buffer_update_outputs(struct wlr_scene_buffer *scene_buffer,
|
|||
static void _scene_node_update_outputs(struct wlr_scene_node *node,
|
||||
int lx, int ly, struct wlr_scene *scene,
|
||||
struct wlr_scene_output *ignore) {
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
struct wlr_scene_buffer *scene_buffer =
|
||||
wlr_scene_buffer_from_node(node);
|
||||
scene_buffer_update_outputs(scene_buffer, lx, ly, scene, ignore);
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_scene_raster *scene_raster =
|
||||
wlr_scene_raster_from_node(node);
|
||||
scene_raster_update_outputs(scene_raster, lx, ly, scene, ignore);
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
|
||||
struct wlr_scene_node *child;
|
||||
|
|
@ -322,57 +321,54 @@ void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[sta
|
|||
scene_node_damage_whole(&rect->node);
|
||||
}
|
||||
|
||||
struct wlr_scene_buffer *wlr_scene_buffer_create(struct wlr_scene_tree *parent,
|
||||
struct wlr_buffer *buffer) {
|
||||
struct wlr_scene_buffer *scene_buffer = calloc(1, sizeof(*scene_buffer));
|
||||
if (scene_buffer == NULL) {
|
||||
struct wlr_scene_raster *wlr_scene_raster_create(struct wlr_scene_tree *parent,
|
||||
struct wlr_raster *raster) {
|
||||
struct wlr_scene_raster *scene_raster = calloc(1, sizeof(*scene_raster));
|
||||
if (scene_raster == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
assert(parent);
|
||||
scene_node_init(&scene_buffer->node, WLR_SCENE_NODE_BUFFER, parent);
|
||||
scene_node_init(&scene_raster->node, WLR_SCENE_NODE_RASTER, parent);
|
||||
|
||||
if (buffer) {
|
||||
scene_buffer->buffer = wlr_buffer_lock(buffer);
|
||||
if (raster) {
|
||||
scene_raster->raster = wlr_raster_lock(raster);
|
||||
}
|
||||
|
||||
wl_signal_init(&scene_buffer->events.output_enter);
|
||||
wl_signal_init(&scene_buffer->events.output_leave);
|
||||
wl_signal_init(&scene_buffer->events.output_present);
|
||||
wl_signal_init(&scene_buffer->events.frame_done);
|
||||
wl_signal_init(&scene_raster->events.output_enter);
|
||||
wl_signal_init(&scene_raster->events.output_leave);
|
||||
wl_signal_init(&scene_raster->events.output_present);
|
||||
wl_signal_init(&scene_raster->events.frame_done);
|
||||
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
|
||||
scene_node_update_outputs(&scene_buffer->node, NULL);
|
||||
scene_node_update_outputs(&scene_raster->node, NULL);
|
||||
|
||||
return scene_buffer;
|
||||
return scene_raster;
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer, pixman_region32_t *damage) {
|
||||
// specifying a region for a NULL buffer doesn't make sense. We need to know
|
||||
// about the buffer to scale the buffer local coordinates down to scene
|
||||
void wlr_scene_raster_set_raster_with_damage(struct wlr_scene_raster *scene_raster,
|
||||
struct wlr_raster *raster, pixman_region32_t *damage) {
|
||||
// specifying a region for a NULL raster doesn't make sense. We need to know
|
||||
// about the raster to scale the raster local coordinates down to scene
|
||||
// coordinates.
|
||||
assert(buffer || !damage);
|
||||
assert(raster || !damage);
|
||||
|
||||
if (buffer != scene_buffer->buffer) {
|
||||
if (raster != scene_raster->raster) {
|
||||
if (!damage) {
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
}
|
||||
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
scene_buffer->texture = NULL;
|
||||
wlr_buffer_unlock(scene_buffer->buffer);
|
||||
wlr_raster_unlock(scene_raster->raster);
|
||||
scene_raster->raster = NULL;
|
||||
|
||||
if (buffer) {
|
||||
scene_buffer->buffer = wlr_buffer_lock(buffer);
|
||||
} else {
|
||||
scene_buffer->buffer = NULL;
|
||||
if (raster) {
|
||||
scene_raster->raster = wlr_raster_lock(raster);
|
||||
}
|
||||
|
||||
scene_node_update_outputs(&scene_buffer->node, NULL);
|
||||
scene_node_update_outputs(&scene_raster->node, NULL);
|
||||
|
||||
if (!damage) {
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -381,41 +377,41 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
}
|
||||
|
||||
int lx, ly;
|
||||
if (!wlr_scene_node_coords(&scene_buffer->node, &lx, &ly)) {
|
||||
if (!wlr_scene_node_coords(&scene_raster->node, &lx, &ly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_fbox box = scene_buffer->src_box;
|
||||
struct wlr_fbox box = scene_raster->src_box;
|
||||
if (wlr_fbox_empty(&box)) {
|
||||
box.x = 0;
|
||||
box.y = 0;
|
||||
|
||||
if (scene_buffer->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
box.width = buffer->height;
|
||||
box.height = buffer->width;
|
||||
if (scene_raster->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
box.width = raster->height;
|
||||
box.height = raster->width;
|
||||
} else {
|
||||
box.width = buffer->width;
|
||||
box.height = buffer->height;
|
||||
box.width = raster->width;
|
||||
box.height = raster->height;
|
||||
}
|
||||
}
|
||||
|
||||
double scale_x, scale_y;
|
||||
if (scene_buffer->dst_width || scene_buffer->dst_height) {
|
||||
scale_x = scene_buffer->dst_width / box.width;
|
||||
scale_y = scene_buffer->dst_height / box.height;
|
||||
if (scene_raster->dst_width || scene_raster->dst_height) {
|
||||
scale_x = scene_raster->dst_width / box.width;
|
||||
scale_y = scene_raster->dst_height / box.height;
|
||||
} else {
|
||||
scale_x = buffer->width / box.width;
|
||||
scale_y = buffer->height / box.height;
|
||||
scale_x = raster->width / box.width;
|
||||
scale_y = raster->height / box.height;
|
||||
}
|
||||
|
||||
pixman_region32_t trans_damage;
|
||||
pixman_region32_init(&trans_damage);
|
||||
wlr_region_transform(&trans_damage, damage,
|
||||
scene_buffer->transform, buffer->width, buffer->height);
|
||||
scene_raster->transform, raster->width, raster->height);
|
||||
pixman_region32_intersect_rect(&trans_damage, &trans_damage,
|
||||
box.x, box.y, box.width, box.height);
|
||||
|
||||
struct wlr_scene *scene = scene_node_get_root(&scene_buffer->node);
|
||||
struct wlr_scene *scene = scene_node_get_root(&scene_raster->node);
|
||||
struct wlr_scene_output *scene_output;
|
||||
wl_list_for_each(scene_output, &scene->outputs, link) {
|
||||
float output_scale = scene_output->output->scale;
|
||||
|
|
@ -435,14 +431,14 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
pixman_region32_fini(&trans_damage);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_buffer(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer) {
|
||||
wlr_scene_buffer_set_buffer_with_damage(scene_buffer, buffer, NULL);
|
||||
void wlr_scene_raster_set_raster(struct wlr_scene_raster *scene_raster,
|
||||
struct wlr_raster *raster) {
|
||||
wlr_scene_raster_set_raster_with_damage(scene_raster, raster, NULL);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_source_box(struct wlr_scene_buffer *scene_buffer,
|
||||
void wlr_scene_raster_set_source_box(struct wlr_scene_raster *scene_raster,
|
||||
const struct wlr_fbox *box) {
|
||||
struct wlr_fbox *cur = &scene_buffer->src_box;
|
||||
struct wlr_fbox *cur = &scene_raster->src_box;
|
||||
if ((wlr_fbox_empty(box) && wlr_fbox_empty(cur)) ||
|
||||
(box != NULL && memcmp(cur, box, sizeof(*box)) == 0)) {
|
||||
return;
|
||||
|
|
@ -454,56 +450,39 @@ void wlr_scene_buffer_set_source_box(struct wlr_scene_buffer *scene_buffer,
|
|||
memset(cur, 0, sizeof(*cur));
|
||||
}
|
||||
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_dest_size(struct wlr_scene_buffer *scene_buffer,
|
||||
void wlr_scene_raster_set_dest_size(struct wlr_scene_raster *scene_raster,
|
||||
int width, int height) {
|
||||
if (scene_buffer->dst_width == width && scene_buffer->dst_height == height) {
|
||||
if (scene_raster->dst_width == width && scene_raster->dst_height == height) {
|
||||
return;
|
||||
}
|
||||
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_buffer->dst_width = width;
|
||||
scene_buffer->dst_height = height;
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
scene_raster->dst_width = width;
|
||||
scene_raster->dst_height = height;
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
|
||||
scene_node_update_outputs(&scene_buffer->node, NULL);
|
||||
scene_node_update_outputs(&scene_raster->node, NULL);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_transform(struct wlr_scene_buffer *scene_buffer,
|
||||
void wlr_scene_raster_set_transform(struct wlr_scene_raster *scene_raster,
|
||||
enum wl_output_transform transform) {
|
||||
if (scene_buffer->transform == transform) {
|
||||
if (scene_raster->transform == transform) {
|
||||
return;
|
||||
}
|
||||
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_buffer->transform = transform;
|
||||
scene_node_damage_whole(&scene_buffer->node);
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
scene_raster->transform = transform;
|
||||
scene_node_damage_whole(&scene_raster->node);
|
||||
|
||||
scene_node_update_outputs(&scene_buffer->node, NULL);
|
||||
scene_node_update_outputs(&scene_raster->node, NULL);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_send_frame_done(struct wlr_scene_buffer *scene_buffer,
|
||||
void wlr_scene_raster_send_frame_done(struct wlr_scene_raster *scene_raster,
|
||||
struct timespec *now) {
|
||||
wlr_signal_emit_safe(&scene_buffer->events.frame_done, now);
|
||||
}
|
||||
|
||||
static struct wlr_texture *scene_buffer_get_texture(
|
||||
struct wlr_scene_buffer *scene_buffer, struct wlr_renderer *renderer) {
|
||||
struct wlr_client_buffer *client_buffer =
|
||||
wlr_client_buffer_get(scene_buffer->buffer);
|
||||
if (client_buffer != NULL) {
|
||||
return client_buffer->texture;
|
||||
}
|
||||
|
||||
if (scene_buffer->texture != NULL) {
|
||||
return scene_buffer->texture;
|
||||
}
|
||||
|
||||
scene_buffer->texture =
|
||||
wlr_texture_from_buffer(renderer, scene_buffer->buffer);
|
||||
return scene_buffer->texture;
|
||||
wlr_signal_emit_safe(&scene_raster->events.frame_done, now);
|
||||
}
|
||||
|
||||
static void scene_node_get_size(struct wlr_scene_node *node,
|
||||
|
|
@ -519,18 +498,18 @@ static void scene_node_get_size(struct wlr_scene_node *node,
|
|||
*width = scene_rect->width;
|
||||
*height = scene_rect->height;
|
||||
break;
|
||||
case WLR_SCENE_NODE_BUFFER:;
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
if (scene_buffer->dst_width > 0 && scene_buffer->dst_height > 0) {
|
||||
*width = scene_buffer->dst_width;
|
||||
*height = scene_buffer->dst_height;
|
||||
} else if (scene_buffer->buffer) {
|
||||
if (scene_buffer->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
*height = scene_buffer->buffer->width;
|
||||
*width = scene_buffer->buffer->height;
|
||||
case WLR_SCENE_NODE_RASTER:;
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
if (scene_raster->dst_width > 0 && scene_raster->dst_height > 0) {
|
||||
*width = scene_raster->dst_width;
|
||||
*height = scene_raster->dst_height;
|
||||
} else if (scene_raster->raster) {
|
||||
if (scene_raster->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
*height = scene_raster->raster->width;
|
||||
*width = scene_raster->raster->height;
|
||||
} else {
|
||||
*width = scene_buffer->buffer->width;
|
||||
*height = scene_buffer->buffer->height;
|
||||
*width = scene_raster->raster->width;
|
||||
*height = scene_raster->raster->height;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -718,8 +697,8 @@ bool wlr_scene_node_coords(struct wlr_scene_node *node,
|
|||
return enabled;
|
||||
}
|
||||
|
||||
static void scene_node_for_each_scene_buffer(struct wlr_scene_node *node,
|
||||
int lx, int ly, wlr_scene_buffer_iterator_func_t user_iterator,
|
||||
static void scene_node_for_each_scene_raster(struct wlr_scene_node *node,
|
||||
int lx, int ly, wlr_scene_raster_iterator_func_t user_iterator,
|
||||
void *user_data) {
|
||||
if (!node->enabled) {
|
||||
return;
|
||||
|
|
@ -728,21 +707,21 @@ static void scene_node_for_each_scene_buffer(struct wlr_scene_node *node,
|
|||
lx += node->x;
|
||||
ly += node->y;
|
||||
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
user_iterator(scene_buffer, lx, ly, user_data);
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
user_iterator(scene_raster, lx, ly, user_data);
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
|
||||
struct wlr_scene_node *child;
|
||||
wl_list_for_each(child, &scene_tree->children, link) {
|
||||
scene_node_for_each_scene_buffer(child, lx, ly, user_iterator, user_data);
|
||||
scene_node_for_each_scene_raster(child, lx, ly, user_iterator, user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_scene_node_for_each_buffer(struct wlr_scene_node *node,
|
||||
wlr_scene_buffer_iterator_func_t user_iterator, void *user_data) {
|
||||
scene_node_for_each_scene_buffer(node, 0, 0, user_iterator, user_data);
|
||||
void wlr_scene_node_for_each_raster(struct wlr_scene_node *node,
|
||||
wlr_scene_raster_iterator_func_t user_iterator, void *user_data) {
|
||||
scene_node_for_each_scene_raster(node, 0, 0, user_iterator, user_data);
|
||||
}
|
||||
|
||||
struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node,
|
||||
|
|
@ -773,11 +752,11 @@ struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node,
|
|||
scene_node_get_size(node, &width, &height);
|
||||
intersects = lx >= 0 && lx < width && ly >= 0 && ly < height;
|
||||
break;
|
||||
case WLR_SCENE_NODE_BUFFER:;
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
case WLR_SCENE_NODE_RASTER:;
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
|
||||
if (scene_buffer->point_accepts_input) {
|
||||
intersects = scene_buffer->point_accepts_input(scene_buffer, lx, ly);
|
||||
if (scene_raster->point_accepts_input) {
|
||||
intersects = scene_raster->point_accepts_input(scene_raster, lx, ly);
|
||||
} else {
|
||||
int width, height;
|
||||
scene_node_get_size(node, &width, &height);
|
||||
|
|
@ -841,8 +820,8 @@ static void render_rect(struct wlr_output *output,
|
|||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
static void render_texture(struct wlr_output *output,
|
||||
pixman_region32_t *output_damage, struct wlr_texture *texture,
|
||||
static void render_raster(struct wlr_output *output,
|
||||
pixman_region32_t *output_damage, struct wlr_raster *raster,
|
||||
const struct wlr_fbox *src_box, const struct wlr_box *dst_box,
|
||||
const float matrix[static 9]) {
|
||||
struct wlr_renderer *renderer = output->renderer;
|
||||
|
|
@ -850,8 +829,8 @@ static void render_texture(struct wlr_output *output,
|
|||
|
||||
struct wlr_fbox default_src_box = {0};
|
||||
if (wlr_fbox_empty(src_box)) {
|
||||
default_src_box.width = texture->width;
|
||||
default_src_box.height = texture->height;
|
||||
default_src_box.width = raster->width;
|
||||
default_src_box.height = raster->height;
|
||||
src_box = &default_src_box;
|
||||
}
|
||||
|
||||
|
|
@ -865,7 +844,7 @@ static void render_texture(struct wlr_output *output,
|
|||
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
|
||||
for (int i = 0; i < nrects; ++i) {
|
||||
scissor_output(output, &rects[i]);
|
||||
wlr_render_subtexture_with_matrix(renderer, texture, src_box, matrix, 1.0);
|
||||
wlr_render_subraster_with_matrix(renderer, raster, src_box, matrix, 1.0);
|
||||
}
|
||||
|
||||
pixman_region32_fini(&damage);
|
||||
|
|
@ -890,7 +869,6 @@ static void render_node_iterator(struct wlr_scene_node *node,
|
|||
scene_node_get_size(node, &dst_box.width, &dst_box.height);
|
||||
scale_box(&dst_box, output->scale);
|
||||
|
||||
struct wlr_texture *texture;
|
||||
float matrix[9];
|
||||
enum wl_output_transform transform;
|
||||
switch (node->type) {
|
||||
|
|
@ -903,26 +881,20 @@ static void render_node_iterator(struct wlr_scene_node *node,
|
|||
render_rect(output, output_damage, scene_rect->color, &dst_box,
|
||||
output->transform_matrix);
|
||||
break;
|
||||
case WLR_SCENE_NODE_BUFFER:;
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
if (!scene_buffer->buffer) {
|
||||
case WLR_SCENE_NODE_RASTER:;
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
if (!scene_raster->raster) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_renderer *renderer = output->renderer;
|
||||
texture = scene_buffer_get_texture(scene_buffer, renderer);
|
||||
if (texture == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
transform = wlr_output_transform_invert(scene_buffer->transform);
|
||||
transform = wlr_output_transform_invert(scene_raster->transform);
|
||||
wlr_matrix_project_box(matrix, &dst_box, transform, 0.0,
|
||||
output->transform_matrix);
|
||||
|
||||
render_texture(output, output_damage, texture, &scene_buffer->src_box,
|
||||
&dst_box, matrix);
|
||||
render_raster(output, output_damage, scene_raster->raster,
|
||||
&scene_raster->src_box, &dst_box, matrix);
|
||||
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_present, scene_output);
|
||||
wlr_signal_emit_safe(&scene_raster->events.output_present, scene_output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1181,31 +1153,35 @@ static bool scene_output_scanout(struct wlr_scene_output *scene_output) {
|
|||
}
|
||||
|
||||
struct wlr_scene_node *node = check_scanout_data.node;
|
||||
struct wlr_buffer *buffer;
|
||||
struct wlr_raster *raster;
|
||||
switch (node->type) {
|
||||
case WLR_SCENE_NODE_BUFFER:;
|
||||
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
||||
if (scene_buffer->buffer == NULL ||
|
||||
!wlr_fbox_empty(&scene_buffer->src_box) ||
|
||||
scene_buffer->transform != output->transform) {
|
||||
case WLR_SCENE_NODE_RASTER:;
|
||||
struct wlr_scene_raster *scene_raster = wlr_scene_raster_from_node(node);
|
||||
if (scene_raster->raster == NULL ||
|
||||
!wlr_fbox_empty(&scene_raster->src_box) ||
|
||||
scene_raster->transform != output->transform) {
|
||||
return false;
|
||||
}
|
||||
buffer = scene_buffer->buffer;
|
||||
raster = scene_raster->raster;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
wlr_output_attach_buffer(output, buffer);
|
||||
if (!raster->buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
wlr_output_attach_buffer(output, raster->buffer);
|
||||
if (!wlr_output_test(output)) {
|
||||
wlr_output_rollback(output);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
struct wlr_scene_buffer *scene_buffer =
|
||||
wlr_scene_buffer_from_node(node);
|
||||
wlr_signal_emit_safe(&scene_buffer->events.output_present, scene_output);
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_scene_raster *scene_raster =
|
||||
wlr_scene_raster_from_node(node);
|
||||
wlr_signal_emit_safe(&scene_raster->events.output_present, scene_output);
|
||||
}
|
||||
|
||||
return wlr_output_commit(output);
|
||||
|
|
@ -1371,12 +1347,12 @@ static void scene_node_send_frame_done(struct wlr_scene_node *node,
|
|||
return;
|
||||
}
|
||||
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
struct wlr_scene_buffer *scene_buffer =
|
||||
wlr_scene_buffer_from_node(node);
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_scene_raster *scene_raster =
|
||||
wlr_scene_raster_from_node(node);
|
||||
|
||||
if (scene_buffer->primary_output == scene_output) {
|
||||
wlr_scene_buffer_send_frame_done(scene_buffer, now);
|
||||
if (scene_raster->primary_output == scene_output) {
|
||||
wlr_scene_raster_send_frame_done(scene_raster, now);
|
||||
}
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
|
||||
|
|
@ -1393,9 +1369,9 @@ void wlr_scene_output_send_frame_done(struct wlr_scene_output *scene_output,
|
|||
scene_output, now);
|
||||
}
|
||||
|
||||
static void scene_output_for_each_scene_buffer(const struct wlr_box *output_box,
|
||||
static void scene_output_for_each_scene_raster(const struct wlr_box *output_box,
|
||||
struct wlr_scene_node *node, int lx, int ly,
|
||||
wlr_scene_buffer_iterator_func_t user_iterator, void *user_data) {
|
||||
wlr_scene_raster_iterator_func_t user_iterator, void *user_data) {
|
||||
if (!node->enabled) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1403,31 +1379,31 @@ static void scene_output_for_each_scene_buffer(const struct wlr_box *output_box,
|
|||
lx += node->x;
|
||||
ly += node->y;
|
||||
|
||||
if (node->type == WLR_SCENE_NODE_BUFFER) {
|
||||
if (node->type == WLR_SCENE_NODE_RASTER) {
|
||||
struct wlr_box node_box = { .x = lx, .y = ly };
|
||||
scene_node_get_size(node, &node_box.width, &node_box.height);
|
||||
|
||||
struct wlr_box intersection;
|
||||
if (wlr_box_intersection(&intersection, output_box, &node_box)) {
|
||||
struct wlr_scene_buffer *scene_buffer =
|
||||
wlr_scene_buffer_from_node(node);
|
||||
user_iterator(scene_buffer, lx, ly, user_data);
|
||||
struct wlr_scene_raster *scene_raster =
|
||||
wlr_scene_raster_from_node(node);
|
||||
user_iterator(scene_raster, lx, ly, user_data);
|
||||
}
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
struct wlr_scene_tree *scene_tree = scene_tree_from_node(node);
|
||||
struct wlr_scene_node *child;
|
||||
wl_list_for_each(child, &scene_tree->children, link) {
|
||||
scene_output_for_each_scene_buffer(output_box, child, lx, ly,
|
||||
scene_output_for_each_scene_raster(output_box, child, lx, ly,
|
||||
user_iterator, user_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_scene_output_for_each_buffer(struct wlr_scene_output *scene_output,
|
||||
wlr_scene_buffer_iterator_func_t iterator, void *user_data) {
|
||||
void wlr_scene_output_for_each_raster(struct wlr_scene_output *scene_output,
|
||||
wlr_scene_raster_iterator_func_t iterator, void *user_data) {
|
||||
struct wlr_box box = { .x = scene_output->x, .y = scene_output->y };
|
||||
wlr_output_effective_resolution(scene_output->output,
|
||||
&box.width, &box.height);
|
||||
scene_output_for_each_scene_buffer(&box, &scene_output->scene->tree.node, 0, 0,
|
||||
scene_output_for_each_scene_raster(&box, &scene_output->scene->tree.node, 0, 0,
|
||||
iterator, user_data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,59 +109,8 @@ bool wlr_resource_is_buffer(struct wl_resource *resource) {
|
|||
return strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) == 0;
|
||||
}
|
||||
|
||||
static const struct wlr_buffer_impl client_buffer_impl;
|
||||
|
||||
struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer) {
|
||||
if (buffer->impl != &client_buffer_impl) {
|
||||
return NULL;
|
||||
}
|
||||
return (struct wlr_client_buffer *)buffer;
|
||||
}
|
||||
|
||||
static struct wlr_client_buffer *client_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
struct wlr_client_buffer *client_buffer = wlr_client_buffer_get(buffer);
|
||||
assert(client_buffer != NULL);
|
||||
return client_buffer;
|
||||
}
|
||||
|
||||
static void client_buffer_destroy(struct wlr_buffer *buffer) {
|
||||
struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer);
|
||||
wl_list_remove(&client_buffer->source_destroy.link);
|
||||
wlr_texture_destroy(client_buffer->texture);
|
||||
free(client_buffer);
|
||||
}
|
||||
|
||||
static bool client_buffer_get_dmabuf(struct wlr_buffer *buffer,
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer);
|
||||
|
||||
if (client_buffer->source == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return wlr_buffer_get_dmabuf(client_buffer->source, attribs);
|
||||
}
|
||||
|
||||
static const struct wlr_buffer_impl client_buffer_impl = {
|
||||
.destroy = client_buffer_destroy,
|
||||
.get_dmabuf = client_buffer_get_dmabuf,
|
||||
};
|
||||
|
||||
static void client_buffer_handle_source_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_client_buffer *client_buffer =
|
||||
wl_container_of(listener, client_buffer, source_destroy);
|
||||
wl_list_remove(&client_buffer->source_destroy.link);
|
||||
wl_list_init(&client_buffer->source_destroy.link);
|
||||
client_buffer->source = NULL;
|
||||
}
|
||||
|
||||
static struct wlr_shm_client_buffer *shm_client_buffer_get_or_create(
|
||||
struct wl_resource *resource);
|
||||
static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer);
|
||||
static struct wlr_shm_client_buffer *shm_client_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer);
|
||||
|
||||
/* struct wlr_buffer_resource_interface */
|
||||
static struct wl_array buffer_resource_interfaces = {0};
|
||||
|
|
@ -263,99 +212,13 @@ bool buffer_is_opaque(struct wlr_buffer *buffer) {
|
|||
return !format_info->has_alpha;
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
|
||||
struct wlr_renderer *renderer) {
|
||||
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer);
|
||||
if (texture == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to create texture");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *client_buffer =
|
||||
calloc(1, sizeof(struct wlr_client_buffer));
|
||||
if (client_buffer == NULL) {
|
||||
wlr_texture_destroy(texture);
|
||||
return NULL;
|
||||
}
|
||||
wlr_buffer_init(&client_buffer->base, &client_buffer_impl,
|
||||
texture->width, texture->height);
|
||||
client_buffer->source = buffer;
|
||||
client_buffer->texture = texture;
|
||||
|
||||
wl_signal_add(&buffer->events.destroy, &client_buffer->source_destroy);
|
||||
client_buffer->source_destroy.notify = client_buffer_handle_source_destroy;
|
||||
|
||||
if (buffer_is_shm_client_buffer(buffer)) {
|
||||
struct wlr_shm_client_buffer *shm_client_buffer =
|
||||
shm_client_buffer_from_buffer(buffer);
|
||||
client_buffer->shm_source_format = shm_client_buffer->format;
|
||||
} else {
|
||||
client_buffer->shm_source_format = DRM_FORMAT_INVALID;
|
||||
}
|
||||
|
||||
// Ensure the buffer will be released before being destroyed
|
||||
wlr_buffer_lock(&client_buffer->base);
|
||||
wlr_buffer_drop(&client_buffer->base);
|
||||
|
||||
return client_buffer;
|
||||
}
|
||||
|
||||
bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
|
||||
struct wlr_buffer *next, pixman_region32_t *damage) {
|
||||
if (client_buffer->base.n_locks > 1) {
|
||||
// Someone else still has a reference to the buffer
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((uint32_t)next->width != client_buffer->texture->width ||
|
||||
(uint32_t)next->height != client_buffer->texture->height) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (client_buffer->shm_source_format == DRM_FORMAT_INVALID) {
|
||||
// Uploading only damaged regions only works for wl_shm buffers and
|
||||
// mutable textures (created from wl_shm buffer)
|
||||
return false;
|
||||
}
|
||||
|
||||
void *data;
|
||||
uint32_t format;
|
||||
size_t stride;
|
||||
if (!wlr_buffer_begin_data_ptr_access(next, WLR_BUFFER_DATA_PTR_ACCESS_READ,
|
||||
&data, &format, &stride)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (format != client_buffer->shm_source_format) {
|
||||
// Uploading to textures can't change the format
|
||||
wlr_buffer_end_data_ptr_access(next);
|
||||
return false;
|
||||
}
|
||||
|
||||
int n;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(damage, &n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
pixman_box32_t *r = &rects[i];
|
||||
if (!wlr_texture_write_pixels(client_buffer->texture, stride,
|
||||
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
|
||||
r->x1, r->y1, data)) {
|
||||
wlr_buffer_end_data_ptr_access(next);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_buffer_end_data_ptr_access(next);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct wlr_buffer_impl shm_client_buffer_impl;
|
||||
|
||||
static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer) {
|
||||
bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer) {
|
||||
return buffer->impl == &shm_client_buffer_impl;
|
||||
}
|
||||
|
||||
static struct wlr_shm_client_buffer *shm_client_buffer_from_buffer(
|
||||
struct wlr_shm_client_buffer *shm_client_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer_is_shm_client_buffer(buffer));
|
||||
return (struct wlr_shm_client_buffer *)buffer;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/interfaces/wlr_buffer.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
|
|
@ -333,45 +334,15 @@ static void surface_state_move(struct wlr_surface_state *state,
|
|||
static void surface_apply_damage(struct wlr_surface *surface) {
|
||||
if (surface->current.buffer == NULL) {
|
||||
// NULL commit
|
||||
if (surface->buffer != NULL) {
|
||||
wlr_buffer_unlock(&surface->buffer->base);
|
||||
}
|
||||
surface->buffer = NULL;
|
||||
surface->opaque = false;
|
||||
return;
|
||||
}
|
||||
|
||||
surface->opaque = buffer_is_opaque(surface->current.buffer);
|
||||
|
||||
if (surface->buffer != NULL) {
|
||||
if (wlr_client_buffer_apply_damage(surface->buffer,
|
||||
surface->current.buffer, &surface->buffer_damage)) {
|
||||
wlr_buffer_unlock(surface->current.buffer);
|
||||
surface->current.buffer = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *buffer = wlr_client_buffer_create(
|
||||
surface->current.buffer, surface->renderer);
|
||||
|
||||
wlr_buffer_unlock(surface->current.buffer);
|
||||
surface->current.buffer = NULL;
|
||||
|
||||
if (buffer == NULL) {
|
||||
wlr_log(WLR_ERROR, "Failed to upload buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (surface->buffer != NULL) {
|
||||
wlr_buffer_unlock(&surface->buffer->base);
|
||||
}
|
||||
surface->buffer = buffer;
|
||||
}
|
||||
|
||||
static void surface_update_opaque_region(struct wlr_surface *surface) {
|
||||
struct wlr_texture *texture = wlr_surface_get_texture(surface);
|
||||
if (texture == NULL) {
|
||||
if (!wlr_surface_has_buffer(surface)) {
|
||||
pixman_region32_clear(&surface->opaque_region);
|
||||
return;
|
||||
}
|
||||
|
|
@ -445,8 +416,34 @@ static void surface_commit_state(struct wlr_surface *surface,
|
|||
surface_state_move(&surface->current, next);
|
||||
|
||||
if (invalid_buffer) {
|
||||
if (!surface->current.buffer) {
|
||||
wlr_raster_unlock(surface->raster);
|
||||
surface->raster = NULL;
|
||||
}
|
||||
|
||||
if (!surface->raster || surface->raster->buffer != surface->current.buffer) {
|
||||
surface->old_raster = surface->raster;
|
||||
|
||||
if (surface->current.buffer) {
|
||||
surface->raster = wlr_raster_create(surface->current.buffer);
|
||||
}
|
||||
|
||||
if (surface->old_raster) {
|
||||
// By the time we unlock the buffer next the buffer might
|
||||
// get destroyed. We need to start listening here.
|
||||
wl_signal_add(&surface->old_raster->events.destroy,
|
||||
&surface->raster_destroy);
|
||||
|
||||
wlr_raster_unlock(surface->old_raster);
|
||||
}
|
||||
}
|
||||
|
||||
surface_apply_damage(surface);
|
||||
|
||||
wlr_buffer_unlock(surface->current.buffer);
|
||||
surface->current.buffer = NULL;
|
||||
}
|
||||
|
||||
surface_update_opaque_region(surface);
|
||||
surface_update_input_region(surface);
|
||||
|
||||
|
|
@ -480,6 +477,37 @@ static void surface_commit_state(struct wlr_surface *surface,
|
|||
}
|
||||
|
||||
wlr_signal_emit_safe(&surface->events.commit, surface);
|
||||
|
||||
if (surface->old_raster) {
|
||||
wl_list_remove(&surface->raster_destroy.link);
|
||||
surface->old_raster = NULL;
|
||||
}
|
||||
|
||||
if (invalid_buffer && surface->raster) {
|
||||
// upload the texture to all renderers that this surface intersects.
|
||||
struct wlr_surface_output *surface_output;
|
||||
wl_list_for_each(surface_output, &surface->current_outputs, link) {
|
||||
if (!surface_output->output->renderer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
wlr_renderer_raster_upload(surface_output->output->renderer,
|
||||
surface->raster);
|
||||
}
|
||||
|
||||
// unlock the buffer for shm buffers only. Clients may implement
|
||||
// optimizations if given the shm buffer back immediately. But only do
|
||||
// this if the raster has a source, if not, that means that the surface
|
||||
// is not visible on any outputs and let's continue locking the buffer
|
||||
// until it is visible.
|
||||
//
|
||||
// For other buffers, we want to continue to lock it so that we
|
||||
// may direct scanout.
|
||||
if (!wl_list_empty(&surface->raster->sources) && surface->raster->buffer &&
|
||||
buffer_is_shm_client_buffer(surface->raster->buffer)) {
|
||||
wlr_raster_remove_buffer(surface->raster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void collect_subsurface_damage_iter(struct wlr_surface *surface,
|
||||
|
|
@ -644,6 +672,8 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
|||
surface_output_destroy(surface_output);
|
||||
}
|
||||
|
||||
wlr_raster_unlock(surface->raster);
|
||||
|
||||
wlr_signal_emit_safe(&surface->events.destroy, surface);
|
||||
|
||||
wlr_addon_set_finish(&surface->addons);
|
||||
|
|
@ -653,28 +683,63 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
|||
surface_state_destroy_cached(cached);
|
||||
}
|
||||
|
||||
wl_list_remove(&surface->renderer_destroy.link);
|
||||
surface_state_finish(&surface->pending);
|
||||
surface_state_finish(&surface->current);
|
||||
pixman_region32_fini(&surface->buffer_damage);
|
||||
pixman_region32_fini(&surface->external_damage);
|
||||
pixman_region32_fini(&surface->opaque_region);
|
||||
pixman_region32_fini(&surface->input_region);
|
||||
if (surface->buffer != NULL) {
|
||||
wlr_buffer_unlock(&surface->buffer->base);
|
||||
}
|
||||
free(surface);
|
||||
}
|
||||
|
||||
static void surface_handle_renderer_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
static void surface_handle_raster_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_surface *surface =
|
||||
wl_container_of(listener, surface, renderer_destroy);
|
||||
wl_resource_destroy(surface->resource);
|
||||
wl_container_of(listener, surface, raster_destroy);
|
||||
|
||||
// if there are already sources for the new raster, don't bother uploading
|
||||
// if something else already did for us.
|
||||
if (!wl_list_empty(&surface->raster->sources)) {
|
||||
surface->old_raster = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// try to reclaim the textures from this raster so we can try to do a partial
|
||||
// upload.
|
||||
struct wlr_texture *texture, *tmp_texture;
|
||||
wl_list_for_each_safe(texture, tmp_texture,
|
||||
&surface->old_raster->sources, link) {
|
||||
wlr_raster_detach(surface->old_raster, texture);
|
||||
|
||||
bool visible = false;
|
||||
|
||||
// only try to reuse textures of renderers that will see this surface.
|
||||
struct wlr_surface_output *surface_output;
|
||||
wl_list_for_each(surface_output, &surface->current_outputs, link) {
|
||||
if (surface_output->output->renderer == texture->renderer) {
|
||||
visible = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!visible) {
|
||||
wlr_texture_destroy(texture);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wlr_texture_update_from_raster(texture,
|
||||
surface->raster, &surface->buffer_damage)) {
|
||||
wlr_texture_destroy(texture);
|
||||
continue;
|
||||
}
|
||||
|
||||
wlr_raster_attach(surface->raster, texture);
|
||||
}
|
||||
|
||||
surface->old_raster = NULL;
|
||||
}
|
||||
|
||||
static struct wlr_surface *surface_create(struct wl_client *client,
|
||||
uint32_t version, uint32_t id, struct wlr_renderer *renderer) {
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_surface *surface = calloc(1, sizeof(struct wlr_surface));
|
||||
if (!surface) {
|
||||
wl_client_post_no_memory(client);
|
||||
|
|
@ -692,8 +757,6 @@ static struct wlr_surface *surface_create(struct wl_client *client,
|
|||
|
||||
wlr_log(WLR_DEBUG, "New wlr_surface %p (res %p)", surface, surface->resource);
|
||||
|
||||
surface->renderer = renderer;
|
||||
|
||||
surface_state_init(&surface->current);
|
||||
surface_state_init(&surface->pending);
|
||||
surface->pending.seq = 1;
|
||||
|
|
@ -710,21 +773,13 @@ static struct wlr_surface *surface_create(struct wl_client *client,
|
|||
pixman_region32_init(&surface->input_region);
|
||||
wlr_addon_set_init(&surface->addons);
|
||||
|
||||
wl_signal_add(&renderer->events.destroy, &surface->renderer_destroy);
|
||||
surface->renderer_destroy.notify = surface_handle_renderer_destroy;
|
||||
surface->raster_destroy.notify = surface_handle_raster_destroy;
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface) {
|
||||
if (surface->buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return surface->buffer->texture;
|
||||
}
|
||||
|
||||
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
|
||||
return wlr_surface_get_texture(surface) != NULL;
|
||||
return surface->raster != NULL;
|
||||
}
|
||||
|
||||
bool wlr_surface_set_role(struct wlr_surface *surface,
|
||||
|
|
@ -1097,7 +1152,7 @@ static void compositor_create_surface(struct wl_client *client,
|
|||
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
||||
|
||||
struct wlr_surface *surface = surface_create(client,
|
||||
wl_resource_get_version(resource), id, compositor->renderer);
|
||||
wl_resource_get_version(resource), id);
|
||||
if (surface == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
|
|
@ -1139,8 +1194,7 @@ static void compositor_handle_display_destroy(
|
|||
free(compositor);
|
||||
}
|
||||
|
||||
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
||||
struct wlr_renderer *renderer) {
|
||||
struct wlr_compositor *wlr_compositor_create(struct wl_display *display) {
|
||||
struct wlr_compositor *compositor = calloc(1, sizeof(*compositor));
|
||||
if (!compositor) {
|
||||
return NULL;
|
||||
|
|
@ -1152,7 +1206,6 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
|||
free(compositor);
|
||||
return NULL;
|
||||
}
|
||||
compositor->renderer = renderer;
|
||||
|
||||
wl_signal_init(&compositor->events.new_surface);
|
||||
wl_signal_init(&compositor->events.destroy);
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ struct wlr_dmabuf_v1_buffer *wlr_dmabuf_v1_buffer_from_buffer_resource(
|
|||
|
||||
static const struct wlr_buffer_impl buffer_impl;
|
||||
|
||||
bool wlr_dmabuf_v1_buffer_is_buffer(struct wlr_buffer *buffer) {
|
||||
return buffer->impl == &buffer_impl;
|
||||
}
|
||||
|
||||
static struct wlr_dmabuf_v1_buffer *dmabuf_v1_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer->impl == &buffer_impl);
|
||||
|
|
@ -197,17 +201,15 @@ static void buffer_handle_resource_destroy(struct wl_resource *buffer_resource)
|
|||
}
|
||||
|
||||
static bool check_import_dmabuf(struct wlr_linux_dmabuf_v1 *linux_dmabuf,
|
||||
struct wlr_dmabuf_attributes *attribs) {
|
||||
struct wlr_texture *texture =
|
||||
wlr_texture_from_dmabuf(linux_dmabuf->renderer, attribs);
|
||||
if (texture == NULL) {
|
||||
struct wlr_buffer *dmabuf) {
|
||||
struct wlr_raster *raster = wlr_raster_create(dmabuf);
|
||||
if (!raster) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We can import the image, good. No need to keep it since wlr_surface will
|
||||
// import it again on commit.
|
||||
wlr_texture_destroy(texture);
|
||||
return true;
|
||||
bool success = wlr_renderer_raster_upload(linux_dmabuf->renderer, raster);
|
||||
wlr_raster_unlock(raster);
|
||||
return success;
|
||||
}
|
||||
|
||||
static void params_create_common(struct wl_resource *params_resource,
|
||||
|
|
@ -327,17 +329,19 @@ static void params_create_common(struct wl_resource *params_resource,
|
|||
}
|
||||
}
|
||||
|
||||
/* Check if dmabuf is usable */
|
||||
if (!check_import_dmabuf(linux_dmabuf, &attribs)) {
|
||||
goto err_failed;
|
||||
}
|
||||
|
||||
struct wlr_dmabuf_v1_buffer *buffer = calloc(1, sizeof(*buffer));
|
||||
if (!buffer) {
|
||||
wl_resource_post_no_memory(params_resource);
|
||||
goto err_failed;
|
||||
}
|
||||
wlr_buffer_init(&buffer->base, &buffer_impl, attribs.width, attribs.height);
|
||||
buffer->attributes = attribs;
|
||||
|
||||
/* Check if dmabuf is usable */
|
||||
if (!check_import_dmabuf(linux_dmabuf, &buffer->base)) {
|
||||
free(buffer);
|
||||
goto err_failed;
|
||||
}
|
||||
|
||||
struct wl_client *client = wl_resource_get_client(params_resource);
|
||||
buffer->resource = wl_resource_create(client, &wl_buffer_interface,
|
||||
|
|
@ -350,8 +354,6 @@ static void params_create_common(struct wl_resource *params_resource,
|
|||
wl_resource_set_implementation(buffer->resource,
|
||||
&wl_buffer_impl, buffer, buffer_handle_resource_destroy);
|
||||
|
||||
buffer->attributes = attribs;
|
||||
|
||||
buffer->release.notify = buffer_handle_release;
|
||||
wl_signal_add(&buffer->base.events.release, &buffer->release);
|
||||
|
||||
|
|
|
|||
103
types/wlr_raster.c
Normal file
103
types/wlr_raster.c
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <assert.h>
|
||||
#include <wlr/types/wlr_raster.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/render/wlr_texture.h>
|
||||
#include "types/wlr_buffer.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
struct wlr_raster *wlr_raster_create(struct wlr_buffer *buffer) {
|
||||
struct wlr_raster *raster = calloc(1, sizeof(*raster));
|
||||
if (!raster) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_list_init(&raster->sources);
|
||||
wl_signal_init(&raster->events.destroy);
|
||||
|
||||
assert(buffer);
|
||||
raster->width = buffer->width;
|
||||
raster->height = buffer->height;
|
||||
raster->buffer = wlr_buffer_lock(buffer);
|
||||
|
||||
raster->n_locks = 1;
|
||||
|
||||
return raster;
|
||||
}
|
||||
|
||||
void wlr_raster_remove_buffer(struct wlr_raster *raster) {
|
||||
assert(raster->buffer);
|
||||
assert(!wl_list_empty(&raster->sources));
|
||||
|
||||
wlr_buffer_unlock(raster->buffer);
|
||||
raster->buffer = NULL;
|
||||
}
|
||||
|
||||
static void raster_consider_destroy(struct wlr_raster *raster) {
|
||||
if (raster->n_locks > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&raster->events.destroy, NULL);
|
||||
|
||||
struct wlr_texture *texture, *texture_tmp;
|
||||
wl_list_for_each_safe(texture, texture_tmp, &raster->sources, link) {
|
||||
wlr_texture_destroy(texture);
|
||||
}
|
||||
|
||||
wlr_buffer_unlock(raster->buffer);
|
||||
free(raster);
|
||||
}
|
||||
|
||||
struct wlr_raster *wlr_raster_lock(struct wlr_raster *raster) {
|
||||
raster->n_locks++;
|
||||
return raster;
|
||||
}
|
||||
|
||||
void wlr_raster_unlock(struct wlr_raster *raster) {
|
||||
if (!raster) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(raster->n_locks > 0);
|
||||
|
||||
raster->n_locks--;
|
||||
raster_consider_destroy(raster);
|
||||
}
|
||||
|
||||
void wlr_raster_attach(struct wlr_raster *raster, struct wlr_texture *texture) {
|
||||
assert(texture);
|
||||
assert(!texture->raster);
|
||||
assert(texture->width == raster->width && texture->height == raster->height);
|
||||
|
||||
wl_list_insert(&raster->sources, &texture->link);
|
||||
texture->raster = raster;
|
||||
}
|
||||
|
||||
void wlr_raster_detach(struct wlr_raster *raster, struct wlr_texture *texture) {
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(texture->raster == raster);
|
||||
texture->raster = NULL;
|
||||
wl_list_remove(&texture->link);
|
||||
}
|
||||
|
||||
struct wlr_raster *wlr_raster_from_pixels(uint32_t fmt, uint32_t stride,
|
||||
uint32_t width, uint32_t height, const void *data) {
|
||||
assert(data);
|
||||
|
||||
struct wlr_readonly_data_buffer *buffer =
|
||||
readonly_data_buffer_create(fmt, stride, width, height, data);
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_raster *raster = wlr_raster_create(&buffer->base);
|
||||
|
||||
// By this point, the renderer should have locked the buffer if it still
|
||||
// needs to access it in the future.
|
||||
readonly_data_buffer_drop(buffer);
|
||||
|
||||
return raster;
|
||||
}
|
||||
|
|
@ -226,14 +226,18 @@ static bool frame_shm_copy(struct wlr_screencopy_frame_v1 *frame,
|
|||
static bool blit_dmabuf(struct wlr_renderer *renderer,
|
||||
struct wlr_dmabuf_v1_buffer *dst_dmabuf,
|
||||
struct wlr_buffer *src_buffer) {
|
||||
struct wlr_buffer *dst_buffer = wlr_buffer_lock(&dst_dmabuf->base);
|
||||
|
||||
struct wlr_texture *src_tex =
|
||||
wlr_texture_from_buffer(renderer, src_buffer);
|
||||
if (src_tex == NULL) {
|
||||
goto error_src_tex;
|
||||
struct wlr_raster *raster = wlr_raster_create(src_buffer);
|
||||
if (!raster){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!wlr_renderer_raster_upload(renderer, raster)) {
|
||||
wlr_raster_unlock(raster);
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_buffer *dst_buffer = wlr_buffer_lock(&dst_dmabuf->base);
|
||||
|
||||
float mat[9];
|
||||
wlr_matrix_identity(mat);
|
||||
wlr_matrix_scale(mat, dst_buffer->width, dst_buffer->height);
|
||||
|
|
@ -243,17 +247,16 @@ static bool blit_dmabuf(struct wlr_renderer *renderer,
|
|||
}
|
||||
|
||||
wlr_renderer_clear(renderer, (float[]){ 0.0, 0.0, 0.0, 0.0 });
|
||||
wlr_render_texture_with_matrix(renderer, src_tex, mat, 1.0f);
|
||||
wlr_render_raster_with_matrix(renderer, raster, mat, 1.0f);
|
||||
|
||||
wlr_renderer_end(renderer);
|
||||
|
||||
wlr_texture_destroy(src_tex);
|
||||
wlr_raster_unlock(raster);
|
||||
wlr_buffer_unlock(dst_buffer);
|
||||
return true;
|
||||
|
||||
error_renderer_begin:
|
||||
wlr_texture_destroy(src_tex);
|
||||
error_src_tex:
|
||||
wlr_raster_unlock(raster);
|
||||
wlr_buffer_unlock(dst_buffer);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue