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

Commit 2f61546

Browse files
emersionkennylevinsen
authored andcommitted
backend: add output state allow-lists
Right now, when a new output state field is added, all backends by default won't reject it. This means we need to add new checks to each and every backend when we introduce a new state field. Instead, introduce a bitmask of supported output state fields in each backend, and error out if the user has submitted an unknown field. Some fields don't need any backend involvment to work. These are listed in WLR_OUTPUT_STATE_BACKEND_OPTIONAL as a convenience.
1 parent 15c8453 commit 2f61546

File tree

6 files changed

+63
-8
lines changed

6 files changed

+63
-8
lines changed

backend/drm/drm.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include "types/wlr_buffer.h"
3232
#include "util/signal.h"
3333

34+
static const uint32_t SUPPORTED_OUTPUT_STATE =
35+
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
36+
WLR_OUTPUT_STATE_BUFFER |
37+
WLR_OUTPUT_STATE_MODE |
38+
WLR_OUTPUT_STATE_ENABLED |
39+
WLR_OUTPUT_STATE_GAMMA_LUT;
40+
3441
bool check_drm_features(struct wlr_drm_backend *drm) {
3542
if (drmGetCap(drm->fd, DRM_CAP_CURSOR_WIDTH, &drm->cursor_width)) {
3643
drm->cursor_width = 64;
@@ -435,6 +442,13 @@ static bool drm_connector_test(struct wlr_output *output) {
435442
return false;
436443
}
437444

445+
uint32_t unsupported = output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
446+
if (unsupported != 0) {
447+
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
448+
unsupported);
449+
return false;
450+
}
451+
438452
if ((output->pending.committed & WLR_OUTPUT_STATE_ENABLED) &&
439453
output->pending.enabled) {
440454
if (output->current_mode == NULL &&

backend/headless/output.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#include "backend/headless.h"
88
#include "util/signal.h"
99

10+
static const uint32_t SUPPORTED_OUTPUT_STATE =
11+
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
12+
WLR_OUTPUT_STATE_BUFFER |
13+
WLR_OUTPUT_STATE_MODE;
14+
1015
static struct wlr_headless_output *headless_output_from_output(
1116
struct wlr_output *wlr_output) {
1217
assert(wlr_output_is_headless(wlr_output));
@@ -29,8 +34,11 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
2934
}
3035

3136
static bool output_test(struct wlr_output *wlr_output) {
32-
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
33-
wlr_log(WLR_DEBUG, "Cannot disable a headless output");
37+
uint32_t unsupported =
38+
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
39+
if (unsupported != 0) {
40+
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
41+
unsupported);
3442
return false;
3543
}
3644

backend/noop/output.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "backend/noop.h"
77
#include "util/signal.h"
88

9+
static const uint32_t SUPPORTED_OUTPUT_STATE =
10+
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
11+
WLR_OUTPUT_STATE_MODE;
12+
913
static struct wlr_noop_output *noop_output_from_output(
1014
struct wlr_output *wlr_output) {
1115
assert(wlr_output_is_noop(wlr_output));
@@ -22,8 +26,11 @@ static void output_rollback_render(struct wlr_output *wlr_output) {
2226
}
2327

2428
static bool output_commit(struct wlr_output *wlr_output) {
25-
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
26-
wlr_log(WLR_DEBUG, "Cannot disable a noop output");
29+
uint32_t unsupported =
30+
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
31+
if (unsupported != 0) {
32+
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
33+
unsupported);
2734
return false;
2835
}
2936

backend/wayland/output.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include "xdg-decoration-unstable-v1-client-protocol.h"
2828
#include "xdg-shell-client-protocol.h"
2929

30+
static const uint32_t SUPPORTED_OUTPUT_STATE =
31+
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
32+
WLR_OUTPUT_STATE_BUFFER |
33+
WLR_OUTPUT_STATE_MODE;
34+
3035
static struct wlr_wl_output *get_wl_output_from_output(
3136
struct wlr_output *wlr_output) {
3237
assert(wlr_output_is_wl(wlr_output));
@@ -244,8 +249,11 @@ static bool output_test(struct wlr_output *wlr_output) {
244249
struct wlr_wl_output *output =
245250
get_wl_output_from_output(wlr_output);
246251

247-
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
248-
wlr_log(WLR_DEBUG, "Cannot disable a Wayland output");
252+
uint32_t unsupported =
253+
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
254+
if (unsupported != 0) {
255+
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
256+
unsupported);
249257
return false;
250258
}
251259

backend/x11/output.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include "util/signal.h"
2626
#include "util/time.h"
2727

28+
static const uint32_t SUPPORTED_OUTPUT_STATE =
29+
WLR_OUTPUT_STATE_BACKEND_OPTIONAL |
30+
WLR_OUTPUT_STATE_BUFFER |
31+
WLR_OUTPUT_STATE_MODE;
32+
2833
static void parse_xcb_setup(struct wlr_output *output,
2934
xcb_connection_t *xcb) {
3035
const xcb_setup_t *xcb_setup = xcb_get_setup(xcb);
@@ -94,8 +99,11 @@ static void output_destroy(struct wlr_output *wlr_output) {
9499
}
95100

96101
static bool output_test(struct wlr_output *wlr_output) {
97-
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_ENABLED) {
98-
wlr_log(WLR_DEBUG, "Cannot disable an X11 output");
102+
uint32_t unsupported =
103+
wlr_output->pending.committed & ~SUPPORTED_OUTPUT_STATE;
104+
if (unsupported != 0) {
105+
wlr_log(WLR_DEBUG, "Unsupported output state fields: 0x%"PRIx32,
106+
unsupported);
99107
return false;
100108
}
101109

include/wlr/interfaces/wlr_output.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
#include <wlr/types/wlr_box.h>
1515
#include <wlr/types/wlr_output.h>
1616

17+
/**
18+
* Output state fields that don't require backend support. Backends can ignore
19+
* them without breaking the API contract.
20+
*/
21+
#define WLR_OUTPUT_STATE_BACKEND_OPTIONAL \
22+
(WLR_OUTPUT_STATE_DAMAGE | \
23+
WLR_OUTPUT_STATE_SCALE | \
24+
WLR_OUTPUT_STATE_TRANSFORM | \
25+
WLR_OUTPUT_STATE_ADAPTIVE_SYNC_ENABLED)
26+
1727
/**
1828
* A backend implementation of wlr_output.
1929
*

0 commit comments

Comments
 (0)