Bug 1780792 - Move the remaining buffer logic in Device.cpp into Buffer.cpp. r=jimb

Having the code in the same place makes it easier to follow. This made me realize that the validation of aMode in mapAsync has to move to the device side (fix coming in a followup).

Depends on D151631

Differential Revision: https://phabricator.services.mozilla.com/D151632
This commit is contained in:
Nicolas Silva
2022-08-10 11:38:56 +00:00
parent d0c8334330
commit ad9e77ca3f
3 changed files with 18 additions and 30 deletions

View File

@@ -166,8 +166,21 @@ already_AddRefed<dom::Promise> Buffer::MapAsync(
RefPtr<Buffer> self(this);
ffi::WGPUHostMap mode;
switch (aMode) {
case dom::GPUMapMode_Binding::READ:
mode = ffi::WGPUHostMap_Read;
break;
case dom::GPUMapMode_Binding::WRITE:
mode = ffi::WGPUHostMap_Write;
break;
default:
// TODO: This has to be validated on the device timeline.
MOZ_CRASH();
}
auto mappingPromise =
GetDevice().MapBufferAsync(mId, aMode, aOffset, size, aRv);
GetDevice().GetBridge()->SendBufferMap(mId, mode, aOffset, size);
MOZ_ASSERT(mappingPromise);
mMapRequest = promise;
@@ -291,7 +304,10 @@ void Buffer::Unmap(JSContext* aCx, ErrorResult& aRv) {
mShmem = ipc::Shmem();
}
GetDevice().UnmapBuffer(mId, mMapped->mWritable);
if (!GetDevice().IsLost()) {
GetDevice().GetBridge()->SendBufferUnmap(mId, mMapped->mWritable);
}
mMapped.reset();
}