WebXR.webidl (7039B)
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. 5 * 6 * The origin of this IDL file is 7 * https://immersive-web.github.io/webxr/ 8 */ 9 10 11 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 12 interface XRSystem : EventTarget { 13 // Methods 14 [NewObject] 15 Promise<boolean> isSessionSupported(XRSessionMode mode); 16 [NewObject, NeedsCallerType] 17 Promise<XRSession> requestSession(XRSessionMode mode, optional XRSessionInit options = {}); 18 19 // Events 20 attribute EventHandler ondevicechange; 21 }; 22 23 enum XRSessionMode { 24 "inline", 25 "immersive-vr", 26 "immersive-ar", 27 }; 28 29 dictionary XRSessionInit { 30 sequence<DOMString> requiredFeatures; 31 sequence<DOMString> optionalFeatures; 32 }; 33 34 enum XRVisibilityState { 35 "visible", 36 "visible-blurred", 37 "hidden", 38 }; 39 40 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 41 interface XRSession : EventTarget { 42 // Attributes 43 readonly attribute XRVisibilityState visibilityState; 44 [SameObject] readonly attribute XRRenderState renderState; 45 [SameObject] readonly attribute XRInputSourceArray inputSources; 46 readonly attribute float? frameRate; 47 readonly attribute Float32Array? supportedFrameRates; 48 49 // Methods 50 [Throws] 51 undefined updateRenderState(optional XRRenderStateInit state = {}); 52 [NewObject] 53 Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type); 54 [NewObject] 55 Promise<undefined> updateTargetFrameRate(float rate); 56 57 [Throws] 58 long requestAnimationFrame(XRFrameRequestCallback callback); 59 [Throws] 60 undefined cancelAnimationFrame(long handle); 61 62 [NewObject] 63 Promise<undefined> end(); 64 65 // Events 66 attribute EventHandler onend; 67 attribute EventHandler oninputsourceschange; 68 attribute EventHandler onselect; 69 attribute EventHandler onselectstart; 70 attribute EventHandler onselectend; 71 attribute EventHandler onsqueeze; 72 attribute EventHandler onsqueezestart; 73 attribute EventHandler onsqueezeend; 74 attribute EventHandler onvisibilitychange; 75 }; 76 77 dictionary XRRenderStateInit { 78 double depthNear; 79 double depthFar; 80 double inlineVerticalFieldOfView; 81 XRWebGLLayer? baseLayer; 82 }; 83 84 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 85 interface XRRenderState { 86 readonly attribute double depthNear; 87 readonly attribute double depthFar; 88 readonly attribute double? inlineVerticalFieldOfView; 89 readonly attribute XRWebGLLayer? baseLayer; 90 }; 91 92 callback XRFrameRequestCallback = undefined (DOMHighResTimeStamp time, XRFrame frame); 93 94 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 95 interface XRFrame { 96 [SameObject] readonly attribute XRSession session; 97 98 [Throws] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace); 99 [Throws] XRPose? getPose(XRSpace space, XRSpace baseSpace); 100 }; 101 102 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 103 interface XRSpace : EventTarget { 104 105 }; 106 107 enum XRReferenceSpaceType { 108 "viewer", 109 "local", 110 "local-floor", 111 "bounded-floor", 112 "unbounded" 113 }; 114 115 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 116 interface XRReferenceSpace : XRSpace { 117 [NewObject] 118 XRReferenceSpace getOffsetReferenceSpace(XRRigidTransform originOffset); 119 120 attribute EventHandler onreset; 121 }; 122 123 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 124 interface XRBoundedReferenceSpace : XRReferenceSpace { 125 // TODO: Use FrozenArray once available. (Bug 1236777) 126 [Frozen, Cached, Pure] 127 readonly attribute sequence<DOMPointReadOnly> boundsGeometry; 128 }; 129 130 enum XREye { 131 "none", 132 "left", 133 "right" 134 }; 135 136 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 137 interface XRView { 138 readonly attribute XREye eye; 139 [Throws] 140 readonly attribute Float32Array projectionMatrix; 141 [Throws, SameObject] 142 readonly attribute XRRigidTransform transform; 143 }; 144 145 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 146 interface XRViewport { 147 readonly attribute long x; 148 readonly attribute long y; 149 readonly attribute long width; 150 readonly attribute long height; 151 }; 152 153 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 154 interface XRRigidTransform { 155 [Throws] 156 constructor(optional DOMPointInit position = {}, optional DOMPointInit orientation = {}); 157 [SameObject] readonly attribute DOMPointReadOnly position; 158 [SameObject] readonly attribute DOMPointReadOnly orientation; 159 [Throws] 160 readonly attribute Float32Array matrix; 161 [SameObject] readonly attribute XRRigidTransform inverse; 162 }; 163 164 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 165 interface XRPose { 166 [SameObject] readonly attribute XRRigidTransform transform; 167 readonly attribute boolean emulatedPosition; 168 }; 169 170 [ProbablyShortLivingWrapper, Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 171 interface XRViewerPose : XRPose { 172 // TODO: Use FrozenArray once available. (Bug 1236777) 173 [Constant, Cached, Frozen] 174 readonly attribute sequence<XRView> views; 175 }; 176 177 enum XRHandedness { 178 "none", 179 "left", 180 "right" 181 }; 182 183 enum XRTargetRayMode { 184 "gaze", 185 "tracked-pointer", 186 "screen" 187 }; 188 189 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 190 interface XRInputSource { 191 readonly attribute XRHandedness handedness; 192 readonly attribute XRTargetRayMode targetRayMode; 193 [SameObject] readonly attribute XRSpace targetRaySpace; 194 [SameObject] readonly attribute XRSpace? gripSpace; 195 // TODO: Use FrozenArray once available. (Bug 1236777) 196 [Constant, Cached, Frozen] 197 readonly attribute sequence<DOMString> profiles; 198 // https://immersive-web.github.io/webxr-gamepads-module/ 199 [SameObject] readonly attribute Gamepad? gamepad; 200 }; 201 202 203 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 204 interface XRInputSourceArray { 205 iterable<XRInputSource>; 206 readonly attribute unsigned long length; 207 getter XRInputSource(unsigned long index); 208 }; 209 210 typedef (WebGLRenderingContext or 211 WebGL2RenderingContext) XRWebGLRenderingContext; 212 213 dictionary XRWebGLLayerInit { 214 boolean antialias = true; 215 boolean depth = true; 216 boolean stencil = false; 217 boolean alpha = true; 218 boolean ignoreDepthValues = false; 219 double framebufferScaleFactor = 1.0; 220 }; 221 222 [Pref="dom.vr.webxr.enabled", SecureContext, Exposed=Window] 223 interface XRWebGLLayer { 224 [Throws] 225 constructor(XRSession session, 226 XRWebGLRenderingContext context, 227 optional XRWebGLLayerInit layerInit = {}); 228 // Attributes 229 readonly attribute boolean antialias; 230 readonly attribute boolean ignoreDepthValues; 231 232 [SameObject] readonly attribute WebGLFramebuffer? framebuffer; 233 readonly attribute unsigned long framebufferWidth; 234 readonly attribute unsigned long framebufferHeight; 235 236 // Methods 237 XRViewport? getViewport(XRView view); 238 239 // Static Methods 240 static double getNativeFramebufferScaleFactor(XRSession session); 241 };