drawAtlas method

void drawAtlas (Image atlas, List<RSTransform> transforms, List<Rect> rects, List<Color> colors, BlendMode blendMode, Rect cullRect, Paint paint)

Implementation

void drawAtlas(Image atlas,
               List<RSTransform> transforms,
               List<Rect> rects,
               List<Color> colors,
               BlendMode blendMode,
               Rect cullRect,
               Paint paint) {
  assert(atlas != null); // atlas is checked on the engine side
  assert(transforms != null);
  assert(rects != null);
  assert(colors != null);
  assert(blendMode != null);
  assert(paint != null);

  final int rectCount = rects.length;
  if (transforms.length != rectCount)
    throw new ArgumentError('"transforms" and "rects" lengths must match.');
  if (colors.isNotEmpty && colors.length != rectCount)
    throw new ArgumentError('If non-null, "colors" length must match that of "transforms" and "rects".');

  final Float32List rstTransformBuffer = new Float32List(rectCount * 4);
  final Float32List rectBuffer = new Float32List(rectCount * 4);

  for (int i = 0; i < rectCount; ++i) {
    final int index0 = i * 4;
    final int index1 = index0 + 1;
    final int index2 = index0 + 2;
    final int index3 = index0 + 3;
    final RSTransform rstTransform = transforms[i];
    final Rect rect = rects[i];
    assert(_rectIsValid(rect));
    rstTransformBuffer[index0] = rstTransform.scos;
    rstTransformBuffer[index1] = rstTransform.ssin;
    rstTransformBuffer[index2] = rstTransform.tx;
    rstTransformBuffer[index3] = rstTransform.ty;
    rectBuffer[index0] = rect.left;
    rectBuffer[index1] = rect.top;
    rectBuffer[index2] = rect.right;
    rectBuffer[index3] = rect.bottom;
  }

  final Int32List colorBuffer = colors.isEmpty ? null : _encodeColorList(colors);
  final Float32List cullRectBuffer = cullRect?._value;

  _drawAtlas(
    paint._objects, paint._data, atlas, rstTransformBuffer, rectBuffer,
    colorBuffer, blendMode.index, cullRectBuffer
  );
}