[dxgi] Removed SDL dependencies from DxgiSwapChain

This commit is contained in:
Philip Rebohle 2017-12-05 14:43:03 +01:00
parent 34ed79dacc
commit 245ba75123
3 changed files with 44 additions and 87 deletions

View File

@ -37,15 +37,6 @@ namespace dxvk {
m_stats.SyncQPCTime.QuadPart = 0;
m_stats.SyncGPUTime.QuadPart = 0;
// Create SDL window handle
m_window = SDL_CreateWindowFrom(m_desc.OutputWindow);
if (m_window == nullptr) {
throw DxvkError(str::format(
"DxgiSwapChain::DxgiSwapChain: Failed to create window:\n",
SDL_GetError()));
}
// Adjust initial back buffer size. If zero, these
// shall be set to the current window size.
VkExtent2D windowSize = this->getWindowSize();
@ -54,8 +45,8 @@ namespace dxvk {
if (m_desc.BufferDesc.Height == 0) m_desc.BufferDesc.Height = windowSize.height;
// Set initial window mode and fullscreen state
if (FAILED(this->SetFullscreenState(!pDesc->Windowed, nullptr)))
throw DxvkError("DxgiSwapChain::DxgiSwapChain: Failed to set initial fullscreen state");
// if (FAILED(this->SetFullscreenState(!pDesc->Windowed, nullptr)))
// throw DxvkError("DxgiSwapChain::DxgiSwapChain: Failed to set initial fullscreen state");
this->createPresenter();
this->createBackBuffer();
@ -105,18 +96,9 @@ namespace dxvk {
if (ppOutput != nullptr)
return DXGI_ERROR_INVALID_CALL;
// We can use the display index returned by SDL to query the
// containing output, since DxgiAdapter::EnumOutputs uses the
// same output IDs.
std::lock_guard<std::mutex> lock(m_mutex);
int32_t displayId = SDL_GetWindowDisplayIndex(m_window);
if (displayId < 0) {
Logger::err("DxgiSwapChain::GetContainingOutput: Failed to query window display index");
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
}
return m_adapter->EnumOutputs(displayId, ppOutput);
Logger::err("DxgiSwapChain::GetContainingOutput: Not implemented yet");
return E_NOTIMPL;
}
@ -228,27 +210,38 @@ namespace dxvk {
std::lock_guard<std::mutex> lock(m_mutex);
// Applies to windowed mode
SDL_SetWindowSize(m_window,
RECT newRect;
RECT oldRect;
::SetRect(&newRect, 0, 0,
pNewTargetParameters->Width,
pNewTargetParameters->Height);
::AdjustWindowRectEx(&newRect,
GetWindowLongW(m_desc.OutputWindow, GWL_STYLE), FALSE,
GetWindowLongW(m_desc.OutputWindow, GWL_EXSTYLE));
::SetRect(&newRect, 0, 0,
newRect.right - newRect.left,
newRect.bottom - newRect.top);
::GetWindowRect(m_desc.OutputWindow, &oldRect);
::OffsetRect(&newRect, oldRect.left, oldRect.top);
// Applies to fullscreen mode
SDL_DisplayMode displayMode;
displayMode.format = SDL_PIXELFORMAT_RGBA32;
displayMode.w = pNewTargetParameters->Width;
displayMode.h = pNewTargetParameters->Height;
displayMode.refresh_rate = pNewTargetParameters->RefreshRate.Numerator
/ pNewTargetParameters->RefreshRate.Denominator;
displayMode.driverdata = nullptr;
// TODO implement fullscreen mode
if (SDL_SetWindowDisplayMode(m_window, &displayMode)) {
throw DxvkError(str::format(
"DxgiSwapChain::ResizeTarget: Failed to set display mode:\n",
SDL_GetError()));
::MoveWindow(m_desc.OutputWindow,
newRect.left, newRect.top,
newRect.right - newRect.left,
newRect.bottom - newRect.top, TRUE);
try {
m_presenter->recreateSwapchain(
m_desc.BufferDesc.Width,
m_desc.BufferDesc.Height,
m_desc.BufferDesc.Format);
return S_OK;
} catch (const DxvkError& e) {
Logger::err(e.message());
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
}
return S_OK;
}
@ -257,46 +250,8 @@ namespace dxvk {
IDXGIOutput* pTarget) {
std::lock_guard<std::mutex> lock(m_mutex);
// Unconditionally reset the swap chain to windowed mode first.
// This required if the application wants to move the window to
// a different display while remaining in fullscreen mode.
if (SDL_SetWindowFullscreen(m_window, 0)) {
Logger::err(str::format(
"DxgiSwapChain::SetFullscreenState: Failed to set windowed mode:\n",
SDL_GetError()));
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
}
m_desc.Windowed = !Fullscreen;
if (Fullscreen) {
// If a target output is specified, we need to move the
// window to that output first while in windowed mode.
if (pTarget != nullptr) {
DXGI_OUTPUT_DESC outputDesc;
if (FAILED(pTarget->GetDesc(&outputDesc))) {
Logger::err("DxgiSwapChain::SetFullscreenState: Failed to query output properties");
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
}
SDL_SetWindowPosition(m_window,
outputDesc.DesktopCoordinates.left,
outputDesc.DesktopCoordinates.top);
}
// Now that the window is located at the target location,
// SDL should fullscreen it on the requested display. We
// only use borderless fullscreen for now, may be changed.
if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP)) {
Logger::err(str::format(
"DxgiSwapChain::SetFullscreenState: Failed to set fullscreen mode:\n",
SDL_GetError()));
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
}
}
return S_OK;
Logger::err("DxgiSwapChain::SetFullscreenState: Not implemented yet");
return E_NOTIMPL;
}
@ -325,6 +280,7 @@ namespace dxvk {
DxvkImageCreateInfo imageInfo;
imageInfo.type = VK_IMAGE_TYPE_2D;
imageInfo.format = bufferFormat.actual;
imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
imageInfo.extent.width = m_desc.BufferDesc.Width;
imageInfo.extent.height = m_desc.BufferDesc.Height;
@ -388,15 +344,16 @@ namespace dxvk {
VkExtent2D DxgiSwapChain::getWindowSize() const {
int winWidth = 0;
int winHeight = 0;
RECT rect;
SDL_GetWindowSize(m_window, &winWidth, &winHeight);
if (::GetClientRect(m_desc.OutputWindow, &rect)) {
VkExtent2D result;
result.width = rect.right - rect.left;
result.height = rect.bottom - rect.top;
return result;
}
VkExtent2D result;
result.width = winWidth;
result.height = winHeight;
return result;
throw DxvkError("DxgiSwapChain::getWindowSize: Failed to get window rect");
}
}

View File

@ -91,9 +91,6 @@ namespace dxvk {
DXGI_SWAP_CHAIN_DESC m_desc;
DXGI_FRAME_STATISTICS m_stats;
SDL_Window* m_window = nullptr;
Rc<DxvkContext> m_context;
Rc<DxvkCommandList> m_commandList;
Rc<DxvkSurface> m_surface;

View File

@ -54,6 +54,9 @@ public:
if (FAILED(m_device->CreateRenderTargetView(m_buffer.ptr(), nullptr, &m_bufferView)))
throw DxvkError("Failed to create render target view");
if (FAILED(m_swapChain->ResizeTarget(&swapDesc.BufferDesc)))
throw DxvkError("Failed to resize window");
}