static QSurface *createSurface(int surfaceClass) { if (surfaceClass == int(QSurface::Window)) { QWindow *window = new QWindow; window->setSurfaceType(QWindow::OpenGLSurface); window->setGeometry(0, 0, 10, 10); window->create(); return window; } else if (surfaceClass == int(QSurface::Offscreen)) { // Create a window and get the format from that. For example, if an EGL // implementation provides 565 and 888 configs for PBUFFER_BIT but only // 888 for WINDOW_BIT, we may end up with a pbuffer surface that is // incompatible with the context since it could choose the 565 while the // window and the context uses a config with 888. static QSurfaceFormat format; if (format.redBufferSize() == -1) { QWindow *window = new QWindow; window->setSurfaceType(QWindow::OpenGLSurface); window->setGeometry(0, 0, 10, 10); window->create(); format = window->format(); delete window; } QOffscreenSurface *offscreenSurface = new QOffscreenSurface; offscreenSurface->setFormat(format); offscreenSurface->create(); return offscreenSurface; } return 0; }
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() { QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); window.setGeometry(0, 0, 10, 10); window.create(); QOpenGLFramebufferObject *fbo = 0; { QOpenGLContext ctx; ctx.create(); ctx.makeCurrent(&window); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); fbo = new QOpenGLFramebufferObject(128, 128); QVERIFY(fbo->handle() != 0); } QCOMPARE(fbo->handle(), 0U); }
void QWidgetPrivate::show_sys() { Q_Q(QWidget); QWindow *window = q->windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { invalidateBuffer(q->rect()); q->setAttribute(Qt::WA_Mapped); if (q->isWindow() && q->windowModality() != Qt::NonModal && window) { // add our window to the modal window list QGuiApplicationPrivate::showModalWindow(window); } return; } QApplication::postEvent(q, new QUpdateLaterEvent(q->rect())); if (!q->isWindow() && !q->testAttribute(Qt::WA_NativeWindow)) return; if (window) { if (q->isWindow()) fixPosIncludesFrame(); QRect geomRect = q->geometry(); if (!q->isWindow()) { QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint()); geomRect.moveTopLeft(topLeftOfWindow); } const QRect windowRect = window->geometry(); if (windowRect != geomRect) { if (q->testAttribute(Qt::WA_Moved)) window->setGeometry(geomRect); else window->resize(geomRect.size()); } if (QBackingStore *store = q->backingStore()) { if (store->size() != geomRect.size()) { store->resize(geomRect.size()); } } #ifndef QT_NO_CURSOR qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show #endif invalidateBuffer(q->rect()); window->setVisible(true); // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ? if (window->isTopLevel()) { const QPoint crectTopLeft = q->data->crect.topLeft(); const QPoint windowTopLeft = window->geometry().topLeft(); if (crectTopLeft == QPoint(0, 0) && windowTopLeft != crectTopLeft) q->data->crect.moveTopLeft(windowTopLeft); } } }
void MythRenderOpenGL::MoveResizeWindow(const QRect &rect) { #ifdef USE_OPENGL_QT5 QWindow *parent = m_window; #else QWidget *parent = dynamic_cast<QWidget* >(this->device()); #endif if (parent) parent->setGeometry(rect); }
bool MouseEventFilter::eventFilter(QObject *obj, QEvent *event) { if(event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if(mouseEvent) { ApplicationManager::singleton()->setMouseX(mouseEvent->pos().x()); ApplicationManager::singleton()->setMouseY(mouseEvent->pos().y()); if(mouseEvent->buttons() && Qt::LeftButton && ApplicationManager::singleton()->grabbingWindowMoveHandle() && ApplicationManager::singleton()->windowControlButtonsEnabled()) { QPoint diffPosition = mouseEvent->pos() - mousePos.toPoint(); QPoint newPosition = ApplicationManager::singleton()->window()->position() + diffPosition; int oldWindowWidth = ApplicationManager::singleton()->window()->width(); if(ApplicationManager::singleton()->showNormal()) { int windowWidth = ApplicationManager::singleton()->window()->width(); ApplicationManager::singleton()->window()->setPosition(newPosition.x() + (oldWindowWidth - windowWidth) * (mousePos.x() / oldWindowWidth), newPosition.y()); mousePos.setX(mousePos.x() - (oldWindowWidth - windowWidth) * (mousePos.x() / oldWindowWidth)); } else { ApplicationManager::singleton()->window()->setPosition(newPosition); } } else if(mouseEvent->buttons() && Qt::LeftButton && ApplicationManager::singleton()->grabbingWindowResizeHandle() && ApplicationManager::singleton()->windowControlButtonsEnabled()) { QPoint diffPosition = mouseEvent->pos() - mousePos.toPoint(); mousePos = mouseEvent->pos(); QWindow *window = ApplicationManager::singleton()->window(); int newWidth = window->width() + diffPosition.x(); int newHeight = window->height() + diffPosition.y(); if(newWidth < 1024) newWidth = 1024; if(newHeight < 600) newHeight = 600; window->setGeometry(window->position().x(), window->position().y(), newWidth, newHeight); } } } else if(event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if(mouseEvent) { mousePos = mouseEvent->pos(); } } return QObject::eventFilter(obj, event); }
/*! Convenience method to resize all the maximized and fullscreen windows of this platform screen. */ void QPlatformScreen::resizeMaximizedWindows() { QList<QWindow*> windows = QGuiApplication::allWindows(); // 'screen()' still has the old geometry info while 'this' has the new geometry info const QRect oldGeometry = screen()->geometry(); const QRect oldAvailableGeometry = screen()->availableGeometry(); const QRect newGeometry = geometry(); const QRect newAvailableGeometry = availableGeometry(); // make sure maximized and fullscreen windows are updated for (int i = 0; i < windows.size(); ++i) { QWindow *w = windows.at(i); if (platformScreenForWindow(w) != this) continue; if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry) w->setGeometry(newAvailableGeometry); else if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry) w->setGeometry(newGeometry); } }
static QSurface *createSurface(int surfaceClass) { if (surfaceClass == int(QSurface::Window)) { QWindow *window = new QWindow; window->setSurfaceType(QWindow::OpenGLSurface); window->setGeometry(0, 0, 10, 10); window->create(); return window; } else if (surfaceClass == int(QSurface::Offscreen)) { QOffscreenSurface *offscreenSurface = new QOffscreenSurface; offscreenSurface->create(); return offscreenSurface; } return 0; }
void tst_QWindowContainer::testPositionAndSize() { QWindow *window = new QWindow(); window->setGeometry(300, 400, 500, 600); QWidget *container = QWidget::createWindowContainer(window); container->setGeometry(50, 50, 200, 200); container->show(); QVERIFY(QTest::qWaitForWindowExposed(container)); QCOMPARE(window->x(), 0); QCOMPARE(window->y(), 0); QCOMPARE(window->width(), container->width()); QCOMPARE(window->height(), container->height()); }
void tst_QOpenGL::aboutToBeDestroyed() { QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); window.setGeometry(0, 0, 128, 128); window.create(); QOpenGLContext *context = new QOpenGLContext; QSignalSpy spy(context, SIGNAL(aboutToBeDestroyed())); context->create(); context->makeCurrent(&window); QCOMPARE(spy.size(), 0); delete context; QCOMPARE(spy.size(), 1); }
void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero() { #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__) QSKIP("QTBUG-22617"); #endif QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); window.setGeometry(0, 0, 128, 128); window.create(); QOpenGLContext ctx; ctx.create(); ctx.makeCurrent(&window); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); QOpenGLFramebufferObject fbo(128, 128); fbo.bind(); QOpenGLPaintDevice device(128, 128); // QTBUG-15621 is only a problem when qreal is double, but do the test anyway. qreal delta = sizeof(qreal) == sizeof(float) ? 1e-4 : 1e-8; QVERIFY(128 != 128 + delta); QPainterPath path; path.moveTo(16 + delta, 16); path.moveTo(16, 16); path.lineTo(16 + delta, 16); // Short lines to check for division by zero. path.lineTo(112 - delta, 16); path.lineTo(112, 16); path.quadTo(112, 16, 112, 16 + delta); path.quadTo(112, 64, 112, 112 - delta); path.quadTo(112, 112, 112, 112); path.cubicTo(112, 112, 112, 112, 112 - delta, 112); path.cubicTo(80, 112, 48, 112, 16 + delta, 112); path.cubicTo(16 + delta, 112, 16 + delta, 112, 16, 112); path.closeSubpath(); QPen pen(Qt::red, 28, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); QPainter p(&device); p.fillRect(QRect(0, 0, 128, 128), Qt::blue); p.strokePath(path, pen); p.end(); QImage image = fbo.toImage().convertToFormat(QImage::Format_RGB32); const QRgb red = 0xffff0000; const QRgb blue = 0xff0000ff; QCOMPARE(image.pixel(8, 8), red); QCOMPARE(image.pixel(119, 8), red); QCOMPARE(image.pixel(8, 119), red); QCOMPARE(image.pixel(119, 119), red); QCOMPARE(image.pixel(0, 0), blue); QCOMPARE(image.pixel(127, 0), blue); QCOMPARE(image.pixel(0, 127), blue); QCOMPARE(image.pixel(127, 127), blue); QCOMPARE(image.pixel(32, 32), blue); QCOMPARE(image.pixel(95, 32), blue); QCOMPARE(image.pixel(32, 95), blue); QCOMPARE(image.pixel(95, 95), blue); }
void tst_QQuickView::resizemodeitem() { QWindow window; window.setGeometry(0, 0, 400, 400); QQuickView *view = new QQuickView(&window); QVERIFY(view); view->setResizeMode(QQuickView::SizeRootObjectToView); QCOMPARE(QSize(0,0), view->initialSize()); view->setSource(testFileUrl("resizemodeitem.qml")); QQuickItem* item = qobject_cast<QQuickItem*>(view->rootObject()); QVERIFY(item); window.show(); view->show(); // initial size from root object QCOMPARE(item->width(), 200.0); QCOMPARE(item->height(), 200.0); QCOMPARE(view->size(), QSize(200, 200)); QCOMPARE(view->size(), view->sizeHint()); QCOMPARE(view->size(), view->initialSize()); // size update from view view->resize(QSize(80,100)); QTRY_COMPARE(item->width(), 80.0); QCOMPARE(item->height(), 100.0); QCOMPARE(view->size(), QSize(80, 100)); QCOMPARE(view->size(), view->sizeHint()); view->setResizeMode(QQuickView::SizeViewToRootObject); // size update from view disabled view->resize(QSize(60,80)); QCOMPARE(item->width(), 80.0); QCOMPARE(item->height(), 100.0); QTest::qWait(50); QCOMPARE(view->size(), QSize(60, 80)); // size update from root object item->setWidth(250); item->setHeight(350); QCOMPARE(item->width(), 250.0); QCOMPARE(item->height(), 350.0); QTRY_COMPARE(view->size(), QSize(250, 350)); QCOMPARE(view->size(), QSize(250, 350)); QCOMPARE(view->size(), view->sizeHint()); // reset window window.hide(); delete view; view = new QQuickView(&window); QVERIFY(view); view->setResizeMode(QQuickView::SizeViewToRootObject); view->setSource(testFileUrl("resizemodeitem.qml")); item = qobject_cast<QQuickItem*>(view->rootObject()); QVERIFY(item); window.show(); view->show(); // initial size for root object QCOMPARE(item->width(), 200.0); QCOMPARE(item->height(), 200.0); QCOMPARE(view->size(), view->sizeHint()); QCOMPARE(view->size(), view->initialSize()); // size update from root object item->setWidth(80); item->setHeight(100); QCOMPARE(item->width(), 80.0); QCOMPARE(item->height(), 100.0); QTRY_COMPARE(view->size(), QSize(80, 100)); QCOMPARE(view->size(), QSize(80, 100)); QCOMPARE(view->size(), view->sizeHint()); // size update from root object disabled view->setResizeMode(QQuickView::SizeRootObjectToView); item->setWidth(60); item->setHeight(80); QCOMPARE(view->width(), 80); QCOMPARE(view->height(), 100); QCOMPARE(QSize(item->width(), item->height()), view->sizeHint()); // size update from view view->resize(QSize(200,300)); QTest::qWait(50); QCOMPARE(item->width(), 200.0); QCOMPARE(item->height(), 300.0); QCOMPARE(view->size(), QSize(200, 300)); QCOMPARE(view->size(), view->sizeHint()); window.hide(); delete view; // if we set a specific size for the view then it should keep that size // for SizeRootObjectToView mode. view = new QQuickView(&window); view->resize(300, 300); view->setResizeMode(QQuickView::SizeRootObjectToView); QCOMPARE(QSize(0,0), view->initialSize()); view->setSource(testFileUrl("resizemodeitem.qml")); view->resize(300, 300); item = qobject_cast<QQuickItem*>(view->rootObject()); QVERIFY(item); window.show(); view->show(); QTest::qWait(50); // initial size from root object QCOMPARE(item->width(), 300.0); QCOMPARE(item->height(), 300.0); QCOMPARE(view->size(), QSize(300, 300)); QCOMPARE(view->size(), view->sizeHint()); QCOMPARE(view->initialSize(), QSize(200, 200)); // initial object size delete view; }
bool OculusWin32DisplayPlugin::start() { { ovrInitParams initParams; memset(&initParams, 0, sizeof(initParams)); #ifdef DEBUG initParams.Flags |= ovrInit_Debug; #endif ovrResult result = ovr_Initialize(&initParams); Q_ASSERT(OVR_SUCCESS(result)); result = ovr_Create(&_hmd, &_luid); _hmdDesc = ovr_GetHmdDesc(_hmd); for_each_eye([&](ovrEyeType eye) { _eyeFovs[eye] = _hmdDesc.DefaultEyeFov[eye]; _eyeProjections[eye] = toGlm(ovrMatrix4f_Projection(_eyeFovs[eye], 0.01f, 100.0f, ovrProjection_RightHanded)); ovrEyeRenderDesc erd = ovr_GetRenderDesc(_hmd, eye, _eyeFovs[eye]); _eyeOffsets[eye] = erd.HmdToEyeViewOffset; }); _eyeTextureSize = ovr_GetFovTextureSize(_hmd, ovrEye_Left, _eyeFovs[ovrEye_Left], 1.0f); _renderTargetSize = { _eyeTextureSize.w * 2, _eyeTextureSize.h }; ovr_ConfigureTracking(_hmd, ovrTrackingCap_Orientation | ovrTrackingCap_Position | ovrTrackingCap_MagYawCorrection, ovrTrackingCap_Orientation); } Q_ASSERT(!_window); Q_ASSERT(_shareContext); _window = new QWindow; _window->setSurfaceType(QSurface::OpenGLSurface); _window->setFormat(getDesiredSurfaceFormat()); _context = new QOpenGLContext; _context->setFormat(getDesiredSurfaceFormat()); _context->setShareContext(_shareContext); _context->create(); _window->show(); _window->setGeometry(QRect(100, -800, 1280, 720)); bool result = _context->makeCurrent(_window); #if defined(Q_OS_WIN) if (wglewGetExtension("WGL_EXT_swap_control")) { wglSwapIntervalEXT(0); int swapInterval = wglGetSwapIntervalEXT(); qDebug("V-Sync is %s\n", (swapInterval > 0 ? "ON" : "OFF")); } #elif defined(Q_OS_LINUX) #else qCDebug(interfaceapp, "V-Sync is FORCED ON on this system\n"); #endif Q_ASSERT(result); { // The geometry and shader for rendering the 2D UI surface when needed _program = oria::loadProgram( Resource::SHADERS_TEXTURED_VS, Resource::SHADERS_TEXTURED_FS); _quad = oria::loadPlane(_program, 1.0f); glClearColor(0, 1, 1, 1); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); _mirrorFbo = new MirrorFramebufferWrapper(_hmd); _sceneSwapFbo = new SwapFramebufferWrapper(_hmd); _sceneSwapFbo->Init(toGlm(_renderTargetSize)); _uiSwapFbo = new SwapFramebufferWrapper(_hmd); _uiSwapFbo->Init(_uiSize); _mirrorFbo->Init(uvec2(100, 100)); _context->doneCurrent(); } _sceneLayer.ColorTexture[0] = _sceneSwapFbo->color; _sceneLayer.ColorTexture[1] = nullptr; _sceneLayer.Viewport[0].Pos = { 0, 0 }; _sceneLayer.Viewport[0].Size = _eyeTextureSize; _sceneLayer.Viewport[1].Pos = { _eyeTextureSize.w, 0 }; _sceneLayer.Viewport[1].Size = _eyeTextureSize; _sceneLayer.Header.Type = ovrLayerType_EyeFov; _sceneLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft; for_each_eye([&](ovrEyeType eye) { _eyeViewports[eye] = _sceneLayer.Viewport[eye]; _sceneLayer.Fov[eye] = _eyeFovs[eye]; }); _uiLayer.ColorTexture = _uiSwapFbo->color; _uiLayer.Header.Type = ovrLayerType_QuadInWorld; _uiLayer.Header.Flags = ovrLayerFlag_TextureOriginAtBottomLeft; _uiLayer.QuadPoseCenter.Orientation = { 0, 0, 0, 1 }; _uiLayer.QuadPoseCenter.Position = { 0, 0, -1 }; _uiLayer.QuadSize = { aspect(_uiSize), 1.0f }; _uiLayer.Viewport = { { 0, 0 }, { (int)_uiSize.x, (int)_uiSize.y } }; _timer.start(0); connect(_window, &QWindow::widthChanged, this, &OculusWin32DisplayPlugin::resizedMirror); connect(_window, &QWindow::heightChanged, this, &OculusWin32DisplayPlugin::resizedMirror); resizedMirror(); return true; }
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) { Q_Q(QWidget); Q_UNUSED(window); Q_UNUSED(initializeWindow); Q_UNUSED(destroyOldWindow); Qt::WindowFlags flags = data.window_flags; if (!q->testAttribute(Qt::WA_NativeWindow) && !q->isWindow()) return; // we only care about real toplevels QWindow *win = topData()->window; // topData() ensures the extra is created but does not ensure 'window' is non-null // in case the extra was already valid. if (!win) { createTLSysExtra(); win = topData()->window; } win->setFlags(data.window_flags); fixPosIncludesFrame(); if (q->testAttribute(Qt::WA_Moved)) win->setGeometry(q->geometry()); else win->resize(q->size()); win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0)); if (q->testAttribute(Qt::WA_TranslucentBackground)) { QSurfaceFormat format; format.setAlphaBufferSize(8); win->setFormat(format); } if (QWidget *nativeParent = q->nativeParentWidget()) { if (nativeParent->windowHandle()) { if (flags & Qt::Window) { win->setTransientParent(nativeParent->windowHandle()); win->setParent(0); } else { win->setTransientParent(0); win->setParent(nativeParent->windowHandle()); } } } qt_window_private(win)->positionPolicy = topData()->posIncludesFrame ? QWindowPrivate::WindowFrameInclusive : QWindowPrivate::WindowFrameExclusive; win->create(); // Enable nonclient-area events for QDockWidget and other NonClientArea-mouse event processing. if ((flags & Qt::Desktop) == Qt::Window) win->handle()->setFrameStrutEventsEnabled(true); data.window_flags = win->flags(); QBackingStore *store = q->backingStore(); if (!store) { if (win && q->windowType() != Qt::Desktop) q->setBackingStore(new QBackingStore(win)); else q->setAttribute(Qt::WA_PaintOnScreen, true); } setWindowModified_helper(); setWinId(win->winId()); // Check children and create windows for them if necessary q_createNativeChildrenAndSetParent(q); if (extra && !extra->mask.isEmpty()) setMask_sys(extra->mask); // If widget is already shown, set window visible, too if (q->isVisible()) win->setVisible(true); }