Bug 1469376 - Don't require Window re-creation after webgpu pref change. - r=qdot draft
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 27 Jun 2018 15:12:42 -0700
changeset 812171 63b979a9f719f84651472181746beea204f2b3d5
parent 811590 31327b0db8e53f1586d572e8efff48def22a9c43
push id114471
push userbmo:jgilbert@mozilla.com
push dateThu, 28 Jun 2018 17:44:42 +0000
reviewersqdot
bugs1469376
milestone62.0a1
Bug 1469376 - Don't require Window re-creation after webgpu pref change. - r=qdot MozReview-Commit-ID: 1ntB6J1iI4A
dom/webgpu/InstanceProvider.cpp
dom/webgpu/InstanceProvider.h
dom/webgpu/mochitest/test_enable_pref.html
dom/webidl/WebGPU.webidl
--- a/dom/webgpu/InstanceProvider.cpp
+++ b/dom/webgpu/InstanceProvider.cpp
@@ -13,18 +13,23 @@ namespace webgpu {
 
 InstanceProvider::InstanceProvider(nsIGlobalObject* const global)
     : mGlobal(global)
 { }
 
 InstanceProvider::~InstanceProvider() = default;
 
 already_AddRefed<Instance>
-InstanceProvider::Webgpu() const
+InstanceProvider::GetWebgpu() const
 {
+    bool enabled = false;
+    (void)Preferences::GetBool("dom.webgpu.enable", &enabled);
+    if (!enabled)
+        return nullptr;
+
     if (!mInstance) {
         const auto inst = Instance::Create(mGlobal);
         mInstance = Some(inst);
     }
     auto ret = mInstance.value();
     return ret.forget();
 }
 
--- a/dom/webgpu/InstanceProvider.h
+++ b/dom/webgpu/InstanceProvider.h
@@ -23,17 +23,17 @@ private:
     nsIGlobalObject* const mGlobal;
     mutable Maybe<RefPtr<Instance>> mInstance;
 
 protected:
     InstanceProvider(nsIGlobalObject* global);
     virtual ~InstanceProvider();
 
 public:
-    already_AddRefed<Instance> Webgpu() const;
+    already_AddRefed<Instance> GetWebgpu() const;
 
     nsIGlobalObject* GetParentObject() const { return mGlobal; }
 
     void CcTraverse(nsCycleCollectionTraversalCallback&) const;
     void CcUnlink();
 };
 
 template<typename T>
--- a/dom/webgpu/mochitest/test_enable_pref.html
+++ b/dom/webgpu/mochitest/test_enable_pref.html
@@ -6,23 +6,23 @@
 </head>
 <body>
 <script>
 
 function testEnabled() {
   ok(SpecialPowers.getBoolPref('dom.webgpu.enable'), 'Pref should be enabled.');
 
   ok(window.WebGPU !== undefined, 'window.WebGPU !== undefined');
-  ok(window.webgpu !== undefined, 'window.webgpu !== undefined');
+  ok(!!window.webgpu, '!!window.webgpu');
 
   SimpleTest.finish();
 }
 
 ok(window.WebGPU === undefined, 'window.WebGPU === undefined');
-ok(window.webgpu === undefined, 'window.webgpu === undefined');
+ok(!window.webgpu, '!window.webgpu');
 
 var prefArrArr = [
   ['dom.webgpu.enable', true]
 ];
 var prefEnv = {'set': prefArrArr};
 SpecialPowers.pushPrefEnv(prefEnv, testEnabled);
 SimpleTest.waitForExplicitFinish();
 
--- a/dom/webidl/WebGPU.webidl
+++ b/dom/webidl/WebGPU.webidl
@@ -629,11 +629,11 @@ dictionary WebGPUAdapterDescriptor {
 [Pref="dom.webgpu.enable"]
 interface WebGPU {
     WebGPUAdapter getAdapter(optional WebGPUAdapterDescriptor desc);
 };
 
 // Add a "webgpu" member to Window that contains the global instance of a "WebGPU"
 [NoInterfaceObject]
 interface WebGPUProvider {
-    [SameObject, Replaceable, Pref="dom.webgpu.enable"] readonly attribute WebGPU webgpu;
+    [Replaceable] readonly attribute WebGPU? webgpu;
 };
 //Window includes WebGPUProvider;