Bug 1910206 - refactor(webgpu): make AdapterInfo a refcounted object r=webgpu-reviewers,webidl,saschanaz,smaug,nical

Differential Revision: https://phabricator.services.mozilla.com/D222215
This commit is contained in:
Erich Gubler 2024-09-16 15:39:45 +00:00
parent 9122afd54a
commit 1d8effa6b2
3 changed files with 17 additions and 17 deletions

View File

@ -1257,7 +1257,6 @@ DOMInterfaces = {
'GPUAdapterInfo': {
'nativeType': 'mozilla::webgpu::AdapterInfo',
'headerFile': 'mozilla/webgpu/Adapter.h',
'wrapperCache': False
},
'GPUBindGroup': {
'nativeType': 'mozilla::webgpu::BindGroup',

View File

@ -18,11 +18,8 @@
namespace mozilla::webgpu {
bool AdapterInfo::WrapObject(JSContext* const cx,
JS::Handle<JSObject*> givenProto,
JS::MutableHandle<JSObject*> reflector) {
return dom::GPUAdapterInfo_Binding::Wrap(cx, this, givenProto, reflector);
}
GPU_IMPL_CYCLE_COLLECTION(AdapterInfo, mParent)
GPU_IMPL_JS_WRAP(AdapterInfo)
void AdapterInfo::GetWgpuName(nsString& s) const {
s = mAboutSupportInfo->name;
@ -493,12 +490,12 @@ already_AddRefed<dom::Promise> Adapter::RequestDevice(
// -
already_AddRefed<dom::Promise> Adapter::RequestAdapterInfo(
const dom::Sequence<nsString>& /*aUnmaskHints*/, ErrorResult& aRv) const {
const dom::Sequence<nsString>& /*aUnmaskHints*/, ErrorResult& aRv) {
RefPtr<dom::Promise> promise = dom::Promise::Create(GetParentObject(), aRv);
if (!promise) return nullptr;
auto rai = UniquePtr<AdapterInfo>{new AdapterInfo(mInfoInner)};
promise->MaybeResolve(std::move(rai));
RefPtr<AdapterInfo> rai = new AdapterInfo(this, mInfoInner);
promise->MaybeResolve(rai);
return promise.forget();
}

View File

@ -9,7 +9,6 @@
#include <memory>
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/webgpu/WebGPUTypes.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "nsPrintfCString.h"
@ -31,6 +30,7 @@ class Sequence;
} // namespace dom
namespace webgpu {
class Adapter;
class Device;
class Instance;
class SupportedFeatures;
@ -40,14 +40,21 @@ namespace ffi {
struct WGPUAdapterInformation;
} // namespace ffi
class AdapterInfo final : public dom::NonRefcountedDOMObject {
private:
class AdapterInfo final : public nsWrapperCache, public ChildOf<Adapter> {
public:
GPU_DECL_CYCLE_COLLECTION(AdapterInfo)
GPU_DECL_JS_WRAP(AdapterInfo)
protected:
const std::shared_ptr<ffi::WGPUAdapterInformation> mAboutSupportInfo;
~AdapterInfo() = default;
void Cleanup() {}
public:
explicit AdapterInfo(
Adapter* const aParent,
const std::shared_ptr<ffi::WGPUAdapterInformation>& aAboutSupportInfo)
: mAboutSupportInfo(aAboutSupportInfo) {}
: ChildOf(aParent), mAboutSupportInfo(aAboutSupportInfo) {}
void GetVendor(nsString& s) const { s = nsString(); }
void GetArchitecture(nsString& s) const { s = nsString(); }
@ -62,9 +69,6 @@ class AdapterInfo final : public dom::NonRefcountedDOMObject {
void GetWgpuDriver(nsString&) const;
void GetWgpuDriverInfo(nsString&) const;
void GetWgpuBackend(nsString&) const;
bool WrapObject(JSContext*, JS::Handle<JSObject*>,
JS::MutableHandle<JSObject*>);
};
inline auto ToHexCString(const uint64_t v) {
@ -110,7 +114,7 @@ class Adapter final : public ObjectBase, public ChildOf<Instance> {
const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv);
already_AddRefed<dom::Promise> RequestAdapterInfo(
const dom::Sequence<nsString>& aUnmaskHints, ErrorResult& aRv) const;
const dom::Sequence<nsString>& aUnmaskHints, ErrorResult& aRv);
};
} // namespace webgpu