From c9dcb28824a3356163a8ac35ecdaaa8254825dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 4 Jul 2024 15:31:41 +0200 Subject: [PATCH] Android: Don't set geometry when creating surface or adding native view The window geometry has been propagated to the QtWindow layout already via setGeometry() already, so we don't need the additional plumbing for createSurface and setNativeView. It's enough to set the layout params of the inserted View to match the parent (the QtWindow in this case). Change-Id: I40b44282e80ed04b109ffc1958144cb3e3edd11d Reviewed-by: Petri Virkkunen Reviewed-by: Assam Boudjelthia (cherry picked from commit 9d398a18c24ab0a16ceb0346fc20b8eebf95410d) Reviewed-by: Qt Cherry-pick Bot --- .../jar/src/org/qtproject/qt/android/QtWindow.java | 6 +----- .../android/qandroidplatformforeignwindow.cpp | 6 +----- .../platforms/android/qandroidplatformwindow.cpp | 11 +---------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java index b690f591b35..135f61d0a02 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtWindow.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtWindow.java @@ -104,7 +104,6 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { @UsedFromNativeCode void createSurface(final boolean onTop, - final int x, final int y, final int w, final int h, final int imageDepth, final boolean isOpaque, final int surfaceContainerType) // TODO constant for type { @@ -112,7 +111,6 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { if (m_surfaceContainer != null) removeView(m_surfaceContainer); - setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); if (surfaceContainerType == 0) { m_surfaceContainer = new QtSurface(getContext(), QtWindow.this, onTop, imageDepth); @@ -165,15 +163,13 @@ class QtWindow extends QtLayout implements QtSurfaceInterface { } @UsedFromNativeCode - void setNativeView(final View view, - final int x, final int y, final int w, final int h) + void setNativeView(final View view) { QtNative.runAction(()-> { if (m_nativeView != null) removeView(m_nativeView); m_nativeView = view; - QtWindow.this.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); m_nativeView.setLayoutParams(new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); addView(m_nativeView); diff --git a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp index 7fe106ffe25..6bb0081a810 100644 --- a/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformforeignwindow.cpp @@ -91,11 +91,7 @@ void QAndroidPlatformForeignWindow::addViewToWindow() if (isEmbeddingContainer()) return; - jint x = 0, y = 0, w = -1, h = -1; - if (!geometry().isNull()) - geometry().getRect(&x, &y, &w, &h); - - m_nativeQtWindow.callMethod("setNativeView", m_view, x, y, qMax(w, 1), qMax(h, 1)); + m_nativeQtWindow.callMethod("setNativeView", m_view); m_nativeViewInserted = true; } diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp index 6a51fd17502..e86e617ca3e 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -284,19 +284,10 @@ void QAndroidPlatformWindow::applicationStateChanged(Qt::ApplicationState) void QAndroidPlatformWindow::createSurface() { - const QRect rect = geometry(); - jint x = 0, y = 0, w = -1, h = -1; - if (!rect.isNull()) { - x = rect.x(); - y = rect.y(); - w = std::max(rect.width(), 1); - h = std::max(rect.height(), 1); - } - const bool windowStaysOnTop = bool(window()->flags() & Qt::WindowStaysOnTopHint); const bool isOpaque = !format().hasAlpha() && qFuzzyCompare(window()->opacity(), 1.0); - m_nativeQtWindow.callMethod("createSurface", windowStaysOnTop, x, y, w, h, 32, isOpaque, + m_nativeQtWindow.callMethod("createSurface", windowStaysOnTop, 32, isOpaque, m_surfaceContainerType); m_surfaceCreated = true; }