createBuffer method

bool createBuffer(
  1. String windowId, {
  2. int layerId = 0,
})

Create a path buffer for a window and layer. Returns true if successful.

Implementation

bool createBuffer(String windowId, {int layerId = 0}) {
  if (!_initialized) return false;

  final idPtr = windowId.toNativeUtf8().cast<Char>();
  try {
    final ptr = _createBufferLayer != null
        ? _createBufferLayer!(idPtr, layerId)
        : (layerId == 0 ? _createBuffer(idPtr) : nullptr);
    if (ptr == nullptr) return false;

    final layerBuffers = _buffers.putIfAbsent(windowId, () => {});
    final layerFrames = _frameIds.putIfAbsent(windowId, () => {});
    layerBuffers[layerId] = ptr.cast<GlassPathBuffer>();
    layerFrames[layerId] = 0;
    return true;
  } finally {
    calloc.free(idPtr);
  }
}