Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Make wlr_output_enable idempotent #3306

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d1b7567
ci: add .gitlab-ci.yml
emersion Nov 1, 2021
8bc1086
s/GitHub/GitLab/
emersion Nov 1, 2021
760e166
render: completely disable gles2 if requested but libEGL is found
jbeich Oct 5, 2021
3e801d6
xwayland: add support for -noTouchPointerEmulation
emersion Oct 22, 2021
2ff4e11
backend/session: introduce wlr_device_change_event
emersion Jun 9, 2021
e13f3f8
backend/drm: handle per-connector hotplug events
emersion Jun 9, 2021
8634dd3
output: fix leak of wlr_drm_format
ifreund Nov 6, 2021
fc1ed72
CONTRIBUTING.md: add CoC section
Nov 6, 2021
eb5f23d
scene: fix calloc size mismatch
emersion Nov 7, 2021
e326b76
text-input/input-method: handle strdup() failure
ifreund Nov 7, 2021
f20c49d
export-dmabuf-v1: stop using wlr_output_export_dmabuf
emersion Nov 5, 2021
fa77aeb
screencopy-v1: stop using wlr_output_export_dmabuf
emersion Nov 5, 2021
76bab68
output: drop wlr_output_export_dmabuf
emersion Nov 5, 2021
ab16861
text-input: fix type of send_preedit_string() args
ifreund Nov 7, 2021
02a1ae1
render/allocator: make wlr_allocator part of the public API
bl4ckb0ne Nov 9, 2021
3a685b1
egl: use alts for EGL_EXT_device_enum, if missing
colemickens Nov 10, 2021
4a8e681
util/token: don't leak /dev/urandom fd to children
raphaelr Nov 11, 2021
8274c85
backend/headless: unlink input device on destroy
romangg Nov 14, 2021
9a4e109
linux-dmabuf-v1: properly validate flags
emersion Nov 16, 2021
a04cfca
Remove support for DMA-BUF flags
emersion Nov 16, 2021
b5d4bc3
Improve wlr_drm_format documentation
DemiMarie Nov 15, 2021
142d10e
output: add wlr_output_init_render
emersion Nov 5, 2021
6d6e70b
examples: init wlr_output with allocator and renderer
bl4ckb0ne Sep 24, 2021
a6538ce
tinywl: autocreate allocator and init output
bl4ckb0ne Nov 15, 2021
0c76aef
backend: remove backend ensure renderer and allocator check
bl4ckb0ne Nov 15, 2021
6dc6af1
backend: remove backend_get_allocator
bl4ckb0ne Nov 16, 2021
d07c87f
types/wlr_screencopy_v1: use renderer from output
bl4ckb0ne Nov 15, 2021
5a98eae
types/wlr_scene: use renderer from wlr_output
bl4ckb0ne Nov 15, 2021
5f11198
backend/x11: get renderer from wlr_x11_output
bl4ckb0ne Nov 15, 2021
a143093
backend/headless: don't store the parent renderer
bl4ckb0ne Nov 15, 2021
42549a1
backend/drm: stop initializing backend renderer
bl4ckb0ne Nov 15, 2021
d1ebd52
backend/multi: remove backend_get_renderer
bl4ckb0ne Nov 15, 2021
fdf3169
backend: remove wlr_backend_get_renderer
bl4ckb0ne Nov 15, 2021
7375cfa
Make wlr_output_enable idempotent
DemiMarie Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .builds/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ packages:
- xwayland
- libseat-dev
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- setup: |
cd wlroots
Expand Down
2 changes: 1 addition & 1 deletion .builds/archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packages:
- vulkan-headers
- glslang
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- setup: |
cd wlroots
Expand Down
2 changes: 1 addition & 1 deletion .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packages:
- sysutils/seatd
- gmake
sources:
- https://github.com/swaywm/wlroots
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- wlroots: |
cd wlroots
Expand Down
7 changes: 7 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include: https://git.sr.ht/~emersion/dalligi/blob/master/templates/multi.yml
alpine:
extends: .dalligi
archlinux:
extends: .dalligi
freebsd:
extends: .dalligi
40 changes: 24 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Contributing to wlroots

Contributing just involves sending a pull request. You will probably be more
Contributing just involves sending a merge request. You will probably be more
successful with your contribution if you visit [#sway-devel on Libera Chat]
upfront and discuss your plans.

Note: rules are made to be broken. Adjust or ignore any/all of these as you see
fit, but be prepared to justify it to your peers.

## Pull Requests
## Merge Requests

If you already have your own pull request habits, feel free to use them. If you
If you already have your own merge request habits, feel free to use them. If you
don't, however, allow me to make a suggestion: feature branches pulled from
upstream. Try this:

1. Fork wlroots
2. `git clone git@github.com:<username>/wlroots.git && cd wlroots`
3. `git remote add upstream https://github.com/swaywm/wlroots`
2. `git clone git@gitlab.freedesktop.org:<username>/wlroots.git && cd wlroots`
3. `git remote add upstream https://gitlab.freedesktop.org/wlroots/wlroots.git`

You only need to do this once. You're never going to use your fork's master
branch. Instead, when you start working on a feature, do this:
Expand All @@ -24,11 +24,11 @@ branch. Instead, when you start working on a feature, do this:
2. `git checkout -b add-so-and-so-feature upstream/master`
3. Add and commit your changes
4. `git push -u origin add-so-and-so-feature`
5. Make a pull request from your feature branch
5. Make a merge request from your feature branch

When you submit your pull request, your commit log should do most of the talking
When you submit your merge request, your commit log should do most of the talking
when it comes to describing your changes and their motivation. In addition to
this, your pull request's comments will ideally include a test plan that the
this, your merge request's comments will ideally include a test plan that the
reviewers can use to (1) demonstrate the problem on master, if applicable and
(2) verify that the problem no longer exists with your changes applied (or that
your new features work correctly). Document all of the edge cases you're aware
Expand Down Expand Up @@ -80,15 +80,15 @@ cmd_move"* or *"Improve performance of arrange_windows on ARM"* or similar.

The subsequent lines should be separated from the subject line by a single
blank line, and include optional details. In this you can give justification
for the change, [reference Github issues], or explain some of the subtler
for the change, [reference issues], or explain some of the subtler
details of your patch. This is important because when someone finds a line of
code they don't understand later, they can use the `git blame` command to find
out what the author was thinking when they wrote it. It's also easier to review
your pull requests if they're separated into logical commits that have good
your merge requests if they're separated into logical commits that have good
commit messages and justify themselves in the extended commit description.

As a good rule of thumb, anything you might put into the pull request
description on Github is probably fair game for going into the extended commit
As a good rule of thumb, anything you might put into the merge request
description on GitLab is probably fair game for going into the extended commit
message as well.

See [How to Write a Git Commit Message] for more details.
Expand All @@ -101,18 +101,25 @@ changes will typically see review from several people. Be prepared to receive
some feedback - you may be asked to make changes to your work. Our code review
process is:

1. **Triage** the pull request. Do the commit messages make sense? Is a test
1. **Triage** the merge request. Do the commit messages make sense? Is a test
plan necessary and/or present? Add anyone as reviewers that you think should
be there (using the relevant GitHub feature, if you have the permissions, or
be there (using the relevant GitLab feature, if you have the permissions, or
with an @mention if necessary).
2. **Review** the code. Look for code style violations, naming convention
violations, buffer overflows, memory leaks, logic errors, non-portable code
(including GNU-isms), etc. For significant changes to the public API, loop in
a couple more people for discussion.
3. **Execute** the test plan, if present.
4. **Merge** the pull request when all reviewers approve.
4. **Merge** the merge request when all reviewers approve.
5. **File** follow-up tickets if appropriate.

## Code of Conduct

Note that as a project hosted on freedesktop.org, wlroots follows its
[Code of Conduct], based on the Contributor Covenant. Please conduct yourself
in a respectful and civilized manner when communicating with community members
on IRC and bug tracker.

## Style Reference

wlroots is written in C with a style similar to the [kernel style], but with a
Expand Down Expand Up @@ -396,6 +403,7 @@ static void subsurface_handle_surface_destroy(struct wl_listener *listener,
[#sway-devel on Libera Chat]: https://web.libera.chat/gamja/?channels=#sway-devel
[linear, "recipe" style]: https://www.bitsnbites.eu/git-history-work-log-vs-recipe/
[git-rebase.io]: https://git-rebase.io/
[reference Github issues]: https://help.github.com/articles/closing-issues-via-commit-messages/
[reference issues]: https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically
[Code of Conduct]: https://www.freedesktop.org/wiki/CodeOfConduct/
[How to Write a Git Commit Message]: https://chris.beams.io/posts/git-commit/
[kernel style]: https://www.kernel.org/doc/Documentation/process/coding-style.rst
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Install like so:
See [CONTRIBUTING.md].

[Wayland]: https://wayland.freedesktop.org/
[wiki]: https://github.com/swaywm/wlroots/wiki/Getting-started
[wiki]: https://gitlab.freedesktop.org/wlroots/wlroots/-/wikis/Getting-started
[#sway-devel on Libera Chat]: https://web.libera.chat/gamja/?channels=#sway-devel
[Sway]: https://github.com/swaywm/sway
[wrapper libraries]: https://github.com/search?q=topic%3Abindings+org%3Aswaywm&type=Repositories
[libseat]: https://git.sr.ht/~kennylevinsen/seatd
[CONTRIBUTING.md]: https://github.com/swaywm/wlroots/blob/master/CONTRIBUTING.md
[CONTRIBUTING.md]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/CONTRIBUTING.md
74 changes: 4 additions & 70 deletions backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ void wlr_backend_init(struct wlr_backend *backend,

void wlr_backend_finish(struct wlr_backend *backend) {
wlr_signal_emit_safe(&backend->events.destroy, backend);
wlr_allocator_destroy(backend->allocator);
if (backend->has_own_renderer) {
wlr_renderer_destroy(backend->renderer);
}
}

bool wlr_backend_start(struct wlr_backend *backend) {
Expand All @@ -70,36 +66,6 @@ void wlr_backend_destroy(struct wlr_backend *backend) {
}
}

static bool backend_create_renderer(struct wlr_backend *backend) {
if (backend->renderer != NULL) {
return true;
}

backend->renderer = wlr_renderer_autocreate(backend);
if (backend->renderer == NULL) {
return false;
}

backend->has_own_renderer = true;
return true;
}

struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) {
if (backend->impl->get_renderer) {
return backend->impl->get_renderer(backend);
}
if (backend_get_buffer_caps(backend) != 0) {
// If the backend is capable of presenting buffers, automatically create
// the renderer if necessary.
if (!backend_create_renderer(backend)) {
wlr_log(WLR_ERROR, "Failed to create backend renderer");
return NULL;
}
return backend->renderer;
}
return NULL;
}

struct wlr_session *wlr_backend_get_session(struct wlr_backend *backend) {
if (backend->impl->get_session) {
return backend->impl->get_session(backend);
Expand Down Expand Up @@ -175,23 +141,6 @@ uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
return backend->impl->get_buffer_caps(backend);
}

struct wlr_allocator *backend_get_allocator(struct wlr_backend *backend) {
if (backend->allocator != NULL) {
return backend->allocator;
}

struct wlr_renderer *renderer = wlr_backend_get_renderer(backend);
if (renderer == NULL) {
return NULL;
}

backend->allocator = wlr_allocator_autocreate(backend, renderer);
if (backend->allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to create backend allocator");
}
return backend->allocator;
}

static size_t parse_outputs_env(const char *name) {
const char *outputs_str = getenv(name);
if (outputs_str == NULL) {
Expand All @@ -208,21 +157,6 @@ static size_t parse_outputs_env(const char *name) {
return outputs;
}

static struct wlr_backend *ensure_backend_renderer_and_allocator(
struct wlr_backend *backend) {
struct wlr_renderer *renderer = wlr_backend_get_renderer(backend);
if (renderer == NULL) {
wlr_backend_destroy(backend);
return NULL;
}
struct wlr_allocator *allocator = backend_get_allocator(backend);
if (allocator == NULL) {
wlr_backend_destroy(backend);
return NULL;
}
return backend;
}

static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
struct wlr_backend *backend = wlr_wl_backend_create(display, NULL);
if (backend == NULL) {
Expand All @@ -234,7 +168,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
wlr_wl_output_create(backend);
}

return ensure_backend_renderer_and_allocator(backend);
return backend;
}

#if WLR_HAS_X11_BACKEND
Expand All @@ -250,7 +184,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
wlr_x11_output_create(backend);
}

return ensure_backend_renderer_and_allocator(backend);
return backend;
}
#endif

Expand All @@ -266,7 +200,7 @@ static struct wlr_backend *attempt_headless_backend(
wlr_headless_add_output(backend, 1280, 720);
}

return ensure_backend_renderer_and_allocator(backend);
return backend;
}

static struct wlr_backend *attempt_noop_backend(struct wl_display *display) {
Expand Down Expand Up @@ -320,7 +254,7 @@ static struct wlr_backend *attempt_drm_backend(struct wl_display *display,
return NULL;
}

return ensure_backend_renderer_and_allocator(primary_drm);
return backend;
}
#endif

Expand Down
20 changes: 12 additions & 8 deletions backend/drm/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct wlr_drm_backend *get_drm_backend_from_backend(

static bool backend_start(struct wlr_backend *backend) {
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
scan_drm_connectors(drm);
scan_drm_connectors(drm, NULL);
return true;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ static void handle_session_active(struct wl_listener *listener, void *data) {

if (session->active) {
wlr_log(WLR_INFO, "DRM fd resumed");
scan_drm_connectors(drm);
scan_drm_connectors(drm, NULL);

struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link) {
Expand All @@ -127,13 +127,21 @@ static void handle_session_active(struct wl_listener *listener, void *data) {

static void handle_dev_change(struct wl_listener *listener, void *data) {
struct wlr_drm_backend *drm = wl_container_of(listener, drm, dev_change);
struct wlr_device_change_event *change = data;

if (!drm->session->active) {
return;
}

wlr_log(WLR_DEBUG, "%s invalidated", drm->name);
scan_drm_connectors(drm);
// TODO: add and handle lease uevents
switch (change->type) {
case WLR_DEVICE_HOTPLUG:;
wlr_log(WLR_DEBUG, "Received hotplug event for %s", drm->name);
scan_drm_connectors(drm, &change->hotplug);
break;
default:
wlr_log(WLR_DEBUG, "Received unknown change event for %s", drm->name);
}
}

static void handle_dev_remove(struct wl_listener *listener, void *data) {
Expand Down Expand Up @@ -224,10 +232,6 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
}

if (drm->parent) {
// Ensure we use the same renderer as the parent backend
drm->backend.renderer = wlr_backend_get_renderer(&drm->parent->backend);
assert(drm->backend.renderer != NULL);

if (!init_drm_renderer(drm, &drm->mgpu_renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
goto error_resources;
Expand Down
39 changes: 28 additions & 11 deletions backend/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,8 @@ static uint32_t get_possible_crtcs(int fd, const drmModeConnector *conn) {

static void disconnect_drm_connector(struct wlr_drm_connector *conn);

void scan_drm_connectors(struct wlr_drm_backend *drm) {
void scan_drm_connectors(struct wlr_drm_backend *drm,
struct wlr_device_hotplug_event *event) {
/*
* This GPU is not really a modesetting device.
* It's just being used as a renderer.
Expand All @@ -1186,7 +1187,12 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
return;
}

wlr_log(WLR_INFO, "Scanning DRM connectors on %s", drm->name);
if (event != NULL && event->connector_id != 0) {
wlr_log(WLR_INFO, "Scanning DRM connector %"PRIu32" on %s",
event->connector_id, drm->name);
} else {
wlr_log(WLR_INFO, "Scanning DRM connectors on %s", drm->name);
}

drmModeRes *res = drmModeGetResources(drm->fd);
if (!res) {
Expand All @@ -1203,25 +1209,36 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
struct wlr_drm_connector *new_outputs[res->count_connectors + 1];

for (int i = 0; i < res->count_connectors; ++i) {
drmModeConnector *drm_conn = drmModeGetConnector(drm->fd,
res->connectors[i]);
if (!drm_conn) {
wlr_log_errno(WLR_ERROR, "Failed to get DRM connector");
continue;
}
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
uint32_t conn_id = res->connectors[i];

ssize_t index = -1;
struct wlr_drm_connector *c, *wlr_conn = NULL;
wl_list_for_each(c, &drm->outputs, link) {
index++;
if (c->id == drm_conn->connector_id) {
if (c->id == conn_id) {
wlr_conn = c;
break;
}
}

// If the hotplug event contains a connector ID, ignore any other
// connector.
if (event != NULL && event->connector_id != 0 &&
event->connector_id != conn_id) {
if (wlr_conn != NULL) {
seen[index] = true;
}
continue;
}

drmModeConnector *drm_conn = drmModeGetConnector(drm->fd, conn_id);
if (!drm_conn) {
wlr_log_errno(WLR_ERROR, "Failed to get DRM connector");
continue;
}
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);

if (!wlr_conn) {
wlr_conn = calloc(1, sizeof(*wlr_conn));
if (!wlr_conn) {
Expand Down
Loading