Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Switch to wlr_output_layer
Browse files Browse the repository at this point in the history
See [1].

[1]: swaywm/wlroots#1985
  • Loading branch information
emersion committed Apr 9, 2020
1 parent cd65604 commit b24ac19
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 12 deletions.
72 changes: 72 additions & 0 deletions backend/connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ static void connector_set_crtc(struct glider_drm_connector *conn,

conn->crtc = crtc;
conn->props[GLIDER_DRM_CONNECTOR_CRTC_ID].pending = crtc ? crtc->id : 0;

// TODO: teardown and re-create all liftoff_layers
}

static bool connector_apply_props(struct glider_drm_connector *conn,
Expand All @@ -81,6 +83,42 @@ static bool connector_commit(struct glider_drm_connector *conn,
bool test_only) {
struct wlr_output_state *pending = &conn->output.pending;

struct glider_drm_layer *layer;
wl_list_for_each(layer, &pending->layers, base.pending.link) {
layer->base.accepted = false;

liftoff_layer_set_property(layer->liftoff, "zpos", 2); // TODO

if (layer->base.pending.committed & WLR_OUTPUT_LAYER_STATE_BUFFER) {
struct wlr_buffer *wlr_buffer = layer->base.pending.buffer;
if (wlr_buffer == NULL) {
// TODO
} else {
if (!glider_drm_connector_attach(&conn->output, wlr_buffer,
layer->liftoff)) {
liftoff_layer_set_fb_composited(layer->liftoff);
}
liftoff_layer_set_property(layer->liftoff,
"CRTC_W", wlr_buffer->width);
liftoff_layer_set_property(layer->liftoff,
"CRTC_H", wlr_buffer->height);
liftoff_layer_set_property(layer->liftoff, "SRC_X", 0);
liftoff_layer_set_property(layer->liftoff, "SRC_Y", 0);
liftoff_layer_set_property(layer->liftoff,
"SRC_W", wlr_buffer->width << 16);
liftoff_layer_set_property(layer->liftoff,
"SRC_H", wlr_buffer->height << 16);
}
}

if (layer->base.pending.committed & WLR_OUTPUT_LAYER_STATE_POSITION) {
liftoff_layer_set_property(layer->liftoff,
"CRTC_X", layer->base.pending.x);
liftoff_layer_set_property(layer->liftoff,
"CRTC_Y", layer->base.pending.y);
}
}

uint32_t flags = 0;
if (test_only) {
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
Expand Down Expand Up @@ -147,6 +185,14 @@ static bool connector_commit(struct glider_drm_connector *conn,
wlr_log(WLR_DEBUG, "Atomic commit failed: %s", strerror(-ret));
}

if (ret == 0) {
struct glider_drm_layer *layer;
wl_list_for_each(layer, &pending->layers, base.pending.link) {
layer->base.accepted =
liftoff_layer_get_plane_id(layer->liftoff) != 0;
}
}

if (flags & DRM_MODE_ATOMIC_TEST_ONLY) {
return ret == 0;
}
Expand Down Expand Up @@ -208,11 +254,37 @@ static void output_destroy(struct wlr_output *output) {
memset(&conn->output, 0, sizeof(struct wlr_output));
}

static struct wlr_output_layer *output_create_layer(struct wlr_output *output) {
struct glider_drm_connector *conn = get_drm_connector_from_output(output);

struct glider_drm_layer *layer = calloc(1, sizeof(*layer));
if (layer == NULL) {
return NULL;
}
wlr_output_layer_init(&layer->base, output);

layer->liftoff = liftoff_layer_create(conn->crtc->liftoff_output);
if (layer->liftoff == NULL) {
free(layer);
return NULL;
}

return &layer->base;
}

static void output_destroy_layer(struct wlr_output_layer *wlr_layer) {
struct glider_drm_layer *layer = (struct glider_drm_layer *)wlr_layer;
liftoff_layer_destroy(layer->liftoff);
free(layer);
}

static const struct wlr_output_impl output_impl = {
.attach_render = output_attach_render,
.test = output_test,
.commit = output_commit,
.destroy = output_destroy,
.create_layer = output_create_layer,
.destroy_layer = output_destroy_layer,
};

static uint32_t get_possible_crtcs(int drm_fd, drmModeConnector *conn) {
Expand Down
6 changes: 6 additions & 0 deletions include/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <wlr/backend/interface.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/drm_format_set.h>
#include <wlr/types/wlr_output_layer.h>
#include <xf86drmMode.h>
#include "allocator.h"

Expand Down Expand Up @@ -116,6 +117,11 @@ struct glider_drm_connector {
size_t modes_len;
};

struct glider_drm_layer {
struct wlr_output_layer base;
struct liftoff_layer *liftoff;
};

struct glider_drm_device {
struct glider_drm_backend *backend;
int fd;
Expand Down
2 changes: 1 addition & 1 deletion include/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
struct glider_surface_output {
struct glider_output *output;
struct glider_surface *surface;
struct liftoff_layer *layer;
struct wlr_output_layer *layer;
struct wl_list link; // glider_surface.outputs

struct wl_listener destroy;
Expand Down
8 changes: 6 additions & 2 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static bool output_needs_render(struct glider_output *output) {
wl_list_for_each(surface, &output->server->surfaces, link) {
struct glider_surface_output *so =
glider_surface_get_output(surface, output);
if (so != NULL && liftoff_layer_get_plane_id(so->layer) == 0) {
if (so != NULL && !so->layer->accepted) {
return true;
}
}
Expand All @@ -61,7 +61,7 @@ static bool output_render(struct glider_output *output,
wl_list_for_each(surface, &output->server->surfaces, link) {
struct glider_surface_output *so =
glider_surface_get_output(surface, output);
if (so == NULL || liftoff_layer_get_plane_id(so->layer) != 0) {
if (so == NULL || so->layer->accepted) {
continue;
}

Expand Down Expand Up @@ -180,6 +180,10 @@ void handle_new_output(struct wl_listener *listener, void *data) {
wl_container_of(listener, server, new_output);
struct wlr_output *wlr_output = data;

if (!wl_list_empty(&server->outputs)) {
return; // TODO
}

struct glider_output *output = calloc(1, sizeof(*output));
output->output = wlr_output;
output->server = server;
Expand Down
18 changes: 9 additions & 9 deletions xdg_shell.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <libliftoff.h>
#include <stdlib.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_output_layer.h>
#include "allocator.h"
#include "server.h"
#include "surface.h"
Expand All @@ -11,7 +12,7 @@ static void surface_output_destroy(struct glider_surface_output *so) {
}
wl_list_remove(&so->link);
wl_list_remove(&so->destroy.link);
liftoff_layer_destroy(so->layer);
wlr_output_layer_remove(so->layer);
free(so);
}

Expand All @@ -36,18 +37,17 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) {

static void handle_surface_commit(struct wl_listener *listener, void *data) {
struct glider_surface *surface = wl_container_of(listener, surface, commit);
struct wlr_client_buffer *buffer = surface->wlr_surface->buffer;
struct wlr_client_buffer *client_buffer = surface->wlr_surface->buffer;

if (buffer == NULL) {
return;
struct wlr_buffer *buffer = NULL;
if (client_buffer != NULL) {
buffer = &client_buffer->base;
}

struct glider_surface_output *so;
wl_list_for_each(so, &surface->outputs, link) {
liftoff_layer_set_fb_composited(so->layer);
liftoff_layer_set_property(so->layer, "zpos", 2);

glider_output_attach_buffer(so->output, &buffer->base, so->layer);
wlr_output_layer_attach_buffer(so->layer, buffer);
// TODO: set zpos
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
struct glider_surface_output *so = calloc(1, sizeof(*so));
so->output = output;
so->surface = surface;
so->layer = liftoff_layer_create(output->liftoff_output);
so->layer = wlr_output_layer_create(output->output);
wl_list_insert(&surface->outputs, &so->link);

so->destroy.notify = handle_output_destroy;
Expand Down

0 comments on commit b24ac19

Please sign in to comment.