Title: [237276] trunk
Revision
237276
Author
commit-qu...@webkit.org
Date
2018-10-18 16:59:49 -0700 (Thu, 18 Oct 2018)

Log Message

Add new image type for CSS painting API
https://bugs.webkit.org/show_bug.cgi?id=190697

Patch by Justin Michaud <justin_mich...@apple.com> on 2018-10-18
Reviewed by Dean Jackson.

Source/WebCore:

Add a new image type for the CSS painting API, and hook it up so it can be drawn.
For now, it uses a WebGL rendering context from OfflineCanvas because that was
easy to hook up. The spec actually calls for a RenderingContext2D, which can be
handled in another patch.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSImageGeneratorValue.cpp:
(WebCore::CSSImageGeneratorValue::image):
(WebCore::CSSImageGeneratorValue::isFixedSize const):
(WebCore::CSSImageGeneratorValue::fixedSize):
(WebCore::CSSImageGeneratorValue::isPending const):
(WebCore::CSSImageGeneratorValue::knownToBeOpaque const):
(WebCore::CSSImageGeneratorValue::loadSubimages):
* css/CSSPaintCallback.h:
* css/CSSPaintCallback.idl:
* css/CSSPaintImageValue.cpp:
(WebCore::CSSPaintImageValue::image):
* css/CSSPaintImageValue.h:
* platform/graphics/CustomPaintImage.cpp: Added.
(WebCore::CustomPaintImage::CustomPaintImage):
(WebCore::CustomPaintImage::doCustomPaint):
(WebCore::CustomPaintImage::draw):
(WebCore::CustomPaintImage::drawPattern):
* platform/graphics/CustomPaintImage.h: Copied from Source/WebCore/css/CSSPaintCallback.h.
* platform/graphics/Image.h:
(WebCore::Image::isCustomPaintImage const):
* platform/graphics/ImageBuffer.h:
* platform/graphics/cairo/CairoOperations.cpp:

LayoutTests:

* fast/css-custom-paint/basic-expected.txt:
* fast/css-custom-paint/basic.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237275 => 237276)


--- trunk/LayoutTests/ChangeLog	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/LayoutTests/ChangeLog	2018-10-18 23:59:49 UTC (rev 237276)
@@ -1,3 +1,13 @@
+2018-10-18  Justin Michaud  <justin_mich...@apple.com>
+
+        Add new image type for CSS painting API
+        https://bugs.webkit.org/show_bug.cgi?id=190697
+
+        Reviewed by Dean Jackson.
+
+        * fast/css-custom-paint/basic-expected.txt:
+        * fast/css-custom-paint/basic.html:
+
 2018-10-18  Jer Noble  <jer.no...@apple.com>
 
         [MSE] timestampOffset can introduce floating-point rounding errors to incoming samples

Modified: trunk/LayoutTests/fast/css-custom-paint/basic-expected.txt (237275 => 237276)


--- trunk/LayoutTests/fast/css-custom-paint/basic-expected.txt	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/LayoutTests/fast/css-custom-paint/basic-expected.txt	2018-10-18 23:59:49 UTC (rev 237276)
@@ -6,4 +6,5 @@
 PASS test that registerPaint runs with predefined class 
 PASS test that registerPaint accepts only a string and a class constructor 
 PASS test that test div has paint() value 
+PASS test that test div paint callback gets called 
 

Modified: trunk/LayoutTests/fast/css-custom-paint/basic.html (237275 => 237276)


--- trunk/LayoutTests/fast/css-custom-paint/basic.html	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/LayoutTests/fast/css-custom-paint/basic.html	2018-10-18 23:59:49 UTC (rev 237276)
@@ -66,4 +66,15 @@
   assert_equals(getComputedStyle(paint).getPropertyValue("background-image"), "paint(my-paint)");
 }, 'test that test div has paint() value');
 
+let paint_called_test = async_test('test that test div paint callback gets called');
+paint_called_test.step(function() {
+  CSS.paintWorkletGlobalScope.registerPaint('my-paint', class {
+    paint(ctx, geom, properties) {
+      ctx.clearColor(0,1.0,0,1.0);
+      ctx.clear(ctx.COLOR_BUFFER_BIT);
+      paint_called_test.done();
+    }
+  });
+});
+
 </script>

Modified: trunk/Source/WebCore/ChangeLog (237275 => 237276)


--- trunk/Source/WebCore/ChangeLog	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/ChangeLog	2018-10-18 23:59:49 UTC (rev 237276)
@@ -1,3 +1,40 @@
+2018-10-18  Justin Michaud  <justin_mich...@apple.com>
+
+        Add new image type for CSS painting API
+        https://bugs.webkit.org/show_bug.cgi?id=190697
+
+        Reviewed by Dean Jackson.
+
+        Add a new image type for the CSS painting API, and hook it up so it can be drawn.
+        For now, it uses a WebGL rendering context from OfflineCanvas because that was
+        easy to hook up. The spec actually calls for a RenderingContext2D, which can be
+        handled in another patch.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSImageGeneratorValue.cpp:
+        (WebCore::CSSImageGeneratorValue::image):
+        (WebCore::CSSImageGeneratorValue::isFixedSize const):
+        (WebCore::CSSImageGeneratorValue::fixedSize):
+        (WebCore::CSSImageGeneratorValue::isPending const):
+        (WebCore::CSSImageGeneratorValue::knownToBeOpaque const):
+        (WebCore::CSSImageGeneratorValue::loadSubimages):
+        * css/CSSPaintCallback.h:
+        * css/CSSPaintCallback.idl:
+        * css/CSSPaintImageValue.cpp:
+        (WebCore::CSSPaintImageValue::image):
+        * css/CSSPaintImageValue.h:
+        * platform/graphics/CustomPaintImage.cpp: Added.
+        (WebCore::CustomPaintImage::CustomPaintImage):
+        (WebCore::CustomPaintImage::doCustomPaint):
+        (WebCore::CustomPaintImage::draw):
+        (WebCore::CustomPaintImage::drawPattern):
+        * platform/graphics/CustomPaintImage.h: Copied from Source/WebCore/css/CSSPaintCallback.h.
+        * platform/graphics/Image.h:
+        (WebCore::Image::isCustomPaintImage const):
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/cairo/CairoOperations.cpp:
+
 2018-10-18  Truitt Savell  <tsav...@apple.com>
 
         Unreviewed, rolling out r237272.

Modified: trunk/Source/WebCore/Sources.txt (237275 => 237276)


--- trunk/Source/WebCore/Sources.txt	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/Sources.txt	2018-10-18 23:59:49 UTC (rev 237276)
@@ -1613,6 +1613,7 @@
 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 (237275 => 237276)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-10-18 23:59:49 UTC (rev 237276)
@@ -1352,6 +1352,7 @@
 		4B6B5CC02164386400603817 /* CSSPaintWorkletGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6B5CBF2164386400603817 /* CSSPaintWorkletGlobalScope.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, ); }; };
 		4BDA3FFE2151B6F500FD6604 /* DOMCSSCustomPropertyDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDA3FF82151B6F200FD6604 /* DOMCSSCustomPropertyDescriptor.h */; };
 		4BDA3FFF2151B6F500FD6604 /* DOMCSSRegisterCustomProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDA3FF92151B6F300FD6604 /* DOMCSSRegisterCustomProperty.h */; };
@@ -7894,6 +7895,8 @@
 		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>"; };
 		4BDA3FF52151B6F000FD6604 /* DOMCSSRegisterCustomProperty.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMCSSRegisterCustomProperty.idl; sourceTree = "<group>"; };
 		4BDA3FF72151B6F100FD6604 /* DOMCSSRegisterCustomProperty.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMCSSRegisterCustomProperty.cpp; sourceTree = "<group>"; };
@@ -23952,6 +23955,8 @@
 				C2F4E7891E45AEDF006D7105 /* ComplexTextController.h */,
 				2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */,
 				2D2FC0551460CD6F00263633 /* CrossfadeGeneratedImage.h */,
+				4B7AE4952177B63E00C59959 /* CustomPaintImage.cpp */,
+				4B7AE4922177B56F00C59959 /* CustomPaintImage.h */,
 				A8CB41020E85B8A50032C4F0 /* DashArray.h */,
 				555130001E7CCCCA00A69E38 /* DecodingOptions.h */,
 				49FC7A4F1444AF5F00A5D864 /* DisplayRefreshMonitor.cpp */,
@@ -28073,6 +28078,7 @@
 				93D437A01D57B19A00AB85EA /* CustomElementReactionQueue.h in Headers */,
 				9BD4E91B1C462CFC005065BC /* CustomElementRegistry.h in Headers */,
 				62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
+				4B7AE4932177B56F00C59959 /* CustomPaintImage.h in Headers */,
 				A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */,
 				A80E6D0B0A1989CA007FB8C5 /* DashboardRegion.h in Headers */,
 				97BC6A211505F081001B74AC /* Database.h in Headers */,

Modified: trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp (237275 => 237276)


--- trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp	2018-10-18 23:59:49 UTC (rev 237276)
@@ -33,6 +33,7 @@
 #include "CSSGradientValue.h"
 #include "CSSImageValue.h"
 #include "CSSNamedImageValue.h"
+#include "CSSPaintImageValue.h"
 #include "GeneratedImage.h"
 #include "HTMLCanvasElement.h"
 #include "InspectorInstrumentation.h"
@@ -152,7 +153,7 @@
         return downcast<CSSConicGradientValue>(*this).image(renderer, size);
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
-        return nullptr;
+        return downcast<CSSPaintImageValue>(*this).image(renderer, size);
 #endif
     default:
         ASSERT_NOT_REACHED();
@@ -179,7 +180,7 @@
         return downcast<CSSConicGradientValue>(*this).isFixedSize();
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
-        return false;
+        return downcast<CSSPaintImageValue>(*this).isFixedSize();
 #endif
     default:
         ASSERT_NOT_REACHED();
@@ -204,7 +205,7 @@
         return downcast<CSSConicGradientValue>(*this).fixedSize(renderer);
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
-        return FloatSize();
+        return downcast<CSSPaintImageValue>(*this).fixedSize(renderer);
 #endif
     default:
         ASSERT_NOT_REACHED();
@@ -231,7 +232,7 @@
         return downcast<CSSConicGradientValue>(*this).isPending();
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
-        return false;
+        return downcast<CSSPaintImageValue>(*this).isPending();
 #endif
     default:
         ASSERT_NOT_REACHED();
@@ -258,7 +259,7 @@
         return downcast<CSSConicGradientValue>(*this).knownToBeOpaque(renderer);
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
-        return false;
+        return downcast<CSSPaintImageValue>(*this).knownToBeOpaque(renderer);
 #endif
     default:
         ASSERT_NOT_REACHED();
@@ -289,6 +290,7 @@
         break;
 #if ENABLE(CSS_PAINTING_API)
     case PaintImageClass:
+        downcast<CSSPaintImageValue>(*this).loadSubimages(cachedResourceLoader, options);
         break;
 #endif
     default:

Modified: trunk/Source/WebCore/css/CSSPaintCallback.h (237275 => 237276)


--- trunk/Source/WebCore/css/CSSPaintCallback.h	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/css/CSSPaintCallback.h	2018-10-18 23:59:49 UTC (rev 237276)
@@ -32,12 +32,13 @@
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
+class WebGLRenderingContext;
 
 class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback {
 public:
     using ActiveDOMCallback::ActiveDOMCallback;
 
-    virtual CallbackResult<void> handleEvent() = 0;
+    virtual CallbackResult<void> handleEvent(WebGLRenderingContext&) = 0;
 
     virtual ~CSSPaintCallback()
     {

Modified: trunk/Source/WebCore/css/CSSPaintCallback.idl (237275 => 237276)


--- trunk/Source/WebCore/css/CSSPaintCallback.idl	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/css/CSSPaintCallback.idl	2018-10-18 23:59:49 UTC (rev 237276)
@@ -26,4 +26,4 @@
 [
     EnabledAtRuntime=CSSPaintingAPI,
     Conditional=CSS_PAINTING_API,
-] callback CSSPaintCallback = void ();
+] callback CSSPaintCallback = void (WebGLRenderingContext context);

Modified: trunk/Source/WebCore/css/CSSPaintImageValue.cpp (237275 => 237276)


--- trunk/Source/WebCore/css/CSSPaintImageValue.cpp	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/css/CSSPaintImageValue.cpp	2018-10-18 23:59:49 UTC (rev 237276)
@@ -29,6 +29,9 @@
 
 #if ENABLE(CSS_PAINTING_API)
 
+#include "CSSPaintWorkletGlobalScope.h"
+#include "CustomPaintImage.h"
+#include "RenderElement.h"
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
@@ -43,6 +46,18 @@
     return result.toString();
 }
 
+RefPtr<Image> CSSPaintImageValue::image(RenderElement& renderElement, const FloatSize& size)
+{
+    if (size.isEmpty())
+        return nullptr;
+    auto& selectedGlobalScope = renderElement.document().ensureCSSPaintWorkletGlobalScope();
+    auto* registration = selectedGlobalScope.paintDefinitionMap().get(m_name);
+
+    if (!registration)
+        return nullptr;
+    return CustomPaintImage::create(*registration, size);
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/css/CSSPaintImageValue.h (237275 => 237276)


--- trunk/Source/WebCore/css/CSSPaintImageValue.h	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/css/CSSPaintImageValue.h	2018-10-18 23:59:49 UTC (rev 237276)
@@ -39,10 +39,19 @@
         return adoptRef(*new CSSPaintImageValue(name));
     }
 
+    RefPtr<Image> image(RenderElement&, const FloatSize&);
+
     bool equals(const CSSPaintImageValue& other) const { return m_name == other.m_name; }
-
     String customCSSText() const;
 
+    bool isFixedSize() const { return false; }
+    FloatSize fixedSize(const RenderElement&) const { return FloatSize(); }
+
+    bool isPending() const { return false; }
+    bool knownToBeOpaque(const RenderElement&) const { return false; }
+
+    void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&) { }
+
 private:
     CSSPaintImageValue(const String& name)
         : CSSImageGeneratorValue(PaintImageClass)

Added: trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp (0 => 237276)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp	2018-10-18 23:59:49 UTC (rev 237276)
@@ -0,0 +1,121 @@
+/*
+ * 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. 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 "GraphicsContext.h"
+#include "ImageBitmap.h"
+#include "ImageBuffer.h"
+#include "JSCSSPaintCallback.h"
+#include "OffscreenCanvas.h"
+#include "WebGLRenderingContext.h"
+
+namespace WebCore {
+
+CustomPaintImage::CustomPaintImage(const CSSPaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size)
+    : m_paintCallback(definition.paintCallback.get())
+{
+    setContainerSize(size);
+}
+
+CustomPaintImage::~CustomPaintImage() = default;
+
+ImageDrawResult CustomPaintImage::doCustomPaint(GraphicsContext& destContext, const FloatSize& destSize)
+{
+    JSCSSPaintCallback& callback = static_cast<JSCSSPaintCallback&>(m_paintCallback.get());
+    auto* scriptExecutionContext = callback.scriptExecutionContext();
+    if (!scriptExecutionContext)
+        return ImageDrawResult::DidNothing;
+    auto* execState = scriptExecutionContext->execState();
+    if (!execState)
+        return ImageDrawResult::DidNothing;
+
+    auto canvas = OffscreenCanvas::create(*scriptExecutionContext, destSize.width(), destSize.height());
+    ExceptionOr<OffscreenRenderingContext> contextOrException = canvas->getContext(*execState, OffscreenCanvas::RenderingContextType::Webgl, { });
+
+    if (contextOrException.hasException())
+        return ImageDrawResult::DidNothing;
+    auto context = contextOrException.releaseReturnValue();
+
+    context->clearColor(0, 0, 0, 1.0);
+    context->clear(GL_COLOR_BUFFER_BIT);
+
+    auto result = m_paintCallback->handleEvent(*context);
+    if (result.type() != CallbackResultType::Success)
+        return ImageDrawResult::DidNothing;
+
+    auto bitmap = canvas->transferToImageBitmap();
+    if (!bitmap)
+        return ImageDrawResult::DidNothing;
+
+    destContext.drawImage(*bitmap->buffer()->copyImage(), FloatPoint());
+
+    return ImageDrawResult::DidDraw;
+}
+
+ImageDrawResult CustomPaintImage::draw(GraphicsContext& destContext, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator compositeOp, BlendMode blendMode, DecodingMode, ImageOrientationDescription)
+{
+    GraphicsContextStateSaver stateSaver(destContext);
+    destContext.setCompositeOperation(compositeOp, 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, CompositeOperator compositeOp, BlendMode blendMode)
+{
+    // 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, ColorSpaceSRGB, destContext);
+    if (!buffer)
+        return;
+    doCustomPaint(buffer->context(), adjustedSize);
+
+    if (destContext.drawLuminanceMask())
+        buffer->convertToLuminanceMask();
+
+    buffer->drawPattern(destContext, destRect, adjustedSrcRect, adjustedPatternCTM, phase, spacing, compositeOp, blendMode);
+    destContext.setDrawLuminanceMask(false);
+}
+
+}
+#endif

Copied: trunk/Source/WebCore/platform/graphics/CustomPaintImage.h (from rev 237275, trunk/Source/WebCore/css/CSSPaintCallback.h) (0 => 237276)


--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.h	2018-10-18 23:59:49 UTC (rev 237276)
@@ -0,0 +1,61 @@
+/*
+ * 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 "CSSPaintWorkletGlobalScope.h"
+#include "GeneratedImage.h"
+
+namespace WebCore {
+
+class ImageBuffer;
+
+class CustomPaintImage final : public GeneratedImage {
+public:
+    static Ref<CustomPaintImage> create(const CSSPaintWorkletGlobalScope::PaintDefinition& definition, const FloatSize& size)
+    {
+        return adoptRef(*new CustomPaintImage(definition, size));
+    }
+
+    virtual ~CustomPaintImage();
+    bool isCustomPaintImage() const override { return true; }
+
+private:
+    CustomPaintImage(const CSSPaintWorkletGlobalScope::PaintDefinition&, const FloatSize&);
+
+    ImageDrawResult doCustomPaint(GraphicsContext&, const FloatSize&);
+
+    ImageDrawResult draw(GraphicsContext&, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator, BlendMode, DecodingMode, ImageOrientationDescription) final;
+    void drawPattern(GraphicsContext&, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator, BlendMode) final;
+
+    Ref<CSSPaintCallback> m_paintCallback;
+};
+
+}
+
+SPECIALIZE_TYPE_TRAITS_IMAGE(CustomPaintImage)
+#endif

Modified: trunk/Source/WebCore/platform/graphics/Image.h (237275 => 237276)


--- trunk/Source/WebCore/platform/graphics/Image.h	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2018-10-18 23:59:49 UTC (rev 237276)
@@ -93,6 +93,7 @@
     virtual bool isGradientImage() const { return false; }
     virtual bool isSVGImage() const { return false; }
     virtual bool isPDFDocumentImage() const { return false; }
+    virtual bool isCustomPaintImage() const { return false; }
 
     virtual bool currentFrameKnownToBeOpaque() const = 0;
     virtual bool isAnimated() const { return false; }

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (237275 => 237276)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2018-10-18 23:59:49 UTC (rev 237276)
@@ -156,6 +156,7 @@
     friend class CrossfadeGeneratedImage;
     friend class NamedImageGeneratedImage;
     friend class GradientImage;
+    friend class CustomPaintImage;
 
 private:
     ImageBufferData m_data;

Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (237275 => 237276)


--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2018-10-18 23:44:01 UTC (rev 237275)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp	2018-10-18 23:59:49 UTC (rev 237276)
@@ -35,6 +35,7 @@
 
 #if USE(CAIRO)
 
+#include "CairoUtilities.h"
 #include "DrawErrorUnderline.h"
 #include "FloatConversion.h"
 #include "FloatRect.h"
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to