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();
}

View File

@@ -126,30 +126,6 @@ already_AddRefed<Buffer> Device::CreateBuffer(
return Buffer::Create(this, mId, aDesc, aRv);
}
RefPtr<MappingPromise> Device::MapBufferAsync(RawId aId, uint32_t aMode,
uint64_t aOffset, uint64_t aSize,
ErrorResult& aRv) {
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:
MOZ_CRASH("should have checked aMode in Buffer::MapAsync");
}
return mBridge->SendBufferMap(aId, mode, aOffset, aSize);
}
void Device::UnmapBuffer(RawId aId, bool aFlush) {
if (mBridge->CanSend()) {
mBridge->SendBufferUnmap(aId, aFlush);
}
}
already_AddRefed<Texture> Device::CreateTexture(
const dom::GPUTextureDescriptor& aDesc) {
RawId id = 0;

View File

@@ -100,10 +100,6 @@ class Device final : public DOMEventTargetHelper, public SupportsWeakPtr {
static JSObject* CreateExternalArrayBuffer(JSContext* aCx, size_t aOffset,
size_t aSize,
const ipc::Shmem& aShmem);
RefPtr<MappingPromise> MapBufferAsync(RawId aId, uint32_t aMode,
uint64_t aOffset, uint64_t aSize,
ErrorResult& aRv);
void UnmapBuffer(RawId aId, bool aFlush);
already_AddRefed<Texture> InitSwapChain(
const dom::GPUCanvasConfiguration& aDesc,
const layers::CompositableHandle& aHandle, gfx::SurfaceFormat aFormat,