render method

void render(
  1. Canvas canvas, {
  2. BlendMode? blendMode,
  3. Rect? cullRect,
  4. Paint? paint,
})

Implementation

void render(
  Canvas canvas, {
  BlendMode? blendMode,
  Rect? cullRect,
  Paint? paint,
}) {
  if (isEmpty) {
    return;
  }

  final renderPaint = paint ?? _emptyPaint;

  final hasNoColors = _colors.every((c) => c == _defaultColor);
  final actualBlendMode = blendMode ?? defaultBlendMode;
  if (!hasNoColors && actualBlendMode == null) {
    throw 'When setting any colors, a blend mode must be provided.';
  }

  if (useAtlas && !_flippedAtlasStatus.isGenerating) {
    canvas.drawAtlas(
      atlas,
      _transforms,
      _sources,
      hasNoColors ? null : _colors,
      actualBlendMode,
      cullRect,
      renderPaint,
    );
  } else {
    for (final batchItem in _batchItems) {
      renderPaint.blendMode = blendMode ?? renderPaint.blendMode;

      canvas
        ..save()
        ..transform(batchItem.matrix.storage)
        ..drawRect(batchItem.destination, batchItem.paint)
        ..drawImageRect(
          atlas,
          batchItem.source,
          batchItem.destination,
          renderPaint,
        )
        ..restore();
    }
  }
}