Skip to content

Commit

Permalink
[WebGPU] WebGPU is not working correctly in an offscreen canvas
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266448
<radar://119698186>

Reviewed by Tadeu Zagallo.

When OffscreenCanvas's scriptExecutionContext is a Document,
get the Navigator instance from its local DOMWindow to create
the gpu context.

* Source/WebCore/html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::getContext):

Canonical link: https://commits.webkit.org/272515@main
  • Loading branch information
mwyrzykowski committed Dec 27, 2023
1 parent 30edec4 commit 1598a12
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Source/WebCore/html/OffscreenCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
#include "WebGL2RenderingContext.h"
#endif // ENABLE(WEBGL)

#if HAVE(WEBGPU_IMPLEMENTATION)
#include "LocalDomWindow.h"
#include "Navigator.h"
#endif

namespace WebCore {

WTF_MAKE_ISO_ALLOCATED_IMPL(OffscreenCanvas);
Expand Down Expand Up @@ -243,16 +248,26 @@ ExceptionOr<std::optional<OffscreenRenderingContext>> OffscreenCanvas::getContex
return { { std::nullopt } };
}
if (contextType == RenderingContextType::Webgpu) {
#if HAVE(WEBGPU_IMPLEMENTATION)
if (!m_context) {
auto scope = DECLARE_THROW_SCOPE(state.vm());
RETURN_IF_EXCEPTION(scope, Exception { ExceptionCode::ExistingExceptionError });
if (auto* globalScope = dynamicDowncast<WorkerGlobalScope>(this->scriptExecutionContext())) {
if (auto* gpu = globalScope->navigator().gpu())
auto* scriptExecutionContext = this->scriptExecutionContext();
if (scriptExecutionContext->isWorkerGlobalScope()) {
auto& globalScope = downcast<WorkerGlobalScope>(*scriptExecutionContext);
if (auto* gpu = globalScope.navigator().gpu())
m_context = GPUCanvasContext::create(*this, *gpu);
} else if (scriptExecutionContext->isDocument()) {
auto& document = downcast<Document>(*scriptExecutionContext);
if (auto* domWindow = document.domWindow()) {
if (auto* gpu = domWindow->navigator().gpu())
m_context = GPUCanvasContext::create(*this, *gpu);
}
}
}
if (RefPtr context = dynamicDowncast<GPUCanvasContext>(m_context.get()))
return { { WTFMove(context) } };
#endif
return { { std::nullopt } };
}
#if ENABLE(WEBGL)
Expand Down

0 comments on commit 1598a12

Please sign in to comment.