Properly read back the actual format in xcb and xlib plugins.

Change-Id: Iccef2c4a87863b93914b84edf3a6015dad5e512a
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
Samuel Rødal 2012-02-10 10:23:15 +01:00 committed by Qt by Nokia
parent 7dca7c3c57
commit 38257651b7
8 changed files with 30 additions and 18 deletions

View File

@ -153,23 +153,28 @@ GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat
XFree(configs); XFree(configs);
} }
reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced); if (!chosenConfig)
reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced);
} }
return chosenConfig; return chosenConfig;
} }
XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QSurfaceFormat &format) XVisualInfo *qglx_findVisualInfo(Display *display, int screen, QSurfaceFormat *format)
{ {
Q_ASSERT(format);
XVisualInfo *visualInfo = 0; XVisualInfo *visualInfo = 0;
GLXFBConfig config = qglx_findConfig(display,screen,format); GLXFBConfig config = qglx_findConfig(display,screen,*format);
if (config) if (config) {
visualInfo = glXGetVisualFromFBConfig(display, config); visualInfo = glXGetVisualFromFBConfig(display, config);
*format = qglx_surfaceFormatFromGLXFBConfig(display, config);
}
// attempt to fall back to glXChooseVisual // attempt to fall back to glXChooseVisual
bool reduced = true; bool reduced = true;
QSurfaceFormat reducedFormat = format; QSurfaceFormat reducedFormat = *format;
while (!visualInfo && reduced) { while (!visualInfo && reduced) {
QVarLengthArray<int, 13> attribs; QVarLengthArray<int, 13> attribs;
attribs.append(GLX_RGBA); attribs.append(GLX_RGBA);

View File

@ -48,9 +48,9 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <GL/glx.h> #include <GL/glx.h>
XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QSurfaceFormat &format); XVisualInfo *qglx_findVisualInfo(Display *display, int screen, QSurfaceFormat *format);
GLXFBConfig qglx_findConfig(Display *display, int screen, const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT); GLXFBConfig qglx_findConfig(Display *display, int screen, const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT);
QSurfaceFormat qglx_surfaceFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context); QSurfaceFormat qglx_surfaceFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context = 0);
QVector<int> qglx_buildSpec(const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT); QVector<int> qglx_buildSpec(const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT);
QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced); QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced);

View File

@ -64,6 +64,7 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat
: QPlatformOpenGLContext() : QPlatformOpenGLContext()
, m_screen(screen) , m_screen(screen)
, m_context(0) , m_context(0)
, m_format(format)
{ {
m_shareContext = 0; m_shareContext = 0;
if (share) if (share)
@ -82,7 +83,7 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlat
if (m_context) if (m_context)
m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context); m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context);
} else { } else {
XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), screen->screenNumber(), format); XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), screen->screenNumber(), &m_format);
if (!visualInfo) if (!visualInfo)
qFatal("Could not initialize GLX"); qFatal("Could not initialize GLX");
m_context = glXCreateContext(DISPLAY_FROM_XCB(screen), visualInfo, m_shareContext, true); m_context = glXCreateContext(DISPLAY_FROM_XCB(screen), visualInfo, m_shareContext, true);

View File

@ -201,19 +201,21 @@ void QXcbWindow::create()
if (parent()) if (parent())
xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window(); xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window();
m_requestedFormat = window()->format(); m_format = window()->requestedFormat();
#if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB) #if (defined(XCB_USE_GLX) || defined(XCB_USE_EGL)) && defined(XCB_USE_XLIB)
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL) if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
|| window()->format().hasAlpha()) || m_format.hasAlpha())
{ {
#if defined(XCB_USE_GLX) #if defined(XCB_USE_GLX)
XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->format()); XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen), m_screen->screenNumber(), &m_format);
if (!visualInfo) if (!visualInfo)
qFatal("Could not initialize GLX"); qFatal("Could not initialize GLX");
#elif defined(XCB_USE_EGL) #elif defined(XCB_USE_EGL)
EGLDisplay eglDisplay = connection()->egl_display(); EGLDisplay eglDisplay = connection()->egl_display();
EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->format(), true); EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, m_format, true);
m_format = q_glFormatFromConfig(eglDisplay, eglConfig);
VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig); VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
XVisualInfo visualInfoTemplate; XVisualInfo visualInfoTemplate;
@ -1167,7 +1169,7 @@ void QXcbWindow::setOrientation(Qt::ScreenOrientation orientation)
QSurfaceFormat QXcbWindow::format() const QSurfaceFormat QXcbWindow::format() const
{ {
// ### return actual format // ### return actual format
return m_requestedFormat; return m_format;
} }
#if defined(XCB_USE_EGL) #if defined(XCB_USE_EGL)

View File

@ -155,7 +155,7 @@ private:
bool m_transparent; bool m_transparent;
xcb_window_t m_netWmUserTimeWindow; xcb_window_t m_netWmUserTimeWindow;
QSurfaceFormat m_requestedFormat; QSurfaceFormat m_format;
mutable bool m_dirtyFrameMargins; mutable bool m_dirtyFrameMargins;
mutable QMargins m_frameMargins; mutable QMargins m_frameMargins;

View File

@ -65,6 +65,7 @@ QGLXContext::QGLXContext(QXlibScreen *screen, const QSurfaceFormat &format, QPla
: QPlatformOpenGLContext() : QPlatformOpenGLContext()
, m_screen(screen) , m_screen(screen)
, m_context(0) , m_context(0)
, m_windowFormat(format)
{ {
GLXContext shareGlxContext = 0; GLXContext shareGlxContext = 0;
if (share) if (share)
@ -77,7 +78,7 @@ QGLXContext::QGLXContext(QXlibScreen *screen, const QSurfaceFormat &format, QPla
m_context = glXCreateNewContext(xDisplay,config,GLX_RGBA_TYPE,shareGlxContext,TRUE); m_context = glXCreateNewContext(xDisplay,config,GLX_RGBA_TYPE,shareGlxContext,TRUE);
m_windowFormat = qglx_surfaceFormatFromGLXFBConfig(xDisplay,config,m_context); m_windowFormat = qglx_surfaceFormatFromGLXFBConfig(xDisplay,config,m_context);
} else { } else {
XVisualInfo *visualInfo = qglx_findVisualInfo(xDisplay, screen->xScreenNumber(), format); XVisualInfo *visualInfo = qglx_findVisualInfo(xDisplay, screen->xScreenNumber(), &m_windowFormat);
if (!visualInfo) if (!visualInfo)
qFatal("Could not initialize GLX"); qFatal("Could not initialize GLX");
m_context = glXCreateContext(xDisplay, visualInfo, shareGlxContext, true); m_context = glXCreateContext(xDisplay, visualInfo, shareGlxContext, true);

View File

@ -82,11 +82,12 @@ QXlibWindow::QXlibWindow(QWindow *window)
int w = window->width(); int w = window->width();
int h = window->height(); int h = window->height();
mSurfaceFormat = window->requestedFormat();
#if !defined(QT_NO_OPENGL) #if !defined(QT_NO_OPENGL)
if(window->surfaceType() == QWindow::OpenGLSurface) { if(window->surfaceType() == QWindow::OpenGLSurface) {
#if !defined(QT_OPENGL_ES_2) #if !defined(QT_OPENGL_ES_2)
XVisualInfo *visualInfo = qglx_findVisualInfo(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber(), XVisualInfo *visualInfo = qglx_findVisualInfo(mScreen->display()->nativeDisplay(), mScreen->xScreenNumber(), &mSurfaceFormat);
window->format());
if (!visualInfo) if (!visualInfo)
qFatal("Could not initialize GLX"); qFatal("Could not initialize GLX");
#else #else
@ -694,7 +695,7 @@ void QXlibWindow::setCursor(const Cursor &cursor)
QSurfaceFormat QXlibWindow::format() const QSurfaceFormat QXlibWindow::format() const
{ {
return window()->format(); return mSurfaceFormat;
} }

View File

@ -143,6 +143,8 @@ private:
QImage::Format mFormat; QImage::Format mFormat;
Visual* mVisual; Visual* mVisual;
QSurfaceFormat mSurfaceFormat;
GC createGC(); GC createGC();
QPlatformOpenGLContext *mGLContext; QPlatformOpenGLContext *mGLContext;