From 6f7ad99d514c55acc02a8052e208b3a923671c9b Mon Sep 17 00:00:00 2001 From: Chester Liu Date: Fri, 18 Oct 2019 02:06:14 +0800 Subject: [PATCH] Reduce text layout CPU usage when DWrite analysis is not needed (#2959) References #806. --- src/renderer/dx/CustomTextLayout.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp index de883e842..122a594f7 100644 --- a/src/renderer/dx/CustomTextLayout.cpp +++ b/src/renderer/dx/CustomTextLayout.cpp @@ -129,13 +129,20 @@ CustomTextLayout::CustomTextLayout(gsl::not_null const factory // Allocate enough room to have one breakpoint per code unit. _breakpoints.resize(_text.size()); - // Call each of the analyzers in sequence, recording their results. - RETURN_IF_FAILED(_analyzer->AnalyzeLineBreakpoints(this, 0, textLength, this)); - 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. - RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength)); + BOOL isTextSimple = FALSE; + UINT32 uiLengthRead = 0; + RETURN_IF_FAILED(_analyzer->GetTextComplexity(_text.c_str(), textLength, _font.Get(), &isTextSimple, &uiLengthRead, NULL)); + + if (!(isTextSimple && uiLengthRead == _text.size())) + { + // Call each of the analyzers in sequence, recording their results. + RETURN_IF_FAILED(_analyzer->AnalyzeLineBreakpoints(this, 0, textLength, this)); + 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. + RETURN_IF_FAILED(_AnalyzeFontFallback(this, 0, textLength)); + } // Ensure that a font face is attached to every run for (auto& run : _runs)