diff options
Diffstat (limited to 'mkspecs/unsupported/android-g++')
-rw-r--r-- | mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp | 71 | ||||
-rw-r--r-- | mkspecs/unsupported/android-g++/qmake.conf | 9 |
2 files changed, 77 insertions, 3 deletions
diff --git a/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp b/mkspecs/unsupported/android-g++/qeglfshooks_surfaceflinger.cpp index 2329bf1eb0..689300dbde 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,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<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,6 +135,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<QEglFSPandaHooks *>(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..29cc709cb9 100644 --- a/mkspecs/unsupported/android-g++/qmake.conf +++ b/mkspecs/unsupported/android-g++/qmake.conf @@ -18,11 +18,13 @@ defineReplace(getAndroidBuildVar) { store_ANDROID_TARGET_CFLAGS = "ANDROID_TARGET_CFLAGS=$$getAndroidBuildVar(TARGET_GLOBAL_CFLAGS)" store_ANDROID_TARGET_LDFLAGS = "ANDROID_TARGET_LDFLAGS=$$getAndroidBuildVar(TARGET_GLOBAL_LDFLAGS)" store_ANDROID_TARGET_ARCH = "ANDROID_TARGET_ARCH=$$getAndroidBuildVar(TARGET_ARCH)" + store_ANDROID_VERSION = "ANDROID_VERSION=$$getAndroidBuildVar(PLATFORM_VERSION)" write_file(android_build_vars, store_ANDROID_TOOLCHAIN_PREFIX) write_file(android_build_vars, store_ANDROID_TARGET_CFLAGS, append) write_file(android_build_vars, store_ANDROID_TARGET_LDFLAGS, append) write_file(android_build_vars, store_ANDROID_TARGET_ARCH, append) + write_file(android_build_vars, store_ANDROID_VERSION, append) } info(using android build env from cache in $$PWD/android_build_vars . delete this file if you changed your build env ) @@ -30,6 +32,9 @@ exists($$PWD/android_build_vars) { include($$PWD/android_build_vars) } +ANDROID_VERSION_SPLIT = $$split(ANDROID_VERSION, ".") +ANDROID_VERSION_MAJOR = $$member(ANDROID_VERSION_SPLIT, 0) +ANDROID_VERSION_MINOR = $$member(ANDROID_VERSION_SPLIT, 1) MAKEFILE_GENERATOR = UNIX QMAKE_COMPILER = gcc @@ -43,6 +48,8 @@ include(../../common/gcc-base-unix.conf) CONFIG = qt warn_on release link_prl QT = core gui DEFINES += Q_OS_LINUX_ANDROID HAVE_ANDROID_OS +DEFINES += Q_ANDROID_VERSION_MAJOR=$$ANDROID_VERSION_MAJOR +DEFINES += Q_ANDROID_VERSION_MINOR=$$ANDROID_VERSION_MINOR DEFINES += QT_NO_PRINTER QT_NO_PRINTDIALOG QT_NO_EXCEPTIONS #note: -DANDROID results in weird behaviour of math.h @@ -50,7 +57,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 |