eglChooseConfig function
Implementation
List<Pointer<Void>> eglChooseConfig(
Pointer<Void> display, {
Map<EglConfigAttribute, int>? attributes,
int maxConfigs = 1,
}) {
final attributeCount = attributes == null ? 1 : attributes.length * 2 + 1;
final attributeList = calloc<Int32>(attributeCount);
if (attributes != null) {
final attributeEntries = attributes.entries.toList(growable: false);
for (var i = 0; i < attributeEntries.length; ++i) {
attributeList[i * 2] = attributeEntries[i].key.toIntValue();
attributeList[i * 2 + 1] = attributeEntries[i].value;
}
}
// The list must be terminated with EGL_NONE.
attributeList[attributeCount - 1] = EglValue.none.toIntValue();
final configs = calloc<IntPtr>(maxConfigs);
final numConfigs = calloc<Int32>();
final nativeCallSucceeded = _libEGL!.eglChooseConfig(
display,
attributeList,
configs.cast<Pointer<Void>>(),
maxConfigs,
numConfigs,
) ==
1;
List<Pointer<Void>> result = <Pointer<Void>>[];
if (nativeCallSucceeded) {
for (var i = 0; i < numConfigs.value; ++i) {
result.add(Pointer.fromAddress(configs[i]));
}
}
calloc.free(attributeList);
calloc.free(configs);
calloc.free(numConfigs);
if (!nativeCallSucceeded) {
throw EglException(
'Failed to choose config for display [$display], attributes $attributes, max configs $maxConfigs.');
}
return result;
}