WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-190762-20181019152039.patch (text/plain), 55.40 KB, created by
Justin Michaud
on 2018-10-19 15:20:40 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Michaud
Created:
2018-10-19 15:20:40 PDT
Size:
55.40 KB
patch
obsolete
>Subversion Revision: 237300 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index ed83d2fe47a885f60486eb2e1bc4f3569a0cc97c..2f81419ada3dc8e47cba641b06fbe754066d3129 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,84 @@ >+2018-10-19 Justin Michaud <justin_michaud@apple.com> >+ >+ CSS Paint API should give a 2d rendering context >+ https://bugs.webkit.org/show_bug.cgi?id=190762 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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: Added. >+ (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::buffer const): >+ (WebCore::CustomPaintCanvas::copiedImage const): >+ (WebCore::CustomPaintCanvas::drawingContext const): >+ (WebCore::CustomPaintCanvas::existingDrawingContext const): >+ (WebCore::CustomPaintCanvas::createImageBuffer const): >+ (WebCore::CustomPaintCanvas::setImageBuffer 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::CanvasRenderingContext2DBase::unwindStateStack): >+ (WebCore::CanvasRenderingContext2DBase::isAccelerated const): >+ (WebCore::CanvasRenderingContext2DBase::setStrokeStyle): >+ (WebCore::CanvasRenderingContext2DBase::setFillStyle): >+ (WebCore::CanvasRenderingContext2DBase::resetTransform): >+ (WebCore::CanvasRenderingContext2DBase::drawImage): >+ (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): >+ (WebCore::CanvasRenderingContext2DBase::getImageData const): >+ (WebCore::CanvasRenderingContext2DBase::putImageData): >+ (WebCore::CanvasRenderingContext2DBase::platformLayer 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-19 Zalan Bujtas <zalan@apple.com> > > [LFC][IFC] RenderReplaced renderer should create InlineBox >diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt >index 8b02a52d50d01d77ec1e3610cc7872612634e938..a596405209e63b3a4d226b6fbcce7fe70440cc98 100644 >--- a/Source/WebCore/CMakeLists.txt >+++ b/Source/WebCore/CMakeLists.txt >@@ -803,6 +803,7 @@ set(WebCore_NON_SVG_IDL_FILES > 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 >diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make >index 15a5d6bd95e76df012d4f73826e050fff8ec9636..ed9653f8a1651d243b17900b274706498ff19c55 100644 >--- a/Source/WebCore/DerivedSources.make >+++ b/Source/WebCore/DerivedSources.make >@@ -726,6 +726,7 @@ JS_BINDING_IDLS = \ > $(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 \ >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 0463d1579e4c62d93012c0615e932ba74f163d3a..f3c2792f95dab0fe4a91da1181cf3a336e1098c8 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -443,6 +443,7 @@ bindings/js/JSNodeCustom.cpp > 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 >@@ -968,6 +969,7 @@ html/ButtonInputType.cpp > html/CanvasBase.cpp > html/CheckboxInputType.cpp > html/ColorInputType.cpp >+html/CustomPaintCanvas.cpp > html/DOMFormData.cpp > html/DOMTokenList.cpp > html/DOMURL.cpp >@@ -1126,6 +1128,7 @@ html/canvas/CanvasRenderingContext2DBase.cpp > 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 >@@ -2843,6 +2846,7 @@ JSOfflineAudioCompletionEvent.cpp > JSOfflineAudioContext.cpp > JSOffscreenCanvas.cpp > JSOffscreenCanvasRenderingContext2D.cpp >+JSPaintRenderingContext2D.cpp > JSOscillatorNode.cpp > JSOverconstrainedError.cpp > JSOverconstrainedErrorEvent.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index ba15fcf1deec04fea6436c30a581c6b2d253aaee..a1b9bc39baa5b9e01ba984c9b64c818a098030da 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -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>"; }; >@@ -17628,6 +17636,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 */, >@@ -20205,6 +20216,7 @@ > BCD9C2610C17AA67005C90A2 /* JSNodeListCustom.cpp */, > AD20B18C18E9D216005A8083 /* JSNodeListCustom.h */, > 3140C52B1FE06B4900D2A873 /* JSOffscreenCanvasRenderingContext2DCustom.cpp */, >+ 4B1E13EE217941320042CF98 /* JSPaintRenderingContext2DCustom.cpp */, > CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */, > 833CF70F20DB3F5F00141BCC /* JSPerformanceObserverCustom.cpp */, > A4A69B8BB91B49D0A804C31D /* JSPromiseRejectionEventCustom.cpp */, >@@ -20771,6 +20783,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 */, >@@ -28089,6 +28103,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 */, >@@ -30114,6 +30129,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 */, >diff --git a/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp b/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..2b77fc9776b8d0de4e8f77989291770de24c108a >--- /dev/null >+++ b/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp >@@ -0,0 +1,50 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * This library is free software; you can redistribute it and/or >+ * modify it under the terms of the GNU Library General Public >+ * License as published by the Free Software Foundation; either >+ * version 2 of the License, or (at your option) any later version. >+ * >+ * This library is distributed in the hope that it will be useful, >+ * but WITHOUT ANY WARRANTY; without even the implied warranty of >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >+ * Library General Public License for more details. >+ * >+ * You should have received a copy of the GNU Library General Public License >+ * along with this library; see the file COPYING.LIB. If not, write to >+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, >+ * Boston, MA 02110-1301, USA. >+ */ >+ >+#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 >+ >diff --git a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >index 024930d15c4b4d023313178b1405d782a45f6d71..0085ad7efdbd3cf91117925d0e1703862244ec75 100644 >--- a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >+++ b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >@@ -113,6 +113,7 @@ namespace WebCore { > macro(NavigatorUserMedia) \ > macro(OffscreenCanvas) \ > macro(OffscreenCanvasRenderingContext2D) \ >+ macro(PaintRenderingContext2D) \ > macro(PaymentAddress) \ > macro(PaymentMethodChangeEvent) \ > macro(PaymentRequest) \ >diff --git a/Source/WebCore/css/CSSPaintCallback.h b/Source/WebCore/css/CSSPaintCallback.h >index f0ec2c44135ae44cc893506d85a5075963b23136..f21e678bc91fd0b2bb63e11bb5956c41a7f709de 100644 >--- a/Source/WebCore/css/CSSPaintCallback.h >+++ b/Source/WebCore/css/CSSPaintCallback.h >@@ -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() > { >diff --git a/Source/WebCore/css/CSSPaintCallback.idl b/Source/WebCore/css/CSSPaintCallback.idl >index 76d9b6c95ba1cf8d2952a479d1c5307494cc809c..2941473a030bc81c5fb6ddd23a7cd9cf310535bc 100644 >--- a/Source/WebCore/css/CSSPaintCallback.idl >+++ b/Source/WebCore/css/CSSPaintCallback.idl >@@ -26,4 +26,4 @@ > [ > EnabledAtRuntime=CSSPaintingAPI, > Conditional=CSS_PAINTING_API, >-] callback CSSPaintCallback = void (WebGLRenderingContext context); >+] callback CSSPaintCallback = void (PaintRenderingContext2D context); >diff --git a/Source/WebCore/html/CanvasBase.cpp b/Source/WebCore/html/CanvasBase.cpp >index 85939b274f590b00cc83a3797b799696ddd6a8c2..f4f3c5ea384801d1ed4602d96daa032770d670c2 100644 >--- a/Source/WebCore/html/CanvasBase.cpp >+++ b/Source/WebCore/html/CanvasBase.cpp >@@ -41,6 +41,7 @@ CanvasBase::CanvasBase(ScriptExecutionContext* scriptExecutionContext) > > CanvasBase::~CanvasBase() > { >+ ASSERT(!m_context); // Should have been set to null by base class > notifyObserversCanvasDestroyed(); > } > >diff --git a/Source/WebCore/html/CanvasBase.h b/Source/WebCore/html/CanvasBase.h >index 5dfe29352e1534f6620c5366beb98441a1f472f7..c91b5c96009045778cfe342318c4a9ef2998ff5d 100644 >--- a/Source/WebCore/html/CanvasBase.h >+++ b/Source/WebCore/html/CanvasBase.h >@@ -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 @@ public: > > 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,18 @@ public: > > 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 bool hasCreatedImageBuffer() const = 0; >+ virtual ImageBuffer* buffer() const = 0; >+ virtual Image* copiedImage() const = 0; >+ > protected: > CanvasBase(ScriptExecutionContext*); > >diff --git a/Source/WebCore/html/CustomPaintCanvas.cpp b/Source/WebCore/html/CustomPaintCanvas.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..69b6f70d94c73c3f204477e42fd69bf091547f6d >--- /dev/null >+++ b/Source/WebCore/html/CustomPaintCanvas.cpp >@@ -0,0 +1,156 @@ >+/* >+ * 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); >+ if (!m_context) >+ return { nullptr }; >+ >+ return { RefPtr<PaintRenderingContext2D> { &downcast<PaintRenderingContext2D>(*m_context) } }; >+} >+ >+ImageBuffer* CustomPaintCanvas::buffer() const >+{ >+ if (!m_hasCreatedImageBuffer) >+ createImageBuffer(); >+ return m_imageBuffer.get(); >+} >+ >+Image* CustomPaintCanvas::copiedImage() const >+{ >+ if (buffer()) { >+ if (m_context) >+ m_context->paintRenderingResultsToCanvas(); >+ m_copiedImage = buffer()->copyImage(CopyBackingStore, PreserveResolution::Yes); >+ } >+ return m_copiedImage.get(); >+} >+ >+GraphicsContext* CustomPaintCanvas::drawingContext() const >+{ >+ return buffer() ? &m_imageBuffer->context() : nullptr; >+} >+ >+GraphicsContext* CustomPaintCanvas::existingDrawingContext() const >+{ >+ if (!m_hasCreatedImageBuffer) >+ return nullptr; >+ >+ return drawingContext(); >+} >+ >+void CustomPaintCanvas::createImageBuffer() const >+{ >+ ASSERT(!m_imageBuffer); >+ >+ m_hasCreatedImageBuffer = true; >+ >+ if (!width() || !height()) >+ return; >+ >+ RenderingMode renderingMode = Unaccelerated; >+ >+ setImageBuffer(ImageBuffer::create(size(), renderingMode, 1, ColorSpaceSRGB, nullptr)); >+ if (!m_imageBuffer) >+ return; >+ m_imageBuffer->context().setShadowsIgnoreTransforms(true); >+ m_imageBuffer->context().setStrokeThickness(1); >+} >+ >+void CustomPaintCanvas::setImageBuffer(std::unique_ptr<ImageBuffer>&& buffer) const >+{ >+ m_imageBuffer = WTFMove(buffer); >+ if (m_imageBuffer && m_size != m_imageBuffer->internalSize()) >+ m_size = m_imageBuffer->internalSize(); >+} >+ >+void CustomPaintCanvas::makeRenderingResultsAvailable() >+{ >+ if (m_context) >+ m_context->paintRenderingResultsToCanvas(); >+} >+ >+} >+#endif >diff --git a/Source/WebCore/html/CustomPaintCanvas.h b/Source/WebCore/html/CustomPaintCanvas.h >new file mode 100644 >index 0000000000000000000000000000000000000000..523d83a48fa092dcd42b17eb7855377337b68037 >--- /dev/null >+++ b/Source/WebCore/html/CustomPaintCanvas.h >@@ -0,0 +1,97 @@ >+/* >+ * 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_hasCreatedImageBuffer); return m_imageBuffer->baseTransform(); } >+ >+ bool hasCreatedImageBuffer() const final { return m_hasCreatedImageBuffer; } >+ ImageBuffer* buffer() const final; >+ 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(); } >+ >+ void createImageBuffer() const; >+ void setImageBuffer(std::unique_ptr<ImageBuffer>&&) const; >+ >+ mutable IntSize m_size; >+ mutable bool m_hasCreatedImageBuffer { false }; >+ mutable std::unique_ptr<ImageBuffer> m_imageBuffer; >+ mutable RefPtr<Image> m_copiedImage; >+}; >+ >+} >+SPECIALIZE_TYPE_TRAITS_CANVAS(WebCore::CustomPaintCanvas, isCustomPaintCanvas()) >+#endif >diff --git a/Source/WebCore/html/HTMLCanvasElement.h b/Source/WebCore/html/HTMLCanvasElement.h >index 2df9c0b30f5606d8bee6c1c818779c6b1e48e88c..34cbfeabcc0195619406c2373ce02bd766752549 100644 >--- a/Source/WebCore/html/HTMLCanvasElement.h >+++ b/Source/WebCore/html/HTMLCanvasElement.h >@@ -112,20 +112,20 @@ public: > 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(); > ExceptionOr<Ref<MediaStream>> captureStream(ScriptExecutionContext&, std::optional<double>&& frameRequestRate); > #endif > >- ImageBuffer* buffer() const; >- Image* copiedImage() const; >+ ImageBuffer* buffer() const final; >+ Image* copiedImage() const final; > void clearCopiedImage(); > RefPtr<ImageData> getImageData(); > void makePresentationCopy(); >@@ -133,10 +133,10 @@ public: > > SecurityOrigin* securityOrigin() const final; > >- AffineTransform baseTransform() const; >+ AffineTransform baseTransform() const final; > >- void makeRenderingResultsAvailable(); >- bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; } >+ void makeRenderingResultsAvailable() final; >+ bool hasCreatedImageBuffer() const final { return m_hasCreatedImageBuffer; } > > bool shouldAccelerate(const IntSize&) const; > >diff --git a/Source/WebCore/html/OffscreenCanvas.h b/Source/WebCore/html/OffscreenCanvas.h >index c272ed6e999f8c0209b474b676a840da0e68926c..bda1c0fa82b09973107c8f82ef0d340d0378f9ba 100644 >--- a/Source/WebCore/html/OffscreenCanvas.h >+++ b/Source/WebCore/html/OffscreenCanvas.h >@@ -25,6 +25,7 @@ > > #pragma once > >+#include "AffineTransform.h" > #include "CanvasBase.h" > #include "EventTarget.h" > #include "ExceptionOr.h" >@@ -75,6 +76,18 @@ public: > 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 { }; } >+ >+ bool hasCreatedImageBuffer() const final { return false; } >+ ImageBuffer* buffer() const final { return nullptr; } >+ Image* copiedImage() const final { return nullptr; } >+ > using RefCounted::ref; > using RefCounted::deref; > >diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext.cpp >index c34610215e569fe7aa119ca5216a7d83e1556229..3361438f1ef233699d0eda3521c056de67baed25 100644 >--- a/Source/WebCore/html/canvas/CanvasRenderingContext.cpp >+++ b/Source/WebCore/html/canvas/CanvasRenderingContext.cpp >@@ -61,7 +61,7 @@ bool CanvasRenderingContext::wouldTaintOrigin(const CanvasPattern* pattern) > return false; > } > >-bool CanvasRenderingContext::wouldTaintOrigin(const HTMLCanvasElement* sourceCanvas) >+bool CanvasRenderingContext::wouldTaintOrigin(const CanvasBase* sourceCanvas) > { > if (m_canvas.originClean() && sourceCanvas && !sourceCanvas->originClean()) > return true; >diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext.h b/Source/WebCore/html/canvas/CanvasRenderingContext.h >index 2d2d887579018d0fafdaadfae6d22c1eb39041e2..f0071c2ce2f408072983b0c5b36512a57652ad1a 100644 >--- a/Source/WebCore/html/canvas/CanvasRenderingContext.h >+++ b/Source/WebCore/html/canvas/CanvasRenderingContext.h >@@ -63,6 +63,7 @@ public: > 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; } >@@ -73,7 +74,7 @@ public: > 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*); >diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp >index 144e68decc56b96c5598bcb98951e739dd179fb7..005cc704b6be987c19bc3e13167d926c84261231 100644 >--- a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp >+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp >@@ -146,8 +146,7 @@ void CanvasRenderingContext2DBase::unwindStateStack() > // 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,8 +166,7 @@ CanvasRenderingContext2DBase::~CanvasRenderingContext2DBase() > bool CanvasRenderingContext2DBase::isAccelerated() const > { > #if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS) >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >- if (!canvas.hasCreatedImageBuffer()) >+ if (!canvasBase().hasCreatedImageBuffer()) > return false; > auto* context = drawingContext(); > return context && context->isAcceleratedContext(); >@@ -401,9 +399,9 @@ void CanvasRenderingContext2DBase::setStrokeStyle(CanvasStyle style) > 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 +428,9 @@ void CanvasRenderingContext2DBase::setFillStyle(CanvasStyle style) > 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 +926,7 @@ void CanvasRenderingContext2DBase::resetTransform() > > realizeSaves(); > >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >- c->setCTM(canvas.baseTransform()); >+ c->setCTM(canvasBase().baseTransform()); > modifiableState().transform = AffineTransform(); > > if (hasInvertibleTransform) >@@ -1565,7 +1562,7 @@ ExceptionOr<void> CanvasRenderingContext2DBase::drawImage(HTMLImageElement& imag > return { }; > } > >-ExceptionOr<void> CanvasRenderingContext2DBase::drawImage(HTMLCanvasElement& sourceCanvas, const FloatRect& srcRect, const FloatRect& dstRect) >+ExceptionOr<void> CanvasRenderingContext2DBase::drawImage(CanvasBase& sourceCanvas, const FloatRect& srcRect, const FloatRect& dstRect) > { > FloatRect srcCanvasRect = FloatRect(FloatPoint(), sourceCanvas.size()); > >@@ -1727,18 +1724,16 @@ void CanvasRenderingContext2DBase::clearCanvas() > 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(); > } > > 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 +1747,14 @@ Path CanvasRenderingContext2DBase::transformAreaToDevice(const FloatRect& rect) > 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 +1771,8 @@ std::unique_ptr<ImageBuffer> CanvasRenderingContext2DBase::createCompositingBuff > > 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,7 +1937,7 @@ ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(H > 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()) > return Exception { InvalidStateError }; >@@ -1988,8 +1979,7 @@ ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(I > > 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 +2024,7 @@ void CanvasRenderingContext2DBase::didDraw(const FloatRect& r, unsigned options) > // 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,10 +2064,8 @@ void CanvasRenderingContext2DBase::paintRenderingResultsToCanvas() > if (!m_recordingContext) > return; > >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >- >- FloatRect clip(FloatPoint::zero(), canvas.size()); >- DisplayList::Replayer replayer(*canvas.drawingContext(), m_recordingContext->displayList); >+ FloatRect clip(FloatPoint::zero(), canvasBase().size()); >+ DisplayList::Replayer replayer(*canvasBase().drawingContext(), m_recordingContext->displayList); > > if (UNLIKELY(m_tracksDisplayListReplay)) { > auto replayList = replayer.replay(clip, m_tracksDisplayListReplay); >@@ -2092,14 +2079,13 @@ void CanvasRenderingContext2DBase::paintRenderingResultsToCanvas() > > 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>(*canvasBase().drawingContext(), FloatRect(FloatPoint::zero(), canvasBase().size())); > return &m_recordingContext->context; > } > >- return canvas.drawingContext(); >+ return canvasBase().drawingContext(); > } > > static RefPtr<ImageData> createEmptyImageData(const IntSize& size) >@@ -2167,9 +2153,8 @@ ExceptionOr<RefPtr<ImageData>> CanvasRenderingContext2DBase::getImageData(ImageB > return nullptr; > > IntRect imageDataRect = enclosingIntRect(logicalRect); >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); > >- ImageBuffer* buffer = canvas.buffer(); >+ ImageBuffer* buffer = canvasBase().buffer(); > if (!buffer) > return createEmptyImageData(imageDataRect.size()); > >@@ -2200,9 +2185,7 @@ void CanvasRenderingContext2DBase::putImageData(ImageData& data, float dx, float > > void CanvasRenderingContext2DBase::putImageData(ImageData& data, ImageBuffer::CoordinateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight) > { >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >- >- ImageBuffer* buffer = canvas.buffer(); >+ ImageBuffer* buffer = canvasBase().buffer(); > if (!buffer) > return; > >@@ -2255,9 +2238,7 @@ void CanvasRenderingContext2DBase::inflateStrokeRect(FloatRect& rect) const > > PlatformLayer* CanvasRenderingContext2DBase::platformLayer() const > { >- auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); >- >- return canvas.buffer() ? canvas.buffer()->platformLayer() : nullptr; >+ return canvasBase().buffer() ? canvasBase().buffer()->platformLayer() : nullptr; > } > > #endif >diff --git a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h >index 65548ad1f496b0ac0360613735e9b36e15374961..47242a7857042f94f6049f5d3392f749b9cc7f80 100644 >--- a/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h >+++ b/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h >@@ -316,7 +316,7 @@ protected: > 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 >@@ -324,7 +324,7 @@ protected: > > ExceptionOr<void> drawImage(HTMLImageElement&, const FloatRect& srcRect, const FloatRect& dstRect); > ExceptionOr<void> drawImage(HTMLImageElement&, const FloatRect& srcRect, const FloatRect& dstRect, const CompositeOperator&, const BlendMode&); >- ExceptionOr<void> drawImage(HTMLCanvasElement&, const FloatRect& srcRect, const FloatRect& dstRect); >+ ExceptionOr<void> drawImage(CanvasBase&, const FloatRect& srcRect, const FloatRect& dstRect); > #if ENABLE(VIDEO) > ExceptionOr<void> drawImage(HTMLVideoElement&, const FloatRect& srcRect, const FloatRect& dstRect); > #endif >diff --git a/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp b/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..bae1fca21043f203ab6193d091dbab4d6b0e8fd8 >--- /dev/null >+++ b/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp >@@ -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 >diff --git a/Source/WebCore/html/canvas/PaintRenderingContext2D.h b/Source/WebCore/html/canvas/PaintRenderingContext2D.h >new file mode 100644 >index 0000000000000000000000000000000000000000..3d8a4049512da26261633afff9b2a4aa87a13e15 >--- /dev/null >+++ b/Source/WebCore/html/canvas/PaintRenderingContext2D.h >@@ -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 >diff --git a/Source/WebCore/html/canvas/PaintRenderingContext2D.idl b/Source/WebCore/html/canvas/PaintRenderingContext2D.idl >new file mode 100644 >index 0000000000000000000000000000000000000000..3c4385bb9c2f1fef242c690cd5c2474879469d80 >--- /dev/null >+++ b/Source/WebCore/html/canvas/PaintRenderingContext2D.idl >@@ -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; >diff --git a/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h b/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h >index 26bc3e0c75a2211146c43eeafccafbd7e098331c..edd4b057e462101bd827b64bc26a718edfbfd5bd 100644 >--- a/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h >+++ b/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h >@@ -27,8 +27,8 @@ > > #if ENABLE(WEBMETAL) > >-#include <wtf/Ref.h> > #include <wtf/RefCounted.h> >+#include <wtf/RefPtr.h> > > namespace WebCore { > >diff --git a/Source/WebCore/platform/graphics/CustomPaintImage.cpp b/Source/WebCore/platform/graphics/CustomPaintImage.cpp >index 8b34936279c4c619bfeef53d0846d87c921d01ce..d2e42c0c9e6199f5274291670f17a06e9de820fb 100644 >--- a/Source/WebCore/platform/graphics/CustomPaintImage.cpp >+++ b/Source/WebCore/platform/graphics/CustomPaintImage.cpp >@@ -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 @@ ImageDrawResult CustomPaintImage::doCustomPaint(GraphicsContext& destContext, co > 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; > } >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 8b7b34631af2ff7490791ceea7935cfa341b7238..ec2346a73a9188c81a13948be0375bf43f735113 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,12 @@ >+2018-10-19 Justin Michaud <justin_michaud@apple.com> >+ >+ CSS Paint API should give a 2d rendering context >+ https://bugs.webkit.org/show_bug.cgi?id=190762 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * fast/css-custom-paint/basic.html: >+ > 2018-10-19 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r237254. >diff --git a/LayoutTests/fast/css-custom-paint/basic.html b/LayoutTests/fast/css-custom-paint/basic.html >index cf3afe834516f7f01b072616d2f926a9faabef02..3f4dc3a2d02ef21a2e972d4c8b4f2fae8c389458 100644 >--- a/LayoutTests/fast/css-custom-paint/basic.html >+++ b/LayoutTests/fast/css-custom-paint/basic.html >@@ -8,8 +8,8 @@ > <style> > #paint { > background-image: paint(my-paint); >- width: 50px; >- height: 50px; >+ width: 150px; >+ height: 150px; > } > </style> > >@@ -70,8 +70,13 @@ let paint_called_test = async_test('test that test div paint callback gets calle > 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(); > } > });
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 190762
:
352825
|
352828
|
352849
|
352911
|
352921
|
352929