diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-02-19 12:02:15 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-02-19 12:02:49 +0100 |
commit | bcc965ef4bae2565456522b19687a3e726da8315 (patch) | |
tree | 905c4228ed9e5a15ad818e90a5ad665271d7698a /src/plugins/platforms | |
parent | d40aca0840ca998636f8bdbc217f2a0a5f89c2a6 (diff) | |
parent | 9b49b375e3d753fa3cd8166da266724a85cfe389 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Change-Id: I7bee7df50af3d607a349b68103cd2c67791281fb
Diffstat (limited to 'src/plugins/platforms')
6 files changed, 60 insertions, 32 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 1eae295724..6340d47c18 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -78,6 +78,7 @@ static AAssetManager *m_assetManager = nullptr; static jobject m_resourcesObj = nullptr; static jobject m_activityObject = nullptr; static jmethodID m_createSurfaceMethodID = nullptr; +static jobject m_serviceObject = nullptr; static jmethodID m_setSurfaceGeometryMethodID = nullptr; static jmethodID m_destroySurfaceMethodID = nullptr; @@ -193,6 +194,11 @@ namespace QtAndroid return m_activityObject; } + jobject service() + { + return m_serviceObject; + } + void showStatusBar() { if (m_statusBarShowing) @@ -534,7 +540,6 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para return pthread_create(&m_qtAppThread, nullptr, startMainMethod, nullptr) == 0; } - static void quitQtAndroidPlugin(JNIEnv *env, jclass /*clazz*/) { Q_UNUSED(env); @@ -553,6 +558,8 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/) env->DeleteGlobalRef(m_resourcesObj); if (m_activityObject) env->DeleteGlobalRef(m_activityObject); + if (m_serviceObject) + env->DeleteGlobalRef(m_serviceObject); if (m_bitmapClass) env->DeleteGlobalRef(m_bitmapClass); if (m_ARGB_8888_BitmapConfigValue) @@ -785,20 +792,26 @@ static int registerNatives(JNIEnv *env) jmethodID methodID; GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "activity", "()Landroid/app/Activity;"); jobject activityObject = env->CallStaticObjectMethod(m_applicationClass, methodID); + GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "service", "()Landroid/app/Service;"); + jobject serviceObject = env->CallStaticObjectMethod(m_applicationClass, methodID); GET_AND_CHECK_STATIC_METHOD(methodID, m_applicationClass, "classLoader", "()Ljava/lang/ClassLoader;"); m_classLoaderObject = env->NewGlobalRef(env->CallStaticObjectMethod(m_applicationClass, methodID)); clazz = env->GetObjectClass(m_classLoaderObject); GET_AND_CHECK_METHOD(m_loadClassMethodID, clazz, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); + if (serviceObject) + m_serviceObject = env->NewGlobalRef(serviceObject); - if (activityObject) { + if (activityObject) m_activityObject = env->NewGlobalRef(activityObject); + jobject object = activityObject ? activityObject : serviceObject; + if (object) { FIND_AND_CHECK_CLASS("android/content/ContextWrapper"); GET_AND_CHECK_METHOD(methodID, clazz, "getAssets", "()Landroid/content/res/AssetManager;"); - m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(activityObject, methodID)); + m_assetManager = AAssetManager_fromJava(env, env->CallObjectMethod(object, methodID)); GET_AND_CHECK_METHOD(methodID, clazz, "getResources", "()Landroid/content/res/Resources;"); - m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(activityObject, methodID)); + m_resourcesObj = env->NewGlobalRef(env->CallObjectMethod(object, methodID)); FIND_AND_CHECK_CLASS("android/graphics/Bitmap"); m_bitmapClass = static_cast<jclass>(env->NewGlobalRef(clazz)); @@ -819,8 +832,6 @@ static int registerNatives(JNIEnv *env) "(Landroid/content/res/Resources;Landroid/graphics/Bitmap;)V"); } - - return JNI_TRUE; } diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h index e3c18b2e7a..218e52ccc1 100644 --- a/src/plugins/platforms/android/androidjnimain.h +++ b/src/plugins/platforms/android/androidjnimain.h @@ -83,6 +83,7 @@ namespace QtAndroid AAssetManager *assetManager(); jclass applicationClass(); jobject activity(); + jobject service(); void setApplicationActive(); diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 1f8ee79396..80d7e31aa3 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -66,7 +66,6 @@ #include "qandroidplatformtheme.h" #include "qandroidsystemlocale.h" - QT_BEGIN_NAMESPACE int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320; @@ -87,6 +86,8 @@ void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteA return QtAndroid::javaVM(); if (resource == "QtActivity") return QtAndroid::activity(); + if (resource == "QtService") + return QtAndroid::service(); if (resource == "AndroidStyleData") { if (m_androidStyle) { if (m_androidStyle->m_styleData.isEmpty()) @@ -122,7 +123,6 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ #endif { Q_UNUSED(paramList); - m_androidPlatformNativeInterface = new QAndroidPlatformNativeInterface(); m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); @@ -159,6 +159,9 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ #endif // QT_NO_ACCESSIBILITY QJNIObjectPrivate javaActivity(QtAndroid::activity()); + if (!javaActivity.isValid()) + javaActivity = QtAndroid::service(); + if (javaActivity.isValid()) { QJNIObjectPrivate resources = javaActivity.callObjectMethod("getResources", "()Landroid/content/res/Resources;"); QJNIObjectPrivate configuration = resources.callObjectMethod("getConfiguration", "()Landroid/content/res/Configuration;"); @@ -205,13 +208,13 @@ static bool needsBasicRenderloopWorkaround() bool QAndroidPlatformIntegration::hasCapability(Capability cap) const { switch (cap) { - case ThreadedPixmaps: return true; case ApplicationState: return true; - case NativeWidgets: return true; - case OpenGL: return true; - case ForeignWindows: return true; - case ThreadedOpenGL: return !needsBasicRenderloopWorkaround(); - case RasterGLSurface: return true; + case ThreadedPixmaps: return true; + case NativeWidgets: return QtAndroid::activity(); + case OpenGL: return QtAndroid::activity(); + case ForeignWindows: return QtAndroid::activity(); + case ThreadedOpenGL: return !needsBasicRenderloopWorkaround() && QtAndroid::activity(); + case RasterGLSurface: return QtAndroid::activity(); default: return QPlatformIntegration::hasCapability(cap); } @@ -219,11 +222,15 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const QPlatformBackingStore *QAndroidPlatformIntegration::createPlatformBackingStore(QWindow *window) const { + if (!QtAndroid::activity()) + return nullptr; return new QAndroidPlatformBackingStore(window); } QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const { + if (!QtAndroid::activity()) + return nullptr; QSurfaceFormat format(context->format()); format.setAlphaBufferSize(8); format.setRedBufferSize(8); @@ -234,6 +241,8 @@ QPlatformOpenGLContext *QAndroidPlatformIntegration::createPlatformOpenGLContext QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const { + if (!QtAndroid::activity()) + return nullptr; QSurfaceFormat format(surface->requestedFormat()); format.setAlphaBufferSize(8); format.setRedBufferSize(8); @@ -245,6 +254,8 @@ QPlatformOffscreenSurface *QAndroidPlatformIntegration::createPlatformOffscreenS QPlatformWindow *QAndroidPlatformIntegration::createPlatformWindow(QWindow *window) const { + if (!QtAndroid::activity()) + return nullptr; if (window->type() == Qt::ForeignWindow) return new QAndroidPlatformForeignWindow(window); else diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp index dd29c29bab..aa4fa94f0a 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.cpp +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -294,6 +294,8 @@ int QAndroidPlatformScreen::rasterSurfaces() void QAndroidPlatformScreen::doRedraw() { PROFILE_SCOPE; + if (!QtAndroid::activity()) + return; if (m_dirtyRect.isEmpty()) return; diff --git a/src/plugins/platforms/android/qandroidsystemlocale.cpp b/src/plugins/platforms/android/qandroidsystemlocale.cpp index 1528d90d06..7fe36aa9bc 100644 --- a/src/plugins/platforms/android/qandroidsystemlocale.cpp +++ b/src/plugins/platforms/android/qandroidsystemlocale.cpp @@ -56,6 +56,8 @@ void QAndroidSystemLocale::getLocaleFromJava() const QJNIObjectPrivate javaLocaleObject; QJNIObjectPrivate javaActivity(QtAndroid::activity()); + if (!javaActivity.isValid()) + javaActivity = QtAndroid::service(); if (javaActivity.isValid()) { QJNIObjectPrivate resources = javaActivity.callObjectMethod("getResources", "()Landroid/content/res/Resources;"); QJNIObjectPrivate configuration = resources.callObjectMethod("getConfiguration", "()Landroid/content/res/Configuration;"); diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 22a2922235..464fcc886f 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -376,12 +376,13 @@ static void setWindowOpacity(HWND hwnd, Qt::WindowFlags flags, bool hasAlpha, bo Q_UNUSED(level); #else if (QWindowsWindow::setWindowLayered(hwnd, flags, hasAlpha, level)) { + const BYTE alpha = BYTE(qRound(255.0 * level)); if (hasAlpha && !openGL && (flags & Qt::FramelessWindowHint)) { // Non-GL windows with alpha: Use blend function to update. - BLENDFUNCTION blend = {AC_SRC_OVER, 0, (BYTE)(255.0 * level), AC_SRC_ALPHA}; + BLENDFUNCTION blend = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA}; QWindowsContext::user32dll.updateLayeredWindow(hwnd, NULL, NULL, NULL, NULL, NULL, 0, &blend, ULW_ALPHA); } else { - QWindowsContext::user32dll.setLayeredWindowAttributes(hwnd, 0, (int)(level * 255), LWA_ALPHA); + QWindowsContext::user32dll.setLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA); } } else if (IsWindowVisible(hwnd)) { // Repaint when switching from layered. InvalidateRect(hwnd, NULL, TRUE); @@ -505,7 +506,7 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag QVariant prop = w->property("_q_embedded_native_parent_handle"); if (prop.isValid()) { embedded = true; - parentHandle = (HWND)prop.value<WId>(); + parentHandle = reinterpret_cast<HWND>(prop.value<WId>()); } if (creationFlags & ForceChild) { @@ -680,10 +681,10 @@ void WindowCreationData::applyWindowFlags(HWND hwnd) const if (newExStyle != oldExStyle) SetWindowLongPtr(hwnd, GWL_EXSTYLE, newExStyle); qCDebug(lcQpaWindows).nospace() << __FUNCTION__ << hwnd << *this - << "\n Style from " << debugWinStyle(oldStyle) << "\n to " - << debugWinStyle(newStyle) << "\n ExStyle from " - << debugWinExStyle(oldExStyle) << " to " - << debugWinExStyle(newExStyle); + << "\n Style from " << debugWinStyle(DWORD(oldStyle)) << "\n to " + << debugWinStyle(DWORD(newStyle)) << "\n ExStyle from " + << debugWinExStyle(DWORD(oldExStyle)) << " to " + << debugWinExStyle(DWORD(newExStyle)); } void WindowCreationData::initialize(const QWindow *w, HWND hwnd, bool frameChange, qreal opacityLevel) const @@ -802,8 +803,8 @@ bool QWindowsGeometryHint::handleCalculateSize(const QMargins &customMargins, co #ifndef Q_OS_WINCE void QWindowsGeometryHint::applyToMinMaxInfo(HWND hwnd, MINMAXINFO *mmi) const { - return applyToMinMaxInfo(GetWindowLong(hwnd, GWL_STYLE), - GetWindowLong(hwnd, GWL_EXSTYLE), mmi); + return applyToMinMaxInfo(DWORD(GetWindowLong(hwnd, GWL_STYLE)), + DWORD(GetWindowLong(hwnd, GWL_EXSTYLE)), mmi); } void QWindowsGeometryHint::applyToMinMaxInfo(DWORD style, DWORD exStyle, MINMAXINFO *mmi) const @@ -1363,7 +1364,7 @@ void QWindowsWindow::updateTransientParent() const if (!tw->testFlag(WithinDestroy)) // Prevent destruction by parent window (QTBUG-35499, QTBUG-36666) newTransientParent = tw->handle(); if (newTransientParent != oldTransientParent) - SetWindowLongPtr(m_data.hwnd, GWL_HWNDPARENT, (LONG_PTR)newTransientParent); + SetWindowLongPtr(m_data.hwnd, GWL_HWNDPARENT, LONG_PTR(newTransientParent)); #endif // !Q_OS_WINCE } @@ -2015,7 +2016,7 @@ QMargins QWindowsWindow::frameMargins() const void QWindowsWindow::setOpacity(qreal level) { qCDebug(lcQpaWindows) << __FUNCTION__ << level; - if (m_opacity != level) { + if (!qFuzzyCompare(m_opacity, level)) { m_opacity = level; if (m_data.hwnd) setWindowOpacity(m_data.hwnd, m_data.flags, @@ -2317,7 +2318,7 @@ void QWindowsWindow::setAlertState(bool enabled) void QWindowsWindow::alertWindow(int durationMs) { - DWORD timeOutMs = GetCaretBlinkTime(); + UINT timeOutMs = GetCaretBlinkTime(); if (!timeOutMs || timeOutMs == INFINITE) timeOutMs = 250; @@ -2326,7 +2327,7 @@ void QWindowsWindow::alertWindow(int durationMs) info.hwnd = m_data.hwnd; info.dwFlags = FLASHW_TRAY; info.dwTimeout = timeOutMs; - info.uCount = durationMs == 0 ? 10 : durationMs / timeOutMs; + info.uCount = durationMs == 0 ? 10 : UINT(durationMs) / timeOutMs; FlashWindowEx(&info); } @@ -2379,11 +2380,11 @@ void QWindowsWindow::setWindowIcon(const QIcon &icon) m_iconBig = createHIcon(icon, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); if (m_iconBig) { - SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)m_iconSmall); - SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)m_iconBig); + SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, LPARAM(m_iconSmall)); + SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, LPARAM(m_iconBig)); } else { - SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)m_iconSmall); - SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, (LPARAM)m_iconSmall); + SendMessage(m_data.hwnd, WM_SETICON, 0 /* ICON_SMALL */, LPARAM(m_iconSmall)); + SendMessage(m_data.hwnd, WM_SETICON, 1 /* ICON_BIG */, LPARAM(m_iconSmall)); } } } @@ -2464,7 +2465,7 @@ void QWindowsWindow::registerTouchWindow(QWindowsWindowFunctions::TouchWindowTou // such as HCBT_CREATEWND if (ret || touchFlags != 0) return; - if (QWindowsContext::user32dll.registerTouchWindow(m_data.hwnd, (ULONG)touchTypes)) + if (QWindowsContext::user32dll.registerTouchWindow(m_data.hwnd, ULONG(touchTypes))) setFlag(TouchRegistered); else qErrnoWarning("RegisterTouchWindow() failed for window '%s'.", qPrintable(window()->objectName())); |