2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-06-13 20:43:48 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#ifndef GPU_OBJECT_MODEL_H_
|
|
|
|
#define GPU_OBJECT_MODEL_H_
|
2018-06-13 20:43:48 +03:00
|
|
|
|
|
|
|
#include "nsWrapperCache.h"
|
2019-10-02 19:46:03 +03:00
|
|
|
#include "nsString.h"
|
2018-06-13 20:43:48 +03:00
|
|
|
|
|
|
|
class nsIGlobalObject;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace webgpu {
|
|
|
|
|
|
|
|
template <typename T>
|
2019-10-02 19:46:03 +03:00
|
|
|
class ChildOf {
|
2018-06-13 20:43:48 +03:00
|
|
|
public:
|
|
|
|
const RefPtr<T> mParent;
|
|
|
|
|
2019-11-14 07:59:56 +03:00
|
|
|
explicit ChildOf(T* const parent);
|
|
|
|
|
2018-06-13 20:43:48 +03:00
|
|
|
protected:
|
|
|
|
virtual ~ChildOf();
|
|
|
|
|
|
|
|
public:
|
|
|
|
nsIGlobalObject* GetParentObject() const;
|
|
|
|
};
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
class ObjectBase : public nsWrapperCache {
|
|
|
|
private:
|
|
|
|
nsString mLabel;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ObjectBase() = default;
|
2020-01-22 10:31:51 +03:00
|
|
|
// Internal mutability model for WebGPU objects.
|
|
|
|
bool mValid = true;
|
2019-10-02 19:46:03 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
void GetLabel(nsAString& aValue) const;
|
|
|
|
void SetLabel(const nsAString& aLabel);
|
|
|
|
};
|
|
|
|
|
2018-06-13 20:43:48 +03:00
|
|
|
} // namespace webgpu
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#define GPU_DECL_JS_WRAP(T) \
|
|
|
|
JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) \
|
|
|
|
override;
|
|
|
|
|
|
|
|
#define GPU_DECL_CYCLE_COLLECTION(T) \
|
2018-06-13 20:43:48 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(T) \
|
2019-10-02 19:46:03 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(T)
|
2018-06-13 20:43:48 +03:00
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#define GPU_IMPL_JS_WRAP(T) \
|
2018-06-13 20:43:48 +03:00
|
|
|
JSObject* T::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) { \
|
2019-10-02 19:46:03 +03:00
|
|
|
return dom::GPU##T##_Binding::Wrap(cx, this, givenProto); \
|
|
|
|
}
|
2018-06-13 20:43:48 +03:00
|
|
|
|
2020-01-22 10:31:51 +03:00
|
|
|
// Note: we don't use `NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE` directly
|
|
|
|
// because there is a custom action we need to always do.
|
|
|
|
#define GPU_IMPL_CYCLE_COLLECTION(T, ...) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(T, AddRef) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(T, Release) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(T) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(T) \
|
|
|
|
tmp->Cleanup(); \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(T) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(T)
|
2018-06-13 20:43:48 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
|
|
|
const RefPtr<T>& field, const char* name,
|
|
|
|
uint32_t flags) {
|
|
|
|
CycleCollectionNoteChild(callback, field.get(), name, flags);
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:29:51 +03:00
|
|
|
template <typename T>
|
|
|
|
void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& callback,
|
|
|
|
nsTArray<RefPtr<const T>>& field,
|
|
|
|
const char* name, uint32_t flags) {
|
|
|
|
for (auto& element : field) {
|
|
|
|
CycleCollectionNoteChild(callback, const_cast<T*>(element.get()), name,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 20:43:48 +03:00
|
|
|
template <typename T>
|
|
|
|
void ImplCycleCollectionUnlink(const RefPtr<T>& field) {
|
|
|
|
const auto mutPtr = const_cast<RefPtr<T>*>(&field);
|
|
|
|
ImplCycleCollectionUnlink(*mutPtr);
|
|
|
|
}
|
|
|
|
|
2020-03-18 20:29:51 +03:00
|
|
|
template <typename T>
|
|
|
|
void ImplCycleCollectionUnlink(nsTArray<RefPtr<const T>>& field) {
|
|
|
|
for (auto& element : field) {
|
|
|
|
ImplCycleCollectionUnlink(element);
|
|
|
|
}
|
|
|
|
field.Clear();
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:46:03 +03:00
|
|
|
#endif // GPU_OBJECT_MODEL_H_
|