Title: [287936] trunk/Source/WebCore
Revision
287936
Author
wei...@apple.com
Date
2022-01-12 10:56:45 -0800 (Wed, 12 Jan 2022)

Log Message

Add some functions to Color to make debugging using color indicators easier
https://bugs.webkit.org/show_bug.cgi?id=234886

Reviewed by Darin Adler.

Add two helpers to Color to aid debugging, allowing easy access to components in simplified form.

* platform/graphics/Color.cpp:
(WebCore::Color::debugRGBA const):
(WebCore::Color::debugDescription const):
* platform/graphics/Color.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287935 => 287936)


--- trunk/Source/WebCore/ChangeLog	2022-01-12 18:55:06 UTC (rev 287935)
+++ trunk/Source/WebCore/ChangeLog	2022-01-12 18:56:45 UTC (rev 287936)
@@ -1,3 +1,17 @@
+2022-01-12  Sam Weinig  <wei...@apple.com>
+
+        Add some functions to Color to make debugging using color indicators easier
+        https://bugs.webkit.org/show_bug.cgi?id=234886
+
+        Reviewed by Darin Adler.
+
+        Add two helpers to Color to aid debugging, allowing easy access to components in simplified form.
+
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::debugRGBA const):
+        (WebCore::Color::debugDescription const):
+        * platform/graphics/Color.h:
+
 2022-01-12  Antoine Quint  <grao...@webkit.org>
 
         css/css-transitions/pseudo-elements-002.html WPT is a failure

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (287935 => 287936)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2022-01-12 18:55:06 UTC (rev 287935)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2022-01-12 18:56:45 UTC (rev 287936)
@@ -195,6 +195,17 @@
     });
 }
 
+Color::DebugRGBA Color::debugRGBA() const
+{
+    auto [r, g, b, a] = toColorTypeLossy<SRGBA<uint8_t>>().resolved();
+    return { r, g, b, a };
+}
+
+String Color::debugDescription() const
+{
+    return serializationForRenderTreeAsText(*this);
+}
+
 TextStream& operator<<(TextStream& ts, const Color& color)
 {
     return ts << serializationForRenderTreeAsText(color);

Modified: trunk/Source/WebCore/platform/graphics/Color.h (287935 => 287936)


--- trunk/Source/WebCore/platform/graphics/Color.h	2022-01-12 18:55:06 UTC (rev 287935)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2022-01-12 18:56:45 UTC (rev 287936)
@@ -166,6 +166,17 @@
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static std::optional<Color> decode(Decoder&);
 
+    // Returns the underlying color converted to pre-resolved 8-bit sRGBA, useful for debugging purposes.
+    struct DebugRGBA {
+        unsigned red;
+        unsigned green;
+        unsigned blue;
+        unsigned alpha;
+    };
+    DebugRGBA debugRGBA() const;
+
+    String debugDescription() const;
+
 private:
     class OutOfLineComponents : public ThreadSafeRefCounted<OutOfLineComponents> {
     public:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to