diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-04-16 20:56:22 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-04-16 20:56:22 +0300 |
commit | d54a6e8e8a170591d6eb98c8e2d4236763258f5d (patch) | |
tree | a6610e20d0ffc110f107a5bbcb9ca8d432a61da0 | |
parent | 31988f414f7f879171f7fa137f1866e0c4ca7b66 (diff) |
kmscube: support X
-rw-r--r-- | kmscube/CMakeLists.txt | 43 | ||||
-rw-r--r-- | kmscube/kmscube.cpp | 106 |
2 files changed, 110 insertions, 39 deletions
diff --git a/kmscube/CMakeLists.txt b/kmscube/CMakeLists.txt index 4730d04..9c1a9d6 100644 --- a/kmscube/CMakeLists.txt +++ b/kmscube/CMakeLists.txt @@ -1,17 +1,38 @@ -include_directories(${LIBDRM_INCLUDE_DIRS}) -link_directories(${LIBDRM_LIBRARY_DIRS}) pkg_check_modules(GLESv2 glesv2 REQUIRED) -include_directories(${GLESv2_INCLUDE_DIRS}) -link_directories(${GLESv2_LIBRARY_DIRS}) - pkg_check_modules(EGL egl REQUIRED) -include_directories(${EGL_INCLUDE_DIRS}) -link_directories(${EGL_LIBRARY_DIRS}) - pkg_check_modules(GBM gbm REQUIRED) -include_directories(${GBM_INCLUDE_DIRS}) -link_directories(${GBM_LIBRARY_DIRS}) +pkg_check_modules(X11 x11 REQUIRED) +pkg_check_modules(XCB xcb REQUIRED) +pkg_check_modules(X11XCB x11-xcb REQUIRED) + +include_directories( + ${LIBDRM_INCLUDE_DIRS} + ${GLESv2_INCLUDE_DIRS} + ${EGL_INCLUDE_DIRS} + ${GBM_INCLUDE_DIRS} + ${X11_INCLUDE_DIRS} + ${XCB_INCLUDE_DIRS} + ${X11XCB_INCLUDE_DIRS} +) + +link_directories( + ${LIBDRM_LIBRARY_DIRS} + ${GLESv2_LIBRARY_DIRS} + ${EGL_LIBRARY_DIRS} + ${GBM_LIBRARY_DIRS} + ${X11_LIBRARY_DIRS} + ${XCB_LIBRARY_DIRS} + ${X11XCB_LIBRARY_DIRS} +) add_executable (kmscube kmscube.cpp esTransform.c esUtil.h cube.h) -target_link_libraries(kmscube kms++ kmstest ${LIBDRM_LIBRARIES} ${GLESv2_LIBRARIES} ${EGL_LIBRARIES} ${GBM_LIBRARIES}) +target_link_libraries(kmscube kms++ kmstest + ${LIBDRM_LIBRARIES} + ${GLESv2_LIBRARIES} + ${EGL_LIBRARIES} + ${GBM_LIBRARIES} + ${X11_LIBRARIES} + ${XCB_LIBRARIES} + ${X11XCB_LIBRARIES} +) 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 <xf86drm.h> #include <xf86drmMode.h> #include <gbm.h> +#include <X11/Xlib-xcb.h> #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<EGLNativeDisplayType>(display)); + EglSurface surface(egl, reinterpret_cast<EGLNativeWindowType>(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; |