diff options
Diffstat (limited to 'mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp')
-rw-r--r-- | mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp | 120 |
1 files changed, 62 insertions, 58 deletions
diff --git a/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp b/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp index 2329bf1eb0..78a1eb183e 100644 --- a/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp +++ b/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp @@ -43,12 +43,17 @@ #include <ui/DisplayInfo.h> #include <ui/FramebufferNativeWindow.h> -#include <gui/SurfaceComposerClient.h> #include <fcntl.h> #include <unistd.h> #include <linux/fb.h> #include <sys/ioctl.h> +#if Q_ANDROID_VERSION_MAJOR > 4 || (Q_ANDROID_VERSION_MAJOR == 4 && Q_ANDROID_VERSION_MINOR >= 1) +#include <gui/SurfaceComposerClient.h> +#else +#include <surfaceflinger/SurfaceComposerClient.h> +#endif + using namespace android; QT_BEGIN_NAMESPACE @@ -56,17 +61,61 @@ QT_BEGIN_NAMESPACE 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); + EGLNativeWindowType createNativeWindowFramebuffer(const QSize &size, const QSurfaceFormat &format); + + void ensureFramebufferNativeWindowCreated(); + // androidy things sp<android::SurfaceComposerClient> mSession; sp<android::SurfaceControl> mControl; sp<android::Surface> mAndroidSurface; + + sp<android::FramebufferNativeWindow> mFramebufferNativeWindow; + EGLint mFramebufferVisualId; + + bool mUseFramebuffer; }; -EGLNativeWindowType QEglFSPandaHooks::createNativeWindow(const QSize &size, const QSurfaceFormat &) +QEglFSPandaHooks::QEglFSPandaHooks() + : mFramebufferVisualId(EGL_DONT_CARE) +{ + mUseFramebuffer = qgetenv("QT_QPA_EGLFS_NO_SURFACEFLINGER").toInt(); +} + +void QEglFSPandaHooks::ensureFramebufferNativeWindowCreated() +{ + if (mFramebufferNativeWindow.get()) + return; + mFramebufferNativeWindow = new FramebufferNativeWindow(); + framebuffer_device_t const *fbDev = mFramebufferNativeWindow->getDevice(); + if (!fbDev) + qFatal("Failed to get valid FramebufferNativeWindow, no way to create EGL surfaces"); + + ANativeWindow *window = mFramebufferNativeWindow.get(); + + window->query(window, NATIVE_WINDOW_FORMAT, &mFramebufferVisualId); +} + +EGLNativeWindowType QEglFSPandaHooks::createNativeWindow(const QSize &size, const QSurfaceFormat &format) +{ + return mUseFramebuffer ? createNativeWindowFramebuffer(size, format) : createNativeWindowSurfaceFlinger(size, format); +} + +EGLNativeWindowType QEglFSPandaHooks::createNativeWindowFramebuffer(const QSize &size, const QSurfaceFormat &) +{ + Q_UNUSED(size); + ensureFramebufferNativeWindowCreated(); + return mFramebufferNativeWindow.get(); +} + +EGLNativeWindowType QEglFSPandaHooks::createNativeWindowSurfaceFlinger(const QSize &size, const QSurfaceFormat &) { Q_UNUSED(size); @@ -85,66 +134,21 @@ EGLNativeWindowType QEglFSPandaHooks::createNativeWindow(const QSize &size, cons EGLNativeWindowType eglWindow = mAndroidSurface.get(); return eglWindow; } -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 +bool QEglFSPandaHooks::filterConfig(EGLDisplay display, EGLConfig config) const { - static int depth = qgetenv("QT_QPA_EGLFS_DEPTH").toInt(); + if (!mUseFramebuffer) + return true; - if (depth == 0) { - struct fb_var_screeninfo vinfo; - int fd = open("/dev/graphics/fb0", O_RDONLY); + const_cast<QEglFSPandaHooks *>(this)->ensureFramebufferNativeWindowCreated(); - if (fd != -1) { - if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) - qWarning("Could not query variable screen info."); - else - depth = vinfo.bits_per_pixel; + if (mFramebufferVisualId == EGL_DONT_CARE) + return true; - close(fd); - } else { - qWarning("Failed to open /dev/graphics/fb0 to detect screen depth."); - } - } + EGLint nativeVisualId = 0; + eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId); - return depth == 0 ? 32 : depth; + return nativeVisualId == mFramebufferVisualId; } static QEglFSPandaHooks eglFSPandaHooks; |