Match the fbconfig visual depth to the window

Not all RGBA 8888 fbconfigs in the NVIDIA driver have an associated
X visual with a 32 bit depth.

This fixes a regression from 88f8078073.

Tested-by: Eike Hein <hein@kde.org>
This commit is contained in:
Fredrik Höglund 2014-09-03 18:43:45 +02:00
parent c00c67bf29
commit c061cc5fd9
2 changed files with 33 additions and 0 deletions

View file

@ -168,6 +168,8 @@ void GlxBackend::init()
setIsDirectRendering(bool(glXIsDirect(display(), ctx)));
qDebug() << "Direct rendering:" << isDirectRendering() << endl;
initVisualDepthHashTable();
}
bool GlxBackend::initRenderingContext()
@ -304,6 +306,26 @@ bool GlxBackend::initFbConfig()
return true;
}
void GlxBackend::initVisualDepthHashTable()
{
const xcb_setup_t *setup = xcb_get_setup(connection());
for (auto screen = xcb_setup_roots_iterator(setup); screen.rem; xcb_screen_next(&screen)) {
for (auto depth = xcb_screen_allowed_depths_iterator(screen.data); depth.rem; xcb_depth_next(&depth)) {
const int len = xcb_depth_visuals_length(depth.data);
const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data);
for (int i = 0; i < len; i++)
m_visualDepthHash.insert(visuals[i].visual_id, depth.data->depth);
}
}
}
int GlxBackend::visualDepth(xcb_visualid_t visual) const
{
return m_visualDepthHash.value(visual);
}
FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual)
{
FBConfigInfo *&info = m_fbconfigHash[visual];
@ -331,6 +353,8 @@ FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual)
const int blue_bits = bitCount(direct->blue_mask);
const int alpha_bits = bitCount(direct->alpha_mask);
const int depth = visualDepth(visual);
const auto rgb_sizes = std::tie(red_bits, green_bits, blue_bits);
const int attribs[] = {
@ -366,6 +390,12 @@ FBConfigInfo *GlxBackend::infoForVisual(xcb_visualid_t visual)
if (std::tie(red, green, blue) != rgb_sizes)
continue;
xcb_visualid_t visual;
glXGetFBConfigAttrib(display(), configs[i], GLX_VISUAL_ID, (int *) &visual);
if (visualDepth(visual) != depth)
continue;
int bind_rgb, bind_rgba;
glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGBA_EXT, &bind_rgba);
glXGetFBConfigAttrib(display(), configs[i], GLX_BIND_TO_TEXTURE_RGB_EXT, &bind_rgb);

View file

@ -60,8 +60,10 @@ private:
void waitSync();
bool initRenderingContext();
bool initFbConfig();
void initVisualDepthHashTable();
void setSwapInterval(int interval);
int visualDepth(xcb_visualid_t visual) const;
FBConfigInfo *infoForVisual(xcb_visualid_t visual);
/**
@ -73,6 +75,7 @@ private:
GLXWindow glxWindow;
GLXContext ctx;
QHash<xcb_visualid_t, FBConfigInfo *> m_fbconfigHash;
QHash<xcb_visualid_t, int> m_visualDepthHash;
int m_bufferAge;
bool m_haveMESACopySubBuffer;
bool m_haveMESASwapControl;