1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief X11 using XCB utilities.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuX11Xcb.hpp"
32 XcbDisplay::XcbDisplay (EventState& platform, const char* name)
33 : DisplayBase (platform)
35 m_connection = xcb_connect(name, NULL);
36 const xcb_setup_t *setup = xcb_get_setup(m_connection);
37 xcb_screen_iterator_t iterator = xcb_setup_roots_iterator(setup);
38 m_screen = iterator.data;
41 XcbDisplay::~XcbDisplay (void)
43 xcb_disconnect (m_connection);
46 void XcbDisplay::processEvents (void)
48 xcb_generic_event_t *ev;
49 while ((ev = xcb_poll_for_event(m_connection)))
52 /* Manage your event */
56 XcbWindow::XcbWindow (XcbDisplay& display, int width, int height, xcb_visualid_t* visual)
60 xcb_connection_t* connection = m_display.getConnection();
62 m_window = xcb_generate_id(connection);
63 m_colormap = xcb_generate_id(connection);
65 if (visual == DE_NULL)
66 visual = &m_display.getScreen()->root_visual;
68 values[0] = m_display.getScreen()->white_pixel;
69 values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_PROPERTY_CHANGE;
72 connection, // Connection
73 XCB_COPY_FROM_PARENT, // depth (same as root)
74 m_window, // window Id
75 display.getScreen()->root, // parent window
77 static_cast<uint16_t >(width), // width
78 static_cast<uint16_t >(height), // height
80 XCB_WINDOW_CLASS_INPUT_OUTPUT, // class
82 XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, // masks
88 XCB_COLORMAP_ALLOC_NONE,
94 xcb_alloc_color_reply_t* rep = xcb_alloc_color_reply(connection, xcb_alloc_color(connection, m_colormap, 65535, 0, 0), NULL);
96 xcb_flush (connection);
99 XcbWindow::~XcbWindow (void)
101 xcb_flush (m_display.getConnection());
102 xcb_free_colormap(m_display.getConnection(), m_colormap);
103 xcb_destroy_window(m_display.getConnection(), m_window);
106 void XcbWindow::setVisibility (bool visible)
108 if (visible == m_visible)
112 xcb_map_window(m_display.getConnection(), m_window);
114 xcb_unmap_window(m_display.getConnection(), m_window);
117 xcb_flush (m_display.getConnection());
121 void XcbWindow::processEvents (void)
123 // A bit of a hack, since we don't really handle all the events.
124 m_display.processEvents();
127 void XcbWindow::getDimensions (int* width, int* height) const
129 xcb_get_geometry_reply_t *geom;
130 geom = xcb_get_geometry_reply(m_display.getConnection(), xcb_get_geometry(m_display.getConnection(), m_window), NULL);
131 *height = static_cast<int>(geom->height);
132 *width = static_cast<int>(geom->width);
136 void XcbWindow::setDimensions (int width, int height)
138 const uint32_t values[] = {static_cast<uint32_t >(width), static_cast<uint32_t >(height)};
139 xcb_void_cookie_t result;
140 xcb_connection_t* display = m_display.getConnection();
141 result = xcb_configure_window(display, m_window, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
142 DE_ASSERT(DE_NULL == xcb_request_check(display,result));
147 xcb_generic_event_t* event = xcb_poll_for_event(display);
151 if (XCB_PROPERTY_NOTIFY == (event->response_type & ~0x80))
153 const xcb_property_notify_event_t* pnEvent = (xcb_property_notify_event_t*)event;
154 if (pnEvent->atom == XCB_ATOM_RESOLUTION)
162 getDimensions (&w,&h);
163 if (h==height || w==width)