Refactor QEglFSPandaHooks and add physicalScreenSize()
Change-Id: I5a198af5347cc1fdce97031e0a1be99b2120c3ac Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>bb10
parent
07843b1b12
commit
6bd03762d4
|
|
@ -63,9 +63,8 @@ class QEglFSPandaHooks : public QEglFSHooks
|
|||
public:
|
||||
QEglFSPandaHooks();
|
||||
virtual EGLNativeWindowType createNativeWindow(const QSize &size, const QSurfaceFormat &format);
|
||||
virtual QSize screenSize() const;
|
||||
virtual int screenDepth() const;
|
||||
virtual bool filterConfig(EGLDisplay display, EGLConfig config) const;
|
||||
virtual const char *fbDeviceName() const { return "/dev/graphics/fb0"; }
|
||||
|
||||
private:
|
||||
EGLNativeWindowType createNativeWindowSurfaceFlinger(const QSize &size, const QSurfaceFormat &format);
|
||||
|
|
@ -152,68 +151,6 @@ bool QEglFSPandaHooks::filterConfig(EGLDisplay display, EGLConfig config) const
|
|||
return nativeVisualId == mFramebufferVisualId;
|
||||
}
|
||||
|
||||
QSize QEglFSPandaHooks::screenSize() const
|
||||
{
|
||||
static QSize size;
|
||||
|
||||
if (size.isEmpty()) {
|
||||
int width = qgetenv("QT_QPA_EGLFS_WIDTH").toInt();
|
||||
int height = qgetenv("QT_QPA_EGLFS_HEIGHT").toInt();
|
||||
|
||||
if (width && height) {
|
||||
// no need to read fb0
|
||||
size.setWidth(width);
|
||||
size.setHeight(height);
|
||||
return size;
|
||||
}
|
||||
|
||||
struct fb_var_screeninfo vinfo;
|
||||
int fd = open("/dev/graphics/fb0", O_RDONLY);
|
||||
|
||||
if (fd != -1) {
|
||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||
qWarning("Could not query variable screen info.");
|
||||
else
|
||||
size = QSize(vinfo.xres, vinfo.yres);
|
||||
|
||||
close(fd);
|
||||
} else {
|
||||
qWarning("Failed to open /dev/graphics/fb0 to detect screen resolution.");
|
||||
}
|
||||
|
||||
// override fb0 from environment var setting
|
||||
if (width)
|
||||
size.setWidth(width);
|
||||
if (height)
|
||||
size.setHeight(height);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int QEglFSPandaHooks::screenDepth() const
|
||||
{
|
||||
static int depth = qgetenv("QT_QPA_EGLFS_DEPTH").toInt();
|
||||
|
||||
if (depth == 0) {
|
||||
struct fb_var_screeninfo vinfo;
|
||||
int fd = open("/dev/graphics/fb0", O_RDONLY);
|
||||
|
||||
if (fd != -1) {
|
||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||
qWarning("Could not query variable screen info.");
|
||||
else
|
||||
depth = vinfo.bits_per_pixel;
|
||||
|
||||
close(fd);
|
||||
} else {
|
||||
qWarning("Failed to open /dev/graphics/fb0 to detect screen depth.");
|
||||
}
|
||||
}
|
||||
|
||||
return depth == 0 ? 32 : depth;
|
||||
}
|
||||
|
||||
static QEglFSPandaHooks eglFSPandaHooks;
|
||||
QEglFSHooks *platformHooks = &eglFSPandaHooks;
|
||||
|
||||
|
|
|
|||
|
|
@ -55,10 +55,11 @@ class QEglFSScreen;
|
|||
class QEglFSHooks
|
||||
{
|
||||
public:
|
||||
virtual ~QEglFSHooks() {};
|
||||
virtual ~QEglFSHooks() {}
|
||||
virtual void platformInit();
|
||||
virtual void platformDestroy();
|
||||
virtual EGLNativeDisplayType platformDisplay() const;
|
||||
virtual QSizeF physicalScreenSize() const;
|
||||
virtual QSize screenSize() const;
|
||||
virtual int screenDepth() const;
|
||||
virtual QImage::Format screenFormat() const;
|
||||
|
|
@ -68,6 +69,8 @@ public:
|
|||
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
virtual QEglFSCursor *createCursor(QEglFSScreen *screen) const;
|
||||
virtual bool filterConfig(EGLDisplay display, EGLConfig config) const;
|
||||
|
||||
virtual const char *fbDeviceName() const;
|
||||
};
|
||||
|
||||
#ifdef EGLFS_PLATFORM_HOOKS
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
const char *QEglFSHooks::fbDeviceName() const
|
||||
{
|
||||
return "/dev/fb0";
|
||||
}
|
||||
|
||||
void QEglFSHooks::platformInit()
|
||||
{
|
||||
Q_UNUSED(hooks);
|
||||
|
|
@ -62,6 +67,39 @@ EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
|||
return EGL_DEFAULT_DISPLAY;
|
||||
}
|
||||
|
||||
QSizeF QEglFSHooks::physicalScreenSize() const
|
||||
{
|
||||
static QSizeF size;
|
||||
if (size.isEmpty()) {
|
||||
|
||||
// Note: in millimeters
|
||||
int width = qgetenv("QT_QPA_EGLFS_PHYSICAL_WIDTH").toInt();
|
||||
int height = qgetenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT").toInt();
|
||||
|
||||
if (width && height) {
|
||||
// no need to read fb0
|
||||
size.setWidth(width);
|
||||
size.setHeight(height);
|
||||
return size;
|
||||
}
|
||||
|
||||
struct fb_var_screeninfo vinfo;
|
||||
int fd = open(fbDeviceName(), O_RDONLY);
|
||||
|
||||
if (fd != -1) {
|
||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||
qWarning("Could not query variable screen info.");
|
||||
else
|
||||
size = QSizeF(vinfo.width, vinfo.height);
|
||||
|
||||
close(fd);
|
||||
} else {
|
||||
qWarning("Failed to open %s to detect screen size.", fbDeviceName());
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
QSize QEglFSHooks::screenSize() const
|
||||
{
|
||||
static QSize size;
|
||||
|
|
@ -78,7 +116,7 @@ QSize QEglFSHooks::screenSize() const
|
|||
}
|
||||
|
||||
struct fb_var_screeninfo vinfo;
|
||||
int fd = open("/dev/fb0", O_RDONLY);
|
||||
int fd = open(fbDeviceName(), O_RDONLY);
|
||||
|
||||
if (fd != -1) {
|
||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||
|
|
@ -88,7 +126,7 @@ QSize QEglFSHooks::screenSize() const
|
|||
|
||||
close(fd);
|
||||
} else {
|
||||
qWarning("Failed to open /dev/fb0 to detect screen resolution.");
|
||||
qWarning("Failed to open %s to detect screen depth.", fbDeviceName());
|
||||
}
|
||||
|
||||
// override fb0 from environment var setting
|
||||
|
|
@ -107,7 +145,7 @@ int QEglFSHooks::screenDepth() const
|
|||
|
||||
if (depth == 0) {
|
||||
struct fb_var_screeninfo vinfo;
|
||||
int fd = open("/dev/fb0", O_RDONLY);
|
||||
int fd = open(fbDeviceName(), O_RDONLY);
|
||||
|
||||
if (fd != -1) {
|
||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||
|
|
@ -117,7 +155,7 @@ int QEglFSHooks::screenDepth() const
|
|||
|
||||
close(fd);
|
||||
} else {
|
||||
qWarning("Failed to open /dev/fb0 to detect screen depth.");
|
||||
qWarning("Failed to open %s to detect screen depth.", fbDeviceName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ QImage::Format QEglFSScreen::format() const
|
|||
return hooks->screenFormat();
|
||||
}
|
||||
|
||||
QSizeF QEglFSScreen::physicalSize() const
|
||||
{
|
||||
return hooks->physicalScreenSize();
|
||||
}
|
||||
|
||||
QPlatformCursor *QEglFSScreen::cursor() const
|
||||
{
|
||||
return m_cursor;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ public:
|
|||
int depth() const;
|
||||
QImage::Format format() const;
|
||||
|
||||
QSizeF physicalSize() const;
|
||||
|
||||
QPlatformCursor *cursor() const;
|
||||
|
||||
EGLDisplay display() const { return m_dpy; }
|
||||
|
|
|
|||
Loading…
Reference in New Issue