Changeset 237344 in webkit
- Timestamp:
- Oct 22, 2018 5:46:14 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 21 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r237342 r237344 1 2018-10-22 Justin Michaud <justin_michaud@apple.com> 2 3 CSS Paint API should give a 2d rendering context 4 https://bugs.webkit.org/show_bug.cgi?id=190762 5 6 Reviewed by Dean Jackson. 7 8 * fast/css-custom-paint/basic.html: 9 1 10 2018-10-22 Ryan Haddad <ryanhaddad@apple.com> 2 11 -
trunk/LayoutTests/fast/css-custom-paint/basic.html
r237276 r237344 9 9 #paint { 10 10 background-image: paint(my-paint); 11 width: 50px;12 height: 50px;11 width: 150px; 12 height: 150px; 13 13 } 14 14 </style> … … 71 71 CSS.paintWorkletGlobalScope.registerPaint('my-paint', class { 72 72 paint(ctx, geom, properties) { 73 ctx.clearColor(0,1.0,0,1.0); 74 ctx.clear(ctx.COLOR_BUFFER_BIT); 73 for (var i = 0; i < 6; i++){ 74 for (var j = 0; j < 6; j++){ 75 ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ',' + 76 Math.floor(255 - 42.5 * j) + ',0)'; 77 ctx.fillRect(j * 25, i * 25, 25, 25); 78 } 79 } 75 80 paint_called_test.done(); 76 81 } -
trunk/Source/WebCore/CMakeLists.txt
r237306 r237344 807 807 html/canvas/ImageSmoothingQuality.idl 808 808 html/canvas/OffscreenCanvasRenderingContext2D.idl 809 html/canvas/PaintRenderingContext2D.idl 809 810 html/canvas/Path2D.idl 810 811 html/canvas/WebMetalBuffer.idl -
trunk/Source/WebCore/ChangeLog
r237340 r237344 1 2018-10-22 Justin Michaud <justin_michaud@apple.com> 2 3 CSS Paint API should give a 2d rendering context 4 https://bugs.webkit.org/show_bug.cgi?id=190762 5 6 Reviewed by Dean Jackson. 7 8 Add a new type of canvas and 2d rendering context to support the CSS Painting API. 9 Make many of the methods from HTMLCanvasElement virtual functions on CanvasBase, and 10 remove many of the downcasts in CanvasRenderingContext2DBase as a result. 11 12 * CMakeLists.txt: 13 * DerivedSources.make: 14 * Sources.txt: 15 * WebCore.xcodeproj/project.pbxproj: 16 * bindings/js/JSPaintRenderingContext2DCustom.cpp: Copied from Source/WebCore/css/CSSPaintCallback.h. 17 (WebCore::root): 18 (WebCore::JSPaintRenderingContext2DOwner::isReachableFromOpaqueRoots): 19 (WebCore::JSPaintRenderingContext2D::visitAdditionalChildren): 20 * bindings/js/WebCoreBuiltinNames.h: 21 * css/CSSPaintCallback.h: 22 * css/CSSPaintCallback.idl: 23 * html/CanvasBase.cpp: 24 (WebCore::CanvasBase::~CanvasBase): 25 * html/CanvasBase.h: 26 (WebCore::CanvasBase::isCustomPaintCanvas const): 27 * html/CustomPaintCanvas.cpp: Added. 28 (WebCore::CustomPaintCanvas::create): 29 (WebCore::CustomPaintCanvas::CustomPaintCanvas): 30 (WebCore::CustomPaintCanvas::~CustomPaintCanvas): 31 (WebCore::CustomPaintCanvas::width const): 32 (WebCore::CustomPaintCanvas::setWidth): 33 (WebCore::CustomPaintCanvas::height const): 34 (WebCore::CustomPaintCanvas::setHeight): 35 (WebCore::CustomPaintCanvas::size const): 36 (WebCore::CustomPaintCanvas::setSize): 37 (WebCore::CustomPaintCanvas::getContext): 38 (WebCore::CustomPaintCanvas::copiedImage const): 39 (WebCore::CustomPaintCanvas::drawingContext const): 40 (WebCore::CustomPaintCanvas::existingDrawingContext const): 41 (WebCore::CustomPaintCanvas::makeRenderingResultsAvailable): 42 * html/CustomPaintCanvas.h: Copied from Source/WebCore/html/OffscreenCanvas.h. 43 * html/HTMLCanvasElement.h: 44 * html/OffscreenCanvas.h: 45 * html/canvas/CanvasRenderingContext.cpp: 46 (WebCore::CanvasRenderingContext::wouldTaintOrigin): 47 * html/canvas/CanvasRenderingContext.h: 48 (WebCore::CanvasRenderingContext::isPaint const): 49 * html/canvas/CanvasRenderingContext2DBase.cpp: 50 (WebCore::DisplayListDrawingContext::DisplayListDrawingContext): 51 (WebCore::CanvasRenderingContext2DBase::unwindStateStack): 52 (WebCore::CanvasRenderingContext2DBase::isAccelerated const): 53 (WebCore::CanvasRenderingContext2DBase::setStrokeStyle): 54 (WebCore::CanvasRenderingContext2DBase::setFillStyle): 55 (WebCore::CanvasRenderingContext2DBase::resetTransform): 56 (WebCore::CanvasRenderingContext2DBase::clearCanvas): 57 (WebCore::CanvasRenderingContext2DBase::transformAreaToDevice const): 58 (WebCore::CanvasRenderingContext2DBase::rectContainsCanvas const): 59 (WebCore::CanvasRenderingContext2DBase::calculateCompositingBufferRect): 60 (WebCore::CanvasRenderingContext2DBase::compositeBuffer): 61 (WebCore::CanvasRenderingContext2DBase::createPattern): 62 (WebCore::CanvasRenderingContext2DBase::didDrawEntireCanvas): 63 (WebCore::CanvasRenderingContext2DBase::didDraw): 64 (WebCore::CanvasRenderingContext2DBase::paintRenderingResultsToCanvas): 65 (WebCore::CanvasRenderingContext2DBase::drawingContext const): 66 * html/canvas/CanvasRenderingContext2DBase.h: 67 * html/canvas/PaintRenderingContext2D.cpp: Copied from Source/WebCore/css/CSSPaintCallback.h. 68 (WebCore::PaintRenderingContext2D::create): 69 (WebCore::PaintRenderingContext2D::PaintRenderingContext2D): 70 * html/canvas/PaintRenderingContext2D.h: Copied from Source/WebCore/css/CSSPaintCallback.h. 71 * html/canvas/PaintRenderingContext2D.idl: Copied from Source/WebCore/css/CSSPaintCallback.idl. 72 * html/canvas/WebMetalRenderPassAttachmentDescriptor.h: 73 * platform/graphics/CustomPaintImage.cpp: 74 (WebCore::CustomPaintImage::doCustomPaint): 75 1 76 2018-10-22 Keith Rollin <krollin@apple.com> 2 77 -
trunk/Source/WebCore/DerivedSources.make
r237306 r237344 730 730 $(WebCore)/html/canvas/OESVertexArrayObject.idl \ 731 731 $(WebCore)/html/canvas/OffscreenCanvasRenderingContext2D.idl \ 732 $(WebCore)/html/canvas/PaintRenderingContext2D.idl \ 732 733 $(WebCore)/html/canvas/Path2D.idl \ 733 734 $(WebCore)/html/canvas/WebGL2RenderingContext.idl \ -
trunk/Source/WebCore/Sources.txt
r237306 r237344 446 446 bindings/js/JSNodeListCustom.cpp 447 447 bindings/js/JSOffscreenCanvasRenderingContext2DCustom.cpp 448 bindings/js/JSPaintRenderingContext2DCustom.cpp 448 449 bindings/js/JSPaymentMethodChangeEventCustom.cpp 449 450 bindings/js/JSPaymentResponseCustom.cpp … … 971 972 html/CheckboxInputType.cpp 972 973 html/ColorInputType.cpp 974 html/CustomPaintCanvas.cpp 973 975 html/DOMFormData.cpp 974 976 html/DOMTokenList.cpp … … 1129 1131 html/canvas/ImageBitmapRenderingContext.cpp 1130 1132 html/canvas/OffscreenCanvasRenderingContext2D.cpp 1133 html/canvas/PaintRenderingContext2D.cpp 1131 1134 html/canvas/Path2D.cpp 1132 1135 html/canvas/PlaceholderRenderingContext.cpp … … 2846 2849 JSOffscreenCanvas.cpp 2847 2850 JSOffscreenCanvasRenderingContext2D.cpp 2851 JSPaintRenderingContext2D.cpp 2848 2852 JSOscillatorNode.cpp 2849 2853 JSOverconstrainedError.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r237340 r237344 1346 1346 4AD01009127E642A0015035F /* HTMLOutputElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AD01006127E642A0015035F /* HTMLOutputElement.h */; }; 1347 1347 4AD0173D127E82860015035F /* JSHTMLOutputElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4AD0173B127E82860015035F /* JSHTMLOutputElement.h */; }; 1348 4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */; }; 1349 4B1E13EB217937B30042CF98 /* PaintRenderingContext2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */; }; 1348 1350 4B2708C70AF19EE40065127F /* Pasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B2708C50AF19EE40065127F /* Pasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1349 1351 4B3043CD0AE0373B00A82647 /* Editor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3043CB0AE0373B00A82647 /* Editor.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 7884 7886 4AD0173B127E82860015035F /* JSHTMLOutputElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLOutputElement.h; sourceTree = "<group>"; }; 7885 7887 4B1706642162B42F00E578BB /* CSSRegisteredCustomProperty.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSRegisteredCustomProperty.cpp; sourceTree = "<group>"; }; 7888 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomPaintCanvas.h; sourceTree = "<group>"; }; 7889 4B1E13E921790D7E0042CF98 /* CustomPaintCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CustomPaintCanvas.cpp; sourceTree = "<group>"; }; 7890 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PaintRenderingContext2D.h; sourceTree = "<group>"; }; 7891 4B1E13EC217938380042CF98 /* PaintRenderingContext2D.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PaintRenderingContext2D.cpp; sourceTree = "<group>"; }; 7892 4B1E13ED21793DC10042CF98 /* PaintRenderingContext2D.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PaintRenderingContext2D.idl; sourceTree = "<group>"; }; 7893 4B1E13EE217941320042CF98 /* JSPaintRenderingContext2DCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSPaintRenderingContext2DCustom.cpp; sourceTree = "<group>"; }; 7886 7894 4B2708C50AF19EE40065127F /* Pasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pasteboard.h; sourceTree = "<group>"; }; 7887 7895 4B2709810AF2E5E00065127F /* PasteboardMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteboardMac.mm; sourceTree = "<group>"; }; … … 17637 17645 3140C51E1FDF151A00D2A873 /* OffscreenCanvasRenderingContext2D.h */, 17638 17646 3140C51B1FDF13D200D2A873 /* OffscreenCanvasRenderingContext2D.idl */, 17647 4B1E13EC217938380042CF98 /* PaintRenderingContext2D.cpp */, 17648 4B1E13EA217937B30042CF98 /* PaintRenderingContext2D.h */, 17649 4B1E13ED21793DC10042CF98 /* PaintRenderingContext2D.idl */, 17639 17650 7C193BA71F5E0EAF0088F3E6 /* Path2D.cpp */, 17640 17651 7C193BAB1F5E0EB10088F3E6 /* Path2D.h */, … … 20212 20223 AD20B18C18E9D216005A8083 /* JSNodeListCustom.h */, 20213 20224 3140C52B1FE06B4900D2A873 /* JSOffscreenCanvasRenderingContext2DCustom.cpp */, 20225 4B1E13EE217941320042CF98 /* JSPaintRenderingContext2DCustom.cpp */, 20214 20226 CB38FD551CD21D5B00592A3F /* JSPerformanceEntryCustom.cpp */, 20215 20227 833CF70F20DB3F5F00141BCC /* JSPerformanceObserverCustom.cpp */, … … 20778 20790 BC29935C17A1DD5800BCE880 /* ColorInputType.cpp */, 20779 20791 F55B3D801251F12D003EF269 /* ColorInputType.h */, 20792 4B1E13E921790D7E0042CF98 /* CustomPaintCanvas.cpp */, 20793 4B1E13E621790D660042CF98 /* CustomPaintCanvas.h */, 20780 20794 E517670220B88C1400D41167 /* DataListSuggestionInformation.h */, 20781 20795 F55B3D811251F12D003EF269 /* DateInputType.cpp */, … … 28104 28118 9BD4E91B1C462CFC005065BC /* CustomElementRegistry.h in Headers */, 28105 28119 62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */, 28120 4B1E13E721790D660042CF98 /* CustomPaintCanvas.h in Headers */, 28106 28121 4B7AE4932177B56F00C59959 /* CustomPaintImage.h in Headers */, 28107 28122 A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */, … … 30129 30144 0885067F11DA045B00182B98 /* PaintInfo.h in Headers */, 30130 30145 0885068011DA045B00182B98 /* PaintPhase.h in Headers */, 30146 4B1E13EB217937B30042CF98 /* PaintRenderingContext2D.h in Headers */, 30131 30147 A80E6CFB0A1989CA007FB8C5 /* Pair.h in Headers */, 30132 30148 FD3160A312B026F700C1A359 /* Panner.h in Headers */, -
trunk/Source/WebCore/bindings/js/JSPaintRenderingContext2DCustom.cpp
r237342 r237344 24 24 */ 25 25 26 #pragma once 26 #include "config.h" 27 #include "JSPaintRenderingContext2D.h" 27 28 28 29 #if ENABLE(CSS_PAINTING_API) 29 30 30 #include "ActiveDOMCallback.h" 31 #include "CallbackResult.h" 32 #include <wtf/RefCounted.h> 31 namespace WebCore { 32 using namespace JSC; 33 33 34 namespace WebCore { 35 class WebGLRenderingContext; 34 inline void* root(CustomPaintCanvas* canvas) 35 { 36 return canvas; 37 } 36 38 37 class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback { 38 public: 39 using ActiveDOMCallback::ActiveDOMCallback; 39 bool JSPaintRenderingContext2DOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason) 40 { 41 if (UNLIKELY(reason)) 42 *reason = "Canvas is opaque root"; 40 43 41 virtual CallbackResult<void> handleEvent(WebGLRenderingContext&) = 0; 44 JSPaintRenderingContext2D* jsPaintRenderingContext = jsCast<JSPaintRenderingContext2D*>(handle.slot()->asCell()); 45 void* root = WebCore::root(&jsPaintRenderingContext->wrapped().canvas()); 46 return visitor.containsOpaqueRoot(root); 47 } 42 48 43 virtual ~CSSPaintCallback()44 45 }46 } ;49 void JSPaintRenderingContext2D::visitAdditionalChildren(SlotVisitor& visitor) 50 { 51 visitor.addOpaqueRoot(root(&wrapped().canvas())); 52 } 47 53 48 54 } // namespace WebCore 49 55 #endif 56 -
trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h
r237306 r237344 114 114 macro(OffscreenCanvas) \ 115 115 macro(OffscreenCanvasRenderingContext2D) \ 116 macro(PaintRenderingContext2D) \ 116 117 macro(PaymentAddress) \ 117 118 macro(PaymentMethodChangeEvent) \ -
trunk/Source/WebCore/css/CSSPaintCallback.h
r237276 r237344 33 33 34 34 namespace WebCore { 35 class WebGLRenderingContext;35 class PaintRenderingContext2D; 36 36 37 37 class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback { … … 39 39 using ActiveDOMCallback::ActiveDOMCallback; 40 40 41 virtual CallbackResult<void> handleEvent( WebGLRenderingContext&) = 0;41 virtual CallbackResult<void> handleEvent(PaintRenderingContext2D&) = 0; 42 42 43 43 virtual ~CSSPaintCallback() -
trunk/Source/WebCore/css/CSSPaintCallback.idl
r237276 r237344 27 27 EnabledAtRuntime=CSSPaintingAPI, 28 28 Conditional=CSS_PAINTING_API, 29 ] callback CSSPaintCallback = void ( WebGLRenderingContextcontext);29 ] callback CSSPaintCallback = void (PaintRenderingContext2D context); -
trunk/Source/WebCore/html/CanvasBase.cpp
r226439 r237344 42 42 CanvasBase::~CanvasBase() 43 43 { 44 ASSERT(!m_context); // Should have been set to null by base class. 44 45 notifyObserversCanvasDestroyed(); 45 46 } -
trunk/Source/WebCore/html/CanvasBase.h
r226439 r237344 31 31 namespace WebCore { 32 32 33 class AffineTransform; 33 34 class CanvasBase; 34 35 class CanvasRenderingContext; 35 36 class Element; 37 class GraphicsContext; 38 class Image; 39 class ImageBuffer; 36 40 class IntSize; 37 41 class FloatRect; … … 59 63 virtual bool isHTMLCanvasElement() const { return false; } 60 64 virtual bool isOffscreenCanvas() const { return false; } 65 virtual bool isCustomPaintCanvas() const { return false; } 61 66 62 67 virtual unsigned width() const = 0; … … 82 87 HashSet<Element*> cssCanvasClients() const; 83 88 89 virtual GraphicsContext* drawingContext() const = 0; 90 virtual GraphicsContext* existingDrawingContext() const = 0; 91 92 virtual void makeRenderingResultsAvailable() = 0; 93 virtual void didDraw(const FloatRect&) = 0; 94 95 virtual AffineTransform baseTransform() const = 0; 96 virtual Image* copiedImage() const = 0; 97 84 98 protected: 85 99 CanvasBase(ScriptExecutionContext*); -
trunk/Source/WebCore/html/CustomPaintCanvas.h
r237342 r237344 1 1 /* 2 * Copyright (C) 201 7Apple Inc. All rights reserved.2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 26 26 #pragma once 27 27 28 #if ENABLE(CSS_PAINTING_API) 29 30 #include "AffineTransform.h" 28 31 #include "CanvasBase.h" 29 32 #include "EventTarget.h" 30 33 #include "ExceptionOr.h" 34 #include "ImageBuffer.h" 31 35 #include "IntSize.h" 32 36 #include "JSDOMPromiseDeferred.h" … … 39 43 40 44 class ImageBitmap; 41 class WebGLRenderingContext;45 class PaintRenderingContext2D; 42 46 43 #if ENABLE(WEBGL) 44 using OffscreenRenderingContext = RefPtr<WebGLRenderingContext>; 45 #endif 46 47 class OffscreenCanvas final : public RefCounted<OffscreenCanvas>, public CanvasBase, public EventTargetWithInlineData { 47 class CustomPaintCanvas final : public RefCounted<CustomPaintCanvas>, public CanvasBase { 48 48 WTF_MAKE_FAST_ALLOCATED; 49 49 public: 50 50 51 struct ImageEncodeOptions { 52 String type = "image/png"; 53 double quality = 1.0; 54 }; 55 56 enum class RenderingContextType { 57 _2d, 58 Webgl 59 }; 60 61 static Ref<OffscreenCanvas> create(ScriptExecutionContext&, unsigned width, unsigned height); 62 virtual ~OffscreenCanvas(); 51 static Ref<CustomPaintCanvas> create(ScriptExecutionContext&, unsigned width, unsigned height); 52 virtual ~CustomPaintCanvas(); 53 bool isCustomPaintCanvas() const final { return true; } 63 54 64 55 unsigned width() const final; … … 70 61 void setSize(const IntSize&) final; 71 62 72 #if ENABLE(WEBGL) 73 ExceptionOr<OffscreenRenderingContext> getContext(JSC::ExecState&, RenderingContextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments); 74 #endif 75 RefPtr<ImageBitmap> transferToImageBitmap(); 76 // void convertToBlob(ImageEncodeOptions options); 63 ExceptionOr<RefPtr<PaintRenderingContext2D>> getContext(); 64 65 GraphicsContext* drawingContext() const final; 66 GraphicsContext* existingDrawingContext() const final; 67 68 void makeRenderingResultsAvailable() final; 69 void didDraw(const FloatRect&) final { } 70 71 AffineTransform baseTransform() const final { ASSERT(m_destinationGraphicsContext && m_copiedBuffer); return m_copiedBuffer->baseTransform(); } 72 Image* copiedImage() const final; 77 73 78 74 using RefCounted::ref; … … 80 76 81 77 private: 82 83 OffscreenCanvas(ScriptExecutionContext&, unsigned width, unsigned height); 84 85 bool isOffscreenCanvas() const final { return true; } 86 87 ScriptExecutionContext* scriptExecutionContext() const final { return CanvasBase::scriptExecutionContext(); } 88 89 EventTargetInterface eventTargetInterface() const final { return OffscreenCanvasEventTargetInterfaceType; } 90 void refEventTarget() final { ref(); } 91 void derefEventTarget() final { deref(); } 78 CustomPaintCanvas(ScriptExecutionContext&, unsigned width, unsigned height); 92 79 93 80 void refCanvasBase() final { ref(); } 94 81 void derefCanvasBase() final { deref(); } 95 82 96 IntSize m_size; 83 mutable GraphicsContext* m_destinationGraphicsContext = nullptr; 84 mutable IntSize m_size; 85 mutable std::unique_ptr<ImageBuffer> m_copiedBuffer; 86 mutable RefPtr<Image> m_copiedImage; 97 87 }; 98 88 99 89 } 100 101 SPECIALIZE_TYPE_TRAITS_CANVAS(WebCore::OffscreenCanvas, isOffscreenCanvas()) 90 SPECIALIZE_TYPE_TRAITS_CANVAS(WebCore::CustomPaintCanvas, isCustomPaintCanvas()) 91 #endif -
trunk/Source/WebCore/html/HTMLCanvasElement.h
r237306 r237344 119 119 120 120 // Used for rendering 121 void didDraw(const FloatRect&) ;121 void didDraw(const FloatRect&) final; 122 122 123 123 void paint(GraphicsContext&, const LayoutRect&); 124 124 125 GraphicsContext* drawingContext() const ;126 GraphicsContext* existingDrawingContext() const ;125 GraphicsContext* drawingContext() const final; 126 GraphicsContext* existingDrawingContext() const final; 127 127 128 128 #if ENABLE(MEDIA_STREAM) … … 132 132 133 133 ImageBuffer* buffer() const; 134 Image* copiedImage() const ;134 Image* copiedImage() const final; 135 135 void clearCopiedImage(); 136 136 RefPtr<ImageData> getImageData(); … … 140 140 SecurityOrigin* securityOrigin() const final; 141 141 142 AffineTransform baseTransform() const ;143 144 void makeRenderingResultsAvailable() ;142 AffineTransform baseTransform() const final; 143 144 void makeRenderingResultsAvailable() final; 145 145 bool hasCreatedImageBuffer() const { return m_hasCreatedImageBuffer; } 146 146 -
trunk/Source/WebCore/html/OffscreenCanvas.cpp
r225713 r237344 27 27 #include "OffscreenCanvas.h" 28 28 29 #include "CanvasRenderingContext.h" 29 30 #include "ImageBitmap.h" 30 31 #include "WebGLRenderingContext.h" … … 43 44 } 44 45 45 OffscreenCanvas::~OffscreenCanvas() = default; 46 OffscreenCanvas::~OffscreenCanvas() 47 { 48 m_context = nullptr; 49 } 46 50 47 51 unsigned OffscreenCanvas::width() const -
trunk/Source/WebCore/html/OffscreenCanvas.h
r226439 r237344 26 26 #pragma once 27 27 28 #include "AffineTransform.h" 28 29 #include "CanvasBase.h" 29 30 #include "EventTarget.h" … … 76 77 // void convertToBlob(ImageEncodeOptions options); 77 78 79 GraphicsContext* drawingContext() const final { return nullptr; } 80 GraphicsContext* existingDrawingContext() const final { return nullptr; } 81 82 void makeRenderingResultsAvailable() final { } 83 void didDraw(const FloatRect&) final { } 84 85 AffineTransform baseTransform() const final { return { }; } 86 Image* copiedImage() const final { return nullptr; } 87 78 88 using RefCounted::ref; 79 89 using RefCounted::deref; -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext.cpp
r234055 r237344 62 62 } 63 63 64 bool CanvasRenderingContext::wouldTaintOrigin(const HTMLCanvasElement* sourceCanvas)64 bool CanvasRenderingContext::wouldTaintOrigin(const CanvasBase* sourceCanvas) 65 65 { 66 66 if (m_canvas.originClean() && sourceCanvas && !sourceCanvas->originClean()) -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext.h
r237306 r237344 67 67 virtual bool isPlaceholder() const { return false; } 68 68 virtual bool isOffscreen2d() const { return false; } 69 virtual bool isPaint() const { return false; } 69 70 70 71 virtual void paintRenderingResultsToCanvas() {} … … 77 78 explicit CanvasRenderingContext(CanvasBase&); 78 79 bool wouldTaintOrigin(const CanvasPattern*); 79 bool wouldTaintOrigin(const HTMLCanvasElement*);80 bool wouldTaintOrigin(const CanvasBase*); 80 81 bool wouldTaintOrigin(const HTMLImageElement*); 81 82 bool wouldTaintOrigin(const HTMLVideoElement*); -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
r237198 r237344 89 89 90 90 DisplayListDrawingContext(GraphicsContext& context, const FloatRect& clip) 91 : DisplayListDrawingContext(context.state(), clip) 92 { 93 } 94 95 DisplayListDrawingContext(const GraphicsContextState& state, const FloatRect& clip) 91 96 : context([&](GraphicsContext& displayListContext) { 92 return std::make_unique<DisplayList::Recorder>(displayListContext, displayList, context.state(), clip, AffineTransform());97 return std::make_unique<DisplayList::Recorder>(displayListContext, displayList, state, clip, AffineTransform()); 93 98 }) 94 99 { … … 147 152 // GraphicsContext dtor. 148 153 if (size_t stackSize = m_stateStack.size()) { 149 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 150 if (GraphicsContext* context = canvas.existingDrawingContext()) { 154 if (auto* context = canvasBase().existingDrawingContext()) { 151 155 while (--stackSize) 152 156 context->restore(); … … 168 172 { 169 173 #if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS) 170 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 171 if (!canvas.hasCreatedImageBuffer()) 172 return false; 173 auto* context = drawingContext(); 174 auto* context = canvasBase().existingDrawingContext(); 174 175 return context && context->isAcceleratedContext(); 175 176 #else … … 402 403 return; 403 404 404 auto& canvas = downcast<HTMLCanvasElement>(canvasBase());405 406 if (style.isCurrentColor()) { 405 if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) { 406 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 407 407 408 if (style.hasOverrideAlpha()) { 408 409 // FIXME: Should not use RGBA32 here. … … 431 432 return; 432 433 433 auto& canvas = downcast<HTMLCanvasElement>(canvasBase());434 435 if (style.isCurrentColor()) { 434 if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) { 435 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 436 436 437 if (style.hasOverrideAlpha()) { 437 438 // FIXME: Should not use RGBA32 here. … … 929 930 realizeSaves(); 930 931 931 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 932 c->setCTM(canvas.baseTransform()); 932 c->setCTM(canvasBase().baseTransform()); 933 933 modifiableState().transform = AffineTransform(); 934 934 … … 1728 1728 1729 1729 c->save(); 1730 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 1731 c->setCTM(canvas.baseTransform()); 1732 c->clearRect(FloatRect(0, 0, canvas.width(), canvas.height())); 1730 c->setCTM(canvasBase().baseTransform()); 1731 c->clearRect(FloatRect(0, 0, canvasBase().width(), canvasBase().height())); 1733 1732 c->restore(); 1734 1733 } … … 1737 1736 { 1738 1737 Path transformed(path); 1739 auto& canvas = downcast<HTMLCanvasElement>(canvasBase());1740 1738 transformed.transform(state().transform); 1741 transformed.transform(canvas .baseTransform());1739 transformed.transform(canvasBase().baseTransform()); 1742 1740 return transformed; 1743 1741 } … … 1753 1751 { 1754 1752 FloatQuad quad(rect); 1755 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 1756 FloatQuad canvasQuad(FloatRect(0, 0, canvas.width(), canvas.height())); 1753 FloatQuad canvasQuad(FloatRect(0, 0, canvasBase().width(), canvasBase().height())); 1757 1754 return state().transform.mapQuad(quad).containsQuad(canvasQuad); 1758 1755 } … … 1760 1757 template<class T> IntRect CanvasRenderingContext2DBase::calculateCompositingBufferRect(const T& area, IntSize* croppedOffset) 1761 1758 { 1762 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 1763 1764 IntRect canvasRect(0, 0, canvas.width(), canvas.height()); 1765 canvasRect = canvas.baseTransform().mapRect(canvasRect); 1759 IntRect canvasRect(0, 0, canvasBase().width(), canvasBase().height()); 1760 canvasRect = canvasBase().baseTransform().mapRect(canvasRect); 1766 1761 Path path = transformAreaToDevice(area); 1767 1762 IntRect bufferRect = enclosingIntRect(path.fastBoundingRect()); … … 1780 1775 void CanvasRenderingContext2DBase::compositeBuffer(ImageBuffer& buffer, const IntRect& bufferRect, CompositeOperator op) 1781 1776 { 1782 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 1783 IntRect canvasRect(0, 0, canvas.width(), canvas.height()); 1784 canvasRect = canvas.baseTransform().mapRect(canvasRect); 1777 IntRect canvasRect(0, 0, canvasBase().width(), canvasBase().height()); 1778 canvasRect = canvasBase().baseTransform().mapRect(canvasRect); 1785 1779 1786 1780 auto* c = drawingContext(); … … 1947 1941 } 1948 1942 1949 ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern( HTMLCanvasElement& canvas, bool repeatX, bool repeatY)1950 { 1951 if (!canvas.width() || !canvas.height() || !canvas.buffer())1943 ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(CanvasBase& canvas, bool repeatX, bool repeatY) 1944 { 1945 if (!canvas.width() || !canvas.height()) 1952 1946 return Exception { InvalidStateError }; 1953 1954 return RefPtr<CanvasPattern> { CanvasPattern::create(*canvas.copiedImage(), repeatX, repeatY, canvas.originClean()) }; 1947 auto* copiedImage = canvas.copiedImage(); 1948 1949 if (!copiedImage) 1950 return Exception { InvalidStateError }; 1951 1952 return RefPtr<CanvasPattern> { CanvasPattern::create(*copiedImage, repeatX, repeatY, canvas.originClean()) }; 1955 1953 } 1956 1954 … … 1989 1987 void CanvasRenderingContext2DBase::didDrawEntireCanvas() 1990 1988 { 1991 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 1992 didDraw(FloatRect(FloatPoint::zero(), canvas.size()), CanvasDidDrawApplyClip); 1989 didDraw(FloatRect(FloatPoint::zero(), canvasBase().size()), CanvasDidDrawApplyClip); 1993 1990 } 1994 1991 … … 2035 2032 } 2036 2033 2037 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 2038 canvas.didDraw(dirtyRect); 2034 canvasBase().didDraw(dirtyRect); 2039 2035 } 2040 2036 … … 2076 2072 return; 2077 2073 2078 auto& canvas = downcast<HTMLCanvasElement>(canvasBase()); 2079 2080 FloatRect clip(FloatPoint::zero(), canvas.size()); 2081 DisplayList::Replayer replayer(*canvas.drawingContext(), m_recordingContext->displayList); 2074 FloatRect clip(FloatPoint::zero(), canvasBase().size()); 2075 DisplayList::Replayer replayer(*canvasBase().drawingContext(), m_recordingContext->displayList); 2082 2076 2083 2077 if (UNLIKELY(m_tracksDisplayListReplay)) { … … 2093 2087 GraphicsContext* CanvasRenderingContext2DBase::drawingContext() const 2094 2088 { 2095 auto& canvas = downcast<HTMLCanvasElement>(canvasBase());2096 2089 if (UNLIKELY(m_usesDisplayListDrawing)) { 2097 2090 if (!m_recordingContext) 2098 m_recordingContext = std::make_unique<DisplayListDrawingContext>( *canvas.drawingContext(), FloatRect(FloatPoint::zero(), canvas.size()));2091 m_recordingContext = std::make_unique<DisplayListDrawingContext>(GraphicsContextState(), FloatRect(FloatPoint::zero(), canvasBase().size())); 2099 2092 return &m_recordingContext->context; 2100 2093 } 2101 2094 2102 return canvas .drawingContext();2095 return canvasBase().drawingContext(); 2103 2096 } 2104 2097 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h
r237198 r237344 317 317 318 318 ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLImageElement&, bool repeatX, bool repeatY); 319 ExceptionOr<RefPtr<CanvasPattern>> createPattern( HTMLCanvasElement&, bool repeatX, bool repeatY);319 ExceptionOr<RefPtr<CanvasPattern>> createPattern(CanvasBase&, bool repeatX, bool repeatY); 320 320 #if ENABLE(VIDEO) 321 321 ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLVideoElement&, bool repeatX, bool repeatY); -
trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.cpp
r237342 r237344 24 24 */ 25 25 26 #pragma once 26 #include "config.h" 27 #include "PaintRenderingContext2D.h" 27 28 28 29 #if ENABLE(CSS_PAINTING_API) 29 30 30 #include "ActiveDOMCallback.h" 31 #include "CallbackResult.h" 32 #include <wtf/RefCounted.h> 31 namespace WebCore { 33 32 34 namespace WebCore { 35 class WebGLRenderingContext; 33 std::unique_ptr<PaintRenderingContext2D> PaintRenderingContext2D::create(CanvasBase& canvas) 34 { 35 return std::unique_ptr<PaintRenderingContext2D>(new PaintRenderingContext2D(canvas)); 36 } 36 37 37 class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback { 38 public: 39 using ActiveDOMCallback::ActiveDOMCallback; 38 PaintRenderingContext2D::PaintRenderingContext2D(CanvasBase& canvas) 39 : CanvasRenderingContext2DBase(canvas, false, false) 40 { 41 } 40 42 41 virtual CallbackResult<void> handleEvent(WebGLRenderingContext&) = 0; 42 43 virtual ~CSSPaintCallback() 44 { 45 } 46 }; 43 PaintRenderingContext2D::~PaintRenderingContext2D() = default; 47 44 48 45 } // namespace WebCore -
trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.h
r237342 r237344 26 26 #pragma once 27 27 28 #include "CanvasRenderingContext2DBase.h" 29 28 30 #if ENABLE(CSS_PAINTING_API) 29 31 30 #include "ActiveDOMCallback.h" 31 #include "CallbackResult.h" 32 #include <wtf/RefCounted.h> 32 #include "CustomPaintCanvas.h" 33 33 34 34 namespace WebCore { 35 class WebGLRenderingContext;36 35 37 class CSSPaintCallback : public RefCounted<CSSPaintCallback>, public ActiveDOMCallback{36 class PaintRenderingContext2D final : public CanvasRenderingContext2DBase { 38 37 public: 39 using ActiveDOMCallback::ActiveDOMCallback;38 static std::unique_ptr<PaintRenderingContext2D> create(CanvasBase&); 40 39 41 virtual CallbackResult<void> handleEvent(WebGLRenderingContext&) = 0;40 virtual ~PaintRenderingContext2D(); 42 41 43 virtual ~CSSPaintCallback() 44 { 45 } 42 bool isPaint() const override { return true; } 43 CustomPaintCanvas& canvas() const { return downcast<CustomPaintCanvas>(canvasBase()); } 44 45 private: 46 PaintRenderingContext2D(CanvasBase&); 46 47 }; 47 48 48 49 } // namespace WebCore 50 SPECIALIZE_TYPE_TRAITS_CANVASRENDERINGCONTEXT(WebCore::PaintRenderingContext2D, isPaint()) 49 51 #endif -
trunk/Source/WebCore/html/canvas/PaintRenderingContext2D.idl
r237342 r237344 1 1 /* 2 * Copyright (C) 2018 Apple Inc. 2 * Copyright (C) 2018 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 25 25 26 26 [ 27 CustomIsReachable, 27 28 EnabledAtRuntime=CSSPaintingAPI, 28 29 Conditional=CSS_PAINTING_API, 29 ] callback CSSPaintCallback = void (WebGLRenderingContext context); 30 JSGenerateToJSObject, 31 JSCustomMarkFunction, 32 ] interface PaintRenderingContext2D { 33 }; 34 35 PaintRenderingContext2D implements CanvasState; 36 PaintRenderingContext2D implements CanvasTransform; 37 PaintRenderingContext2D implements CanvasCompositing; 38 PaintRenderingContext2D implements CanvasImageSmoothing; 39 PaintRenderingContext2D implements CanvasFillStrokeStyles; 40 PaintRenderingContext2D implements CanvasShadowStyles; 41 PaintRenderingContext2D implements CanvasRect; 42 PaintRenderingContext2D implements CanvasDrawPath; 43 PaintRenderingContext2D implements CanvasDrawImage; 44 PaintRenderingContext2D implements CanvasPathDrawingStyles; 45 PaintRenderingContext2D implements CanvasPath; -
trunk/Source/WebCore/html/canvas/WebMetalRenderPassAttachmentDescriptor.h
r236954 r237344 28 28 #if ENABLE(WEBMETAL) 29 29 30 #include <wtf/Ref.h>31 30 #include <wtf/RefCounted.h> 31 #include <wtf/RefPtr.h> 32 32 33 33 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/CustomPaintImage.cpp
r237276 r237344 29 29 #if ENABLE(CSS_PAINTING_API) 30 30 31 #include "CustomPaintCanvas.h" 31 32 #include "GraphicsContext.h" 32 33 #include "ImageBitmap.h" 33 34 #include "ImageBuffer.h" 34 35 #include "JSCSSPaintCallback.h" 35 #include "OffscreenCanvas.h" 36 #include "WebGLRenderingContext.h" 36 #include "PaintRenderingContext2D.h" 37 37 38 38 namespace WebCore { … … 52 52 if (!scriptExecutionContext) 53 53 return ImageDrawResult::DidNothing; 54 auto* execState = scriptExecutionContext->execState();55 if (!execState)56 return ImageDrawResult::DidNothing;57 54 58 auto canvas = OffscreenCanvas::create(*scriptExecutionContext, destSize.width(), destSize.height());59 ExceptionOr< OffscreenRenderingContext> contextOrException = canvas->getContext(*execState, OffscreenCanvas::RenderingContextType::Webgl, { });55 auto canvas = CustomPaintCanvas::create(*scriptExecutionContext, destSize.width(), destSize.height()); 56 ExceptionOr<RefPtr<PaintRenderingContext2D>> contextOrException = canvas->getContext(); 60 57 61 58 if (contextOrException.hasException()) … … 63 60 auto context = contextOrException.releaseReturnValue(); 64 61 65 context->clearColor(0, 0, 0, 1.0);66 context->clear(GL_COLOR_BUFFER_BIT);67 68 62 auto result = m_paintCallback->handleEvent(*context); 69 63 if (result.type() != CallbackResultType::Success) 70 64 return ImageDrawResult::DidNothing; 71 65 72 auto bitmap = canvas->transferToImageBitmap(); 73 if (!bitmap) 66 UNUSED_PARAM(destContext); 67 auto image = canvas->copiedImage(); 68 if (!image) 74 69 return ImageDrawResult::DidNothing; 75 70 76 destContext.drawImage(* bitmap->buffer()->copyImage(), FloatPoint());71 destContext.drawImage(*image, FloatPoint()); 77 72 78 73 return ImageDrawResult::DidDraw;
Note: See TracChangeset
for help on using the changeset viewer.