How to get the ratio of CSS pixels to device pixels:

    var iw = window.innerWidth;
    var ow = window.outerWidth;
    var dpr = window.devicePixelRatio || 1;
    var cssRatio = dpr * (ow/iw);

How to get the ratio of canvas pixels to device pixels:

    var bspr = (ctx.webkitBackingStorePixelRatio || 1);
    var canvasRatio = bspr * (ow/iw);

How to get 1:1 canvas:device pixels:

    var scaleRatio = cssRatio / bspr;
    canvas.style.width = canvas.width + 'px';
    canvas.style.height = canvas.height + 'px';
    canvas.width *= scaleRatio;
    canvas.height *= scaleRatio;

How to get a headache:

    Figure out all the above for the first time.