Bug 1818654 - Don't give up on clipping to the visible rect in nsDisplayText when selection or shadow is present. r=emilio

Although I haven't been able to reproduce the reporter's OOM crash here, I hope this will avoid
the issue; it certainly improves performance characteristics in my local build.

On the example here, my laptop happily scrolls the text field at 60fps when nothing is selected;
but if the text is selected it can only manage around 40fps, because we lose the clipping
optimization here.

With this change, it maintains 60fps regardless of whether the text is selected (or text-shadow
is present), and memory footprint is substantially reduced.

Differential Revision: https://phabricator.services.mozilla.com/D171318
This commit is contained in:
Jonathan Kew
2023-03-01 11:37:27 +00:00
parent b337666fd9
commit 9449d3c3d1
3 changed files with 55 additions and 16 deletions

View File

@@ -6227,14 +6227,17 @@ bool nsTextFrame::GetSelectionTextColors(SelectionType aSelectionType,
* type of selection.
* If text-shadow was not specified, *aShadows is left untouched.
*/
static void GetSelectionTextShadow(nsIFrame* aFrame,
SelectionType aSelectionType,
nsTextPaintStyle& aTextPaintStyle,
Span<const StyleSimpleShadow>* aShadows) {
void nsTextFrame::GetSelectionTextShadow(
SelectionType aSelectionType, Span<const StyleSimpleShadow>* aShadows,
nsTextPaintStyle* aTextPaintStyle) {
if (aSelectionType != SelectionType::eNormal) {
return;
}
aTextPaintStyle.GetSelectionShadow(aShadows);
if (aTextPaintStyle) {
aTextPaintStyle->GetSelectionShadow(aShadows);
} else {
nsTextPaintStyle(this).GetSelectionShadow(aShadows);
}
}
/**
@@ -6673,8 +6676,7 @@ bool nsTextFrame::PaintTextWithSelectionColors(
// Determine what shadow, if any, to draw - either from textStyle
// or from the ::-moz-selection pseudo-class if specified there
Span<const StyleSimpleShadow> shadows = textStyle->mTextShadow.AsSpan();
GetSelectionTextShadow(this, selectionType, *aParams.textPaintStyle,
&shadows);
GetSelectionTextShadow(selectionType, &shadows, aParams.textPaintStyle);
if (!shadows.IsEmpty()) {
nscoord startEdge = iOffset;
if (mTextRun->IsInlineReversed()) {