Title: [261636] trunk/Source/WebCore
Revision
261636
Author
[email protected]
Date
2020-05-13 12:24:01 -0700 (Wed, 13 May 2020)

Log Message

[Wheel event region] Debug overlay
https://bugs.webkit.org/show_bug.cgi?id=211850

Reviewed by Simon Fraser.

This is tied to the existing Wheel event handler overlay debug flag.

* platform/graphics/Color.cpp:
(WebCore::makeRGB): Deleted.
(WebCore::makeRGBA): Deleted.
* platform/graphics/Color.h:
(WebCore::makeRGB):
(WebCore::makeRGBA):

Make constexpr.

* rendering/EventRegion.cpp:
(WebCore::EventRegion::eventListenerRegionForType const):
* rendering/EventRegion.h:
* rendering/RenderLayerBacking.cpp:
(WebCore::patternForDescription):

Factor into a function.

(WebCore::patternForTouchAction):
(WebCore::patternForEventListenerRegionType):
(WebCore::RenderLayerBacking::paintDebugOverlays):
(WebCore::RenderLayerBacking::paintContents):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (261635 => 261636)


--- trunk/Source/WebCore/ChangeLog	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/ChangeLog	2020-05-13 19:24:01 UTC (rev 261636)
@@ -1,3 +1,34 @@
+2020-05-13  Antti Koivisto  <[email protected]>
+
+        [Wheel event region] Debug overlay
+        https://bugs.webkit.org/show_bug.cgi?id=211850
+
+        Reviewed by Simon Fraser.
+
+        This is tied to the existing Wheel event handler overlay debug flag.
+
+        * platform/graphics/Color.cpp:
+        (WebCore::makeRGB): Deleted.
+        (WebCore::makeRGBA): Deleted.
+        * platform/graphics/Color.h:
+        (WebCore::makeRGB):
+        (WebCore::makeRGBA):
+
+        Make constexpr.
+
+        * rendering/EventRegion.cpp:
+        (WebCore::EventRegion::eventListenerRegionForType const):
+        * rendering/EventRegion.h:
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::patternForDescription):
+
+        Factor into a function.
+
+        (WebCore::patternForTouchAction):
+        (WebCore::patternForEventListenerRegionType):
+        (WebCore::RenderLayerBacking::paintDebugOverlays):
+        (WebCore::RenderLayerBacking::paintContents):
+
 2020-05-13  Antoine Quint  <[email protected]>
 
         [Web Animations] Fix refactoring issue with animation suspension following r261336

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (261635 => 261636)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2020-05-13 19:24:01 UTC (rev 261636)
@@ -50,16 +50,6 @@
     return (fastMultiplyBy255(c) + a - 1) / a;
 }
 
-RGBA32 makeRGB(int r, int g, int b)
-{
-    return makeRGBA(r, g, b, 0xFF);
-}
-
-RGBA32 makeRGBA(int r, int g, int b, int a)
-{
-    return { static_cast<unsigned>(std::max(0, std::min(a, 0xFF)) << 24 | std::max(0, std::min(r, 0xFF)) << 16 | std::max(0, std::min(g, 0xFF)) << 8 | std::max(0, std::min(b, 0xFF))) };
-}
-
 RGBA32 makePremultipliedRGBA(int r, int g, int b, int a, bool ceiling)
 {
     return makeRGBA(premultipliedChannel(r, a, ceiling), premultipliedChannel(g, a, ceiling), premultipliedChannel(b, a, ceiling), a);

Modified: trunk/Source/WebCore/platform/graphics/Color.h (261635 => 261636)


--- trunk/Source/WebCore/platform/graphics/Color.h	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2020-05-13 19:24:01 UTC (rev 261636)
@@ -84,8 +84,8 @@
 // FIXME: Remove this after migrating to the new name.
 using RGBA32 = SimpleColor;
 
-WEBCORE_EXPORT RGBA32 makeRGB(int r, int g, int b);
-WEBCORE_EXPORT RGBA32 makeRGBA(int r, int g, int b, int a);
+constexpr RGBA32 makeRGB(int r, int g, int b);
+constexpr RGBA32 makeRGBA(int r, int g, int b, int a);
 
 RGBA32 makePremultipliedRGBA(int r, int g, int b, int a, bool ceiling = true);
 RGBA32 makeUnPremultipliedRGBA(int r, int g, int b, int a);
@@ -418,6 +418,16 @@
     return color.rgb() == Color::white;
 }
 
+constexpr RGBA32 makeRGB(int r, int g, int b)
+{
+    return makeRGBA(r, g, b, 0xFF);
+}
+
+constexpr RGBA32 makeRGBA(int r, int g, int b, int a)
+{
+    return { static_cast<unsigned>(std::max(0, std::min(a, 0xFF)) << 24 | std::max(0, std::min(r, 0xFF)) << 16 | std::max(0, std::min(g, 0xFF)) << 8 | std::max(0, std::min(b, 0xFF))) };
+}
+
 } // namespace WebCore
 
 namespace WTF {

Modified: trunk/Source/WebCore/rendering/EventRegion.cpp (261635 => 261636)


--- trunk/Source/WebCore/rendering/EventRegion.cpp	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/rendering/EventRegion.cpp	2020-05-13 19:24:01 UTC (rev 261636)
@@ -240,6 +240,18 @@
     return regionTypes;
 }
 
+const Region& EventRegion::eventListenerRegionForType(EventListenerRegionType type) const
+{
+    switch (type) {
+    case EventListenerRegionType::Wheel:
+        return m_wheelEventListenerRegion;
+    case EventListenerRegionType::NonPassiveWheel:
+        return m_nonPassiveWheelEventListenerRegion;
+    }
+    ASSERT_NOT_REACHED();
+    return m_wheelEventListenerRegion;
+}
+
 #if ENABLE(EDITABLE_REGION)
 
 bool EventRegion::containsEditableElementsInRect(const IntRect& rect) const

Modified: trunk/Source/WebCore/rendering/EventRegion.h (261635 => 261636)


--- trunk/Source/WebCore/rendering/EventRegion.h	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/rendering/EventRegion.h	2020-05-13 19:24:01 UTC (rev 261636)
@@ -80,6 +80,7 @@
     const Region* regionForTouchAction(TouchAction) const;
 
     OptionSet<EventListenerRegionType> eventListenerRegionTypesForPoint(const IntPoint&) const;
+    const Region& eventListenerRegionForType(EventListenerRegionType) const;
 
 #if ENABLE(EDITABLE_REGION)
     WEBCORE_EXPORT bool containsEditableElementsInRect(const IntRect&) const;

Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (261635 => 261636)


--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2020-05-13 19:18:23 UTC (rev 261635)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp	2020-05-13 19:24:01 UTC (rev 261636)
@@ -3081,44 +3081,14 @@
     return paintFlags;
 }
 
-static RefPtr<Pattern> patternForTouchAction(TouchAction touchAction, FloatSize contentOffset, GraphicsContext& destContext)
+struct PatternDescription {
+    ASCIILiteral name;
+    FloatSize phase;
+    RGBA32 fillColor;
+};
+
+static RefPtr<Pattern> patternForDescription(PatternDescription description, FloatSize contentOffset, GraphicsContext& destContext)
 {
-    auto toIndex = [](TouchAction touchAction) -> unsigned {
-        switch (touchAction) {
-        case TouchAction::None:
-            return 1;
-        case TouchAction::Manipulation:
-            return 2;
-        case TouchAction::PanX:
-            return 3;
-        case TouchAction::PanY:
-            return 4;
-        case TouchAction::PinchZoom:
-            return 5;
-        case TouchAction::Auto:
-            break;
-        }
-        return 0;
-    };
-
-    struct TouchActionAndRGB {
-        TouchAction action;
-        ASCIILiteral name;
-        FloatSize phase;
-    };
-    static const TouchActionAndRGB actionsAndColors[] = {
-        { TouchAction::Auto, "auto"_s, { } },
-        { TouchAction::None, "none"_s, { } },
-        { TouchAction::Manipulation, "manip"_s, { } },
-        { TouchAction::PanX, "pan-x"_s, { } },
-        { TouchAction::PanY, "pan-y"_s, { 0, 9 } },
-        { TouchAction::PinchZoom, "p-z"_s, { 16, 4.5 } },
-    };
-    
-    auto actionIndex = toIndex(touchAction);
-    if (!actionIndex || actionIndex >= ARRAY_SIZE(actionsAndColors))
-        return nullptr;
-
     const FloatSize tileSize { 32, 18 };
 
     auto imageBuffer = ImageBuffer::createCompatibleBuffer(tileSize, ColorSpace::SRGB, destContext);
@@ -3125,7 +3095,6 @@
     if (!imageBuffer)
         return nullptr;
 
-    const auto& touchActionData = actionsAndColors[actionIndex];
     {
         GraphicsContext& imageContext = imageBuffer->context();
 
@@ -3137,8 +3106,8 @@
         FontCascade font(WTFMove(fontDescription), 0, 0);
         font.update(nullptr);
 
-        TextRun textRun = TextRun(touchActionData.name);
-        imageContext.setFillColor(Color(0, 0, 0, 128));
+        TextRun textRun = TextRun(description.name);
+        imageContext.setFillColor(description.fillColor);
 
         constexpr float textGap = 4;
         constexpr float yOffset = 12;
@@ -3148,13 +3117,69 @@
     auto tileImage = ImageBuffer::sinkIntoImage(WTFMove(imageBuffer));
     auto fillPattern = Pattern::create(tileImage.releaseNonNull(), true, true);
     AffineTransform patternOffsetTransform;
-    patternOffsetTransform.translate(contentOffset + touchActionData.phase);
+    patternOffsetTransform.translate(contentOffset + description.phase);
     patternOffsetTransform.scale(1 / destContext.scaleFactor());
     fillPattern->setPatternSpaceTransform(patternOffsetTransform);
 
     return fillPattern;
+};
+
+static RefPtr<Pattern> patternForTouchAction(TouchAction touchAction, FloatSize contentOffset, GraphicsContext& destContext)
+{
+    auto toIndex = [](TouchAction touchAction) -> unsigned {
+        switch (touchAction) {
+        case TouchAction::None:
+            return 1;
+        case TouchAction::Manipulation:
+            return 2;
+        case TouchAction::PanX:
+            return 3;
+        case TouchAction::PanY:
+            return 4;
+        case TouchAction::PinchZoom:
+            return 5;
+        case TouchAction::Auto:
+            break;
+        }
+        return 0;
+    };
+
+    constexpr auto fillColor = makeRGBA(0, 0, 0, 128);
+
+    static const PatternDescription patternDescriptions[] = {
+        { "auto"_s, { }, fillColor },
+        { "none"_s, { }, fillColor },
+        { "manip"_s, { }, fillColor },
+        { "pan-x"_s, { }, fillColor },
+        { "pan-y"_s, { 0, 9 }, fillColor },
+        { "p-z"_s, { 16, 4.5 }, fillColor },
+    };
+    
+    auto actionIndex = toIndex(touchAction);
+    if (!actionIndex || actionIndex >= ARRAY_SIZE(patternDescriptions))
+        return nullptr;
+
+    return patternForDescription(patternDescriptions[actionIndex], contentOffset, destContext);
 }
 
+static RefPtr<Pattern> patternForEventListenerRegionType(EventListenerRegionType type, FloatSize contentOffset, GraphicsContext& destContext)
+{
+    constexpr auto fillColor = makeRGBA(0, 128, 0, 128);
+
+    auto patternAndPhase = [&]() -> PatternDescription {
+        switch (type) {
+        case EventListenerRegionType::Wheel:
+            return { "wheel"_s, { }, fillColor };
+        case EventListenerRegionType::NonPassiveWheel:
+            return { "sync"_s, { 0, 9 }, fillColor };
+        }
+        ASSERT_NOT_REACHED();
+        return { ""_s, { }, fillColor };
+    }();
+
+    return patternForDescription(patternAndPhase, contentOffset, destContext);
+}
+
 void RenderLayerBacking::paintDebugOverlays(const GraphicsLayer* graphicsLayer, GraphicsContext& context)
 {
     auto& eventRegion = graphicsLayer->eventRegion();
@@ -3200,6 +3225,17 @@
         }
     }
 
+    if (visibleDebugOverlayRegions & WheelEventHandlerRegion) {
+        for (auto type : { EventListenerRegionType::Wheel, EventListenerRegionType::NonPassiveWheel }) {
+            auto fillPattern = patternForEventListenerRegionType(type, contentOffsetInCompositingLayer(), context);
+            context.setFillPattern(fillPattern.releaseNonNull());
+
+            auto& region = graphicsLayer->eventRegion().eventListenerRegionForType(type);
+            for (auto rect : region.rects())
+                context.fillRect(rect);
+        }
+    }
+
 #if ENABLE(EDITABLE_REGION)
     // Paint rects for editable elements.
     if (visibleDebugOverlayRegions & EditableElementRegion) {
@@ -3249,7 +3285,7 @@
 
         paintIntoLayer(graphicsLayer, context, dirtyRect, behavior);
 
-        if (renderer().settings().visibleDebugOverlayRegions() & (TouchActionRegion | EditableElementRegion))
+        if (renderer().settings().visibleDebugOverlayRegions() & (TouchActionRegion | EditableElementRegion | WheelEventHandlerRegion))
             paintDebugOverlays(graphicsLayer, context);
 
     } else if (graphicsLayer == layerForHorizontalScrollbar()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to