mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:08:51 +02:00
Make display plugin switching atomic from other threads
This commit is contained in:
parent
caf2595e13
commit
520cccb219
2 changed files with 30 additions and 19 deletions
|
@ -4677,13 +4677,18 @@ qreal Application::getDevicePixelRatio() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayPlugin* Application::getActiveDisplayPlugin() {
|
DisplayPlugin* Application::getActiveDisplayPlugin() {
|
||||||
std::unique_lock<std::recursive_mutex> lock(_displayPluginLock);
|
DisplayPlugin* result = nullptr;
|
||||||
if (nullptr == _displayPlugin && QThread::currentThread() == thread()) {
|
if (QThread::currentThread() == thread()) {
|
||||||
updateDisplayMode();
|
if (nullptr == _displayPlugin) {
|
||||||
Q_ASSERT(_displayPlugin);
|
updateDisplayMode();
|
||||||
|
Q_ASSERT(_displayPlugin);
|
||||||
|
}
|
||||||
|
result = _displayPlugin.get();
|
||||||
|
} else {
|
||||||
|
std::unique_lock<std::mutex> lock(_displayPluginLock);
|
||||||
|
result = _displayPlugin.get();
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
return _displayPlugin.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DisplayPlugin* Application::getActiveDisplayPlugin() const {
|
const DisplayPlugin* Application::getActiveDisplayPlugin() const {
|
||||||
|
@ -4801,20 +4806,26 @@ void Application::updateDisplayMode() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_displayPlugin) {
|
|
||||||
_displayPlugin->deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
|
||||||
// FIXME probably excessive and useless context switching
|
// Make the switch atomic from the perspective of other threads
|
||||||
_offscreenContext->makeCurrent();
|
{
|
||||||
newDisplayPlugin->activate();
|
std::unique_lock<std::mutex> lock(_displayPluginLock);
|
||||||
_offscreenContext->makeCurrent();
|
|
||||||
offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
|
if (_displayPlugin) {
|
||||||
_offscreenContext->makeCurrent();
|
_displayPlugin->deactivate();
|
||||||
getApplicationCompositor().setDisplayPlugin(newDisplayPlugin);
|
}
|
||||||
_displayPlugin = newDisplayPlugin;
|
|
||||||
|
// FIXME probably excessive and useless context switching
|
||||||
|
_offscreenContext->makeCurrent();
|
||||||
|
newDisplayPlugin->activate();
|
||||||
|
_offscreenContext->makeCurrent();
|
||||||
|
offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
|
||||||
|
_offscreenContext->makeCurrent();
|
||||||
|
getApplicationCompositor().setDisplayPlugin(newDisplayPlugin);
|
||||||
|
_displayPlugin = newDisplayPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
emit activeDisplayPluginChanged();
|
emit activeDisplayPluginChanged();
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ private:
|
||||||
|
|
||||||
OffscreenGLCanvas* _offscreenContext { nullptr };
|
OffscreenGLCanvas* _offscreenContext { nullptr };
|
||||||
DisplayPluginPointer _displayPlugin;
|
DisplayPluginPointer _displayPlugin;
|
||||||
std::recursive_mutex _displayPluginLock;
|
std::mutex _displayPluginLock;
|
||||||
InputPluginList _activeInputPlugins;
|
InputPluginList _activeInputPlugins;
|
||||||
|
|
||||||
bool _activatingDisplayPlugin { false };
|
bool _activatingDisplayPlugin { false };
|
||||||
|
|
Loading…
Reference in a new issue