From 4f0e81892052000889862a3199c94974dccde096 Mon Sep 17 00:00:00 2001 From: "justin_fan@apple.com" Date: Tue, 30 Apr 2019 16:33:35 +0000 Subject: [PATCH] [WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator https://bugs.webkit.org/show_bug.cgi?id=197348 Reviewed by Myles C. Maxfield. Source/WebCore: Latest API provides 'gpu' through Navigator instead of DOMWindow. Replace DOMWindowWebGPU with NavigatorGPU. Existing tests updated to match. Add test: webgpu-enabled-in-worker.html to ensure workers can access WebGPU. * CMakeLists.txt: * DerivedSources.make: * Modules/webgpu/NavigatorGPU.cpp: (WebCore::NavigatorGPU::from): (WebCore::NavigatorGPU::supplementName): (WebCore::NavigatorGPU::gpu): (WebCore::NavigatorGPU::gpu const): * Modules/webgpu/NavigatorGPU.h: * Modules/webgpu/NavigatorGPU.idl: * Modules/webgpu/WorkerNavigatorGPU.cpp: (WebCore::WorkerNavigatorGPU::from): (WebCore::WorkerNavigatorGPU::supplementName): (WebCore::WorkerNavigatorGPU::gpu): (WebCore::WorkerNavigatorGPU::gpu const): * Modules/webgpu/WorkerNavigatorGPU.h: * Modules/webgpu/WorkerNavigatorGPU.idl: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: LayoutTests: WebGPU is now accessed through navigator.gpu instead of window.gpu. Add webgpu-enabled-in-worker to ensure workers can access WebGPU. * webgpu/adapter-options.html: * webgpu/js/create-worker-device.js: Added. (async.tryCreateDevice): * webgpu/js/webgpu-functions.js: (async.getBasicDevice): * webgpu/queue-creation.html: * webgpu/webgpu-enabled-in-worker-expected.txt: Added. * webgpu/webgpu-enabled-in-worker.html: Added. * webgpu/webgpu-enabled.html: * webgpu/whlsl.html: Add navigator.gpu to expectations for navigator-detached-no-crash. * fast/dom/navigator-detached-no-crash-expected.txt: * platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt: * platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244777 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 26 ++++++++ .../dom/navigator-detached-no-crash-expected.txt | 2 + .../dom/navigator-detached-no-crash-expected.txt | 2 + .../dom/navigator-detached-no-crash-expected.txt | 2 + LayoutTests/webgpu/adapter-options.html | 6 +- LayoutTests/webgpu/js/create-worker-device.js | 11 ++++ LayoutTests/webgpu/js/webgpu-functions.js | 2 +- LayoutTests/webgpu/queue-creation.html | 4 +- .../webgpu/webgpu-enabled-in-worker-expected.txt | 3 + LayoutTests/webgpu/webgpu-enabled-in-worker.html | 20 +++++++ LayoutTests/webgpu/webgpu-enabled.html | 5 +- LayoutTests/webgpu/whlsl.html | 2 +- Source/WebCore/CMakeLists.txt | 3 +- Source/WebCore/ChangeLog | 30 ++++++++++ Source/WebCore/DerivedSources.make | 3 +- .../{DOMWindowWebGPU.cpp => NavigatorGPU.cpp} | 35 +++++------ .../webgpu/{DOMWindowWebGPU.h => NavigatorGPU.h} | 14 ++--- Source/WebCore/Modules/webgpu/NavigatorGPU.idl | 33 +++++++++++ .../WebCore/Modules/webgpu/WorkerNavigatorGPU.cpp | 69 ++++++++++++++++++++++ Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.h | 53 +++++++++++++++++ ...{DOMWindowWebGPU.idl => WorkerNavigatorGPU.idl} | 6 +- Source/WebCore/Sources.txt | 6 +- Source/WebCore/WebCore.xcodeproj/project.pbxproj | 20 ++++--- 23 files changed, 306 insertions(+), 51 deletions(-) create mode 100644 LayoutTests/webgpu/js/create-worker-device.js create mode 100644 LayoutTests/webgpu/webgpu-enabled-in-worker-expected.txt create mode 100644 LayoutTests/webgpu/webgpu-enabled-in-worker.html rename Source/WebCore/Modules/webgpu/{DOMWindowWebGPU.cpp => NavigatorGPU.cpp} (71%) rename Source/WebCore/Modules/webgpu/{DOMWindowWebGPU.h => NavigatorGPU.h} (83%) create mode 100644 Source/WebCore/Modules/webgpu/NavigatorGPU.idl create mode 100644 Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.cpp create mode 100644 Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.h rename Source/WebCore/Modules/webgpu/{DOMWindowWebGPU.idl => WorkerNavigatorGPU.idl} (89%) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 47a8225..2d4c1a0 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,29 @@ +2019-04-30 Justin Fan + + [WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator + https://bugs.webkit.org/show_bug.cgi?id=197348 + + Reviewed by Myles C. Maxfield. + + WebGPU is now accessed through navigator.gpu instead of window.gpu. + Add webgpu-enabled-in-worker to ensure workers can access WebGPU. + + * webgpu/adapter-options.html: + * webgpu/js/create-worker-device.js: Added. + (async.tryCreateDevice): + * webgpu/js/webgpu-functions.js: + (async.getBasicDevice): + * webgpu/queue-creation.html: + * webgpu/webgpu-enabled-in-worker-expected.txt: Added. + * webgpu/webgpu-enabled-in-worker.html: Added. + * webgpu/webgpu-enabled.html: + * webgpu/whlsl.html: + + Add navigator.gpu to expectations for navigator-detached-no-crash. + * fast/dom/navigator-detached-no-crash-expected.txt: + * platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt: + * platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt: + 2019-04-30 Youenn Fablet Update WPT service-worker resource-timing test to use hosts[alt] diff --git a/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt index d9f644f..f2f63e8 100644 --- a/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt +++ b/LayoutTests/fast/dom/navigator-detached-no-crash-expected.txt @@ -8,6 +8,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK @@ -33,6 +34,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK diff --git a/LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt index d93add7..7953fa5 100644 --- a/LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt +++ b/LayoutTests/platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt @@ -7,6 +7,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK @@ -30,6 +31,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK diff --git a/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt b/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt index 6c99ccb..924b329 100644 --- a/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt +++ b/LayoutTests/platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt @@ -8,6 +8,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK @@ -32,6 +33,7 @@ navigator.appVersion is OK navigator.cookieEnabled is OK navigator.credentials is OK navigator.getStorageUpdates() is OK +navigator.gpu is OK navigator.javaEnabled() is OK navigator.language is OK navigator.languages is OK diff --git a/LayoutTests/webgpu/adapter-options.html b/LayoutTests/webgpu/adapter-options.html index 986cce1..9f5187a 100644 --- a/LayoutTests/webgpu/adapter-options.html +++ b/LayoutTests/webgpu/adapter-options.html @@ -6,21 +6,21 @@ + + + \ No newline at end of file diff --git a/LayoutTests/webgpu/webgpu-enabled.html b/LayoutTests/webgpu/webgpu-enabled.html index 76d6c38..537350b 100644 --- a/LayoutTests/webgpu/webgpu-enabled.html +++ b/LayoutTests/webgpu/webgpu-enabled.html @@ -10,9 +10,10 @@ promise_test(async () => { const context = canvas.getContext("gpu"); assert_true(context instanceof GPUCanvasContext, "Created GPUCanvasContext."); - assert_not_equals(window.gpu, undefined, "window.gpu is defined."); + assert_equals(window.gpu, undefined, "window.gpu should not be defined.") + assert_not_equals(navigator.gpu, undefined, "navigator.gpu is defined."); - const adapter = await window.gpu.requestAdapter(); + const adapter = await navigator.gpu.requestAdapter(); assert_true(adapter instanceof WebGPUAdapter, "Created default GPUAdapter."); const device = await adapter.requestDevice(); diff --git a/LayoutTests/webgpu/whlsl.html b/LayoutTests/webgpu/whlsl.html index 47aa518..7c7d79e 100644 --- a/LayoutTests/webgpu/whlsl.html +++ b/LayoutTests/webgpu/whlsl.html @@ -15,7 +15,7 @@ fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 { } `; async function start() { - const adapter = await window.gpu.requestAdapter(); + const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true}); diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 2a83ee0..e06abb5 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -468,7 +468,6 @@ set(WebCore_NON_SVG_IDL_FILES Modules/webdriver/NavigatorWebDriver.idl - Modules/webgpu/DOMWindowWebGPU.idl Modules/webgpu/GPUBindGroupLayoutBinding.idl Modules/webgpu/GPUBindGroupLayoutDescriptor.idl Modules/webgpu/GPUBlendDescriptor.idl @@ -493,6 +492,7 @@ set(WebCore_NON_SVG_IDL_FILES Modules/webgpu/GPUTextureUsage.idl Modules/webgpu/GPUVertexAttributeDescriptor.idl Modules/webgpu/GPUVertexInputDescriptor.idl + Modules/webgpu/NavigatorGPU.idl Modules/webgpu/WebGPU.idl Modules/webgpu/WebGPUAdapter.idl Modules/webgpu/WebGPUBindGroup.idl @@ -523,6 +523,7 @@ set(WebCore_NON_SVG_IDL_FILES Modules/webgpu/WebGPUSwapChain.idl Modules/webgpu/WebGPUTexture.idl Modules/webgpu/WebGPUTextureView.idl + Modules/webgpu/WorkerNavigatorGPU.idl Modules/websockets/CloseEvent.idl Modules/websockets/WebSocket.idl diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 0e81aeb..0be60be 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,33 @@ +2019-04-30 Justin Fan + + [WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator + https://bugs.webkit.org/show_bug.cgi?id=197348 + + Reviewed by Myles C. Maxfield. + + Latest API provides 'gpu' through Navigator instead of DOMWindow. Replace DOMWindowWebGPU with NavigatorGPU. + + Existing tests updated to match. Add test: webgpu-enabled-in-worker.html to ensure workers can access WebGPU. + + * CMakeLists.txt: + * DerivedSources.make: + * Modules/webgpu/NavigatorGPU.cpp: + (WebCore::NavigatorGPU::from): + (WebCore::NavigatorGPU::supplementName): + (WebCore::NavigatorGPU::gpu): + (WebCore::NavigatorGPU::gpu const): + * Modules/webgpu/NavigatorGPU.h: + * Modules/webgpu/NavigatorGPU.idl: + * Modules/webgpu/WorkerNavigatorGPU.cpp: + (WebCore::WorkerNavigatorGPU::from): + (WebCore::WorkerNavigatorGPU::supplementName): + (WebCore::WorkerNavigatorGPU::gpu): + (WebCore::WorkerNavigatorGPU::gpu const): + * Modules/webgpu/WorkerNavigatorGPU.h: + * Modules/webgpu/WorkerNavigatorGPU.idl: + * Sources.txt: + * WebCore.xcodeproj/project.pbxproj: + 2019-04-30 Zalan Bujtas Double-tapping a post to like doesn't work on Instagram.com (needs 'dblclick' event) diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make index 8e1009f..0433fab8 100644 --- a/Source/WebCore/DerivedSources.make +++ b/Source/WebCore/DerivedSources.make @@ -374,7 +374,6 @@ JS_BINDING_IDLS = \ $(WebCore)/Modules/webdatabase/SQLTransactionCallback.idl \ $(WebCore)/Modules/webdatabase/SQLTransactionErrorCallback.idl \ $(WebCore)/Modules/webdriver/NavigatorWebDriver.idl \ - $(WebCore)/Modules/webgpu/DOMWindowWebGPU.idl \ $(WebCore)/Modules/webgpu/GPUCanvasContext.idl \ $(WebCore)/Modules/webgpu/GPUColor.idl \ $(WebCore)/Modules/webgpu/GPUColorStateDescriptor.idl \ @@ -399,6 +398,7 @@ JS_BINDING_IDLS = \ $(WebCore)/Modules/webgpu/GPUTextureUsage.idl \ $(WebCore)/Modules/webgpu/GPUVertexAttributeDescriptor.idl \ $(WebCore)/Modules/webgpu/GPUVertexInputDescriptor.idl \ + $(WebCore)/Modules/webgpu/NavigatorGPU.idl \ $(WebCore)/Modules/webgpu/WebGPU.idl \ $(WebCore)/Modules/webgpu/WebGPUAdapter.idl \ $(WebCore)/Modules/webgpu/WebGPUBindGroup.idl \ @@ -429,6 +429,7 @@ JS_BINDING_IDLS = \ $(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \ $(WebCore)/Modules/webgpu/WebGPUTexture.idl \ $(WebCore)/Modules/webgpu/WebGPUTextureView.idl \ + $(WebCore)/Modules/webgpu/WorkerNavigatorGPU.idl \ $(WebCore)/Modules/websockets/CloseEvent.idl \ $(WebCore)/Modules/websockets/WebSocket.idl \ $(WebCore)/Modules/webvr/DOMWindowWebVR.idl \ diff --git a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.cpp b/Source/WebCore/Modules/webgpu/NavigatorGPU.cpp similarity index 71% rename from Source/WebCore/Modules/webgpu/DOMWindowWebGPU.cpp rename to Source/WebCore/Modules/webgpu/NavigatorGPU.cpp index 825f733..88a9780 100644 --- a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.cpp +++ b/Source/WebCore/Modules/webgpu/NavigatorGPU.cpp @@ -24,47 +24,42 @@ */ #include "config.h" -#include "DOMWindowWebGPU.h" +#include "NavigatorGPU.h" #if ENABLE(WEBGPU) -#include "DOMWindow.h" +#include "Navigator.h" #include "RuntimeEnabledFeatures.h" #include "WebGPU.h" namespace WebCore { -DOMWindowWebGPU::DOMWindowWebGPU(DOMWindow* window) - : DOMWindowProperty(window) +NavigatorGPU* NavigatorGPU::from(Navigator* navigator) { -} - -const char* DOMWindowWebGPU::supplementName() -{ - return "DOMWindowWebGPU"; -} - -DOMWindowWebGPU* DOMWindowWebGPU::from(DOMWindow* window) -{ - DOMWindowWebGPU* supplement = static_cast(Supplement::from(window, supplementName())); + NavigatorGPU* supplement = static_cast(Supplement::from(navigator, supplementName())); if (!supplement) { - auto newSupplement = std::make_unique(window); + auto newSupplement = std::make_unique(); supplement = newSupplement.get(); - provideTo(window, supplementName(), WTFMove(newSupplement)); + provideTo(navigator, supplementName(), WTFMove(newSupplement)); } return supplement; } -WebGPU* DOMWindowWebGPU::gpu(DOMWindow& window) +const char* NavigatorGPU::supplementName() +{ + return "NavigatorGPU"; +} + +const WebGPU* NavigatorGPU::gpu(Navigator& navigator) { - return DOMWindowWebGPU::from(&window)->gpu(); + return NavigatorGPU::from(&navigator)->gpu(); } -WebGPU* DOMWindowWebGPU::gpu() const +const WebGPU* NavigatorGPU::gpu() const { ASSERT(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled()); - if (!m_gpu && frame()) + if (!m_gpu) m_gpu = WebGPU::create(); return m_gpu.get(); } diff --git a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.h b/Source/WebCore/Modules/webgpu/NavigatorGPU.h similarity index 83% rename from Source/WebCore/Modules/webgpu/DOMWindowWebGPU.h rename to Source/WebCore/Modules/webgpu/NavigatorGPU.h index a8b5bd3..7758d08 100644 --- a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.h +++ b/Source/WebCore/Modules/webgpu/NavigatorGPU.h @@ -27,25 +27,23 @@ #if ENABLE(WEBGPU) -#include "DOMWindowProperty.h" #include "Supplementable.h" namespace WebCore { -class DOMWindow; +class Navigator; class WebGPU; -class DOMWindowWebGPU : public Supplement, public DOMWindowProperty { +class NavigatorGPU final : public Supplement { WTF_MAKE_FAST_ALLOCATED; public: - explicit DOMWindowWebGPU(DOMWindow*); - virtual ~DOMWindowWebGPU() = default; - static DOMWindowWebGPU* from(DOMWindow*); - static WebGPU* gpu(DOMWindow&); - WebGPU* gpu() const; + static const WebGPU* gpu(Navigator&); private: + static NavigatorGPU* from(Navigator*); static const char* supplementName(); + + const WebGPU* gpu() const; mutable RefPtr m_gpu; }; diff --git a/Source/WebCore/Modules/webgpu/NavigatorGPU.idl b/Source/WebCore/Modules/webgpu/NavigatorGPU.idl new file mode 100644 index 0000000..fc2ede1 --- /dev/null +++ b/Source/WebCore/Modules/webgpu/NavigatorGPU.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2018 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +// https://github.com/gpuweb/gpuweb/blob/master/spec/index.bs + +[ + Conditional=WEBGPU, + EnabledAtRuntime=WebGPU, + Exposed=Window +] partial interface Navigator { + [SameObject] readonly attribute WebGPU gpu; +}; diff --git a/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.cpp b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.cpp new file mode 100644 index 0000000..bf90f6c --- /dev/null +++ b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WorkerNavigatorGPU.h" + +#if ENABLE(WEBGPU) + +#include "RuntimeEnabledFeatures.h" +#include "WebGPU.h" +#include "WorkerNavigator.h" + +namespace WebCore { + +WorkerNavigatorGPU* WorkerNavigatorGPU::from(WorkerNavigator* navigator) +{ + WorkerNavigatorGPU* supplement = static_cast(Supplement::from(navigator, supplementName())); + if (!supplement) { + auto newSupplement = std::make_unique(); + supplement = newSupplement.get(); + provideTo(navigator, supplementName(), WTFMove(newSupplement)); + } + return supplement; +} + +const char* WorkerNavigatorGPU::supplementName() +{ + return "WorkerNavigatorGPU"; +} + +const WebGPU* WorkerNavigatorGPU::gpu(WorkerNavigator& navigator) +{ + return WorkerNavigatorGPU::from(&navigator)->gpu(); +} + +const WebGPU* WorkerNavigatorGPU::gpu() const +{ + ASSERT(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled()); + + if (!m_gpu) + m_gpu = WebGPU::create(); + return m_gpu.get(); +} + +} // namespace WebCore + +#endif // ENABLE(WEBGPU) diff --git a/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.h b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.h new file mode 100644 index 0000000..e67453f --- /dev/null +++ b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2018 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#if ENABLE(WEBGPU) + +#include "Supplementable.h" + +namespace WebCore { + +class WebGPU; +class WorkerNavigator; + +class WorkerNavigatorGPU final : public Supplement { + WTF_MAKE_FAST_ALLOCATED; +public: + static const WebGPU* gpu(WorkerNavigator&); + +private: + static WorkerNavigatorGPU* from(WorkerNavigator*); + static const char* supplementName(); + + const WebGPU* gpu() const; + + mutable RefPtr m_gpu; +}; + +} // namespace WebCore + +#endif // ENABLE(WEBGPU) diff --git a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.idl b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.idl similarity index 89% rename from Source/WebCore/Modules/webgpu/DOMWindowWebGPU.idl rename to Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.idl index b06a8b3..aeda689 100644 --- a/Source/WebCore/Modules/webgpu/DOMWindowWebGPU.idl +++ b/Source/WebCore/Modules/webgpu/WorkerNavigatorGPU.idl @@ -22,11 +22,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ -// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl +// https://github.com/gpuweb/gpuweb/blob/master/spec/index.bs [ Conditional=WEBGPU, EnabledAtRuntime=WebGPU -] partial interface DOMWindow { - [Replaceable, SameObject] readonly attribute WebGPU gpu; +] partial interface WorkerNavigator { + [SameObject] readonly attribute WebGPU gpu; }; diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index 3606acb..e09eb2e 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -304,8 +304,8 @@ Modules/websockets/WebSocketFrame.cpp Modules/websockets/WebSocketHandshake.cpp Modules/websockets/WorkerThreadableWebSocketChannel.cpp -Modules/webgpu/DOMWindowWebGPU.cpp Modules/webgpu/GPUCanvasContext.cpp +Modules/webgpu/NavigatorGPU.cpp Modules/webgpu/WHLSL/WHLSLInferTypes.cpp Modules/webgpu/WHLSL/WHLSLLexer.cpp Modules/webgpu/WHLSL/WHLSLParser.cpp @@ -375,6 +375,7 @@ Modules/webgpu/WebGPUSwapChain.cpp Modules/webgpu/WebGPUSwapChainDescriptor.cpp Modules/webgpu/WebGPUTexture.cpp Modules/webgpu/WebGPUTextureView.cpp +Modules/webgpu/WorkerNavigatorGPU.cpp Modules/webvr/NavigatorWebVR.cpp Modules/webvr/VRDisplay.cpp @@ -2655,7 +2656,6 @@ JSDOMWindowFetch.cpp JSDOMWindowIndexedDatabase.cpp JSDOMWindowSpeechSynthesis.cpp JSDOMWindowWebDatabase.cpp -JSDOMWindowWebGPU.cpp JSDOMWindowWebVR.cpp JSDataTransfer.cpp JSDataTransferItem.cpp @@ -2918,6 +2918,7 @@ JSNavigator.cpp JSNavigatorBeacon.cpp JSNavigatorCredentials.cpp JSNavigatorGeolocation.cpp +JSNavigatorGPU.cpp JSNavigatorID.cpp JSNavigatorLanguage.cpp JSNavigatorMediaCapabilities.cpp @@ -3327,6 +3328,7 @@ JSWorkerGlobalScopeFetch.cpp JSWorkerGlobalScopeIndexedDatabase.cpp JSWorkerLocation.cpp JSWorkerNavigator.cpp +JSWorkerNavigatorGPU.cpp JSWorkerType.cpp JSWritableStream.cpp JSXMLDocument.cpp diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index d717275..7bfdca2 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -100,7 +100,6 @@ 0709FC4E1025DEE30059CDBA /* AccessibilitySlider.h in Headers */ = {isa = PBXBuildFile; fileRef = 0709FC4D1025DEE30059CDBA /* AccessibilitySlider.h */; }; 070E09191875EEFC003A1D3C /* PlatformMediaSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 070E09181875ED93003A1D3C /* PlatformMediaSession.h */; settings = {ATTRIBUTES = (Private, ); }; }; 070E81D11BF27656001FDA48 /* VideoTrackPrivateMediaStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 070E81D01BF27656001FDA48 /* VideoTrackPrivateMediaStream.h */; }; - CDA79827170A279100D45C55 /* AudioSessionIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA79825170A279000D45C55 /* AudioSessionIOS.mm */; }; 070F549817F12F6B00169E04 /* MediaStreamConstraintsValidationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 070F549717F12F6B00169E04 /* MediaStreamConstraintsValidationClient.h */; }; 0719427F1D088F21002AA51D /* AVFoundationMIMETypeCache.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07C8AD111D073D630087C5CE /* AVFoundationMIMETypeCache.mm */; }; 071A9EC2168FBC43002629F9 /* TextTrackCueGeneric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 071A9EC0168FB56C002629F9 /* TextTrackCueGeneric.cpp */; }; @@ -4080,6 +4079,7 @@ CDA29A321CC01A9500901CCF /* PlaybackSessionInterfaceAVKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA29A2E1CBF73FC00901CCF /* PlaybackSessionInterfaceAVKit.h */; settings = {ATTRIBUTES = (Private, ); }; }; CDA595932146DEC300A84185 /* HEVCUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA595912146DEC300A84185 /* HEVCUtilities.h */; }; CDA595982146DF7800A84185 /* HEVCUtilitiesCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA595962146DF7800A84185 /* HEVCUtilitiesCocoa.h */; }; + CDA79827170A279100D45C55 /* AudioSessionIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA79825170A279000D45C55 /* AudioSessionIOS.mm */; }; CDA7982A170A3D0000D45C55 /* AudioSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA79821170A22DC00D45C55 /* AudioSession.h */; settings = {ATTRIBUTES = (Private, ); }; }; CDA98E0B1603CD6000FEA3B1 /* LegacyCDM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDA98E091603CD5900FEA3B1 /* LegacyCDM.cpp */; }; CDAB6D2917C7DE6C00C60B34 /* MediaControlsHost.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAB6D2717C7DE6C00C60B34 /* MediaControlsHost.h */; }; @@ -13822,12 +13822,14 @@ D003914122248D400098998C /* GPUProgrammablePassEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUProgrammablePassEncoder.cpp; sourceTree = ""; }; D00487D222457BEA00EED7D9 /* WebGPUPipelineLayoutDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUPipelineLayoutDescriptor.cpp; sourceTree = ""; }; D00487E5226A634200EED7D9 /* WebGPUSwapChainDescriptor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSwapChainDescriptor.cpp; sourceTree = ""; }; + D00487EB2274281200EED7D9 /* NavigatorGPU.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = NavigatorGPU.idl; sourceTree = ""; }; + D00487ED2274281300EED7D9 /* NavigatorGPU.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = NavigatorGPU.cpp; sourceTree = ""; }; + D00487EE2274281400EED7D9 /* NavigatorGPU.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NavigatorGPU.h; sourceTree = ""; }; + D00487FD2277AF8100EED7D9 /* WorkerNavigatorGPU.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WorkerNavigatorGPU.idl; sourceTree = ""; }; + D00487FE2277AF8200EED7D9 /* WorkerNavigatorGPU.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WorkerNavigatorGPU.h; sourceTree = ""; }; D00D77FD2242ED450043F12C /* WebGPUComputePassEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUComputePassEncoder.h; sourceTree = ""; }; D00D77FE2242ED450043F12C /* WebGPUComputePassEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUComputePassEncoder.cpp; sourceTree = ""; }; D00D77FF2242ED450043F12C /* WebGPUComputePassEncoder.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUComputePassEncoder.idl; sourceTree = ""; }; - D00F5940216ECC7A000D71DB /* DOMWindowWebGPU.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DOMWindowWebGPU.h; sourceTree = ""; }; - D00F5941216ECC7A000D71DB /* DOMWindowWebGPU.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowWebGPU.cpp; sourceTree = ""; }; - D00F5942216ECC7A000D71DB /* DOMWindowWebGPU.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMWindowWebGPU.idl; sourceTree = ""; }; D00F5946216EFE54000D71DB /* WebGPU.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPU.h; sourceTree = ""; }; D00F5947216EFE54000D71DB /* WebGPU.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPU.cpp; sourceTree = ""; }; D00F5948216EFE54000D71DB /* WebGPU.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPU.idl; sourceTree = ""; }; @@ -13967,6 +13969,7 @@ D0C419F7218404DA009EC1DE /* WebGPURenderPipeline.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPURenderPipeline.h; sourceTree = ""; }; D0C419F8218404DA009EC1DE /* WebGPURenderPipeline.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPURenderPipeline.cpp; sourceTree = ""; }; D0C419F9218404DA009EC1DE /* WebGPURenderPipeline.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPURenderPipeline.idl; sourceTree = ""; }; + D0CAAD532277C2A600801CDF /* WorkerNavigatorGPU.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerNavigatorGPU.cpp; sourceTree = ""; }; D0CCA94922299F97006979B6 /* GPUOrigin3D.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUOrigin3D.h; sourceTree = ""; }; D0CCA94A22299F97006979B6 /* GPUOrigin3D.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUOrigin3D.idl; sourceTree = ""; }; D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutDescriptor.h; sourceTree = ""; }; @@ -25756,9 +25759,6 @@ isa = PBXGroup; children = ( C210E90D21B4BCA400B7F83D /* WHLSL */, - D00F5941216ECC7A000D71DB /* DOMWindowWebGPU.cpp */, - D00F5940216ECC7A000D71DB /* DOMWindowWebGPU.h */, - D00F5942216ECC7A000D71DB /* DOMWindowWebGPU.idl */, D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */, D0D69C9F222E015E0032927E /* GPUBindGroupLayoutBinding.idl */, D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */, @@ -25789,6 +25789,9 @@ D026F483220A472F00AC5F49 /* GPUTextureUsage.idl */, D0D8649621BA18F4003C983C /* GPUVertexAttributeDescriptor.idl */, D0D8649821BA19A7003C983C /* GPUVertexInputDescriptor.idl */, + D00487ED2274281300EED7D9 /* NavigatorGPU.cpp */, + D00487EE2274281400EED7D9 /* NavigatorGPU.h */, + D00487EB2274281200EED7D9 /* NavigatorGPU.idl */, D00F5947216EFE54000D71DB /* WebGPU.cpp */, D00F5946216EFE54000D71DB /* WebGPU.h */, D00F5948216EFE54000D71DB /* WebGPU.idl */, @@ -25878,6 +25881,9 @@ D0EACF882193EE4E000FA75C /* WebGPUTextureView.cpp */, D0EACF872193EE4E000FA75C /* WebGPUTextureView.h */, D0EACF892193EE4E000FA75C /* WebGPUTextureView.idl */, + D0CAAD532277C2A600801CDF /* WorkerNavigatorGPU.cpp */, + D00487FE2277AF8200EED7D9 /* WorkerNavigatorGPU.h */, + D00487FD2277AF8100EED7D9 /* WorkerNavigatorGPU.idl */, ); path = webgpu; sourceTree = ""; -- 1.8.3.1