Title: [294099] trunk/Source/WebCore
Revision
294099
Author
za...@apple.com
Date
2022-05-12 06:12:22 -0700 (Thu, 12 May 2022)

Log Message

TextBoxPainter::paintBackground should bail out early when nothing to paint
https://bugs.webkit.org/show_bug.cgi?id=240317

Reviewed by Simon Fraser.

Collecting markers and highlights is a somewhat expensive operation while most
of the time the text has neither markers nor highlights. Let's just bail out early when applicable.

* dom/Document.h:
(WebCore::Document::hasHighlightRegister const):
* rendering/TextBoxPainter.cpp:
(WebCore::TextBoxPainter::paintBackground):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (294098 => 294099)


--- trunk/Source/WebCore/ChangeLog	2022-05-12 12:40:27 UTC (rev 294098)
+++ trunk/Source/WebCore/ChangeLog	2022-05-12 13:12:22 UTC (rev 294099)
@@ -1,3 +1,18 @@
+2022-05-12  Alan Bujtas  <za...@apple.com>
+
+        TextBoxPainter::paintBackground should bail out early when nothing to paint
+        https://bugs.webkit.org/show_bug.cgi?id=240317
+
+        Reviewed by Simon Fraser.
+
+        Collecting markers and highlights is a somewhat expensive operation while most
+        of the time the text has neither markers nor highlights. Let's just bail out early when applicable.
+
+        * dom/Document.h:
+        (WebCore::Document::hasHighlightRegister const):
+        * rendering/TextBoxPainter.cpp:
+        (WebCore::TextBoxPainter::paintBackground):
+
 2022-05-12  Tim Nguyen  <n...@apple.com>
 
         [:has() pseudo-class] Support invalidation for :target pseudo-class

Modified: trunk/Source/WebCore/Modules/highlight/HighlightRegister.h (294098 => 294099)


--- trunk/Source/WebCore/Modules/highlight/HighlightRegister.h	2022-05-12 12:40:27 UTC (rev 294098)
+++ trunk/Source/WebCore/Modules/highlight/HighlightRegister.h	2022-05-12 13:12:22 UTC (rev 294099)
@@ -45,7 +45,7 @@
     void setFromMapLike(AtomString&&, Ref<Highlight>&&);
     void clear();
     bool remove(const AtomString&);
-    
+    bool isEmpty() const { return map().isEmpty(); }    
 
     HighlightVisibility highlightsVisibility() const { return m_highlightVisibility; }
 #if ENABLE(APP_HIGHLIGHTS)

Modified: trunk/Source/WebCore/dom/Document.cpp (294098 => 294099)


--- trunk/Source/WebCore/dom/Document.cpp	2022-05-12 12:40:27 UTC (rev 294098)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-05-12 13:12:22 UTC (rev 294099)
@@ -2886,6 +2886,16 @@
     return XMLDocumentParser::create(*this, view());
 }
 
+bool Document::hasHighlight() const
+{
+    return (m_highlightRegister && !m_highlightRegister->isEmpty())
+        || (m_fragmentHighlightRegister && !m_fragmentHighlightRegister->isEmpty()) 
+#if ENABLE(APP_HIGHLIGHTS)
+        || (m_appHighlightRegister && !m_appHighlightRegister->isEmpty())
+#endif
+    ;
+}
+
 HighlightRegister& Document::highlightRegister()
 {
     if (!m_highlightRegister)

Modified: trunk/Source/WebCore/dom/Document.h (294098 => 294099)


--- trunk/Source/WebCore/dom/Document.h	2022-05-12 12:40:27 UTC (rev 294098)
+++ trunk/Source/WebCore/dom/Document.h	2022-05-12 13:12:22 UTC (rev 294099)
@@ -1630,6 +1630,7 @@
     WEBCORE_EXPORT TextManipulationController& textManipulationController();
     TextManipulationController* textManipulationControllerIfExists() { return m_textManipulationController.get(); }
 
+    bool hasHighlight() const;
     HighlightRegister* highlightRegisterIfExists() { return m_highlightRegister.get(); }
     HighlightRegister& highlightRegister();
     void updateHighlightPositions();

Modified: trunk/Source/WebCore/rendering/TextBoxPainter.cpp (294098 => 294099)


--- trunk/Source/WebCore/rendering/TextBoxPainter.cpp	2022-05-12 12:40:27 UTC (rev 294098)
+++ trunk/Source/WebCore/rendering/TextBoxPainter.cpp	2022-05-12 13:12:22 UTC (rev 294099)
@@ -26,6 +26,7 @@
 #include "TextBoxPainter.h"
 
 #include "CompositionHighlight.h"
+#include "DocumentMarkerController.h"
 #include "Editor.h"
 #include "EventRegion.h"
 #include "GraphicsContext.h"
@@ -124,7 +125,28 @@
 
 void TextBoxPainter::paintBackground()
 {
-    if (m_containsComposition && !m_useCustomUnderlines)
+    auto shouldPaintCompositionBackground = m_containsComposition && !m_useCustomUnderlines;
+#if ENABLE(TEXT_SELECTION)
+    auto hasSelectionWithNonCustomUnderline = m_haveSelection && !m_useCustomUnderlines;
+#endif
+
+    auto shouldPaintBackground = [&] {
+#if ENABLE(TEXT_SELECTION)
+        if (hasSelectionWithNonCustomUnderline)
+            return true;
+#endif
+        if (shouldPaintCompositionBackground)
+            return true;
+        if (m_document.markers().hasMarkers())
+            return true;
+        if (m_document.hasHighlight())
+            return true;
+        return false;
+    };
+    if (!shouldPaintBackground())
+        return;
+
+    if (shouldPaintCompositionBackground)
         paintCompositionBackground();
 
     Vector<MarkedText> markedTexts;
@@ -132,7 +154,7 @@
     markedTexts.appendVector(MarkedText::collectForHighlights(m_renderer, m_selectableRange, MarkedText::PaintPhase::Background));
 
 #if ENABLE(TEXT_SELECTION)
-    if (m_haveSelection && !m_useCustomUnderlines && !m_paintInfo.context().paintingDisabled()) {
+    if (hasSelectionWithNonCustomUnderline && !m_paintInfo.context().paintingDisabled()) {
         auto selectionMarkedText = createMarkedTextFromSelectionInBox();
         if (!selectionMarkedText.isEmpty())
             markedTexts.append(WTFMove(selectionMarkedText));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to