script/dom/webgl/extensions/
extension.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use canvas_traits::webgl::WebGLVersion;
6
7use super::WebGLExtensions;
8use crate::dom::bindings::reflector::DomObject;
9use crate::dom::bindings::root::DomRoot;
10use crate::dom::bindings::trace::JSTraceable;
11use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
12use crate::script_runtime::CanGc;
13
14/// Trait implemented by WebGL extensions.
15pub(crate) trait WebGLExtension: Sized
16where
17    Self::Extension: DomObject + JSTraceable,
18{
19    #[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
20    type Extension;
21
22    /// Creates the DOM object of the WebGL extension.
23    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<Self::Extension>;
24
25    /// Returns which WebGL spec is this extension written against.
26    fn spec() -> WebGLExtensionSpec;
27
28    /// Checks if the extension is supported.
29    fn is_supported(ext: &WebGLExtensions) -> bool;
30
31    /// Enable the extension.
32    fn enable(ext: &WebGLExtensions);
33
34    /// Name of the WebGL Extension.
35    fn name() -> &'static str;
36}
37
38pub(crate) enum WebGLExtensionSpec {
39    /// Extensions written against both WebGL and WebGL2 specs.
40    All,
41    /// Extensions writen against a specific WebGL version spec.
42    Specific(WebGLVersion),
43}