renderTextureQuad method

  1. @override
void renderTextureQuad(
  1. RenderState renderState,
  2. RenderTextureQuad renderTextureQuad
)
override

Implementation

@override
void renderTextureQuad(
    RenderState renderState, RenderTextureQuad renderTextureQuad) {
  if (renderTextureQuad.hasCustomVertices) {
    final renderTexture = renderTextureQuad.renderTexture;
    final ixList = renderTextureQuad.ixList;
    final vxList = renderTextureQuad.vxList;
    renderTextureMesh(renderState, renderTexture, ixList, vxList);
    return;
  }

  final context = _renderingContext;
  final source = renderTextureQuad.renderTexture.source ??
      renderTextureQuad.renderTexture.imageBitmap;

  final rotation = renderTextureQuad.rotation;
  final sourceRect = renderTextureQuad.sourceRectangle;
  final vxList = renderTextureQuad.vxListQuad;
  final matrix = renderState.globalMatrix;
  final alpha = renderState.globalAlpha;
  final blendMode = renderState.globalBlendMode;

  if (_activeAlpha != alpha) {
    _activeAlpha = alpha;
    context.globalAlpha = alpha;
  }

  if (_activeBlendMode != blendMode) {
    _activeBlendMode = blendMode;
    context.globalCompositeOperation = blendMode.compositeOperation;
  }

  // Note: We need to use js_util.callMethod for the drawImage calls,
  // since Dart SDK does not support ImageBitmap as a CanvasImageSource

  if (rotation == 0) {
    context.setTransform(
        matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
    js_util.callMethod<void>(context, 'drawImage', [
      source,
      sourceRect.left,
      sourceRect.top,
      sourceRect.width,
      sourceRect.height,
      vxList[0],
      vxList[1],
      vxList[8] - vxList[0],
      vxList[9] - vxList[1]
    ]);
  } else if (rotation == 1) {
    context.setTransform(
        -matrix.c, -matrix.d, matrix.a, matrix.b, matrix.tx, matrix.ty);
    js_util.callMethod<void>(context, 'drawImage', [
      source,
      sourceRect.left,
      sourceRect.top,
      sourceRect.width,
      sourceRect.height,
      0.0 - vxList[13],
      vxList[12],
      vxList[9] - vxList[1],
      vxList[8] - vxList[0]
    ]);
  } else if (rotation == 2) {
    context.setTransform(
        -matrix.a, -matrix.b, -matrix.c, -matrix.d, matrix.tx, matrix.ty);
    js_util.callMethod<void>(context, 'drawImage', [
      source,
      sourceRect.left,
      sourceRect.top,
      sourceRect.width,
      sourceRect.height,
      0.0 - vxList[8],
      0.0 - vxList[9],
      vxList[8] - vxList[0],
      vxList[9] - vxList[1]
    ]);
  } else if (rotation == 3) {
    context.setTransform(
        matrix.c, matrix.d, -matrix.a, -matrix.b, matrix.tx, matrix.ty);
    js_util.callMethod<void>(context, 'drawImage', [
      source,
      sourceRect.left,
      sourceRect.top,
      sourceRect.width,
      sourceRect.height,
      vxList[5],
      0.0 - vxList[4],
      vxList[9] - vxList[1],
      vxList[8] - vxList[0]
    ]);
  }
}