From d54a6e8e8a170591d6eb98c8e2d4236763258f5d Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 16 Apr 2016 20:56:22 +0300 Subject: kmscube: support X --- kmscube/kmscube.cpp | 106 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 28 deletions(-) (limited to 'kmscube/kmscube.cpp') diff --git a/kmscube/kmscube.cpp b/kmscube/kmscube.cpp index 1902970..e9145c9 100644 --- a/kmscube/kmscube.cpp +++ b/kmscube/kmscube.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "esUtil.h" @@ -456,17 +457,17 @@ private: struct gbm_bo* bo_next; }; -class NullEglSurface +class EglSurface { public: - NullEglSurface(const EglState& egl) + EglSurface(const EglState& egl, EGLNativeWindowType wnd) : egl(egl) { - esurface = eglCreateWindowSurface(egl.display(), egl.config(), 0, NULL); + esurface = eglCreateWindowSurface(egl.display(), egl.config(), wnd, NULL); FAIL_IF(esurface == EGL_NO_SURFACE, "failed to create egl surface"); } - ~NullEglSurface() + ~EglSurface() { eglDestroySurface(egl.display(), esurface); } @@ -710,10 +711,68 @@ static void main_gbm() } } -static void main_egl() +static void main_x() +{ + Display* display = XOpenDisplay(NULL); + + xcb_connection_t *connection = XGetXCBConnection(display); + + /* Get the first screen */ + const xcb_setup_t *setup = xcb_get_setup (connection); + xcb_screen_t *screen = xcb_setup_roots_iterator (setup).data; + + /* Create the window */ + + uint32_t width = 600; + uint32_t height = 600; + + const uint32_t xcb_window_attrib_mask = XCB_CW_EVENT_MASK; + const uint32_t xcb_window_attrib_list[] = { + XCB_EVENT_MASK_EXPOSURE, + }; + + xcb_window_t window = xcb_generate_id (connection); + xcb_create_window (connection, /* Connection */ + XCB_COPY_FROM_PARENT, /* depth (same as root)*/ + window, /* window Id */ + screen->root, /* parent window */ + 0, 0, /* x, y */ + width, height, /* width, height */ + 0, /* border_width */ + XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ + screen->root_visual, /* visual */ + xcb_window_attrib_mask, + xcb_window_attrib_list); + + xcb_map_window (connection, window); + xcb_flush (connection); + + EglState egl(reinterpret_cast(display)); + EglSurface surface(egl, reinterpret_cast(window)); + GlScene scene; + + scene.set_viewport(width, height); + + int framenum = 0; + + surface.make_current(); + surface.swap_buffers(); + + xcb_generic_event_t *event; + while ( (event = xcb_poll_for_event (connection)) ) { + + surface.make_current(); + scene.draw(framenum++); + surface.swap_buffers(); + } + + xcb_disconnect (connection); +} + +static void main_null() { EglState egl(EGL_DEFAULT_DISPLAY); - NullEglSurface surface(egl); + EglSurface surface(egl, 0); GlScene scene; scene.set_viewport(600, 600); @@ -749,31 +808,22 @@ int main(int argc, char *argv[]) optionset.parse(argc, argv); - int mode; - - if (optionset.params().size() == 0) { - mode = 0; - } else { - const string m = optionset.params().front(); + string m; - if (m == "gbm") - mode = 0; - else if (m == "null") - mode = 1; - else { - printf("Unknown mode %s\n", m.c_str()); - return -1; - } - } + if (optionset.params().size() == 0) + m = "gbm"; + else + m = optionset.params().front(); - switch (mode) { - case 0: + if (m == "gbm") main_gbm(); - break; - - case 1: - main_egl(); - break; + else if (m == "null") + main_null(); + else if (m == "x") + main_x(); + else { + printf("Unknown mode %s\n", m.c_str()); + return -1; } return 0; -- cgit v1.2.3