From 9d36b08b82c67c6965263c63bb83b024c15f3474 Mon Sep 17 00:00:00 2001 From: Force Charlie <6904176+fcharlie@users.noreply.github.com> Date: Thu, 25 Jul 2019 00:57:13 +0800 Subject: [PATCH] Switch away from OS version detection for DirectWrite things (#2065) * If IDWriteTextFormat1 does not exist, return directly * We use DXGI_SCALING_NONE create SwapChain first, if failed switch to DXGI_SCALING_STRETCH Co-Authored-By: Michael Niksa Co-Authored-By: Dustin L. Howett (MSFT) --- .vsconfig | 6 ++--- src/renderer/dx/CustomTextLayout.cpp | 13 +++++------ src/renderer/dx/DxRenderer.cpp | 33 ++++++++++++++-------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.vsconfig b/.vsconfig index 6c8fea8e62..9d9827efe9 100644 --- a/.vsconfig +++ b/.vsconfig @@ -25,10 +25,10 @@ "Microsoft.VisualStudio.Component.VC.Redist.14.Latest", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "Microsoft.VisualStudio.Component.VC.Tools.ARM64", - "Microsoft.VisualStudio.Component.VC.v141.x86.x64", - "Microsoft.VisualStudio.Component.VC.v141.ARM64", + "Microsoft.VisualStudio.Component.VC.v142.x86.x64", + "Microsoft.VisualStudio.Component.VC.v142.ARM64", "Microsoft.VisualStudio.ComponentGroup.UWP.VC", - "Microsoft.VisualStudio.ComponentGroup.UWP.VC.v141", + "Microsoft.VisualStudio.ComponentGroup.UWP.VC.v142", "Microsoft.VisualStudio.Component.UWP.VC.ARM64" ] } diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp index 1d6c2ccca5..94cf4c8e47 100644 --- a/src/renderer/dx/CustomTextLayout.cpp +++ b/src/renderer/dx/CustomTextLayout.cpp @@ -133,13 +133,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, RETURN_IF_FAILED(_analyzer->AnalyzeBidi(this, 0, textLength, this)); RETURN_IF_FAILED(_analyzer->AnalyzeScript(this, 0, textLength, this)); RETURN_IF_FAILED(_analyzer->AnalyzeNumberSubstitution(this, 0, textLength, this)); - // Perform our custom font fallback analyzer that mimics the pattern of the real analyzers. - // Fallback routines are not available below Windows 8.1, so just skip them and let a replacement character happen. - if (IsWindows8Point1OrGreater()) - { - RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength)); - } + RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength)); // Ensure that a font face is attached to every run for (auto& run : _runs) @@ -790,7 +785,11 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory, { // Get the font fallback first ::Microsoft::WRL::ComPtr format1; - RETURN_IF_FAILED(_format.As(&format1)); + if (FAILED(_format.As(&format1))) + { + // If IDWriteTextFormat1 does not exist, return directly as this OS version doesn't have font fallback. + return S_FALSE; + } RETURN_HR_IF_NULL(E_NOINTERFACE, format1); ::Microsoft::WRL::ComPtr fallback; diff --git a/src/renderer/dx/DxRenderer.cpp b/src/renderer/dx/DxRenderer.cpp index e7d3f22f4a..f59f02c960 100644 --- a/src/renderer/dx/DxRenderer.cpp +++ b/src/renderer/dx/DxRenderer.cpp @@ -192,16 +192,7 @@ DxEngine::~DxEngine() SwapChainDesc.BufferCount = 2; SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; - - // DXGI_SCALING_NONE is only valid on Windows 8+ - if (IsWindows8OrGreater()) - { - SwapChainDesc.Scaling = DXGI_SCALING_NONE; - } - else - { - SwapChainDesc.Scaling = DXGI_SCALING_STRETCH; - } + SwapChainDesc.Scaling = DXGI_SCALING_NONE; switch (_chainMode) { @@ -216,13 +207,23 @@ DxEngine::~DxEngine() // We can't do alpha for HWNDs. Set to ignore. It will fail otherwise. SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + const auto createSwapChainResult = _dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(), + _hwndTarget, + &SwapChainDesc, + nullptr, + nullptr, + &_dxgiSwapChain); + if (FAILED(createSwapChainResult)) + { + SwapChainDesc.Scaling = DXGI_SCALING_STRETCH; + RETURN_IF_FAILED(_dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(), + _hwndTarget, + &SwapChainDesc, + nullptr, + nullptr, + &_dxgiSwapChain)); + } - RETURN_IF_FAILED(_dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(), - _hwndTarget, - &SwapChainDesc, - nullptr, - nullptr, - &_dxgiSwapChain)); break; } case SwapChainMode::ForComposition: