dom/webgpu/InstanceProvider.cpp
author J.C. Jones <jjones@mozilla.com>
Wed, 12 Jun 2019 23:22:22 +0000
changeset 478563 547109ab8d7bb037fa42996e1837f7d231b5d615
parent 449035 66eb1f485c1a3ea81372758bc92292c9428b17cd
child 495817 1ca9b7056c58303f35da14504be8ada9d38ec9aa
permissions -rw-r--r--
Bug 1558977 - Upgrade NSS 3.45 r=keeler Differential Revision: https://phabricator.services.mozilla.com/D34784

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "InstanceProvider.h"

#include "Instance.h"
#include "mozilla/dom/WebGPUBinding.h"

namespace mozilla {
namespace webgpu {

InstanceProvider::InstanceProvider(nsIGlobalObject* const global)
    : mGlobal(global) {}

InstanceProvider::~InstanceProvider() = default;

already_AddRefed<Instance> InstanceProvider::Webgpu() const {
  if (!mInstance) {
    const auto inst = Instance::Create(mGlobal);
    mInstance = Some(inst);
  }
  auto ret = mInstance.value();
  return ret.forget();
}

void InstanceProvider::CcTraverse(
    nsCycleCollectionTraversalCallback& callback) const {
  if (mInstance) {
    CycleCollectionNoteChild(callback, mInstance.ref().get(),
                             "webgpu::InstanceProvider::mInstance", 0);
  }
}

void InstanceProvider::CcUnlink() { mInstance = Some(nullptr); }

}  // namespace webgpu
}  // namespace mozilla