diff options
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r-- | src/plugins/platforms/android/android.json (renamed from src/plugins/platforms/android/src/android.json) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/android.pro | 81 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniaccessibility.cpp (renamed from src/plugins/platforms/android/src/androidjniaccessibility.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniaccessibility.h (renamed from src/plugins/platforms/android/src/androidjniaccessibility.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniclipboard.cpp (renamed from src/plugins/platforms/android/src/androidjniclipboard.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniclipboard.h (renamed from src/plugins/platforms/android/src/androidjniclipboard.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.cpp (renamed from src/plugins/platforms/android/src/androidjniinput.cpp) | 9 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.h (renamed from src/plugins/platforms/android/src/androidjniinput.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjnimain.cpp (renamed from src/plugins/platforms/android/src/androidjnimain.cpp) | 380 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjnimain.h (renamed from src/plugins/platforms/android/src/androidjnimain.h) | 22 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjnimenu.cpp (renamed from src/plugins/platforms/android/src/androidjnimenu.cpp) | 18 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidjnimenu.h (renamed from src/plugins/platforms/android/src/androidjnimenu.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidplatformplugin.cpp (renamed from src/plugins/platforms/android/src/androidplatformplugin.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/androidsurfaceclient.h (renamed from src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h) | 24 | ||||
-rw-r--r-- | src/plugins/platforms/android/opengl/opengl.pro | 32 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp (renamed from src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidassetsfileenginehandler.h (renamed from src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp (renamed from src/plugins/platforms/android/src/qandroidinputcontext.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.h (renamed from src/plugins/platforms/android/src/qandroidinputcontext.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformaccessibility.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformaccessibility.h (renamed from src/plugins/platforms/android/src/qandroidplatformaccessibility.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformbackingstore.cpp | 78 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformbackingstore.h (renamed from src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp) | 31 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformclipboard.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformclipboard.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformclipboard.h (renamed from src/plugins/platforms/android/src/qandroidplatformclipboard.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp) | 51 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformdialoghelpers.h (renamed from src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformfontdatabase.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformfontdatabase.h (renamed from src/plugins/platforms/android/src/qandroidplatformfontdatabase.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformintegration.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformintegration.cpp) | 157 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformintegration.h (renamed from src/plugins/platforms/android/src/qandroidplatformintegration.h) | 41 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenu.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformmenu.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenu.h (renamed from src/plugins/platforms/android/src/qandroidplatformmenu.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenubar.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformmenubar.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenubar.h (renamed from src/plugins/platforms/android/src/qandroidplatformmenubar.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenuitem.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformmenuitem.h (renamed from src/plugins/platforms/android/src/qandroidplatformmenuitem.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglcontext.cpp (renamed from src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp) | 49 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglcontext.h (renamed from src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h) | 22 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglwindow.cpp | 160 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglwindow.h (renamed from src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h) | 64 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformrasterwindow.cpp | 78 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformrasterwindow.h | 70 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformscreen.cpp | 352 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformscreen.h (renamed from src/plugins/platforms/android/src/raster/qandroidplatformscreen.h) | 68 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformservices.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformservices.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformservices.h (renamed from src/plugins/platforms/android/src/qandroidplatformservices.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformtheme.cpp (renamed from src/plugins/platforms/android/src/qandroidplatformtheme.cpp) | 16 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformtheme.h (renamed from src/plugins/platforms/android/src/qandroidplatformtheme.h) | 1 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformwindow.cpp (renamed from src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp) | 111 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformwindow.h (renamed from src/plugins/platforms/android/src/raster/qandroidplatformwindow.h) | 39 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidsystemlocale.cpp (renamed from src/plugins/platforms/android/src/qandroidsystemlocale.cpp) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidsystemlocale.h (renamed from src/plugins/platforms/android/src/qandroidsystemlocale.h) | 0 | ||||
-rw-r--r-- | src/plugins/platforms/android/raster/raster.pro | 19 | ||||
-rw-r--r-- | src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp | 178 | ||||
-rw-r--r-- | src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp | 161 | ||||
-rw-r--r-- | src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp | 94 | ||||
-rw-r--r-- | src/plugins/platforms/android/src/raster/raster.pri | 7 | ||||
-rw-r--r-- | src/plugins/platforms/android/src/src.pri | 55 |
59 files changed, 1297 insertions, 1171 deletions
diff --git a/src/plugins/platforms/android/src/android.json b/src/plugins/platforms/android/android.json index 6843bd3301..6843bd3301 100644 --- a/src/plugins/platforms/android/src/android.json +++ b/src/plugins/platforms/android/android.json diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index aa5ab4ddbd..4d873dd986 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -1,3 +1,80 @@ -TEMPLATE = subdirs +TARGET = qtforandroid -SUBDIRS += raster opengl +PLUGIN_TYPE = platforms + +# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp +# Yes, the plugin imports itself statically +DEFINES += QT_STATICPLUGIN + +load(qt_plugin) + +!contains(ANDROID_PLATFORM, android-9) { + INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include + LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid +} else { + LIBS += -ljnigraphics -landroid +} + +QT += core-private gui-private platformsupport-private + +CONFIG += qpa/genericunixfontdatabase + +OTHER_FILES += $$PWD/android.json + +INCLUDEPATH += $$PWD + +SOURCES += $$PWD/androidplatformplugin.cpp \ + $$PWD/androidjnimain.cpp \ + $$PWD/androidjniaccessibility.cpp \ + $$PWD/androidjniinput.cpp \ + $$PWD/androidjnimenu.cpp \ + $$PWD/androidjniclipboard.cpp \ + $$PWD/qandroidplatformintegration.cpp \ + $$PWD/qandroidplatformservices.cpp \ + $$PWD/qandroidassetsfileenginehandler.cpp \ + $$PWD/qandroidinputcontext.cpp \ + $$PWD/qandroidplatformaccessibility.cpp \ + $$PWD/qandroidplatformfontdatabase.cpp \ + $$PWD/qandroidplatformdialoghelpers.cpp \ + $$PWD/qandroidplatformclipboard.cpp \ + $$PWD/qandroidplatformtheme.cpp \ + $$PWD/qandroidplatformmenubar.cpp \ + $$PWD/qandroidplatformmenu.cpp \ + $$PWD/qandroidplatformmenuitem.cpp \ + $$PWD/qandroidsystemlocale.cpp \ + $$PWD/qandroidplatformscreen.cpp \ + $$PWD/qandroidplatformwindow.cpp \ + $$PWD/qandroidplatformopenglwindow.cpp \ + $$PWD/qandroidplatformrasterwindow.cpp \ + $$PWD/qandroidplatformbackingstore.cpp \ + $$PWD/qandroidplatformopenglcontext.cpp + +HEADERS += $$PWD/qandroidplatformintegration.h \ + $$PWD/androidjnimain.h \ + $$PWD/androidjniaccessibility.h \ + $$PWD/androidjniinput.h \ + $$PWD/androidjnimenu.h \ + $$PWD/androidjniclipboard.h \ + $$PWD/qandroidplatformservices.h \ + $$PWD/qandroidassetsfileenginehandler.h \ + $$PWD/qandroidinputcontext.h \ + $$PWD/qandroidplatformaccessibility.h \ + $$PWD/qandroidplatformfontdatabase.h \ + $$PWD/qandroidplatformclipboard.h \ + $$PWD/qandroidplatformdialoghelpers.h \ + $$PWD/qandroidplatformtheme.h \ + $$PWD/qandroidplatformmenubar.h \ + $$PWD/qandroidplatformmenu.h \ + $$PWD/qandroidplatformmenuitem.h \ + $$PWD/qandroidsystemlocale.h \ + $$PWD/androidsurfaceclient.h \ + $$PWD/qandroidplatformscreen.h \ + $$PWD/qandroidplatformwindow.h \ + $$PWD/qandroidplatformopenglwindow.h \ + $$PWD/qandroidplatformrasterwindow.h \ + $$PWD/qandroidplatformbackingstore.h \ + $$PWD/qandroidplatformopenglcontext.h + +#Non-standard install directory, QTBUG-29859 +DESTDIR = $$DESTDIR/android +target.path = $${target.path}/android diff --git a/src/plugins/platforms/android/src/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index b987c49c9c..b987c49c9c 100644 --- a/src/plugins/platforms/android/src/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp diff --git a/src/plugins/platforms/android/src/androidjniaccessibility.h b/src/plugins/platforms/android/androidjniaccessibility.h index e708138c33..e708138c33 100644 --- a/src/plugins/platforms/android/src/androidjniaccessibility.h +++ b/src/plugins/platforms/android/androidjniaccessibility.h diff --git a/src/plugins/platforms/android/src/androidjniclipboard.cpp b/src/plugins/platforms/android/androidjniclipboard.cpp index 05270ac374..05270ac374 100644 --- a/src/plugins/platforms/android/src/androidjniclipboard.cpp +++ b/src/plugins/platforms/android/androidjniclipboard.cpp diff --git a/src/plugins/platforms/android/src/androidjniclipboard.h b/src/plugins/platforms/android/androidjniclipboard.h index 15cd93202e..15cd93202e 100644 --- a/src/plugins/platforms/android/src/androidjniclipboard.h +++ b/src/plugins/platforms/android/androidjniclipboard.h diff --git a/src/plugins/platforms/android/src/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 8ce95532d3..55d44b7377 100644 --- a/src/plugins/platforms/android/src/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -471,6 +471,9 @@ namespace QtAndroidInput case 0x000000ba: // KEYCODE_PROG_BLUE return Qt::Key_Blue; + case 0x000000a5: // KEYCODE_INFO + return Qt::Key_Info; + case 0x000000a6: // KEYCODE_CHANNEL_UP return Qt::Key_ChannelUp; @@ -483,9 +486,15 @@ namespace QtAndroidInput case 0x000000a9: // KEYCODE_ZOOM_OUT return Qt::Key_ZoomOut; + case 0x000000ac: // KEYCODE_GUIDE + return Qt::Key_Guide; + case 0x000000af: // KEYCODE_CAPTIONS return Qt::Key_Subtitle; + case 0x000000b0: // KEYCODE_SETTINGS + return Qt::Key_Settings; + case 0x000000d0: // KEYCODE_CALENDAR return Qt::Key_Calendar; diff --git a/src/plugins/platforms/android/src/androidjniinput.h b/src/plugins/platforms/android/androidjniinput.h index a78c7519db..a78c7519db 100644 --- a/src/plugins/platforms/android/src/androidjniinput.h +++ b/src/plugins/platforms/android/androidjniinput.h diff --git a/src/plugins/platforms/android/src/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 3064e5d4e2..ee62c002d8 100644 --- a/src/plugins/platforms/android/src/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -53,6 +53,7 @@ #include <qdebug.h> #include <qglobal.h> #include <qobjectdefs.h> +#include <QtCore/private/qjni_p.h> #include <stdlib.h> #include "androidjnimain.h" @@ -73,14 +74,6 @@ #include <qpa/qwindowsysteminterface.h> -#ifdef ANDROID_PLUGIN_OPENGL -# include "qandroidopenglplatformwindow.h" -#endif - -#include <android/native_window_jni.h> - -static jmethodID m_redrawSurfaceMethodID = 0; - Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin) static JavaVM *m_javaVM = NULL; @@ -90,6 +83,9 @@ static jmethodID m_loadClassMethodID = NULL; static AAssetManager *m_assetManager = NULL; static jobject m_resourcesObj; static jobject m_activityObject = NULL; +static jmethodID m_createSurfaceMethodID = 0; +static jmethodID m_setSurfaceGeometryMethodID = 0; +static jmethodID m_destroySurfaceMethodID = 0; static bool m_activityActive = true; // defaults to true because when the platform plugin is // initialized, QtActivity::onResume() has already been called @@ -110,17 +106,19 @@ static Main m_main = NULL; static void *m_mainLibraryHnd = NULL; static QList<QByteArray> m_applicationParams; -#ifndef ANDROID_PLUGIN_OPENGL -static jobject m_surface = NULL; -#else -static EGLNativeWindowType m_nativeWindow = 0; -static QSemaphore m_waitForWindowSemaphore; -static bool m_waitForWindow = false; -#endif +struct SurfaceData +{ + ~SurfaceData() { delete surface; } + QJNIObjectPrivate *surface = 0; + AndroidSurfaceClient *client = 0; +}; + +QHash<int, AndroidSurfaceClient *> m_surfaces; +static QMutex m_surfacesMutex; +static int m_surfaceId = 1; static QSemaphore m_quitAppSemaphore; -static QMutex m_surfaceMutex(QMutex::Recursive); static QSemaphore m_pauseApplicationSemaphore; static QMutex m_pauseApplicationMutex; @@ -140,128 +138,18 @@ static const char m_qtTag[] = "Qt"; static const char m_classErrorMsg[] = "Can't find class \"%s\""; static const char m_methodErrorMsg[] = "Can't find method \"%s%s\""; -static inline void checkPauseApplication() -{ - m_pauseApplicationMutex.lock(); - if (m_pauseApplication) { - m_pauseApplicationMutex.unlock(); - m_pauseApplicationSemaphore.acquire(); // wait until surface is created - - m_pauseApplicationMutex.lock(); - m_pauseApplication = false; - m_pauseApplicationMutex.unlock(); - - //FIXME -// QWindowSystemInterface::handleScreenAvailableGeometryChange(0); -// QWindowSystemInterface::handleScreenGeometryChange(0); - } else { - m_pauseApplicationMutex.unlock(); - } -} - namespace QtAndroid { -#ifndef ANDROID_PLUGIN_OPENGL - void flushImage(const QPoint &pos, const QImage &image, const QRect &destinationRect) - { - checkPauseApplication(); - QMutexLocker locker(&m_surfaceMutex); - if (!m_surface) - return; - AttachedJNIEnv env; - if (!env.jniEnv) - return; - - int bpp = 2; - AndroidBitmapInfo info; - int ret; - - if ((ret = AndroidBitmap_getInfo(env.jniEnv, m_surface, &info)) < 0) { - qWarning() << "AndroidBitmap_getInfo() failed ! error=" << ret; - m_javaVM->DetachCurrentThread(); - return; - } - - if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) { - qWarning() << "Bitmap format is not RGB_565!"; - m_javaVM->DetachCurrentThread(); - return; - } - - void *pixels; - unsigned char *screenBits; - if ((ret = AndroidBitmap_lockPixels(env.jniEnv, m_surface, &pixels)) < 0) { - qWarning() << "AndroidBitmap_lockPixels() failed! error=" << ret; - m_javaVM->DetachCurrentThread(); - return; - } - - screenBits = static_cast<unsigned char *>(pixels); - int sbpl = info.stride; - int swidth = info.width; - int sheight = info.height; - - unsigned sposx = pos.x() + destinationRect.x(); - unsigned sposy = pos.y() + destinationRect.y(); - - screenBits += sposy * sbpl; - - unsigned ibpl = image.bytesPerLine(); - unsigned iposx = destinationRect.x(); - unsigned iposy = destinationRect.y(); - - const unsigned char *imageBits = static_cast<const unsigned char *>(image.bits()); - imageBits += iposy * ibpl; - - unsigned width = swidth - sposx < unsigned(destinationRect.width()) - ? (swidth-sposx) - : destinationRect.width(); - unsigned height = sheight - sposy < unsigned(destinationRect.height()) - ? (sheight - sposy) - : destinationRect.height(); - - for (unsigned y = 0; y < height; y++) { - memcpy(screenBits + y*sbpl + sposx*bpp, - imageBits + y*ibpl + iposx*bpp, - width*bpp); - } - AndroidBitmap_unlockPixels(env.jniEnv, m_surface); - - env.jniEnv->CallStaticVoidMethod(m_applicationClass, - m_redrawSurfaceMethodID, - jint(destinationRect.left()), - jint(destinationRect.top()), - jint(destinationRect.right() + 1), - jint(destinationRect.bottom() + 1)); -#warning FIXME dirty hack, figure out why it needs to add 1 to right and bottom !!!! - } - -#else // for #ifndef ANDROID_PLUGIN_OPENGL - EGLNativeWindowType nativeWindow(bool waitForWindow) - { - m_surfaceMutex.lock(); - if (!m_nativeWindow && waitForWindow) { - m_waitForWindow = true; - m_surfaceMutex.unlock(); - m_waitForWindowSemaphore.acquire(); - m_waitForWindow = false; - return m_nativeWindow; - } - m_surfaceMutex.unlock(); - return m_nativeWindow; - } -#endif - void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration) { - m_surfaceMutex.lock(); + m_surfacesMutex.lock(); m_androidPlatformIntegration = androidPlatformIntegration; - m_surfaceMutex.unlock(); + m_surfacesMutex.unlock(); } QAndroidPlatformIntegration *androidPlatformIntegration() { - QMutexLocker locker(&m_surfaceMutex); + QMutexLocker locker(&m_surfacesMutex); return m_androidPlatformIntegration; } @@ -353,14 +241,14 @@ namespace QtAndroid jobject createBitmap(QImage img, JNIEnv *env) { - if (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_RGB16) - img = img.convertToFormat(QImage::Format_ARGB32); + if (img.format() != QImage::Format_RGBA8888 && img.format() != QImage::Format_RGB16) + img = img.convertToFormat(QImage::Format_RGBA8888); jobject bitmap = env->CallStaticObjectMethod(m_bitmapClass, m_createBitmapMethodID, img.width(), img.height(), - img.format() == QImage::Format_ARGB32 + img.format() == QImage::Format_RGBA8888 ? m_ARGB_8888_BitmapConfigValue : m_RGB_565_BitmapConfigValue); if (!bitmap) @@ -393,6 +281,21 @@ namespace QtAndroid return bitmap; } + jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env) + { + if (format != QImage::Format_RGBA8888 + && format != QImage::Format_RGB16) + return 0; + + return env->CallStaticObjectMethod(m_bitmapClass, + m_createBitmapMethodID, + width, + height, + format == QImage::Format_RGB16 + ? m_RGB_565_BitmapConfigValue + : m_ARGB_8888_BitmapConfigValue); + } + jobject createBitmapDrawable(jobject bitmap, JNIEnv *env) { if (!bitmap) @@ -418,25 +321,74 @@ namespace QtAndroid { return m_qtTag; } + + int createSurface(AndroidSurfaceClient *client, const QRect &geometry, bool onTop) + { + QJNIEnvironmentPrivate env; + if (!env) + return 0; + + m_surfacesMutex.lock(); + int surfaceId = m_surfaceId++; + m_surfaces[surfaceId] = client; + m_surfacesMutex.unlock(); + + jint x = 0, y = 0, w = -1, h = -1; + if (!geometry.isNull()) { + x = geometry.x(); + y = geometry.y(); + w = std::max(geometry.width(), 1); + h = std::max(geometry.height(), 1); + } + env->CallStaticVoidMethod(m_applicationClass, + m_createSurfaceMethodID, + surfaceId, + jboolean(onTop), + x, y, w, h); + return surfaceId; + } + + void setSurfaceGeometry(int surfaceId, const QRect &geometry) + { + QJNIEnvironmentPrivate env; + if (!env) + return; + jint x = 0, y = 0, w = -1, h = -1; + if (!geometry.isNull()) { + x = geometry.x(); + y = geometry.y(); + w = geometry.width(); + h = geometry.height(); + } + env->CallStaticVoidMethod(m_applicationClass, + m_setSurfaceGeometryMethodID, + surfaceId, + x, y, w, h); + } + + void destroySurface(int surfaceId) + { + QMutexLocker lock(&m_surfacesMutex); + const auto &it = m_surfaces.find(surfaceId); + if (it == m_surfaces.end()) + return; + + m_surfaces.remove(surfaceId); + QJNIEnvironmentPrivate env; + if (!env) + return; + + env->CallStaticVoidMethod(m_applicationClass, + m_destroySurfaceMethodID, + surfaceId); + } } static jboolean startQtAndroidPlugin(JNIEnv* /*env*/, jobject /*object*//*, jobject applicationAssetManager*/) { -#ifndef ANDROID_PLUGIN_OPENGL - m_surface = 0; -#else - m_nativeWindow = 0; - m_waitForWindow = false; -#endif - m_androidPlatformIntegration = 0; m_androidAssetsFileEngineHandler = new AndroidAssetsFileEngineHandler(); - -#ifdef ANDROID_PLUGIN_OPENGL return true; -#else - return false; -#endif } static void *startMainMethod(void */*data*/) @@ -512,54 +464,16 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para return pthread_create(&appThread, NULL, startMainMethod, NULL) == 0; } -static void pauseQtApp(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); - m_pauseApplicationMutex.lock(); - - if (m_androidPlatformIntegration) - m_androidPlatformIntegration->pauseApp(); - m_pauseApplication = true; - - m_pauseApplicationMutex.unlock(); - m_surfaceMutex.unlock(); -} - -static void resumeQtApp(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); - m_pauseApplicationMutex.lock(); - if (m_androidPlatformIntegration) - m_androidPlatformIntegration->resumeApp(); - - if (m_pauseApplication) - m_pauseApplicationSemaphore.release(); - - m_pauseApplicationMutex.unlock(); - m_surfaceMutex.unlock(); -} static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) { -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) { - env->DeleteGlobalRef(m_surface); - m_surface = 0; - } -#else Q_UNUSED(env); -#endif - m_androidPlatformIntegration = 0; delete m_androidAssetsFileEngineHandler; } static void terminateQt(JNIEnv *env, jclass /*clazz*/) { -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) - env->DeleteGlobalRef(m_surface); -#endif env->DeleteGlobalRef(m_applicationClass); env->DeleteGlobalRef(m_classLoaderObject); env->DeleteGlobalRef(m_resourcesObj); @@ -568,76 +482,19 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) env->DeleteGlobalRef(m_ARGB_8888_BitmapConfigValue); env->DeleteGlobalRef(m_RGB_565_BitmapConfigValue); env->DeleteGlobalRef(m_bitmapDrawableClass); + m_androidPlatformIntegration = 0; + delete m_androidAssetsFileEngineHandler; } -static void setSurface(JNIEnv *env, jobject /*thiz*/, jobject jSurface) -{ -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) - env->DeleteGlobalRef(m_surface); - m_surface = env->NewGlobalRef(jSurface); -#else - m_surfaceMutex.lock(); - EGLNativeWindowType nativeWindow = ANativeWindow_fromSurface(env, jSurface); - bool sameNativeWindow = (nativeWindow != 0 && nativeWindow == m_nativeWindow); - - m_nativeWindow = nativeWindow; - if (m_waitForWindow) - m_waitForWindowSemaphore.release(); - - if (m_androidPlatformIntegration) { - // Use the desktop size. - // On some devices, the getters for the native window size gives wrong values - QSize size = QAndroidPlatformIntegration::defaultDesktopSize(); - - QPlatformScreen *screen = m_androidPlatformIntegration->screen(); - QRect geometry(QPoint(0, 0), size); - if (screen) { - QWindowSystemInterface::handleScreenAvailableGeometryChange(screen->screen(), geometry); - QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), geometry); - } - - if (!sameNativeWindow) { - m_surfaceMutex.unlock(); - m_androidPlatformIntegration->surfaceChanged(); - } else { - // Resize all top level windows, since they share the same surface - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast<QAndroidOpenGLPlatformWindow *>(w->handle()); - - if (window != 0) { - window->lock(); - window->scheduleResize(size); - - QWindowSystemInterface::handleExposeEvent(window->window(), - QRegion(window->window()->geometry())); - window->unlock(); - } - } - - m_surfaceMutex.unlock(); - } - - } else { - m_surfaceMutex.unlock(); - } -#endif // for #ifndef ANDROID_PLUGIN_OPENGL -} - -static void destroySurface(JNIEnv *env, jobject /*thiz*/) +static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, jint w, jint h) { -#ifndef ANDROID_PLUGIN_OPENGL - if (m_surface) { - env->DeleteGlobalRef(m_surface); - m_surface = 0; + QMutexLocker lock(&m_surfacesMutex); + const auto &it = m_surfaces.find(id); + if (it == m_surfaces.end()) { + qWarning()<<"Can't find surface" << id; + return; } -#else - Q_UNUSED(env); - m_nativeWindow = 0; - if (m_androidPlatformIntegration != 0) - m_androidPlatformIntegration->invalidateNativeSurface(); -#endif + it.value()->surfaceChanged(env, jSurface, w, h); } static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, @@ -660,16 +517,6 @@ static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, } } -static void lockSurface(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.lock(); -} - -static void unlockSurface(JNIEnv */*env*/, jobject /*thiz*/) -{ - m_surfaceMutex.unlock(); -} - static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/) { if (!m_androidPlatformIntegration) @@ -680,12 +527,8 @@ static void updateWindow(JNIEnv */*env*/, jobject /*thiz*/) QWindowSystemInterface::handleExposeEvent(w, QRegion(w->geometry())); } -#ifndef ANDROID_PLUGIN_OPENGL QAndroidPlatformScreen *screen = static_cast<QAndroidPlatformScreen *>(m_androidPlatformIntegration->screen()); QMetaObject::invokeMethod(screen, "setDirty", Qt::QueuedConnection, Q_ARG(QRect,screen->geometry())); -#else - qWarning("updateWindow: Dirty screen not implemented yet on OpenGL"); -#endif } static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state) @@ -734,15 +577,10 @@ static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint new static JNINativeMethod methods[] = { {"startQtAndroidPlugin", "()Z", (void *)startQtAndroidPlugin}, {"startQtApplication", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)startQtApplication}, - {"pauseQtApp", "()V", (void *)pauseQtApp}, - {"resumeQtApp", "()V", (void *)resumeQtApp}, {"quitQtAndroidPlugin", "()V", (void *)quitQtAndroidPlugin}, {"terminateQt", "()V", (void *)terminateQt}, {"setDisplayMetrics", "(IIIIDDD)V", (void *)setDisplayMetrics}, - {"setSurface", "(Ljava/lang/Object;)V", (void *)setSurface}, - {"destroySurface", "()V", (void *)destroySurface}, - {"lockSurface", "()V", (void *)lockSurface}, - {"unlockSurface", "()V", (void *)unlockSurface}, + {"setSurface", "(ILjava/lang/Object;II)V", (void *)setSurface}, {"updateWindow", "()V", (void *)updateWindow}, {"updateApplicationState", "(I)V", (void *)updateApplicationState}, {"handleOrientationChanged", "(II)V", (void *)handleOrientationChanged} @@ -795,7 +633,9 @@ static int registerNatives(JNIEnv *env) return JNI_FALSE; } - GET_AND_CHECK_STATIC_METHOD(m_redrawSurfaceMethodID, m_applicationClass, "redrawSurface", "(IIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_createSurfaceMethodID, m_applicationClass, "createSurface", "(IZIIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_setSurfaceGeometryMethodID, m_applicationClass, "setSurfaceGeometry", "(IIIII)V"); + GET_AND_CHECK_STATIC_METHOD(m_destroySurfaceMethodID, m_applicationClass, "destroySurface", "(I)V"); jmethodID methodID; GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "activity", "()Landroid/app/Activity;"); diff --git a/src/plugins/platforms/android/src/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h index 11d3573404..24287df474 100644 --- a/src/plugins/platforms/android/src/androidjnimain.h +++ b/src/plugins/platforms/android/androidjnimain.h @@ -1,7 +1,7 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -45,16 +45,11 @@ #include <android/log.h> -#ifdef ANDROID_PLUGIN_OPENGL -# include <EGL/eglplatform.h> -#endif - -#include <QtCore/qsize.h> - #include <jni.h> #include <android/asset_manager.h> -class QImage; +#include <QImage> + class QRect; class QPoint; class QThread; @@ -62,6 +57,7 @@ class QAndroidPlatformIntegration; class QWidget; class QString; class QWindow; +class AndroidSurfaceClient; namespace QtAndroid { @@ -69,11 +65,10 @@ namespace QtAndroid void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration); void setQtThread(QThread *thread); -#ifndef ANDROID_PLUGIN_OPENGL - void flushImage(const QPoint &pos, const QImage &image, const QRect &rect); -#else - EGLNativeWindowType nativeWindow(bool waitToCreate = true); -#endif + + int createSurface(AndroidSurfaceClient * client, const QRect &geometry, bool onTop); + void setSurfaceGeometry(int surfaceId, const QRect &geometry); + void destroySurface(int surfaceId); QWindow *topLevelWindowAt(const QPoint &globalPos); int desktopWidthPixels(); @@ -91,6 +86,7 @@ namespace QtAndroid void hideStatusBar(); jobject createBitmap(QImage img, JNIEnv *env = 0); + jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env); jobject createBitmapDrawable(jobject bitmap, JNIEnv *env = 0); struct AttachedJNIEnv diff --git a/src/plugins/platforms/android/src/androidjnimenu.cpp b/src/plugins/platforms/android/androidjnimenu.cpp index dbdd7c9b8e..dc2afe2b03 100644 --- a/src/plugins/platforms/android/src/androidjnimenu.cpp +++ b/src/plugins/platforms/android/androidjnimenu.cpp @@ -143,6 +143,9 @@ namespace QtAndroidMenu void setActiveTopLevelWindow(QWindow *window) { Qt::WindowFlags flags = window ? window->flags() : Qt::WindowFlags(); + if (!window) + return; + bool isNonRegularWindow = flags & (Qt::Desktop | Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; if (isNonRegularWindow) return; @@ -195,9 +198,9 @@ namespace QtAndroidMenu static void fillMenuItem(JNIEnv *env, jobject menuItem, bool checkable, bool checked, bool enabled, bool visible, const QIcon &icon=QIcon()) { - env->CallObjectMethod(menuItem, setCheckableMenuItemMethodID, checkable); - env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked); - env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled); + env->DeleteLocalRef(env->CallObjectMethod(menuItem, setCheckableMenuItemMethodID, checkable)); + env->DeleteLocalRef(env->CallObjectMethod(menuItem, setCheckedMenuItemMethodID, checked)); + env->DeleteLocalRef(env->CallObjectMethod(menuItem, setEnabledMenuItemMethodID, enabled)); if (!icon.isNull()) { // isNull() only checks the d pointer, not the actual image data. int sz = qMax(36, qgetenv("QT_ANDROID_APP_ICON_SIZE").toInt()); @@ -207,13 +210,13 @@ namespace QtAndroidMenu : QIcon::Disabled, QIcon::On).toImage(); if (!img.isNull()) { // Make sure we have a valid image. - env->CallObjectMethod(menuItem, - setIconMenuItemMethodID, - createBitmapDrawable(createBitmap(img, env), env)); + env->DeleteLocalRef(env->CallObjectMethod(menuItem, + setIconMenuItemMethodID, + createBitmapDrawable(createBitmap(img, env), env))); } } - env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible); + env->DeleteLocalRef(env->CallObjectMethod(menuItem, setVisibleMenuItemMethodID, visible)); } static int addAllMenuItemsToMenu(JNIEnv *env, jobject menu, QAndroidPlatformMenu *platformMenu) { @@ -239,6 +242,7 @@ namespace QtAndroidMenu item->isEnabled(), item->isVisible(), item->icon()); + env->DeleteLocalRef(menuItem); } return order; diff --git a/src/plugins/platforms/android/src/androidjnimenu.h b/src/plugins/platforms/android/androidjnimenu.h index 7c5422f67b..7c5422f67b 100644 --- a/src/plugins/platforms/android/src/androidjnimenu.h +++ b/src/plugins/platforms/android/androidjnimenu.h diff --git a/src/plugins/platforms/android/src/androidplatformplugin.cpp b/src/plugins/platforms/android/androidplatformplugin.cpp index 2cf5aa1e01..2cf5aa1e01 100644 --- a/src/plugins/platforms/android/src/androidplatformplugin.cpp +++ b/src/plugins/platforms/android/androidplatformplugin.cpp diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h b/src/plugins/platforms/android/androidsurfaceclient.h index e9251592aa..254e47123b 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.h +++ b/src/plugins/platforms/android/androidsurfaceclient.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -39,22 +39,20 @@ ** ****************************************************************************/ -#ifndef QANDROIDOPENGLPLATFORMSCREEN_H -#define QANDROIDOPENGLPLATFORMSCREEN_H +#ifndef ANDROIDSURFACECLIENT_H +#define ANDROIDSURFACECLIENT_H +#include <QMutex> +#include <jni.h> -#include "qeglfsscreen.h" - -QT_BEGIN_NAMESPACE - -class QAndroidOpenGLPlatformScreen : public QEglFSScreen +class AndroidSurfaceClient { public: - QAndroidOpenGLPlatformScreen(EGLDisplay display); + virtual void surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h) = 0; + void lockSurface() { m_surfaceMutex.lock(); } + void unlockSurface() { m_surfaceMutex.unlock(); } protected: - void topWindowChanged(QPlatformWindow *window); + QMutex m_surfaceMutex; }; -QT_END_NAMESPACE - -#endif // QANDROIDOPENGLPLATFORMSCREEN_H +#endif // ANDROIDSURFACECLIENT_H diff --git a/src/plugins/platforms/android/opengl/opengl.pro b/src/plugins/platforms/android/opengl/opengl.pro deleted file mode 100644 index ea050ca3a0..0000000000 --- a/src/plugins/platforms/android/opengl/opengl.pro +++ /dev/null @@ -1,32 +0,0 @@ -TARGET = qtforandroidGL - -PLUGIN_TYPE = platforms -load(qt_plugin) - -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN ANDROID_PLUGIN_OPENGL - -!equals(ANDROID_PLATFORM, android-9) { - INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include - LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid -} else { - LIBS += -ljnigraphics -landroid -} - -EGLFS_PLATFORM_HOOKS_SOURCES = $$PWD/../src/opengl/qeglfshooks_android.cpp - -INCLUDEPATH += $$PWD/../src/opengl/ - -HEADERS += \ - $$PWD/../src/opengl/qandroidopenglcontext.h \ - $$PWD/../src/opengl/qandroidopenglplatformwindow.h \ - $$PWD/../src/opengl/qandroidopenglplatformscreen.h - -SOURCES += \ - $$PWD/../src/opengl/qandroidopenglcontext.cpp \ - $$PWD/../src/opengl/qandroidopenglplatformwindow.cpp \ - $$PWD/../src/opengl/qandroidopenglplatformscreen.cpp - -include($$PWD/../../eglfs/eglfs.pri) -include($$PWD/../src/src.pri) diff --git a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index 95844fc649..95844fc649 100644 --- a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp diff --git a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h index 7bd560886c..7bd560886c 100644 --- a/src/plugins/platforms/android/src/qandroidassetsfileenginehandler.h +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.h diff --git a/src/plugins/platforms/android/src/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 326972e71e..326972e71e 100644 --- a/src/plugins/platforms/android/src/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp diff --git a/src/plugins/platforms/android/src/qandroidinputcontext.h b/src/plugins/platforms/android/qandroidinputcontext.h index 041bd0dc49..041bd0dc49 100644 --- a/src/plugins/platforms/android/src/qandroidinputcontext.h +++ b/src/plugins/platforms/android/qandroidinputcontext.h diff --git a/src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp b/src/plugins/platforms/android/qandroidplatformaccessibility.cpp index 229368345b..229368345b 100644 --- a/src/plugins/platforms/android/src/qandroidplatformaccessibility.cpp +++ b/src/plugins/platforms/android/qandroidplatformaccessibility.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformaccessibility.h b/src/plugins/platforms/android/qandroidplatformaccessibility.h index 1b87f11919..1b87f11919 100644 --- a/src/plugins/platforms/android/src/qandroidplatformaccessibility.h +++ b/src/plugins/platforms/android/qandroidplatformaccessibility.h diff --git a/src/plugins/platforms/android/qandroidplatformbackingstore.cpp b/src/plugins/platforms/android/qandroidplatformbackingstore.cpp new file mode 100644 index 0000000000..1df7ce3179 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformbackingstore.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformbackingstore.h" +#include "qandroidplatformscreen.h" +#include "qandroidplatformrasterwindow.h" +#include <qpa/qplatformscreen.h> + +QT_BEGIN_NAMESPACE + +QAndroidPlatformBackingStore::QAndroidPlatformBackingStore(QWindow *window) + : QPlatformBackingStore(window) +{ + Q_ASSERT(window->handle()); + (static_cast<QAndroidPlatformRasterWindow *>(window->handle()))->setBackingStore(this); +} + +QPaintDevice *QAndroidPlatformBackingStore::paintDevice() +{ + return &m_image; +} + +void QAndroidPlatformBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(offset); + + (static_cast<QAndroidPlatformRasterWindow *>(window->handle()))->repaint(region); +} + +void QAndroidPlatformBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(staticContents); + + if (m_image.size() != size) + m_image = QImage(size, window()->screen()->handle()->format()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformbackingstore.h index de4075feff..e6ea3dcce0 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformscreen.cpp +++ b/src/plugins/platforms/android/qandroidplatformbackingstore.h @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -39,23 +40,27 @@ ** ****************************************************************************/ -#include "qandroidopenglplatformscreen.h" -#include "qandroidopenglplatformwindow.h" -#include "androidjnimenu.h" +#ifndef QANDROIDPLATFORMBACKINGSTORE_H +#define QANDROIDPLATFORMBACKINGSTORE_H + +#include <qpa/qplatformbackingstore.h> +#include <qpa/qwindowsysteminterface.h> QT_BEGIN_NAMESPACE -QAndroidOpenGLPlatformScreen::QAndroidOpenGLPlatformScreen(EGLDisplay display) - : QEglFSScreen(display) +class QAndroidPlatformBackingStore : public QPlatformBackingStore { -} +public: + explicit QAndroidPlatformBackingStore(QWindow *window); + virtual QPaintDevice *paintDevice(); + virtual void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + virtual void resize(const QSize &size, const QRegion &staticContents); + const QImage image() { return m_image; } -void QAndroidOpenGLPlatformScreen::topWindowChanged(QPlatformWindow *window) -{ - QtAndroidMenu::setActiveTopLevelWindow(window->window()); - QAndroidOpenGLPlatformWindow *platformWindow = static_cast<QAndroidOpenGLPlatformWindow *>(window); - if (platformWindow != 0) - platformWindow->updateStatusBarVisibility(); -} +protected: + QImage m_image; +}; QT_END_NAMESPACE + +#endif // QANDROIDPLATFORMBACKINGSTORE_H diff --git a/src/plugins/platforms/android/src/qandroidplatformclipboard.cpp b/src/plugins/platforms/android/qandroidplatformclipboard.cpp index bc48b4935b..bc48b4935b 100644 --- a/src/plugins/platforms/android/src/qandroidplatformclipboard.cpp +++ b/src/plugins/platforms/android/qandroidplatformclipboard.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformclipboard.h b/src/plugins/platforms/android/qandroidplatformclipboard.h index 644f326934..644f326934 100644 --- a/src/plugins/platforms/android/src/qandroidplatformclipboard.h +++ b/src/plugins/platforms/android/qandroidplatformclipboard.h diff --git a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp index 4c91e76e0f..4b99f2ce73 100644 --- a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.cpp +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp @@ -43,6 +43,8 @@ #include <QtWidgets/QStyle> #include "qandroidplatformdialoghelpers.h" #include "androidjnimain.h" +#include <private/qguiapplication_p.h> +#include <qpa/qplatformtheme.h> namespace QtAndroidDialogHelpers { static jclass g_messageDialogHelperClass = 0; @@ -61,49 +63,6 @@ void QAndroidPlatformMessageDialogHelper::exec() m_loop.exec(); } -static QString standardButtonText(int sbutton) -{ - switch (sbutton) { - case QMessageDialogOptions::Ok: - return QAndroidPlatformMessageDialogHelper::tr("OK"); - case QMessageDialogOptions::Save: - return QAndroidPlatformMessageDialogHelper::tr("Save"); - case QMessageDialogOptions::Open: - return QAndroidPlatformMessageDialogHelper::tr("Open"); - case QMessageDialogOptions::Cancel: - return QAndroidPlatformMessageDialogHelper::tr("Cancel"); - case QMessageDialogOptions::Close: - return QAndroidPlatformMessageDialogHelper::tr("Close"); - case QMessageDialogOptions::Apply: - return QAndroidPlatformMessageDialogHelper::tr("Apply"); - case QMessageDialogOptions::Reset: - return QAndroidPlatformMessageDialogHelper::tr("Reset"); - case QMessageDialogOptions::Help: - return QAndroidPlatformMessageDialogHelper::tr("Help"); - case QMessageDialogOptions::Discard: - return QAndroidPlatformMessageDialogHelper::tr("Discard"); - case QMessageDialogOptions::Yes: - return QAndroidPlatformMessageDialogHelper::tr("Yes"); - case QMessageDialogOptions::YesToAll: - return QAndroidPlatformMessageDialogHelper::tr("Yes to All"); - case QMessageDialogOptions::No: - return QAndroidPlatformMessageDialogHelper::tr("No"); - case QMessageDialogOptions::NoToAll: - return QAndroidPlatformMessageDialogHelper::tr("No to All"); - case QMessageDialogOptions::SaveAll: - return QAndroidPlatformMessageDialogHelper::tr("Save All"); - case QMessageDialogOptions::Abort: - return QAndroidPlatformMessageDialogHelper::tr("Abort"); - case QMessageDialogOptions::Retry: - return QAndroidPlatformMessageDialogHelper::tr("Retry"); - case QMessageDialogOptions::Ignore: - return QAndroidPlatformMessageDialogHelper::tr("Ignore"); - case QMessageDialogOptions::RestoreDefaults: - return QAndroidPlatformMessageDialogHelper::tr("Restore Defaults"); - } // switch - return QString(); -} - bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags , Qt::WindowModality windowModality , QWindow *parent) @@ -134,8 +93,10 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags m_javaMessageDialog.callMethod<void>("setDetailedText", "(Ljava/lang/String;)V", QJNIObjectPrivate::fromString(str).object()); for (int i = QMessageDialogOptions::FirstButton; i < QMessageDialogOptions::LastButton; i<<=1) { - if ( opt->standardButtons() & i ) - m_javaMessageDialog.callMethod<void>("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(standardButtonText(i)).object()); + if ( opt->standardButtons() & i ) { + const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(i); + m_javaMessageDialog.callMethod<void>("addButton", "(ILjava/lang/String;)V", i, QJNIObjectPrivate::fromString(text).object()); + } } m_javaMessageDialog.callMethod<void>("show", "(J)V", jlong(static_cast<QObject*>(this))); diff --git a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h b/src/plugins/platforms/android/qandroidplatformdialoghelpers.h index 88ec91d936..88ec91d936 100644 --- a/src/plugins/platforms/android/src/qandroidplatformdialoghelpers.h +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.h diff --git a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp index 7f68b44ed8..7f68b44ed8 100644 --- a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.cpp +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.h b/src/plugins/platforms/android/qandroidplatformfontdatabase.h index 3cbfe95d36..3cbfe95d36 100644 --- a/src/plugins/platforms/android/src/qandroidplatformfontdatabase.h +++ b/src/plugins/platforms/android/qandroidplatformfontdatabase.h diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index ae3e257d3c..2fc6b987ab 100644 --- a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -40,35 +40,32 @@ ****************************************************************************/ #include "qandroidplatformintegration.h" -#include "qabstracteventdispatcher.h" -#include "androidjnimain.h" -#include <QtGui/qguiapplication.h> -#include <qpa/qwindowsysteminterface.h> + +#include <QGuiApplication> +#include <QOpenGLContext> #include <QThread> + +#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> + +#include <qpa/qwindowsysteminterface.h> #include <qpa/qplatformwindow.h> + +#warning sort the headers +#include "androidjnimain.h" +#include "qabstracteventdispatcher.h" +#include "qandroidplatformrasterwindow.h" +#include "qandroidplatformopenglwindow.h" +#include "qandroidplatformbackingstore.h" #include "qandroidplatformservices.h" #include "qandroidplatformfontdatabase.h" #include "qandroidplatformclipboard.h" #include "qandroidplatformaccessibility.h" -#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> - -#ifndef ANDROID_PLUGIN_OPENGL -# include "qandroidplatformscreen.h" -# include "qandroidplatformwindow.h" -# include <QtPlatformSupport/private/qfbbackingstore_p.h> -#else -# include "qeglfswindow.h" -# include "androidjnimenu.h" -# include "qandroidopenglcontext.h" -# include "qandroidopenglplatformwindow.h" -# include "qandroidopenglplatformscreen.h" -# include "qeglfshooks.h" -# include <QtGui/qopenglcontext.h> -#endif - +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformscreen.h" #include "qandroidplatformtheme.h" #include "qandroidsystemlocale.h" + QT_BEGIN_NAMESPACE int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320; @@ -102,12 +99,21 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface(); -#ifndef ANDROID_PLUGIN_OPENGL + if (!eglBindAPI(EGL_OPENGL_ES_API)) + qFatal("Could not bind GL_ES API"); + + m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (m_eglDisplay == EGL_NO_DISPLAY) + qFatal("Could not open egl display"); + + EGLint major, minor; + if (!eglInitialize(m_eglDisplay, &major, &minor)) + qFatal("Could not initialize egl display"); + m_primaryScreen = new QAndroidPlatformScreen(); screenAdded(m_primaryScreen); m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth, m_defaultPhysicalSizeHeight)); m_primaryScreen->setGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight)); -#endif m_mainThread = QThread::currentThread(); QtAndroid::setAndroidPlatformIntegration(this); @@ -124,83 +130,53 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const switch (cap) { case ThreadedPixmaps: return true; case ApplicationState: return true; - case NativeWidgets: return false; + case NativeWidgets: return true; + case OpenGL: return true; + case ThreadedOpenGL: return true; default: -#ifndef ANDROID_PLUGIN_OPENGL - return QPlatformIntegration::hasCapability(cap); -#else - return QEglFSIntegration::hasCapability(cap); -#endif + return QPlatformIntegration::hasCapability(cap); } } -#ifndef ANDROID_PLUGIN_OPENGL QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(QWindow *window) const { - return new QFbBackingStore(window); + return new QAndroidPlatformBackingStore(window); } -QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const +QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { - QAndroidPlatformWindow *platformWindow = new QAndroidPlatformWindow(window); - platformWindow->setWindowState(window->windowState()); - - return platformWindow; + QSurfaceFormat format(context->format()); + format.setAlphaBufferSize(8); + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + return new QAndroidPlatformOpenGLContext(format, context->shareHandle(), m_eglDisplay); } -QAbstractEventDispatcher *QAndroidPlatformIntegration::createEventDispatcher() const -{ - return createUnixEventDispatcher(); -} -#else // !ANDROID_PLUGIN_OPENGL QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const { - QAndroidOpenGLPlatformWindow *platformWindow = new QAndroidOpenGLPlatformWindow(window); - platformWindow->create(); - platformWindow->requestActivateWindow(); - platformWindow->setWindowState(window->windowState()); - QtAndroidMenu::setActiveTopLevelWindow(window); - - return platformWindow; + if (window->surfaceType() == QSurface::RasterSurface) + return new QAndroidPlatformRasterWindow(window); + else + return new QAndroidPlatformOpenGLWindow(window, m_eglDisplay); } -void QAndroidPlatformIntegration::invalidateNativeSurface() -{ - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast<QAndroidOpenGLPlatformWindow *>(w->handle()); - if (window != 0) - window->invalidateSurface(); - } -} - -void QAndroidPlatformIntegration::surfaceChanged() -{ - QAndroidOpenGLPlatformWindow::updateStaticNativeWindow(); - foreach (QWindow *w, QGuiApplication::topLevelWindows()) { - QAndroidOpenGLPlatformWindow *window = - static_cast<QAndroidOpenGLPlatformWindow *>(w->handle()); - if (window != 0) - window->resetSurface(); - } -} - -QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const +QAbstractEventDispatcher *QAndroidPlatformIntegration::createEventDispatcher() const { - return new QAndroidOpenGLContext(this, - QEglFSHooks::hooks()->surfaceFormatFor(context->format()), - context->shareHandle(), - display()); + return createUnixEventDispatcher(); } -#endif // ANDROID_PLUGIN_OPENGL QAndroidPlatformIntegration::~QAndroidPlatformIntegration() { + if (m_eglDisplay != EGL_NO_DISPLAY) + eglTerminate(m_eglDisplay); + delete m_androidPlatformNativeInterface; delete m_androidFDB; delete m_androidSystemLocale; QtAndroid::setAndroidPlatformIntegration(NULL); } + QPlatformFontDatabase *QAndroidPlatformIntegration::fontDatabase() const { return m_androidFDB; @@ -295,8 +271,6 @@ QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const } #endif - -#ifndef ANDROID_PLUGIN_OPENGL void QAndroidPlatformIntegration::setDesktopSize(int width, int height) { if (m_primaryScreen) @@ -308,36 +282,5 @@ void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height) if (m_primaryScreen) QMetaObject::invokeMethod(m_primaryScreen, "setPhysicalSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height))); } -#else -void QAndroidPlatformIntegration::setDesktopSize(int width, int height) -{ - m_defaultGeometryWidth = width; - m_defaultGeometryHeight = height; -} - -void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height) -{ - m_defaultPhysicalSizeWidth = width; - m_defaultPhysicalSizeHeight = height; -} - -QEglFSScreen *QAndroidPlatformIntegration::createScreen() const -{ - return new QAndroidOpenGLPlatformScreen(display()); -} - -#endif - -void QAndroidPlatformIntegration::pauseApp() -{ - if (QAbstractEventDispatcher::instance(m_mainThread)) - QAbstractEventDispatcher::instance(m_mainThread)->interrupt(); -} - -void QAndroidPlatformIntegration::resumeApp() -{ - if (QAbstractEventDispatcher::instance(m_mainThread)) - QAbstractEventDispatcher::instance(m_mainThread)->wakeUp(); -} QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index bd08ad694c..a6cba7ac16 100644 --- a/src/plugins/platforms/android/src/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -47,14 +47,11 @@ #include <qpa/qplatformnativeinterface.h> #include <QtWidgets/QAction> +#include <EGL/egl.h> #include <jni.h> #include "qandroidinputcontext.h" -#ifndef ANDROID_PLUGIN_OPENGL -# include "qandroidplatformscreen.h" -#else -# include "qeglfsintegration.h" -#endif +#include "qandroidplatformscreen.h" QT_BEGIN_NAMESPACE @@ -63,10 +60,6 @@ class QAndroidPlatformServices; class QAndroidSystemLocale; class QPlatformAccessibility; -#ifdef ANDROID_PLUGIN_OPENGL -class QAndroidOpenGLPlatformWindow; -#endif - class QAndroidPlatformNativeInterface: public QPlatformNativeInterface { public: @@ -75,12 +68,7 @@ public: QHash<int, QFont> m_fonts; }; -class QAndroidPlatformIntegration -#ifndef ANDROID_PLUGIN_OPENGL - : public QPlatformIntegration -#else - : public QEglFSIntegration -#endif +class QAndroidPlatformIntegration : public QPlatformIntegration { friend class QAndroidPlatformScreen; @@ -90,17 +78,11 @@ public: bool hasCapability(QPlatformIntegration::Capability cap) const; -#ifndef ANDROID_PLUGIN_OPENGL - QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; QAbstractEventDispatcher *createEventDispatcher() const; QAndroidPlatformScreen *screen() { return m_primaryScreen; } -#else - QPlatformWindow *createPlatformWindow(QWindow *window) const; - void invalidateNativeSurface(); - void surfaceChanged(); - QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; -#endif virtual void setDesktopSize(int width, int height); virtual void setDisplayMetrics(int width, int height); @@ -121,13 +103,11 @@ public: #endif QVariant styleHint(StyleHint hint) const; - Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const Q_DECL_OVERRIDE; + Qt::WindowState defaultWindowState(Qt::WindowFlags flags) const; QStringList themeNames() const; QPlatformTheme *createPlatformTheme(const QString &name) const; - void pauseApp(); - void resumeApp(); static void setDefaultDisplayMetrics(int gw, int gh, int sw, int sh); static void setDefaultDesktopSize(int gw, int gh); static void setScreenOrientation(Qt::ScreenOrientation currentOrientation, @@ -141,19 +121,12 @@ public: QTouchDevice *touchDevice() const { return m_touchDevice; } void setTouchDevice(QTouchDevice *touchDevice) { m_touchDevice = touchDevice; } -#ifdef ANDROID_PLUGIN_OPENGL - QEglFSScreen *createScreen() const; -#endif - private: - - friend class QEglFSAndroidHooks; + EGLDisplay m_eglDisplay; QTouchDevice *m_touchDevice; -#ifndef ANDROID_PLUGIN_OPENGL QAndroidPlatformScreen *m_primaryScreen; -#endif QThread *m_mainThread; diff --git a/src/plugins/platforms/android/src/qandroidplatformmenu.cpp b/src/plugins/platforms/android/qandroidplatformmenu.cpp index 1ecabb25e2..1ecabb25e2 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenu.cpp +++ b/src/plugins/platforms/android/qandroidplatformmenu.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformmenu.h b/src/plugins/platforms/android/qandroidplatformmenu.h index 305b64168a..305b64168a 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenu.h +++ b/src/plugins/platforms/android/qandroidplatformmenu.h diff --git a/src/plugins/platforms/android/src/qandroidplatformmenubar.cpp b/src/plugins/platforms/android/qandroidplatformmenubar.cpp index 134062fb32..134062fb32 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenubar.cpp +++ b/src/plugins/platforms/android/qandroidplatformmenubar.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformmenubar.h b/src/plugins/platforms/android/qandroidplatformmenubar.h index 56915335c2..56915335c2 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenubar.h +++ b/src/plugins/platforms/android/qandroidplatformmenubar.h diff --git a/src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp b/src/plugins/platforms/android/qandroidplatformmenuitem.cpp index bd37834d2a..bd37834d2a 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenuitem.cpp +++ b/src/plugins/platforms/android/qandroidplatformmenuitem.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformmenuitem.h b/src/plugins/platforms/android/qandroidplatformmenuitem.h index 5861e8e195..5861e8e195 100644 --- a/src/plugins/platforms/android/src/qandroidplatformmenuitem.h +++ b/src/plugins/platforms/android/qandroidplatformmenuitem.h diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 6431914812..d99cafe6b7 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -39,49 +40,30 @@ ** ****************************************************************************/ -#include "qandroidopenglcontext.h" -#include "qandroidopenglplatformwindow.h" -#include "qandroidplatformintegration.h" - -#include <QtCore/qdebug.h> -#include <qpa/qwindowsysteminterface.h> +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformopenglwindow.h" +#include <QSurface> #include <QtGui/private/qopenglcontext_p.h> QT_BEGIN_NAMESPACE -QAndroidOpenGLContext::QAndroidOpenGLContext(const QAndroidPlatformIntegration *integration, - const QSurfaceFormat &format, - QPlatformOpenGLContext *share, - EGLDisplay display, - EGLenum eglApi) - : QEglFSContext(format, share, display, eglApi) - , m_platformIntegration(integration) +QAndroidPlatformOpenGLContext::QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display) + :QEGLPlatformContext(format, share, display, EGL_OPENGL_ES_API) { } -void QAndroidOpenGLContext::swapBuffers(QPlatformSurface *surface) +void QAndroidPlatformOpenGLContext::swapBuffers(QPlatformSurface *surface) { - QEglFSContext::swapBuffers(surface); + QEGLPlatformContext::swapBuffers(surface); - if (surface->surface()->surfaceClass() == QSurface::Window) { - QAndroidOpenGLPlatformWindow *window = static_cast<QAndroidOpenGLPlatformWindow *>(surface); - window->lock(); - QSize size = window->scheduledResize(); - if (size.isValid()) { - QRect geometry(QPoint(0, 0), size); - window->setGeometry(geometry); - QWindowSystemInterface::handleGeometryChange(window->window(), geometry); - QWindowSystemInterface::handleExposeEvent(window->window(), QRegion(geometry)); - window->scheduleResize(QSize()); - } - window->unlock(); - } + if (surface->surface()->surfaceClass() == QSurface::Window) + static_cast<QAndroidPlatformOpenGLWindow *>(surface)->checkNativeSurface(eglConfig()); } -bool QAndroidOpenGLContext::makeCurrent(QPlatformSurface *surface) +bool QAndroidPlatformOpenGLContext::makeCurrent(QPlatformSurface *surface) { - bool ret = QEglFSContext::makeCurrent(surface); + bool ret = QEGLPlatformContext::makeCurrent(surface); const char *rendererString = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); if (rendererString != 0 && qstrncmp(rendererString, "Android Emulator", 16) == 0) { @@ -92,4 +74,11 @@ bool QAndroidOpenGLContext::makeCurrent(QPlatformSurface *surface) return ret; } +EGLSurface QAndroidPlatformOpenGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface) +{ + if (surface->surface()->surfaceClass() == QSurface::Window) + return static_cast<QAndroidPlatformOpenGLWindow *>(surface)->eglSurface(eglConfig()); + return EGL_NO_SURFACE; +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h b/src/plugins/platforms/android/qandroidplatformopenglcontext.h index c419ae8392..29e5f596d5 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglcontext.h +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.h @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -39,31 +40,24 @@ ** ****************************************************************************/ -#ifndef QANDROIDOPENGLCONTEXT_H -#define QANDROIDOPENGLCONTEXT_H +#ifndef QANDROIDPLATFORMOPENGLCONTEXT_H +#define QANDROIDPLATFORMOPENGLCONTEXT_H -#include <QtCore/qreadwritelock.h> -#include "qeglfscontext.h" +#include <QtPlatformSupport/private/qeglplatformcontext_p.h> QT_BEGIN_NAMESPACE -class QAndroidPlatformIntegration; -class QAndroidOpenGLContext : public QEglFSContext +class QAndroidPlatformOpenGLContext : public QEGLPlatformContext { public: - QAndroidOpenGLContext(const QAndroidPlatformIntegration *integration, - const QSurfaceFormat &format, - QPlatformOpenGLContext *share, - EGLDisplay display, - EGLenum eglApi = EGL_OPENGL_ES_API); - + QAndroidPlatformOpenGLContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display); void swapBuffers(QPlatformSurface *surface); bool makeCurrent(QPlatformSurface *surface); private: - const QAndroidPlatformIntegration *m_platformIntegration; + virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface); }; QT_END_NAMESPACE -#endif // QANDROIDOPENGLCONTEXT_H +#endif // QANDROIDPLATFORMOPENGLCONTEXT_H diff --git a/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp new file mode 100644 index 0000000000..498f59be88 --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformopenglwindow.h" + +#include "androidjnimain.h" + +#include <QSurfaceFormat> + +#include <qpa/qwindowsysteminterface.h> + +#include <android/native_window.h> +#include <android/native_window_jni.h> + +#warning remove me +#include <QDebug> + +QT_BEGIN_NAMESPACE + +QAndroidPlatformOpenGLWindow::QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display) + :QAndroidPlatformWindow(window), m_eglDisplay(display) +{ + lockSurface(); + m_nativeSurfaceId = QtAndroid::createSurface(this, geometry(), bool(window->flags() & Qt::WindowStaysOnTopHint)); + m_surfaceWaitCondition.wait(&m_surfaceMutex); + unlockSurface(); +} + +QAndroidPlatformOpenGLWindow::~QAndroidPlatformOpenGLWindow() +{ + m_surfaceWaitCondition.wakeOne(); + lockSurface(); + if (m_nativeSurfaceId != -1) + QtAndroid::destroySurface(m_nativeSurfaceId); + clearEgl(); + unlockSurface(); +} + +void QAndroidPlatformOpenGLWindow::setGeometry(const QRect &rect) +{ + if (rect == geometry()) + return; + + qDebug() << rect; + QAndroidPlatformWindow::setGeometry(rect); + QtAndroid::setSurfaceGeometry(m_nativeSurfaceId, rect); +} + +EGLSurface QAndroidPlatformOpenGLWindow::eglSurface(EGLConfig config) +{ + QMutexLocker lock(&m_surfaceMutex); + if (m_eglSurface == EGL_NO_SURFACE) { + m_surfaceMutex.unlock(); + checkNativeSurface(config); + m_surfaceMutex.lock(); + } + return m_eglSurface; +} + +void QAndroidPlatformOpenGLWindow::checkNativeSurface(EGLConfig config) +{ + QMutexLocker lock(&m_surfaceMutex); + qDebug() << geometry() << m_changedAndroidSurface.isValid(); + if (m_nativeSurfaceId == -1 || !m_changedAndroidSurface.isValid()) + return; + + createEgl(config); + + // we've create another surface, the window should be repainted + QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); +} + +void QAndroidPlatformOpenGLWindow::createEgl(EGLConfig config) +{ + clearEgl(); + m_androidSurface = QJNIObjectPrivate(); + m_androidSurface = m_changedAndroidSurface; + m_changedAndroidSurface = QJNIObjectPrivate(); + QJNIEnvironmentPrivate env; + m_nativeWindow = ANativeWindow_fromSurface(env, m_androidSurface.object()); + if (m_nativeWindow) + ANativeWindow_acquire(m_nativeWindow); + + m_eglSurface = eglCreateWindowSurface(m_eglDisplay, config, m_nativeWindow, NULL); + if (m_eglSurface == EGL_NO_SURFACE) { + EGLint error = eglGetError(); + eglTerminate(m_eglDisplay); + qFatal("EGL Error : Could not create the egl surface: error = 0x%x\n", error); + } +} + +void QAndroidPlatformOpenGLWindow::clearEgl() +{ + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + if (m_eglSurface != EGL_NO_SURFACE) { + eglDestroySurface(m_eglDisplay, m_eglSurface); + m_eglSurface = EGL_NO_SURFACE; + } + + if (m_nativeWindow) { + ANativeWindow_release(m_nativeWindow); + m_nativeWindow = 0; + } +} + +void QAndroidPlatformOpenGLWindow::surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h) +{ + Q_UNUSED(jniEnv); + Q_UNUSED(w); + Q_UNUSED(h); + qDebug() << w << h; + lockSurface(); + m_changedAndroidSurface = surface; + m_surfaceWaitCondition.wakeOne(); + unlockSurface(); + + // repaint the window + QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h b/src/plugins/platforms/android/qandroidplatformopenglwindow.h index e4ff0444d4..820453ab01 100644 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.h +++ b/src/plugins/platforms/android/qandroidplatformopenglwindow.h @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** @@ -39,53 +40,44 @@ ** ****************************************************************************/ -#ifndef QANDROIDOPENGLPLATFORMWINDOW_H -#define QANDROIDOPENGLPLATFORMWINDOW_H +#ifndef QANDROIDPLATFORMOPENGLWINDOW_H +#define QANDROIDPLATFORMOPENGLWINDOW_H -#include "qeglfswindow.h" -#include <QtCore/qmutex.h> -#include <QtCore/qreadwritelock.h> +#include <EGL/egl.h> +#include <QWaitCondition> +#include <QtCore/private/qjni_p.h> + +#include "androidsurfaceclient.h" +#include "qandroidplatformwindow.h" QT_BEGIN_NAMESPACE -class QAndroidOpenGLPlatformWindow : public QEglFSWindow +class QAndroidPlatformOpenGLWindow : public QAndroidPlatformWindow, public AndroidSurfaceClient { public: - QAndroidOpenGLPlatformWindow(QWindow *window); - ~QAndroidOpenGLPlatformWindow(); - - QSize scheduledResize() const { return m_scheduledResize; } - void scheduleResize(const QSize &size) { m_scheduledResize = size; } - - void lock() { m_lock.lock(); } - void unlock() { m_lock.unlock(); } - - bool isExposed() const; + explicit QAndroidPlatformOpenGLWindow(QWindow *window, EGLDisplay display); + ~QAndroidPlatformOpenGLWindow(); - void raise(); + void setGeometry(const QRect &rect); + EGLSurface eglSurface(EGLConfig config); - void invalidateSurface(); - void resetSurface(); - void setWindowState(Qt::WindowState state); + void checkNativeSurface(EGLConfig config); - void setVisible(bool visible); - - void destroy(); - - static void updateStaticNativeWindow(); - void updateStatusBarVisibility(); +protected: + virtual void surfaceChanged(JNIEnv *jniEnv, jobject surface, int w, int h); + void createEgl(EGLConfig config); + void clearEgl(); private: - QSize m_scheduledResize; - QMutex m_lock; - Qt::WindowState m_state; - - static QReadWriteLock m_staticSurfaceLock; - static EGLSurface m_staticSurface; - static EGLNativeWindowType m_staticNativeWindow; - static QBasicAtomicInt m_referenceCount; + EGLDisplay m_eglDisplay; + EGLSurface m_eglSurface = EGL_NO_SURFACE; + EGLNativeWindowType m_nativeWindow = nullptr; + + int m_nativeSurfaceId = -1; + QJNIObjectPrivate m_androidSurface; + QJNIObjectPrivate m_changedAndroidSurface; + QWaitCondition m_surfaceWaitCondition; }; QT_END_NAMESPACE - -#endif // QANDROIDOPENGLPLATFORMWINDOW_H +#endif // QANDROIDPLATFORMOPENGLWINDOW_H diff --git a/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp b/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp new file mode 100644 index 0000000000..113a69427d --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformrasterwindow.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidplatformrasterwindow.h" + +#include "qandroidplatformscreen.h" + +QT_BEGIN_NAMESPACE + +QAndroidPlatformRasterWindow::QAndroidPlatformRasterWindow(QWindow *window) + :QAndroidPlatformWindow(window) +{ + +} + +void QAndroidPlatformRasterWindow::repaint(const QRegion ®ion) +{ + QRect currentGeometry = geometry(); + + QRect dirtyClient = region.boundingRect(); + QRect dirtyRegion(currentGeometry.left() + dirtyClient.left(), + currentGeometry.top() + dirtyClient.top(), + dirtyClient.width(), + dirtyClient.height()); + QRect mOldGeometryLocal = m_oldGeometry; + m_oldGeometry = currentGeometry; + // If this is a move, redraw the previous location + if (mOldGeometryLocal != currentGeometry) + platformScreen()->setDirty(mOldGeometryLocal); + platformScreen()->setDirty(dirtyRegion); +} + +void QAndroidPlatformRasterWindow::setGeometry(const QRect &rect) +{ + m_oldGeometry = geometry(); + QAndroidPlatformWindow::setGeometry(rect); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformrasterwindow.h b/src/plugins/platforms/android/qandroidplatformrasterwindow.h new file mode 100644 index 0000000000..50c0d497af --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformrasterwindow.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDPLATFORMRASTERWINDOW_H +#define QANDROIDPLATFORMRASTERWINDOW_H + +#include "qandroidplatformwindow.h" +QT_BEGIN_NAMESPACE + +class QAndroidPlatformBackingStore; +class QAndroidPlatformRasterWindow : public QObject, public QAndroidPlatformWindow +{ + Q_OBJECT +public: + QAndroidPlatformRasterWindow(QWindow *window); + + void setBackingStore(QAndroidPlatformBackingStore *store) { m_backingStore = store; } + QAndroidPlatformBackingStore *backingStore() const { return m_backingStore; } + void repaint(const QRegion®ion); + +public slots: + void setGeometry(const QRect &rect); + +private: + QAndroidPlatformBackingStore *m_backingStore = nullptr; + QRect m_oldGeometry; + +}; + +QT_END_NAMESPACE +#endif // QANDROIDPLATFORMRASTERWINDOW_H diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp new file mode 100644 index 0000000000..4f956f7a4f --- /dev/null +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -0,0 +1,352 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QDebug> +#include <QTime> + +#include <qpa/qwindowsysteminterface.h> + +#include "qandroidplatformscreen.h" +#include "qandroidplatformbackingstore.h" +#include "qandroidplatformintegration.h" +#include "androidjnimain.h" +#include "androidjnimenu.h" +#include "qandroidplatformrasterwindow.h" + +#include <android/bitmap.h> + +QT_BEGIN_NAMESPACE + +#warning REMOVE ME +class ScopedProfiler +{ +public: + ScopedProfiler(const QString &msg) + { + m_msg = msg; + } + ~ScopedProfiler() + { + qDebug() << m_msg << m_timer.elapsed(); + } + +private: + QTime m_timer; + QString m_msg; +}; + +#define PROFILE_SCOPE ScopedProfiler ___sp___(__func__) + +QAndroidPlatformScreen::QAndroidPlatformScreen():QObject(),QPlatformScreen() +{ + m_geometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight); + // Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16 + // is way much faster than 32 + if (qgetenv("QT_ANDROID_RASTER_IMAGE_DEPTH").toInt() == 16) { + m_format = QImage::Format_RGB16; + m_depth = 16; + } else { + m_format = QImage::Format_RGBA8888; + m_depth = 32; + } + m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); + m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth); + m_redrawTimer.setSingleShot(true); + m_redrawTimer.setInterval(0); + connect(&m_redrawTimer, SIGNAL(timeout()), this, SLOT(doRedraw())); +} + +QAndroidPlatformScreen::~QAndroidPlatformScreen() +{ + if (m_id != -1) { + QtAndroid::destroySurface(m_id); + m_surfaceWaitCondition.wakeOne(); + if (m_bitmap) + QtAndroid::AttachedJNIEnv().jniEnv->DeleteGlobalRef(m_bitmap); + } +} + +QWindow *QAndroidPlatformScreen::topWindow() const +{ + foreach (QAndroidPlatformWindow *w, m_windowStack) + if (w->window()->type() == Qt::Window || w->window()->type() == Qt::Dialog) + return w->window(); + return 0; +} + +QWindow *QAndroidPlatformScreen::topLevelAt(const QPoint &p) const +{ + foreach (QAndroidPlatformWindow *w, m_windowStack) { + if (w->geometry().contains(p, false) && w->window()->isVisible()) + return w->window(); + } + return 0; +} + +void QAndroidPlatformScreen::addWindow(QAndroidPlatformWindow *window) +{ + m_windowStack.prepend(window); + if (window->isRaster()) + setDirty(window->geometry()); + + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::removeWindow(QAndroidPlatformWindow *window) +{ + m_windowStack.removeOne(window); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::raise(QAndroidPlatformWindow *window) +{ + int index = m_windowStack.indexOf(window); + if (index <= 0) + return; + m_windowStack.move(index, 0); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::lower(QAndroidPlatformWindow *window) +{ + int index = m_windowStack.indexOf(window); + if (index == -1 || index == (m_windowStack.size() - 1)) + return; + m_windowStack.move(index, m_windowStack.size() - 1); + if (window->isRaster()) { + setDirty(window->geometry()); + } + QWindow *w = topWindow(); + QWindowSystemInterface::handleWindowActivated(w); + topWindowChanged(w); +} + +void QAndroidPlatformScreen::scheduleUpdate() +{ + if (!m_redrawTimer.isActive()) + m_redrawTimer.start(); +} + +void QAndroidPlatformScreen::setDirty(const QRect &rect) +{ + QRect intersection = rect.intersected(m_geometry); + QPoint screenOffset = m_geometry.topLeft(); + m_repaintRegion += intersection.translated(-screenOffset); // global to local translation + scheduleUpdate(); +} + +void QAndroidPlatformScreen::setPhysicalSize(const QSize &size) +{ + m_physicalSize = size; +} + +void QAndroidPlatformScreen::setGeometry(const QRect &rect) +{ + QMutexLocker lock(&m_surfaceMutex); + if (m_geometry == rect) + return; + + m_geometry = rect; + QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry()); + QWindowSystemInterface::handleScreenAvailableGeometryChange(QPlatformScreen::screen(), availableGeometry()); + resizeMaximizedWindows(); + + if (m_id != -1) { + if (m_bitmap) { + QtAndroid::AttachedJNIEnv().jniEnv->DeleteGlobalRef(m_bitmap); + m_bitmap = 0; + } + QtAndroid::setSurfaceGeometry(m_id, rect); + } +} + +void QAndroidPlatformScreen::topWindowChanged(QWindow *w) +{ + QtAndroidMenu::setActiveTopLevelWindow(w); + + if (w != 0) { + QAndroidPlatformWindow *platformWindow = static_cast<QAndroidPlatformWindow *>(w->handle()); + if (platformWindow != 0) + platformWindow->updateStatusBarVisibility(); + } +} + +void QAndroidPlatformScreen::doRedraw() +{ + PROFILE_SCOPE; + + if (m_repaintRegion.isEmpty()) + return; + + QVector<QRect> rects = m_repaintRegion.rects(); + + QMutexLocker lock(&m_surfaceMutex); + if (m_id == -1) { + m_id = QtAndroid::createSurface(this, m_geometry, true); + m_surfaceWaitCondition.wait(&m_surfaceMutex); + } + + if (!m_bitmap || !m_surface.isValid()) + return; + + QJNIEnvironmentPrivate env; + if (!env) + return; + + int ret; + void *pixels; + + if ((ret = AndroidBitmap_lockPixels(env, m_bitmap, &pixels)) < 0) { + qWarning() << "AndroidBitmap_lockPixels() failed! error=" << ret; + return; + } + + QImage mScreenImage(reinterpret_cast<uchar *>(pixels), m_bitmapWidth, m_bitmapHeight, m_bitmapStride, m_format); + QPainter mCompositePainter(&mScreenImage); + + for (int rectIndex = 0; rectIndex < rects.size(); rectIndex++) { + QRegion visibleRegion = rects[rectIndex]; + foreach (QAndroidPlatformWindow *window, m_windowStack) { + if (!window->window()->isVisible() + || !window->isRaster()) + continue; + + foreach (const QRect &rect, visibleRegion.rects()) { + QRect targetRect = window->geometry(); + targetRect &= rect; + + if (targetRect.isNull()) + continue; + + visibleRegion -= targetRect; + QRect windowRect = targetRect.translated(-window->geometry().topLeft()); + QAndroidPlatformBackingStore *backingStore = static_cast<QAndroidPlatformRasterWindow *>(window)->backingStore(); + if (backingStore) + mCompositePainter.drawImage(targetRect, backingStore->image(), windowRect); + } + } + + foreach (const QRect &rect, visibleRegion.rects()) + mCompositePainter.fillRect(rect, Qt::transparent); + } + + + QRect br = m_repaintRegion.boundingRect(); + m_repaintRegion = QRegion(); + AndroidBitmap_unlockPixels(env, m_bitmap); + + QJNIObjectPrivate jrect("android.graphics.Rect", "(IIII)V", + jint(br.left()), + jint(br.top()), + jint(br.right() + 1), + jint(br.bottom() + 1)); + + QJNIObjectPrivate canvas = m_surface.callObjectMethod("lockCanvas", + "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;", + jrect.object()); + if (!canvas.isValid()) { + qWarning() << "Can't lockCanvas"; + return; + } + canvas.callMethod<void>("drawBitmap", + "(Landroid/graphics/Bitmap;Landroid/graphics/Rect;Landroid/graphics/Rect;Landroid/graphics/Paint;)V", + m_bitmap, jrect.object(), jrect.object(), jobject(0)); + + m_surface.callMethod<void>("unlockCanvasAndPost", "(Landroid/graphics/Canvas;)V", canvas.object()); +} + +QDpi QAndroidPlatformScreen::logicalDpi() const +{ + qreal lDpi = QtAndroid::scaledDensity() * 72; + return QDpi(lDpi, lDpi); +} + +Qt::ScreenOrientation QAndroidPlatformScreen::orientation() const +{ + return QAndroidPlatformIntegration::m_orientation; +} + +Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const +{ + return QAndroidPlatformIntegration::m_nativeOrientation; +} + +void QAndroidPlatformScreen::surfaceChanged(JNIEnv *env, jobject surface, int w, int h) +{ + lockSurface(); + m_surface = surface; + + if (surface && w && h) { + if (w != m_bitmapWidth || h != m_bitmapHeight) { + if (m_bitmap) + env->DeleteGlobalRef(m_bitmap); + m_bitmap = env->NewGlobalRef(QtAndroid::createBitmap(w, h, m_format, env)); + AndroidBitmapInfo info; + int res = AndroidBitmap_getInfo(env, m_bitmap, &info); + Q_ASSERT(res > -1); + m_bitmapStride = info.stride; + m_bitmapWidth = info.width; + m_bitmapHeight = info.height; + } + } else { + if (m_bitmap) { + env->DeleteGlobalRef(m_bitmap); + m_bitmap = 0; + } + } + unlockSurface(); + m_surfaceWaitCondition.wakeOne(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h index 9f8807b995..2310b31a51 100644 --- a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.h +++ b/src/plugins/platforms/android/qandroidplatformscreen.h @@ -1,6 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -42,21 +43,78 @@ #ifndef QANDROIDPLATFORMSCREEN_H #define QANDROIDPLATFORMSCREEN_H -#include <QtPlatformSupport/private/qfbscreen_p.h> +#include <qpa/qplatformscreen.h> +#include <QList> +#include <QPainter> +#include <QTimer> +#include <QWaitCondition> +#include <QtCore/private/qjni_p.h> -class QAndroidPlatformScreen: public QFbScreen +#include "androidsurfaceclient.h" + +QT_BEGIN_NAMESPACE + +class QAndroidPlatformWindow; +class QAndroidPlatformBackingStore; + +class QAndroidPlatformScreen: public QObject, public QPlatformScreen, public AndroidSurfaceClient { Q_OBJECT public: QAndroidPlatformScreen(); + ~QAndroidPlatformScreen(); + + QRect geometry() const { return m_geometry; } + int depth() const { return m_depth; } + QImage::Format format() const { return m_format; } + QSizeF physicalSize() const { return m_physicalSize; } + + inline QWindow *topWindow() const; + QWindow *topLevelAt(const QPoint & p) const; + + // compositor api + void addWindow(QAndroidPlatformWindow *window); + void removeWindow(QAndroidPlatformWindow *window); + void raise(QAndroidPlatformWindow *window); + void lower(QAndroidPlatformWindow *window); + + void scheduleUpdate(); void topWindowChanged(QWindow *w); + +public slots: + void setDirty(const QRect &rect); + void setPhysicalSize(const QSize &size); + void setGeometry(const QRect &rect); + +protected: + typedef QList<QAndroidPlatformWindow *> WindowStackType; + WindowStackType m_windowStack; + QRegion m_repaintRegion; + QTimer m_redrawTimer; + + QRect m_geometry; + int m_depth; + QImage::Format m_format; + QSizeF m_physicalSize; + +private: QDpi logicalDpi() const; Qt::ScreenOrientation orientation() const; Qt::ScreenOrientation nativeOrientation() const; + void surfaceChanged(JNIEnv *env, jobject surface, int w, int h); -public slots: - QRegion doRedraw(); +private slots: + void doRedraw(); +private: + int m_id = -1; + QJNIObjectPrivate m_surface; + jobject m_bitmap = nullptr; + QWaitCondition m_surfaceWaitCondition; + int m_bitmapStride = -1; + int m_bitmapWidth = -1; + int m_bitmapHeight = -1; }; +QT_END_NAMESPACE #endif diff --git a/src/plugins/platforms/android/src/qandroidplatformservices.cpp b/src/plugins/platforms/android/qandroidplatformservices.cpp index 0df882f1f0..0df882f1f0 100644 --- a/src/plugins/platforms/android/src/qandroidplatformservices.cpp +++ b/src/plugins/platforms/android/qandroidplatformservices.cpp diff --git a/src/plugins/platforms/android/src/qandroidplatformservices.h b/src/plugins/platforms/android/qandroidplatformservices.h index 8368b19043..8368b19043 100644 --- a/src/plugins/platforms/android/src/qandroidplatformservices.h +++ b/src/plugins/platforms/android/qandroidplatformservices.h diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp b/src/plugins/platforms/android/qandroidplatformtheme.cpp index 308bb70faf..ab29541f15 100644 --- a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp +++ b/src/plugins/platforms/android/qandroidplatformtheme.cpp @@ -46,6 +46,7 @@ #include "qandroidplatformdialoghelpers.h" #include <QVariant> #include <QFileInfo> +#include <QCoreApplication> #include <qandroidplatformintegration.h> QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface) @@ -152,6 +153,21 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const } } +QString QAndroidPlatformTheme::standardButtonText(int button) const +{ + switch (button) { + case QMessageDialogOptions::Yes: + return QCoreApplication::translate("QAndroidPlatformTheme", "Yes"); + case QMessageDialogOptions::YesToAll: + return QCoreApplication::translate("QAndroidPlatformTheme", "Yes to All"); + case QMessageDialogOptions::No: + return QCoreApplication::translate("QAndroidPlatformTheme", "No"); + case QMessageDialogOptions::NoToAll: + return QCoreApplication::translate("QAndroidPlatformTheme", "No to All"); + } + return QPlatformTheme::standardButtonText(button); +} + bool QAndroidPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { if (type == MessageDialog) diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.h b/src/plugins/platforms/android/qandroidplatformtheme.h index ec259a9b0a..544061a7a2 100644 --- a/src/plugins/platforms/android/src/qandroidplatformtheme.h +++ b/src/plugins/platforms/android/qandroidplatformtheme.h @@ -54,6 +54,7 @@ public: virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QFont *font(Font type = SystemFont) const; virtual QVariant themeHint(ThemeHint hint) const; + QString standardButtonText(int button) const Q_DECL_OVERRIDE; virtual bool usePlatformNativeDialog(DialogType type) const; virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const; diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp index 7ff18526d9..7c2dfd6bac 100644 --- a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -40,63 +41,117 @@ ****************************************************************************/ #include "qandroidplatformwindow.h" +#include "qandroidplatformopenglcontext.h" +#include "qandroidplatformscreen.h" #include "androidjnimain.h" #include <qpa/qwindowsysteminterface.h> +QT_BEGIN_NAMESPACE + QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window) - : QFbWindow(window) + : QPlatformWindow(window) { + m_windowFlags = Qt::Widget; + m_windowState = Qt::WindowNoState; + static QAtomicInt winIdGenerator(1); + m_windowId = winIdGenerator.fetchAndAddRelaxed(1); + setWindowState(window->windowState()); } -void QAndroidPlatformWindow::setGeometry(const QRect &rect) +void QAndroidPlatformWindow::lower() { - QFbWindow::setGeometry(rect); + platformScreen()->lower(this); } -void QAndroidPlatformWindow::propagateSizeHints() +void QAndroidPlatformWindow::raise() { - //shut up warning from default implementation + updateStatusBarVisibility(); + platformScreen()->raise(this); } -void QAndroidPlatformWindow::updateStatusBarVisibility() +void QAndroidPlatformWindow::setGeometry(const QRect &rect) { - Qt::WindowFlags flags = window()->flags(); - bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; - if (!isNonRegularWindow) { - if (mWindowState & Qt::WindowFullScreen) - QtAndroid::hideStatusBar(); - else if (mWindowState & Qt::WindowMaximized) - QtAndroid::showStatusBar(); - } + QWindowSystemInterface::handleGeometryChange(window(), rect); + QPlatformWindow::setGeometry(rect); } -void QAndroidPlatformWindow::raise() +void QAndroidPlatformWindow::setVisible(bool visible) { - updateStatusBarVisibility(); - QFbWindow::raise(); + if (visible) + updateStatusBarVisibility(); + + if (visible) { + if (m_windowState & Qt::WindowFullScreen) + setGeometry(platformScreen()->geometry()); + else if (m_windowState & Qt::WindowMaximized) + setGeometry(platformScreen()->availableGeometry()); + } + + QPlatformWindow::setVisible(visible); + + if (visible) + platformScreen()->addWindow(this); + else + platformScreen()->removeWindow(this); + + // The Android Activity is activated before Qt is initialized, causing the application state to + // never be set to 'active'. We explicitly set this state when the first window becomes visible. + if (visible) + QtAndroid::setApplicationActive(); } void QAndroidPlatformWindow::setWindowState(Qt::WindowState state) { - if (mWindowState == state) + if (m_windowState == state) return; + QPlatformWindow::setWindowState(state); + m_windowState = state; + if (window()->isVisible()) updateStatusBarVisibility(); +} - QFbWindow::setWindowState(state); +void QAndroidPlatformWindow::setWindowFlags(Qt::WindowFlags flags) +{ + if (m_windowFlags == flags) + return; + + m_windowFlags = flags; } -void QAndroidPlatformWindow::setVisible(bool visible) +Qt::WindowFlags QAndroidPlatformWindow::windowFlags() const { - if (visible) - updateStatusBarVisibility(); + return m_windowFlags; +} - QFbWindow::setVisible(visible); +QAndroidPlatformScreen *QAndroidPlatformWindow::platformScreen() const +{ + return static_cast<QAndroidPlatformScreen *>(window()->screen()->handle()); +} - // The Android Activity is activated before Qt is initialized, causing the application state to - // never be set to 'active'. We explicitly set this state when the first window becomes visible. - if (visible) - QtAndroid::setApplicationActive(); +void QAndroidPlatformWindow::propagateSizeHints() +{ + //shut up warning from default implementation } + +void QAndroidPlatformWindow::requestActivateWindow() +{ + platformScreen()->topWindowChanged(window()); +} + +void QAndroidPlatformWindow::updateStatusBarVisibility() +{ + Qt::WindowFlags flags = window()->flags(); + bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; + if (!isNonRegularWindow) { + if (m_windowState & Qt::WindowFullScreen) + QtAndroid::hideStatusBar(); + else if (m_windowState & Qt::WindowMaximized) + QtAndroid::showStatusBar(); + } +} + + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h index 9e3f203201..db3cb35368 100644 --- a/src/plugins/platforms/android/src/raster/qandroidplatformwindow.h +++ b/src/plugins/platforms/android/qandroidplatformwindow.h @@ -1,6 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the plugins of the Qt Toolkit. @@ -42,23 +43,45 @@ #ifndef ANDROIDPLATFORMWINDOW_H #define ANDROIDPLATFORMWINDOW_H #include <qobject.h> -#include <QtPlatformSupport/private/qfbwindow_p.h> +#include <qrect.h> +#include <qpa/qplatformwindow.h> -class QAndroidPlatformWindow: public QObject, public QFbWindow +QT_BEGIN_NAMESPACE + +class QAndroidPlatformScreen; + +class QAndroidPlatformWindow: public QPlatformWindow { - Q_OBJECT public: explicit QAndroidPlatformWindow(QWindow *window); - void propagateSizeHints(); - + void lower(); void raise(); - void setWindowState(Qt::WindowState state); + void setVisible(bool visible); + + void setWindowState(Qt::WindowState state); + void setWindowFlags(Qt::WindowFlags flags); + Qt::WindowFlags windowFlags() const; + + WId winId() const { return m_windowId; } + + QAndroidPlatformScreen *platformScreen() const; + + void propagateSizeHints(); + void requestActivateWindow(); void updateStatusBarVisibility(); + inline bool isRaster() const { return window()->surfaceType() == QSurface::RasterSurface; } -public slots: +protected: void setGeometry(const QRect &rect); + +protected: + Qt::WindowFlags m_windowFlags; + Qt::WindowState m_windowState; + + WId m_windowId; }; +QT_END_NAMESPACE #endif // ANDROIDPLATFORMWINDOW_H diff --git a/src/plugins/platforms/android/src/qandroidsystemlocale.cpp b/src/plugins/platforms/android/qandroidsystemlocale.cpp index a20f970a44..a20f970a44 100644 --- a/src/plugins/platforms/android/src/qandroidsystemlocale.cpp +++ b/src/plugins/platforms/android/qandroidsystemlocale.cpp diff --git a/src/plugins/platforms/android/src/qandroidsystemlocale.h b/src/plugins/platforms/android/qandroidsystemlocale.h index fc2f6fad98..fc2f6fad98 100644 --- a/src/plugins/platforms/android/src/qandroidsystemlocale.h +++ b/src/plugins/platforms/android/qandroidsystemlocale.h diff --git a/src/plugins/platforms/android/raster/raster.pro b/src/plugins/platforms/android/raster/raster.pro deleted file mode 100644 index 53d8ee7a2b..0000000000 --- a/src/plugins/platforms/android/raster/raster.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = qtforandroid - -PLUGIN_TYPE = platforms - -# STATICPLUGIN needed because there's a Q_IMPORT_PLUGIN in androidjnimain.cpp -# Yes, the plugin imports itself statically -DEFINES += QT_STATICPLUGIN - -load(qt_plugin) - -!contains(ANDROID_PLATFORM, android-9) { - INCLUDEPATH += $$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/include - LIBS += -L$$NDK_ROOT/platforms/android-9/arch-$$ANDROID_ARCHITECTURE/usr/lib -ljnigraphics -landroid -} else { - LIBS += -ljnigraphics -landroid -} - -include($$PWD/../src/src.pri) -include($$PWD/../src/raster/raster.pri) diff --git a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp b/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp deleted file mode 100644 index 6ed805174b..0000000000 --- a/src/plugins/platforms/android/src/opengl/qandroidopenglplatformwindow.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidopenglplatformwindow.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" -#include <qpa/qwindowsysteminterface.h> - -QT_BEGIN_NAMESPACE - -EGLSurface QAndroidOpenGLPlatformWindow::m_staticSurface = 0; -EGLNativeWindowType QAndroidOpenGLPlatformWindow::m_staticNativeWindow = 0; -QReadWriteLock QAndroidOpenGLPlatformWindow::m_staticSurfaceLock; -QBasicAtomicInt QAndroidOpenGLPlatformWindow::m_referenceCount = Q_BASIC_ATOMIC_INITIALIZER(0); - -QAndroidOpenGLPlatformWindow::QAndroidOpenGLPlatformWindow(QWindow *window) - : QEglFSWindow(window) - , m_state(Qt::WindowNoState) -{ -} - -QAndroidOpenGLPlatformWindow::~QAndroidOpenGLPlatformWindow() -{ - destroy(); -} - -bool QAndroidOpenGLPlatformWindow::isExposed() const -{ - return QtAndroid::nativeWindow(false) != 0 && QEglFSWindow::isExposed(); -} - -void QAndroidOpenGLPlatformWindow::invalidateSurface() -{ - QWindowSystemInterface::handleExposeEvent(window(), QRegion()); // Obscure event - QWindowSystemInterface::flushWindowSystemEvents(); - - m_window = 0; - m_surface = 0; - - if (!m_referenceCount.deref()){ - QWriteLocker locker(&m_staticSurfaceLock); - - EGLDisplay display = (static_cast<QEglFSScreen *>(window()->screen()->handle()))->display(); - eglDestroySurface(display, m_staticSurface); - - m_staticSurface = 0; - m_staticNativeWindow = 0; - } -} - -void QAndroidOpenGLPlatformWindow::updateStaticNativeWindow() -{ - QWriteLocker locker(&m_staticSurfaceLock); - m_staticNativeWindow = QtAndroid::nativeWindow(false); -} - -void QAndroidOpenGLPlatformWindow::resetSurface() -{ - // Only add a reference if we're not already holding one, otherwise we're just updating - // the native window pointer - if (m_window == 0) - m_referenceCount.ref(); - - if (m_staticSurface == 0) { - QWriteLocker locker(&m_staticSurfaceLock); - QEglFSWindow::resetSurface(); - m_staticSurface = m_surface; - m_staticNativeWindow = m_window; - } else { - QReadLocker locker(&m_staticSurfaceLock); - m_window = m_staticNativeWindow; - m_surface = m_staticSurface; - } - - { - lock(); - // Use the desktop size. - // On some devices, the getters for the native window size gives wrong values - scheduleResize(QAndroidPlatformIntegration::defaultDesktopSize()); - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event - unlock(); - } - - QWindowSystemInterface::flushWindowSystemEvents(); -} - -void QAndroidOpenGLPlatformWindow::destroy() -{ - if (!m_referenceCount.deref()) { - QEglFSWindow::destroy(); - } else { - m_window = 0; - m_surface = 0; - } -} - -void QAndroidOpenGLPlatformWindow::updateStatusBarVisibility() -{ - Qt::WindowFlags flags = window()->flags(); - bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window; - if (!isNonRegularWindow) { - if (m_state & Qt::WindowFullScreen) - QtAndroid::hideStatusBar(); - else if (m_state & Qt::WindowMaximized) - QtAndroid::showStatusBar(); - } -} - -void QAndroidOpenGLPlatformWindow::raise() -{ - updateStatusBarVisibility(); -} - -void QAndroidOpenGLPlatformWindow::setWindowState(Qt::WindowState state) -{ - if (m_state == state) - return; - - m_state = state; - if (window()->isVisible()) - updateStatusBarVisibility(); -} - -void QAndroidOpenGLPlatformWindow::setVisible(bool visible) -{ - if (visible) - updateStatusBarVisibility(); - - QEglFSWindow::setVisible(visible); - - // The Android Activity is activated before Qt is initialized, causing the application state to - // never be set to 'active'. We explicitly set this state when the first window becomes visible. - if (visible) - QtAndroid::setApplicationActive(); - - QWindowSystemInterface::handleExposeEvent(window(), QRegion(geometry())); // Expose event - QWindowSystemInterface::flushWindowSystemEvents(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp b/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp deleted file mode 100644 index 278cd553f4..0000000000 --- a/src/plugins/platforms/android/src/opengl/qeglfshooks_android.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qeglfshooks.h" -#include "androidjnimain.h" -#include "qandroidplatformintegration.h" - -#include <android/native_window.h> -#include <jni.h> - -QT_BEGIN_NAMESPACE - -class QEglFSAndroidHooks: public QEglFSHooks -{ -public: - void platformInit(); - void platformDestroy(); - EGLNativeDisplayType platformDisplay() const; - QSize screenSize() const; - QSizeF physicalScreenSize() const; - QDpi logicalDpi() const; - Qt::ScreenOrientation orientation() const; - Qt::ScreenOrientation nativeOrientation() const; - int screenDepth() const; - QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &inputFormat) const; - EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format); - void destroyNativeWindow(EGLNativeWindowType window); - bool hasCapability(QPlatformIntegration::Capability cap) const; - QEglFSCursor *createCursor(QEglFSScreen *screen) const; -}; - -void QEglFSAndroidHooks::platformInit() -{ -} - -void QEglFSAndroidHooks::platformDestroy() -{ -} - -EGLNativeDisplayType QEglFSAndroidHooks::platformDisplay() const -{ - return EGL_DEFAULT_DISPLAY; -} - -QSize QEglFSAndroidHooks::screenSize() const -{ - return QAndroidPlatformIntegration::defaultDesktopSize(); -} - -QSizeF QEglFSAndroidHooks::physicalScreenSize() const -{ - return QSizeF(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth, QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); -} - -QDpi QEglFSAndroidHooks::logicalDpi() const -{ - qreal lDpi = QtAndroid::scaledDensity() * 72; - return QDpi(lDpi, lDpi); -} - -Qt::ScreenOrientation QEglFSAndroidHooks::orientation() const -{ - return QAndroidPlatformIntegration::m_orientation; -} - -Qt::ScreenOrientation QEglFSAndroidHooks::nativeOrientation() const -{ - return QAndroidPlatformIntegration::m_nativeOrientation; -} - -EGLNativeWindowType QEglFSAndroidHooks::createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format) -{ - Q_UNUSED(platformWindow); - Q_UNUSED(size); - Q_UNUSED(format); - ANativeWindow *window = QtAndroid::nativeWindow(); - if (window != 0) - ANativeWindow_acquire(window); - - return window; -} - -void QEglFSAndroidHooks::destroyNativeWindow(EGLNativeWindowType window) -{ - if (window != 0) - ANativeWindow_release(window); -} - -bool QEglFSAndroidHooks::hasCapability(QPlatformIntegration::Capability capability) const -{ - switch (capability) { - case QPlatformIntegration::OpenGL: return true; - case QPlatformIntegration::ThreadedOpenGL: return true; - default: return false; - }; -} - -int QEglFSAndroidHooks::screenDepth() const -{ - // ### Hardcoded - return 32; -} - -QSurfaceFormat QEglFSAndroidHooks::surfaceFormatFor(const QSurfaceFormat &inputFormat) const -{ - QSurfaceFormat ret(inputFormat); - ret.setAlphaBufferSize(8); - ret.setRedBufferSize(8); - ret.setGreenBufferSize(8); - ret.setBlueBufferSize(8); - return ret; -} - -QEglFSCursor *QEglFSAndroidHooks::createCursor(QEglFSScreen *screen) const -{ - Q_UNUSED(screen); - return 0; -} - -static QEglFSAndroidHooks eglFSAndroidHooks; -QEglFSHooks *platformHooks = &eglFSAndroidHooks; - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp b/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp deleted file mode 100644 index 2e59c307c3..0000000000 --- a/src/plugins/platforms/android/src/raster/qandroidplatformscreen.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> -** Contact: http://www.qt-project.org/legal -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidplatformscreen.h" -#include "qandroidplatformintegration.h" -#include "androidjnimain.h" -#include "androidjnimenu.h" -#include "qandroidplatformwindow.h" - -QAndroidPlatformScreen::QAndroidPlatformScreen():QFbScreen() -{ - mGeometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight); - mFormat = QImage::Format_RGB16; - mDepth = 16; - mPhysicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight); - mPhysicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth); - initializeCompositor(); -} - -void QAndroidPlatformScreen::topWindowChanged(QWindow *w) -{ - QtAndroidMenu::setActiveTopLevelWindow(w); - - if (w != 0) { - QAndroidPlatformWindow *platformWindow = static_cast<QAndroidPlatformWindow *>(w->handle()); - if (platformWindow != 0) - platformWindow->updateStatusBarVisibility(); - } -} - -QRegion QAndroidPlatformScreen::doRedraw() -{ - QRegion touched; - touched = QFbScreen::doRedraw(); - if (touched.isEmpty()) - return touched; - - QtAndroid::flushImage(mGeometry.topLeft(), *mScreenImage, touched.boundingRect()); - return touched; -} - -QDpi QAndroidPlatformScreen::logicalDpi() const -{ - qreal lDpi = QtAndroid::scaledDensity() * 72; - return QDpi(lDpi, lDpi); -} - -Qt::ScreenOrientation QAndroidPlatformScreen::orientation() const -{ - return QAndroidPlatformIntegration::m_orientation; -} - -Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const -{ - return QAndroidPlatformIntegration::m_nativeOrientation; -} diff --git a/src/plugins/platforms/android/src/raster/raster.pri b/src/plugins/platforms/android/src/raster/raster.pri deleted file mode 100644 index 86e5aa235f..0000000000 --- a/src/plugins/platforms/android/src/raster/raster.pri +++ /dev/null @@ -1,7 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += $$PWD/qandroidplatformscreen.cpp \ - $$PWD/qandroidplatformwindow.cpp - -HEADERS += $$PWD/qandroidplatformscreen.h \ - $$PWD/qandroidplatformwindow.h diff --git a/src/plugins/platforms/android/src/src.pri b/src/plugins/platforms/android/src/src.pri deleted file mode 100644 index 9b64e846f7..0000000000 --- a/src/plugins/platforms/android/src/src.pri +++ /dev/null @@ -1,55 +0,0 @@ -load(qt_plugin) - -QT += core-private gui-private platformsupport-private - -CONFIG += qpa/genericunixfontdatabase - -OTHER_FILES += $$PWD/android.json - -INCLUDEPATH += $$PWD -INCLUDEPATH += $$PWD/../../../../3rdparty/android/src - -SOURCES += $$PWD/androidplatformplugin.cpp \ - $$PWD/androidjnimain.cpp \ - $$PWD/androidjniaccessibility.cpp \ - $$PWD/androidjniinput.cpp \ - $$PWD/androidjnimenu.cpp \ - $$PWD/androidjniclipboard.cpp \ - $$PWD/qandroidplatformintegration.cpp \ - $$PWD/qandroidplatformservices.cpp \ - $$PWD/qandroidassetsfileenginehandler.cpp \ - $$PWD/qandroidinputcontext.cpp \ - $$PWD/qandroidplatformaccessibility.cpp \ - $$PWD/qandroidplatformfontdatabase.cpp \ - $$PWD/qandroidplatformdialoghelpers.cpp \ - $$PWD/qandroidplatformclipboard.cpp \ - $$PWD/qandroidplatformtheme.cpp \ - $$PWD/qandroidplatformmenubar.cpp \ - $$PWD/qandroidplatformmenu.cpp \ - $$PWD/qandroidplatformmenuitem.cpp \ - $$PWD/qandroidsystemlocale.cpp - - -HEADERS += $$PWD/qandroidplatformintegration.h \ - $$PWD/androidjnimain.h \ - $$PWD/androidjniaccessibility.h \ - $$PWD/androidjniinput.h \ - $$PWD/androidjnimenu.h \ - $$PWD/androidjniclipboard.h \ - $$PWD/qandroidplatformservices.h \ - $$PWD/qandroidassetsfileenginehandler.h \ - $$PWD/qandroidinputcontext.h \ - $$PWD/qandroidplatformaccessibility.h \ - $$PWD/qandroidplatformfontdatabase.h \ - $$PWD/qandroidplatformclipboard.h \ - $$PWD/qandroidplatformdialoghelpers.h \ - $$PWD/qandroidplatformtheme.h \ - $$PWD/qandroidplatformmenubar.h \ - $$PWD/qandroidplatformmenu.h \ - $$PWD/qandroidplatformmenuitem.h \ - $$PWD/qandroidsystemlocale.h - - -#Non-standard install directory, QTBUG-29859 -DESTDIR = $$DESTDIR/android -target.path = $${target.path}/android |