62QAndroidPlatformScreen::QAndroidPlatformScreen(
const QJniObject &displayObject)
63 : QObject(), QPlatformScreen()
67 if (qEnvironmentVariableIntValue(
"QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) {
68 m_format = QImage::Format_RGB16;
71 m_format = QImage::Format_ARGB32_Premultiplied;
75 connect(
qGuiApp, &QGuiApplication::applicationStateChanged,
this,
76 &QAndroidPlatformScreen::applicationStateChanged);
78 if (!displayObject.isValid())
81 m_name = displayObject.callObjectMethod<jstring>(
"getName").toString();
82 m_refreshRate = displayObject.callMethod<jfloat>(
"getRefreshRate");
83 m_displayId = displayObject.callMethod<jint>(
"getDisplayId");
84 m_size = sizeForDisplayId(m_displayId);
85 m_availableGeometry = defaultAvailableGeometry();
87 const auto context = QNativeInterface::QAndroidApplication::context();
88 const auto resources = context.callMethod<QtJniTypes::Resources>(
"getResources");
89 const auto metrics = resources.callMethod<QtJniTypes::DisplayMetrics>(
"getDisplayMetrics");
90 m_xdpi = QtJniTypes::QtDisplayManager::callStaticMethod<jfloat>(
"getXDpi", metrics);
91 m_ydpi = QtJniTypes::QtDisplayManager::callStaticMethod<jfloat>(
"getYDpi", metrics);
96 setPhysicalSizeFromPixels(m_size);
98 if (QNativeInterface::QAndroidApplication::sdkVersion() >= 23) {
99 const QJniObject currentMode = displayObject.callObjectMethod<QtJniTypes::DisplayMode>(
"getMode");
100 m_currentMode = currentMode.callMethod<jint>(
"getModeId");
102 const QJniObject supportedModes = displayObject.callObjectMethod<QtJniTypes::DisplayMode[]>(
103 "getSupportedModes");
104 const auto modeArray = jobjectArray(supportedModes.object());
107 const auto size = env->GetArrayLength(modeArray);
108 for (jsize i = 0; i < size; ++i) {
109 const auto mode = QJniObject::fromLocalRef(env->GetObjectArrayElement(modeArray, i));
110 m_modes << QPlatformScreen::Mode {
111 .size = QSize { mode.callMethod<jint>(
"getPhysicalWidth"),
112 mode.callMethod<jint>(
"getPhysicalHeight") },
113 .refreshRate = mode.callMethod<jfloat>(
"getRefreshRate")
257 if (m_availableGeometry == rect)
260 QRect oldGeometry = m_availableGeometry;
262 m_availableGeometry = rect;
263 m_size = sizeForDisplayId(m_displayId);
264 QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(), availableGeometry());
265 resizeMaximizedWindows();
267 if (oldGeometry.width() == 0 && oldGeometry.height() == 0 && rect.width() > 0 && rect.height() > 0) {
268 QList<QWindow *> windows = QGuiApplication::allWindows();
269 for (
int i = 0; i < windows.size(); ++i) {
270 QWindow *w = windows.at(i);
272 QRect geometry = w->handle()->geometry();
273 if (geometry.width() > 0 && geometry.height() > 0)
274 QWindowSystemInterface::handleExposeEvent(w, QRect(QPoint(0, 0), geometry.size()));