Title: [266275] trunk
Revision
266275
Author
[email protected]
Date
2020-08-28 01:46:45 -0700 (Fri, 28 Aug 2020)

Log Message

Add WebGL(2) context support to OffscreenCanvas
https://bugs.webkit.org/show_bug.cgi?id=209809

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Rebaseline OffscreenCanvas tests after enabling WebGL contexts.

* web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt:
* web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt:

Source/WebCore:

Enable WebGL contexts with OffscreenCanvas by making sure the required
settings are marshalled to workers and that any functionality that
doesn't require an HTMLCanvasElement uses CanvasBase instead.

No new tests, rebaselined existing test.

* html/CanvasBase.h:
* html/CustomPaintCanvas.cpp:
(WebCore::CustomPaintCanvas::clearCopiedImage const):
* html/CustomPaintCanvas.h:
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::clearCopiedImage const):
* html/HTMLCanvasElement.h:
* html/OffscreenCanvas.cpp:
(WebCore::requiresAcceleratedCompositingForWebGL):
(WebCore::shouldEnableWebGL):
(WebCore::OffscreenCanvas::createContextWebGL):
(WebCore::OffscreenCanvas::getContext):
* html/OffscreenCanvas.h:
* html/OffscreenCanvas.idl:
* html/canvas/WebGL2RenderingContext.idl:
* html/canvas/WebGLRenderingContext.idl:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
(WebCore::WebGLRenderingContextBase::markContextChanged):
(WebCore::WebGLRenderingContextBase::paintRenderingResultsToCanvas):
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope):
* workers/WorkerGlobalScope.h:
(WebCore::WorkerGlobalScope::acceleratedCompositingEnabled const):
(WebCore::WorkerGlobalScope::webGLEnabled const):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
* workers/WorkerThread.cpp:
(WebCore::WorkerParameters::isolatedCopy const):
* workers/WorkerThread.h:
* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::ServiceWorkerThread):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (266274 => 266275)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-28 08:46:45 UTC (rev 266275)
@@ -1,3 +1,15 @@
+2020-08-28  Chris Lord  <[email protected]>
+
+        Add WebGL(2) context support to OffscreenCanvas
+        https://bugs.webkit.org/show_bug.cgi?id=209809
+
+        Reviewed by Dean Jackson.
+
+        Rebaseline OffscreenCanvas tests after enabling WebGL contexts.
+
+        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt:
+        * web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt:
+
 2020-08-27  Ryosuke Niwa  <[email protected]>
 
         Prevent infinite recursion when upgrading custom elements

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt (266274 => 266275)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt	2020-08-28 08:46:45 UTC (rev 266275)
@@ -1,6 +1,6 @@
 
 PASS Test that getContext with un-supported string throws a TypeError. 
-FAIL Test that getContext with supported string returns correct results Argument 1 ('contextType') to OffscreenCanvas.getContext must be one of: "2d", "webgl"
+FAIL Test that getContext with supported string returns correct results Can't find variable: WebGL2RenderingContext
 PASS Test that getContext twice with different context type returns null the second time 
 PASS Test that 2dcontext.canvas should return the original OffscreenCanvas 
 PASS Test that webglcontext.canvas should return the original OffscreenCanvas 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt (266274 => 266275)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext.worker-expected.txt	2020-08-28 08:46:45 UTC (rev 266275)
@@ -1,6 +1,6 @@
 
 PASS Test that getContext with un-supported string throws a TypeError. 
-FAIL Test that getContext with supported string returns correct results Can't find variable: WebGLRenderingContext
+FAIL Test that getContext with supported string returns correct results Can't find variable: WebGL2RenderingContext
 PASS Test that getContext twice with different context type returns null the second time 
 PASS Test that 2dcontext.canvas should return the original OffscreenCanvas 
 PASS Test that webglcontext.canvas should return the original OffscreenCanvas 

Modified: trunk/Source/WebCore/ChangeLog (266274 => 266275)


--- trunk/Source/WebCore/ChangeLog	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/ChangeLog	2020-08-28 08:46:45 UTC (rev 266275)
@@ -1,3 +1,49 @@
+2020-08-28  Chris Lord  <[email protected]>
+
+        Add WebGL(2) context support to OffscreenCanvas
+        https://bugs.webkit.org/show_bug.cgi?id=209809
+
+        Reviewed by Dean Jackson.
+
+        Enable WebGL contexts with OffscreenCanvas by making sure the required
+        settings are marshalled to workers and that any functionality that
+        doesn't require an HTMLCanvasElement uses CanvasBase instead.
+
+        No new tests, rebaselined existing test.
+
+        * html/CanvasBase.h:
+        * html/CustomPaintCanvas.cpp:
+        (WebCore::CustomPaintCanvas::clearCopiedImage const):
+        * html/CustomPaintCanvas.h:
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::clearCopiedImage const):
+        * html/HTMLCanvasElement.h:
+        * html/OffscreenCanvas.cpp:
+        (WebCore::requiresAcceleratedCompositingForWebGL):
+        (WebCore::shouldEnableWebGL):
+        (WebCore::OffscreenCanvas::createContextWebGL):
+        (WebCore::OffscreenCanvas::getContext):
+        * html/OffscreenCanvas.h:
+        * html/OffscreenCanvas.idl:
+        * html/canvas/WebGL2RenderingContext.idl:
+        * html/canvas/WebGLRenderingContext.idl:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
+        (WebCore::WebGLRenderingContextBase::markContextChanged):
+        (WebCore::WebGLRenderingContextBase::paintRenderingResultsToCanvas):
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::WorkerGlobalScope):
+        * workers/WorkerGlobalScope.h:
+        (WebCore::WorkerGlobalScope::acceleratedCompositingEnabled const):
+        (WebCore::WorkerGlobalScope::webGLEnabled const):
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+        * workers/WorkerThread.cpp:
+        (WebCore::WorkerParameters::isolatedCopy const):
+        * workers/WorkerThread.h:
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
+
 2020-08-27  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] LineBuilder:Run should not have vertical geometry

Modified: trunk/Source/WebCore/html/CanvasBase.h (266274 => 266275)


--- trunk/Source/WebCore/html/CanvasBase.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/CanvasBase.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -101,6 +101,8 @@
     virtual void didDraw(const FloatRect&) = 0;
 
     virtual Image* copiedImage() const = 0;
+    virtual void clearCopiedImage() const = 0;
+
     bool callTracingActive() const;
 
 protected:

Modified: trunk/Source/WebCore/html/CustomPaintCanvas.cpp (266274 => 266275)


--- trunk/Source/WebCore/html/CustomPaintCanvas.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/CustomPaintCanvas.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -105,6 +105,11 @@
     return m_copiedImage.get();
 }
 
+void CustomPaintCanvas::clearCopiedImage() const
+{
+    m_copiedImage = nullptr;
+}
+
 GraphicsContext* CustomPaintCanvas::drawingContext() const
 {
     return m_destinationGraphicsContext;

Modified: trunk/Source/WebCore/html/CustomPaintCanvas.h (266274 => 266275)


--- trunk/Source/WebCore/html/CustomPaintCanvas.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/CustomPaintCanvas.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -63,6 +63,8 @@
 
     AffineTransform baseTransform() const final { ASSERT(m_destinationGraphicsContext && m_copiedBuffer); return m_copiedBuffer->baseTransform(); }
     Image* copiedImage() const final;
+    void clearCopiedImage() const final;
+
     void replayDisplayList(GraphicsContext*) const;
 
     using RefCounted::ref;

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (266274 => 266275)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -1002,7 +1002,7 @@
     }
 }
 
-void HTMLCanvasElement::clearCopiedImage()
+void HTMLCanvasElement::clearCopiedImage() const
 {
     m_copiedImage = nullptr;
     m_didClearImageBuffer = false;

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (266274 => 266275)


--- trunk/Source/WebCore/html/HTMLCanvasElement.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -113,7 +113,7 @@
 #endif
 
     Image* copiedImage() const final;
-    void clearCopiedImage();
+    void clearCopiedImage() const final;
     RefPtr<ImageData> getImageData();
     void makePresentationCopy();
     void clearPresentationCopy();

Modified: trunk/Source/WebCore/html/OffscreenCanvas.cpp (266274 => 266275)


--- trunk/Source/WebCore/html/OffscreenCanvas.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/OffscreenCanvas.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -39,10 +39,18 @@
 #include "MIMETypeRegistry.h"
 #include "OffscreenCanvasRenderingContext2D.h"
 #include "PlaceholderRenderingContext.h"
-#include "WebGLRenderingContext.h"
 #include "WorkerGlobalScope.h"
 #include <wtf/IsoMallocInlines.h>
 
+#if ENABLE(WEBGL)
+#include "Settings.h"
+#include "WebGLRenderingContext.h"
+
+#if ENABLE(WEBGL2)
+#include "WebGL2RenderingContext.h"
+#endif
+#endif // ENABLE(WEBGL)
+
 namespace WebCore {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(OffscreenCanvas);
@@ -141,6 +149,48 @@
     reset();
 }
 
+#if ENABLE(WEBGL)
+static bool requiresAcceleratedCompositingForWebGL()
+{
+#if PLATFORM(GTK) || PLATFORM(WIN_CAIRO)
+    return false;
+#else
+    return true;
+#endif
+}
+
+static bool shouldEnableWebGL(bool webGLEnabled, bool acceleratedCompositingEnabled)
+{
+    if (!webGLEnabled)
+        return false;
+
+    if (!requiresAcceleratedCompositingForWebGL())
+        return true;
+
+    return acceleratedCompositingEnabled;
+}
+
+void OffscreenCanvas::createContextWebGL(RenderingContextType contextType, WebGLContextAttributes&& attrs)
+{
+    ASSERT(!m_context);
+
+    auto context = scriptExecutionContext();
+    if (context->isWorkerGlobalScope()) {
+        WorkerGlobalScope& workerGlobalScope = downcast<WorkerGlobalScope>(*context);
+        if (!shouldEnableWebGL(workerGlobalScope.webGLEnabled(), workerGlobalScope.acceleratedCompositingEnabled()))
+            return;
+    } else if (context->isDocument()) {
+        auto& settings = downcast<Document>(*context).settings();
+        if (!shouldEnableWebGL(settings.webGLEnabled(), settings.acceleratedCompositingEnabled()))
+            return;
+    } else
+        return;
+
+    m_context = WebGLRenderingContextBase::create(*this, attrs, (contextType == RenderingContextType::Webgl) ? "webgl" : "webgl2");
+}
+
+#endif // ENABLE(WEBGL)
+
 ExceptionOr<Optional<OffscreenRenderingContext>> OffscreenCanvas::getContext(JSC::JSGlobalObject& state, RenderingContextType contextType, Vector<JSC::Strong<JSC::Unknown>>&& arguments)
 {
     if (m_detached)
@@ -160,10 +210,14 @@
         return { { RefPtr<OffscreenCanvasRenderingContext2D> { &downcast<OffscreenCanvasRenderingContext2D>(*m_context) } } };
     }
 #if ENABLE(WEBGL)
-    if (contextType == RenderingContextType::Webgl) {
+    else {
         if (m_context) {
             if (is<WebGLRenderingContext>(*m_context))
                 return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } };
+#if ENABLE(WEBGL2)
+            if (is<WebGL2RenderingContext>(*m_context))
+                return { { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*m_context) } } };
+#endif
             return { { WTF::nullopt } };
         }
 
@@ -171,10 +225,14 @@
         auto attributes = convert<IDLDictionary<WebGLContextAttributes>>(state, !arguments.isEmpty() ? arguments[0].get() : JSC::jsUndefined());
         RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
 
-        m_context = WebGLRenderingContextBase::create(*this, attributes, "webgl");
+        createContextWebGL(contextType, WTFMove(attributes));
         if (!m_context)
             return { { WTF::nullopt } };
 
+#if ENABLE(WEBGL2)
+        if (is<WebGL2RenderingContext>(*m_context))
+            return { { RefPtr<WebGL2RenderingContext> { &downcast<WebGL2RenderingContext>(*m_context) } } };
+#endif
         return { { RefPtr<WebGLRenderingContext> { &downcast<WebGLRenderingContext>(*m_context) } } };
     }
 #endif

Modified: trunk/Source/WebCore/html/OffscreenCanvas.h (266274 => 266275)


--- trunk/Source/WebCore/html/OffscreenCanvas.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/OffscreenCanvas.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -40,7 +40,11 @@
 #include <wtf/RefCounted.h>
 #include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
+#if ENABLE(WEBGL)
+#include "WebGLContextAttributes.h"
+#endif
 
+
 namespace WebCore {
 
 class CanvasRenderingContext;
@@ -50,13 +54,19 @@
 class ImageBitmap;
 class ImageData;
 class OffscreenCanvasRenderingContext2D;
+class WebGL2RenderingContext;
 class WebGLRenderingContext;
+class WebGLRenderingContextBase;
 
+using OffscreenRenderingContext = Variant<
 #if ENABLE(WEBGL)
-using OffscreenRenderingContext = Variant<RefPtr<OffscreenCanvasRenderingContext2D>, RefPtr<WebGLRenderingContext>>;
-#else
-using OffscreenRenderingContext = Variant<RefPtr<OffscreenCanvasRenderingContext2D>>;
+    RefPtr<WebGLRenderingContext>,
 #endif
+#if ENABLE(WEBGL2)
+    RefPtr<WebGL2RenderingContext>,
+#endif
+    RefPtr<OffscreenCanvasRenderingContext2D>
+>;
 
 class DetachedOffscreenCanvas {
     WTF_MAKE_NONCOPYABLE(DetachedOffscreenCanvas);
@@ -96,7 +106,8 @@
 
     enum class RenderingContextType {
         _2d,
-        Webgl
+        Webgl,
+        Webgl2
     };
 
     static Ref<OffscreenCanvas> create(ScriptExecutionContext&, unsigned width, unsigned height);
@@ -118,6 +129,8 @@
     void didDraw(const FloatRect&) final;
 
     Image* copiedImage() const final;
+    void clearCopiedImage() const final;
+
     bool hasCreatedImageBuffer() const final { return m_hasCreatedImageBuffer; }
 
     SecurityOrigin* securityOrigin() const final;
@@ -149,13 +162,16 @@
     void derefCanvasBase() final { deref(); }
 
     void setSize(const IntSize&) final;
+
+#if ENABLE(WEBGL)
+    void createContextWebGL(RenderingContextType, WebGLContextAttributes&& = { });
+#endif
+
     void createImageBuffer() const final;
     std::unique_ptr<ImageBuffer> takeImageBuffer() const;
 
     void reset();
 
-    void clearCopiedImage() const;
-
     void setPlaceholderCanvas(HTMLCanvasElement&);
     void pushBufferToPlaceholder();
     void scheduleCommitToPlaceholderCanvas();

Modified: trunk/Source/WebCore/html/OffscreenCanvas.idl (266274 => 266275)


--- trunk/Source/WebCore/html/OffscreenCanvas.idl	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/OffscreenCanvas.idl	2020-08-28 08:46:45 UTC (rev 266275)
@@ -23,11 +23,14 @@
 * THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+typedef (
 #if defined(ENABLE_WEBGL) && ENABLE_WEBGL
-typedef (OffscreenCanvasRenderingContext2D or WebGLRenderingContext) OffscreenRenderingContext;
-#else
-typedef (OffscreenCanvasRenderingContext2D) OffscreenRenderingContext;
+    WebGLRenderingContext or
 #endif
+#if defined(ENABLE_WEBGL2) && ENABLE_WEBGL2
+    WebGL2RenderingContext or
+#endif
+    OffscreenCanvasRenderingContext2D) OffscreenRenderingContext;
 
 dictionary ImageEncodeOptions
 {
@@ -38,7 +41,8 @@
 enum OffscreenRenderingContextType
 {
    "2d",
-   "webgl"
+   "webgl",
+   "webgl2"
 };
 
 [

Modified: trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.idl (266274 => 266275)


--- trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.idl	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/canvas/WebGL2RenderingContext.idl	2020-08-28 08:46:45 UTC (rev 266275)
@@ -58,6 +58,7 @@
     JSCustomMarkFunction,
     JSGenerateToJSObject,
     DoNotCheckConstants,
+    Exposed=(Window,Worker),
     CallTracingCallback=recordCanvasAction,
 ] interface WebGL2RenderingContext {
 

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContext.idl (266274 => 266275)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContext.idl	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContext.idl	2020-08-28 08:46:45 UTC (rev 266275)
@@ -41,6 +41,7 @@
     JSGenerateToJSObject,
     DoNotCheckConstants,
     ExportMacro=WEBCORE_EXPORT,
+    Exposed=(Window,Worker),
     CallTracingCallback=recordCanvasAction,
 ] interface WebGLRenderingContext {
 };

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (266274 => 266275)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -751,7 +751,8 @@
     m_restoreTimer.suspendIfNeeded();
 
     registerWithWebGLStateTracker();
-    m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay);
+    if (canvas.isHTMLCanvasElement())
+        m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay);
 }
 
 WebGLRenderingContextBase::WebGLRenderingContextBase(CanvasBase& canvas, Ref<GraphicsContextGLOpenGL>&& context, WebGLContextAttributes attributes)
@@ -778,7 +779,8 @@
     setupFlags();
 
     registerWithWebGLStateTracker();
-    m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay);
+    if (canvas.isHTMLCanvasElement())
+        m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay);
 
     addActivityStateChangeObserverIfNecessary();
 }
@@ -1067,21 +1069,20 @@
 
     m_layerCleared = false;
 
-    auto* canvas = htmlCanvas();
-    if (!canvas)
-        return;
-
-    RenderBox* renderBox = canvas->renderBox();
-    if (isAccelerated() && renderBox && renderBox->hasAcceleratedCompositing()) {
-        m_markedCanvasDirty = true;
-        htmlCanvas()->clearCopiedImage();
-        renderBox->contentChanged(CanvasPixelsChanged);
-    } else {
-        if (!m_markedCanvasDirty) {
+    if (auto* canvas = htmlCanvas()) {
+        RenderBox* renderBox = canvas->renderBox();
+        if (isAccelerated() && renderBox && renderBox->hasAcceleratedCompositing()) {
             m_markedCanvasDirty = true;
-            canvas->didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize()));
+            canvas->clearCopiedImage();
+            renderBox->contentChanged(CanvasPixelsChanged);
+            return;
         }
     }
+
+    if (!m_markedCanvasDirty) {
+        m_markedCanvasDirty = true;
+        canvasBase().didDraw(FloatRect(FloatPoint(0, 0), clampedCanvasSize()));
+    }
 }
 
 void WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver()
@@ -1192,30 +1193,31 @@
     if (isContextLostOrPending())
         return;
 
-    auto* canvas = htmlCanvas();
-    if (!canvas)
-        return;
+    if (auto* canvas = htmlCanvas()) {
+        if (canvas->document().printing() || (canvas->isSnapshotting() && canvas->document().page()->isVisible()))
+            canvas->clearPresentationCopy();
 
-    if (canvas->document().printing() || (canvas->isSnapshotting() && canvas->document().page()->isVisible()))
-        canvas->clearPresentationCopy();
+        // Until the canvas is written to by the application, the clear that
+        // happened after it was composited should be ignored by the compositor.
+        if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) {
+            m_context->paintRenderingResultsToCanvas(canvas->buffer());
 
-    // Until the canvas is written to by the application, the clear that
-    // happened after it was composited should be ignored by the compositor.
-    if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) {
-        m_context->paintRenderingResultsToCanvas(canvas->buffer());
+            canvas->makePresentationCopy();
+        } else
+            canvas->clearPresentationCopy();
+    }
 
-        canvas->makePresentationCopy();
-    } else
-        canvas->clearPresentationCopy();
     clearIfComposited();
 
     if (!m_markedCanvasDirty && !m_layerCleared)
         return;
 
-    canvas->clearCopiedImage();
+    auto& base = canvasBase();
+    base.clearCopiedImage();
+
     m_markedCanvasDirty = false;
 
-    m_context->paintRenderingResultsToCanvas(canvas->buffer());
+    m_context->paintRenderingResultsToCanvas(base.buffer());
 }
 
 RefPtr<ImageData> WebGLRenderingContextBase::paintRenderingResultsToImageData()

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (266274 => 266275)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -79,6 +79,8 @@
     , m_performance(Performance::create(this, params.timeOrigin))
     , m_referrerPolicy(params.referrerPolicy)
     , m_requestAnimationFrameEnabled(params.requestAnimationFrameEnabled)
+    , m_acceleratedCompositingEnabled(params.acceleratedCompositingEnabled)
+    , m_webGLEnabled(params.webGLEnabled)
 {
 #if !ENABLE(INDEXED_DATABASE)
     UNUSED_PARAM(connectionProxy);

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (266274 => 266275)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -142,6 +142,8 @@
     ReferrerPolicy referrerPolicy() const final;
 
     bool requestAnimationFrameEnabled() const { return m_requestAnimationFrameEnabled; }
+    bool acceleratedCompositingEnabled() const { return m_acceleratedCompositingEnabled; }
+    bool webGLEnabled() const { return m_webGLEnabled; }
 
 protected:
     WorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, WorkerThread&, Ref<SecurityOrigin>&& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
@@ -223,6 +225,8 @@
     std::unique_ptr<CSSValuePool> m_cssValuePool;
     ReferrerPolicy m_referrerPolicy;
     bool m_requestAnimationFrameEnabled;
+    bool m_acceleratedCompositingEnabled;
+    bool m_webGLEnabled;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp (266274 => 266275)


--- trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -89,7 +89,7 @@
 
     SocketProvider* socketProvider = document.socketProvider();
 
-    WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy, document.settings().requestAnimationFrameEnabled() };
+    WorkerParameters params = { scriptURL, name, identifier, userAgent, isOnline, contentSecurityPolicyResponseHeaders, shouldBypassMainWorldContentSecurityPolicy, timeOrigin, referrerPolicy, document.settings().requestAnimationFrameEnabled(), document.settings().acceleratedCompositingEnabled(), document.settings().webGLEnabled() };
     auto thread = DedicatedWorkerThread::create(params, sourceCode, *this, *this, *this, startMode, document.topOrigin(), proxy, socketProvider, runtimeFlags);
 
     workerThreadCreated(thread.get());

Modified: trunk/Source/WebCore/workers/WorkerThread.cpp (266274 => 266275)


--- trunk/Source/WebCore/workers/WorkerThread.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/WorkerThread.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -82,6 +82,8 @@
         timeOrigin,
         referrerPolicy,
         requestAnimationFrameEnabled,
+        acceleratedCompositingEnabled,
+        webGLEnabled,
     };
 }
 

Modified: trunk/Source/WebCore/workers/WorkerThread.h (266274 => 266275)


--- trunk/Source/WebCore/workers/WorkerThread.h	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/WorkerThread.h	2020-08-28 08:46:45 UTC (rev 266275)
@@ -69,6 +69,8 @@
     MonotonicTime timeOrigin;
     ReferrerPolicy referrerPolicy;
     bool requestAnimationFrameEnabled;
+    bool acceleratedCompositingEnabled;
+    bool webGLEnabled;
 
     WorkerParameters isolatedCopy() const;
 };

Modified: trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp (266274 => 266275)


--- trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2020-08-28 04:49:10 UTC (rev 266274)
+++ trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp	2020-08-28 08:46:45 UTC (rev 266275)
@@ -74,7 +74,7 @@
 // FIXME: Use valid runtime flags
 
 ServiceWorkerThread::ServiceWorkerThread(const ServiceWorkerContextData& data, String&& userAgent, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider)
-    : 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())
+    : 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())
     , m_data(data.isolatedCopy())
     , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
     , m_heartBeatTimeout(SWContextManager::singleton().connection()->shouldUseShortTimeout() ? heartBeatTimeoutForTest : heartBeatTimeout)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to