From 328f2f9c35f3cc5e7049a060a608c3f72876484a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 6 Jan 2014 14:51:37 +0100 Subject: eglfs: Move reusable functionality to eglconvenience MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cursor implementation is generic GL(ES) code that should be shared by all the present and future egl-based embedded platform plugins. Follow the pattern of QEGLPlatformContext and move this class into eglconvenience as QEGLPlatformCursor. Similarly, the common bits from the context implementation context are moved back to EGLPlatformContext. eglconvenience has now base classes for integration, screen, window, etc. too. By using these, eglfs becomes much smaller and cleaner. This also paves the way for creating new, separate EGL-based platform plugins for Android, embedded Linux, etc. Also added some documentation to each of the base classes. devicediscovery is now fixed to be usable on any platform. The implementation in this case is naturally a dummy one. This finally allows using it from anywhere without myriads of ugly ifdefs. Change-Id: I02946e360c04e02de7fe234a23a08320eff4ccf5 Reviewed-by: Jørgen Lind --- .../eglconvenience/qeglconvenience.cpp | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'src/platformsupport/eglconvenience/qeglconvenience.cpp') diff --git a/src/platformsupport/eglconvenience/qeglconvenience.cpp b/src/platformsupport/eglconvenience/qeglconvenience.cpp index fe6ba2b215..6c2cc4a186 100644 --- a/src/platformsupport/eglconvenience/qeglconvenience.cpp +++ b/src/platformsupport/eglconvenience/qeglconvenience.cpp @@ -41,6 +41,12 @@ #include +#ifdef Q_OS_UNIX +#include +#include +#include +#endif + #include "qeglconvenience_p.h" QT_BEGIN_NAMESPACE @@ -427,4 +433,106 @@ void q_printEglConfig(EGLDisplay display, EGLConfig config) qWarning("\n"); } +#ifdef Q_OS_UNIX + +QSizeF q_physicalScreenSizeFromFb(int framebufferDevice) +{ + const int defaultPhysicalDpi = 100; + 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) { + size.setWidth(width); + size.setHeight(height); + return size; + } + + struct fb_var_screeninfo vinfo; + int w = -1; + int h = -1; + QSize screenResolution; + + if (framebufferDevice != -1) { + if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("eglconvenience: Could not query screen info"); + } else { + w = vinfo.width; + h = vinfo.height; + screenResolution = QSize(vinfo.xres, vinfo.yres); + } + } else { + screenResolution = q_screenSizeFromFb(framebufferDevice); + } + + size.setWidth(w <= 0 ? screenResolution.width() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); + size.setHeight(h <= 0 ? screenResolution.height() * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); + } + + return size; +} + +QSize q_screenSizeFromFb(int framebufferDevice) +{ + const int defaultWidth = 800; + const int defaultHeight = 600; + 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) { + size.setWidth(width); + size.setHeight(height); + return size; + } + + struct fb_var_screeninfo vinfo; + int xres = -1; + int yres = -1; + + if (framebufferDevice != -1) { + if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("eglconvenience: Could not read screen info"); + } else { + xres = vinfo.xres; + yres = vinfo.yres; + } + } + + size.setWidth(xres <= 0 ? defaultWidth : xres); + size.setHeight(yres <= 0 ? defaultHeight : yres); + } + + return size; +} + +int q_screenDepthFromFb(int framebufferDevice) +{ + const int defaultDepth = 32; + static int depth = qgetenv("QT_QPA_EGLFS_DEPTH").toInt(); + + if (depth == 0) { + struct fb_var_screeninfo vinfo; + + if (framebufferDevice != -1) { + if (ioctl(framebufferDevice, FBIOGET_VSCREENINFO, &vinfo) == -1) + qWarning("eglconvenience: Could not query screen info"); + else + depth = vinfo.bits_per_pixel; + } + + if (depth <= 0) + depth = defaultDepth; + } + + return depth; +} + +#endif // Q_OS_UNIX + QT_END_NAMESPACE -- cgit v1.2.3