Esempio n. 1
0
static void setSurface(JNIEnv *env, jobject /*thiz*/, jobject jSurface)
{
#ifndef ANDROID_PLUGIN_OPENGL
    if (m_surface)
        env->DeleteGlobalRef(m_surface);
    m_surface = env->NewGlobalRef(jSurface);
#else
    m_surfaceMutex.lock();
    EGLNativeWindowType nativeWindow = ANativeWindow_fromSurface(env, jSurface);
    bool sameNativeWindow = (nativeWindow != 0 && nativeWindow == m_nativeWindow);

    m_nativeWindow = nativeWindow;
    if (m_waitForWindow)
        m_waitForWindowSemaphore.release();

    if (m_androidPlatformIntegration) {
        // Use the desktop size.
        // On some devices, the getters for the native window size gives wrong values
        QSize size = QAndroidPlatformIntegration::defaultDesktopSize();

        QPlatformScreen *screen = m_androidPlatformIntegration->screen();
        QRect geometry(QPoint(0, 0), size);
        if (screen) {
            QWindowSystemInterface::handleScreenAvailableGeometryChange(screen->screen(), geometry);
            QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), geometry);
        }

        if (!sameNativeWindow) {
            m_surfaceMutex.unlock();
            m_androidPlatformIntegration->surfaceChanged();
        } else {
            // Resize all top level windows, since they share the same surface
            foreach (QWindow *w, QGuiApplication::topLevelWindows()) {
                QAndroidOpenGLPlatformWindow *window =
                        static_cast<QAndroidOpenGLPlatformWindow *>(w->handle());

                if (window != 0) {
                    window->lock();
                    window->scheduleResize(size);

                    QWindowSystemInterface::handleExposeEvent(window->window(),
                                                              QRegion(window->window()->geometry()));
                    window->unlock();
                }
            }

            m_surfaceMutex.unlock();
        }

    } else {
Esempio n. 2
0
int QWidget::metric(PaintDeviceMetric m) const
{
    Q_D(const QWidget);

    QScreen *screen = 0;
    if (QWidget *topLevel = window())
        if (QWindow *topLevelWindow = topLevel->windowHandle()) {
            QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
            if (platformScreen)
                screen = platformScreen->screen();
        }
    if (!screen && QGuiApplication::primaryScreen())
        screen = QGuiApplication::primaryScreen();

    if (!screen) {
        if (m == PdmDpiX || m == PdmDpiY)
              return 72;
        return QPaintDevice::metric(m);
    }
    int val;
    if (m == PdmWidth) {
        val = data->crect.width();
    } else if (m == PdmWidthMM) {
        val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
    } else if (m == PdmHeight) {
        val = data->crect.height();
    } else if (m == PdmHeightMM) {
        val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
    } else if (m == PdmDepth) {
        return screen->depth();
    } else if (m == PdmDpiX) {
        if (d->extra && d->extra->customDpiX)
            return d->extra->customDpiX;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        return qRound(screen->logicalDotsPerInchX());
    } else if (m == PdmDpiY) {
        if (d->extra && d->extra->customDpiY)
            return d->extra->customDpiY;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        return qRound(screen->logicalDotsPerInchY());
    } else if (m == PdmPhysicalDpiX) {
        return qRound(screen->physicalDotsPerInchX());
    } else if (m == PdmPhysicalDpiY) {
        return qRound(screen->physicalDotsPerInchY());
    } else if (m == PdmDevicePixelRatio) {
        return screen->devicePixelRatio();
    } else {
        val = QPaintDevice::metric(m);// XXX
    }
    return val;
}
QPlatformWindow *QWindowsIntegration::createPlatformWindow(QWindow *window) const
{
    QWindowsWindowData requested;
    requested.flags = window->flags();
    requested.geometry = QHighDpi::toNativePixels(window->geometry(), window);
    // Apply custom margins (see  QWindowsWindow::setCustomMargins())).
    const QVariant customMarginsV = window->property("_q_windowsCustomMargins");
    if (customMarginsV.isValid())
        requested.customMargins = qvariant_cast<QMargins>(customMarginsV);

    QWindowsWindowData obtained = QWindowsWindowData::create(window, requested, window->title());
    qCDebug(lcQpaWindows).nospace()
        << __FUNCTION__ << ' ' << window
        << "\n    Requested: " << requested.geometry << " frame incl.="
        << QWindowsGeometryHint::positionIncludesFrame(window)
        << ' ' << requested.flags
        << "\n    Obtained : " << obtained.geometry << " margins=" << obtained.frame
        << " handle=" << obtained.hwnd << ' ' << obtained.flags << '\n';

    if (Q_UNLIKELY(!obtained.hwnd))
        return Q_NULLPTR;

    QWindowsWindow *result = createPlatformWindowHelper(window, obtained);
    Q_ASSERT(result);

    if (requested.flags != obtained.flags)
        window->setFlags(obtained.flags);
    // Trigger geometry change (unless it has a special state in which case setWindowState()
    // will send the message) and screen change signals of QWindow.
    if ((obtained.flags & Qt::Desktop) != Qt::Desktop) {
        const Qt::WindowState state = window->windowState();
        if (state != Qt::WindowMaximized && state != Qt::WindowFullScreen
            && requested.geometry != obtained.geometry) {
            QWindowSystemInterface::handleGeometryChange(window, obtained.geometry);
        }
        QPlatformScreen *screen = result->screenForGeometry(obtained.geometry);
        if (screen && result->screen() != screen)
            QWindowSystemInterface::handleWindowScreenChanged(window, screen->screen());
    }

    return result;
}