getDirectAccess method
Get direct access to internal arrays for performance-critical operations.
The returned object performs a lifecycle check before every native-memory
read or write. It becomes unusable when this buffer is invalidated (for
example by the next Renderer.render() call).
Implementation
DirectBufferAccess getDirectAccess() {
_checkValid();
final w = _bindings.getBufferWidth(_ptr);
final h = _bindings.getBufferHeight(_ptr);
final len = w * h;
if (len == 0) {
throw StateError('Buffer has zero size');
}
final charPtr = _bindings.bufferGetCharPtr(_ptr);
final fgPtr = _bindings.bufferGetFgPtr(_ptr);
final bgPtr = _bindings.bufferGetBgPtr(_ptr);
final attrPtr = _bindings.bufferGetAttributesPtr(_ptr);
return DirectBufferAccess._(
owner: this,
generation: _validity.directAccessGeneration,
chars: charPtr.asTypedList(len),
foregrounds: fgPtr.asTypedList(len * 4), // 4 u16 values per Color
backgrounds: bgPtr.asTypedList(len * 4),
attributes: attrPtr.asTypedList(len),
width: w,
height: h,
);
}