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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
Assam Boudjelthia 2025-01-06 18:02:18 +02:00
parent 6f79d46e80
commit 65c41c6be6
5 changed files with 17 additions and 37 deletions

View File

@ -20,6 +20,7 @@
#include "qandroidplatformdialoghelpers.h" #include "qandroidplatformdialoghelpers.h"
#include "qandroidplatformintegration.h" #include "qandroidplatformintegration.h"
#include "qandroidplatformclipboard.h" #include "qandroidplatformclipboard.h"
#include "qandroidplatformscreen.h"
#include "qandroidplatformwindow.h" #include "qandroidplatformwindow.h"
#include <android/api-level.h> #include <android/api-level.h>
@ -71,7 +72,6 @@ static void *m_mainLibraryHnd = nullptr;
static QList<QByteArray> m_applicationParams; static QList<QByteArray> m_applicationParams;
static sem_t m_exitSemaphore, m_terminateSemaphore; static sem_t m_exitSemaphore, m_terminateSemaphore;
static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr; static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr;
static int m_availableWidthPixels = 0; static int m_availableWidthPixels = 0;
@ -580,14 +580,11 @@ static void setDisplayMetrics(JNIEnv * /*env*/, jclass /*clazz*/,
qRound(double(screenHeightPixels) / ydpi * 25.4)); qRound(double(screenHeightPixels) / ydpi * 25.4));
QMutexLocker lock(&m_platformMutex); QMutexLocker lock(&m_platformMutex);
if (!m_androidPlatformIntegration) { if (m_androidPlatformIntegration) {
QAndroidPlatformIntegration::setDefaultDisplayMetrics( m_androidPlatformIntegration->setScreenSizeParameters(
availableGeometry.left(), availableGeometry.top(), availableGeometry.width(), physicalSize, screenSize, availableGeometry);
availableGeometry.height(), physicalSize.width(), physicalSize.height(), } else if (QAndroidPlatformScreen::defaultAvailableGeometry().isNull()) {
screenSize.width(), screenSize.height()); QAndroidPlatformScreen::defaultAvailableGeometry() = availableGeometry;
} else {
m_androidPlatformIntegration->setScreenSizeParameters(physicalSize, screenSize,
availableGeometry);
} }
} }
Q_DECLARE_JNI_NATIVE_METHOD(setDisplayMetrics) Q_DECLARE_JNI_NATIVE_METHOD(setDisplayMetrics)

View File

@ -46,10 +46,6 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals; 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_orientation = Qt::PrimaryOrientation;
Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation; Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation;
@ -494,17 +490,6 @@ QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &
return 0; 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, void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation,
Qt::ScreenOrientation nativeOrientation) Qt::ScreenOrientation nativeOrientation)
{ {
@ -515,8 +500,8 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur
void QAndroidPlatformIntegration::flushPendingUpdates() void QAndroidPlatformIntegration::flushPendingUpdates()
{ {
if (m_primaryScreen) { if (m_primaryScreen) {
m_primaryScreen->setSizeParameters(m_defaultPhysicalSize, m_defaultScreenSize, m_primaryScreen->setSizeParameters(m_primaryScreen->physicalSize().toSize(),
m_defaultAvailableGeometry); m_primaryScreen->geometry().size(), m_primaryScreen->availableGeometry());
} }
} }

View File

@ -99,9 +99,6 @@ public:
QStringList themeNames() const override; QStringList themeNames() const override;
QPlatformTheme *createPlatformTheme(const QString &name) 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, static void setScreenOrientation(Qt::ScreenOrientation currentOrientation,
Qt::ScreenOrientation nativeOrientation); Qt::ScreenOrientation nativeOrientation);
@ -126,10 +123,6 @@ private:
static Qt::ColorScheme m_colorScheme; 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_orientation;
static Qt::ScreenOrientation m_nativeOrientation; static Qt::ScreenOrientation m_nativeOrientation;
static bool m_showPasswordEnabled; static bool m_showPasswordEnabled;

View File

@ -63,10 +63,6 @@ Q_DECLARE_JNI_CLASS(DisplayMode, "android/view/Display$Mode")
QAndroidPlatformScreen::QAndroidPlatformScreen(const QJniObject &displayObject) QAndroidPlatformScreen::QAndroidPlatformScreen(const QJniObject &displayObject)
: QObject(), QPlatformScreen() : 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 // Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16
// is way much faster than 32 // is way much faster than 32
if (qEnvironmentVariableIntValue("QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) { if (qEnvironmentVariableIntValue("QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) {
@ -92,6 +88,7 @@ QAndroidPlatformScreen::QAndroidPlatformScreen(const QJniObject &displayObject)
"getDisplaySize", context, "getDisplaySize", context,
displayObject.object<QtJniTypes::Display>()); displayObject.object<QtJniTypes::Display>());
m_size = QSize(sizeObj.callMethod<int>("getWidth"), sizeObj.callMethod<int>("getHeight")); m_size = QSize(sizeObj.callMethod<int>("getWidth"), sizeObj.callMethod<int>("getHeight"));
m_availableGeometry = defaultAvailableGeometry();
const auto resources = context.callMethod<QtJniTypes::Resources>("getResources"); const auto resources = context.callMethod<QtJniTypes::Resources>("getResources");
const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>("getDisplayMetrics"); const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>("getDisplayMetrics");
@ -324,4 +321,10 @@ Qt::ScreenOrientation QAndroidPlatformScreen::nativeOrientation() const
{ {
return QAndroidPlatformIntegration::m_nativeOrientation; return QAndroidPlatformIntegration::m_nativeOrientation;
} }
QRect &QAndroidPlatformScreen::defaultAvailableGeometry()
{
static QRect defaultAvailableGeometry;
return defaultAvailableGeometry;
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -48,6 +48,8 @@ public:
void topVisibleWindowChanged(); void topVisibleWindowChanged();
int displayId() const override; int displayId() const override;
static QRect &defaultAvailableGeometry();
public slots: public slots:
void setPhysicalSize(const QSize &size); void setPhysicalSize(const QSize &size);
void setAvailableGeometry(const QRect &rect); void setAvailableGeometry(const QRect &rect);