Skip to content
Permalink
Browse files
TextBoxPainter::paintForeground: painting text with no marking/decora…
…tion should be simple

https://bugs.webkit.org/show_bug.cgi?id=240319

Reviewed by Simon Fraser.

Let's have a fast codepath for regular, simple text painting.

* rendering/StyledMarkedText.cpp:
(WebCore::StyledMarkedText::computeStyleForUnmarkedMarkedText):
(WebCore::computeStyleForUnmarkedMarkedText): Deleted.
* rendering/StyledMarkedText.h:
(WebCore::StyledMarkedText::StyledMarkedText):
(WebCore::StyledMarkedText::style):
* rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter::paintBackground):
(WebCore::TextBoxPainter::paintForegroundAndDecorations):

Canonical link: https://commits.webkit.org/250505@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294128 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed May 13, 2022
1 parent a1b4641 commit e1a113f784d5f9189dbabd3fe3e06941def97bc4
Showing 4 changed files with 56 additions and 11 deletions.
@@ -1,3 +1,22 @@
2022-05-12 Alan Bujtas <zalan@apple.com>

TextBoxPainter::paintForeground: painting text with no marking/decoration should be simple
https://bugs.webkit.org/show_bug.cgi?id=240319

Reviewed by Simon Fraser.

Let's have a fast codepath for regular, simple text painting.

* rendering/StyledMarkedText.cpp:
(WebCore::StyledMarkedText::computeStyleForUnmarkedMarkedText):
(WebCore::computeStyleForUnmarkedMarkedText): Deleted.
* rendering/StyledMarkedText.h:
(WebCore::StyledMarkedText::StyledMarkedText):
(WebCore::StyledMarkedText::style):
* rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter::paintBackground):
(WebCore::TextBoxPainter::paintForegroundAndDecorations):

2022-05-12 Sihui Liu <sihui_liu@apple.com>

StorageMap::removeItem may fail to remove item from map
@@ -110,7 +110,7 @@ static StyledMarkedText resolveStyleForMarkedText(const MarkedText& markedText,
return styledMarkedText;
}

static StyledMarkedText::Style computeStyleForUnmarkedMarkedText(const RenderText& renderer, const RenderStyle& lineStyle, bool isFirstLine, const PaintInfo& paintInfo)
StyledMarkedText::Style StyledMarkedText::computeStyleForUnmarkedMarkedText(const RenderText& renderer, const RenderStyle& lineStyle, bool isFirstLine, const PaintInfo& paintInfo)
{
StyledMarkedText::Style style;
style.textDecorationStyles = TextDecorationPainter::stylesForRenderer(renderer, lineStyle.textDecorationsInEffect(), isFirstLine);
@@ -36,11 +36,6 @@ class RenderText;
class RenderedDocumentMarker;

struct StyledMarkedText : MarkedText {
StyledMarkedText(const MarkedText& marker)
: MarkedText { marker }
{
}

struct Style {
Color backgroundColor;
TextPaintStyle textStyles;
@@ -49,12 +44,24 @@ struct StyledMarkedText : MarkedText {
float alpha { 1 };
};

StyledMarkedText(const MarkedText& marker)
: MarkedText { marker }
{
}

StyledMarkedText(const MarkedText& marker, Style style)
: MarkedText { marker }
, style(style)
{
}

Style style;

static Vector<StyledMarkedText> subdivideAndResolve(const Vector<MarkedText>&, const RenderText&, bool isFirstLine, const PaintInfo&);
static Vector<StyledMarkedText> coalesceAdjacentWithEqualBackground(const Vector<StyledMarkedText>&);
static Vector<StyledMarkedText> coalesceAdjacentWithEqualForeground(const Vector<StyledMarkedText>&);
static Vector<StyledMarkedText> coalesceAdjacentWithEqualDecorations(const Vector<StyledMarkedText>&);
static Style computeStyleForUnmarkedMarkedText(const RenderText&, const RenderStyle&, bool isFirstLine, const PaintInfo&);
};

}
@@ -171,7 +171,29 @@ void TextBoxPainter::paintBackground()

void TextBoxPainter::paintForegroundAndDecorations()
{
bool shouldPaintSelectionForeground = m_haveSelection && !m_useCustomUnderlines;
auto shouldPaintSelectionForeground = m_haveSelection && !m_useCustomUnderlines;
auto hasTextDecoration = !m_style.textDecorationsInEffect().isEmpty();
auto hasHighlightDecoration = m_document.hasHighlight() && !MarkedText::collectForHighlights(m_renderer, m_selectableRange, MarkedText::PaintPhase::Decoration).isEmpty();
auto hasDecoration = hasTextDecoration || hasHighlightDecoration;

auto contentMayNeedStyledMarkedText = [&] {
if (hasDecoration)
return true;
if (shouldPaintSelectionForeground)
return true;
if (m_document.markers().hasMarkers())
return true;
if (m_document.hasHighlight())
return true;
return false;
};
if (!contentMayNeedStyledMarkedText()) {
auto& lineStyle = m_isFirstLine ? m_renderer.firstLineStyle() : m_renderer.style();
paintForeground({ MarkedText { m_selectableRange.clamp(textBox().start()), m_selectableRange.clamp(textBox().end()), MarkedText::Unmarked },
StyledMarkedText::computeStyleForUnmarkedMarkedText(m_renderer, lineStyle, m_isFirstLine, m_paintInfo) });
return;
}

Vector<MarkedText> markedTexts;
if (m_paintInfo.phase != PaintPhase::Selection) {
// The marked texts for the gaps between document markers and selection are implicitly created by subdividing the entire line.
@@ -208,10 +230,7 @@ void TextBoxPainter::paintForegroundAndDecorations()
});
}

auto textDecorations = m_style.textDecorationsInEffect();
bool highlightDecorations = !MarkedText::collectForHighlights(m_renderer, m_selectableRange, MarkedText::PaintPhase::Decoration).isEmpty();
bool lineDecorations = !textDecorations.isEmpty();
if ((lineDecorations || highlightDecorations) && m_paintInfo.phase != PaintPhase::Selection) {
if (hasDecoration && m_paintInfo.phase != PaintPhase::Selection) {
TextRun textRun = textBox().createTextRun();
unsigned length = m_selectableRange.truncation.value_or(textRun.length());
unsigned selectionStart = 0;

0 comments on commit e1a113f

Please sign in to comment.