readWebGpuAdapter function
The adapter Google's browser runtimes ask WebGPU for, named for
TaskPlatform.gpu as WebGPU and its vendor, architecture and
description, with a fallback adapter marked as such; null without WebGPU.
A family whose browser runtime needs WebGPU sets it as
taskPlatformGpuReader when its plugin registers.
Implementation
Future<String?> readWebGpuAdapter() async {
final gpu = _gpu;
if (gpu == null) return null;
final adapter = await gpu
.callMethod<JSPromise<JSObject?>>(
'requestAdapter'.toJS,
{'powerPreference': 'high-performance'}.jsify(),
)
.toDart;
if (adapter == null) return null;
final info = adapter.getProperty<JSObject?>('info'.toJS);
String part(String name) =>
info?.getProperty<JSString?>(name.toJS)?.toDart ?? '';
final fallback =
adapter.getProperty<JSBoolean?>('isFallbackAdapter'.toJS)?.toDart ??
false;
return [
webGpuAdapterPrefix,
for (final name in ['vendor', 'architecture', 'description'])
if (part(name).isNotEmpty) part(name),
if (fallback) '(fallback adapter)',
].join(' ');
}