Title: [271232] trunk/Source/WebCore
Revision
271232
Author
[email protected]
Date
2021-01-07 02:05:19 -0800 (Thu, 07 Jan 2021)

Log Message

Only update the resources when rendering SVG selected text
https://bugs.webkit.org/show_bug.cgi?id=218486

Patch by Carlos Garcia Campos <[email protected]> on 2021-01-07
Reviewed by Ryosuke Niwa.

Instead of calling SVGResourcesCache::clientStyleChanged() that marks the renderer for layout and parent
resource invalidation, add a helper class SVGResourcesCache::SetStyleForScope() that just updates the resources
for the new style on construction and restores the previous one on destruction.

* rendering/svg/SVGInlineTextBox.cpp:
(WebCore::SVGInlineTextBox::paintText): Use SVGResourcesCache::SetStyleForScope().
* rendering/svg/SVGResourcesCache.cpp:
(WebCore::SVGResourcesCache::SetStyleForScope::SetStyleForScope): Call setStyle() with the new style.
(WebCore::SVGResourcesCache::SetStyleForScope::~SetStyleForScope): Call setStyle() with the previous style.
(WebCore::SVGResourcesCache::SetStyleForScope::setStyle): Set the given style if needed.
* rendering/svg/SVGResourcesCache.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271231 => 271232)


--- trunk/Source/WebCore/ChangeLog	2021-01-07 10:02:44 UTC (rev 271231)
+++ trunk/Source/WebCore/ChangeLog	2021-01-07 10:05:19 UTC (rev 271232)
@@ -1,5 +1,24 @@
 2021-01-07  Carlos Garcia Campos  <[email protected]>
 
+        Only update the resources when rendering SVG selected text
+        https://bugs.webkit.org/show_bug.cgi?id=218486
+
+        Reviewed by Ryosuke Niwa.
+
+        Instead of calling SVGResourcesCache::clientStyleChanged() that marks the renderer for layout and parent
+        resource invalidation, add a helper class SVGResourcesCache::SetStyleForScope() that just updates the resources
+        for the new style on construction and restores the previous one on destruction.
+
+        * rendering/svg/SVGInlineTextBox.cpp:
+        (WebCore::SVGInlineTextBox::paintText): Use SVGResourcesCache::SetStyleForScope().
+        * rendering/svg/SVGResourcesCache.cpp:
+        (WebCore::SVGResourcesCache::SetStyleForScope::SetStyleForScope): Call setStyle() with the new style.
+        (WebCore::SVGResourcesCache::SetStyleForScope::~SetStyleForScope): Call setStyle() with the previous style.
+        (WebCore::SVGResourcesCache::SetStyleForScope::setStyle): Set the given style if needed.
+        * rendering/svg/SVGResourcesCache.h:
+
+2021-01-07  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Build failures with GTK4 3.99.5.1
         https://bugs.webkit.org/show_bug.cgi?id=219844
 

Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (271231 => 271232)


--- trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2021-01-07 10:02:44 UTC (rev 271231)
+++ trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2021-01-07 10:05:19 UTC (rev 271232)
@@ -602,14 +602,11 @@
         paintTextWithShadows(context, style, textRun, fragment, 0, startPosition);
 
     // Draw text using selection style from the start to the end position of the selection
-    if (style != selectionStyle)
-        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifference::Repaint, selectionStyle);
+    {
+        SVGResourcesCache::SetStyleForScope temporaryStyleChange(parent()->renderer(), style, selectionStyle);
+        paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
+    }
 
-    paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
-
-    if (style != selectionStyle)
-        SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifference::Repaint, style);
-
     // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
     if (endPosition < fragment.length && !paintSelectedTextOnly)
         paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length);

Modified: trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp (271231 => 271232)


--- trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp	2021-01-07 10:02:44 UTC (rev 271231)
+++ trunk/Source/WebCore/rendering/svg/SVGResourcesCache.cpp	2021-01-07 10:05:19 UTC (rev 271232)
@@ -169,4 +169,27 @@
     }
 }
 
+SVGResourcesCache::SetStyleForScope::SetStyleForScope(RenderElement& renderer, const RenderStyle& scopedStyle, const RenderStyle& newStyle)
+    : m_renderer(renderer)
+    , m_scopedStyle(scopedStyle)
+    , m_needsNewStyle(scopedStyle != newStyle && rendererCanHaveResources(renderer))
+{
+    setStyle(newStyle);
 }
+
+SVGResourcesCache::SetStyleForScope::~SetStyleForScope()
+{
+    setStyle(m_scopedStyle);
+}
+
+void SVGResourcesCache::SetStyleForScope::setStyle(const RenderStyle& style)
+{
+    if (!m_needsNewStyle)
+        return;
+
+    auto& cache = resourcesCacheFromRenderer(m_renderer);
+    cache.removeResourcesFromRenderer(m_renderer);
+    cache.addResourcesFromRenderer(m_renderer, style);
+}
+
+}

Modified: trunk/Source/WebCore/rendering/svg/SVGResourcesCache.h (271231 => 271232)


--- trunk/Source/WebCore/rendering/svg/SVGResourcesCache.h	2021-01-07 10:02:44 UTC (rev 271231)
+++ trunk/Source/WebCore/rendering/svg/SVGResourcesCache.h	2021-01-07 10:05:19 UTC (rev 271232)
@@ -58,6 +58,19 @@
     // Called from RenderSVGResourceContainer::willBeDestroyed().
     static void resourceDestroyed(RenderSVGResourceContainer&);
 
+    class SetStyleForScope {
+        WTF_MAKE_NONCOPYABLE(SetStyleForScope);
+    public:
+        SetStyleForScope(RenderElement&, const RenderStyle& scopedStyle, const RenderStyle& newStyle);
+        ~SetStyleForScope();
+    private:
+        void setStyle(const RenderStyle&);
+
+        RenderElement& m_renderer;
+        const RenderStyle& m_scopedStyle;
+        bool m_needsNewStyle { false };
+    };
+
 private:
     void addResourcesFromRenderer(RenderElement&, const RenderStyle&);
     void removeResourcesFromRenderer(RenderElement&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to