checkNativeImport function
void
checkNativeImport(
- NativeHandle handle, {
- required Set<
NativeHandleKind> accepts, - required bool fence,
- required String backend,
- required String operation,
Refuses handle unless this device can import it as operation asks:
its kind is one of accepts (the device's shareableKinds), and it is
a fence kind exactly when fence is. Since 1.0.0-rc.1, from
package:flutter3d_hardware/backend.dart.
For a backend's importTexture, importBuffer and importFence, on
the way in, after the feature check. Several kinds are the same
integer underneath (a Win32 handle is Vulkan memory, a Direct3D 12
resource or a fence), and an API handed one as another either fails far
from the call or maps memory it was never given. So a kind the device
does not list is refused by name, never substituted for the nearest one
it does.
Throws a DeviceResourceException naming backend and the kind.
Implementation
void checkNativeImport(
NativeHandle handle, {
required Set<NativeHandleKind> accepts,
required bool fence,
required String backend,
required String operation,
}) {
final kind = handle.kind;
if (kind.isFence != fence) {
throw DeviceResourceException(
operation: operation,
backend: backend,
reason:
'${kind.name} names ${kind.isFence ? 'a fence' : 'memory'}, and '
'$operation imports ${fence ? 'a fence' : 'memory'}',
);
}
if (!accepts.contains(kind)) {
final listed = accepts.isEmpty
? 'none'
: accepts.map((NativeHandleKind k) => k.name).join(', ');
throw DeviceResourceException(
operation: operation,
backend: backend,
reason:
'it does not import ${kind.name} (it imports $listed), and a '
'handle of one kind is never read as another',
);
}
}