v160 · graphics · canvas

Canvas2D tone mapping

A float16 2D canvas can already store colours brighter than white — but until now every browser squashed them to SDR on screen and in exported files. A new creation setting, getContext("2d", { toneMapping: { mode: "extended" } }), tells the browser the bitmap is HDR and should be shown with the display’s extra headroom. The default, "standard", keeps today’s behaviour. It is the same CanvasToneMapping dictionary WebGPU already uses, now shared with 2D canvas and WebGL.

Flag: Blink runtime feature CanvasToneMapping (experimental). Enable chrome://flags/#enable-experimental-web-platform-features or launch with --enable-blink-features=CanvasToneMapping; Chrome 160 is planned to ship it on by default. Visible HDR also needs an HDR display. Every concept page probes the exact surface and labels a partial or missing implementation honestly — on Chrome 153 with the flag, for example, the setting is parsed and validated but "extended" is not yet reflected.

concepts

  1. Mode reflection

    The canonical call. Create contexts with every toneMapping value (omitted, {}, standard, extended, invalid) on HTMLCanvasElement and OffscreenCanvas, read getContextAttributes() back, and run the WPT table.

  2. Feature-detection kit

    Dictionary members are invisible to in checks. Four independent detectors — member read, enum validation, default reflection, extended reflection — show which one is a false positive and which one an app should branch on.

  3. HDR highlight viewer

    A scene with a sun up to 8× SDR white drawn into a "standard" and an "extended" canvas side by side. Sample the pixels to prove tone mapping changes the display, never the stored values.

  4. Encode & ImageBitmap round-trip

    Paint 16× white, export through toDataURL, toBlob, convertToBlob, createImageBitmap and transferToImageBitmap, decode, and measure — the WPT encode-hdr matrix, live, for PNG, JPEG and WebP.

  5. dynamic-range-limit interplay

    The script knob meets the style knob: apply CSS dynamic-range-limit values to standard and extended canvases and see why "extended" under dynamic-range-limit: standard equals "standard".

  6. One dictionary, three contexts

    Push the same {mode} through 2D getContext, WebGL drawingBufferToneMapping() and WebGPU configure() and see which contexts honour the unified CanvasToneMapping in this browser.

why it shipped

Floating-point 2D canvases (colorType: "float16") can represent values above 1.0, but the spec had no way to say whether those values were higher-precision SDR or genuine HDR, so browsers always limited canvas output to standard dynamic range. WebGPU solved this with GPUCanvasToneMapping; the W3C Color on the Web CG proposed renaming it to CanvasToneMapping, moving it into HTML (WHATWG PR #11734), and adding it to 2D canvas so HDR image editors, viewers and games can show highlights properly and export them to HDR files. The default stays "standard", so no existing page changes. Security review notes it exposes no display headroom to script.

the API

enum CanvasToneMappingMode { "standard", "extended" };
dictionary CanvasToneMapping { CanvasToneMappingMode mode = "standard"; };

partial dictionary CanvasRenderingContext2DSettings {
  CanvasToneMapping toneMapping = {};
};

const ctx = canvas.getContext("2d", {
  colorSpace: "srgb-linear", colorType: "float16",
  toneMapping: { mode: "extended" },
});
ctx.getContextAttributes().toneMapping;   // { mode: "extended" }

references