From 01d5c6c949e3cc6e83a7e4ad91c9336fd8bca82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 25 Oct 2012 17:10:03 +0200 Subject: Android-eglfs: Added support for non-composited rendering. By using FramebufferNativeWindow Qt can render directly without going through the SurfaceFlinger compositor. Change-Id: I0538fca9f2e905c076ff5837dd73589ee9c632ca Reviewed-by: Gunnar Sletta --- .../android-g++/qeglfshooks_surfaceflinger.cpp | 64 +++++++++++++++++++++- mkspecs/unsupported/android-g++/qmake.conf | 2 +- 2 files changed, 64 insertions(+), 2 deletions(-) (limited to 'mkspecs') diff --git a/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp b/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp index cef1d1ccbe..0a71a5fe12 100644 --- a/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp +++ b/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp @@ -56,17 +56,62 @@ 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; + private: + EGLNativeWindowType createNativeWindowSurfaceFlinger(const QSize &size, const QSurfaceFormat &format); + EGLNativeWindowType createNativeWindowFramebuffer(const QSize &size, const QSurfaceFormat &format); + + void ensureFramebufferNativeWindowCreated(); + // androidy things sp mSession; sp mControl; sp mAndroidSurface; + + sp 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,6 +130,23 @@ EGLNativeWindowType QEglFSPandaHooks::createNativeWindow(const QSize &size, cons EGLNativeWindowType eglWindow = mAndroidSurface.get(); return eglWindow; } + +bool QEglFSPandaHooks::filterConfig(EGLDisplay display, EGLConfig config) const +{ + if (!mUseFramebuffer) + return true; + + const_cast(this)->ensureFramebufferNativeWindowCreated(); + + if (mFramebufferVisualId == EGL_DONT_CARE) + return true; + + EGLint nativeVisualId = 0; + eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId); + + return nativeVisualId == mFramebufferVisualId; +} + QSize QEglFSPandaHooks::screenSize() const { static QSize size; diff --git a/mkspecs/unsupported/android-g++/qmake.conf b/mkspecs/unsupported/android-g++/qmake.conf index 8e0af9268d..7bd8f15b57 100644 --- a/mkspecs/unsupported/android-g++/qmake.conf +++ b/mkspecs/unsupported/android-g++/qmake.conf @@ -50,7 +50,7 @@ DEFINES += ANDROID QT_QPA_DEFAULT_PLATFORM = eglfs EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/qeglfshooks_surfaceflinger.cpp -EGLFS_PLATFORM_HOOKS_LIBS += -lgui -lutils +EGLFS_PLATFORM_HOOKS_LIBS += -lui -lgui -lutils -lcutils QMAKE_CC = $${ANDROID_TOOLCHAIN_PREFIX}gcc -- cgit v1.2.3