Bug 1780792 - use Buffer::GetDevice instead of mParent. r=jimb

Another cosmetic change. I've dabbled with IPDL actors too much to not think about WebGPUParent when reading "mParent". Also the parent-child relationship between Device and Buffer is not very obvious to me (nor is it part of the specification).
So I find that wrapping mParent in a GetDevice method to make the code easier to understand. It also makes it explicit that the parent pointer cannot be null.

Depends on D151630

Differential Revision: https://phabricator.services.mozilla.com/D151631
This commit is contained in:
Nicolas Silva 2022-08-10 15:55:07 +00:00
Родитель 15f2edabb7
Коммит ea11e14b00
2 изменённых файлов: 12 добавлений и 9 удалений

Просмотреть файл

@ -46,6 +46,7 @@ Buffer::Buffer(Device* const aParent, RawId aId, BufferAddress aSize,
uint32_t aUsage, ipc::Shmem&& aShmem)
: ChildOf(aParent), mId(aId), mSize(aSize), mUsage(aUsage), mShmem(aShmem) {
mozilla::HoldJSObjects(this);
MOZ_ASSERT(mParent);
}
Buffer::~Buffer() {
@ -108,15 +109,15 @@ void Buffer::Cleanup() {
// The array buffers could live longer than us and our shmem, so make sure
// we clear the external buffer bindings.
dom::AutoJSAPI jsapi;
if (jsapi.Init(mParent->GetOwnerGlobal())) {
if (jsapi.Init(GetDevice().GetOwnerGlobal())) {
IgnoredErrorResult rv;
UnmapArrayBuffers(jsapi.cx(), rv);
}
}
mMapped.reset();
if (mValid && !mParent->IsLost()) {
mParent->GetBridge()->SendBufferDestroy(mId);
if (mValid && !GetDevice().IsLost()) {
GetDevice().GetBridge()->SendBufferDestroy(mId);
}
mValid = false;
}
@ -141,7 +142,7 @@ already_AddRefed<dom::Promise> Buffer::MapAsync(
return nullptr;
}
if (mParent->IsLost()) {
if (GetDevice().IsLost()) {
promise->MaybeRejectWithOperationError("Device Lost");
return promise.forget();
}
@ -165,7 +166,8 @@ already_AddRefed<dom::Promise> Buffer::MapAsync(
RefPtr<Buffer> self(this);
auto mappingPromise = mParent->MapBufferAsync(mId, aMode, aOffset, size, aRv);
auto mappingPromise =
GetDevice().MapBufferAsync(mId, aMode, aOffset, size, aRv);
MOZ_ASSERT(mappingPromise);
mMapRequest = promise;
@ -225,7 +227,7 @@ void Buffer::GetMappedRange(JSContext* aCx, uint64_t aOffset,
return;
}
auto* const arrayBuffer = mParent->CreateExternalArrayBuffer(
auto* const arrayBuffer = GetDevice().CreateExternalArrayBuffer(
aCx, checkedOffset.value(), checkedSize.value(), mShmem);
if (!arrayBuffer) {
aRv.NoteJSContextException(aCx);
@ -289,7 +291,7 @@ void Buffer::Unmap(JSContext* aCx, ErrorResult& aRv) {
mShmem = ipc::Shmem();
}
mParent->UnmapBuffer(mId, mMapped->mWritable);
GetDevice().UnmapBuffer(mId, mMapped->mWritable);
mMapped.reset();
}
@ -298,8 +300,8 @@ void Buffer::Destroy(JSContext* aCx, ErrorResult& aRv) {
Unmap(aCx, aRv);
}
if (!mParent->IsLost()) {
mParent->GetBridge()->SendBufferDestroy(mId);
if (!GetDevice().IsLost()) {
GetDevice().GetBridge()->SendBufferDestroy(mId);
}
// TODO: we don't have to implement it right now, but it's used by the
// examples

Просмотреть файл

@ -57,6 +57,7 @@ class Buffer final : public ObjectBase, public ChildOf<Device> {
Buffer(Device* const aParent, RawId aId, BufferAddress aSize, uint32_t aUsage,
ipc::Shmem&& aShmem);
virtual ~Buffer();
Device& GetDevice() { return *mParent; }
void Cleanup();
void UnmapArrayBuffers(JSContext* aCx, ErrorResult& aRv);
void RejectMapRequest(dom::Promise* aPromise, nsACString& message);