Title: [289409] trunk/Source/WebCore
- Revision
- 289409
- Author
- [email protected]
- Date
- 2022-02-08 11:30:28 -0800 (Tue, 08 Feb 2022)
Log Message
[WebXR] Ensure only one frame update can be requested with the device at any time
https://bugs.webkit.org/show_bug.cgi?id=236247
Patch by Ada Chan <[email protected]> on 2022-02-08
Reviewed by Dean Jackson.
Rename WebXRSession::requestFrame() to WebXRSession::requestFrameIfNeeded()
with logic added to determine whether a new frame update request should be
sent to the device. The boolean m_isDeviceFrameRequestPending tracks whether
a frame request is pending with the device, and requestFrameIfNeeded() should
bail early if that boolean is true.
* Modules/webxr/WebXRSession.cpp:
(WebCore::WebXRSession::requestAnimationFrame):
(WebCore::WebXRSession::updateSessionVisibilityState):
(WebCore::WebXRSession::requestFrameIfNeeded):
(WebCore::WebXRSession::onFrame):
(WebCore::WebXRSession::requestFrame): Deleted.
* Modules/webxr/WebXRSession.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (289408 => 289409)
--- trunk/Source/WebCore/ChangeLog 2022-02-08 19:29:07 UTC (rev 289408)
+++ trunk/Source/WebCore/ChangeLog 2022-02-08 19:30:28 UTC (rev 289409)
@@ -1,3 +1,24 @@
+2022-02-08 Ada Chan <[email protected]>
+
+ [WebXR] Ensure only one frame update can be requested with the device at any time
+ https://bugs.webkit.org/show_bug.cgi?id=236247
+
+ Reviewed by Dean Jackson.
+
+ Rename WebXRSession::requestFrame() to WebXRSession::requestFrameIfNeeded()
+ with logic added to determine whether a new frame update request should be
+ sent to the device. The boolean m_isDeviceFrameRequestPending tracks whether
+ a frame request is pending with the device, and requestFrameIfNeeded() should
+ bail early if that boolean is true.
+
+ * Modules/webxr/WebXRSession.cpp:
+ (WebCore::WebXRSession::requestAnimationFrame):
+ (WebCore::WebXRSession::updateSessionVisibilityState):
+ (WebCore::WebXRSession::requestFrameIfNeeded):
+ (WebCore::WebXRSession::onFrame):
+ (WebCore::WebXRSession::requestFrame): Deleted.
+ * Modules/webxr/WebXRSession.h:
+
2022-02-08 Sam Weinig <[email protected]>
Conversion to a color space with a smaller gamut should perform gamut mapping
Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (289408 => 289409)
--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp 2022-02-08 19:29:07 UTC (rev 289408)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp 2022-02-08 19:30:28 UTC (rev 289409)
@@ -265,8 +265,7 @@
// Script can add multiple requestAnimationFrame callbacks but we should only request a device frame once.
// When requestAnimationFrame is called during processing RAF callbacks the next requestFrame is scheduled
// at the end of WebXRSession::onFrame() to prevent requesting a new frame before the current one has ended.
- if (m_callbacks.size() == 1)
- requestFrame();
+ requestFrameIfNeeded();
// 4. Return session's animation frame callback identifier's current value.
return newId;
@@ -451,12 +450,9 @@
if (m_visibilityState == visibilityState)
return;
- bool wasHidden = m_visibilityState == XRVisibilityState::Hidden;
-
m_visibilityState = visibilityState;
- if (wasHidden && !m_ended && !m_callbacks.isEmpty())
- requestFrame();
+ requestFrameIfNeeded();
// From https://immersive-web.github.io/webxr/#event-types
// A user agent MUST dispatch a visibilitychange event on an XRSession each time the
@@ -523,9 +519,22 @@
return true;
}
-void WebXRSession::requestFrame()
+void WebXRSession::requestFrameIfNeeded()
{
+ ASSERT(isMainThread());
+
+ if (m_ended)
+ return;
+
+ if (m_visibilityState == XRVisibilityState::Hidden)
+ return;
+
+ if (m_callbacks.isEmpty() || m_isDeviceFrameRequestPending)
+ return;
+
+ m_isDeviceFrameRequestPending = true;
m_device->requestFrame([this, protectedThis = Ref { *this }](auto&& frameData) {
+ m_isDeviceFrameRequestPending = false;
onFrame(WTFMove(frameData));
});
}
@@ -613,9 +622,7 @@
m_device->submitFrame(WTFMove(frameLayers));
}
- if (!m_callbacks.isEmpty())
- requestFrame();
-
+ requestFrameIfNeeded();
});
}
Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.h (289408 => 289409)
--- trunk/Source/WebCore/Modules/webxr/WebXRSession.h 2022-02-08 19:29:07 UTC (rev 289408)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.h 2022-02-08 19:30:28 UTC (rev 289409)
@@ -123,7 +123,7 @@
bool referenceSpaceIsSupported(XRReferenceSpaceType) const;
bool frameShouldBeRendered() const;
- void requestFrame();
+ void requestFrameIfNeeded();
void onFrame(PlatformXR::Device::FrameData&&);
void applyPendingRenderState();
@@ -145,6 +145,7 @@
unsigned m_nextCallbackId { 1 };
Vector<Ref<XRFrameRequestCallback>> m_callbacks;
+ bool m_isDeviceFrameRequestPending { false };
Vector<PlatformXR::Device::ViewData> m_views;
PlatformXR::Device::FrameData m_frameData;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes