diff options
author | Assam Boudjelthia <[email protected]> | 2025-01-06 18:02:18 +0200 |
---|---|---|
committer | Assam Boudjelthia <[email protected]> | 2025-01-22 20:33:18 +0200 |
commit | 65c41c6be663b5e028430600641490c556492494 (patch) | |
tree | d52e5c97db05ba2108bbe72f54a5154b8af14864 | |
parent | 6f79d46e80e7068d059bc5d40aa007d39ad15375 (diff) |
Android: get rid of default screen sizes and physical size
The default screen size and physical size are not needed, since
QAndroidPlatformScreen constructor calculates that shortly after we
assign it a default value. As for the default available geometry,
we need to keep that, but we can move that to live directly under
QAndroidPlatformScreen class, with that we can reduce the chained
calls from androidjnimain.cpp to the platform integration to the
platform screen.
Task-number: QTBUG-132720
Change-Id: Icd2db91ab36a68cd53c3dfb702f41f6b519e476b
Reviewed-by: Tor Arne Vestbø <[email protected]>
5 files changed, 17 insertions, 37 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 62348b473c0..67cedb048ea 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -20,6 +20,7 @@ #include "qandroidplatformdialoghelpers.h" #include "qandroidplatformintegration.h" #include "qandroidplatformclipboard.h" +#include "qandroidplatformscreen.h" #include "qandroidplatformwindow.h" #include <android/api-level.h> @@ -71,7 +72,6 @@ static void *m_mainLibraryHnd = nullptr; static QList<QByteArray> m_applicationParams; static sem_t m_exitSemaphore, m_terminateSemaphore; - static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr; static int m_availableWidthPixels = 0; @@ -580,14 +580,11 @@ static void setDisplayMetrics(JNIEnv * /*env*/, jclass /*clazz*/, qRound(double(screenHeightPixels) / ydpi * 25.4)); QMutexLocker lock(&m_platformMutex); - if (!m_androidPlatformIntegration) { - QAndroidPlatformIntegration::setDefaultDisplayMetrics( - availableGeometry.left(), availableGeometry.top(), availableGeometry.width(), - availableGeometry.height(), physicalSize.width(), physicalSize.height(), - screenSize.width(), screenSize.height()); - } else { - m_androidPlatformIntegration->setScreenSizeParameters(physicalSize, screenSize, - availableGeometry); + if (m_androidPlatformIntegration) { + m_androidPlatformIntegration->setScreenSizeParameters( + physicalSize, screenSize, availableGeometry); + } else if (QAndroidPlatformScreen::defaultAvailableGeometry().isNull()) { + QAndroidPlatformScreen::defaultAvailableGeometry() = availableGeometry; } } Q_DECLARE_JNI_NATIVE_METHOD(setDisplayMetrics) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index a311fb1adaf..497b5329227 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -46,10 +46,6 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; -Q_CONSTINIT QSize QAndroidPlatformIntegration::m_defaultScreenSize = QSize(320, 455); -Q_CONSTINIT QRect QAndroidPlatformIntegration::m_defaultAvailableGeometry = QRect(0, 0, 320, 455); -Q_CONSTINIT QSize QAndroidPlatformIntegration::m_defaultPhysicalSize = QSize(50, 71); - Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation; Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation; @@ -494,17 +490,6 @@ QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString & return 0; } -void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int availableLeft, int availableTop, - int availableWidth, int availableHeight, - int physicalWidth, int physicalHeight, - int screenWidth, int screenHeight) -{ - m_defaultAvailableGeometry = QRect(availableLeft, availableTop, - availableWidth, availableHeight); - m_defaultPhysicalSize = QSize(physicalWidth, physicalHeight); - m_defaultScreenSize = QSize(screenWidth, screenHeight); -} - void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation, Qt::ScreenOrientation nativeOrientation) { @@ -515,8 +500,8 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur void QAndroidPlatformIntegration::flushPendingUpdates() { if (m_primaryScreen) { - m_primaryScreen->setSizeParameters(m_defaultPhysicalSize, m_defaultScreenSize, - m_defaultAvailableGeometry); + m_primaryScreen->setSizeParameters(m_primaryScreen->physicalSize().toSize(), + m_primaryScreen->geometry().size(), m_primaryScreen->availableGeometry()); } } diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index 135790dda63..343c71b4991 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -99,9 +99,6 @@ public: QStringList themeNames() const override; QPlatformTheme *createPlatformTheme(const QString &name) const override; - static void setDefaultDisplayMetrics(int availableLeft, int availableTop, int availableWidth, - int availableHeight, int physicalWidth, int physicalHeight, - int screenWidth, int screenHeight); static void setScreenOrientation(Qt::ScreenOrientation currentOrientation, Qt::ScreenOrientation nativeOrientation); @@ -126,10 +123,6 @@ private: static Qt::ColorScheme m_colorScheme; - static QRect m_defaultAvailableGeometry; - static QSize m_defaultPhysicalSize; - static QSize m_defaultScreenSize; - static Qt::ScreenOrientation m_orientation; static Qt::ScreenOrientation m_nativeOrientation; static bool m_showPasswordEnabled; diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp index 012a1fb4635..bb8e6ecf376 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.cpp +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -63,10 +63,6 @@ Q_DECLARE_JNI_CLASS(DisplayMode, "android/view/Display$Mode") QAndroidPlatformScreen::QAndroidPlatformScreen(const QJniObject &displayObject) : QObject(), QPlatformScreen() { - m_availableGeometry = QAndroidPlatformIntegration::m_defaultAvailableGeometry; - m_size = QAndroidPlatformIntegration::m_defaultScreenSize; - m_physicalSize = QAndroidPlatformIntegration::m_defaultPhysicalSize; - // Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16 // is way much faster than 32 if (qEnvironmentVariableIntValue("QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) { @@ -92,6 +88,7 @@ QAndroidPlatformScreen::QAndroidPlatformScreen(const QJniObject &displayObject) "getDisplaySize", context, displayObject.object<QtJniTypes::Display>()); m_size = QSize(sizeObj.callMethod<int>("getWidth"), sizeObj.callMethod<int>("getHeight")); + m_availableGeometry = defaultAvailableGeometry(); const auto resources = context.callMethod<QtJniTypes::Resources>("getResources"); const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>("getDisplayMetrics"); @@ -324,4 +321,10 @@ Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const { return QAndroidPlatformIntegration::m_nativeOrientation; } + +QRect &QAndroidPlatformScreen::defaultAvailableGeometry() +{ + static QRect defaultAvailableGeometry; + return defaultAvailableGeometry; +} QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h index d850d0db095..93291be0e94 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.h +++ b/src/plugins/platforms/android/qandroidplatformscreen.h @@ -48,6 +48,8 @@ public: void topVisibleWindowChanged(); int displayId() const override; + static QRect &defaultAvailableGeometry(); + public slots: void setPhysicalSize(const QSize &size); void setAvailableGeometry(const QRect &rect); |