Commit a2ef70e0 authored by tzik's avatar tzik Committed by Commit Bot

Expand XRSessionCreationOptions on a WTF::Bind parameter

XRDevice passes an XRSessionCreationOptions instance to WTF::Bind, and
its |output_context_| is a garbage collected object.
As we have no chance to call XRSessionCreationOptions::Trace while it's
held in the callback, |output_context_| may be collected incorrectly by
GC.

This CL expands XRSessionCreationOptions members to the parameters of
XRDevice::OnRequestSessionReturned to fix the object graph.

Cq-Include-Trybots: luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Iae4750dbec20d99f838f45d69fc3b782ed71cee2
Reviewed-on: https://chromium-review.googlesource.com/1160741Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580392}
parent ebcd19b1
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "third_party/blink/renderer/modules/event_target_modules.h" #include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/xr/xr.h" #include "third_party/blink/renderer/modules/xr/xr.h"
#include "third_party/blink/renderer/modules/xr/xr_frame_provider.h" #include "third_party/blink/renderer/modules/xr/xr_frame_provider.h"
#include "third_party/blink/renderer/modules/xr/xr_presentation_context.h"
#include "third_party/blink/renderer/modules/xr/xr_session.h" #include "third_party/blink/renderer/modules/xr/xr_session.h"
namespace blink { namespace blink {
...@@ -178,19 +179,25 @@ ScriptPromise XRDevice::requestSession( ...@@ -178,19 +179,25 @@ ScriptPromise XRDevice::requestSession(
options.environmentIntegration(); options.environmentIntegration();
session_options->has_user_activation = has_user_activation; session_options->has_user_activation = has_user_activation;
XRPresentationContext* output_context =
options.hasOutputContext() ? options.outputContext() : nullptr;
// TODO(offenwanger): Once device activation is sorted out for WebXR, either // TODO(offenwanger): Once device activation is sorted out for WebXR, either
// pass in the value for metrics, or remove the value as soon as legacy API // pass in the value for metrics, or remove the value as soon as legacy API
// has been removed. // has been removed.
display_->RequestSession( display_->RequestSession(
std::move(session_options), false /* triggered by display activate */, std::move(session_options), false /* triggered by display activate */,
WTF::Bind(&XRDevice::OnRequestSessionReturned, WrapWeakPersistent(this), WTF::Bind(&XRDevice::OnRequestSessionReturned, WrapWeakPersistent(this),
WrapPersistent(resolver), options)); WrapPersistent(resolver), WrapPersistent(output_context),
options.environmentIntegration(), options.immersive()));
return promise; return promise;
} }
void XRDevice::OnRequestSessionReturned( void XRDevice::OnRequestSessionReturned(
ScriptPromiseResolver* resolver, ScriptPromiseResolver* resolver,
const XRSessionCreationOptions& options, XRPresentationContext* output_context,
bool environment_integration,
bool immersive,
device::mojom::blink::XRSessionPtr session_ptr) { device::mojom::blink::XRSessionPtr session_ptr) {
if (!session_ptr) { if (!session_ptr) {
DOMException* exception = DOMException::Create( DOMException* exception = DOMException::Create(
...@@ -199,22 +206,15 @@ void XRDevice::OnRequestSessionReturned( ...@@ -199,22 +206,15 @@ void XRDevice::OnRequestSessionReturned(
return; return;
} }
XRPresentationContext* output_context = nullptr;
if (options.hasOutputContext()) {
output_context = options.outputContext();
}
XRSession::EnvironmentBlendMode blend_mode = XRSession::kBlendModeOpaque; XRSession::EnvironmentBlendMode blend_mode = XRSession::kBlendModeOpaque;
if (options.environmentIntegration()) { if (environment_integration)
blend_mode = XRSession::kBlendModeAlphaBlend; blend_mode = XRSession::kBlendModeAlphaBlend;
}
XRSession* session = XRSession* session = new XRSession(this, immersive, environment_integration,
new XRSession(this, options.immersive(), options.environmentIntegration(), output_context, blend_mode);
output_context, blend_mode);
sessions_.insert(session); sessions_.insert(session);
if (options.immersive()) { if (immersive) {
frameProvider()->BeginImmersiveSession(session, std::move(session_ptr)); frameProvider()->BeginImmersiveSession(session, std::move(session_ptr));
} else { } else {
magic_window_provider_.Bind(std::move(session_ptr->data_provider)); magic_window_provider_.Bind(std::move(session_ptr->data_provider));
......
...@@ -88,7 +88,9 @@ class XRDevice final : public ScriptWrappable, ...@@ -88,7 +88,9 @@ class XRDevice final : public ScriptWrappable,
const char* checkSessionSupport(const XRSessionCreationOptions&) const; const char* checkSessionSupport(const XRSessionCreationOptions&) const;
void OnRequestSessionReturned(ScriptPromiseResolver* resolver, void OnRequestSessionReturned(ScriptPromiseResolver* resolver,
const XRSessionCreationOptions& options, XRPresentationContext* output_context,
bool environment_integration,
bool immersive,
device::mojom::blink::XRSessionPtr session); device::mojom::blink::XRSessionPtr session);
void OnSupportsSessionReturned(ScriptPromiseResolver* resolver, void OnSupportsSessionReturned(ScriptPromiseResolver* resolver,
bool supports_session); bool supports_session);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment