mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-13 13:29:44 -05:00
Introduce wlr_output_layer
This new API allows compositors to display buffers without needing to perform rendering operations. This API can be implemented on Wayland using subsurfaces and on DRM using KMS planes. The goal is to make use of this API in a future scene-graph API. References: https://github.com/swaywm/wlroots/issues/1826
This commit is contained in:
parent
7429ba116f
commit
0fad58760a
7 changed files with 277 additions and 1 deletions
11
include/types/wlr_output_layer.h
Normal file
11
include/types/wlr_output_layer.h
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef TYPES_WLR_OUTPUT_LAYER_H
|
||||||
|
#define TYPES_WLR_OUTPUT_LAYER_H
|
||||||
|
|
||||||
|
#include <wlr/types/wlr_output_layer.h>
|
||||||
|
|
||||||
|
void output_layer_destroy(struct wlr_output_layer *layer);
|
||||||
|
void output_layer_state_move(struct wlr_output_layer_state *dst,
|
||||||
|
struct wlr_output_layer_state *src);
|
||||||
|
void output_layer_state_clear(struct wlr_output_layer_state *state);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -29,6 +29,8 @@ struct wlr_output_impl {
|
||||||
size_t (*get_gamma_size)(struct wlr_output *output);
|
size_t (*get_gamma_size)(struct wlr_output *output);
|
||||||
bool (*export_dmabuf)(struct wlr_output *output,
|
bool (*export_dmabuf)(struct wlr_output *output,
|
||||||
struct wlr_dmabuf_attributes *attribs);
|
struct wlr_dmabuf_attributes *attribs);
|
||||||
|
struct wlr_output_layer *(*create_layer)(struct wlr_output *output);
|
||||||
|
void (*destroy_layer)(struct wlr_output_layer *layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
||||||
|
|
@ -44,4 +46,7 @@ void wlr_output_send_frame(struct wlr_output *output);
|
||||||
void wlr_output_send_present(struct wlr_output *output,
|
void wlr_output_send_present(struct wlr_output *output,
|
||||||
struct wlr_output_event_present *event);
|
struct wlr_output_event_present *event);
|
||||||
|
|
||||||
|
void wlr_output_layer_init(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output *output);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ enum wlr_output_state_field {
|
||||||
WLR_OUTPUT_STATE_SCALE = 1 << 4,
|
WLR_OUTPUT_STATE_SCALE = 1 << 4,
|
||||||
WLR_OUTPUT_STATE_TRANSFORM = 1 << 5,
|
WLR_OUTPUT_STATE_TRANSFORM = 1 << 5,
|
||||||
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED = 1 << 6,
|
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED = 1 << 6,
|
||||||
|
WLR_OUTPUT_STATE_LAYERS = 1 << 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum wlr_output_state_buffer_type {
|
enum wlr_output_state_buffer_type {
|
||||||
|
|
@ -94,6 +95,8 @@ struct wlr_output_state {
|
||||||
int32_t width, height;
|
int32_t width, height;
|
||||||
int32_t refresh; // mHz, may be zero
|
int32_t refresh; // mHz, may be zero
|
||||||
} custom_mode;
|
} custom_mode;
|
||||||
|
|
||||||
|
struct wl_list layers; // wlr_output_layer.pending.link
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_output_impl;
|
struct wlr_output_impl;
|
||||||
|
|
@ -141,6 +144,8 @@ struct wlr_output {
|
||||||
bool frame_pending;
|
bool frame_pending;
|
||||||
float transform_matrix[9];
|
float transform_matrix[9];
|
||||||
|
|
||||||
|
struct wl_list layers; // wlr_output_layer.current.link
|
||||||
|
|
||||||
struct wlr_output_state pending;
|
struct wlr_output_state pending;
|
||||||
|
|
||||||
// Commit sequence number. Incremented on each commit, may overflow.
|
// Commit sequence number. Incremented on each commit, may overflow.
|
||||||
|
|
|
||||||
83
include/wlr/types/wlr_output_layer.h
Normal file
83
include/wlr/types/wlr_output_layer.h
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* This an unstable interface of wlroots. No guarantees are made regarding the
|
||||||
|
* future consistency of this API.
|
||||||
|
*/
|
||||||
|
#ifndef WLR_USE_UNSTABLE
|
||||||
|
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WLR_TYPES_WLR_OUTPUT_LAYER_H
|
||||||
|
#define WLR_TYPES_WLR_OUTPUT_LAYER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output layers provide an API to display buffers without rendering them. It
|
||||||
|
* relies on backend features which are not always available: the backend can
|
||||||
|
* refuse to display a layer. However when the backend accepts to display a
|
||||||
|
* layer, performance and battery usage will be improved.
|
||||||
|
*
|
||||||
|
* Operations on output layers are double-buffered. An output commit is needed
|
||||||
|
* to apply the pending state.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <wayland-server-core.h>
|
||||||
|
|
||||||
|
enum wlr_output_layer_state_field {
|
||||||
|
WLR_OUTPUT_LAYER_STATE_LINK = 1 << 0,
|
||||||
|
WLR_OUTPUT_LAYER_STATE_BUFFER = 1 << 1,
|
||||||
|
WLR_OUTPUT_LAYER_STATE_POSITION = 1 << 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_output_layer_state {
|
||||||
|
uint32_t committed; // enum wlr_output_layer_state_field
|
||||||
|
struct wl_list link;
|
||||||
|
struct wlr_buffer *buffer; // only valid if WLR_OUTPUT_LAYER_STATE_BUFFER
|
||||||
|
int x, y; // only valid if WLR_OUTPUT_LAYER_STATE_POSITION
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wlr_output_layer {
|
||||||
|
struct wlr_output *output;
|
||||||
|
/** If true, the backend has accepted to display the layer. If false, the
|
||||||
|
* compositor needs to manually render the layer. After each output commit,
|
||||||
|
* the backend will update this field. */
|
||||||
|
bool accepted;
|
||||||
|
|
||||||
|
struct wlr_output_layer_state current, pending;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new output layer.
|
||||||
|
*/
|
||||||
|
struct wlr_output_layer *wlr_output_layer_create(struct wlr_output *output);
|
||||||
|
/**
|
||||||
|
* Remove the output layer. This operation is double-buffered, see
|
||||||
|
* wlr_output_commit.
|
||||||
|
*
|
||||||
|
* Callers must not access the wlr_output_layer after calling this function.
|
||||||
|
*/
|
||||||
|
void wlr_output_layer_remove(struct wlr_output_layer *layer);
|
||||||
|
/**
|
||||||
|
* Attach a buffer to the layer. This operation is double-buffered, see
|
||||||
|
* wlr_output_commit.
|
||||||
|
*/
|
||||||
|
void wlr_output_layer_attach_buffer(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_buffer *buffer);
|
||||||
|
/**
|
||||||
|
* Set the position of the layer relative to the output. The coordinates are
|
||||||
|
* given in output-buffer-local coordinates. This operation is double-buffered,
|
||||||
|
* see wlr_output_commit.
|
||||||
|
*/
|
||||||
|
void wlr_output_layer_move(struct wlr_output_layer *layer, int x, int y);
|
||||||
|
/**
|
||||||
|
* Move the layer right above the specified sibling. This operation is
|
||||||
|
* double-buffered, see wlr_output_commit.
|
||||||
|
*/
|
||||||
|
void wlr_output_layer_place_above(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output_layer *sibling);
|
||||||
|
/**
|
||||||
|
* Move the layer right below the specified sibling. This operation is
|
||||||
|
* double-buffered, see wlr_output_commit.
|
||||||
|
*/
|
||||||
|
void wlr_output_layer_place_below(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output_layer *sibling);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -45,6 +45,7 @@ wlr_files += files(
|
||||||
'wlr_matrix.c',
|
'wlr_matrix.c',
|
||||||
'wlr_output_damage.c',
|
'wlr_output_damage.c',
|
||||||
'wlr_output_layout.c',
|
'wlr_output_layout.c',
|
||||||
|
'wlr_output_layer.c',
|
||||||
'wlr_output_management_v1.c',
|
'wlr_output_management_v1.c',
|
||||||
'wlr_output_power_management_v1.c',
|
'wlr_output_power_management_v1.c',
|
||||||
'wlr_output.c',
|
'wlr_output.c',
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#include <wlr/util/region.h>
|
#include <wlr/util/region.h>
|
||||||
#include "util/global.h"
|
#include "util/global.h"
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
#include "types/wlr_output_layer.h"
|
||||||
|
|
||||||
#define OUTPUT_VERSION 3
|
#define OUTPUT_VERSION 3
|
||||||
|
|
||||||
|
|
@ -340,6 +341,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
||||||
wl_signal_init(&output->events.description);
|
wl_signal_init(&output->events.description);
|
||||||
wl_signal_init(&output->events.destroy);
|
wl_signal_init(&output->events.destroy);
|
||||||
pixman_region32_init(&output->pending.damage);
|
pixman_region32_init(&output->pending.damage);
|
||||||
|
wl_list_init(&output->layers);
|
||||||
|
wl_list_init(&output->pending.layers);
|
||||||
|
|
||||||
const char *no_hardware_cursors = getenv("WLR_NO_HARDWARE_CURSORS");
|
const char *no_hardware_cursors = getenv("WLR_NO_HARDWARE_CURSORS");
|
||||||
if (no_hardware_cursors != NULL && strcmp(no_hardware_cursors, "1") == 0) {
|
if (no_hardware_cursors != NULL && strcmp(no_hardware_cursors, "1") == 0) {
|
||||||
|
|
@ -493,6 +496,42 @@ static void output_pending_resolution(struct wlr_output *output, int *width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void output_commit_layers(struct wlr_output *output) {
|
||||||
|
if (output->pending.committed & WLR_OUTPUT_STATE_LAYERS) {
|
||||||
|
// Update the layer ordering in the current output state
|
||||||
|
struct wlr_output_layer *layer;
|
||||||
|
wl_list_for_each(layer, &output->pending.layers, pending.link) {
|
||||||
|
wl_list_remove(&layer->current.link);
|
||||||
|
wl_list_insert(output->layers.prev, &layer->current.link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_output_layer *layer, *tmp;
|
||||||
|
wl_list_for_each_safe(layer, tmp, &output->layers, current.link) {
|
||||||
|
if (wl_list_empty(&layer->pending.link)) {
|
||||||
|
output_layer_destroy(layer);
|
||||||
|
} else {
|
||||||
|
output_layer_state_move(&layer->current, &layer->pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void output_rollback_layers(struct wlr_output *output) {
|
||||||
|
if (output->pending.committed & WLR_OUTPUT_STATE_LAYERS) {
|
||||||
|
// Rollback the layer ordering in the pending output state
|
||||||
|
struct wlr_output_layer *layer;
|
||||||
|
wl_list_for_each(layer, &output->layers, current.link) {
|
||||||
|
wl_list_remove(&layer->pending.link);
|
||||||
|
wl_list_insert(output->pending.layers.prev, &layer->pending.link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_output_layer *layer, *tmp;
|
||||||
|
wl_list_for_each_safe(layer, tmp, &output->pending.layers, pending.link) {
|
||||||
|
output_layer_state_clear(&layer->pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool output_basic_test(struct wlr_output *output) {
|
static bool output_basic_test(struct wlr_output *output) {
|
||||||
if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
|
if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||||
if (output->frame_pending) {
|
if (output->frame_pending) {
|
||||||
|
|
@ -576,7 +615,7 @@ bool wlr_output_commit(struct wlr_output *output) {
|
||||||
wlr_signal_emit_safe(&output->events.precommit, &event);
|
wlr_signal_emit_safe(&output->events.precommit, &event);
|
||||||
|
|
||||||
if (!output->impl->commit(output)) {
|
if (!output->impl->commit(output)) {
|
||||||
output_state_clear(&output->pending);
|
wlr_output_rollback(output);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -626,11 +665,13 @@ bool wlr_output_commit(struct wlr_output *output) {
|
||||||
output->needs_frame = false;
|
output->needs_frame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output_commit_layers(output);
|
||||||
output_state_clear(&output->pending);
|
output_state_clear(&output->pending);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_output_rollback(struct wlr_output *output) {
|
void wlr_output_rollback(struct wlr_output *output) {
|
||||||
|
output_rollback_layers(output);
|
||||||
output_state_clear(&output->pending);
|
output_state_clear(&output->pending);
|
||||||
|
|
||||||
if (output->impl->rollback) {
|
if (output->impl->rollback) {
|
||||||
|
|
|
||||||
130
types/wlr_output_layer.c
Normal file
130
types/wlr_output_layer.c
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
|
#include <wlr/types/wlr_output.h>
|
||||||
|
#include <wlr/types/wlr_output_layer.h>
|
||||||
|
#include "types/wlr_output_layer.h"
|
||||||
|
|
||||||
|
struct wlr_output_layer *wlr_output_layer_create(struct wlr_output *output) {
|
||||||
|
if (output->impl->create_layer) {
|
||||||
|
return output->impl->create_layer(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_output_layer *layer = calloc(1, sizeof(*layer));
|
||||||
|
if (layer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
wlr_output_layer_init(layer, output);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_init(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output *output) {
|
||||||
|
layer->output = output;
|
||||||
|
wl_list_insert(output->layers.prev, &layer->current.link);
|
||||||
|
wl_list_insert(output->pending.layers.prev, &layer->pending.link);
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_LINK;
|
||||||
|
output->pending.committed |= WLR_OUTPUT_STATE_LAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_layer_destroy(struct wlr_output_layer *layer) {
|
||||||
|
output_layer_state_clear(&layer->current);
|
||||||
|
output_layer_state_clear(&layer->pending);
|
||||||
|
|
||||||
|
wl_list_remove(&layer->current.link);
|
||||||
|
wl_list_remove(&layer->pending.link);
|
||||||
|
|
||||||
|
if (layer->output->impl->destroy_layer) {
|
||||||
|
layer->output->impl->destroy_layer(layer);
|
||||||
|
} else {
|
||||||
|
free(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_remove(struct wlr_output_layer *layer) {
|
||||||
|
wlr_output_layer_attach_buffer(layer, NULL);
|
||||||
|
|
||||||
|
wl_list_remove(&layer->pending.link);
|
||||||
|
wl_list_init(&layer->pending.link);
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_LINK;
|
||||||
|
layer->output->pending.committed |= WLR_OUTPUT_STATE_LAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_attach_buffer(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_buffer *buffer) {
|
||||||
|
if (buffer == layer->current.buffer) {
|
||||||
|
layer->pending.committed &= ~WLR_OUTPUT_LAYER_STATE_BUFFER;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_buffer_unlock(layer->pending.buffer);
|
||||||
|
layer->pending.buffer = NULL;
|
||||||
|
|
||||||
|
if (buffer == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer->pending.buffer = wlr_buffer_lock(buffer);
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_move(struct wlr_output_layer *layer, int x, int y) {
|
||||||
|
if (x == layer->current.x && y == layer->current.y) {
|
||||||
|
layer->pending.committed &= ~WLR_OUTPUT_LAYER_STATE_POSITION;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer->pending.x = x;
|
||||||
|
layer->pending.y = y;
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_place_above(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output_layer *sibling) {
|
||||||
|
assert(layer->output == sibling->output);
|
||||||
|
|
||||||
|
wl_list_remove(&layer->pending.link);
|
||||||
|
wl_list_insert(&sibling->pending.link, &layer->pending.link);
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_LINK;
|
||||||
|
layer->output->pending.committed |= WLR_OUTPUT_STATE_LAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_output_layer_place_below(struct wlr_output_layer *layer,
|
||||||
|
struct wlr_output_layer *sibling) {
|
||||||
|
assert(layer->output == sibling->output);
|
||||||
|
|
||||||
|
wl_list_remove(&layer->pending.link);
|
||||||
|
wl_list_insert(sibling->pending.link.prev, &layer->pending.link);
|
||||||
|
layer->pending.committed |= WLR_OUTPUT_LAYER_STATE_LINK;
|
||||||
|
layer->output->pending.committed |= WLR_OUTPUT_STATE_LAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void output_layer_state_copy(struct wlr_output_layer_state *dst,
|
||||||
|
struct wlr_output_layer_state *src) {
|
||||||
|
// link has already been taken care of
|
||||||
|
if (src->committed & WLR_OUTPUT_LAYER_STATE_BUFFER) {
|
||||||
|
wlr_buffer_unlock(dst->buffer);
|
||||||
|
if (src->buffer != NULL) {
|
||||||
|
dst->buffer = wlr_buffer_lock(src->buffer);
|
||||||
|
} else {
|
||||||
|
dst->buffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (src->committed & WLR_OUTPUT_LAYER_STATE_POSITION) {
|
||||||
|
dst->x = src->x;
|
||||||
|
dst->y = src->y;
|
||||||
|
}
|
||||||
|
dst->committed |= src->committed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_layer_state_clear(struct wlr_output_layer_state *state) {
|
||||||
|
wlr_buffer_unlock(state->buffer);
|
||||||
|
state->buffer = NULL;
|
||||||
|
state->committed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void output_layer_state_move(struct wlr_output_layer_state *dst,
|
||||||
|
struct wlr_output_layer_state *src) {
|
||||||
|
output_layer_state_copy(dst, src);
|
||||||
|
output_layer_state_clear(src);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue