Title: [277529] trunk/Source/WebCore
Revision
277529
Author
wei...@apple.com
Date
2021-05-14 20:34:17 -0700 (Fri, 14 May 2021)

Log Message

CustomPaintImage being in platform/graphics is a layering violation
https://bugs.webkit.org/show_bug.cgi?id=225356

Reviewed by Darin Adler.

It is layering violation for a file in platform/ to reference classes
like RenderElement or PaintWorkletGlobalScope. This fixes this by moving
CustomPaintImage out of platform/graphics to html/, next to the existing
CustomPaintCanvas class.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* html/CustomPaintImage.cpp: Copied from Source/WebCore/platform/graphics/CustomPaintImage.cpp.
* html/CustomPaintImage.h: Copied from Source/WebCore/platform/graphics/CustomPaintImage.h.
* platform/graphics/CustomPaintImage.cpp: Removed.
* platform/graphics/CustomPaintImage.h: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277528 => 277529)


--- trunk/Source/WebCore/ChangeLog	2021-05-15 03:15:41 UTC (rev 277528)
+++ trunk/Source/WebCore/ChangeLog	2021-05-15 03:34:17 UTC (rev 277529)
@@ -1,3 +1,22 @@
+2021-05-14  Sam Weinig  <wei...@apple.com>
+
+        CustomPaintImage being in platform/graphics is a layering violation
+        https://bugs.webkit.org/show_bug.cgi?id=225356
+
+        Reviewed by Darin Adler.
+
+        It is layering violation for a file in platform/ to reference classes
+        like RenderElement or PaintWorkletGlobalScope. This fixes this by moving
+        CustomPaintImage out of platform/graphics to html/, next to the existing
+        CustomPaintCanvas class.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/CustomPaintImage.cpp: Copied from Source/WebCore/platform/graphics/CustomPaintImage.cpp.
+        * html/CustomPaintImage.h: Copied from Source/WebCore/platform/graphics/CustomPaintImage.h.
+        * platform/graphics/CustomPaintImage.cpp: Removed.
+        * platform/graphics/CustomPaintImage.h: Removed.
+
 2021-05-14  Darin Adler  <da...@apple.com>
 
         output element doesn't react properly to node tree mutations

Modified: trunk/Source/WebCore/Sources.txt (277528 => 277529)


--- trunk/Source/WebCore/Sources.txt	2021-05-15 03:15:41 UTC (rev 277528)
+++ trunk/Source/WebCore/Sources.txt	2021-05-15 03:34:17 UTC (rev 277529)
@@ -1161,6 +1161,7 @@
 html/CheckboxInputType.cpp
 html/ColorInputType.cpp
 html/CustomPaintCanvas.cpp
+html/CustomPaintImage.cpp
 html/DOMFormData.cpp
 html/DOMTokenList.cpp
 html/DOMURL.cpp
@@ -1951,7 +1952,6 @@
 platform/graphics/ColorUtilities.cpp
 platform/graphics/ComplexTextController.cpp
 platform/graphics/CrossfadeGeneratedImage.cpp
-platform/graphics/CustomPaintImage.cpp
 platform/graphics/DisplayRefreshMonitor.cpp
 platform/graphics/DisplayRefreshMonitorClient.cpp
 platform/graphics/DisplayRefreshMonitorManager.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277528 => 277529)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-15 03:15:41 UTC (rev 277528)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-15 03:34:17 UTC (rev 277529)
@@ -1413,7 +1413,6 @@
 		4B6B5CC02164386400603817 /* PaintWorkletGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6B5CBF2164386400603817 /* PaintWorkletGlobalScope.h */; };
 		4B6E87692176D69200420E5E /* CSSPaintImageValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6E87682176D69200420E5E /* CSSPaintImageValue.h */; };
 		4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6FA6F20C39E48C00087011 /* SmartReplace.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		4B7AE4932177B56F00C59959 /* CustomPaintImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B7AE4922177B56F00C59959 /* CustomPaintImage.h */; };
 		4BAE95B10B2FA9CE00AED8A0 /* EditorDeleteAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4BAFD0CB2190EBD600C0AB64 /* CSSPaintSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAFD0CA2190EBD600C0AB64 /* CSSPaintSize.h */; };
 		4BAFD0CF2190F9B500C0AB64 /* StylePropertyMapReadOnly.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAFD0CE2190F9B400C0AB64 /* StylePropertyMapReadOnly.h */; };
@@ -8566,8 +8565,6 @@
 		4B6E876B2176D8A100420E5E /* CSSPaintImageValue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSPaintImageValue.cpp; sourceTree = "<group>"; };
 		4B6FA6F20C39E48C00087011 /* SmartReplace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartReplace.h; sourceTree = "<group>"; };
 		4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmartReplaceCF.cpp; sourceTree = "<group>"; };
-		4B7AE4922177B56F00C59959 /* CustomPaintImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomPaintImage.h; sourceTree = "<group>"; };
-		4B7AE4952177B63E00C59959 /* CustomPaintImage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CustomPaintImage.cpp; sourceTree = "<group>"; };
 		4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorDeleteAction.h; sourceTree = "<group>"; };
 		4BAFD0CA2190EBD600C0AB64 /* CSSPaintSize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSPaintSize.h; sourceTree = "<group>"; };
 		4BAFD0CD2190EBE900C0AB64 /* CSSPaintSize.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = CSSPaintSize.idl; sourceTree = "<group>"; };
@@ -14302,6 +14299,8 @@
 		BC8243260D0CE8A200460C8F /* JSSQLTransaction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSSQLTransaction.h; sourceTree = "<group>"; };
 		BC8243E60D0CFD7500460C8F /* WindowFeatures.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WindowFeatures.cpp; sourceTree = "<group>"; };
 		BC8243E70D0CFD7500460C8F /* WindowFeatures.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowFeatures.h; sourceTree = "<group>"; };
+		BC84F4392641AB1400F57C1C /* CustomPaintImage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CustomPaintImage.cpp; sourceTree = "<group>"; };
+		BC84F43A2641AB1400F57C1C /* CustomPaintImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomPaintImage.h; sourceTree = "<group>"; };
 		BC8AE34C12EA096A00EB3AE6 /* ScrollableArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollableArea.cpp; sourceTree = "<group>"; };
 		BC8AE34D12EA096A00EB3AE6 /* ScrollableArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollableArea.h; sourceTree = "<group>"; };
 		BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollbarThemeMac.h; sourceTree = "<group>"; };
@@ -23620,6 +23619,8 @@
 				F55B3D801251F12D003EF269 /* ColorInputType.h */,
 				4B1E13E921790D7E0042CF98 /* CustomPaintCanvas.cpp */,
 				4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */,
+				BC84F4392641AB1400F57C1C /* CustomPaintImage.cpp */,
+				BC84F43A2641AB1400F57C1C /* CustomPaintImage.h */,
 				E517670220B88C1400D41167 /* DataListSuggestionInformation.h */,
 				F55B3D811251F12D003EF269 /* DateInputType.cpp */,
 				F55B3D821251F12D003EF269 /* DateInputType.h */,
@@ -26889,8 +26890,6 @@
 				72BAC3A723E17328008D741C /* ConcreteImageBuffer.h */,
 				2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */,
 				2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */,
-				4B7AE4952177B63E00C59959 /* CustomPaintImage.cpp */,
-				4B7AE4922177B56F00C59959 /* CustomPaintImage.h */,
 				A8CB41020E85B8A50032C4F0 /* DashArray.h */,
 				555130001E7CCCCA00A69E38 /* DecodingOptions.h */,
 				49FC7A4F1444AF5F00A5D864 /* DisplayRefreshMonitor.cpp */,
@@ -32143,7 +32142,6 @@
 				62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
 				5C5D2385227A0652000B9BDA /* CustomHeaderFields.h in Headers */,
 				4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */,
-				4B7AE4932177B56F00C59959 /* CustomPaintImage.h in Headers */,
 				A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */,
 				97BC6A211505F081001B74AC /* Database.h in Headers */,
 				97BC6A241505F081001B74AC /* DatabaseAuthorizer.h in Headers */,

Copied: trunk/Source/WebCore/html/CustomPaintImage.cpp (from rev 277528, trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp) (0 => 277529)


--- trunk/Source/WebCore/html/CustomPaintImage.cpp	                        (rev 0)
+++ trunk/Source/WebCore/html/CustomPaintImage.cpp	2021-05-15 03:34:17 UTC (rev 277529)
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CustomPaintImage.h"
+
+#if ENABLE(CSS_PAINTING_API)
+
+#include "CSSComputedStyleDeclaration.h"
+#include "CSSImageValue.h"
+#include "CSSPrimitiveValue.h"
+#include "CSSPropertyParser.h"
+#include "CustomPaintCanvas.h"
+#include "GraphicsContext.h"
+#include "ImageBitmap.h"
+#include "ImageBuffer.h"
+#include "JSCSSPaintCallback.h"
+#include "JSDOMExceptionHandling.h"
+#include "PaintRenderingContext2D.h"
+#include "RenderElement.h"
+#include "StylePropertyMap.h"
+#include "TypedOMCSSImageValue.h"
+#include "TypedOMCSSUnitValue.h"
+#include "TypedOMCSSUnparsedValue.h"
+#include <_javascript_Core/ConstructData.h>
+
+namespace WebCore {
+
+CustomPaintImage::CustomPaintImage(PaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size, RenderElement& element, const Vector<String>& arguments)
+    : m_paintDefinition(makeWeakPtr(definition))
+    , m_inputProperties(definition.inputProperties)
+    , m_element(makeWeakPtr(element))
+    , m_arguments(arguments)
+{
+    setContainerSize(size);
+}
+
+CustomPaintImage::~CustomPaintImage() = default;
+
+static RefPtr<TypedOMCSSStyleValue> extractComputedProperty(const String& name, Element& element)
+{
+    ComputedStyleExtractor extractor(&element);
+
+    if (isCustomPropertyName(name)) {
+        auto value = extractor.customPropertyValue(name);
+        return StylePropertyMapReadOnly::customPropertyValueOrDefault(name, element.document(), value.get(), &element);
+    }
+
+    CSSPropertyID propertyID = cssPropertyID(name);
+    if (!propertyID)
+        return nullptr;
+
+    auto value = extractor.propertyValue(propertyID, DoNotUpdateLayout);
+    return StylePropertyMapReadOnly::reifyValue(value.get(), element.document(), &element);
+}
+
+class HashMapStylePropertyMap final : public StylePropertyMap {
+public:
+    static Ref<StylePropertyMap> create(HashMap<String, RefPtr<TypedOMCSSStyleValue>>&& map)
+    {
+        return adoptRef(*new HashMapStylePropertyMap(WTFMove(map)));
+    }
+
+    static RefPtr<TypedOMCSSStyleValue> extractComputedProperty(const String& name, Element& element)
+    {
+        ComputedStyleExtractor extractor(&element);
+
+        if (isCustomPropertyName(name)) {
+            auto value = extractor.customPropertyValue(name);
+            return StylePropertyMapReadOnly::customPropertyValueOrDefault(name, element.document(), value.get(), &element);
+        }
+
+        CSSPropertyID propertyID = cssPropertyID(name);
+        if (!propertyID)
+            return nullptr;
+
+        auto value = extractor.propertyValue(propertyID, DoNotUpdateLayout);
+        return StylePropertyMapReadOnly::reifyValue(value.get(), element.document(), &element);
+    }
+
+private:
+    explicit HashMapStylePropertyMap(HashMap<String, RefPtr<TypedOMCSSStyleValue>>&& map)
+        : m_map(WTFMove(map))
+    {
+    }
+
+    void clearElement() override { }
+
+    RefPtr<TypedOMCSSStyleValue> get(const String& property) const final { return makeRefPtr(m_map.get(property)); }
+
+    HashMap<String, RefPtr<TypedOMCSSStyleValue>> m_map;
+};
+
+ImageDrawResult CustomPaintImage::doCustomPaint(GraphicsContext& destContext, const FloatSize& destSize)
+{
+    if (!m_element || !m_element->element() || !m_paintDefinition)
+        return ImageDrawResult::DidNothing;
+
+    JSC::JSValue paintConstructor = m_paintDefinition->paintConstructor;
+
+    if (!paintConstructor)
+        return ImageDrawResult::DidNothing;
+
+    ASSERT(!m_element->needsLayout());
+    ASSERT(!m_element->element()->document().needsStyleRecalc());
+
+    JSCSSPaintCallback& callback = static_cast<JSCSSPaintCallback&>(m_paintDefinition->paintCallback.get());
+    auto* scriptExecutionContext = callback.scriptExecutionContext();
+    if (!scriptExecutionContext)
+        return ImageDrawResult::DidNothing;
+
+    auto canvas = CustomPaintCanvas::create(*scriptExecutionContext, destSize.width(), destSize.height());
+    ExceptionOr<RefPtr<PaintRenderingContext2D>> contextOrException = canvas->getContext();
+
+    if (contextOrException.hasException())
+        return ImageDrawResult::DidNothing;
+    auto context = contextOrException.releaseReturnValue();
+
+    HashMap<String, RefPtr<TypedOMCSSStyleValue>> propertyValues;
+
+    if (auto* element = m_element->element()) {
+        for (auto& name : m_inputProperties)
+            propertyValues.add(name, extractComputedProperty(name, *element));
+    }
+
+    auto size = CSSPaintSize::create(destSize.width(), destSize.height());
+    Ref<StylePropertyMapReadOnly> propertyMap = HashMapStylePropertyMap::create(WTFMove(propertyValues));
+
+    auto& vm = paintConstructor.getObject()->vm();
+    JSC::JSLockHolder lock(vm);
+    auto scope = DECLARE_THROW_SCOPE(vm);
+    auto& globalObject = *paintConstructor.getObject()->globalObject();
+
+    auto& lexicalGlobalObject = globalObject;
+    JSC::ArgList noArgs;
+    JSC::JSValue thisObject = { JSC::construct(&lexicalGlobalObject, paintConstructor, noArgs, "Failed to construct paint class") };
+
+    if (UNLIKELY(scope.exception())) {
+        reportException(&lexicalGlobalObject, scope.exception());
+        return ImageDrawResult::DidNothing;
+    }
+
+    auto result = callback.handleEvent(WTFMove(thisObject), *context, size, propertyMap, m_arguments);
+    if (result.type() != CallbackResultType::Success)
+        return ImageDrawResult::DidNothing;
+
+    canvas->replayDisplayList(&destContext);
+
+    return ImageDrawResult::DidDraw;
+}
+
+ImageDrawResult CustomPaintImage::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options)
+{
+    GraphicsContextStateSaver stateSaver(destContext);
+    destContext.setCompositeOperation(options.compositeOperator(), options.blendMode());
+    destContext.clip(destRect);
+    destContext.translate(destRect.location());
+    if (destRect.size() != srcRect.size())
+        destContext.scale(destRect.size() / srcRect.size());
+    destContext.translate(-srcRect.location());
+    return doCustomPaint(destContext, size());
+}
+
+void CustomPaintImage::drawPattern(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform& patternTransform,
+    const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions& options)
+{
+    // Allow the generator to provide visually-equivalent tiling parameters for better performance.
+    FloatSize adjustedSize = size();
+    FloatRect adjustedSrcRect = srcRect;
+
+    // Factor in the destination context's scale to generate at the best resolution
+    AffineTransform destContextCTM = destContext.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
+    double xScale = fabs(destContextCTM.xScale());
+    double yScale = fabs(destContextCTM.yScale());
+    AffineTransform adjustedPatternCTM = patternTransform;
+    adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
+    adjustedSrcRect.scale(xScale, yScale);
+
+    auto buffer = ImageBuffer::createCompatibleBuffer(adjustedSize, DestinationColorSpace::SRGB, destContext);
+    if (!buffer)
+        return;
+    doCustomPaint(buffer->context(), adjustedSize);
+
+    if (destContext.drawLuminanceMask())
+        buffer->convertToLuminanceMask();
+
+    buffer->drawPattern(destContext, destRect, adjustedSrcRect, adjustedPatternCTM, phase, spacing, options);
+    destContext.setDrawLuminanceMask(false);
+}
+
+}
+#endif

Copied: trunk/Source/WebCore/html/CustomPaintImage.h (from rev 277528, trunk/Source/WebCore/platform/graphics/CustomPaintImage.h) (0 => 277529)


--- trunk/Source/WebCore/html/CustomPaintImage.h	                        (rev 0)
+++ trunk/Source/WebCore/html/CustomPaintImage.h	2021-05-15 03:34:17 UTC (rev 277529)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(CSS_PAINTING_API)
+
+#include "GeneratedImage.h"
+#include "PaintWorkletGlobalScope.h"
+
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class ImageBuffer;
+class RenderElement;
+
+class CustomPaintImage final : public GeneratedImage {
+public:
+    static Ref<CustomPaintImage> create(PaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size, RenderElement& element, const Vector<String>& arguments)
+    {
+        return adoptRef(*new CustomPaintImage(definition, size, element, arguments));
+    }
+
+    virtual ~CustomPaintImage();
+    bool isCustomPaintImage() const override { return true; }
+
+private:
+    CustomPaintImage(PaintWorkletGlobalScope::PaintDefinition&, const FloatSize&, RenderElement&, const Vector<String>& arguments);
+
+    ImageDrawResult doCustomPaint(GraphicsContext&, const FloatSize&);
+
+    ImageDrawResult draw(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, const ImagePaintingOptions& = { }) final;
+    void drawPattern(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions& = { }) final;
+
+    WeakPtr<PaintWorkletGlobalScope::PaintDefinition> m_paintDefinition;
+    Vector<String> m_inputProperties;
+    WeakPtr<RenderElement> m_element;
+    Vector<String> m_arguments;
+};
+
+}
+
+SPECIALIZE_TYPE_TRAITS_IMAGE(CustomPaintImage)
+#endif

Deleted: trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp (277528 => 277529)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	2021-05-15 03:15:41 UTC (rev 277528)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	2021-05-15 03:34:17 UTC (rev 277529)
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CustomPaintImage.h"
-
-#if ENABLE(CSS_PAINTING_API)
-
-#include "CSSComputedStyleDeclaration.h"
-#include "CSSImageValue.h"
-#include "CSSPrimitiveValue.h"
-#include "CSSPropertyParser.h"
-#include "CustomPaintCanvas.h"
-#include "GraphicsContext.h"
-#include "ImageBitmap.h"
-#include "ImageBuffer.h"
-#include "JSCSSPaintCallback.h"
-#include "JSDOMExceptionHandling.h"
-#include "PaintRenderingContext2D.h"
-#include "RenderElement.h"
-#include "StylePropertyMap.h"
-#include "TypedOMCSSImageValue.h"
-#include "TypedOMCSSUnitValue.h"
-#include "TypedOMCSSUnparsedValue.h"
-#include <_javascript_Core/ConstructData.h>
-
-namespace WebCore {
-
-CustomPaintImage::CustomPaintImage(PaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size, RenderElement& element, const Vector<String>& arguments)
-    : m_paintDefinition(makeWeakPtr(definition))
-    , m_inputProperties(definition.inputProperties)
-    , m_element(makeWeakPtr(element))
-    , m_arguments(arguments)
-{
-    setContainerSize(size);
-}
-
-CustomPaintImage::~CustomPaintImage() = default;
-
-static RefPtr<TypedOMCSSStyleValue> extractComputedProperty(const String& name, Element& element)
-{
-    ComputedStyleExtractor extractor(&element);
-
-    if (isCustomPropertyName(name)) {
-        auto value = extractor.customPropertyValue(name);
-        return StylePropertyMapReadOnly::customPropertyValueOrDefault(name, element.document(), value.get(), &element);
-    }
-
-    CSSPropertyID propertyID = cssPropertyID(name);
-    if (!propertyID)
-        return nullptr;
-
-    auto value = extractor.propertyValue(propertyID, DoNotUpdateLayout);
-    return StylePropertyMapReadOnly::reifyValue(value.get(), element.document(), &element);
-}
-
-class HashMapStylePropertyMap final : public StylePropertyMap {
-public:
-    static Ref<StylePropertyMap> create(HashMap<String, RefPtr<TypedOMCSSStyleValue>>&& map)
-    {
-        return adoptRef(*new HashMapStylePropertyMap(WTFMove(map)));
-    }
-
-    static RefPtr<TypedOMCSSStyleValue> extractComputedProperty(const String& name, Element& element)
-    {
-        ComputedStyleExtractor extractor(&element);
-
-        if (isCustomPropertyName(name)) {
-            auto value = extractor.customPropertyValue(name);
-            return StylePropertyMapReadOnly::customPropertyValueOrDefault(name, element.document(), value.get(), &element);
-        }
-
-        CSSPropertyID propertyID = cssPropertyID(name);
-        if (!propertyID)
-            return nullptr;
-
-        auto value = extractor.propertyValue(propertyID, DoNotUpdateLayout);
-        return StylePropertyMapReadOnly::reifyValue(value.get(), element.document(), &element);
-    }
-
-private:
-    explicit HashMapStylePropertyMap(HashMap<String, RefPtr<TypedOMCSSStyleValue>>&& map)
-        : m_map(WTFMove(map))
-    {
-    }
-
-    void clearElement() override { }
-
-    RefPtr<TypedOMCSSStyleValue> get(const String& property) const final { return makeRefPtr(m_map.get(property)); }
-
-    HashMap<String, RefPtr<TypedOMCSSStyleValue>> m_map;
-};
-
-ImageDrawResult CustomPaintImage::doCustomPaint(GraphicsContext& destContext, const FloatSize& destSize)
-{
-    if (!m_element || !m_element->element() || !m_paintDefinition)
-        return ImageDrawResult::DidNothing;
-
-    JSC::JSValue paintConstructor = m_paintDefinition->paintConstructor;
-
-    if (!paintConstructor)
-        return ImageDrawResult::DidNothing;
-
-    ASSERT(!m_element->needsLayout());
-    ASSERT(!m_element->element()->document().needsStyleRecalc());
-
-    JSCSSPaintCallback& callback = static_cast<JSCSSPaintCallback&>(m_paintDefinition->paintCallback.get());
-    auto* scriptExecutionContext = callback.scriptExecutionContext();
-    if (!scriptExecutionContext)
-        return ImageDrawResult::DidNothing;
-
-    auto canvas = CustomPaintCanvas::create(*scriptExecutionContext, destSize.width(), destSize.height());
-    ExceptionOr<RefPtr<PaintRenderingContext2D>> contextOrException = canvas->getContext();
-
-    if (contextOrException.hasException())
-        return ImageDrawResult::DidNothing;
-    auto context = contextOrException.releaseReturnValue();
-
-    HashMap<String, RefPtr<TypedOMCSSStyleValue>> propertyValues;
-
-    if (auto* element = m_element->element()) {
-        for (auto& name : m_inputProperties)
-            propertyValues.add(name, extractComputedProperty(name, *element));
-    }
-
-    auto size = CSSPaintSize::create(destSize.width(), destSize.height());
-    Ref<StylePropertyMapReadOnly> propertyMap = HashMapStylePropertyMap::create(WTFMove(propertyValues));
-
-    auto& vm = paintConstructor.getObject()->vm();
-    JSC::JSLockHolder lock(vm);
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    auto& globalObject = *paintConstructor.getObject()->globalObject();
-
-    auto& lexicalGlobalObject = globalObject;
-    JSC::ArgList noArgs;
-    JSC::JSValue thisObject = { JSC::construct(&lexicalGlobalObject, paintConstructor, noArgs, "Failed to construct paint class") };
-
-    if (UNLIKELY(scope.exception())) {
-        reportException(&lexicalGlobalObject, scope.exception());
-        return ImageDrawResult::DidNothing;
-    }
-
-    auto result = callback.handleEvent(WTFMove(thisObject), *context, size, propertyMap, m_arguments);
-    if (result.type() != CallbackResultType::Success)
-        return ImageDrawResult::DidNothing;
-
-    canvas->replayDisplayList(&destContext);
-
-    return ImageDrawResult::DidDraw;
-}
-
-ImageDrawResult CustomPaintImage::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options)
-{
-    GraphicsContextStateSaver stateSaver(destContext);
-    destContext.setCompositeOperation(options.compositeOperator(), options.blendMode());
-    destContext.clip(destRect);
-    destContext.translate(destRect.location());
-    if (destRect.size() != srcRect.size())
-        destContext.scale(destRect.size() / srcRect.size());
-    destContext.translate(-srcRect.location());
-    return doCustomPaint(destContext, size());
-}
-
-void CustomPaintImage::drawPattern(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform& patternTransform,
-    const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions& options)
-{
-    // Allow the generator to provide visually-equivalent tiling parameters for better performance.
-    FloatSize adjustedSize = size();
-    FloatRect adjustedSrcRect = srcRect;
-
-    // Factor in the destination context's scale to generate at the best resolution
-    AffineTransform destContextCTM = destContext.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
-    double xScale = fabs(destContextCTM.xScale());
-    double yScale = fabs(destContextCTM.yScale());
-    AffineTransform adjustedPatternCTM = patternTransform;
-    adjustedPatternCTM.scale(1.0 / xScale, 1.0 / yScale);
-    adjustedSrcRect.scale(xScale, yScale);
-
-    auto buffer = ImageBuffer::createCompatibleBuffer(adjustedSize, DestinationColorSpace::SRGB, destContext);
-    if (!buffer)
-        return;
-    doCustomPaint(buffer->context(), adjustedSize);
-
-    if (destContext.drawLuminanceMask())
-        buffer->convertToLuminanceMask();
-
-    buffer->drawPattern(destContext, destRect, adjustedSrcRect, adjustedPatternCTM, phase, spacing, options);
-    destContext.setDrawLuminanceMask(false);
-}
-
-}
-#endif

Deleted: trunk/Source/WebCore/platform/graphics/CustomPaintImage.h (277528 => 277529)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	2021-05-15 03:15:41 UTC (rev 277528)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	2021-05-15 03:34:17 UTC (rev 277529)
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(CSS_PAINTING_API)
-
-#include "GeneratedImage.h"
-#include "PaintWorkletGlobalScope.h"
-
-#include <wtf/WeakPtr.h>
-
-namespace WebCore {
-
-class ImageBuffer;
-class RenderElement;
-
-class CustomPaintImage final : public GeneratedImage {
-public:
-    static Ref<CustomPaintImage> create(PaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size, RenderElement& element, const Vector<String>& arguments)
-    {
-        return adoptRef(*new CustomPaintImage(definition, size, element, arguments));
-    }
-
-    virtual ~CustomPaintImage();
-    bool isCustomPaintImage() const override { return true; }
-
-private:
-    CustomPaintImage(PaintWorkletGlobalScope::PaintDefinition&, const FloatSize&, RenderElement&, const Vector<String>& arguments);
-
-    ImageDrawResult doCustomPaint(GraphicsContext&, const FloatSize&);
-
-    ImageDrawResult draw(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, const ImagePaintingOptions& = { }) final;
-    void drawPattern(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions& = { }) final;
-
-    WeakPtr<PaintWorkletGlobalScope::PaintDefinition> m_paintDefinition;
-    Vector<String> m_inputProperties;
-    WeakPtr<RenderElement> m_element;
-    Vector<String> m_arguments;
-};
-
-}
-
-SPECIALIZE_TYPE_TRAITS_IMAGE(CustomPaintImage)
-#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to