backend/headless: add assertions

This commit is contained in:
emersion 2018-09-17 21:46:39 +02:00
parent 9288c827aa
commit bc34486c04
4 changed files with 30 additions and 13 deletions

View File

@ -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);

View File

@ -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));

View File

@ -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));

View File

@ -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