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__)
67 m_availableGeometry = QAndroidPlatformIntegration::m_defaultAvailableGeometry;
68 m_size = QAndroidPlatformIntegration::m_defaultScreenSize;
69 m_physicalSize = QAndroidPlatformIntegration::m_defaultPhysicalSize;
82 &QAndroidPlatformScreen::applicationStateChanged);
84 if (!displayObject.isValid())
87 m_name = displayObject.callObjectMethod<jstring>(
"getName").
toString();
88 m_refreshRate = displayObject.callMethod<jfloat>(
"getRefreshRate");
89 m_displayId = displayObject.callMethod<jint>(
"getDisplayId");
92 const auto displayContext =
context.callMethod<QtJniTypes::Context>(
"createDisplayContext",
93 displayObject.object<QtJniTypes::Display>());
95 const auto sizeObj = QtJniTypes::QtDisplayManager::callStaticMethod<QtJniTypes::Size>(
96 "getDisplaySize", displayContext,
97 displayObject.object<QtJniTypes::Display>());
98 m_size =
QSize(sizeObj.callMethod<
int>(
"getWidth"), sizeObj.callMethod<
int>(
"getHeight"));
100 const auto resources = displayContext.callMethod<QtJniTypes::Resources>(
"getResources");
101 const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>(
"getDisplayMetrics");
102 const float xdpi =
metrics.getField<
float>(
"xdpi");
103 const float ydpi =
metrics.getField<
float>(
"ydpi");
108 m_physicalSize.setWidth(
qRound(m_size.width() / xdpi * 25.4));
109 m_physicalSize.setHeight(
qRound(m_size.height() / ydpi * 25.4));
111 if (QNativeInterface::QAndroidApplication::sdkVersion() >= 23) {
112 const QJniObject currentMode = displayObject.callObjectMethod<QtJniTypes::DisplayMode>(
"getMode");
113 m_currentMode = currentMode.callMethod<jint>(
"getModeId");
115 const QJniObject supportedModes = displayObject.callObjectMethod<QtJniTypes::DisplayMode[]>(
116 "getSupportedModes");
117 const auto modeArray = jobjectArray(supportedModes.object());
120 const auto size = env->GetArrayLength(modeArray);
121 for (jsize
i = 0;
i <
size; ++
i) {
122 const auto mode = QJniObject::fromLocalRef(env->GetObjectArrayElement(modeArray,
i));
125 mode.callMethod<jint>(
"getPhysicalHeight") },
126 .refreshRate =
mode.callMethod<jfloat>(
"getRefreshRate")
140 if (
w->window()->isVisible() &&
151 if (
w->geometry().contains(
p,
false) &&
w->window()->isVisible())
168 reg->callInterface<QtJniTypes::QtWindowInterface,
void>(
"addTopLevelWindow",
171 if (
window->window()->isVisible())
180 qWarning() <<
"Failed to remove window";
183 reg->callInterface<QtJniTypes::QtWindowInterface,
void>(
"removeTopLevelWindow",
198 reg->callInterface<QtJniTypes::QtWindowInterface,
void>(
"bringChildToFront",
212 reg->callInterface<QtJniTypes::QtWindowInterface,
void>(
"bringChildToBack",
230 const QRect &availableGeometry)
276 if (oldGeometry.
width() == 0 && oldGeometry.
height() == 0 &&
rect.width() > 0 &&
rect.height() > 0) {
292 w->applicationStateChanged(
state);
300 if (
w &&
w->handle()) {
312 return QDpi(lDpi, lDpi);
322 return QAndroidPlatformIntegration::m_orientation;
327 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)
AndroidBackendRegister * backendRegister()
@ 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