Bug 1788188 - Implement missing framerate methods in the WebXR spec. r=emilio

In particular this adds an initial implementation for the
updateTargetFrameRate method and adds the supportedFrameRates
and frameRate attributes to the XRSession.

Differential Revision: https://phabricator.services.mozilla.com/D156063
This commit is contained in:
Imanol Fernandez 2022-08-31 16:13:13 +00:00
Родитель 9dc15db244
Коммит 06712ca497
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -231,6 +231,13 @@ XRRenderState* XRSession::RenderState() { return mActiveRenderState; }
XRInputSourceArray* XRSession::InputSources() { return mInputSources; }
Nullable<float> XRSession::GetFrameRate() { return {}; }
void XRSession::GetSupportedFrameRates(JSContext*,
JS::MutableHandle<JSObject*> aRetVal) {
aRetVal.set(nullptr);
}
// https://immersive-web.github.io/webxr/#apply-the-pending-render-state
void XRSession::ApplyPendingRenderState() {
if (mPendingRenderState == nullptr) {
@ -393,6 +400,31 @@ already_AddRefed<Promise> XRSession::RequestReferenceSpace(
return promise.forget();
}
already_AddRefed<Promise> XRSession::UpdateTargetFrameRate(float aRate,
ErrorResult& aRv) {
nsCOMPtr<nsIGlobalObject> global = GetParentObject();
NS_ENSURE_TRUE(global, nullptr);
RefPtr<Promise> promise = Promise::Create(global, aRv);
NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
if (mEnded) {
promise->MaybeRejectWithInvalidStateError(
"UpdateTargetFrameRate can not be called on an XRSession that has "
"ended.");
return promise.forget();
}
// https://immersive-web.github.io/webxr/#dom-xrsession-updatetargetframerate
// TODO: Validate the rate with the frame rates supported from the device.
// We add a no op for now to avoid JS exceptions related to undefined method.
// The spec states that user agent MAY use rate to calculate a new display
// frame rate, so it's fine to let the default frame rate for now.
promise->MaybeResolve(JS::UndefinedHandleValue);
return promise.forget();
}
XRRenderState* XRSession::GetActiveRenderState() const {
return mActiveRenderState;
}

Просмотреть файл

@ -67,6 +67,9 @@ class XRSession final : public DOMEventTargetHelper, public nsARefreshObserver {
XRVisibilityState VisibilityState() const;
XRRenderState* RenderState();
XRInputSourceArray* InputSources();
Nullable<float> GetFrameRate();
void GetSupportedFrameRates(JSContext* aJSContext,
JS::MutableHandle<JSObject*> aRetval);
// WebIDL Methods
void UpdateRenderState(const XRRenderStateInit& aNewState, ErrorResult& aRv);
@ -76,6 +79,8 @@ class XRSession final : public DOMEventTargetHelper, public nsARefreshObserver {
mozilla::ErrorResult& aError);
void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
already_AddRefed<Promise> End(ErrorResult& aRv);
already_AddRefed<Promise> UpdateTargetFrameRate(float aRate,
ErrorResult& aRv);
// WebIDL Events
IMPL_EVENT_HANDLER(end);

Просмотреть файл

@ -43,12 +43,16 @@ interface XRSession : EventTarget {
readonly attribute XRVisibilityState visibilityState;
[SameObject] readonly attribute XRRenderState renderState;
[SameObject] readonly attribute XRInputSourceArray inputSources;
readonly attribute float? frameRate;
readonly attribute Float32Array? supportedFrameRates;
// Methods
[Throws]
void updateRenderState(optional XRRenderStateInit state = {});
[NewObject]
Promise<XRReferenceSpace> requestReferenceSpace(XRReferenceSpaceType type);
[NewObject]
Promise<void> updateTargetFrameRate(float rate);
[Throws]
long requestAnimationFrame(XRFrameRequestCallback callback);