chromium/third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.idl

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The spec for HTMLCanvasElement.getContext() defines the context
// creation attributes as type "any". In order to eliminate custom
// bindings for getContext(), we define a dictionary that contains the
// union of all of the context types' attributes. Note that it is not
// possible to use a union type for this purpose because two dictionary
// types are not distinguishable.
//
// Fortunately, there aren't any context creation attributes which are
// defined with different default values in different context
// specifications. (The "alpha" value, in particular, has a default
// value of true for both the Canvas2D and WebGL specifications.)
//
// The PermissiveDictionaryConversion extended attribute ignores
// non-object types (like 'true' and 'false') passed to getContext() for
// the attributes instead of raising TypeError, following the behavior
// of the previous custom binding.
//
// N.B.: Web IDL doesn't support multiple inheritance of dictionaries.

enum CanvasPixelFormat {
    "uint8", // default
    "float16",
};

enum CanvasPowerPreference {
    "default",
    "low-power",
    "high-performance",
};

enum CanvasWillReadFrequently {
  "true",
  "false",
  "undefined" // default
};

// The PermissiveDictionaryConversion extended attribute is needed to allow the
// autogenerated code to match the behavior of the custom binding. Web IDL
// requires throwing TypeError if the incoming argument is not an object type
// (and is not undefined or null). The binding must ignore this.
// Related spec issue: https://github.com/whatwg/html/issues/595
[PermissiveDictionaryConversion]
dictionary CanvasContextCreationAttributesModule {
    boolean desynchronized = false;

    // Canvas 2D attributes
    boolean alpha = true;  // Also used for WebGL.
    PredefinedColorSpace colorSpace = "srgb";
    [RuntimeEnabled=CanvasFloatingPoint] CanvasPixelFormat pixelFormat = "uint8";
    CanvasWillReadFrequently willReadFrequently = "undefined";

    // WebGL attributes
    boolean depth = true;
    boolean stencil = false;
    boolean antialias = true;
    boolean premultipliedAlpha = true;
    boolean preserveDrawingBuffer = false;
    CanvasPowerPreference powerPreference = "default";
    boolean failIfMajorPerformanceCaveat = false;
    [RuntimeEnabled=WebXR] boolean xrCompatible = false;
};