summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/Render.cpp
diff options
context:
space:
mode:
authorJules Blok <jules.blok@gmail.com>2016-11-09 01:07:56 +0100
committerJules Blok <jules.blok@gmail.com>2016-11-11 20:36:04 +0100
commitc21efa0cad0e968dcc9c439169e09ba7b3fed27c (patch)
tree0990a1e3aba1199166ff47abf9779384dd83bf3a /Source/Core/VideoBackends/D3D/Render.cpp
parentf0ce3275afacbb8b61656f6d64216efee1dc2958 (diff)
D3D: Move exclusive mode switching to UI thread.
This prevents deadlocks when switching to exclusive mode. And it also allows the CPU thread to block until we've completed the switch.
Diffstat (limited to 'Source/Core/VideoBackends/D3D/Render.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/Render.cpp58
1 files changed, 19 insertions, 39 deletions
diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp
index bf0b487276..70dbb77bb3 100644
--- a/Source/Core/VideoBackends/D3D/Render.cpp
+++ b/Source/Core/VideoBackends/D3D/Render.cpp
@@ -5,6 +5,7 @@
#include <cinttypes>
#include <cmath>
#include <memory>
+#include <mutex>
#include <string>
#include <strsafe.h>
#include <unordered_map>
@@ -43,6 +44,9 @@ namespace DX11
static u32 s_last_multisamples = 1;
static bool s_last_stereo_mode = false;
static bool s_last_xfb_mode = false;
+static bool s_last_exclusive_mode = false;
+
+static std::mutex s_critical_fullscreen;
static Television s_television;
@@ -851,8 +855,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
SetWindowSize(fbStride, fbHeight);
const bool windowResized = CheckForResize();
- const bool fullscreen = g_ActiveConfig.bFullscreen && !g_ActiveConfig.bBorderlessFullscreen &&
- !SConfig::GetInstance().bRenderToMain;
bool xfbchanged = s_last_xfb_mode != g_ActiveConfig.bUseRealXFB;
@@ -869,33 +871,19 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
// Flip/present backbuffer to frontbuffer here
D3D::Present();
- // Check exclusive fullscreen state
- bool exclusive_mode, fullscreen_changed = false;
- if (SUCCEEDED(D3D::GetFullscreenState(&exclusive_mode)))
+ // Check if we need to regain exclusive mode
{
- if (fullscreen && !exclusive_mode)
- {
- if (g_Config.bExclusiveMode)
- OSD::AddMessage("Lost exclusive fullscreen.");
+ std::lock_guard<std::mutex> lk(s_critical_fullscreen);
- // Exclusive fullscreen is enabled in the configuration, but we're
- // not in exclusive mode. Either exclusive fullscreen was turned on
- // or the render frame lost focus. When the render frame is in focus
- // we can apply exclusive mode.
- fullscreen_changed = Host_RendererHasFocus();
-
- g_Config.bExclusiveMode = false;
- }
- else if (!fullscreen && exclusive_mode)
- {
- // Exclusive fullscreen is disabled, but we're still in exclusive mode.
- fullscreen_changed = true;
- }
+ bool exclusive_mode = false;
+ D3D::GetFullscreenState(&exclusive_mode);
+ if (s_last_exclusive_mode && !exclusive_mode && Host_RendererHasFocus())
+ D3D::SetFullscreenState(true);
}
// Resize the back buffers NOW to avoid flickering
if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height) || xfbchanged || windowResized ||
- fullscreen_changed || s_last_efb_scale != g_ActiveConfig.iEFBScale ||
+ s_last_efb_scale != g_ActiveConfig.iEFBScale ||
s_last_multisamples != g_ActiveConfig.iMultisamples ||
s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
{
@@ -903,23 +891,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
s_last_multisamples = g_ActiveConfig.iMultisamples;
PixelShaderCache::InvalidateMSAAShaders();
- if (windowResized || fullscreen_changed)
+ if (windowResized)
{
- // Apply fullscreen state
- if (fullscreen_changed)
- {
- g_Config.bExclusiveMode = fullscreen;
-
- if (fullscreen)
- OSD::AddMessage("Entered exclusive fullscreen.");
-
- D3D::SetFullscreenState(fullscreen);
-
- // If fullscreen is disabled we can safely notify the UI to exit fullscreen.
- if (!g_ActiveConfig.bFullscreen)
- Host_RequestFullscreen(false);
- }
-
// TODO: Aren't we still holding a reference to the back buffer right now?
D3D::Reset();
SAFE_RELEASE(s_screenshot_texture);
@@ -1291,4 +1264,11 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
}
}
+void Renderer::SetFullscreen(bool enable_fullscreen)
+{
+ std::lock_guard<std::mutex> lk(s_critical_fullscreen);
+ s_last_exclusive_mode = enable_fullscreen;
+ D3D::SetFullscreenState(enable_fullscreen);
+}
+
} // namespace DX11