71QOffscreenSurface::QOffscreenSurface(QScreen *targetScreen, QObject *parent)
72 : QObject(*
new QOffscreenSurfacePrivate(), parent)
75 Q_D(QOffscreenSurface);
76 d->screen = targetScreen;
78 d->screen = QGuiApplication::primaryScreen();
84 connect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
118void QOffscreenSurface::create()
120 Q_D(QOffscreenSurface);
121 if (!d->platformOffscreenSurface && !d->offscreenWindow) {
122 d->platformOffscreenSurface = QGuiApplicationPrivate::platformIntegration()->createPlatformOffscreenSurface(
this);
124 if (!d->platformOffscreenSurface) {
125 if (!QThread::isMainThread())
126 qWarning(
"Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures.");
127 d->offscreenWindow =
new QWindow(d->screen);
130 d->offscreenWindow->setFlags(d->offscreenWindow->flags()
131 | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
132 d->offscreenWindow->setObjectName(
"QOffscreenSurface"_L1);
135 QGuiApplicationPrivate::window_list.removeOne(d->offscreenWindow);
136 d->offscreenWindow->setSurfaceType(QWindow::OpenGLSurface);
137 d->offscreenWindow->setFormat(d->requestedFormat);
139 qt_window_private(d->offscreenWindow)->setAutomaticPositionAndResizeEnabled(
false);
140 d->offscreenWindow->setGeometry(0, 0, d->size.width(), d->size.height());
141 d->offscreenWindow->create();
144 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
145 QGuiApplication::sendEvent(
this, &e);
154void QOffscreenSurface::destroy()
156 Q_D(QOffscreenSurface);
158 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
159 QGuiApplication::sendEvent(
this, &e);
161 delete d->platformOffscreenSurface;
162 d->platformOffscreenSurface =
nullptr;
163 if (d->offscreenWindow) {
164 d->offscreenWindow->destroy();
165 delete d->offscreenWindow;
166 d->offscreenWindow =
nullptr;
260void QOffscreenSurface::setScreen(QScreen *newScreen)
262 Q_D(QOffscreenSurface);
264 newScreen = QCoreApplication::instance() ? QGuiApplication::primaryScreen() :
nullptr;
265 if (newScreen != d->screen) {
266 const bool wasCreated = d->platformOffscreenSurface !=
nullptr || d->offscreenWindow !=
nullptr;
270 disconnect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
271 d->screen = newScreen;
273 connect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
277 emit screenChanged(newScreen);