kmscube: split into parts
[android/external-libkmsxx.git] / kmscube / cube-x11.cpp
2 #include <X11/Xlib-xcb.h>
4 #include "cube-egl.h"
5 #include "cube-gles2.h"
7 #include "test.h"
9 using namespace std;
11 void main_x11()
12 {
13         Display* display = XOpenDisplay(NULL);
15         xcb_connection_t *connection = XGetXCBConnection(display);
17         /* Get the first screen */
18         const xcb_setup_t      *setup  = xcb_get_setup (connection);
19         xcb_screen_t           *screen = xcb_setup_roots_iterator (setup).data;
21         /* Create the window */
23         uint32_t width = 600;
24         uint32_t height = 600;
26         const uint32_t xcb_window_attrib_mask = XCB_CW_EVENT_MASK;
27         const uint32_t xcb_window_attrib_list[] = {
28                 XCB_EVENT_MASK_EXPOSURE,
29         };
31         xcb_window_t window = xcb_generate_id (connection);
32         xcb_create_window (connection,                    /* Connection          */
33                            XCB_COPY_FROM_PARENT,          /* depth (same as root)*/
34                            window,                        /* window Id           */
35                            screen->root,                  /* parent window       */
36                            0, 0,                          /* x, y                */
37                            width, height,                 /* width, height       */
38                            0,                             /* border_width        */
39                            XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
40                            screen->root_visual,           /* visual              */
41                            xcb_window_attrib_mask,
42                            xcb_window_attrib_list);
44         xcb_map_window (connection, window);
45         xcb_flush (connection);
47         EglState egl(display);
48         EglSurface surface(egl, (void*)(uintptr_t)window);
49         GlScene scene;
51         scene.set_viewport(width, height);
53         int framenum = 0;
55         surface.make_current();
56         surface.swap_buffers();
58         xcb_generic_event_t *event;
59         while ( (event = xcb_poll_for_event (connection)) ) {
61                 surface.make_current();
62                 scene.draw(framenum++);
63                 surface.swap_buffers();
64         }
66         xcb_disconnect (connection);
67 }