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 <miniksa@microsoft.com>
Co-Authored-By: Dustin L. Howett (MSFT) <duhowett@microsoft.com>
This commit is contained in:
Force Charlie 2019-07-25 00:57:13 +08:00 committed by Dustin L. Howett (MSFT)
parent 5da2ab1a86
commit 9d36b08b82
3 changed files with 26 additions and 26 deletions

View file

@ -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"
]
}

View file

@ -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<IDWriteTextFormat1> 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<IDWriteFontFallback> fallback;

View file

@ -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: