[whatwg] [canvas] request for {create, get, put}ImageDataHD and ctx.backingStorePixelRatio

Edward O'Connor eoconnor at apple.com
Tue Mar 20 13:42:01 PDT 2012

Tab wrote:

> So, I support adding an alternate API that explicitly returns a
> high-res store. If people fuck *that* up, then we're just screwed.


> I'm not as sure about the backingStorePixelRatio bit. What's the
> use-case for it? Why do devs need to detect this, and what will they
> do different in the multiple code paths?

Suppose you're a clever developer who basically does something like this
to handle both an iPhone 3GS and an iPhone 4:

if (window.devicePixelRatio == 1) {
 // create a 100x100 canvas
} else if (window.devicePixelRatio == 2) {
 // create a 200x200 canvas and scale it down to 100x100 with CSS
} // etc.

But now run through this logic when the <canvas> is making a high res
backing store automatically: by doing the clever thing, you're now
quadrupling the size of the canvas, and you're paying an exorbitant
storage cost for doing so.

You really only want to do the "make it twice as big and then scale it
down with CSS" trick when backing store pixels are 1:1 to CSS pixels.


More information about the whatwg mailing list