dom/webgpu/InstanceProvider.h
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/. */

#ifndef WEBGPU_INSTANCE_PROVIDER_H_
#define WEBGPU_INSTANCE_PROVIDER_H_

#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"

class nsCycleCollectionTraversalCallback;
class nsIGlobalObject;

namespace mozilla {
namespace webgpu {
class Instance;

class InstanceProvider {
 private:
  nsIGlobalObject* const mGlobal;
  mutable Maybe<RefPtr<Instance>> mInstance;

 protected:
  explicit InstanceProvider(nsIGlobalObject* global);
  virtual ~InstanceProvider();

 public:
  already_AddRefed<Instance> Webgpu() const;

  nsIGlobalObject* GetParentObject() const { return mGlobal; }

  void CcTraverse(nsCycleCollectionTraversalCallback&) const;
  void CcUnlink();
};

template <typename T>
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
                                 const Maybe<T>& field, const char* name,
                                 uint32_t flags) {
  if (field) {
    CycleCollectionNoteChild(callback, field.value(), name, flags);
  }
}

template <typename T>
void ImplCycleCollectionUnlink(Maybe<T>& field) {
  field = Nothing();
}

}  // namespace webgpu
}  // namespace mozilla

#endif  // WEBGPU_INSTANCE_PROVIDER_H_