eglfs: rework hooks design
There are two problems with the current design: 1. if (hooks) hooks->foo() doesn't work in debug mode when no platform hook is defined. The problem doesn't arise in release mode because the compiler optimizes away the if (hooks) into a no-op since hooks is NULL when no platform hook is defined. 2. Adding a new hook requires changing every platform's hook implementation. New approach: 1. Define QEglFSHooks as a class with virtual functions. A stub file provides the default implementation. 2. Platform hooks derive from above class and reimplement whatever is needed. The filenames and variables have been changed to be more in line with the Qt style. Change-Id: I2eaaa5ad7c8b48a06361c4747d4f210c428c983f Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
parent
42f3bf772b
commit
e60ca0de60
@ -39,7 +39,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qeglfs_hooks.h"
|
||||
#include "qeglfshooks.h"
|
||||
#include <EGL/fbdev_window.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -48,20 +48,15 @@
|
||||
#include <fcntl.h>
|
||||
#include <linux/fb.h>
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
class QEglFS8726MHooks : public QEglFSHooks
|
||||
{
|
||||
}
|
||||
public:
|
||||
virtual QSize screenSize() const;
|
||||
virtual EGLNativeWindowType createNativeWindow(const QSize &size);
|
||||
virtual void destroyNativeWindow(EGLNativeWindowType window);
|
||||
};
|
||||
|
||||
void QEglFSHooks::platformDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
||||
{
|
||||
return EGL_DEFAULT_DISPLAY;
|
||||
}
|
||||
|
||||
QSize QEglFSHooks::screenSize() const
|
||||
QSize QEglFS8726MHooks::screenSize() const
|
||||
{
|
||||
int fd = open("/dev/fb0", O_RDONLY);
|
||||
if (fd == -1) {
|
||||
@ -78,7 +73,7 @@ QSize QEglFSHooks::screenSize() const
|
||||
return QSize(vinfo.xres, vinfo.yres);
|
||||
}
|
||||
|
||||
EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
EGLNativeWindowType QEglFS8726MHooks::createNativeWindow(const QSize &size)
|
||||
{
|
||||
fbdev_window *window = new fbdev_window;
|
||||
window->width = size.width();
|
||||
@ -87,14 +82,11 @@ EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
return window;
|
||||
}
|
||||
|
||||
void QEglFSHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
void QEglFS8726MHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
{
|
||||
delete window;
|
||||
}
|
||||
|
||||
bool QEglFSHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QEglFS8726MHooks eglFS8726MHooks;
|
||||
QEglFSHooks *platformHooks = &eglFS8726MHooks;
|
||||
|
||||
QEglFSHooks platform_hooks;
|
@ -31,6 +31,6 @@ QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
|
||||
|
||||
deviceSanityCheckCompiler()
|
||||
|
||||
EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/qeglfs_hooks_8726m.cpp
|
||||
EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/qeglfshooks_8726m.cpp
|
||||
|
||||
load(qt_config)
|
||||
|
@ -39,7 +39,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qeglfs_hooks.h"
|
||||
#include "qeglfshooks.h"
|
||||
|
||||
#include <bcm_host.h>
|
||||
|
||||
@ -55,23 +55,35 @@
|
||||
static DISPMANX_DISPLAY_HANDLE_T dispman_display = 0;
|
||||
static DISPMANX_UPDATE_HANDLE_T dispman_update = 0;
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
class QEglFSPiHooks : public QEglFSHooks
|
||||
{
|
||||
public:
|
||||
virtual void platformInit();
|
||||
virtual void platformDestroy();
|
||||
virtual EGLNativeDisplayType platformDisplay() const;
|
||||
virtual QSize screenSize() const;
|
||||
virtual EGLNativeWindowType createNativeWindow(const QSize &size);
|
||||
virtual void destroyNativeWindow(EGLNativeWindowType window);
|
||||
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
};
|
||||
|
||||
void QEglFSPiHooks::platformInit()
|
||||
{
|
||||
bcm_host_init();
|
||||
}
|
||||
|
||||
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
||||
EGLNativeDisplayType QEglFSPiHooks::platformDisplay() const
|
||||
{
|
||||
dispman_display = vc_dispmanx_display_open(0/* LCD */);
|
||||
return EGL_DEFAULT_DISPLAY;
|
||||
}
|
||||
|
||||
void QEglFSHooks::platformDestroy()
|
||||
void QEglFSPiHooks::platformDestroy()
|
||||
{
|
||||
vc_dispmanx_display_close(dispman_display);
|
||||
}
|
||||
|
||||
QSize QEglFSHooks::screenSize() const
|
||||
QSize QEglFSPiHooks::screenSize() const
|
||||
{
|
||||
//both mechanisms work
|
||||
#if 1
|
||||
@ -98,7 +110,7 @@ QSize QEglFSHooks::screenSize() const
|
||||
#endif
|
||||
}
|
||||
|
||||
EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
EGLNativeWindowType QEglFSPiHooks::createNativeWindow(const QSize &size)
|
||||
{
|
||||
VC_RECT_T dst_rect;
|
||||
dst_rect.x = 0;
|
||||
@ -133,14 +145,14 @@ EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
return eglWindow;
|
||||
}
|
||||
|
||||
void QEglFSHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
void QEglFSPiHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
{
|
||||
EGL_DISPMANX_WINDOW_T *eglWindow = static_cast<EGL_DISPMANX_WINDOW_T *>(window);
|
||||
vc_dispmanx_element_remove(dispman_update, eglWindow->element);
|
||||
delete eglWindow;
|
||||
}
|
||||
|
||||
bool QEglFSHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
bool QEglFSPiHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
switch (cap) {
|
||||
case QPlatformIntegration::ThreadedPixmaps:
|
||||
@ -153,4 +165,5 @@ bool QEglFSHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
}
|
||||
}
|
||||
|
||||
QEglFSHooks platform_hooks;
|
||||
QEglFSPiHooks eglFSPiHooks;
|
||||
QEglFSHooks *platformHooks = &eglFSPiHooks;
|
@ -48,7 +48,7 @@ QMAKE_CFLAGS_RELEASE += \
|
||||
|
||||
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE
|
||||
|
||||
EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/qeglfs_hooks.cpp
|
||||
EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/qeglfshooks_pi.cpp
|
||||
|
||||
# Sanity check
|
||||
deviceSanityCheckCompiler()
|
||||
|
@ -13,20 +13,21 @@ DESTDIR = $$QT.gui.plugins/platforms
|
||||
DEFINES += MESA_EGL_NO_X11_HEADERS
|
||||
|
||||
#To test the hooks on x11 (xlib), comment the above define too
|
||||
#EGLFS_PLATFORM_HOOKS_SOURCES += qeglfs_hooks_x11.cpp
|
||||
#EGLFS_PLATFORM_HOOKS_SOURCES += qeglfshooks_x11.cpp
|
||||
#LIBS += -lX11
|
||||
|
||||
SOURCES = main.cpp \
|
||||
qeglfsintegration.cpp \
|
||||
qeglfswindow.cpp \
|
||||
qeglfsbackingstore.cpp \
|
||||
qeglfsscreen.cpp
|
||||
qeglfsscreen.cpp \
|
||||
qeglfshooks_stub.cpp
|
||||
|
||||
HEADERS = qeglfsintegration.h \
|
||||
qeglfswindow.h \
|
||||
qeglfsbackingstore.h \
|
||||
qeglfsscreen.h \
|
||||
qeglfs_hooks.h
|
||||
qeglfshooks.h
|
||||
|
||||
QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
|
||||
|
||||
|
@ -39,31 +39,34 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QEGLFS_HOOKS_H
|
||||
#define QEGLFS_HOOKS_H
|
||||
#ifndef QEGLFSHOOKS_H
|
||||
#define QEGLFSHOOKS_H
|
||||
|
||||
#include "qplatformintegration_qpa.h"
|
||||
#include <EGL/egl.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
struct QEglFSHooks {
|
||||
void platformInit();
|
||||
void platformDestroy();
|
||||
EGLNativeDisplayType platformDisplay() const;
|
||||
QSize screenSize() const;
|
||||
EGLNativeWindowType createNativeWindow(const QSize &size);
|
||||
void destroyNativeWindow(EGLNativeWindowType window);
|
||||
bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
class QEglFSHooks
|
||||
{
|
||||
public:
|
||||
virtual void platformInit();
|
||||
virtual void platformDestroy();
|
||||
virtual EGLNativeDisplayType platformDisplay() const;
|
||||
virtual QSize screenSize() const;
|
||||
virtual EGLNativeWindowType createNativeWindow(const QSize &size);
|
||||
virtual void destroyNativeWindow(EGLNativeWindowType window);
|
||||
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
};
|
||||
|
||||
#ifdef EGLFS_PLATFORM_HOOKS
|
||||
extern QEglFSHooks platform_hooks;
|
||||
static QEglFSHooks *hooks = &platform_hooks;
|
||||
extern QEglFSHooks *platformHooks;
|
||||
static QEglFSHooks *hooks = platformHooks;
|
||||
#else
|
||||
static QEglFSHooks *hooks = 0;
|
||||
extern QEglFSHooks stubHooks;
|
||||
static QEglFSHooks *hooks = &stubHooks;
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
#endif // QEGLFSHOOKS_H
|
81
src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
Normal file
81
src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the qmake spec of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qeglfshooks.h"
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
{
|
||||
}
|
||||
|
||||
void QEglFSHooks::platformDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
||||
{
|
||||
return EGL_DEFAULT_DISPLAY;
|
||||
}
|
||||
|
||||
QSize QEglFSHooks::screenSize() const
|
||||
{
|
||||
return QSize();
|
||||
}
|
||||
|
||||
EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
{
|
||||
Q_UNUSED(size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QEglFSHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
{
|
||||
Q_UNUSED(window);
|
||||
}
|
||||
|
||||
bool QEglFSHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
Q_UNUSED(cap);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef EGLFS_PLATFORM_HOOKS
|
||||
QEglFSHooks stubHooks;
|
||||
#endif
|
@ -39,31 +39,42 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qeglfs_hooks.h"
|
||||
#include "qeglfshooks.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
QEglFSHooks platform_hooks;
|
||||
class QEglFSX11Hooks : public QEglFSHooks
|
||||
{
|
||||
public:
|
||||
virtual void platformInit();
|
||||
virtual void platformDestroy();
|
||||
virtual EGLNativeDisplayType platformDisplay() const;
|
||||
virtual QSize screenSize() const;
|
||||
virtual EGLNativeWindowType createNativeWindow(const QSize &size);
|
||||
virtual void destroyNativeWindow(EGLNativeWindowType window);
|
||||
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
};
|
||||
|
||||
static Display *display = 0;
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
void QEglFSX11Hooks::platformInit()
|
||||
{
|
||||
display = XOpenDisplay(NULL);
|
||||
if (!display)
|
||||
qFatal("Could not open display");
|
||||
}
|
||||
|
||||
void QEglFSHooks::platformDestroy()
|
||||
void QEglFSX11Hooks::platformDestroy()
|
||||
{
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
|
||||
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
||||
EGLNativeDisplayType QEglFSX11Hooks::platformDisplay() const
|
||||
{
|
||||
return display;
|
||||
}
|
||||
|
||||
QSize QEglFSHooks::screenSize() const
|
||||
QSize QEglFSX11Hooks::screenSize() const
|
||||
{
|
||||
QList<QByteArray> env = qgetenv("EGLFS_X11_SIZE").split('x');
|
||||
if (env.length() != 2)
|
||||
@ -71,7 +82,7 @@ QSize QEglFSHooks::screenSize() const
|
||||
return QSize(env.at(0).toInt(), env.at(1).toInt());
|
||||
}
|
||||
|
||||
EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
EGLNativeWindowType QEglFSX11Hooks::createNativeWindow(const QSize &size)
|
||||
{
|
||||
Window root = DefaultRootWindow(display);
|
||||
XSetWindowAttributes swa;
|
||||
@ -83,13 +94,17 @@ EGLNativeWindowType QEglFSHooks::createNativeWindow(const QSize &size)
|
||||
return win;
|
||||
}
|
||||
|
||||
void QEglFSHooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
void QEglFSX11Hooks::destroyNativeWindow(EGLNativeWindowType window)
|
||||
{
|
||||
XDestroyWindow(display, window);
|
||||
}
|
||||
|
||||
bool QEglFSHooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
bool QEglFSX11Hooks::hasCapability(QPlatformIntegration::Capability cap) const
|
||||
{
|
||||
Q_UNUSED(cap);
|
||||
return false;
|
||||
}
|
||||
|
||||
static QEglFSX11Hooks eglFSX11Hooks;
|
||||
QEglFSHooks *platformHooks = &eglFSX11Hooks;
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
#include "qeglfswindow.h"
|
||||
#include "qeglfsbackingstore.h"
|
||||
#include "qeglfs_hooks.h"
|
||||
#include "qeglfshooks.h"
|
||||
|
||||
#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
|
||||
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#include "qeglfsscreen.h"
|
||||
#include "qeglfswindow.h"
|
||||
#include "qeglfs_hooks.h"
|
||||
#include "qeglfshooks.h"
|
||||
|
||||
#include <QtPlatformSupport/private/qeglconvenience_p.h>
|
||||
#include <QtPlatformSupport/private/qeglplatformcontext_p.h>
|
||||
|
Loading…
Reference in New Issue
Block a user