/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */ #include "WebGPUParent.h" #include "mozilla/webgpu/ffi/wgpu.h" namespace mozilla { namespace webgpu { WebGPUParent::WebGPUParent() : mContext(ffi::wgpu_server_new()) {} WebGPUParent::~WebGPUParent() = default; ipc::IPCResult WebGPUParent::RecvInstanceRequestAdapter( const dom::GPURequestAdapterOptions& aOptions, const nsTArray& aTargetIds, InstanceRequestAdapterResolver&& resolver) { ffi::WGPURequestAdapterOptions options = {}; if (aOptions.mPowerPreference.WasPassed()) { options.power_preference = static_cast( aOptions.mPowerPreference.Value()); } // TODO: make available backends configurable by prefs int8_t index = ffi::wgpu_server_instance_request_adapter( mContext, &options, aTargetIds.Elements(), aTargetIds.Length()); if (index >= 0) { resolver(aTargetIds[index]); } else { resolver(0); } return IPC_OK(); } ipc::IPCResult WebGPUParent::RecvAdapterRequestDevice( RawId aSelfId, const dom::GPUDeviceDescriptor& aOptions, RawId aNewId) { ffi::WGPUDeviceDescriptor desc = {}; // TODO: fill up the descriptor ffi::wgpu_server_adapter_request_device(mContext, aSelfId, &desc, aNewId); return IPC_OK(); } ipc::IPCResult WebGPUParent::RecvDeviceDestroy(RawId aSelfId) { ffi::wgpu_server_device_destroy(mContext, aSelfId); return IPC_OK(); } ipc::IPCResult WebGPUParent::RecvShutdown() { ffi::wgpu_server_delete(const_cast(mContext)); return IPC_OK(); } } // namespace webgpu } // namespace mozilla