Skip to content

Max width and height for resizeCanvasToDisplaySize #242

@evoactivity

Description

@evoactivity

I'm using twgl to create backgrounds for pages, on very large displays this can cause the canvas to become huge, tanking performance.

I've patched the project locally to introduce maxWidth and maxHeight arguments for the resizeCanvasToDisplaySize and let CSS stretch the canvas the rest of the way should the display size be large.

function resizeCanvasToDisplaySize(canvas, multiplier, maxWidth, maxHeight) {
  multiplier = multiplier || 1;
  multiplier = Math.max(0, multiplier);
  var width = Math.min(canvas.clientWidth * multiplier | 0, maxWidth);
  var height = Math.min(canvas.clientHeight * multiplier | 0, maxHeight);
  if (canvas.width !== width || canvas.height !== height) {
    canvas.width = width;
    canvas.height = height;
    return true;
  }
  return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions