callNativeFunction static method

Future callNativeFunction(
  1. int engineId,
  2. int renderManagerId,
  3. String callId,
  4. Object params,
  5. bool keep,
)

Implementation

static Future<dynamic> callNativeFunction(
  int engineId,
  int renderManagerId,
  String callId,
  Object params,
  bool keep,
) async {
  var stopwatch = Stopwatch();
  stopwatch.start();
  var callIdU16 = callId.toNativeUtf16();
  var encodeParamsByteData = const StandardMessageCodec().encodeMessage(params);
  if (encodeParamsByteData != null) {
    var length = encodeParamsByteData.lengthInBytes;
    final result = malloc<Uint8>(length);
    final nativeParams = result.asTypedList(length);
    nativeParams.setRange(
      0,
      length,
      encodeParamsByteData.buffer.asUint8List(),
    );
    _RenderBridgeFFIManager.instance.callNativeFunction(
      engineId,
      renderManagerId,
      callIdU16,
      result,
      length,
      keep ? 1 : 0,
    );
    free(result);
    stopwatch.stop();
    LogUtils.profile("callNativeFunction", stopwatch.elapsedMilliseconds);
  } else {
    LogUtils.e(
      'Voltron::Bridge',
      'call native function error, invalid params',
    );
  }

  free(callIdU16);
}