From 3a5b150df21ee5b330130754b970a65de224c0fc Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 26 Sep 2017 16:04:07 +1300 Subject: [PATCH] Basic rendering --- backend/x11/backend.c | 67 ++++++++++++++++++++++++++++++++++++++++--- include/backend/x11.h | 15 +++++++++- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index b75f1f04e..587e5fdbc 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -1,11 +1,14 @@ #include +#include #include +#include +#include #include #include -#include #include #include #include +#include #include #include "backend/x11.h" @@ -20,7 +23,11 @@ int x11_event(int fd, uint32_t mask, void *data) { } switch (event->response_type) { + struct wlr_x11_output *output; + case XCB_EXPOSE: + output = &x11->output; + wl_signal_emit(&output->wlr_output.events.frame, output); break; case XCB_KEY_PRESS: break; @@ -80,8 +87,11 @@ error_x11: return NULL; } +static struct wlr_output_impl output_impl; + static bool wlr_x11_backend_start(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + struct wlr_x11_output *output = &x11->output; uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; uint32_t values[2] = { @@ -89,15 +99,27 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS }; - x11->win = xcb_generate_id(x11->xcb_conn); + output->x11 = x11; - xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, x11->win, x11->screen->root, + wlr_output_init(&output->wlr_output, &output_impl); + snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); + + output->win = xcb_generate_id(x11->xcb_conn); + xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, x11->screen->root_visual, mask, values); - xcb_map_window(x11->xcb_conn, x11->win); + output->surf = wlr_egl_create_surface(&x11->egl, &output->win); + if (!output->surf) { + wlr_log(L_ERROR, "Failed to create EGL surface"); + return false; + } + + xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); + wl_signal_emit(&x11->backend.events.output_add, output); + return true; } @@ -128,3 +150,40 @@ static struct wlr_backend_impl backend_impl = { .destroy = wlr_x11_backend_destroy, .get_egl = wlr_x11_backend_get_egl, }; + +static void output_transform(struct wlr_output *output, enum wl_output_transform transform) { + // TODO +} + +static void output_destroy(struct wlr_output *wlr_output) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + eglDestroySurface(x11->egl.display, output->surf); + xcb_destroy_window(x11->xcb_conn, output->win); +} + +static void output_make_current(struct wlr_output *wlr_output) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + if (!eglMakeCurrent(x11->egl.display, output->surf, output->surf, x11->egl.context)) { + wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); + } +} + +static void output_swap_buffers(struct wlr_output *wlr_output) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + if (!eglSwapBuffers(x11->egl.display, output->surf)) { + wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); + } +} + +static struct wlr_output_impl output_impl = { + .transform = output_transform, + .destroy = output_destroy, + .make_current = output_make_current, + .swap_buffers = output_swap_buffers, +}; diff --git a/include/backend/x11.h b/include/backend/x11.h index f169f7256..eb46e77e7 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -1,10 +1,22 @@ #ifndef WLR_X11_H #define WLR_X11_H +#include #include #include #include #include +#include + +struct wlr_x11_backend; + +struct wlr_x11_output { + struct wlr_output wlr_output; + struct wlr_x11_backend *x11; + + xcb_window_t win; + EGLSurface surf; +}; struct wlr_x11_backend { struct wlr_backend backend; @@ -12,7 +24,8 @@ struct wlr_x11_backend { Display *xlib_conn; xcb_connection_t *xcb_conn; xcb_screen_t *screen; - xcb_window_t win; + + struct wlr_x11_output output; struct wlr_egl egl; struct wl_event_source *event_source;