Title: [238968] trunk/Source/WebCore
Revision
238968
Author
[email protected]
Date
2018-12-07 13:57:49 -0800 (Fri, 07 Dec 2018)

Log Message

CSS Painting API code cleanup
https://bugs.webkit.org/show_bug.cgi?id=192480

Reviewed by Dean Jackson.

No new tests, since the existing tests should cover it.

* bindings/js/JSDOMWrapper.cpp:
(WebCore::outputConstraintSubspaceFor):
(WebCore::globalObjectOutputConstraintSubspaceFor):
* bindings/js/JSWorkletGlobalScopeBase.cpp:
(WebCore::toJS):
* css/CSSPaintCallback.h:
* platform/graphics/CustomPaintImage.cpp:
(WebCore::CustomPaintImage::doCustomPaint):
* platform/graphics/CustomPaintImage.h:
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::addCustomPaintWatchProperty):
(WebCore::changedCustomPaintWatchedProperty):
(WebCore::RenderStyle::changeRequiresRepaint const):
* worklets/PaintWorkletGlobalScope.cpp:
(WebCore::PaintWorkletGlobalScope::registerPaint):
* worklets/PaintWorkletGlobalScope.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (238967 => 238968)


--- trunk/Source/WebCore/ChangeLog	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/ChangeLog	2018-12-07 21:57:49 UTC (rev 238968)
@@ -1,3 +1,29 @@
+2018-12-07  Justin Michaud  <[email protected]>
+
+        CSS Painting API code cleanup
+        https://bugs.webkit.org/show_bug.cgi?id=192480
+
+        Reviewed by Dean Jackson.
+
+        No new tests, since the existing tests should cover it.
+
+        * bindings/js/JSDOMWrapper.cpp:
+        (WebCore::outputConstraintSubspaceFor):
+        (WebCore::globalObjectOutputConstraintSubspaceFor):
+        * bindings/js/JSWorkletGlobalScopeBase.cpp:
+        (WebCore::toJS):
+        * css/CSSPaintCallback.h:
+        * platform/graphics/CustomPaintImage.cpp:
+        (WebCore::CustomPaintImage::doCustomPaint):
+        * platform/graphics/CustomPaintImage.h:
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::addCustomPaintWatchProperty):
+        (WebCore::changedCustomPaintWatchedProperty):
+        (WebCore::RenderStyle::changeRequiresRepaint const):
+        * worklets/PaintWorkletGlobalScope.cpp:
+        (WebCore::PaintWorkletGlobalScope::registerPaint):
+        * worklets/PaintWorkletGlobalScope.h:
+
 2018-12-07  Youenn Fablet  <[email protected]>
 
         Update libwebrtc up to 0d007d7c4f

Modified: trunk/Source/WebCore/bindings/js/JSDOMWrapper.cpp (238967 => 238968)


--- trunk/Source/WebCore/bindings/js/JSDOMWrapper.cpp	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/bindings/js/JSDOMWrapper.cpp	2018-12-07 21:57:49 UTC (rev 238968)
@@ -35,7 +35,6 @@
 #include <_javascript_Core/Error.h>
 
 namespace WebCore {
-using namespace JSC;
 
 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSDOMObject);
 
@@ -45,12 +44,12 @@
     ASSERT(globalObject.classInfo() == JSDOMGlobalObject::info() || scriptExecutionContext() || globalObject.classInfo() == JSRemoteDOMWindow::info());
 }
 
-CompleteSubspace* outputConstraintSubspaceFor(VM& vm)
+JSC::CompleteSubspace* outputConstraintSubspaceFor(JSC::VM& vm)
 {
     return &static_cast<JSVMClientData*>(vm.clientData)->outputConstraintSpace();
 }
 
-CompleteSubspace* globalObjectOutputConstraintSubspaceFor(VM& vm)
+JSC::CompleteSubspace* globalObjectOutputConstraintSubspaceFor(JSC::VM& vm)
 {
     return &static_cast<JSVMClientData*>(vm.clientData)->globalObjectOutputConstraintSpace();
 }

Modified: trunk/Source/WebCore/bindings/js/JSWorkletGlobalScopeBase.cpp (238967 => 238968)


--- trunk/Source/WebCore/bindings/js/JSWorkletGlobalScopeBase.cpp	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/bindings/js/JSWorkletGlobalScopeBase.cpp	2018-12-07 21:57:49 UTC (rev 238968)
@@ -128,9 +128,11 @@
 
 JSValue toJS(ExecState*, WorkletGlobalScope& workletGlobalScope)
 {
-    ASSERT(workletGlobalScope.script());
+    if (!workletGlobalScope.script())
+        return jsUndefined();
     auto* contextWrapper = workletGlobalScope.script()->workletGlobalScopeWrapper();
-    ASSERT(contextWrapper);
+    if (!contextWrapper)
+        return jsUndefined();
     return contextWrapper->proxy();
 }
 

Modified: trunk/Source/WebCore/css/CSSPaintCallback.h (238967 => 238968)


--- trunk/Source/WebCore/css/CSSPaintCallback.h	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/css/CSSPaintCallback.h	2018-12-07 21:57:49 UTC (rev 238968)
@@ -31,10 +31,13 @@
 #include "CSSPaintSize.h"
 #include "CallbackResult.h"
 #include "StylePropertyMapReadOnly.h"
-#include <_javascript_Core/JSCJSValue.h>
 #include <wtf/RefCounted.h>
 #include <wtf/WeakPtr.h>
 
+namespace JSC {
+class JSValue;
+} // namespace JSC
+
 namespace WebCore {
 class PaintRenderingContext2D;
 

Modified: trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp (238967 => 238968)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	2018-12-07 21:57:49 UTC (rev 238968)
@@ -62,17 +62,15 @@
     if (!m_element || !m_element->element() || !m_paintDefinition)
         return ImageDrawResult::DidNothing;
 
-    JSC::JSValue paintConstructor(m_paintDefinition->paintConstructor);
+    JSC::JSValue paintConstructor = m_paintDefinition->paintConstructor;
 
     if (!paintConstructor)
         return ImageDrawResult::DidNothing;
 
-    auto& paintCallback = m_paintDefinition->paintCallback.get();
-
     ASSERT(!m_element->needsLayout());
     ASSERT(!m_element->element()->document().needsStyleRecalc());
 
-    JSCSSPaintCallback& callback = static_cast<JSCSSPaintCallback&>(paintCallback);
+    JSCSSPaintCallback& callback = static_cast<JSCSSPaintCallback&>(m_paintDefinition->paintCallback.get());
     auto* scriptExecutionContext = callback.scriptExecutionContext();
     if (!scriptExecutionContext)
         return ImageDrawResult::DidNothing;
@@ -122,7 +120,7 @@
 
     auto& state = *globalObject.globalExec();
     JSC::ArgList noArgs;
-    JSC::JSValue thisObject = { JSC::construct(&state, WTFMove(paintConstructor), noArgs, "Failed to construct paint class") };
+    JSC::JSValue thisObject = { JSC::construct(&state, paintConstructor, noArgs, "Failed to construct paint class") };
 
     if (UNLIKELY(scope.exception())) {
         reportException(&state, scope.exception());
@@ -129,7 +127,7 @@
         return ImageDrawResult::DidNothing;
     }
 
-    auto result = paintCallback.handleEvent(WTFMove(thisObject), *context, size, propertyMap, m_arguments);
+    auto result = callback.handleEvent(WTFMove(thisObject), *context, size, propertyMap, m_arguments);
     if (result.type() != CallbackResultType::Success)
         return ImageDrawResult::DidNothing;
 

Modified: trunk/Source/WebCore/platform/graphics/CustomPaintImage.h (238967 => 238968)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	2018-12-07 21:57:49 UTC (rev 238968)
@@ -29,8 +29,7 @@
 
 #include "GeneratedImage.h"
 #include "PaintWorkletGlobalScope.h"
-#include <_javascript_Core/JSObject.h>
-#include <_javascript_Core/Weak.h>
+
 #include <wtf/WeakPtr.h>
 
 namespace WebCore {

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (238967 => 238968)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2018-12-07 21:57:49 UTC (rev 238968)
@@ -972,33 +972,12 @@
         data.customPaintWatchedProperties = std::make_unique<HashSet<String>>();
     data.customPaintWatchedProperties->add(name);
 }
-#endif
 
-bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, OptionSet<StyleDifferenceContextSensitiveProperty>& changedContextSensitiveProperties) const
+inline static bool changedCustomPaintWatchedProperty(const RenderStyle& a, const StyleRareNonInheritedData& aData, const RenderStyle& b, const StyleRareNonInheritedData& bData)
 {
-    if (!requiresPainting(*this) && !requiresPainting(other))
-        return false;
+    auto* propertiesA = aData.customPaintWatchedProperties.get();
+    auto* propertiesB = bData.customPaintWatchedProperties.get();
 
-    if (m_inheritedFlags.visibility != other.m_inheritedFlags.visibility
-        || m_inheritedFlags.printColorAdjust != other.m_inheritedFlags.printColorAdjust
-        || m_inheritedFlags.insideLink != other.m_inheritedFlags.insideLink
-        || m_inheritedFlags.insideDefaultButton != other.m_inheritedFlags.insideDefaultButton
-        || m_surroundData->border != other.m_surroundData->border
-        || !m_backgroundData->isEquivalentForPainting(*other.m_backgroundData))
-        return true;
-
-    if (m_rareNonInheritedData.ptr() != other.m_rareNonInheritedData.ptr()
-        && rareNonInheritedDataChangeRequiresRepaint(*m_rareNonInheritedData, *other.m_rareNonInheritedData, changedContextSensitiveProperties))
-        return true;
-
-    if (m_rareInheritedData.ptr() != other.m_rareInheritedData.ptr()
-        && rareInheritedDataChangeRequiresRepaint(*m_rareInheritedData, *other.m_rareInheritedData))
-        return true;
-
-#if ENABLE(CSS_PAINTING_API)
-    auto* propertiesA = m_rareNonInheritedData.ptr()->customPaintWatchedProperties.get();
-    auto* propertiesB = other.m_rareNonInheritedData.ptr()->customPaintWatchedProperties.get();
-
     if (UNLIKELY(propertiesA || propertiesB)) {
         // FIXME: We should not need to use ComputedStyleExtractor here.
         ComputedStyleExtractor extractor((Element*) nullptr);
@@ -1010,15 +989,15 @@
             for (auto& name : *watchPropertiesMap) {
                 RefPtr<CSSValue> valueA;
                 RefPtr<CSSValue> valueB;
-                if (isCustomPropertyName(name) && getCustomProperty(name) && other.getCustomProperty(name)) {
-                    valueA = CSSCustomPropertyValue::create(*getCustomProperty(name));
-                    valueB = CSSCustomPropertyValue::create(*other.getCustomProperty(name));
+                if (isCustomPropertyName(name) && a.getCustomProperty(name) && b.getCustomProperty(name)) {
+                    valueA = CSSCustomPropertyValue::create(*a.getCustomProperty(name));
+                    valueB = CSSCustomPropertyValue::create(*b.getCustomProperty(name));
                 } else {
                     CSSPropertyID propertyID = cssPropertyID(name);
                     if (!propertyID)
                         continue;
-                    valueA = extractor.valueForPropertyinStyle(*this, propertyID);
-                    valueB = extractor.valueForPropertyinStyle(other, propertyID);
+                    valueA = extractor.valueForPropertyinStyle(a, propertyID);
+                    valueB = extractor.valueForPropertyinStyle(b, propertyID);
                 }
 
                 if ((valueA && !valueB) || (!valueA && valueB))
@@ -1032,8 +1011,37 @@
             }
         }
     }
+
+    return false;
+}
 #endif
 
+bool RenderStyle::changeRequiresRepaint(const RenderStyle& other, OptionSet<StyleDifferenceContextSensitiveProperty>& changedContextSensitiveProperties) const
+{
+    if (!requiresPainting(*this) && !requiresPainting(other))
+        return false;
+
+    if (m_inheritedFlags.visibility != other.m_inheritedFlags.visibility
+        || m_inheritedFlags.printColorAdjust != other.m_inheritedFlags.printColorAdjust
+        || m_inheritedFlags.insideLink != other.m_inheritedFlags.insideLink
+        || m_inheritedFlags.insideDefaultButton != other.m_inheritedFlags.insideDefaultButton
+        || m_surroundData->border != other.m_surroundData->border
+        || !m_backgroundData->isEquivalentForPainting(*other.m_backgroundData))
+        return true;
+
+    if (m_rareNonInheritedData.ptr() != other.m_rareNonInheritedData.ptr()
+        && rareNonInheritedDataChangeRequiresRepaint(*m_rareNonInheritedData, *other.m_rareNonInheritedData, changedContextSensitiveProperties))
+        return true;
+
+    if (m_rareInheritedData.ptr() != other.m_rareInheritedData.ptr()
+        && rareInheritedDataChangeRequiresRepaint(*m_rareInheritedData, *other.m_rareInheritedData))
+        return true;
+
+#if ENABLE(CSS_PAINTING_API)
+    if (changedCustomPaintWatchedProperty(*this, *m_rareNonInheritedData, other, *other.m_rareNonInheritedData))
+        return true;
+#endif
+
     return false;
 }
 

Modified: trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.cpp (238967 => 238968)


--- trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.cpp	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.cpp	2018-12-07 21:57:49 UTC (rev 238968)
@@ -141,6 +141,7 @@
 
     // FIXME: construct documentDefinition (step 22).
 
+    // FIXME: we should only repaint affected custom paint images <https://bugs.webkit.org/show_bug.cgi?id=192322>.
     if (responsibleDocument() && responsibleDocument()->renderView())
         responsibleDocument()->renderView()->repaintRootContents();
 

Modified: trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.h (238967 => 238968)


--- trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.h	2018-12-07 21:38:23 UTC (rev 238967)
+++ trunk/Source/WebCore/worklets/PaintWorkletGlobalScope.h	2018-12-07 21:57:49 UTC (rev 238968)
@@ -46,12 +46,12 @@
     ExceptionOr<void> registerPaint(JSC::ExecState&, JSDOMGlobalObject&, const String& name, JSC::Strong<JSC::JSObject> paintConstructor);
     double devicePixelRatio() const;
 
+    // All paint definitions must be destroyed before the vm is destroyed, because otherwise they will point to freed memory.
     struct PaintDefinition : public CanMakeWeakPtr<PaintDefinition> {
         PaintDefinition(const AtomicString& name, JSC::JSObject* paintConstructor, Ref<CSSPaintCallback>&&, Vector<String>&& inputProperties, Vector<String>&& inputArguments);
 
         const AtomicString name;
-        // This map must be cleared before the vm is destroyed!
-        JSC::JSObject* paintConstructor { nullptr };
+        const JSC::JSObject* const paintConstructor;
         const Ref<CSSPaintCallback> paintCallback;
         const Vector<String> inputProperties;
         const Vector<String> inputArguments;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to