Finish encoding/decoding support for DisplayList::SetState
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Dec 2019 22:53:28 +0000 (22:53 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Dec 2019 22:53:28 +0000 (22:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=205018

Reviewed by Tim Horton.

Source/WebCore:

Finishes encoding and decoding support for the `SetState` display list item. See below for more details.

* platform/graphics/Gradient.h:
(WebCore::Gradient::ColorStop::encode const):
(WebCore::Gradient::ColorStop::decode):
(WebCore::Gradient::LinearData::encode const):
(WebCore::Gradient::LinearData::decode):
(WebCore::Gradient::RadialData::encode const):
(WebCore::Gradient::RadialData::decode):
(WebCore::Gradient::ConicData::encode const):
(WebCore::Gradient::ConicData::decode):
(WebCore::Gradient::encode const):
(WebCore::Gradient::decode):

Introduce encoding and decoding support for WebCore::Gradient, and all of its constituent data members.

* platform/graphics/GraphicsContext.h:

Remove ShadowColorChange, which was unused; instead, shadow color changes are indicated by the ShadowChange
flag, which also encompasses shadow offset and blur.

* platform/graphics/Image.h:

Move DisplayList::ImageHandle to ImageHandle in Image.h, so that it can be referenced in the encode/decode
methods of WebCore::Pattern.

* platform/graphics/Pattern.h:
(WebCore::Pattern::encode const):
(WebCore::Pattern::decode):

Introduce encoding and decoding support for WebCore::Pattern.

* platform/graphics/displaylists/DisplayListItems.cpp:
(WebCore::DisplayList::FillRectWithGradient::FillRectWithGradient):

Implement encode and decode for FillRectWithGradient, now that we're able to encode and decode Gradients.

* platform/graphics/displaylists/DisplayListItems.h:
(WebCore::DisplayList::SetState::encode const):
(WebCore::DisplayList::SetState::decode):

Encode the remaining data members of a GraphicsContextStateChange's state. These are: strokeGradient,
strokePattern, fillGradient, fillPattern, shadowOffset, shadowBlur, shadowColor (which was not previously being
encoded due to ShadowColorChange never being set), strokeThickness, textDrawingMode, strokeStyle, fillRule,
compositeOperator, blendMode, imageInterpolationQuality, shouldAntialias, shouldSmoothFonts,
shouldSubpixelQuantizeFonts and shadowsIgnoreTransforms.

(WebCore::DisplayList::FillRectWithGradient::encode const):
(WebCore::DisplayList::FillRectWithGradient::decode):
(WebCore::DisplayList::Item::encode const):
(WebCore::DisplayList::Item::decode):
(WebCore::DisplayList::FillRectWithGradient::FillRectWithGradient): Deleted.

Source/WebKit:

Replaces WebCore::DisplayList::ImageHandle with just WebCore::ImageHandle. See WebCore ChangeLog for more
details.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<ImageHandle>::encode):
(IPC::ArgumentCoder<ImageHandle>::decode):
(IPC::ArgumentCoder<DisplayList::ImageHandle>::encode): Deleted.
(IPC::ArgumentCoder<DisplayList::ImageHandle>::decode): Deleted.
* Shared/WebCoreArgumentCoders.h:

LayoutTests:

Rebaseline several display list layout tests.

* displaylists/layer-dispay-list-expected.txt:
* platform/mac-wk1/displaylists/extent-includes-shadow-expected.txt:
* platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253302 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/displaylists/layer-dispay-list-expected.txt
LayoutTests/platform/mac-wk1/displaylists/extent-includes-shadow-expected.txt
LayoutTests/platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Gradient.h
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/Pattern.h
Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp
Source/WebCore/platform/graphics/displaylists/DisplayListItems.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h

index 4de4b0ca96fc8fecd5a793ceb2583faa5e1276b6..ab10390a6576c39b5fc6007202f11eb85d1bce20 100644 (file)
@@ -1,3 +1,16 @@
+2019-12-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Finish encoding/decoding support for DisplayList::SetState
+        https://bugs.webkit.org/show_bug.cgi?id=205018
+
+        Reviewed by Tim Horton.
+
+        Rebaseline several display list layout tests.
+
+        * displaylists/layer-dispay-list-expected.txt:
+        * platform/mac-wk1/displaylists/extent-includes-shadow-expected.txt:
+        * platform/mac-wk1/displaylists/extent-includes-transforms-expected.txt:
+
 2019-12-09  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Throttling requestAnimationFrame should be controlled by RenderingUpdateScheduler
index c5f6ac6b25a987fb04eee9a11910bef61f731a33..bf3d8525d1f2c49853d00c870a2caa08f8d6f164 100644 (file)
@@ -9,7 +9,7 @@
   (composite-operation source-over)
   (blend-mode normal))
 (set-state
-  (change-flags 131456)
+  (change-flags 65920)
   (fill-color #0000FF)
   (stroke-style 0)
   (should-antialias 0))
index 210e44b0877c040ca852420dd97b42c0eac176c5..1a3e7238bba2b720279016ebea6c3e4f4938e34d 100644 (file)
@@ -5,7 +5,7 @@
 (save
   (restore-index 4))
 (set-state
-  (change-flags 525312)
+  (change-flags 263168)
   (shadow-blur 12.00)
   (shadow-offset width=10 height=20)
   (shadows-use-legacy-radius 0)
index 384e98129dc7ebcdd896d310fa8c75d3653abb7f..5ee136cd8bfa3002a3432380fbf1eeecf91100cf 100644 (file)
@@ -7,7 +7,7 @@
 (save
   (restore-index 5))
 (set-state
-  (change-flags 525312)
+  (change-flags 263168)
   (shadow-blur 12.00)
   (shadow-offset width=10 height=20)
   (shadows-use-legacy-radius 0)
index 39a8225285aa62d2701d192006b15bff234edc38..6ad8b44bea7d382362f58d605690321c1c289778 100644 (file)
@@ -1,3 +1,63 @@
+2019-12-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Finish encoding/decoding support for DisplayList::SetState
+        https://bugs.webkit.org/show_bug.cgi?id=205018
+
+        Reviewed by Tim Horton.
+
+        Finishes encoding and decoding support for the `SetState` display list item. See below for more details.
+
+        * platform/graphics/Gradient.h:
+        (WebCore::Gradient::ColorStop::encode const):
+        (WebCore::Gradient::ColorStop::decode):
+        (WebCore::Gradient::LinearData::encode const):
+        (WebCore::Gradient::LinearData::decode):
+        (WebCore::Gradient::RadialData::encode const):
+        (WebCore::Gradient::RadialData::decode):
+        (WebCore::Gradient::ConicData::encode const):
+        (WebCore::Gradient::ConicData::decode):
+        (WebCore::Gradient::encode const):
+        (WebCore::Gradient::decode):
+
+        Introduce encoding and decoding support for WebCore::Gradient, and all of its constituent data members.
+
+        * platform/graphics/GraphicsContext.h:
+
+        Remove ShadowColorChange, which was unused; instead, shadow color changes are indicated by the ShadowChange
+        flag, which also encompasses shadow offset and blur.
+
+        * platform/graphics/Image.h:
+
+        Move DisplayList::ImageHandle to ImageHandle in Image.h, so that it can be referenced in the encode/decode
+        methods of WebCore::Pattern.
+
+        * platform/graphics/Pattern.h:
+        (WebCore::Pattern::encode const):
+        (WebCore::Pattern::decode):
+
+        Introduce encoding and decoding support for WebCore::Pattern.
+
+        * platform/graphics/displaylists/DisplayListItems.cpp:
+        (WebCore::DisplayList::FillRectWithGradient::FillRectWithGradient):
+
+        Implement encode and decode for FillRectWithGradient, now that we're able to encode and decode Gradients.
+
+        * platform/graphics/displaylists/DisplayListItems.h:
+        (WebCore::DisplayList::SetState::encode const):
+        (WebCore::DisplayList::SetState::decode):
+
+        Encode the remaining data members of a GraphicsContextStateChange's state. These are: strokeGradient,
+        strokePattern, fillGradient, fillPattern, shadowOffset, shadowBlur, shadowColor (which was not previously being
+        encoded due to ShadowColorChange never being set), strokeThickness, textDrawingMode, strokeStyle, fillRule,
+        compositeOperator, blendMode, imageInterpolationQuality, shouldAntialias, shouldSmoothFonts,
+        shouldSubpixelQuantizeFonts and shadowsIgnoreTransforms.
+
+        (WebCore::DisplayList::FillRectWithGradient::encode const):
+        (WebCore::DisplayList::FillRectWithGradient::decode):
+        (WebCore::DisplayList::Item::encode const):
+        (WebCore::DisplayList::Item::decode):
+        (WebCore::DisplayList::FillRectWithGradient::FillRectWithGradient): Deleted.
+
 2019-12-09  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Add support for word-break: break-word (and overflow-wrap)
index 5a869b9d65d981c34924095058232a3c30fd238f..75cdef9fe16e242295913d155606a285ac95ff9e 100644 (file)
@@ -31,6 +31,7 @@
 #include "Color.h"
 #include "FloatPoint.h"
 #include "GraphicsTypes.h"
+#include <wtf/EnumTraits.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Variant.h>
 #include <wtf/Vector.h>
@@ -69,6 +70,9 @@ public:
             , color(color)
         {
         }
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<ColorStop> decode(Decoder&);
     };
 
     using ColorStopVector = Vector<ColorStop, 2>;
@@ -76,6 +80,9 @@ public:
     struct LinearData {
         FloatPoint point0;
         FloatPoint point1;
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<LinearData> decode(Decoder&);
     };
 
     struct RadialData {
@@ -84,24 +91,30 @@ public:
         float startRadius;
         float endRadius;
         float aspectRatio; // For elliptical gradient, width / height.
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<RadialData> decode(Decoder&);
     };
     
     struct ConicData {
         FloatPoint point0;
         float angleRadians;
+
+        template<class Encoder> void encode(Encoder&) const;
+        template<class Decoder> static Optional<ConicData> decode(Decoder&);
     };
 
     using Data = Variant<LinearData, RadialData, ConicData>;
 
     enum class Type { Linear, Radial, Conic };
 
-    static Ref<Gradient> create(LinearData&&);
-    static Ref<Gradient> create(RadialData&&);
-    static Ref<Gradient> create(ConicData&&);
+    WEBCORE_EXPORT static Ref<Gradient> create(LinearData&&);
+    WEBCORE_EXPORT static Ref<Gradient> create(RadialData&&);
+    WEBCORE_EXPORT static Ref<Gradient> create(ConicData&&);
 
     WEBCORE_EXPORT ~Gradient();
 
-    Type type() const;
+    WEBCORE_EXPORT Type type() const;
 
     bool hasAlpha() const;
     bool isZeroSize() const;
@@ -110,15 +123,15 @@ public:
 
     WEBCORE_EXPORT void addColorStop(const ColorStop&);
     WEBCORE_EXPORT void addColorStop(float, const Color&);
-    void setSortedColorStops(ColorStopVector&&);
+    WEBCORE_EXPORT void setSortedColorStops(ColorStopVector&&);
 
     const ColorStopVector& stops() const { return m_stops; }
 
-    void setSpreadMethod(GradientSpreadMethod);
+    WEBCORE_EXPORT void setSpreadMethod(GradientSpreadMethod);
     GradientSpreadMethod spreadMethod() const { return m_spreadMethod; }
 
     // CG needs to transform the gradient at draw time.
-    void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
+    WEBCORE_EXPORT void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransformation);
     const AffineTransform& gradientSpaceTransform() const { return m_gradientSpaceTransformation; }
 
     void fill(GraphicsContext&, const FloatRect&);
@@ -136,6 +149,9 @@ public:
     PlatformGradient createPlatformGradient(float globalAlpha);
 #endif
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<Ref<Gradient>> decode(Decoder&);
+
 private:
     Gradient(LinearData&&);
     Gradient(RadialData&&);
@@ -163,4 +179,225 @@ private:
     PlatformGradient m_gradient;
 };
 
+template<class Encoder>
+void Gradient::ColorStop::encode(Encoder& encoder) const
+{
+    encoder << offset;
+    encoder << color;
+}
+
+template<class Decoder>
+Optional<Gradient::ColorStop> Gradient::ColorStop::decode(Decoder& decoder)
+{
+    Optional<float> offset;
+    decoder >> offset;
+    if (!offset)
+        return WTF::nullopt;
+
+    Optional<Color> color;
+    decoder >> color;
+    if (!color)
+        return WTF::nullopt;
+
+    return {{ *offset, *color }};
+}
+
+template<class Encoder>
+void Gradient::LinearData::encode(Encoder& encoder) const
+{
+    encoder << point0;
+    encoder << point1;
+}
+
+template<class Decoder>
+Optional<Gradient::LinearData> Gradient::LinearData::decode(Decoder& decoder)
+{
+    Optional<FloatPoint> point0;
+    decoder >> point0;
+    if (!point0)
+        return WTF::nullopt;
+
+    Optional<FloatPoint> point1;
+    decoder >> point1;
+    if (!point1)
+        return WTF::nullopt;
+
+    return {{ *point0, *point1 }};
+}
+
+template<class Encoder>
+void Gradient::RadialData::encode(Encoder& encoder) const
+{
+    encoder << point0;
+    encoder << point1;
+    encoder << startRadius;
+    encoder << endRadius;
+    encoder << aspectRatio;
 }
+
+template<class Decoder>
+Optional<Gradient::RadialData> Gradient::RadialData::decode(Decoder& decoder)
+{
+    Optional<FloatPoint> point0;
+    decoder >> point0;
+    if (!point0)
+        return WTF::nullopt;
+
+    Optional<FloatPoint> point1;
+    decoder >> point1;
+    if (!point1)
+        return WTF::nullopt;
+
+    Optional<float> startRadius;
+    decoder >> startRadius;
+    if (!startRadius)
+        return WTF::nullopt;
+
+    Optional<float> endRadius;
+    decoder >> endRadius;
+    if (!endRadius)
+        return WTF::nullopt;
+
+    Optional<float> aspectRatio;
+    decoder >> aspectRatio;
+    if (!aspectRatio)
+        return WTF::nullopt;
+
+    return {{ *point0, *point1, *startRadius, *endRadius, *aspectRatio }};
+}
+
+template<class Encoder>
+void Gradient::ConicData::encode(Encoder& encoder) const
+{
+    encoder << point0;
+    encoder << angleRadians;
+}
+
+template<class Decoder>
+Optional<Gradient::ConicData> Gradient::ConicData::decode(Decoder& decoder)
+{
+    Optional<FloatPoint> point0;
+    decoder >> point0;
+    if (!point0)
+        return WTF::nullopt;
+
+    Optional<float> angleRadians;
+    decoder >> angleRadians;
+    if (!angleRadians)
+        return WTF::nullopt;
+
+    return {{ *point0, *angleRadians }};
+}
+
+template<class Encoder>
+void Gradient::encode(Encoder& encoder) const
+{
+    auto type = this->type();
+    encoder << type;
+    switch (type) {
+    case Type::Linear:
+        encoder << WTF::get<Gradient::LinearData>(m_data);
+        break;
+    case Type::Radial:
+        encoder << WTF::get<Gradient::RadialData>(m_data);
+        break;
+    case Type::Conic:
+        encoder << WTF::get<Gradient::ConicData>(m_data);
+        break;
+    }
+    encoder << m_stops;
+    encoder << m_stopsSorted;
+    encoder.encodeEnum(m_spreadMethod);
+    encoder << m_gradientSpaceTransformation;
+}
+
+template<class Decoder>
+Optional<Ref<Gradient>> Gradient::decode(Decoder& decoder)
+{
+    Optional<Gradient::Type> type;
+    decoder >> type;
+    if (!type)
+        return WTF::nullopt;
+
+    RefPtr<Gradient> gradient;
+    switch (*type) {
+    case Type::Linear: {
+        Optional<LinearData> linearData;
+        decoder >> linearData;
+        if (!linearData)
+            return WTF::nullopt;
+
+        gradient = Gradient::create(WTFMove(*linearData));
+        break;
+    }
+    case Type::Radial: {
+        Optional<RadialData> radialData;
+        decoder >> radialData;
+        if (!radialData)
+            return WTF::nullopt;
+
+        gradient = Gradient::create(WTFMove(*radialData));
+        break;
+    }
+    case Type::Conic: {
+        Optional<ConicData> conicData;
+        decoder >> conicData;
+        if (!conicData)
+            return WTF::nullopt;
+
+        gradient = Gradient::create(WTFMove(*conicData));
+        break;
+    }
+    }
+
+    if (!gradient) {
+        ASSERT_NOT_REACHED();
+        return WTF::nullopt;
+    }
+
+    Optional<ColorStopVector> stops;
+    decoder >> stops;
+    if (!stops)
+        return WTF::nullopt;
+
+    Optional<bool> stopsSorted;
+    decoder >> stopsSorted;
+    if (!stopsSorted.hasValue())
+        return WTF::nullopt;
+
+    if (stopsSorted.value())
+        gradient->setSortedColorStops(WTFMove(*stops));
+    else {
+        for (auto& stop : *stops)
+            gradient->addColorStop(stop);
+    }
+
+    GradientSpreadMethod spreadMethod;
+    if (!decoder.decodeEnum(spreadMethod))
+        return WTF::nullopt;
+
+    gradient->setSpreadMethod(spreadMethod);
+
+    Optional<AffineTransform> gradientSpaceTransformation;
+    decoder >> gradientSpaceTransformation;
+    if (!gradientSpaceTransformation)
+        return WTF::nullopt;
+
+    gradient->setGradientSpaceTransform(WTFMove(*gradientSpaceTransformation));
+    return gradient.releaseNonNull();
+}
+
+} // namespace WebCore
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::Gradient::Type> {
+    using values = EnumValues<
+    WebCore::Gradient::Type,
+    WebCore::Gradient::Type::Linear,
+    WebCore::Gradient::Type::Radial,
+    WebCore::Gradient::Type::Conic
+    >;
+};
+
+} // namespace WTF
index 2f3a06d3cae3d90ae76e7218f77bb7ad0cc9b497..2107cbb08428799abde3fdc648129eaad804976a 100644 (file)
@@ -182,19 +182,18 @@ struct GraphicsContextState {
         FillColorChange                         = 1 << 8,
         FillRuleChange                          = 1 << 9,
         ShadowChange                            = 1 << 10,
-        ShadowColorChange                       = 1 << 11,
-        ShadowsIgnoreTransformsChange           = 1 << 12,
-        AlphaChange                             = 1 << 13,
-        CompositeOperationChange                = 1 << 14,
-        BlendModeChange                         = 1 << 15,
-        TextDrawingModeChange                   = 1 << 16,
-        ShouldAntialiasChange                   = 1 << 17,
-        ShouldSmoothFontsChange                 = 1 << 18,
-        ShouldSubpixelQuantizeFontsChange       = 1 << 19,
-        DrawLuminanceMaskChange                 = 1 << 20,
-        ImageInterpolationQualityChange         = 1 << 21,
+        ShadowsIgnoreTransformsChange           = 1 << 11,
+        AlphaChange                             = 1 << 12,
+        CompositeOperationChange                = 1 << 13,
+        BlendModeChange                         = 1 << 14,
+        TextDrawingModeChange                   = 1 << 15,
+        ShouldAntialiasChange                   = 1 << 16,
+        ShouldSmoothFontsChange                 = 1 << 17,
+        ShouldSubpixelQuantizeFontsChange       = 1 << 18,
+        DrawLuminanceMaskChange                 = 1 << 19,
+        ImageInterpolationQualityChange         = 1 << 20,
 #if HAVE(OS_DARK_MODE_SUPPORT)
-        UseDarkAppearanceChange                 = 1 << 22,
+        UseDarkAppearanceChange                 = 1 << 21,
 #endif
     };
     typedef OptionSet<Change> StateChangeFlags;
index 3722c226e00eb50ffe4ee6dd8721e5a3b21f49c0..e304894791169730535206e204cd25d7455ea5a2 100644 (file)
@@ -199,6 +199,11 @@ private:
     std::unique_ptr<Timer> m_animationStartTimer;
 };
 
+class ImageHandle {
+public:
+    RefPtr<Image> image;
+};
+
 WTF::TextStream& operator<<(WTF::TextStream&, const Image&);
 
 } // namespace WebCore
index 007e5902d9596bb657ebcf98a9e3a61555ca9859..547972e2da95684529faa4a271450cc6330c9b96 100644 (file)
@@ -54,10 +54,11 @@ namespace WebCore {
 class AffineTransform;
 class GraphicsContext;
 class Image;
+class ImageHandle;
 
 class Pattern final : public RefCounted<Pattern> {
 public:
-    static Ref<Pattern> create(Ref<Image>&& tileImage, bool repeatX, bool repeatY);
+    WEBCORE_EXPORT static Ref<Pattern> create(Ref<Image>&& tileImage, bool repeatX, bool repeatY);
     WEBCORE_EXPORT ~Pattern();
 
     Image& tileImage() const { return m_tileImage.get(); }
@@ -68,11 +69,14 @@ public:
 #else
     PlatformPatternPtr createPlatformPattern(const GraphicsContext&, float alpha, const AffineTransform& userSpaceTransformation) const;
 #endif
-    void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
+    WEBCORE_EXPORT void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
     const AffineTransform& patternSpaceTransform() const { return m_patternSpaceTransformation; };
     bool repeatX() const { return m_repeatX; }
     bool repeatY() const { return m_repeatY; }
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<Ref<Pattern>> decode(Decoder&);
+
 private:
     Pattern(Ref<Image>&&, bool repeatX, bool repeatY);
 
@@ -82,5 +86,44 @@ private:
     bool m_repeatY;
 };
 
+template<class Encoder>
+void Pattern::encode(Encoder& encoder) const
+{
+    ImageHandle imageHandle;
+    imageHandle.image = m_tileImage.ptr();
+    encoder << imageHandle;
+    encoder << m_patternSpaceTransformation;
+    encoder << m_repeatX;
+    encoder << m_repeatY;
+}
+
+template<class Decoder>
+Optional<Ref<Pattern>> Pattern::decode(Decoder& decoder)
+{
+    Optional<ImageHandle> imageHandle;
+    decoder >> imageHandle;
+    if (!imageHandle)
+        return WTF::nullopt;
+
+    Optional<AffineTransform> patternSpaceTransformation;
+    decoder >> patternSpaceTransformation;
+    if (!patternSpaceTransformation)
+        return WTF::nullopt;
+
+    Optional<bool> repeatX;
+    decoder >> repeatX;
+    if (!repeatX)
+        return WTF::nullopt;
+
+    Optional<bool> repeatY;
+    decoder >> repeatY;
+    if (!repeatY)
+        return WTF::nullopt;
+
+    auto pattern = Pattern::create(imageHandle->image.releaseNonNull(), *repeatX, *repeatY);
+    pattern->setPatternSpaceTransform(*patternSpaceTransformation);
+    return pattern;
+}
+
 } //namespace
 
index fad74779658da823a70a8fdee8777052fc3a3c35..7803f16209215a9790cc53c969634d3ab3756472 100644 (file)
@@ -979,6 +979,15 @@ static TextStream& operator<<(TextStream& ts, const FillRectWithColor& item)
     return ts;
 }
 
+FillRectWithGradient::FillRectWithGradient(const FloatRect& rect, Gradient& gradient)
+    : DrawingItem(ItemType::FillRectWithGradient)
+    , m_rect(rect)
+    , m_gradient(gradient)
+{
+}
+
+FillRectWithGradient::~FillRectWithGradient() = default;
+
 void FillRectWithGradient::apply(GraphicsContext& context) const
 {
     context.fillRect(m_rect, m_gradient.get());
index 9cb6386f726485c6cf90a0d0e9df0ec95b7f23f5..75ac26b8908c8b04dcbe8c12cd7462bf87442e01 100644 (file)
@@ -32,6 +32,7 @@
 #include "GlyphBuffer.h"
 #include "GraphicsContext.h"
 #include "Image.h"
+#include "Pattern.h"
 #include <wtf/RefCounted.h>
 #include <wtf/TypeCasts.h>
 
@@ -452,18 +453,85 @@ private:
 template<class Encoder>
 void SetState::encode(Encoder& encoder) const
 {
-    encoder << m_state.m_changeFlags;
+    auto changeFlags = m_state.m_changeFlags;
+    encoder << changeFlags;
 
-    // FIXME: Encode the other state changes.
+    auto& state = m_state.m_state;
 
-    if (m_state.m_changeFlags.contains(GraphicsContextState::StrokeColorChange))
-        encoder << m_state.m_state.strokeColor;
+    if (changeFlags.contains(GraphicsContextState::StrokeGradientChange)) {
+        encoder << !!state.strokeGradient;
+        if (state.strokeGradient)
+            encoder << *state.strokeGradient;
+    }
+
+    if (changeFlags.contains(GraphicsContextState::StrokePatternChange)) {
+        encoder << !!state.strokePattern;
+        if (state.strokePattern)
+            encoder << *state.strokePattern;
+    }
+
+    if (changeFlags.contains(GraphicsContextState::FillGradientChange)) {
+        encoder << !!state.fillGradient;
+        if (state.fillGradient)
+            encoder << *state.fillGradient;
+    }
+
+    if (changeFlags.contains(GraphicsContextState::FillPatternChange)) {
+        encoder << !!state.fillPattern;
+        if (state.fillPattern)
+            encoder << *state.fillPattern;
+    }
+
+    if (changeFlags.contains(GraphicsContextState::ShadowChange)) {
+        encoder << state.shadowOffset;
+        encoder << state.shadowBlur;
+        encoder << state.shadowColor;
+#if USE(CG)
+        encoder << state.shadowsUseLegacyRadius;
+#endif // USE(CG)
+    }
+
+    if (changeFlags.contains(GraphicsContextState::StrokeThicknessChange))
+        encoder << state.strokeThickness;
+
+    if (changeFlags.contains(GraphicsContextState::TextDrawingModeChange))
+        encoder.encodeEnum(state.textDrawingMode);
+
+    if (changeFlags.contains(GraphicsContextState::StrokeColorChange))
+        encoder << state.strokeColor;
+
+    if (changeFlags.contains(GraphicsContextState::FillColorChange))
+        encoder << state.fillColor;
+
+    if (changeFlags.contains(GraphicsContextState::StrokeStyleChange))
+        encoder.encodeEnum(state.strokeStyle);
+
+    if (changeFlags.contains(GraphicsContextState::FillRuleChange))
+        encoder << state.fillRule;
+
+    if (changeFlags.contains(GraphicsContextState::CompositeOperationChange))
+        encoder << state.compositeOperator;
 
-    if (m_state.m_changeFlags.contains(GraphicsContextState::FillColorChange))
-        encoder << m_state.m_state.fillColor;
+    if (changeFlags.contains(GraphicsContextState::BlendModeChange))
+        encoder << state.blendMode;
 
-    if (m_state.m_changeFlags.contains(GraphicsContextState::AlphaChange))
-        encoder << m_state.m_state.alpha;
+    if (changeFlags.contains(GraphicsContextState::ImageInterpolationQualityChange))
+        encoder << state.imageInterpolationQuality;
+
+    if (changeFlags.contains(GraphicsContextState::AlphaChange))
+        encoder << state.alpha;
+
+    if (changeFlags.contains(GraphicsContextState::ShouldAntialiasChange))
+        encoder << state.shouldAntialias;
+
+    if (changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange))
+        encoder << state.shouldSmoothFonts;
+
+    if (changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
+        encoder << state.shouldSubpixelQuantizeFonts;
+
+    if (changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
+        encoder << state.shadowsIgnoreTransforms;
 }
 
 template<class Decoder>
@@ -477,6 +545,115 @@ Optional<Ref<SetState>> SetState::decode(Decoder& decoder)
     GraphicsContextStateChange stateChange;
     stateChange.m_changeFlags = *changeFlags;
 
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::StrokeGradientChange)) {
+        Optional<bool> hasStrokeGradient;
+        decoder >> hasStrokeGradient;
+        if (!hasStrokeGradient.hasValue())
+            return WTF::nullopt;
+
+        if (hasStrokeGradient.value()) {
+            auto strokeGradient = Gradient::decode(decoder);
+            if (!strokeGradient)
+                return WTF::nullopt;
+
+            stateChange.m_state.strokeGradient = WTFMove(*strokeGradient);
+        }
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::StrokePatternChange)) {
+        Optional<bool> hasStrokePattern;
+        decoder >> hasStrokePattern;
+        if (!hasStrokePattern.hasValue())
+            return WTF::nullopt;
+
+        if (hasStrokePattern.value()) {
+            auto strokePattern = Pattern::decode(decoder);
+            if (!strokePattern)
+                return WTF::nullopt;
+
+            stateChange.m_state.strokePattern = WTFMove(*strokePattern);
+        }
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::FillGradientChange)) {
+        Optional<bool> hasFillGradient;
+        decoder >> hasFillGradient;
+        if (!hasFillGradient.hasValue())
+            return WTF::nullopt;
+
+        if (hasFillGradient.value()) {
+            auto fillGradient = Gradient::decode(decoder);
+            if (!fillGradient)
+                return WTF::nullopt;
+
+            stateChange.m_state.fillGradient = WTFMove(*fillGradient);
+        }
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::FillPatternChange)) {
+        Optional<bool> hasFillPattern;
+        decoder >> hasFillPattern;
+        if (!hasFillPattern.hasValue())
+            return WTF::nullopt;
+
+        if (hasFillPattern.value()) {
+            auto fillPattern = Pattern::decode(decoder);
+            if (!fillPattern)
+                return WTF::nullopt;
+
+            stateChange.m_state.fillPattern = WTFMove(*fillPattern);
+        }
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ShadowChange)) {
+        Optional<FloatSize> shadowOffset;
+        decoder >> shadowOffset;
+        if (!shadowOffset)
+            return WTF::nullopt;
+
+        stateChange.m_state.shadowOffset = *shadowOffset;
+
+        Optional<float> shadowBlur;
+        decoder >> shadowBlur;
+        if (!shadowBlur)
+            return WTF::nullopt;
+
+        stateChange.m_state.shadowBlur = *shadowBlur;
+
+        Optional<Color> shadowColor;
+        decoder >> shadowColor;
+        if (!shadowColor)
+            return WTF::nullopt;
+
+        stateChange.m_state.shadowColor = *shadowColor;
+
+#if USE(CG)
+        Optional<bool> shadowsUseLegacyRadius;
+        decoder >> shadowsUseLegacyRadius;
+        if (!shadowsUseLegacyRadius)
+            return WTF::nullopt;
+
+        stateChange.m_state.shadowsUseLegacyRadius = *shadowsUseLegacyRadius;
+#endif // USE(CG)
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::StrokeThicknessChange)) {
+        Optional<float> strokeThickness;
+        decoder >> strokeThickness;
+        if (!strokeThickness)
+            return WTF::nullopt;
+
+        stateChange.m_state.strokeThickness = *strokeThickness;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::TextDrawingModeChange)) {
+        TextDrawingModeFlags textDrawingMode;
+        if (!decoder.decodeEnum(textDrawingMode))
+            return WTF::nullopt;
+
+        stateChange.m_state.textDrawingMode = textDrawingMode;
+    }
+
     if (stateChange.m_changeFlags.contains(GraphicsContextState::StrokeColorChange)) {
         Optional<Color> strokeColor;
         decoder >> strokeColor;
@@ -495,6 +672,50 @@ Optional<Ref<SetState>> SetState::decode(Decoder& decoder)
         stateChange.m_state.fillColor = *fillColor;
     }
 
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::StrokeStyleChange)) {
+        StrokeStyle strokeStyle;
+        if (!decoder.decodeEnum(strokeStyle))
+            return WTF::nullopt;
+
+        stateChange.m_state.strokeStyle = strokeStyle;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::FillRuleChange)) {
+        Optional<WindRule> fillRule;
+        decoder >> fillRule;
+        if (!fillRule)
+            return WTF::nullopt;
+
+        stateChange.m_state.fillRule = *fillRule;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::CompositeOperationChange)) {
+        Optional<CompositeOperator> compositeOperator;
+        decoder >> compositeOperator;
+        if (!compositeOperator)
+            return WTF::nullopt;
+
+        stateChange.m_state.compositeOperator = *compositeOperator;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::BlendModeChange)) {
+        Optional<BlendMode> blendMode;
+        decoder >> blendMode;
+        if (!blendMode)
+            return WTF::nullopt;
+
+        stateChange.m_state.blendMode = *blendMode;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ImageInterpolationQualityChange)) {
+        Optional<InterpolationQuality> imageInterpolationQuality;
+        decoder >> imageInterpolationQuality;
+        if (!imageInterpolationQuality)
+            return WTF::nullopt;
+
+        stateChange.m_state.imageInterpolationQuality = *imageInterpolationQuality;
+    }
+
     if (stateChange.m_changeFlags.contains(GraphicsContextState::AlphaChange)) {
         Optional<float> alpha;
         decoder >> alpha;
@@ -504,6 +725,42 @@ Optional<Ref<SetState>> SetState::decode(Decoder& decoder)
         stateChange.m_state.alpha = *alpha;
     }
 
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ShouldAntialiasChange)) {
+        Optional<bool> shouldAntialias;
+        decoder >> shouldAntialias;
+        if (!shouldAntialias)
+            return WTF::nullopt;
+
+        stateChange.m_state.shouldAntialias = *shouldAntialias;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange)) {
+        Optional<bool> shouldSmoothFonts;
+        decoder >> shouldSmoothFonts;
+        if (!shouldSmoothFonts)
+            return WTF::nullopt;
+
+        stateChange.m_state.shouldSmoothFonts = *shouldSmoothFonts;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange)) {
+        Optional<bool> shouldSubpixelQuantizeFonts;
+        decoder >> shouldSubpixelQuantizeFonts;
+        if (!shouldSubpixelQuantizeFonts)
+            return WTF::nullopt;
+
+        stateChange.m_state.shouldSubpixelQuantizeFonts = *shouldSubpixelQuantizeFonts;
+    }
+
+    if (stateChange.m_changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange)) {
+        Optional<bool> shadowsIgnoreTransforms;
+        decoder >> shadowsIgnoreTransforms;
+        if (!shadowsIgnoreTransforms)
+            return WTF::nullopt;
+
+        stateChange.m_state.shadowsIgnoreTransforms = *shadowsIgnoreTransforms;
+    }
+
     return SetState::create(stateChange);
 }
 
@@ -930,11 +1187,6 @@ private:
     ImagePaintingOptions m_imagePaintingOptions;
 };
 
-class ImageHandle {
-public:
-    RefPtr<Image> image;
-};
-
 template<class Encoder>
 void DrawImage::encode(Encoder& encoder) const
 {
@@ -1862,15 +2114,15 @@ public:
         return adoptRef(*new FillRectWithGradient(rect, gradient));
     }
 
+    WEBCORE_EXPORT virtual ~FillRectWithGradient();
+
     FloatRect rect() const { return m_rect; }
 
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<Ref<FillRectWithGradient>> decode(Decoder&);
+
 private:
-    FillRectWithGradient(const FloatRect& rect, Gradient& gradient)
-        : DrawingItem(ItemType::FillRectWithGradient)
-        , m_rect(rect)
-        , m_gradient(gradient)
-    {
-    }
+    WEBCORE_EXPORT FillRectWithGradient(const FloatRect&, Gradient&);
 
     void apply(GraphicsContext&) const override;
     Optional<FloatRect> localBounds(const GraphicsContext&) const override { return m_rect; }
@@ -1879,6 +2131,28 @@ private:
     mutable Ref<Gradient> m_gradient; // FIXME: Make this not mutable
 };
 
+template<class Encoder>
+void FillRectWithGradient::encode(Encoder& encoder) const
+{
+    encoder << m_rect;
+    encoder << m_gradient.get();
+}
+
+template<class Decoder>
+Optional<Ref<FillRectWithGradient>> FillRectWithGradient::decode(Decoder& decoder)
+{
+    Optional<FloatRect> rect;
+    decoder >> rect;
+    if (!rect)
+        return WTF::nullopt;
+
+    auto gradient = Gradient::decode(decoder);
+    if (!gradient)
+        return WTF::nullopt;
+
+    return FillRectWithGradient::create(*rect, gradient->get());
+}
+
 class FillCompositedRect : public DrawingItem {
 public:
     static Ref<FillCompositedRect> create(const FloatRect& rect, const Color& color, CompositeOperator op, BlendMode blendMode)
@@ -2511,7 +2785,7 @@ void Item::encode(Encoder& encoder) const
         encoder << downcast<FillRectWithColor>(*this);
         break;
     case ItemType::FillRectWithGradient:
-        WTFLogAlways("DisplayList::Item::encode cannot yet encode FillRectWithGradient");
+        encoder << downcast<FillRectWithGradient>(*this);
         break;
     case ItemType::FillCompositedRect:
         encoder << downcast<FillCompositedRect>(*this);
@@ -2698,7 +2972,8 @@ Optional<Ref<Item>> Item::decode(Decoder& decoder)
             return static_reference_cast<Item>(WTFMove(*item));
         break;
     case ItemType::FillRectWithGradient:
-        WTFLogAlways("DisplayList::Item::decode cannot yet decode FillRectWithGradient");
+        if (auto item = FillRectWithGradient::decode(decoder))
+            return static_reference_cast<Item>(WTFMove(*item));
         break;
     case ItemType::FillCompositedRect:
         if (auto item = FillCompositedRect::decode(decoder))
index 9cbb72352b6c35fc3ac0fb94f5bf76dc0921cb8d..1d9df0bdab5d51ef593fae771da8dd8ba13eb6c0 100644 (file)
@@ -1,3 +1,20 @@
+2019-12-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Finish encoding/decoding support for DisplayList::SetState
+        https://bugs.webkit.org/show_bug.cgi?id=205018
+
+        Reviewed by Tim Horton.
+
+        Replaces WebCore::DisplayList::ImageHandle with just WebCore::ImageHandle. See WebCore ChangeLog for more
+        details.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<ImageHandle>::encode):
+        (IPC::ArgumentCoder<ImageHandle>::decode):
+        (IPC::ArgumentCoder<DisplayList::ImageHandle>::encode): Deleted.
+        (IPC::ArgumentCoder<DisplayList::ImageHandle>::decode): Deleted.
+        * Shared/WebCoreArgumentCoders.h:
+
 2019-12-09  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Throttling requestAnimationFrame should be controlled by RenderingUpdateScheduler
index 82be18fd79cfcab827978e1075aef1ae601ffd55..1a97ffad2f848d452e70f33f531b0157a16df7a1 100644 (file)
@@ -1028,12 +1028,12 @@ static bool decodeOptionalImage(Decoder& decoder, RefPtr<Image>& image)
     return decodeImage(decoder, image);
 }
 
-void ArgumentCoder<DisplayList::ImageHandle>::encode(Encoder& encoder, const DisplayList::ImageHandle& imageHandle)
+void ArgumentCoder<ImageHandle>::encode(Encoder& encoder, const ImageHandle& imageHandle)
 {
     encodeOptionalImage(encoder, imageHandle.image.get());
 }
 
-bool ArgumentCoder<DisplayList::ImageHandle>::decode(Decoder& decoder, DisplayList::ImageHandle& imageHandle)
+bool ArgumentCoder<ImageHandle>::decode(Decoder& decoder, ImageHandle& imageHandle)
 {
     if (!decodeOptionalImage(decoder, imageHandle.image))
         return false;
index f3e692f976fc93bb142a41484e5b2dc405bb30ad..5adfcfb6c233f4d9948a68a29273dbc762e4b93c 100644 (file)
@@ -81,6 +81,7 @@ class FloatRoundedRect;
 class FloatSize;
 class FixedPositionViewportConstraints;
 class HTTPHeaderMap;
+class ImageHandle;
 class IntPoint;
 class IntRect;
 class IntSize;
@@ -189,10 +190,6 @@ struct CacheInfo;
 struct Record;
 }
 
-namespace DisplayList {
-class ImageHandle;
-}
-
 } // namespace WebCore
 
 namespace IPC {
@@ -381,9 +378,9 @@ template<> struct ArgumentCoder<WebCore::Cursor> {
     static bool decode(Decoder&, WebCore::Cursor&);
 };
 
-template<> struct ArgumentCoder<WebCore::DisplayList::ImageHandle> {
-    static void encode(Encoder&, const WebCore::DisplayList::ImageHandle&);
-    static bool decode(Decoder&, WebCore::DisplayList::ImageHandle&);
+template<> struct ArgumentCoder<WebCore::ImageHandle> {
+    static void encode(Encoder&, const WebCore::ImageHandle&);
+    static bool decode(Decoder&, WebCore::ImageHandle&);
 };
 
 template<> struct ArgumentCoder<WebCore::ResourceRequest> {