70QOffscreenSurface::QOffscreenSurface(QScreen *targetScreen, QObject *parent)
71 : QObject(*
new QOffscreenSurfacePrivate(), parent)
74 Q_D(QOffscreenSurface);
75 d->screen = targetScreen;
77 d->screen = QGuiApplication::primaryScreen();
83 connect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
117void QOffscreenSurface::create()
119 Q_D(QOffscreenSurface);
120 if (!d->platformOffscreenSurface && !d->offscreenWindow) {
121 d->platformOffscreenSurface = QGuiApplicationPrivate::platformIntegration()->createPlatformOffscreenSurface(
this);
123 if (!d->platformOffscreenSurface) {
124 if (!QThread::isMainThread())
125 qWarning(
"Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures.");
126 d->offscreenWindow =
new QWindow(d->screen);
129 d->offscreenWindow->setFlags(d->offscreenWindow->flags()
130 | Qt::CustomizeWindowHint | Qt::FramelessWindowHint);
131 d->offscreenWindow->setObjectName(
"QOffscreenSurface"_L1);
134 QGuiApplicationPrivate::window_list.removeOne(d->offscreenWindow);
135 d->offscreenWindow->setSurfaceType(QWindow::OpenGLSurface);
136 d->offscreenWindow->setFormat(d->requestedFormat);
138 qt_window_private(d->offscreenWindow)->setAutomaticPositionAndResizeEnabled(
false);
139 d->offscreenWindow->setGeometry(0, 0, d->size.width(), d->size.height());
140 d->offscreenWindow->create();
143 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceCreated);
144 QGuiApplication::sendEvent(
this, &e);
153void QOffscreenSurface::destroy()
155 Q_D(QOffscreenSurface);
157 QPlatformSurfaceEvent e(QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed);
158 QGuiApplication::sendEvent(
this, &e);
160 delete d->platformOffscreenSurface;
161 d->platformOffscreenSurface =
nullptr;
162 if (d->offscreenWindow) {
163 d->offscreenWindow->destroy();
164 delete d->offscreenWindow;
165 d->offscreenWindow =
nullptr;
259void QOffscreenSurface::setScreen(QScreen *newScreen)
261 Q_D(QOffscreenSurface);
263 newScreen = QCoreApplication::instance() ? QGuiApplication::primaryScreen() :
nullptr;
264 if (newScreen != d->screen) {
265 const bool wasCreated = d->platformOffscreenSurface !=
nullptr || d->offscreenWindow !=
nullptr;
269 disconnect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
270 d->screen = newScreen;
272 connect(d->screen, SIGNAL(destroyed(QObject*)),
this, SLOT(screenDestroyed(QObject*)));
276 emit screenChanged(newScreen);