summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidplatformscreen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformscreen.cpp')
-rw-r--r--src/plugins/platforms/android/qandroidplatformscreen.cpp110
1 files changed, 89 insertions, 21 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp
index 12ce0d514e..b2ca70ce45 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp
@@ -1,13 +1,12 @@
/****************************************************************************
**
** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:COMM$
-**
+** $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
@@ -16,25 +15,26 @@
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
-** $QT_END_LICENSE$
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
+** $QT_END_LICENSE$
**
****************************************************************************/
@@ -55,6 +55,7 @@
#include <android/native_window_jni.h>
#include <qguiapplication.h>
+#include <QtCore/private/qjnihelpers_p.h>
#include <QtGui/QGuiApplication>
#include <QtGui/QWindow>
#include <QtGui/private/qwindow_p.h>
@@ -104,6 +105,42 @@ QAndroidPlatformScreen::QAndroidPlatformScreen()
m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight);
m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth);
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &QAndroidPlatformScreen::applicationStateChanged);
+
+ QJNIObjectPrivate activity(QtAndroid::activity());
+ if (!activity.isValid())
+ return;
+ QJNIObjectPrivate display;
+ if (QtAndroidPrivate::androidSdkVersion() < 30) {
+ display = activity.callObjectMethod("getWindowManager", "()Landroid/view/WindowManager;")
+ .callObjectMethod("getDefaultDisplay", "()Landroid/view/Display;");
+ } else {
+ display = activity.callObjectMethod("getDisplay", "()Landroid/view/Display;");
+ }
+ if (!display.isValid())
+ return;
+ m_name = display.callObjectMethod("getName", "()Ljava/lang/String;").toString();
+ m_refreshRate = display.callMethod<jfloat>("getRefreshRate");
+ if (QtAndroidPrivate::androidSdkVersion() < 23) {
+ m_modes << Mode { .size = m_physicalSize.toSize(), .refreshRate = m_refreshRate };
+ return;
+ }
+ QJNIEnvironmentPrivate env;
+ const jint currentMode = display.callObjectMethod("getMode", "()Landroid/view/Display$Mode;")
+ .callMethod<jint>("getModeId");
+ const auto modes = display.callObjectMethod("getSupportedModes",
+ "()[Landroid/view/Display$Mode;");
+ const auto modesArray = jobjectArray(modes.object());
+ const auto sz = env->GetArrayLength(modesArray);
+ for (jsize i = 0; i < sz; ++i) {
+ auto mode = QJNIObjectPrivate::fromLocalRef(env->GetObjectArrayElement(modesArray, i));
+ if (currentMode == mode.callMethod<jint>("getModeId"))
+ m_currentMode = m_modes.size();
+ m_modes << Mode { .size = QSize { mode.callMethod<jint>("getPhysicalHeight"),
+ mode.callMethod<jint>("getPhysicalWidth") },
+ .refreshRate = mode.callMethod<jfloat>("getRefreshRate") };
+ }
+ if (m_modes.isEmpty())
+ m_modes << Mode { .size = m_physicalSize.toSize(), .refreshRate = m_refreshRate };
}
QAndroidPlatformScreen::~QAndroidPlatformScreen()
@@ -243,6 +280,37 @@ void QAndroidPlatformScreen::setSize(const QSize &size)
QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(), availableGeometry());
}
+void QAndroidPlatformScreen::setSizeParameters(const QSize &physicalSize, const QSize &size,
+ const QRect &availableGeometry)
+{
+ // The goal of this method is to set all geometry-related parameters
+ // at the same time and generate only one screen geometry change event.
+ m_physicalSize = physicalSize;
+ m_size = size;
+ // If available geometry has changed, the event will be handled in
+ // setAvailableGeometry. Otherwise we need to explicitly handle it to
+ // retain the behavior, because setSize() does the handling unconditionally.
+ if (m_availableGeometry != availableGeometry) {
+ setAvailableGeometry(availableGeometry);
+ } else {
+ QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(),
+ this->availableGeometry());
+ }
+}
+
+void QAndroidPlatformScreen::setRefreshRate(qreal refreshRate)
+{
+ if (refreshRate == m_refreshRate)
+ return;
+ m_refreshRate = refreshRate;
+ QWindowSystemInterface::handleScreenRefreshRateChange(QPlatformScreen::screen(), refreshRate);
+}
+
+void QAndroidPlatformScreen::setOrientation(Qt::ScreenOrientation orientation)
+{
+ QWindowSystemInterface::handleScreenOrientationChange(QPlatformScreen::screen(), orientation);
+}
+
void QAndroidPlatformScreen::setAvailableGeometry(const QRect &rect)
{
QMutexLocker lock(&m_surfaceMutex);
@@ -429,7 +497,7 @@ static const int androidLogicalDpi = 72;
QDpi QAndroidPlatformScreen::logicalDpi() const
{
- qreal lDpi = QtAndroid::scaledDensity() * androidLogicalDpi;
+ qreal lDpi = QtAndroid::pixelDensity() * androidLogicalDpi;
return QDpi(lDpi, lDpi);
}