Changeset 266275 in webkit
- Timestamp:
- Aug 28, 2020 1:46:45 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r266269 r266275 1 2020-08-28 Chris Lord <clord@igalia.com> 2 3 Add WebGL(2) context support to OffscreenCanvas 4 https://bugs.webkit.org/show_bug.cgi?id=209809 5 6 Reviewed by Dean Jackson. 7 8 Rebaseline OffscreenCanvas tests after enabling WebGL contexts. 9 10 * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt: 11 * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt: 12 1 13 2020-08-27 Ryosuke Niwa <rniwa@webkit.org> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt
r265543 r266275 1 1 2 2 PASS Test that getContext with un-supported string throws a TypeError. 3 FAIL Test that getContext with supported string returns correct results Argument 1 ('contextType') to OffscreenCanvas.getContext must be one of: "2d", "webgl"3 FAIL Test that getContext with supported string returns correct results Can't find variable: WebGL2RenderingContext 4 4 PASS Test that getContext twice with different context type returns null the second time 5 5 PASS Test that 2dcontext.canvas should return the original OffscreenCanvas -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt
r265543 r266275 1 1 2 2 PASS Test that getContext with un-supported string throws a TypeError. 3 FAIL Test that getContext with supported string returns correct results Can't find variable: WebGL RenderingContext3 FAIL Test that getContext with supported string returns correct results Can't find variable: WebGL2RenderingContext 4 4 PASS Test that getContext twice with different context type returns null the second time 5 5 PASS Test that 2dcontext.canvas should return the original OffscreenCanvas -
trunk/Source/WebCore/ChangeLog
r266271 r266275 1 2020-08-28 Chris Lord <clord@igalia.com> 2 3 Add WebGL(2) context support to OffscreenCanvas 4 https://bugs.webkit.org/show_bug.cgi?id=209809 5 6 Reviewed by Dean Jackson. 7 8 Enable WebGL contexts with OffscreenCanvas by making sure the required 9 settings are marshalled to workers and that any functionality that 10 doesn't require an HTMLCanvasElement uses CanvasBase instead. 11 12 No new tests, rebaselined existing test. 13 14 * html/CanvasBase.h: 15 * html/CustomPaintCanvas.cpp: 16 (WebCore::CustomPaintCanvas::clearCopiedImage const): 17 * html/CustomPaintCanvas.h: 18 * html/HTMLCanvasElement.cpp: 19 (WebCore::HTMLCanvasElement::clearCopiedImage const): 20 * html/HTMLCanvasElement.h: 21 * html/OffscreenCanvas.cpp: 22 (WebCore::requiresAcceleratedCompositingForWebGL): 23 (WebCore::shouldEnableWebGL): 24 (WebCore::OffscreenCanvas::createContextWebGL): 25 (WebCore::OffscreenCanvas::getContext): 26 * html/OffscreenCanvas.h: 27 * html/OffscreenCanvas.idl: 28 * html/canvas/WebGL2RenderingContext.idl: 29 * html/canvas/WebGLRenderingContext.idl: 30 * html/canvas/WebGLRenderingContextBase.cpp: 31 (WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase): 32 (WebCore::WebGLRenderingContextBase::markContextChanged): 33 (WebCore::WebGLRenderingContextBase::paintRenderingResultsToCanvas): 34 * workers/WorkerGlobalScope.cpp: 35 (WebCore::WorkerGlobalScope::WorkerGlobalScope): 36 * workers/WorkerGlobalScope.h: 37 (WebCore::WorkerGlobalScope::acceleratedCompositingEnabled const): 38 (WebCore::WorkerGlobalScope::webGLEnabled const): 39 * workers/WorkerMessagingProxy.cpp: 40 (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): 41 * workers/WorkerThread.cpp: 42 (WebCore::WorkerParameters::isolatedCopy const): 43 * workers/WorkerThread.h: 44 * workers/service/context/ServiceWorkerThread.cpp: 45 (WebCore::ServiceWorkerThread::ServiceWorkerThread): 46 1 47 2020-08-27 Zalan Bujtas <zalan@apple.com> 2 48 -
trunk/Source/WebCore/html/CanvasBase.h
r255315 r266275 102 102 103 103 virtual Image* copiedImage() const = 0; 104 virtual void clearCopiedImage() const = 0; 105 104 106 bool callTracingActive() const; 105 107 -
trunk/Source/WebCore/html/CustomPaintCanvas.cpp
r258219 r266275 106 106 } 107 107 108 void CustomPaintCanvas::clearCopiedImage() const 109 { 110 m_copiedImage = nullptr; 111 } 112 108 113 GraphicsContext* CustomPaintCanvas::drawingContext() const 109 114 { -
trunk/Source/WebCore/html/CustomPaintCanvas.h
r251874 r266275 64 64 AffineTransform baseTransform() const final { ASSERT(m_destinationGraphicsContext && m_copiedBuffer); return m_copiedBuffer->baseTransform(); } 65 65 Image* copiedImage() const final; 66 void clearCopiedImage() const final; 67 66 68 void replayDisplayList(GraphicsContext*) const; 67 69 -
trunk/Source/WebCore/html/HTMLCanvasElement.cpp
r266168 r266275 1003 1003 } 1004 1004 1005 void HTMLCanvasElement::clearCopiedImage() 1005 void HTMLCanvasElement::clearCopiedImage() const 1006 1006 { 1007 1007 m_copiedImage = nullptr; -
trunk/Source/WebCore/html/HTMLCanvasElement.h
r265543 r266275 114 114 115 115 Image* copiedImage() const final; 116 void clearCopiedImage() ;116 void clearCopiedImage() const final; 117 117 RefPtr<ImageData> getImageData(); 118 118 void makePresentationCopy(); -
trunk/Source/WebCore/html/OffscreenCanvas.cpp
r266168 r266275 40 40 #include "OffscreenCanvasRenderingContext2D.h" 41 41 #include "PlaceholderRenderingContext.h" 42 #include "WebGLRenderingContext.h"43 42 #include "WorkerGlobalScope.h" 44 43 #include <wtf/IsoMallocInlines.h> 44 45 #if ENABLE(WEBGL) 46 #include "Settings.h" 47 #include "WebGLRenderingContext.h" 48 49 #if ENABLE(WEBGL2) 50 #include "WebGL2RenderingContext.h" 51 #endif 52 #endif // ENABLE(WEBGL) 45 53 46 54 namespace WebCore { … … 141 149 reset(); 142 150 } 151 152 #if ENABLE(WEBGL) 153 static bool requiresAcceleratedCompositingForWebGL() 154 { 155 #if PLATFORM(GTK) || PLATFORM(WIN_CAIRO) 156 return false; 157 #else 158 return true; 159 #endif 160 } 161 162 static bool shouldEnableWebGL(bool webGLEnabled, bool acceleratedCompositingEnabled) 163 { 164 if (!webGLEnabled) 165 return false; 166 167 if (!requiresAcceleratedCompositingForWebGL()) 168 return true; 169 170 return acceleratedCompositingEnabled; 171 } 172 173 void OffscreenCanvas::createContextWebGL(RenderingContextType contextType, WebGLContextAttributes&& attrs) 174 { 175 ASSERT(!m_context); 176 177 auto context = scriptExecutionContext(); 178 if (context->isWorkerGlobalScope()) { 179 WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*context); 180 if (!shouldEnableWebGL(workerGlobalScope.webGLEnabled(), workerGlobalScope.acceleratedCompositingEnabled())) 181 return; 182 } else if (context->isDocument()) { 183 auto& settings = downcast<Document>(*context).settings(); 184 if (!shouldEnableWebGL(settings.webGLEnabled(), settings.acceleratedCompositingEnabled())) 185 return; 186 } else 187 return; 188 189 m_context = WebGLRenderingContextBase::create(*this, attrs, (contextType == RenderingContextType::Webgl) ? "webgl" : "webgl2"); 190 } 191 192 #endif // ENABLE(WEBGL) 143 193 144 194 ExceptionOr<Optional<OffscreenRenderingContext>> OffscreenCanvas::getContext(JSC::JSGlobalObject& state, RenderingContextType contextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments) … … 161 211 } 162 212 #if ENABLE(WEBGL) 163 if (contextType == RenderingContextType::Webgl){213 else { 164 214 if (m_context) { 165 215 if (is<WebGLRenderingContext>(*m_context)) 166 216 return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } }; 217 #if ENABLE(WEBGL2) 218 if (is<WebGL2RenderingContext>(*m_context)) 219 return { { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*m_context) } } }; 220 #endif 167 221 return { { WTF::nullopt } }; 168 222 } … … 172 226 RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError }); 173 227 174 m_context = WebGLRenderingContextBase::create(*this, attributes, "webgl");228 createContextWebGL(contextType, WTFMove(attributes)); 175 229 if (!m_context) 176 230 return { { WTF::nullopt } }; 177 231 232 #if ENABLE(WEBGL2) 233 if (is<WebGL2RenderingContext>(*m_context)) 234 return { { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*m_context) } } }; 235 #endif 178 236 return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } }; 179 237 } -
trunk/Source/WebCore/html/OffscreenCanvas.h
r265543 r266275 41 41 #include <wtf/WeakPtr.h> 42 42 #include <wtf/text/WTFString.h> 43 #if ENABLE(WEBGL) 44 #include "WebGLContextAttributes.h" 45 #endif 46 43 47 44 48 namespace WebCore { … … 51 55 class ImageData; 52 56 class OffscreenCanvasRenderingContext2D; 57 class WebGL2RenderingContext; 53 58 class WebGLRenderingContext; 54 59 class WebGLRenderingContextBase; 60 61 using OffscreenRenderingContext = Variant< 55 62 #if ENABLE(WEBGL) 56 using OffscreenRenderingContext = Variant<RefPtr<OffscreenCanvasRenderingContext2D>, RefPtr<WebGLRenderingContext>>; 57 #else 58 using OffscreenRenderingContext = Variant<RefPtr<OffscreenCanvasRenderingContext2D>>; 59 #endif 63 RefPtr<WebGLRenderingContext>, 64 #endif 65 #if ENABLE(WEBGL2) 66 RefPtr<WebGL2RenderingContext>, 67 #endif 68 RefPtr<OffscreenCanvasRenderingContext2D> 69 >; 60 70 61 71 class DetachedOffscreenCanvas { … … 97 107 enum class RenderingContextType { 98 108 _2d, 99 Webgl 109 Webgl, 110 Webgl2 100 111 }; 101 112 … … 119 130 120 131 Image* copiedImage() const final; 132 void clearCopiedImage() const final; 133 121 134 bool hasCreatedImageBuffer() const final { return m_hasCreatedImageBuffer; } 122 135 … … 150 163 151 164 void setSize(const IntSize&) final; 165 166 #if ENABLE(WEBGL) 167 void createContextWebGL(RenderingContextType, WebGLContextAttributes&& = { }); 168 #endif 169 152 170 void createImageBuffer() const final; 153 171 std::unique_ptr<ImageBuffer> takeImageBuffer() const; 154 172 155 173 void reset(); 156 157 void clearCopiedImage() const;158 174 159 175 void setPlaceholderCanvas(HTMLCanvasElement&); -
trunk/Source/WebCore/html/OffscreenCanvas.idl
r263160 r266275 24 24 */ 25 25 26 typedef ( 26 27 #if defined(ENABLE_WEBGL) && ENABLE_WEBGL 27 typedef (OffscreenCanvasRenderingContext2D or WebGLRenderingContext) OffscreenRenderingContext; 28 #else 29 typedef (OffscreenCanvasRenderingContext2D) OffscreenRenderingContext; 28 WebGLRenderingContext or 30 29 #endif 30 #if defined(ENABLE_WEBGL2) && ENABLE_WEBGL2 31 WebGL2RenderingContext or 32 #endif 33 OffscreenCanvasRenderingContext2D) OffscreenRenderingContext; 31 34 32 35 dictionary ImageEncodeOptions … … 39 42 { 40 43 "2d", 41 "webgl" 44 "webgl", 45 "webgl2" 42 46 }; 43 47 -
trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.idl
r265833 r266275 59 59 JSGenerateToJSObject, 60 60 DoNotCheckConstants, 61 Exposed=(Window,Worker), 61 62 CallTracingCallback=recordCanvasAction, 62 63 ] interface WebGL2RenderingContext { -
trunk/Source/WebCore/html/canvas/WebGLRenderingContext.idl
r265833 r266275 42 42 DoNotCheckConstants, 43 43 ExportMacro=WEBCORE_EXPORT, 44 Exposed=(Window,Worker), 44 45 CallTracingCallback=recordCanvasAction, 45 46 ] interface WebGLRenderingContext { -
trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
r266189 r266275 752 752 753 753 registerWithWebGLStateTracker(); 754 m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay); 754 if (canvas.isHTMLCanvasElement()) 755 m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay); 755 756 } 756 757 … … 779 780 780 781 registerWithWebGLStateTracker(); 781 m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay); 782 if (canvas.isHTMLCanvasElement()) 783 m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay); 782 784 783 785 addActivityStateChangeObserverIfNecessary(); … … 1068 1070 m_layerCleared = false; 1069 1071 1070 auto* canvas = htmlCanvas(); 1071 if (!canvas) 1072 return; 1073 1074 RenderBox* renderBox = canvas->renderBox(); 1075 if (isAccelerated() && renderBox && renderBox->hasAcceleratedCompositing()) { 1072 if (auto* canvas = htmlCanvas()) { 1073 RenderBox* renderBox = canvas->renderBox(); 1074 if (isAccelerated() && renderBox && renderBox->hasAcceleratedCompositing()) { 1075 m_markedCanvasDirty = true; 1076 canvas->clearCopiedImage(); 1077 renderBox->contentChanged(CanvasPixelsChanged); 1078 return; 1079 } 1080 } 1081 1082 if (!m_markedCanvasDirty) { 1076 1083 m_markedCanvasDirty = true; 1077 htmlCanvas()->clearCopiedImage(); 1078 renderBox->contentChanged(CanvasPixelsChanged); 1079 } else { 1080 if (!m_markedCanvasDirty) { 1081 m_markedCanvasDirty = true; 1082 canvas->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize())); 1083 } 1084 canvasBase().didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize())); 1084 1085 } 1085 1086 } … … 1193 1194 return; 1194 1195 1195 auto* canvas = htmlCanvas(); 1196 if (!canvas) 1197 return; 1198 1199 if (canvas->document().printing() || (canvas->isSnapshotting() && canvas->document().page()->isVisible())) 1200 canvas->clearPresentationCopy(); 1201 1202 // Until the canvas is written to by the application, the clear that 1203 // happened after it was composited should be ignored by the compositor. 1204 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { 1205 m_context->paintRenderingResultsToCanvas(canvas->buffer()); 1206 1207 canvas->makePresentationCopy(); 1208 } else 1209 canvas->clearPresentationCopy(); 1196 if (auto* canvas = htmlCanvas()) { 1197 if (canvas->document().printing() || (canvas->isSnapshotting() && canvas->document().page()->isVisible())) 1198 canvas->clearPresentationCopy(); 1199 1200 // Until the canvas is written to by the application, the clear that 1201 // happened after it was composited should be ignored by the compositor. 1202 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { 1203 m_context->paintRenderingResultsToCanvas(canvas->buffer()); 1204 1205 canvas->makePresentationCopy(); 1206 } else 1207 canvas->clearPresentationCopy(); 1208 } 1209 1210 1210 clearIfComposited(); 1211 1211 … … 1213 1213 return; 1214 1214 1215 canvas->clearCopiedImage(); 1215 auto& base = canvasBase(); 1216 base.clearCopiedImage(); 1217 1216 1218 m_markedCanvasDirty = false; 1217 1219 1218 m_context->paintRenderingResultsToCanvas( canvas->buffer());1220 m_context->paintRenderingResultsToCanvas(base.buffer()); 1219 1221 } 1220 1222 -
trunk/Source/WebCore/workers/WorkerGlobalScope.cpp
r263422 r266275 80 80 , m_referrerPolicy(params.referrerPolicy) 81 81 , m_requestAnimationFrameEnabled(params.requestAnimationFrameEnabled) 82 , m_acceleratedCompositingEnabled(params.acceleratedCompositingEnabled) 83 , m_webGLEnabled(params.webGLEnabled) 82 84 { 83 85 #if !ENABLE(INDEXED_DATABASE) -
trunk/Source/WebCore/workers/WorkerGlobalScope.h
r259298 r266275 143 143 144 144 bool requestAnimationFrameEnabled() const { return m_requestAnimationFrameEnabled; } 145 bool acceleratedCompositingEnabled() const { return m_acceleratedCompositingEnabled; } 146 bool webGLEnabled() const { return m_webGLEnabled; } 145 147 146 148 protected: … … 224 226 ReferrerPolicy m_referrerPolicy; 225 227 bool m_requestAnimationFrameEnabled; 228 bool m_acceleratedCompositingEnabled; 229 bool m_webGLEnabled; 226 230 }; 227 231 -
trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp
r261104 r266275 90 90 SocketProvider* socketProvider = document.socketProvider(); 91 91 92 WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy, document.settings().requestAnimationFrameEnabled() };92 WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy, document.settings().requestAnimationFrameEnabled(), document.settings().acceleratedCompositingEnabled(), document.settings().webGLEnabled() }; 93 93 auto thread = DedicatedWorkerThread::create(params, sourceCode, *this, *this, *this, startMode, document.topOrigin(), proxy, socketProvider, runtimeFlags); 94 94 -
trunk/Source/WebCore/workers/WorkerThread.cpp
r259298 r266275 83 83 referrerPolicy, 84 84 requestAnimationFrameEnabled, 85 acceleratedCompositingEnabled, 86 webGLEnabled, 85 87 }; 86 88 } -
trunk/Source/WebCore/workers/WorkerThread.h
r259298 r266275 70 70 ReferrerPolicy referrerPolicy; 71 71 bool requestAnimationFrameEnabled; 72 bool acceleratedCompositingEnabled; 73 bool webGLEnabled; 72 74 73 75 WorkerParameters isolatedCopy() const; -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
r263422 r266275 75 75 76 76 ServiceWorkerThread::ServiceWorkerThread(const ServiceWorkerContextData& data, String&& userAgent, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider) 77 : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { }, true }, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled())77 : WorkerThread({ data.scriptURL, emptyString(), "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), platformStrategies()->loaderStrategy()->isOnLine(), data.contentSecurityPolicy, false, MonotonicTime::now(), { }, true, true, true }, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, data.registration.key.topOrigin().securityOrigin().get(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled()) 78 78 , m_data(data.isolatedCopy()) 79 79 , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
Note: See TracChangeset
for help on using the changeset viewer.