checkDimension method

  1. @override
void checkDimension()
override

Checks if the canvas dimension has changed.

Implementation

@override
void checkDimension() {
  if (_checkingDimension) return;
  _checkingDimension = true;

  try {
    final canvas = _canvas;

    var canvasClientW = canvas.clientWidth;
    var canvasClientH = canvas.clientHeight;

    if (canvasClientW != 0 && canvasClientH != 0) {
      var canvasW = canvas.width ?? 0;
      var canvasH = canvas.height ?? 0;

      // Already checked dimension (avoid cyclical checking):
      if (_checkDimensionWidth == canvasW &&
          _checkDimensionHeight == canvasH &&
          _checkDimensionClientWidth == canvasClientW &&
          _checkDimensionClientHeight == canvasClientH) {
        return;
      }

      var canvasWpr = (canvasClientW * _pixelRatio).toInt();
      var canvasHpr = (canvasClientH * _pixelRatio).toInt();

      if (canvasW != canvasWpr || canvasH != canvasHpr) {
        canvas.width = canvasWpr;
        canvas.height = canvasHpr;

        print(
            'checkDimension> $canvasW x $canvasH -> $canvasWpr x $canvasHpr');

        var cW2 = canvas.clientWidth;
        var cH2 = canvas.clientHeight;

        _checkDimensionWidth = canvasWpr;
        _checkDimensionHeight = canvasHpr;
        _checkDimensionClientWidth = cW2;
        _checkDimensionClientHeight = cH2;

        _clearSetStates();
      }
    }
  } finally {
    _checkingDimension = false;
  }
}