Merge pull request #7434 from zzmp/clean/incomplete-fbo

Clean up QML Render Thread
This commit is contained in:
Brad Hefta-Gaub 2016-03-23 10:43:21 -07:00
commit 08b87b9b98

View file

@ -214,22 +214,19 @@ void OffscreenQmlRenderThread::init() {
connect(_renderControl, &QQuickRenderControl::sceneChanged, _surface, &OffscreenQmlSurface::requestUpdate); connect(_renderControl, &QQuickRenderControl::sceneChanged, _surface, &OffscreenQmlSurface::requestUpdate);
if (!_canvas.makeCurrent()) { if (!_canvas.makeCurrent()) {
qWarning("Failed to make context current on render thread"); // Failed to make GL context current, this OffscreenQmlSurface is basically dead
qWarning("Failed to make context current on QML Renderer Thread");
return; return;
} }
_renderControl->initialize(_canvas.getContext()); _renderControl->initialize(_canvas.getContext());
setupFbo(); setupFbo();
_escrow.setRecycler([this](GLuint texture){ _escrow.setRecycler([this](GLuint texture){
_textures.recycleTexture(texture); _textures.recycleTexture(texture);
}); });
_canvas.doneCurrent();
} }
void OffscreenQmlRenderThread::cleanup() { void OffscreenQmlRenderThread::cleanup() {
if (!_canvas.makeCurrent()) {
qFatal("Failed to make context current on render thread");
return;
}
_renderControl->invalidate(); _renderControl->invalidate();
_fbo.reset(); _fbo.reset();
@ -237,7 +234,6 @@ void OffscreenQmlRenderThread::cleanup() {
_textures.clear(); _textures.clear();
_canvas.doneCurrent(); _canvas.doneCurrent();
_canvas.getContextObject()->moveToThread(QCoreApplication::instance()->thread()); _canvas.getContextObject()->moveToThread(QCoreApplication::instance()->thread());
_quit = true; _quit = true;
@ -245,40 +241,33 @@ void OffscreenQmlRenderThread::cleanup() {
void OffscreenQmlRenderThread::resize() { void OffscreenQmlRenderThread::resize() {
// Lock _newSize changes // Lock _newSize changes
QMutexLocker locker(&_mutex); {
QMutexLocker locker(&_mutex);
// Update our members // Update our members
if (_quickWindow) { if (_quickWindow) {
_quickWindow->setGeometry(QRect(QPoint(), _newSize)); _quickWindow->setGeometry(QRect(QPoint(), _newSize));
_quickWindow->contentItem()->setSize(_newSize); _quickWindow->contentItem()->setSize(_newSize);
}
// Qt bug in 5.4 forces this check of pixel ratio,
// even though we're rendering offscreen.
qreal pixelRatio = 1.0;
if (_renderControl && _renderControl->_renderWindow) {
pixelRatio = _renderControl->_renderWindow->devicePixelRatio();
}
uvec2 newOffscreenSize = toGlm(_newSize * pixelRatio);
if (newOffscreenSize == _size) {
return;
}
qDebug() << "Offscreen UI resizing to " << _newSize.width() << "x" << _newSize.height() << " with pixel ratio " << pixelRatio;
_size = newOffscreenSize;
} }
// Qt bug in 5.4 forces this check of pixel ratio, _textures.setSize(_size);
// even though we're rendering offscreen.
qreal pixelRatio = 1.0;
if (_renderControl && _renderControl->_renderWindow) {
pixelRatio = _renderControl->_renderWindow->devicePixelRatio();
}
uvec2 newOffscreenSize = toGlm(_newSize * pixelRatio);
_textures.setSize(newOffscreenSize);
if (newOffscreenSize == _size) {
return;
}
_size = newOffscreenSize;
// Clear out any fbos with the old size
if (!_canvas.makeCurrent()) {
qWarning("Failed to make context current on render thread");
return;
}
qDebug() << "Offscreen UI resizing to " << _newSize.width() << "x" << _newSize.height() << " with pixel ratio " << pixelRatio;
locker.unlock();
setupFbo(); setupFbo();
_canvas.doneCurrent();
} }
void OffscreenQmlRenderThread::render() { void OffscreenQmlRenderThread::render() {
@ -287,11 +276,6 @@ void OffscreenQmlRenderThread::render() {
return; return;
} }
if (!_canvas.makeCurrent()) {
qWarning("Failed to make context current on render thread");
return;
}
QMutexLocker locker(&_mutex); QMutexLocker locker(&_mutex);
_renderControl->sync(); _renderControl->sync();
_waitCondition.wakeOne(); _waitCondition.wakeOne();
@ -338,10 +322,10 @@ OffscreenQmlSurface::~OffscreenQmlSurface() {
QObject::disconnect(&_updateTimer); QObject::disconnect(&_updateTimer);
QObject::disconnect(qApp); QObject::disconnect(qApp);
qDebug() << "Stopping QML render thread " << _renderer->currentThreadId(); qDebug() << "Stopping QML Renderer Thread " << _renderer->currentThreadId();
_renderer->_queue.add(STOP); _renderer->_queue.add(STOP);
if (!_renderer->wait(MAX_SHUTDOWN_WAIT_SECS * USECS_PER_SECOND)) { if (!_renderer->wait(MAX_SHUTDOWN_WAIT_SECS * USECS_PER_SECOND)) {
qWarning() << "Failed to shut down the QML render thread"; qWarning() << "Failed to shut down the QML Renderer Thread";
} }
delete _rootItem; delete _rootItem;