GPUCanvasContext: getConfiguration()-Methode

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimentell: Dies ist eine experimentelle Technologie
Überprüfen Sie die Browser-Kompatibilitätstabelle sorgfältig vor der Verwendung auf produktiven Webseiten.

Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die getConfiguration()-Methode des GPUCanvasContext-Interfaces gibt die aktuelle Konfiguration zurück, die für den Kontext festgelegt ist.

Syntax

js
getConfiguration()

Parameter

Keine.

Rückgabewert

Ein Objekt, das die auf dem Kontext festgelegten Konfigurationsoptionen enthält (d.h. über die GPUCanvasContext.configure()-Methode festgelegt), oder null, wenn keine Konfiguration festgelegt ist (entweder wurde keine Konfiguration zuvor festgelegt, oder eine Konfiguration wurde festgelegt und dann wurde GPUCanvasContext.unconfigure() auf dem Kontext aufgerufen).

Beispiele

js
const canvas = document.querySelector("canvas");
const context = canvas.getContext("webgpu");

if (!navigator.gpu) {
  throw Error("WebGPU not supported.");
}

const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
  throw Error("Couldn't request WebGPU adapter.");
}

const device = await adapter.requestDevice();

context.configure({
  device: device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  alphaMode: "premultiplied",
});

console.log(context.getConfiguration());
/* Logs something like:

{
  "alphaMode": "premultiplied",
  "colorSpace": "srgb",
  "device": { ... },
  "format": "bgra8unorm",
  "toneMapping": {
      "mode": "standard"
  },
  "usage": 16,
  "viewFormats": []
}
*/

Spezifikationen

Specification
WebGPU
# dom-gpucanvascontext-getconfiguration

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
getConfiguration
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

Siehe auch