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