User:Roc/ScreenCaptureAPI

< User:Roc
Revision as of 12:32, 24 October 2013 by Roc (talk | contribs) (Created page with "== Screen Capture API == Add an API to <iframe> that takes a screenshot asynchronously: Promise createScreenshot(); The Promise returns an ImageBitmap. This can be transfe...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Screen Capture API

Add an API to <iframe> that takes a screenshot asynchronously:

Promise createScreenshot();

The Promise returns an ImageBitmap. This can be transferred to an HTMLImageElement (see [[1]]) for rendering. It can also be drawn to a 2D canvas for postprocessing; e.g. the data retrieved by JS using getImageData or converted to an encoded image (off the main thread) using canvas.toBlob. More APIs can be added to ImageBitmap if necessary.

The ImageBitmap size is not easily predictable since it depends on the size of the <iframe> after zooming. It will be a snapshot of what is visible in the <iframe>'s viewport (including the scrollbar, if any), some time between requesting and receiving the screenshot.

Implementation

createScreenshot forces construction of a layer in the subdocument frame if there isn't already one. It allocates a screenshot request ID and attaches the request to the layer. The request ID is transmitted to the compositor using layers IPC.