Skip to content

Commit

Permalink
libobs-d3d11: Force SDR for legacy swap chain
Browse files Browse the repository at this point in the history
Legacy DISCARD does not support HDR, so prevent HDR preview.
  • Loading branch information
jpark37 authored and jp9000 committed Aug 10, 2022
1 parent e3cebb9 commit b4f7499
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions libobs-d3d11/d3d11-subsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ static bool screen_supports_hdr(gs_device_t *device, HMONITOR hMonitor)
return false;
}

static enum gs_color_space get_next_space(gs_device_t *device, HWND hwnd)
static enum gs_color_space get_next_space(gs_device_t *device, HWND hwnd,
DXGI_SWAP_EFFECT effect)
{
enum gs_color_space next_space = GS_CS_SRGB;
const HMONITOR hMonitor =
MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (hMonitor) {
if (screen_supports_hdr(device, hMonitor))
next_space = GS_CS_709_SCRGB;
if (effect == DXGI_SWAP_EFFECT_FLIP_DISCARD) {
const HMONITOR hMonitor =
MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (hMonitor) {
if (screen_supports_hdr(device, hMonitor))
next_space = GS_CS_709_SCRGB;
}
}

return next_space;
Expand All @@ -131,7 +134,7 @@ make_swap_desc(gs_device *device, DXGI_SWAP_CHAIN_DESC &desc,
const gs_init_data *data, DXGI_SWAP_EFFECT effect, UINT flags)
{
const HWND hwnd = (HWND)data->window.hwnd;
const enum gs_color_space space = get_next_space(device, hwnd);
const enum gs_color_space space = get_next_space(device, hwnd, effect);
const gs_color_format format =
get_swap_format_from_space(space, data->format);

Expand Down Expand Up @@ -243,7 +246,8 @@ void gs_swap_chain::Resize(uint32_t cx, uint32_t cy, gs_color_format format)
void gs_swap_chain::Init()
{
const gs_color_format format = get_swap_format_from_space(
get_next_space(device, hwnd), initData.format);
get_next_space(device, hwnd, swapDesc.SwapEffect),
initData.format);

target.device = device;
target.isRenderTarget = true;
Expand Down Expand Up @@ -1437,7 +1441,8 @@ void device_resize(gs_device_t *device, uint32_t cx, uint32_t cy)
}

const enum gs_color_space next_space =
get_next_space(device, device->curSwapChain->hwnd);
get_next_space(device, device->curSwapChain->hwnd,
device->curSwapChain->swapDesc.SwapEffect);
device_resize_internal(device, cx, cy, next_space);
}

Expand All @@ -1449,8 +1454,9 @@ enum gs_color_space device_get_color_space(gs_device_t *device)
void device_update_color_space(gs_device_t *device)
{
if (device->curSwapChain) {
const enum gs_color_space next_space =
get_next_space(device, device->curSwapChain->hwnd);
const enum gs_color_space next_space = get_next_space(
device, device->curSwapChain->hwnd,
device->curSwapChain->swapDesc.SwapEffect);
if (device->curSwapChain->space != next_space)
device_resize_internal(device, 0, 0, next_space);
} else {
Expand Down

0 comments on commit b4f7499

Please sign in to comment.