aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-09-17 21:46:39 +0200
committeremersion <contact@emersion.fr>2018-09-18 11:01:53 +0200
commitbc34486c04a035079ea808532f311a02659642c1 (patch)
treea1d2b2539615408ddbc76be0fa8e876f577a1050
parent9288c827aaf4ae8acac7a105f223dc612822b76d (diff)
backend/headless: add assertions
-rw-r--r--backend/headless/backend.c20
-rw-r--r--backend/headless/input_device.c3
-rw-r--r--backend/headless/output.c17
-rw-r--r--include/backend/headless.h3
4 files changed, 30 insertions, 13 deletions
diff --git a/backend/headless/backend.c b/backend/headless/backend.c
index 0138166d..cbc158f3 100644
--- a/backend/headless/backend.c
+++ b/backend/headless/backend.c
@@ -1,4 +1,4 @@
-#include "util/signal.h"
+#include <assert.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_output.h>
@@ -7,10 +7,17 @@
#include <wlr/util/log.h>
#include "backend/headless.h"
#include "glapi.h"
+#include "util/signal.h"
+
+struct wlr_headless_backend *headless_backend_from_backend(
+ struct wlr_backend *wlr_backend) {
+ assert(wlr_backend_is_headless(wlr_backend));
+ return (struct wlr_headless_backend *)wlr_backend;
+}
static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend =
- (struct wlr_headless_backend *)wlr_backend;
+ headless_backend_from_backend(wlr_backend);
wlr_log(WLR_INFO, "Starting headless backend");
struct wlr_headless_output *output;
@@ -34,7 +41,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
static void backend_destroy(struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend =
- (struct wlr_headless_backend *)wlr_backend;
+ headless_backend_from_backend(wlr_backend);
if (!wlr_backend) {
return;
}
@@ -62,7 +69,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *wlr_backend) {
struct wlr_headless_backend *backend =
- (struct wlr_headless_backend *)wlr_backend;
+ headless_backend_from_backend(wlr_backend);
return backend->renderer;
}
@@ -107,9 +114,8 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display,
create_renderer_func = wlr_renderer_autocreate;
}
- backend->renderer = create_renderer_func(&backend->egl, EGL_PLATFORM_SURFACELESS_MESA,
- NULL, (EGLint*)config_attribs, 0);
-
+ backend->renderer = create_renderer_func(&backend->egl,
+ EGL_PLATFORM_SURFACELESS_MESA, NULL, (EGLint*)config_attribs, 0);
if (!backend->renderer) {
wlr_log(WLR_ERROR, "Failed to create renderer");
free(backend);
diff --git a/backend/headless/input_device.c b/backend/headless/input_device.c
index a2474aeb..ba251dd7 100644
--- a/backend/headless/input_device.c
+++ b/backend/headless/input_device.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
@@ -18,7 +19,7 @@ bool wlr_input_device_is_headless(struct wlr_input_device *wlr_dev) {
struct wlr_input_device *wlr_headless_add_input_device(
struct wlr_backend *wlr_backend, enum wlr_input_device_type type) {
struct wlr_headless_backend *backend =
- (struct wlr_headless_backend *)wlr_backend;
+ headless_backend_from_backend(wlr_backend);
struct wlr_headless_input_device *device =
calloc(1, sizeof(struct wlr_headless_input_device));
diff --git a/backend/headless/output.c b/backend/headless/output.c
index 24fc3bfd..143900d4 100644
--- a/backend/headless/output.c
+++ b/backend/headless/output.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <stdlib.h>
@@ -7,6 +8,12 @@
#include "backend/headless.h"
#include "util/signal.h"
+static struct wlr_headless_output *headless_output_from_output(
+ struct wlr_output *wlr_output) {
+ assert(wlr_output_is_headless(wlr_output));
+ return (struct wlr_headless_output *)wlr_output;
+}
+
static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width,
unsigned int height) {
EGLint attribs[] = {EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE};
@@ -22,7 +29,7 @@ static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width,
static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
int32_t height, int32_t refresh) {
struct wlr_headless_output *output =
- (struct wlr_headless_output *)wlr_output;
+ headless_output_from_output(wlr_output);
struct wlr_headless_backend *backend = output->backend;
if (refresh <= 0) {
@@ -47,13 +54,13 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
static void output_transform(struct wlr_output *wlr_output,
enum wl_output_transform transform) {
struct wlr_headless_output *output =
- (struct wlr_headless_output *)wlr_output;
+ headless_output_from_output(wlr_output);
output->wlr_output.transform = transform;
}
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
struct wlr_headless_output *output =
- (struct wlr_headless_output *)wlr_output;
+ headless_output_from_output(wlr_output);
return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
buffer_age);
}
@@ -65,7 +72,7 @@ static bool output_swap_buffers(struct wlr_output *wlr_output,
static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_headless_output *output =
- (struct wlr_headless_output *)wlr_output;
+ headless_output_from_output(wlr_output);
wl_list_remove(&output->link);
@@ -97,7 +104,7 @@ static int signal_frame(void *data) {
struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
unsigned int width, unsigned int height) {
struct wlr_headless_backend *backend =
- (struct wlr_headless_backend *)wlr_backend;
+ headless_backend_from_backend(wlr_backend);
struct wlr_headless_output *output =
calloc(1, sizeof(struct wlr_headless_output));
diff --git a/include/backend/headless.h b/include/backend/headless.h
index add4c4e8..35280862 100644
--- a/include/backend/headless.h
+++ b/include/backend/headless.h
@@ -34,4 +34,7 @@ struct wlr_headless_input_device {
struct wlr_headless_backend *backend;
};
+struct wlr_headless_backend *headless_backend_from_backend(
+ struct wlr_backend *wlr_backend);
+
#endif