Skip to content

Commit 9d36b08

Browse files
fcharlieminiksaDHowett
committed
Switch away from OS version detection for DirectWrite things (microsoft#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>
1 parent 5da2ab1 commit 9d36b08

3 files changed

Lines changed: 26 additions & 26 deletions

File tree

.vsconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
2626
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
2727
"Microsoft.VisualStudio.Component.VC.Tools.ARM64",
28-
"Microsoft.VisualStudio.Component.VC.v141.x86.x64",
29-
"Microsoft.VisualStudio.Component.VC.v141.ARM64",
28+
"Microsoft.VisualStudio.Component.VC.v142.x86.x64",
29+
"Microsoft.VisualStudio.Component.VC.v142.ARM64",
3030
"Microsoft.VisualStudio.ComponentGroup.UWP.VC",
31-
"Microsoft.VisualStudio.ComponentGroup.UWP.VC.v141",
31+
"Microsoft.VisualStudio.ComponentGroup.UWP.VC.v142",
3232
"Microsoft.VisualStudio.Component.UWP.VC.ARM64"
3333
]
3434
}

src/renderer/dx/CustomTextLayout.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,8 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
133133
RETURN_IF_FAILED(_analyzer->AnalyzeBidi(this, 0, textLength, this));
134134
RETURN_IF_FAILED(_analyzer->AnalyzeScript(this, 0, textLength, this));
135135
RETURN_IF_FAILED(_analyzer->AnalyzeNumberSubstitution(this, 0, textLength, this));
136-
137136
// Perform our custom font fallback analyzer that mimics the pattern of the real analyzers.
138-
// Fallback routines are not available below Windows 8.1, so just skip them and let a replacement character happen.
139-
if (IsWindows8Point1OrGreater())
140-
{
141-
RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength));
142-
}
137+
RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength));
143138

144139
// Ensure that a font face is attached to every run
145140
for (auto& run : _runs)
@@ -790,7 +785,11 @@ CustomTextLayout::CustomTextLayout(IDWriteFactory1* const factory,
790785
{
791786
// Get the font fallback first
792787
::Microsoft::WRL::ComPtr<IDWriteTextFormat1> format1;
793-
RETURN_IF_FAILED(_format.As(&format1));
788+
if (FAILED(_format.As(&format1)))
789+
{
790+
// If IDWriteTextFormat1 does not exist, return directly as this OS version doesn't have font fallback.
791+
return S_FALSE;
792+
}
794793
RETURN_HR_IF_NULL(E_NOINTERFACE, format1);
795794

796795
::Microsoft::WRL::ComPtr<IDWriteFontFallback> fallback;

src/renderer/dx/DxRenderer.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,7 @@ DxEngine::~DxEngine()
192192
SwapChainDesc.BufferCount = 2;
193193
SwapChainDesc.SampleDesc.Count = 1;
194194
SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
195-
196-
// DXGI_SCALING_NONE is only valid on Windows 8+
197-
if (IsWindows8OrGreater())
198-
{
199-
SwapChainDesc.Scaling = DXGI_SCALING_NONE;
200-
}
201-
else
202-
{
203-
SwapChainDesc.Scaling = DXGI_SCALING_STRETCH;
204-
}
195+
SwapChainDesc.Scaling = DXGI_SCALING_NONE;
205196

206197
switch (_chainMode)
207198
{
@@ -216,13 +207,23 @@ DxEngine::~DxEngine()
216207

217208
// We can't do alpha for HWNDs. Set to ignore. It will fail otherwise.
218209
SwapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
210+
const auto createSwapChainResult = _dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(),
211+
_hwndTarget,
212+
&SwapChainDesc,
213+
nullptr,
214+
nullptr,
215+
&_dxgiSwapChain);
216+
if (FAILED(createSwapChainResult))
217+
{
218+
SwapChainDesc.Scaling = DXGI_SCALING_STRETCH;
219+
RETURN_IF_FAILED(_dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(),
220+
_hwndTarget,
221+
&SwapChainDesc,
222+
nullptr,
223+
nullptr,
224+
&_dxgiSwapChain));
225+
}
219226

220-
RETURN_IF_FAILED(_dxgiFactory2->CreateSwapChainForHwnd(_d3dDevice.Get(),
221-
_hwndTarget,
222-
&SwapChainDesc,
223-
nullptr,
224-
nullptr,
225-
&_dxgiSwapChain));
226227
break;
227228
}
228229
case SwapChainMode::ForComposition:

0 commit comments

Comments
 (0)