8#include <qpa/qwindowsysteminterface.h>
17#include <android/bitmap.h>
18#include <android/native_window_jni.h>
21#include <QtCore/QJniObject>
22#include <QtCore/QJniEnvironment>
23#include <QtGui/QGuiApplication>
24#include <QtGui/QWindow>
25#include <QtGui/private/qwindow_p.h>
30#ifdef QANDROIDPLATFORMSCREEN_DEBUG
34 ScopedProfiler(
const QString &msg)
41 qDebug() << m_msg << m_timer.elapsed();
49# define PROFILE_SCOPE ScopedProfiler ___sp___(__func__)
66 m_availableGeometry = QAndroidPlatformIntegration::m_defaultAvailableGeometry;
67 m_size = QAndroidPlatformIntegration::m_defaultScreenSize;
68 m_physicalSize = QAndroidPlatformIntegration::m_defaultPhysicalSize;
81 &QAndroidPlatformScreen::applicationStateChanged);
83 if (!displayObject.isValid())
86 m_name = displayObject.callObjectMethod<jstring>(
"getName").
toString();
87 m_refreshRate = displayObject.callMethod<jfloat>(
"getRefreshRate");
88 m_displayId = displayObject.callMethod<jint>(
"getDisplayId");
91 const auto displayContext =
context.callMethod<QtJniTypes::Context>(
"createDisplayContext",
92 displayObject.object<QtJniTypes::Display>());
94 const auto sizeObj = QtJniTypes::QtDisplayManager::callStaticMethod<QtJniTypes::Size>(
95 "getDisplaySize", displayContext,
96 displayObject.object<QtJniTypes::Display>());
97 m_size =
QSize(sizeObj.callMethod<
int>(
"getWidth"), sizeObj.callMethod<
int>(
"getHeight"));
99 const auto resources = displayContext.callMethod<QtJniTypes::Resources>(
"getResources");
100 const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>(
"getDisplayMetrics");
101 const float xdpi =
metrics.getField<
float>(
"xdpi");
102 const float ydpi =
metrics.getField<
float>(
"ydpi");
107 m_physicalSize.setWidth(
qRound(m_size.width() / xdpi * 25.4));
108 m_physicalSize.setHeight(
qRound(m_size.height() / ydpi * 25.4));
110 if (QNativeInterface::QAndroidApplication::sdkVersion() >= 23) {
111 const QJniObject currentMode = displayObject.callObjectMethod<QtJniTypes::DisplayMode>(
"getMode");
112 m_currentMode = currentMode.callMethod<jint>(
"getModeId");
114 const QJniObject supportedModes = displayObject.callObjectMethod<QtJniTypes::DisplayMode[]>(
115 "getSupportedModes");
116 const auto modeArray = jobjectArray(supportedModes.object());
119 const auto size = env->GetArrayLength(modeArray);
120 for (jsize
i = 0;
i <
size; ++
i) {
121 const auto mode = QJniObject::fromLocalRef(env->GetObjectArrayElement(modeArray,
i));
124 mode.callMethod<jint>(
"getPhysicalHeight") },
125 .refreshRate =
mode.callMethod<jfloat>(
"getRefreshRate")
139 if (
w->window()->isVisible() &&
150 if (
w->geometry().contains(
p,
false) &&
w->window()->isVisible())
167 if (
window->window()->isVisible())
176 qWarning() <<
"Failed to remove window";
218 const QRect &availableGeometry)
264 if (oldGeometry.
width() == 0 && oldGeometry.
height() == 0 &&
rect.width() > 0 &&
rect.height() > 0) {
280 w->applicationStateChanged(
state);
288 if (
w &&
w->handle()) {
300 return QDpi(lDpi, lDpi);
310 return QAndroidPlatformIntegration::m_orientation;
315 return QAndroidPlatformIntegration::m_nativeOrientation;
static QWindowList allWindows()
Returns a list of all the windows in the application.
void applicationStateChanged(Qt::ApplicationState state)
@ Format_ARGB32_Premultiplied
qsizetype size() const noexcept
bool removeOne(const AT &t)
const_reference at(qsizetype i) const noexcept
void move(qsizetype from, qsizetype to)
void prepend(rvalue_ref t)
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtCore \reentrant
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry, const QRect &newAvailableGeometry)
static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r=Qt::OtherFocusReason)
static bool handleExposeEvent(QWindow *window, const QRegion ®ion)
static void handleScreenOrientationChange(QScreen *screen, Qt::ScreenOrientation newOrientation)
static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
Combined button and popup list for selecting options.
void setActiveTopLevelWindow(QWindow *window)
QtJniTypes::QtActivityDelegateBase qtActivityDelegate()
@ ActiveWindowFocusReason
int qRound(qfloat16 d) noexcept
QPair< qreal, qreal > QDpi
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
QT_BEGIN_NAMESPACE Q_DECLARE_JNI_CLASS(Environment, "android/os/Environment")
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
char * toString(const MyType &t)
[31]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept