Title: [278882] branches/safari-611-branch/Source/WebKit

Diff

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (278881 => 278882)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-06-15 18:01:04 UTC (rev 278881)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-06-15 18:09:19 UTC (rev 278882)
@@ -1,3 +1,52 @@
+2021-06-04  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r277536. rdar://problem/78875336
+
+    Replace PlatformCAAnimationRemote::KeyframeValue with Variant
+    https://bugs.webkit.org/show_bug.cgi?id=225474
+    
+    Patch by Ian Gilbert <i...@apple.com> on 2021-05-15
+    Reviewed by Ryosuke Niwa.
+    
+    KeyframeValue was effectively a Variant. Replaced the existing class with a WTF::Variant.
+    
+    No test as this does not change code behavior.
+    
+    * Shared/WebCoreArgumentCoders.cpp:
+    (IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::encode):
+    (IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::decode):
+    * Shared/WebCoreArgumentCoders.h:
+    * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:
+    * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
+    (WebKit::animationValueFromKeyframeValue):
+    (WebKit::operator<<):
+    (WebKit::PlatformCAAnimationRemote::KeyframeValue::encode const): Deleted.
+    (WebKit::PlatformCAAnimationRemote::KeyframeValue::decode): Deleted.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277536 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-05-15  Ian Gilbert  <i...@apple.com>
+
+            Replace PlatformCAAnimationRemote::KeyframeValue with Variant
+            https://bugs.webkit.org/show_bug.cgi?id=225474
+
+            Reviewed by Ryosuke Niwa.
+
+            KeyframeValue was effectively a Variant. Replaced the existing class with a WTF::Variant.
+
+            No test as this does not change code behavior.
+
+            * Shared/WebCoreArgumentCoders.cpp:
+            (IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::encode):
+            (IPC::ArgumentCoder<RefPtr<WebCore::FilterOperation>>::decode):
+            * Shared/WebCoreArgumentCoders.h:
+            * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:
+            * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
+            (WebKit::animationValueFromKeyframeValue):
+            (WebKit::operator<<):
+            (WebKit::PlatformCAAnimationRemote::KeyframeValue::encode const): Deleted.
+            (WebKit::PlatformCAAnimationRemote::KeyframeValue::decode): Deleted.
+
 2021-06-14  Russell Epstein  <repst...@apple.com>
 
         Apply patch. rdar://problem/77619702

Modified: branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (278881 => 278882)


--- branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-06-15 18:01:04 UTC (rev 278881)
+++ branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2021-06-15 18:09:19 UTC (rev 278882)
@@ -2346,6 +2346,28 @@
 
     return true;
 }
+
+void ArgumentCoder<RefPtr<WebCore::FilterOperation>>::encode(Encoder& encoder, const RefPtr<WebCore::FilterOperation>& operation)
+{
+    encoder << !!operation;
+    if (operation)
+        encoder << *operation;
+}
+
+WARN_UNUSED_RETURN bool ArgumentCoder<RefPtr<WebCore::FilterOperation>>::decode(Decoder& decoder, RefPtr<WebCore::FilterOperation>& value)
+{
+    Optional<bool> isNull;
+    decoder >> isNull;
+    if (!isNull)
+        return false;
+    
+    if (!decodeFilterOperation(decoder, value)) {
+        value = nullptr;
+        return false;
+    }
+    return true;
+}
+
 #endif // !USE(COORDINATED_GRAPHICS)
 
 void ArgumentCoder<BlobPart>::encode(Encoder& encoder, const BlobPart& blobPart)

Modified: branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.h (278881 => 278882)


--- branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-06-15 18:01:04 UTC (rev 278881)
+++ branches/safari-611-branch/Source/WebKit/Shared/WebCoreArgumentCoders.h	2021-06-15 18:09:19 UTC (rev 278882)
@@ -627,6 +627,11 @@
     static void encode(Encoder&, const WebCore::FilterOperation&);
 };
 WARN_UNUSED_RETURN bool decodeFilterOperation(Decoder&, RefPtr<WebCore::FilterOperation>&);
+
+template<> struct ArgumentCoder<RefPtr<WebCore::FilterOperation>> {
+    static void encode(Encoder&, const RefPtr<WebCore::FilterOperation>&);
+    static WARN_UNUSED_RETURN bool decode(Decoder&, RefPtr<WebCore::FilterOperation>&);
+};
 #endif
 
 template<> struct ArgumentCoder<WebCore::BlobPart> {

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h (278881 => 278882)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h	2021-06-15 18:01:04 UTC (rev 278881)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h	2021-06-15 18:09:19 UTC (rev 278882)
@@ -129,125 +129,9 @@
 
     void didStart(CFTimeInterval beginTime) { m_properties.beginTime = beginTime; }
 
-    class KeyframeValue {
-    public:
-        enum KeyframeType {
-            NumberKeyType,
-            ColorKeyType,
-            PointKeyType,
-            TransformKeyType,
-            FilterKeyType,
-        };
 
-        ~KeyframeValue()
-        {
-        }
+    using KeyframeValue = Variant<float, WebCore::Color, WebCore::FloatPoint3D, WebCore::TransformationMatrix, RefPtr<WebCore::FilterOperation>>;
 
-        KeyframeValue(float value = 0)
-            : keyType(NumberKeyType)
-            , number(value)
-        {
-        }
-
-        KeyframeValue(WebCore::Color value)
-            : keyType(ColorKeyType)
-            , color(value)
-        {
-        }
-
-        KeyframeValue(const WebCore::FloatPoint3D& value)
-            : keyType(PointKeyType)
-            , point(value)
-        {
-        }
-
-        KeyframeValue(const WebCore::TransformationMatrix& value)
-            : keyType(TransformKeyType)
-            , transform(value)
-        {
-        }
-
-        KeyframeValue(RefPtr<WebCore::FilterOperation>&& value)
-            : keyType(FilterKeyType)
-            , filter(WTFMove(value))
-        {
-        }
-
-        KeyframeValue(const KeyframeValue& other)
-        {
-            *this = other;
-        }
-
-        KeyframeValue& operator=(const KeyframeValue& other)
-        {
-            keyType = other.keyType;
-            switch (keyType) {
-            case NumberKeyType:
-                number = other.number;
-                break;
-            case ColorKeyType:
-                color = other.color;
-                break;
-            case PointKeyType:
-                point = other.point;
-                break;
-            case TransformKeyType:
-                transform = other.transform;
-                break;
-            case FilterKeyType:
-                filter = other.filter;
-                break;
-            }
-
-            return *this;
-        }
-
-        KeyframeType keyframeType() const { return keyType; }
-
-        float numberValue() const
-        {
-            ASSERT(keyType == NumberKeyType);
-            return number;
-        }
-
-        WebCore::Color colorValue() const
-        {
-            ASSERT(keyType == ColorKeyType);
-            return color;
-        }
-
-        const WebCore::FloatPoint3D& pointValue() const
-        {
-            ASSERT(keyType == PointKeyType);
-            return point;
-        }
-
-        const WebCore::TransformationMatrix& transformValue() const
-        {
-            ASSERT(keyType == TransformKeyType);
-            return transform;
-        }
-
-        const WebCore::FilterOperation* filterValue() const
-        {
-            ASSERT(keyType == FilterKeyType);
-            return filter.get();
-        }
-
-        void encode(IPC::Encoder&) const;
-        static Optional<KeyframeValue> decode(IPC::Decoder&);
-
-    private:
-        KeyframeType keyType;
-        union {
-            float number;
-            WebCore::Color color;
-            WebCore::FloatPoint3D point;
-            WebCore::TransformationMatrix transform;
-        };
-        RefPtr<WebCore::FilterOperation> filter;
-    };
-
     struct Properties {
         Properties()
             : animationType(Basic)
@@ -308,24 +192,8 @@
     Properties m_properties;
 };
 
-WTF::TextStream& operator<<(WTF::TextStream&, const PlatformCAAnimationRemote::KeyframeValue&);
 WTF::TextStream& operator<<(WTF::TextStream&, const PlatformCAAnimationRemote::Properties&);
 
 } // namespace WebKit
 
 SPECIALIZE_TYPE_TRAITS_CAANIMATION(WebKit::PlatformCAAnimationRemote, isPlatformCAAnimationRemote())
-
-namespace WTF {
-
-template<> struct EnumTraits<WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType> {
-    using values = EnumValues<
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType,
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType::NumberKeyType,
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType::ColorKeyType,
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType::PointKeyType,
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType::TransformKeyType,
-        WebKit::PlatformCAAnimationRemote::KeyframeValue::KeyframeType::FilterKeyType
-    >;
-};
-
-} // namespace WTF

Modified: branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm (278881 => 278882)


--- branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm	2021-06-15 18:01:04 UTC (rev 278881)
+++ branches/safari-611-branch/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm	2021-06-15 18:09:19 UTC (rev 278882)
@@ -98,61 +98,6 @@
 namespace WebKit {
 using namespace WebCore;
 
-void PlatformCAAnimationRemote::KeyframeValue::encode(IPC::Encoder& encoder) const
-{
-    encoder << keyType;
-
-    switch (keyType) {
-    case NumberKeyType:
-        encoder << number;
-        break;
-    case ColorKeyType:
-        encoder << color;
-        break;
-    case PointKeyType:
-        encoder << point;
-        break;
-    case TransformKeyType:
-        encoder << transform;
-        break;
-    case FilterKeyType:
-        encoder << *filter.get();
-        break;
-    }
-}
-
-Optional<PlatformCAAnimationRemote::KeyframeValue> PlatformCAAnimationRemote::KeyframeValue::decode(IPC::Decoder& decoder)
-{
-    PlatformCAAnimationRemote::KeyframeValue value;
-    if (!decoder.decode(value.keyType))
-        return WTF::nullopt;
-
-    switch (value.keyType) {
-    case NumberKeyType:
-        if (!decoder.decode(value.number))
-            return WTF::nullopt;
-        break;
-    case ColorKeyType:
-        if (!decoder.decode(value.color))
-            return WTF::nullopt;
-        break;
-    case PointKeyType:
-        if (!decoder.decode(value.point))
-            return WTF::nullopt;
-        break;
-    case TransformKeyType:
-        if (!decoder.decode(value.transform))
-            return WTF::nullopt;
-        break;
-    case FilterKeyType:
-        if (!decodeFilterOperation(decoder, value.filter))
-            return WTF::nullopt;
-        break;
-    }
-
-    return WTFMove(value);
-}
-
 static void encodeTimingFunction(IPC::Encoder& encoder, TimingFunction* timingFunction)
 {
     switch (timingFunction->type()) {
@@ -733,25 +678,22 @@
 
 static NSObject* animationValueFromKeyframeValue(const PlatformCAAnimationRemote::KeyframeValue& keyframeValue)
 {
-    switch (keyframeValue.keyframeType()) {
-    case PlatformCAAnimationRemote::KeyframeValue::NumberKeyType:
-        return @(keyframeValue.numberValue());
-            
-    case PlatformCAAnimationRemote::KeyframeValue::ColorKeyType: {
-        auto [r, g, b, a] = keyframeValue.colorValue().toSRGBALossy<uint8_t>();
-        return @[ @(r), @(g), @(b), @(a) ];
-    }
-
-    case PlatformCAAnimationRemote::KeyframeValue::PointKeyType: {
-        FloatPoint3D point = keyframeValue.pointValue();
-        return @[ @(point.x()), @(point.y()), @(point.z()) ];
-    }
-    case PlatformCAAnimationRemote::KeyframeValue::TransformKeyType:
-        return [NSValue valueWithCATransform3D:keyframeValue.transformValue()];
-            
-    case PlatformCAAnimationRemote::KeyframeValue::FilterKeyType:
-        return PlatformCAFilters::filterValueForOperation(keyframeValue.filterValue(), 0 /* unused */).autorelease();
-    }
+    return WTF::switchOn(keyframeValue,
+        [&](const float number) -> RetainPtr<NSObject> { return @(number); },
+        [&](const WebCore::Color color) -> RetainPtr<NSObject> {
+            auto [r, g, b, a] =  color.toSRGBALossy<uint8_t>();
+            return @[ @(r), @(g), @(b), @(a) ];
+        },
+        [&](const WebCore::FloatPoint3D point) -> RetainPtr<NSObject> {
+            return @[ @(point.x()), @(point.y()), @(point.z()) ];
+        },
+        [&](const WebCore::TransformationMatrix matrix) -> RetainPtr<NSObject> {
+            return [NSValue valueWithCATransform3D:matrix];
+        },
+        [&](const RefPtr<WebCore::FilterOperation> filter) -> RetainPtr<NSObject> {
+            return PlatformCAFilters::filterValueForOperation(filter.get(), 0 /* unused */);
+        }
+    );
 }
 
 static RetainPtr<CAAnimation> createAnimation(CALayer *layer, RemoteLayerTreeHost* layerTreeHost, const PlatformCAAnimationRemote::Properties& properties)
@@ -885,35 +827,6 @@
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
-TextStream& operator<<(TextStream&ts, const PlatformCAAnimationRemote::KeyframeValue& value)
-{
-    switch (value.keyframeType()) {
-    case PlatformCAAnimationRemote::KeyframeValue::NumberKeyType:
-        ts << "number=" << value.numberValue();
-        break;
-    case PlatformCAAnimationRemote::KeyframeValue::ColorKeyType:
-        ts << "color=";
-        ts << value.colorValue();
-        break;
-    case PlatformCAAnimationRemote::KeyframeValue::PointKeyType:
-        ts << "point=";
-        ts << value.pointValue();
-        break;
-    case PlatformCAAnimationRemote::KeyframeValue::TransformKeyType:
-        ts << "transform=";
-        ts << value.transformValue();
-        break;
-    case PlatformCAAnimationRemote::KeyframeValue::FilterKeyType:
-        ts << "filter=";
-        if (value.filterValue())
-            ts << *value.filterValue();
-        else
-            ts << "null";
-        break;
-    }
-    return ts;
-}
-
 TextStream& operator<<(TextStream& ts, const PlatformCAAnimationRemote::Properties& animation)
 {
     ts << "type=";
@@ -973,9 +886,18 @@
         if (i < animation.timingFunctions.size() && animation.timingFunctions[i])
             ts.dumpProperty<const TimingFunction&>("timing function", *animation.timingFunctions[i]);
 
-        if (i < animation.keyValues.size())
-            ts.dumpProperty("value", animation.keyValues[i]);
-
+        if (i < animation.keyValues.size()) {
+            ts.startGroup();
+            ts << "value ";
+            WTF::switchOn(animation.keyValues[i],
+                [&](const float number) { ts << "number=" << number; },
+                [&](const WebCore::Color color) { ts << "color=" << color; },
+                [&](const WebCore::FloatPoint3D point) { ts << "point=" << point; },
+                [&](const WebCore::TransformationMatrix matrix) { ts << "transform=" << matrix; },
+                [&](const RefPtr<WebCore::FilterOperation> filter) { ts << "filter=" << ValueOrNull(filter.get()); }
+            );
+            ts.endGroup();
+        }
         ts << ")";
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to