#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/xr/service/browser_xr_runtime_impl.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/observer_list.h"
#include "build/build_config.h"
#include "content/browser/xr/service/vr_service_impl.h"
#include "content/browser/xr/xr_utils.h"
#include "content/public/browser/browser_xr_runtime.h"
#include "content/public/browser/xr_install_helper.h"
#include "content/public/browser/xr_integration_client.h"
#include "content/public/common/content_features.h"
#include "device/vr/buildflags/buildflags.h"
#include "device/vr/public/cpp/session_mode.h"
#include "device/vr/public/mojom/vr_service.mojom-shared.h"
#include "device/vr/public/mojom/xr_device.mojom-shared.h"
#include "device/vr/public/mojom/xr_session.mojom-shared.h"
#include "ui/gfx/geometry/decomposed_transform.h"
#include "ui/gfx/geometry/transform.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "base/android/android_hardware_buffer_compat.h"
#endif
namespace content {
namespace {
bool IsValidTransform(const gfx::Transform& transform) { … }
device::mojom::XRViewPtr ValidateXRView(const device::mojom::XRView* view) { … }
}
BrowserXRRuntimeImpl::BrowserXRRuntimeImpl(
device::mojom::XRDeviceId id,
device::mojom::XRDeviceDataPtr device_data,
mojo::PendingRemote<device::mojom::XRRuntime> runtime)
: … { … }
BrowserXRRuntimeImpl::~BrowserXRRuntimeImpl() { … }
void BrowserXRRuntimeImpl::ExitActiveImmersiveSession() { … }
bool BrowserXRRuntimeImpl::SupportsFeature(
device::mojom::XRSessionFeature feature) const { … }
bool BrowserXRRuntimeImpl::SupportsAllFeatures(
const std::vector<device::mojom::XRSessionFeature>& features) const { … }
bool BrowserXRRuntimeImpl::SupportsCustomIPD() const { … }
bool BrowserXRRuntimeImpl::SupportsNonEmulatedHeight() const { … }
bool BrowserXRRuntimeImpl::SupportsArBlendMode() { … }
void BrowserXRRuntimeImpl::StopImmersiveSession() { … }
void BrowserXRRuntimeImpl::OnExitPresent() { … }
void BrowserXRRuntimeImpl::OnVisibilityStateChanged(
device::mojom::XRVisibilityState visibility_state) { … }
void BrowserXRRuntimeImpl::OnServiceAdded(VRServiceImpl* service) { … }
void BrowserXRRuntimeImpl::OnServiceRemoved(VRServiceImpl* service) { … }
void BrowserXRRuntimeImpl::ExitPresent(VRServiceImpl* service) { … }
void BrowserXRRuntimeImpl::SetFramesThrottled(const VRServiceImpl* service,
bool throttled) { … }
void BrowserXRRuntimeImpl::RequestInlineSession(
device::mojom::XRRuntimeSessionOptionsPtr options,
device::mojom::XRRuntime::RequestSessionCallback callback) { … }
void BrowserXRRuntimeImpl::RequestImmersiveSession(
VRServiceImpl* service,
device::mojom::XRRuntimeSessionOptionsPtr options,
RequestSessionCallback callback) { … }
void BrowserXRRuntimeImpl::OnRequestSessionResult(
base::WeakPtr<VRServiceImpl> service,
device::mojom::XRRuntimeSessionOptionsPtr options,
RequestSessionCallback callback,
device::mojom::XRRuntimeSessionResultPtr session_result) { … }
void BrowserXRRuntimeImpl::EnsureInstalled(
int render_process_id,
int render_frame_id,
base::OnceCallback<void(bool)> install_callback) { … }
void BrowserXRRuntimeImpl::OnInstallFinished(bool succeeded) { … }
void BrowserXRRuntimeImpl::OnImmersiveSessionError() { … }
void BrowserXRRuntimeImpl::AddObserver(Observer* observer) { … }
void BrowserXRRuntimeImpl::RemoveObserver(Observer* observer) { … }
void BrowserXRRuntimeImpl::BeforeRuntimeRemoved() { … }
std::vector<device::mojom::XRSessionFeature>
BrowserXRRuntimeImpl::GetSupportedFeatures() { … }
#if BUILDFLAG(IS_WIN)
std::optional<CHROME_LUID> BrowserXRRuntimeImpl::GetLuid() const {
return device_data_->luid;
}
#endif
}