Diff
Modified: trunk/LayoutTests/ChangeLog (237343 => 237344)
--- trunk/LayoutTests/ChangeLog 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/LayoutTests/ChangeLog 2018-10-23 00:46:14 UTC (rev 237344)
@@ -1,3 +1,12 @@
+2018-10-22 Justin Michaud <[email protected]>
+
+ CSS Paint API should give a 2d rendering context
+ https://bugs.webkit.org/show_bug.cgi?id=190762
+
+ Reviewed by Dean Jackson.
+
+ * fast/css-custom-paint/basic.html:
+
2018-10-22 Ryan Haddad <[email protected]>
Unreviewed, update TestExpectations for imported/w3c/web-platform-tests/fetch/nosniff/importscripts.html.
Modified: trunk/LayoutTests/fast/css-custom-paint/basic.html (237343 => 237344)
--- trunk/LayoutTests/fast/css-custom-paint/basic.html 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/LayoutTests/fast/css-custom-paint/basic.html 2018-10-23 00:46:14 UTC (rev 237344)
@@ -8,8 +8,8 @@
<style>
#paint {
background-image: paint(my-paint);
- width: 50px;
- height: 50px;
+ width: 150px;
+ height: 150px;
}
</style>
@@ -70,8 +70,13 @@
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);
+ for (var i = 0; i < 6; i++){
+ for (var j = 0; j < 6; j++){
+ ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ',' +
+ Math.floor(255 - 42.5 * j) + ',0)';
+ ctx.fillRect(j * 25, i * 25, 25, 25);
+ }
+ }
paint_called_test.done();
}
});
Modified: trunk/Source/WebCore/CMakeLists.txt (237343 => 237344)
--- trunk/Source/WebCore/CMakeLists.txt 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/CMakeLists.txt 2018-10-23 00:46:14 UTC (rev 237344)
@@ -806,6 +806,7 @@
html/canvas/ImageBitmapRenderingContextSettings.idl
html/canvas/ImageSmoothingQuality.idl
html/canvas/OffscreenCanvasRenderingContext2D.idl
+ html/canvas/PaintRenderingContext2D.idl
html/canvas/Path2D.idl
html/canvas/WebMetalBuffer.idl
html/canvas/WebMetalCommandBuffer.idl
Modified: trunk/Source/WebCore/ChangeLog (237343 => 237344)
--- trunk/Source/WebCore/ChangeLog 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/ChangeLog 2018-10-23 00:46:14 UTC (rev 237344)
@@ -1,3 +1,78 @@
+2018-10-22 Justin Michaud <[email protected]>
+
+ CSS Paint API should give a 2d rendering context
+ https://bugs.webkit.org/show_bug.cgi?id=190762
+
+ Reviewed by Dean Jackson.
+
+ Add a new type of canvas and 2d rendering context to support the CSS Painting API.
+ Make many of the methods from HTMLCanvasElement virtual functions on CanvasBase, and
+ remove many of the downcasts in CanvasRenderingContext2DBase as a result.
+
+ * CMakeLists.txt:
+ * DerivedSources.make:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/JSPaintRenderingContext2DCustom.cpp: Copied from Source/WebCore/css/CSSPaintCallback.h.
+ (WebCore::root):
+ (WebCore::JSPaintRenderingContext2DOwner::isReachableFromOpaqueRoots):
+ (WebCore::JSPaintRenderingContext2D::visitAdditionalChildren):
+ * bindings/js/WebCoreBuiltinNames.h:
+ * css/CSSPaintCallback.h:
+ * css/CSSPaintCallback.idl:
+ * html/CanvasBase.cpp:
+ (WebCore::CanvasBase::~CanvasBase):
+ * html/CanvasBase.h:
+ (WebCore::CanvasBase::isCustomPaintCanvas const):
+ * html/CustomPaintCanvas.cpp: Added.
+ (WebCore::CustomPaintCanvas::create):
+ (WebCore::CustomPaintCanvas::CustomPaintCanvas):
+ (WebCore::CustomPaintCanvas::~CustomPaintCanvas):
+ (WebCore::CustomPaintCanvas::width const):
+ (WebCore::CustomPaintCanvas::setWidth):
+ (WebCore::CustomPaintCanvas::height const):
+ (WebCore::CustomPaintCanvas::setHeight):
+ (WebCore::CustomPaintCanvas::size const):
+ (WebCore::CustomPaintCanvas::setSize):
+ (WebCore::CustomPaintCanvas::getContext):
+ (WebCore::CustomPaintCanvas::copiedImage const):
+ (WebCore::CustomPaintCanvas::drawingContext const):
+ (WebCore::CustomPaintCanvas::existingDrawingContext const):
+ (WebCore::CustomPaintCanvas::makeRenderingResultsAvailable):
+ * html/CustomPaintCanvas.h: Copied from Source/WebCore/html/OffscreenCanvas.h.
+ * html/HTMLCanvasElement.h:
+ * html/OffscreenCanvas.h:
+ * html/canvas/CanvasRenderingContext.cpp:
+ (WebCore::CanvasRenderingContext::wouldTaintOrigin):
+ * html/canvas/CanvasRenderingContext.h:
+ (WebCore::CanvasRenderingContext::isPaint const):
+ * html/canvas/CanvasRenderingContext2DBase.cpp:
+ (WebCore::DisplayListDrawingContext::DisplayListDrawingContext):
+ (WebCore::CanvasRenderingContext2DBase::unwindStateStack):
+ (WebCore::CanvasRenderingContext2DBase::isAccelerated const):
+ (WebCore::CanvasRenderingContext2DBase::setStrokeStyle):
+ (WebCore::CanvasRenderingContext2DBase::setFillStyle):
+ (WebCore::CanvasRenderingContext2DBase::resetTransform):
+ (WebCore::CanvasRenderingContext2DBase::clearCanvas):
+ (WebCore::CanvasRenderingContext2DBase::transformAreaToDevice const):
+ (WebCore::CanvasRenderingContext2DBase::rectContainsCanvas const):
+ (WebCore::CanvasRenderingContext2DBase::calculateCompositingBufferRect):
+ (WebCore::CanvasRenderingContext2DBase::compositeBuffer):
+ (WebCore::CanvasRenderingContext2DBase::createPattern):
+ (WebCore::CanvasRenderingContext2DBase::didDrawEntireCanvas):
+ (WebCore::CanvasRenderingContext2DBase::didDraw):
+ (WebCore::CanvasRenderingContext2DBase::paintRenderingResultsToCanvas):
+ (WebCore::CanvasRenderingContext2DBase::drawingContext const):
+ * html/canvas/CanvasRenderingContext2DBase.h:
+ * html/canvas/PaintRenderingContext2D.cpp: Copied from Source/WebCore/css/CSSPaintCallback.h.
+ (WebCore::PaintRenderingContext2D::create):
+ (WebCore::PaintRenderingContext2D::PaintRenderingContext2D):
+ * html/canvas/PaintRenderingContext2D.h: Copied from Source/WebCore/css/CSSPaintCallback.h.
+ * html/canvas/PaintRenderingContext2D.idl: Copied from Source/WebCore/css/CSSPaintCallback.idl.
+ * html/canvas/WebMetalRenderPassAttachmentDescriptor.h:
+ * platform/graphics/CustomPaintImage.cpp:
+ (WebCore::CustomPaintImage::doCustomPaint):
+
2018-10-22 Keith Rollin <[email protected]>
Use Location = "Relative to Build Products" rather than "Relative to Group"
Modified: trunk/Source/WebCore/DerivedSources.make (237343 => 237344)
--- trunk/Source/WebCore/DerivedSources.make 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/DerivedSources.make 2018-10-23 00:46:14 UTC (rev 237344)
@@ -729,6 +729,7 @@
$(WebCore)/html/canvas/OESTextureHalfFloatLinear.idl \
$(WebCore)/html/canvas/OESVertexArrayObject.idl \
$(WebCore)/html/canvas/OffscreenCanvasRenderingContext2D.idl \
+ $(WebCore)/html/canvas/PaintRenderingContext2D.idl \
$(WebCore)/html/canvas/Path2D.idl \
$(WebCore)/html/canvas/WebGL2RenderingContext.idl \
$(WebCore)/html/canvas/WebGLActiveInfo.idl \
Modified: trunk/Source/WebCore/Sources.txt (237343 => 237344)
--- trunk/Source/WebCore/Sources.txt 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/Sources.txt 2018-10-23 00:46:14 UTC (rev 237344)
@@ -445,6 +445,7 @@
bindings/js/JSNodeIteratorCustom.cpp
bindings/js/JSNodeListCustom.cpp
bindings/js/JSOffscreenCanvasRenderingContext2DCustom.cpp
+bindings/js/JSPaintRenderingContext2DCustom.cpp
bindings/js/JSPaymentMethodChangeEventCustom.cpp
bindings/js/JSPaymentResponseCustom.cpp
bindings/js/JSPerformanceEntryCustom.cpp
@@ -970,6 +971,7 @@
html/CanvasBase.cpp
html/CheckboxInputType.cpp
html/ColorInputType.cpp
+html/CustomPaintCanvas.cpp
html/DOMFormData.cpp
html/DOMTokenList.cpp
html/DOMURL.cpp
@@ -1128,6 +1130,7 @@
html/canvas/CanvasStyle.cpp
html/canvas/ImageBitmapRenderingContext.cpp
html/canvas/OffscreenCanvasRenderingContext2D.cpp
+html/canvas/PaintRenderingContext2D.cpp
html/canvas/Path2D.cpp
html/canvas/PlaceholderRenderingContext.cpp
html/canvas/WebMetalBuffer.cpp
@@ -2845,6 +2848,7 @@
JSOfflineAudioContext.cpp
JSOffscreenCanvas.cpp
JSOffscreenCanvasRenderingContext2D.cpp
+JSPaintRenderingContext2D.cpp
JSOscillatorNode.cpp
JSOverconstrainedError.cpp
JSOverconstrainedErrorEvent.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (237343 => 237344)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-10-23 00:46:14 UTC (rev 237344)
@@ -1345,6 +1345,8 @@
4A9CC82116BF9BB400EC645A /* InspectorCSSOMWrappers.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A9CC81F16BF9BB400EC645A /* InspectorCSSOMWrappers.h */; };
4AD01009127E642A0015035F /* HTMLOutputElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AD01006127E642A0015035F /* HTMLOutputElement.h */; };
4AD0173D127E82860015035F /* JSHTMLOutputElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AD0173B127E82860015035F /* JSHTMLOutputElement.h */; };
+ 4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */; };
+ 4B1E13EB217937B30042CF98 /* PaintRenderingContext2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */; };
4B2708C70AF19EE40065127F /* Pasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B2708C50AF19EE40065127F /* Pasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
4B3043CD0AE0373B00A82647 /* Editor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3043CB0AE0373B00A82647 /* Editor.h */; settings = {ATTRIBUTES = (Private, ); }; };
4B3480940EEF50D400AC1B41 /* ImageSourceCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3480920EEF50D400AC1B41 /* ImageSourceCG.h */; };
@@ -7883,6 +7885,12 @@
4AD0173A127E82860015035F /* JSHTMLOutputElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLOutputElement.cpp; sourceTree = "<group>"; };
4AD0173B127E82860015035F /* JSHTMLOutputElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLOutputElement.h; sourceTree = "<group>"; };
4B1706642162B42F00E578BB /* CSSRegisteredCustomProperty.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSRegisteredCustomProperty.cpp; sourceTree = "<group>"; };
+ 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomPaintCanvas.h; sourceTree = "<group>"; };
+ 4B1E13E921790D7E0042CF98 /* CustomPaintCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CustomPaintCanvas.cpp; sourceTree = "<group>"; };
+ 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaintRenderingContext2D.h; sourceTree = "<group>"; };
+ 4B1E13EC217938380042CF98 /* PaintRenderingContext2D.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaintRenderingContext2D.cpp; sourceTree = "<group>"; };
+ 4B1E13ED21793DC10042CF98 /* PaintRenderingContext2D.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PaintRenderingContext2D.idl; sourceTree = "<group>"; };
+ 4B1E13EE217941320042CF98 /* JSPaintRenderingContext2DCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaintRenderingContext2DCustom.cpp; sourceTree = "<group>"; };
4B2708C50AF19EE40065127F /* Pasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pasteboard.h; sourceTree = "<group>"; };
4B2709810AF2E5E00065127F /* PasteboardMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteboardMac.mm; sourceTree = "<group>"; };
4B3043CA0AE0373B00A82647 /* Editor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Editor.cpp; sourceTree = "<group>"; };
@@ -17636,6 +17644,9 @@
3140C51D1FDF151A00D2A873 /* OffscreenCanvasRenderingContext2D.cpp */,
3140C51E1FDF151A00D2A873 /* OffscreenCanvasRenderingContext2D.h */,
3140C51B1FDF13D200D2A873 /* OffscreenCanvasRenderingContext2D.idl */,
+ 4B1E13EC217938380042CF98 /* PaintRenderingContext2D.cpp */,
+ 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */,
+ 4B1E13ED21793DC10042CF98 /* PaintRenderingContext2D.idl */,
7C193BA71F5E0EAF0088F3E6 /* Path2D.cpp */,
7C193BAB1F5E0EB10088F3E6 /* Path2D.h */,
7C193BB41F5E0EB70088F3E6 /* Path2D.idl */,
@@ -20211,6 +20222,7 @@
BCD9C2610C17AA67005C90A2 /* JSNodeListCustom.cpp */,
AD20B18C18E9D216005A8083 /* JSNodeListCustom.h */,
3140C52B1FE06B4900D2A873 /* JSOffscreenCanvasRenderingContext2DCustom.cpp */,
+ 4B1E13EE217941320042CF98 /* JSPaintRenderingContext2DCustom.cpp */,
CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */,
833CF70F20DB3F5F00141BCC /* JSPerformanceObserverCustom.cpp */,
A4A69B8BB91B49D0A804C31D /* JSPromiseRejectionEventCustom.cpp */,
@@ -20777,6 +20789,8 @@
93C441FF0F813AE100C1A634 /* CollectionType.h */,
BC29935C17A1DD5800BCE880 /* ColorInputType.cpp */,
F55B3D801251F12D003EF269 /* ColorInputType.h */,
+ 4B1E13E921790D7E0042CF98 /* CustomPaintCanvas.cpp */,
+ 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */,
E517670220B88C1400D41167 /* DataListSuggestionInformation.h */,
F55B3D811251F12D003EF269 /* DateInputType.cpp */,
F55B3D821251F12D003EF269 /* DateInputType.h */,
@@ -28103,6 +28117,7 @@
93D437A01D57B19A00AB85EA /* CustomElementReactionQueue.h in Headers */,
9BD4E91B1C462CFC005065BC /* CustomElementRegistry.h in Headers */,
62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
+ 4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */,
4B7AE4932177B56F00C59959 /* CustomPaintImage.h in Headers */,
A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */,
A80E6D0B0A1989CA007FB8C5 /* DashboardRegion.h in Headers */,
@@ -30128,6 +30143,7 @@
55EC9599206AA7A0007DD0A9 /* PaintFrequencyTracker.h in Headers */,
0885067F11DA045B00182B98 /* PaintInfo.h in Headers */,
0885068011DA045B00182B98 /* PaintPhase.h in Headers */,
+ 4B1E13EB217937B30042CF98 /* PaintRenderingContext2D.h in Headers */,
A80E6CFB0A1989CA007FB8C5 /* Pair.h in Headers */,
FD3160A312B026F700C1A359 /* Panner.h in Headers */,
FD31601A12B0267600C1A359 /* PannerNode.h in Headers */,
Copied: trunk/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp (from rev 237342, trunk/Source/WebCore/css/CSSPaintCallback.h) (0 => 237344)
--- trunk/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "JSPaintRenderingContext2D.h"
+
+#if ENABLE(CSS_PAINTING_API)
+
+namespace WebCore {
+using namespace JSC;
+
+inline void* root(CustomPaintCanvas* canvas)
+{
+ return canvas;
+}
+
+bool JSPaintRenderingContext2DOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
+{
+ if (UNLIKELY(reason))
+ *reason = "Canvas is opaque root";
+
+ JSPaintRenderingContext2D* jsPaintRenderingContext = jsCast<JSPaintRenderingContext2D*>(handle.slot()->asCell());
+ void* root = WebCore::root(&jsPaintRenderingContext->wrapped().canvas());
+ return visitor.containsOpaqueRoot(root);
+}
+
+void JSPaintRenderingContext2D::visitAdditionalChildren(SlotVisitor& visitor)
+{
+ visitor.addOpaqueRoot(root(&wrapped().canvas()));
+}
+
+} // namespace WebCore
+#endif
+
Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (237343 => 237344)
--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -113,6 +113,7 @@
macro(NavigatorUserMedia) \
macro(OffscreenCanvas) \
macro(OffscreenCanvasRenderingContext2D) \
+ macro(PaintRenderingContext2D) \
macro(PaymentAddress) \
macro(PaymentMethodChangeEvent) \
macro(PaymentRequest) \
Modified: trunk/Source/WebCore/css/CSSPaintCallback.h (237343 => 237344)
--- trunk/Source/WebCore/css/CSSPaintCallback.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/css/CSSPaintCallback.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -32,13 +32,13 @@
#include <wtf/RefCounted.h>
namespace WebCore {
-class WebGLRenderingContext;
+class PaintRenderingContext2D;
class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback {
public:
using ActiveDOMCallback::ActiveDOMCallback;
- virtual CallbackResult<void> handleEvent(WebGLRenderingContext&) = 0;
+ virtual CallbackResult<void> handleEvent(PaintRenderingContext2D&) = 0;
virtual ~CSSPaintCallback()
{
Modified: trunk/Source/WebCore/css/CSSPaintCallback.idl (237343 => 237344)
--- trunk/Source/WebCore/css/CSSPaintCallback.idl 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/css/CSSPaintCallback.idl 2018-10-23 00:46:14 UTC (rev 237344)
@@ -26,4 +26,4 @@
[
EnabledAtRuntime=CSSPaintingAPI,
Conditional=CSS_PAINTING_API,
-] callback CSSPaintCallback = void (WebGLRenderingContext context);
+] callback CSSPaintCallback = void (PaintRenderingContext2D context);
Modified: trunk/Source/WebCore/html/CanvasBase.cpp (237343 => 237344)
--- trunk/Source/WebCore/html/CanvasBase.cpp 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/CanvasBase.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -41,6 +41,7 @@
CanvasBase::~CanvasBase()
{
+ ASSERT(!m_context); // Should have been set to null by base class.
notifyObserversCanvasDestroyed();
}
Modified: trunk/Source/WebCore/html/CanvasBase.h (237343 => 237344)
--- trunk/Source/WebCore/html/CanvasBase.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/CanvasBase.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -30,9 +30,13 @@
namespace WebCore {
+class AffineTransform;
class CanvasBase;
class CanvasRenderingContext;
class Element;
+class GraphicsContext;
+class Image;
+class ImageBuffer;
class IntSize;
class FloatRect;
class ScriptExecutionContext;
@@ -58,6 +62,7 @@
virtual bool isHTMLCanvasElement() const { return false; }
virtual bool isOffscreenCanvas() const { return false; }
+ virtual bool isCustomPaintCanvas() const { return false; }
virtual unsigned width() const = 0;
virtual unsigned height() const = 0;
@@ -81,6 +86,15 @@
HashSet<Element*> cssCanvasClients() const;
+ virtual GraphicsContext* drawingContext() const = 0;
+ virtual GraphicsContext* existingDrawingContext() const = 0;
+
+ virtual void makeRenderingResultsAvailable() = 0;
+ virtual void didDraw(const FloatRect&) = 0;
+
+ virtual AffineTransform baseTransform() const = 0;
+ virtual Image* copiedImage() const = 0;
+
protected:
CanvasBase(ScriptExecutionContext*);
Added: trunk/Source/WebCore/html/CustomPaintCanvas.cpp (0 => 237344)
--- trunk/Source/WebCore/html/CustomPaintCanvas.cpp (rev 0)
+++ trunk/Source/WebCore/html/CustomPaintCanvas.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,130 @@
+/*
+ * 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 "CustomPaintCanvas.h"
+
+#if ENABLE(CSS_PAINTING_API)
+
+#include "ImageBitmap.h"
+#include "PaintRenderingContext2D.h"
+
+namespace WebCore {
+
+Ref<CustomPaintCanvas> CustomPaintCanvas::create(ScriptExecutionContext& context, unsigned width, unsigned height)
+{
+ return adoptRef(*new CustomPaintCanvas(context, width, height));
+}
+
+CustomPaintCanvas::CustomPaintCanvas(ScriptExecutionContext& context, unsigned width, unsigned height)
+ : CanvasBase(&context)
+ , m_size(width, height)
+{
+}
+
+CustomPaintCanvas::~CustomPaintCanvas()
+{
+ m_context = nullptr; // Ensure this goes away before the ImageBuffer.
+}
+
+unsigned CustomPaintCanvas::width() const
+{
+ return m_size.width();
+}
+
+void CustomPaintCanvas::setWidth(unsigned newWidth)
+{
+ return m_size.setWidth(newWidth);
+}
+
+unsigned CustomPaintCanvas::height() const
+{
+ return m_size.height();
+}
+
+void CustomPaintCanvas::setHeight(unsigned newHeight)
+{
+ return m_size.setHeight(newHeight);
+}
+
+const IntSize& CustomPaintCanvas::size() const
+{
+ return m_size;
+}
+
+void CustomPaintCanvas::setSize(const IntSize& newSize)
+{
+ m_size = newSize;
+}
+
+ExceptionOr<RefPtr<PaintRenderingContext2D>> CustomPaintCanvas::getContext()
+{
+ if (m_context)
+ return { RefPtr<PaintRenderingContext2D> { &downcast<PaintRenderingContext2D>(*m_context) } };
+
+ m_context = PaintRenderingContext2D::create(*this);
+ downcast<PaintRenderingContext2D>(*m_context).setUsesDisplayListDrawing(true);
+ downcast<PaintRenderingContext2D>(*m_context).setTracksDisplayListReplay(false);
+
+ return { RefPtr<PaintRenderingContext2D> { &downcast<PaintRenderingContext2D>(*m_context) } };
+}
+
+Image* CustomPaintCanvas::copiedImage() const
+{
+ ASSERT(!m_destinationGraphicsContext);
+ if (!width() || !height())
+ return nullptr;
+
+ m_copiedBuffer = ImageBuffer::create(size(), Unaccelerated, 1, ColorSpaceSRGB, nullptr);
+ if (!m_copiedBuffer)
+ return nullptr;
+
+ m_destinationGraphicsContext = &m_copiedBuffer->context();
+ if (m_context)
+ m_context->paintRenderingResultsToCanvas();
+ m_destinationGraphicsContext = nullptr;
+
+ m_copiedImage = m_copiedBuffer->copyImage(m_copiedBuffer->fastCopyImageMode(), PreserveResolution::Yes);
+ return m_copiedImage.get();
+}
+
+GraphicsContext* CustomPaintCanvas::drawingContext() const
+{
+ return m_destinationGraphicsContext;
+}
+
+GraphicsContext* CustomPaintCanvas::existingDrawingContext() const
+{
+ return drawingContext();
+}
+
+void CustomPaintCanvas::makeRenderingResultsAvailable()
+{
+ if (m_context)
+ m_context->paintRenderingResultsToCanvas();
+}
+
+}
+#endif
Copied: trunk/Source/WebCore/html/CustomPaintCanvas.h (from rev 237342, trunk/Source/WebCore/html/OffscreenCanvas.h) (0 => 237344)
--- trunk/Source/WebCore/html/CustomPaintCanvas.h (rev 0)
+++ trunk/Source/WebCore/html/CustomPaintCanvas.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#if ENABLE(CSS_PAINTING_API)
+
+#include "AffineTransform.h"
+#include "CanvasBase.h"
+#include "EventTarget.h"
+#include "ExceptionOr.h"
+#include "ImageBuffer.h"
+#include "IntSize.h"
+#include "JSDOMPromiseDeferred.h"
+#include "ScriptWrappable.h"
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class ImageBitmap;
+class PaintRenderingContext2D;
+
+class CustomPaintCanvas final : public RefCounted<CustomPaintCanvas>, public CanvasBase {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+
+ static Ref<CustomPaintCanvas> create(ScriptExecutionContext&, unsigned width, unsigned height);
+ virtual ~CustomPaintCanvas();
+ bool isCustomPaintCanvas() const final { return true; }
+
+ unsigned width() const final;
+ void setWidth(unsigned);
+ unsigned height() const final;
+ void setHeight(unsigned);
+
+ const IntSize& size() const final;
+ void setSize(const IntSize&) final;
+
+ ExceptionOr<RefPtr<PaintRenderingContext2D>> getContext();
+
+ GraphicsContext* drawingContext() const final;
+ GraphicsContext* existingDrawingContext() const final;
+
+ void makeRenderingResultsAvailable() final;
+ void didDraw(const FloatRect&) final { }
+
+ AffineTransform baseTransform() const final { ASSERT(m_destinationGraphicsContext && m_copiedBuffer); return m_copiedBuffer->baseTransform(); }
+ Image* copiedImage() const final;
+
+ using RefCounted::ref;
+ using RefCounted::deref;
+
+private:
+ CustomPaintCanvas(ScriptExecutionContext&, unsigned width, unsigned height);
+
+ void refCanvasBase() final { ref(); }
+ void derefCanvasBase() final { deref(); }
+
+ mutable GraphicsContext* m_destinationGraphicsContext = nullptr;
+ mutable IntSize m_size;
+ mutable std::unique_ptr<ImageBuffer> m_copiedBuffer;
+ mutable RefPtr<Image> m_copiedImage;
+};
+
+}
+SPECIALIZE_TYPE_TRAITS_CANVAS(WebCore::CustomPaintCanvas, isCustomPaintCanvas())
+#endif
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (237343 => 237344)
--- trunk/Source/WebCore/html/HTMLCanvasElement.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -118,12 +118,12 @@
ExceptionOr<void> toBlob(ScriptExecutionContext&, Ref<BlobCallback>&&, const String& mimeType, JSC::JSValue quality);
// Used for rendering
- void didDraw(const FloatRect&);
+ void didDraw(const FloatRect&) final;
void paint(GraphicsContext&, const LayoutRect&);
- GraphicsContext* drawingContext() const;
- GraphicsContext* existingDrawingContext() const;
+ GraphicsContext* drawingContext() const final;
+ GraphicsContext* existingDrawingContext() const final;
#if ENABLE(MEDIA_STREAM)
RefPtr<MediaSample> toMediaSample();
@@ -131,7 +131,7 @@
#endif
ImageBuffer* buffer() const;
- Image* copiedImage() const;
+ Image* copiedImage() const final;
void clearCopiedImage();
RefPtr<ImageData> getImageData();
void makePresentationCopy();
@@ -139,9 +139,9 @@
SecurityOrigin* securityOrigin() const final;
- AffineTransform baseTransform() const;
+ AffineTransform baseTransform() const final;
- void makeRenderingResultsAvailable();
+ void makeRenderingResultsAvailable() final;
bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; }
bool shouldAccelerate(const IntSize&) const;
Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (237343 => 237344)
--- trunk/Source/WebCore/html/OffscreenCanvas.cpp 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -26,6 +26,7 @@
#include "config.h"
#include "OffscreenCanvas.h"
+#include "CanvasRenderingContext.h"
#include "ImageBitmap.h"
#include "WebGLRenderingContext.h"
@@ -42,7 +43,10 @@
{
}
-OffscreenCanvas::~OffscreenCanvas() = default;
+OffscreenCanvas::~OffscreenCanvas()
+{
+ m_context = nullptr;
+}
unsigned OffscreenCanvas::width() const
{
Modified: trunk/Source/WebCore/html/OffscreenCanvas.h (237343 => 237344)
--- trunk/Source/WebCore/html/OffscreenCanvas.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/OffscreenCanvas.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -25,6 +25,7 @@
#pragma once
+#include "AffineTransform.h"
#include "CanvasBase.h"
#include "EventTarget.h"
#include "ExceptionOr.h"
@@ -75,6 +76,15 @@
RefPtr<ImageBitmap> transferToImageBitmap();
// void convertToBlob(ImageEncodeOptions options);
+ GraphicsContext* drawingContext() const final { return nullptr; }
+ GraphicsContext* existingDrawingContext() const final { return nullptr; }
+
+ void makeRenderingResultsAvailable() final { }
+ void didDraw(const FloatRect&) final { }
+
+ AffineTransform baseTransform() const final { return { }; }
+ Image* copiedImage() const final { return nullptr; }
+
using RefCounted::ref;
using RefCounted::deref;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp (237343 => 237344)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -61,7 +61,7 @@
return false;
}
-bool CanvasRenderingContext::wouldTaintOrigin(const HTMLCanvasElement* sourceCanvas)
+bool CanvasRenderingContext::wouldTaintOrigin(const CanvasBase* sourceCanvas)
{
if (m_canvas.originClean() && sourceCanvas && !sourceCanvas->originClean())
return true;
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h (237343 => 237344)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -66,6 +66,7 @@
virtual bool isBitmapRenderer() const { return false; }
virtual bool isPlaceholder() const { return false; }
virtual bool isOffscreen2d() const { return false; }
+ virtual bool isPaint() const { return false; }
virtual void paintRenderingResultsToCanvas() {}
virtual PlatformLayer* platformLayer() const { return 0; }
@@ -76,7 +77,7 @@
protected:
explicit CanvasRenderingContext(CanvasBase&);
bool wouldTaintOrigin(const CanvasPattern*);
- bool wouldTaintOrigin(const HTMLCanvasElement*);
+ bool wouldTaintOrigin(const CanvasBase*);
bool wouldTaintOrigin(const HTMLImageElement*);
bool wouldTaintOrigin(const HTMLVideoElement*);
bool wouldTaintOrigin(const ImageBitmap*);
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (237343 => 237344)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -88,8 +88,13 @@
DisplayList::DisplayList displayList;
DisplayListDrawingContext(GraphicsContext& context, const FloatRect& clip)
+ : DisplayListDrawingContext(context.state(), clip)
+ {
+ }
+
+ DisplayListDrawingContext(const GraphicsContextState& state, const FloatRect& clip)
: context([&](GraphicsContext& displayListContext) {
- return std::make_unique<DisplayList::Recorder>(displayListContext, displayList, context.state(), clip, AffineTransform());
+ return std::make_unique<DisplayList::Recorder>(displayListContext, displayList, state, clip, AffineTransform());
})
{
}
@@ -146,8 +151,7 @@
// is cleared before destruction, to avoid assertions in the
// GraphicsContext dtor.
if (size_t stackSize = m_stateStack.size()) {
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- if (GraphicsContext* context = canvas.existingDrawingContext()) {
+ if (auto* context = canvasBase().existingDrawingContext()) {
while (--stackSize)
context->restore();
}
@@ -167,10 +171,7 @@
bool CanvasRenderingContext2DBase::isAccelerated() const
{
#if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- if (!canvas.hasCreatedImageBuffer())
- return false;
- auto* context = drawingContext();
+ auto* context = canvasBase().existingDrawingContext();
return context && context->isAcceleratedContext();
#else
return false;
@@ -401,9 +402,9 @@
if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentColor(style))
return;
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
+ if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) {
+ auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- if (style.isCurrentColor()) {
if (style.hasOverrideAlpha()) {
// FIXME: Should not use RGBA32 here.
style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvas).rgb(), style.overrideAlpha()));
@@ -430,9 +431,9 @@
if (state().fillStyle.isValid() && state().fillStyle.isEquivalentColor(style))
return;
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
+ if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) {
+ auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- if (style.isCurrentColor()) {
if (style.hasOverrideAlpha()) {
// FIXME: Should not use RGBA32 here.
style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvas).rgb(), style.overrideAlpha()));
@@ -928,8 +929,7 @@
realizeSaves();
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- c->setCTM(canvas.baseTransform());
+ c->setCTM(canvasBase().baseTransform());
modifiableState().transform = AffineTransform();
if (hasInvertibleTransform)
@@ -1727,9 +1727,8 @@
return;
c->save();
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- c->setCTM(canvas.baseTransform());
- c->clearRect(FloatRect(0, 0, canvas.width(), canvas.height()));
+ c->setCTM(canvasBase().baseTransform());
+ c->clearRect(FloatRect(0, 0, canvasBase().width(), canvasBase().height()));
c->restore();
}
@@ -1736,9 +1735,8 @@
Path CanvasRenderingContext2DBase::transformAreaToDevice(const Path& path) const
{
Path transformed(path);
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
transformed.transform(state().transform);
- transformed.transform(canvas.baseTransform());
+ transformed.transform(canvasBase().baseTransform());
return transformed;
}
@@ -1752,17 +1750,14 @@
bool CanvasRenderingContext2DBase::rectContainsCanvas(const FloatRect& rect) const
{
FloatQuad quad(rect);
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- FloatQuad canvasQuad(FloatRect(0, 0, canvas.width(), canvas.height()));
+ FloatQuad canvasQuad(FloatRect(0, 0, canvasBase().width(), canvasBase().height()));
return state().transform.mapQuad(quad).containsQuad(canvasQuad);
}
template<class T> IntRect CanvasRenderingContext2DBase::calculateCompositingBufferRect(const T& area, IntSize* croppedOffset)
{
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-
- IntRect canvasRect(0, 0, canvas.width(), canvas.height());
- canvasRect = canvas.baseTransform().mapRect(canvasRect);
+ IntRect canvasRect(0, 0, canvasBase().width(), canvasBase().height());
+ canvasRect = canvasBase().baseTransform().mapRect(canvasRect);
Path path = transformAreaToDevice(area);
IntRect bufferRect = enclosingIntRect(path.fastBoundingRect());
IntPoint originalLocation = bufferRect.location();
@@ -1779,9 +1774,8 @@
void CanvasRenderingContext2DBase::compositeBuffer(ImageBuffer& buffer, const IntRect& bufferRect, CompositeOperator op)
{
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- IntRect canvasRect(0, 0, canvas.width(), canvas.height());
- canvasRect = canvas.baseTransform().mapRect(canvasRect);
+ IntRect canvasRect(0, 0, canvasBase().width(), canvasBase().height());
+ canvasRect = canvasBase().baseTransform().mapRect(canvasRect);
auto* c = drawingContext();
if (!c)
@@ -1946,12 +1940,16 @@
return RefPtr<CanvasPattern> { CanvasPattern::create(*cachedImage->imageForRenderer(imageElement.renderer()), repeatX, repeatY, originClean) };
}
-ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(HTMLCanvasElement& canvas, bool repeatX, bool repeatY)
+ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(CanvasBase& canvas, bool repeatX, bool repeatY)
{
- if (!canvas.width() || !canvas.height() || !canvas.buffer())
+ if (!canvas.width() || !canvas.height())
return Exception { InvalidStateError };
+ auto* copiedImage = canvas.copiedImage();
- return RefPtr<CanvasPattern> { CanvasPattern::create(*canvas.copiedImage(), repeatX, repeatY, canvas.originClean()) };
+ if (!copiedImage)
+ return Exception { InvalidStateError };
+
+ return RefPtr<CanvasPattern> { CanvasPattern::create(*copiedImage, repeatX, repeatY, canvas.originClean()) };
}
#if ENABLE(VIDEO)
@@ -1988,8 +1986,7 @@
void CanvasRenderingContext2DBase::didDrawEntireCanvas()
{
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- didDraw(FloatRect(FloatPoint::zero(), canvas.size()), CanvasDidDrawApplyClip);
+ didDraw(FloatRect(FloatPoint::zero(), canvasBase().size()), CanvasDidDrawApplyClip);
}
void CanvasRenderingContext2DBase::didDraw(const FloatRect& r, unsigned options)
@@ -2034,8 +2031,7 @@
// we'd have to keep the clip path around.
}
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
- canvas.didDraw(dirtyRect);
+ canvasBase().didDraw(dirtyRect);
}
void CanvasRenderingContext2DBase::setTracksDisplayListReplay(bool tracksDisplayListReplay)
@@ -2075,11 +2071,9 @@
if (!m_recordingContext)
return;
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
+ FloatRect clip(FloatPoint::zero(), canvasBase().size());
+ DisplayList::Replayer replayer(*canvasBase().drawingContext(), m_recordingContext->displayList);
- FloatRect clip(FloatPoint::zero(), canvas.size());
- DisplayList::Replayer replayer(*canvas.drawingContext(), m_recordingContext->displayList);
-
if (UNLIKELY(m_tracksDisplayListReplay)) {
auto replayList = replayer.replay(clip, m_tracksDisplayListReplay);
contextDisplayListMap().add(this, WTFMove(replayList));
@@ -2092,14 +2086,13 @@
GraphicsContext* CanvasRenderingContext2DBase::drawingContext() const
{
- auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
if (UNLIKELY(m_usesDisplayListDrawing)) {
if (!m_recordingContext)
- m_recordingContext = std::make_unique<DisplayListDrawingContext>(*canvas.drawingContext(), FloatRect(FloatPoint::zero(), canvas.size()));
+ m_recordingContext = std::make_unique<DisplayListDrawingContext>(GraphicsContextState(), FloatRect(FloatPoint::zero(), canvasBase().size()));
return &m_recordingContext->context;
}
- return canvas.drawingContext();
+ return canvasBase().drawingContext();
}
static RefPtr<ImageData> createEmptyImageData(const IntSize& size)
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h (237343 => 237344)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -316,7 +316,7 @@
void setFillStyle(CanvasStyle);
ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLImageElement&, bool repeatX, bool repeatY);
- ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLCanvasElement&, bool repeatX, bool repeatY);
+ ExceptionOr<RefPtr<CanvasPattern>> createPattern(CanvasBase&, bool repeatX, bool repeatY);
#if ENABLE(VIDEO)
ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLVideoElement&, bool repeatX, bool repeatY);
#endif
Copied: trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp (from rev 237342, trunk/Source/WebCore/css/CSSPaintCallback.h) (0 => 237344)
--- trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp (rev 0)
+++ trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "PaintRenderingContext2D.h"
+
+#if ENABLE(CSS_PAINTING_API)
+
+namespace WebCore {
+
+std::unique_ptr<PaintRenderingContext2D> PaintRenderingContext2D::create(CanvasBase& canvas)
+{
+ return std::unique_ptr<PaintRenderingContext2D>(new PaintRenderingContext2D(canvas));
+}
+
+PaintRenderingContext2D::PaintRenderingContext2D(CanvasBase& canvas)
+ : CanvasRenderingContext2DBase(canvas, false, false)
+{
+}
+
+PaintRenderingContext2D::~PaintRenderingContext2D() = default;
+
+} // namespace WebCore
+#endif
Copied: trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.h (from rev 237342, trunk/Source/WebCore/css/CSSPaintCallback.h) (0 => 237344)
--- trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.h (rev 0)
+++ trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,51 @@
+/*
+ * 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
+
+#include "CanvasRenderingContext2DBase.h"
+
+#if ENABLE(CSS_PAINTING_API)
+
+#include "CustomPaintCanvas.h"
+
+namespace WebCore {
+
+class PaintRenderingContext2D final : public CanvasRenderingContext2DBase {
+public:
+ static std::unique_ptr<PaintRenderingContext2D> create(CanvasBase&);
+
+ virtual ~PaintRenderingContext2D();
+
+ bool isPaint() const override { return true; }
+ CustomPaintCanvas& canvas() const { return downcast<CustomPaintCanvas>(canvasBase()); }
+
+private:
+ PaintRenderingContext2D(CanvasBase&);
+};
+
+} // namespace WebCore
+SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::PaintRenderingContext2D, isPaint())
+#endif
Copied: trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.idl (from rev 237342, trunk/Source/WebCore/css/CSSPaintCallback.idl) (0 => 237344)
--- trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.idl (rev 0)
+++ trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.idl 2018-10-23 00:46:14 UTC (rev 237344)
@@ -0,0 +1,45 @@
+/*
+* 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.
+*/
+
+[
+ CustomIsReachable,
+ EnabledAtRuntime=CSSPaintingAPI,
+ Conditional=CSS_PAINTING_API,
+ JSGenerateToJSObject,
+ JSCustomMarkFunction,
+] interface PaintRenderingContext2D {
+};
+
+PaintRenderingContext2D implements CanvasState;
+PaintRenderingContext2D implements CanvasTransform;
+PaintRenderingContext2D implements CanvasCompositing;
+PaintRenderingContext2D implements CanvasImageSmoothing;
+PaintRenderingContext2D implements CanvasFillStrokeStyles;
+PaintRenderingContext2D implements CanvasShadowStyles;
+PaintRenderingContext2D implements CanvasRect;
+PaintRenderingContext2D implements CanvasDrawPath;
+PaintRenderingContext2D implements CanvasDrawImage;
+PaintRenderingContext2D implements CanvasPathDrawingStyles;
+PaintRenderingContext2D implements CanvasPath;
Modified: trunk/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h (237343 => 237344)
--- trunk/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h 2018-10-23 00:46:14 UTC (rev 237344)
@@ -27,8 +27,8 @@
#if ENABLE(WEBMETAL)
-#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
namespace WebCore {
Modified: trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp (237343 => 237344)
--- trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp 2018-10-23 00:35:41 UTC (rev 237343)
+++ trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp 2018-10-23 00:46:14 UTC (rev 237344)
@@ -28,12 +28,12 @@
#if ENABLE(CSS_PAINTING_API)
+#include "CustomPaintCanvas.h"
#include "GraphicsContext.h"
#include "ImageBitmap.h"
#include "ImageBuffer.h"
#include "JSCSSPaintCallback.h"
-#include "OffscreenCanvas.h"
-#include "WebGLRenderingContext.h"
+#include "PaintRenderingContext2D.h"
namespace WebCore {
@@ -51,29 +51,24 @@
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, { });
+ 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();
- 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)
+ UNUSED_PARAM(destContext);
+ auto image = canvas->copiedImage();
+ if (!image)
return ImageDrawResult::DidNothing;
- destContext.drawImage(*bitmap->buffer()->copyImage(), FloatPoint());
+ destContext.drawImage(*image, FloatPoint());
return ImageDrawResult::DidDraw;
}