Skip to content
Permalink
Browse files
WebGL fails to initialize within an OffscreenCanvas on the main thread.
https://bugs.webkit.org/show_bug.cgi?id=249679
<rdar://problem/103572325>

Reviewed by Dean Jackson.

Lookup GraphicsClient using the ScriptExecutionContext instead of via HTMLCanvasElement.
This handles the case where the CanvasBase is an OffscreenCanvas, but we're on the main thread (and not a worker).

* LayoutTests/fast/mediacapturefromelement/CanvasCaptureMediaStream-offscreencanvas-expected.txt:
* LayoutTests/http/wpt/offscreen-canvas/getContext-webgl-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/webxr/webGLCanvasContext_create_xrcompatible.https-expected.txt:
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.getcontext-expected.txt.
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap-expected.txt.
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable-expected.txt: Copied from LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable-expected.txt.
* LayoutTests/platform/gtk/imported/w3c/web-platform-tests/webxr/webGLCanvasContext_create_xrcompatible.https-expected.txt: Renamed from LayoutTests/platform/mac-wk1/imported/w3c/web-platform-tests/webxr/webGLCanvasContext_create_xrcompatible.https-expected.txt.
* LayoutTests/platform/mac-wk1/fast/mediacapturefromelement/CanvasCaptureMediaStream-offscreencanvas-expected.txt: Removed.
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::getGraphicsClient):

Canonical link: https://commits.webkit.org/258222@main
  • Loading branch information
mattwoodrow committed Dec 22, 2022
1 parent 3404d08 commit 301e966c8ef8d1b14afe220ba29d771588b61b8b
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 23 deletions.
@@ -1,4 +1,4 @@

PASS capture of an OffscreenCanvas with 2D context
FAIL capture of an OffscreenCanvas with WebGL context null is not an object (evaluating 'gl.clearColor')
FAIL capture of an OffscreenCanvas with WebGL context ctx.commit is not a function. (In 'ctx.commit()', 'ctx.commit' is undefined)

@@ -1,3 +1,3 @@

FAIL Test getContext('webgl'). assert_true: expected true got false
PASS Test getContext('webgl').

@@ -1,9 +1,9 @@

PASS Test that getContext with un-supported string throws a TypeError.
FAIL Test that getContext with supported string returns correct results assert_true: expected true got false
FAIL Test that getContext twice with different context type returns null the second time assert_equals: expected null but got object "[object OffscreenCanvasRenderingContext2D]"
PASS Test that getContext with supported string returns correct results
PASS Test that getContext twice with different context type returns null the second time
PASS Test that 2dcontext.canvas should return the original OffscreenCanvas
FAIL Test that webglcontext.canvas should return the original OffscreenCanvas null is not an object (evaluating 'ctx.canvas')
PASS Test that webglcontext.canvas should return the original OffscreenCanvas
FAIL Test that OffscreenCanvasRenderingContext2D with alpha disabled makes the OffscreenCanvas opaque assert_approx_equals: Green channel of the pixel at (5, 5) expected 127 +/- 2 but got 255
PASS Test that OffscreenCanvasRenderingContext2D with alpha enabled preserves the alpha
PASS Test that 'alpha' context creation attribute is true by default
@@ -1,5 +1,5 @@

FAIL Test that transferToImageBitmap returns an ImageBitmap with correct width and height The object is in an invalid state.
PASS Test that transferToImageBitmap returns an ImageBitmap with correct width and height
FAIL Test that transferToImageBitmap returns an ImageBitmap with correct color assert_equals: Alpha channel of the pixel at (50, 25) expected 255 but got 0
PASS Test that transferToImageBitmap won't change context's property
PASS Test that transferToImageBitmap preserves transform
@@ -1,8 +1,6 @@

PASS Test that offscreenCanvas's size is correct after being transferred to a worker.
FAIL Test that transfer an OffscreenCanvas that has a context throws exception. assert_throws_dom: function "function () {
worker.postMessage({offscreenCanvas}, [offscreenCanvas]);
}" did not throw
PASS Test that transfer an OffscreenCanvas that has a context throws exception.
PASS Test that transfer an OffscreenCanvas twice throws exception.
PASS Test that calling getContext('2d') on a detached OffscreenCanvas throws exception.
PASS Test that calling getContext('webgl') on a detached OffscreenCanvas throws exception.
@@ -1,6 +1,6 @@

PASS Creating a webgl context with no device
PASS Creating a webgl2 context with no device
FAIL An XR-compatible webgl context can be created promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'gl.makeXRCompatible')"
FAIL An XR-compatible webgl2 context can be created promise_test: Unhandled rejection with value: object "TypeError: null is not an object (evaluating 'gl.makeXRCompatible')"
FAIL An XR-compatible webgl context can be created promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
FAIL An XR-compatible webgl2 context can be created promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."

@@ -0,0 +1,9 @@

PASS Test that getContext with un-supported string throws a TypeError.
FAIL Test that getContext with supported string returns correct results assert_true: expected true got false
FAIL Test that getContext twice with different context type returns null the second time assert_equals: expected null but got object "[object OffscreenCanvasRenderingContext2D]"
PASS Test that 2dcontext.canvas should return the original OffscreenCanvas
FAIL Test that webglcontext.canvas should return the original OffscreenCanvas null is not an object (evaluating 'ctx.canvas')
FAIL Test that OffscreenCanvasRenderingContext2D with alpha disabled makes the OffscreenCanvas opaque assert_approx_equals: Green channel of the pixel at (5, 5) expected 127 +/- 2 but got 255
PASS Test that OffscreenCanvasRenderingContext2D with alpha enabled preserves the alpha
PASS Test that 'alpha' context creation attribute is true by default
@@ -0,0 +1,8 @@

FAIL Test that transferToImageBitmap returns an ImageBitmap with correct width and height The object is in an invalid state.
FAIL Test that transferToImageBitmap returns an ImageBitmap with correct color assert_equals: Alpha channel of the pixel at (50, 25) expected 255 but got 0
PASS Test that transferToImageBitmap won't change context's property
PASS Test that transferToImageBitmap preserves transform
PASS Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception
PASS Test that transferToImageBitmap without a context throws an exception

@@ -0,0 +1,9 @@

PASS Test that offscreenCanvas's size is correct after being transferred to a worker.
FAIL Test that transfer an OffscreenCanvas that has a context throws exception. assert_throws_dom: function "function () {
worker.postMessage({offscreenCanvas}, [offscreenCanvas]);
}" did not throw
PASS Test that transfer an OffscreenCanvas twice throws exception.
PASS Test that calling getContext('2d') on a detached OffscreenCanvas throws exception.
PASS Test that calling getContext('webgl') on a detached OffscreenCanvas throws exception.

This file was deleted.

@@ -30,6 +30,7 @@

#include "ANGLEInstancedArrays.h"
#include "CachedImage.h"
#include "Chrome.h"
#include "DOMWindow.h"
#include "DiagnosticLoggingClient.h"
#include "DiagnosticLoggingKeys.h"
@@ -486,16 +487,12 @@ static void removeActiveContext(WebGLRenderingContextBase& context)

static GraphicsClient* getGraphicsClient(CanvasBase& canvas)
{
if (auto* canvasElement = dynamicDowncast<HTMLCanvasElement>(canvas)) {
Document& document = canvasElement->document();
RefPtr<Frame> frame = document.frame();
if (!frame)
return nullptr;

return document.view()->root()->hostWindow();
}
if (is<WorkerGlobalScope>(canvas.scriptExecutionContext()))
return downcast<WorkerGlobalScope>(canvas.scriptExecutionContext())->workerClient();
else if (is<Document>(canvas.scriptExecutionContext())) {
ASSERT(downcast<Document>(canvas.scriptExecutionContext())->page());
return &downcast<Document>(canvas.scriptExecutionContext())->page()->chrome();
}

return nullptr;
}

0 comments on commit 301e966

Please sign in to comment.