Add logging for RenderLayer clip rects
https://bugs.webkit.org/show_bug.cgi?id=197547

Reviewed by Zalan Bujtas.

Add a ClipRects log channel, and stream output for ClipRect and ClipRects.

The ClipRect code is performance sensitive, even in debug, so guard the log sites
with clipRectsLogEnabled() because the macro still evaluates its arguments even if
the channel is disabled (we need some better way to log that doesn't do this).

* platform/Logging.h:
* rendering/ClipRect.cpp:
(WebCore::operator<<):
* rendering/ClipRect.h:
* rendering/RenderLayer.cpp:
(WebCore::operator<<):
(WebCore::RenderLayer::calculateClipRects const):
* rendering/RenderLayer.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245219 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index e4b808b..9271c0a 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2019-05-02  Simon Fraser  <simon.fraser@apple.com>
+
+        Add logging for RenderLayer clip rects
+        https://bugs.webkit.org/show_bug.cgi?id=197547
+
+        Reviewed by Zalan Bujtas.
+
+        Add a ClipRects log channel, and stream output for ClipRect and ClipRects.
+
+        The ClipRect code is performance sensitive, even in debug, so guard the log sites
+        with clipRectsLogEnabled() because the macro still evaluates its arguments even if
+        the channel is disabled (we need some better way to log that doesn't do this).
+
+        * platform/Logging.h:
+        * rendering/ClipRect.cpp:
+        (WebCore::operator<<):
+        * rendering/ClipRect.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::operator<<):
+        (WebCore::RenderLayer::calculateClipRects const):
+        * rendering/RenderLayer.h:
+
 2019-05-12  Simon Fraser  <simon.fraser@apple.com>
 
         Refactor composited backing-sharing code
diff --git a/Source/WebCore/platform/Logging.h b/Source/WebCore/platform/Logging.h
index 0171229..e120a29 100644
--- a/Source/WebCore/platform/Logging.h
+++ b/Source/WebCore/platform/Logging.h
@@ -42,6 +42,7 @@
     M(Animations) \
     M(ApplePay) \
     M(Archives) \
+    M(ClipRects) \
     M(Compositing) \
     M(ContentFiltering) \
     M(ContentObservation) \
diff --git a/Source/WebCore/rendering/ClipRect.cpp b/Source/WebCore/rendering/ClipRect.cpp
index b4db563..3630d16 100644
--- a/Source/WebCore/rendering/ClipRect.cpp
+++ b/Source/WebCore/rendering/ClipRect.cpp
@@ -38,4 +38,17 @@
     return hitTestLocation.intersects(m_rect);
 }
 
+TextStream& operator<<(TextStream& ts, const ClipRect& clipRect)
+{
+    ts << "rect ";
+    if (clipRect.isInfinite())
+        ts << "infinite";
+    else
+        ts << clipRect.rect();
+
+    if (clipRect.affectedByRadius())
+        ts << " affected by radius";
+    return ts;
+}
+
 }
diff --git a/Source/WebCore/rendering/ClipRect.h b/Source/WebCore/rendering/ClipRect.h
index 5ed7a6c..52abb67 100644
--- a/Source/WebCore/rendering/ClipRect.h
+++ b/Source/WebCore/rendering/ClipRect.h
@@ -27,6 +27,10 @@
 
 #include "LayoutRect.h"
 
+namespace WTF {
+class TextStream;
+}
+
 namespace WebCore {
 
 class HitTestLocation;
@@ -103,4 +107,6 @@
     return c;
 }
 
+WTF::TextStream& operator<<(WTF::TextStream&, const ClipRect&);
+
 } // namespace WebCore
diff --git a/Source/WebCore/rendering/RenderLayer.cpp b/Source/WebCore/rendering/RenderLayer.cpp
index 7aa11aa..7a1dc38 100644
--- a/Source/WebCore/rendering/RenderLayer.cpp
+++ b/Source/WebCore/rendering/RenderLayer.cpp
@@ -268,6 +268,24 @@
 #endif
 }
 
+#if !LOG_DISABLED
+static TextStream& operator<<(TextStream& ts, const ClipRects& clipRects)
+{
+    TextStream::GroupScope scope(ts);
+    ts << indent << "ClipRects\n";
+    ts << indent << "  overflow  : " << clipRects.overflowClipRect() << "\n";
+    ts << indent << "  fixed     : " << clipRects.fixedClipRect() << "\n";
+    ts << indent << "  positioned: " << clipRects.posClipRect() << "\n";
+
+    return ts;
+}
+
+static bool clipRectsLogEnabled()
+{
+    return LogClipRects.state == WTFLogChannelState::On;
+}
+#endif
+
 RenderLayer::RenderLayer(RenderLayerModelObject& rendererLayerModelObject)
     : m_isRenderViewLayer(rendererLayerModelObject.isRenderView())
     , m_forcedStackingContext(rendererLayerModelObject.isMedia())
@@ -5602,6 +5620,11 @@
             clipRects.setFixedClipRect(intersection(newPosClip, clipRects.fixedClipRect()));
         }
     }
+
+#if !LOG_DISABLED
+    if (clipRectsLogEnabled())
+        LOG_WITH_STREAM(ClipRects, stream << "RenderLayer " << this << " calculateClipRects " << clipRects);
+#endif
 }
 
 Ref<ClipRects> RenderLayer::parentClipRects(const ClipRectsContext& clipRectsContext) const
@@ -5646,6 +5669,11 @@
     // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite.
     if (parentRects->fixed() && &clipRectsContext.rootLayer->renderer() == &view && !backgroundClipRect.isInfinite())
         backgroundClipRect.moveBy(view.frameView().scrollPositionForFixedPosition());
+
+#if !LOG_DISABLED
+    if (clipRectsLogEnabled())
+        LOG_WITH_STREAM(ClipRects, stream << "RenderLayer " << this << " backgroundClipRect with context " << clipRectsContext << " returning " << backgroundClipRect);
+#endif
     return backgroundClipRect;
 }
 
@@ -6808,6 +6836,21 @@
 #endif
 }
 
+TextStream& operator<<(WTF::TextStream& ts, ClipRectsType clipRectsType)
+{
+    switch (clipRectsType) {
+    case PaintingClipRects: ts << "painting"; break;
+    case RootRelativeClipRects: ts << "root-relative"; break;
+    case AbsoluteClipRects: ts << "absolute"; break;
+    case TemporaryClipRects: ts << "temporary"; break;
+    case NumCachedClipRectsTypes:
+    case AllClipRectTypes:
+        ts << "?";
+        break;
+    }
+    return ts;
+}
+
 TextStream& operator<<(TextStream& ts, const RenderLayer& layer)
 {
     ts << "RenderLayer " << &layer << " " << layer.size();
@@ -6826,6 +6869,15 @@
     return ts;
 }
 
+TextStream& operator<<(TextStream& ts, const RenderLayer::ClipRectsContext& context)
+{
+    ts.dumpProperty("root layer:", context.rootLayer);
+    ts.dumpProperty("type:", context.clipRectsType);
+    ts.dumpProperty("overflow-clip:", context.respectOverflowClip == IgnoreOverflowClip ? "ignore" : "respect");
+    
+    return ts;
+}
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)
diff --git a/Source/WebCore/rendering/RenderLayer.h b/Source/WebCore/rendering/RenderLayer.h
index 22be9bc..e519f4f 100644
--- a/Source/WebCore/rendering/RenderLayer.h
+++ b/Source/WebCore/rendering/RenderLayer.h
@@ -1384,7 +1384,9 @@
 
 bool compositedWithOwnBackingStore(const RenderLayer&);
 
+WTF::TextStream& operator<<(WTF::TextStream&, ClipRectsType);
 WTF::TextStream& operator<<(WTF::TextStream&, const RenderLayer&);
+WTF::TextStream& operator<<(WTF::TextStream&, const RenderLayer::ClipRectsContext&);
 
 } // namespace WebCore