EGLFS: Replace the global static 'hooks' variable with a function
Having a global static variable in a header is a poor choice to start with. All .cpp including that header must use that variable or the compiler will warn of an unused static. Second, for the case of platform hooks, it's possible that it is reading the value of a variable that isn't initialised yet. Change-Id: Id823c2be9cfededb9c31fb76a9080d4122577ca4 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
parent
bc5170f274
commit
1b76cf0174
@ -79,7 +79,7 @@ void QEglFSContext::swapBuffers(QPlatformSurface *surface)
|
||||
cursor->paintOnScreen();
|
||||
}
|
||||
|
||||
hooks->waitForVSync();
|
||||
QEglFSHooks::hooks()->waitForVSync();
|
||||
QEGLPlatformContext::swapBuffers(surface);
|
||||
}
|
||||
|
||||
|
@ -72,15 +72,18 @@ public:
|
||||
virtual void waitForVSync() const;
|
||||
|
||||
virtual const char *fbDeviceName() const;
|
||||
};
|
||||
|
||||
static QEglFSHooks *hooks()
|
||||
{
|
||||
#ifdef EGLFS_PLATFORM_HOOKS
|
||||
extern QEglFSHooks *platformHooks;
|
||||
static QEglFSHooks *hooks = platformHooks;
|
||||
extern QEglFSHooks *platformHooks;
|
||||
return platformHooks;
|
||||
#else
|
||||
extern QEglFSHooks stubHooks;
|
||||
static QEglFSHooks *hooks = &stubHooks;
|
||||
extern QEglFSHooks stubHooks;
|
||||
return &stubHooks;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -62,8 +62,6 @@ const char *QEglFSHooks::fbDeviceName() const
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
{
|
||||
Q_UNUSED(hooks);
|
||||
|
||||
framebuffer = qt_safe_open(fbDeviceName(), O_RDONLY);
|
||||
|
||||
if (framebuffer == -1)
|
||||
|
@ -83,7 +83,7 @@ QEglFSIntegration::QEglFSIntegration()
|
||||
new QEvdevTouchScreenHandlerThread(QString() /* spec */, this);
|
||||
#endif
|
||||
|
||||
hooks->platformInit();
|
||||
QEglFSHooks::hooks()->platformInit();
|
||||
|
||||
EGLint major, minor;
|
||||
|
||||
@ -92,7 +92,7 @@ QEglFSIntegration::QEglFSIntegration()
|
||||
qFatal("EGL error");
|
||||
}
|
||||
|
||||
mDisplay = eglGetDisplay(hooks ? hooks->platformDisplay() : EGL_DEFAULT_DISPLAY);
|
||||
mDisplay = eglGetDisplay(QEglFSHooks::hooks() ? QEglFSHooks::hooks()->platformDisplay() : EGL_DEFAULT_DISPLAY);
|
||||
if (mDisplay == EGL_NO_DISPLAY) {
|
||||
qWarning("Could not open egl display\n");
|
||||
qFatal("EGL error");
|
||||
@ -122,13 +122,13 @@ QEglFSIntegration::~QEglFSIntegration()
|
||||
delete mScreen;
|
||||
|
||||
eglTerminate(mDisplay);
|
||||
hooks->platformDestroy();
|
||||
QEglFSHooks::hooks()->platformDestroy();
|
||||
}
|
||||
|
||||
bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
// We assume that devices will have more and not less capabilities
|
||||
if (hooks && hooks->hasCapability(cap))
|
||||
if (QEglFSHooks::hooks() && QEglFSHooks::hooks()->hasCapability(cap))
|
||||
return true;
|
||||
|
||||
switch (cap) {
|
||||
@ -153,13 +153,13 @@ QPlatformBackingStore *QEglFSIntegration::createPlatformBackingStore(QWindow *wi
|
||||
|
||||
QPlatformOpenGLContext *QEglFSIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
|
||||
{
|
||||
return new QEglFSContext(hooks->surfaceFormatFor(context->format()), context->shareHandle(), mDisplay);
|
||||
return new QEglFSContext(QEglFSHooks::hooks()->surfaceFormatFor(context->format()), context->shareHandle(), mDisplay);
|
||||
}
|
||||
|
||||
QPlatformOffscreenSurface *QEglFSIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
|
||||
{
|
||||
QEglFSScreen *screen = static_cast<QEglFSScreen *>(surface->screen()->handle());
|
||||
return new QEGLPbuffer(screen->display(), hooks->surfaceFormatFor(surface->requestedFormat()), surface);
|
||||
return new QEGLPbuffer(screen->display(), QEglFSHooks::hooks()->surfaceFormatFor(surface->requestedFormat()), surface);
|
||||
}
|
||||
|
||||
QPlatformFontDatabase *QEglFSIntegration::fontDatabase() const
|
||||
@ -230,7 +230,7 @@ EGLConfig QEglFSIntegration::chooseConfig(EGLDisplay display, const QSurfaceForm
|
||||
QEglFSHooks *m_hooks;
|
||||
};
|
||||
|
||||
Chooser chooser(display, hooks);
|
||||
Chooser chooser(display, QEglFSHooks::hooks());
|
||||
chooser.setSurfaceFormat(format);
|
||||
return chooser.chooseConfig();
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ QEglFSScreen::QEglFSScreen(EGLDisplay dpy)
|
||||
|
||||
static int hideCursor = qgetenv("QT_QPA_EGLFS_HIDECURSOR").toInt();
|
||||
if (!hideCursor) {
|
||||
if (QEglFSCursor *customCursor = hooks->createCursor(this))
|
||||
if (QEglFSCursor *customCursor = QEglFSHooks::hooks()->createCursor(this))
|
||||
m_cursor = customCursor;
|
||||
else
|
||||
m_cursor = new QEglFSCursor(this);
|
||||
@ -70,22 +70,22 @@ QEglFSScreen::~QEglFSScreen()
|
||||
|
||||
QRect QEglFSScreen::geometry() const
|
||||
{
|
||||
return QRect(QPoint(0, 0), hooks->screenSize());
|
||||
return QRect(QPoint(0, 0), QEglFSHooks::hooks()->screenSize());
|
||||
}
|
||||
|
||||
int QEglFSScreen::depth() const
|
||||
{
|
||||
return hooks->screenDepth();
|
||||
return QEglFSHooks::hooks()->screenDepth();
|
||||
}
|
||||
|
||||
QImage::Format QEglFSScreen::format() const
|
||||
{
|
||||
return hooks->screenFormat();
|
||||
return QEglFSHooks::hooks()->screenFormat();
|
||||
}
|
||||
|
||||
QSizeF QEglFSScreen::physicalSize() const
|
||||
{
|
||||
return hooks->physicalScreenSize();
|
||||
return QEglFSHooks::hooks()->physicalScreenSize();
|
||||
}
|
||||
|
||||
QPlatformCursor *QEglFSScreen::cursor() const
|
||||
|
@ -76,18 +76,18 @@ void QEglFSWindow::create()
|
||||
return;
|
||||
|
||||
if (window()->type() == Qt::Desktop) {
|
||||
QRect rect(QPoint(), hooks->screenSize());
|
||||
QRect rect(QPoint(), QEglFSHooks::hooks()->screenSize());
|
||||
QPlatformWindow::setGeometry(rect);
|
||||
QWindowSystemInterface::handleGeometryChange(window(), rect);
|
||||
return;
|
||||
}
|
||||
|
||||
EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display();
|
||||
QSurfaceFormat platformFormat = hooks->surfaceFormatFor(window()->requestedFormat());
|
||||
QSurfaceFormat platformFormat = QEglFSHooks::hooks()->surfaceFormatFor(window()->requestedFormat());
|
||||
EGLConfig config = QEglFSIntegration::chooseConfig(display, platformFormat);
|
||||
|
||||
m_format = q_glFormatFromConfig(display, config);
|
||||
m_window = hooks->createNativeWindow(hooks->screenSize(), m_format);
|
||||
m_window = QEglFSHooks::hooks()->createNativeWindow(QEglFSHooks::hooks()->screenSize(), m_format);
|
||||
m_surface = eglCreateWindowSurface(display, config, m_window, NULL);
|
||||
if (m_surface == EGL_NO_SURFACE) {
|
||||
EGLint error = eglGetError();
|
||||
@ -105,7 +105,7 @@ void QEglFSWindow::destroy()
|
||||
}
|
||||
|
||||
if (m_window) {
|
||||
hooks->destroyNativeWindow(m_window);
|
||||
QEglFSHooks::hooks()->destroyNativeWindow(m_window);
|
||||
m_window = 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user