chromium/third_party/blink/renderer/modules/xr/xr_session.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/xr/xr_session.h"

#include <algorithm>
#include <memory>
#include <string>
#include <utility>

#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/trace_event/trace_event.h"
#include "base/types/pass_key.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/renderer/bindings/core/v8/frozen_array.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_frame_request_callback.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_hit_test_options_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_image_tracking_result.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_render_state_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_xr_transient_input_hit_test_options_init.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/probe/async_task_context.h"
#include "third_party/blink/renderer/core/resize_observer/resize_observer.h"
#include "third_party/blink/renderer/core/resize_observer/resize_observer_entry.h"
#include "third_party/blink/renderer/modules/event_target_modules.h"
#include "third_party/blink/renderer/modules/xr/vr_service_type_converters.h"
#include "third_party/blink/renderer/modules/xr/xr_anchor_set.h"
#include "third_party/blink/renderer/modules/xr/xr_bounded_reference_space.h"
#include "third_party/blink/renderer/modules/xr/xr_camera.h"
#include "third_party/blink/renderer/modules/xr/xr_canvas_input_provider.h"
#include "third_party/blink/renderer/modules/xr/xr_cube_map.h"
#include "third_party/blink/renderer/modules/xr/xr_dom_overlay_state.h"
#include "third_party/blink/renderer/modules/xr/xr_frame.h"
#include "third_party/blink/renderer/modules/xr/xr_frame_provider.h"
#include "third_party/blink/renderer/modules/xr/xr_hit_test_source.h"
#include "third_party/blink/renderer/modules/xr/xr_image_tracking_result.h"
#include "third_party/blink/renderer/modules/xr/xr_input_source_event.h"
#include "third_party/blink/renderer/modules/xr/xr_input_sources_change_event.h"
#include "third_party/blink/renderer/modules/xr/xr_light_probe.h"
#include "third_party/blink/renderer/modules/xr/xr_plane_manager.h"
#include "third_party/blink/renderer/modules/xr/xr_ray.h"
#include "third_party/blink/renderer/modules/xr/xr_reference_space.h"
#include "third_party/blink/renderer/modules/xr/xr_render_state.h"
#include "third_party/blink/renderer/modules/xr/xr_session_event.h"
#include "third_party/blink/renderer/modules/xr/xr_session_viewport_scaler.h"
#include "third_party/blink/renderer/modules/xr/xr_system.h"
#include "third_party/blink/renderer/modules/xr/xr_transient_input_hit_test_source.h"
#include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include "third_party/blink/renderer/modules/xr/xr_view.h"
#include "third_party/blink/renderer/modules/xr/xr_webgl_layer.h"
#include "third_party/blink/renderer/platform/bindings/enumeration_base.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/text/string_operators.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/transform.h"

namespace blink {

namespace {

const char kSessionEnded[] =;

const char kReferenceSpaceNotSupported[] =;

const char kIncompatibleLayer[] =;

const char kBaseLayerAndLayers[] =;

const char kMultiLayersNotEnabled[] =;

const char kDuplicateLayer[] =;

const char kInlineVerticalFOVNotSupported[] =;

const char kFeatureNotSupportedByDevicePrefix[] =;

const char kFeatureNotSupportedBySessionPrefix[] =;

const char kDeviceDisconnected[] =;

const char kUnableToDecomposeMatrix[] =;

const char kUnableToRetrieveNativeOrigin[] =;

const char kHitTestSubscriptionFailed[] =;

const char kAnchorCreationFailed[] =;

const char kEntityTypesNotSpecified[] =;

const char kSessionNotHaveSetFrameRate[] =;

const float kMinDefaultFramebufferScale =;
const float kMaxDefaultFramebufferScale =;

// Indices into the views array.
const unsigned int kMonoView =;

// Returns the session feature corresponding to the given reference space type.
std::optional<device::mojom::XRSessionFeature> MapReferenceSpaceTypeToFeature(
    device::mojom::blink::XRReferenceSpaceType type) {}

std::unique_ptr<gfx::Transform> getPoseMatrix(
    const device::mojom::blink::VRPosePtr& pose) {}

std::optional<device::mojom::blink::EntityTypeForHitTest>
EntityTypeForHitTestFromString(const String& string) {}

// Returns a vector of entity types from hit test options, without duplicates.
// OptionsType can be either XRHitTestOptionsInit or
// XRTransientInputHitTestOptionsInit.
template <typename OptionsType>
Vector<device::mojom::blink::EntityTypeForHitTest> GetEntityTypesForHitTest(
    OptionsType* options_init) {}

template <typename T>
HashSet<uint64_t> GetIdsOfUnusedHitTestSources(
    const HeapHashMap<uint64_t, WeakMember<T>>& id_to_hit_test_source,
    const HashSet<uint64_t>& all_ids) {}

String DepthUsageToString(device::mojom::XRDepthUsage usage) {}

String DepthDataFormatToString(device::mojom::XRDepthDataFormat data_format) {}

}  // namespace

#define DCHECK_HIT_TEST_SOURCES()

constexpr char XRSession::kNoRigidTransformSpecified[];
constexpr char XRSession::kUnableToRetrieveMatrix[];
constexpr char XRSession::kNoSpaceSpecified[];
constexpr char XRSession::kAnchorsFeatureNotSupported[];
constexpr char XRSession::kPlanesFeatureNotSupported[];
constexpr char XRSession::kDepthSensingFeatureNotSupported[];
constexpr char XRSession::kRawCameraAccessFeatureNotSupported[];
constexpr char XRSession::kCannotCancelHitTestSource[];
constexpr char XRSession::kCannotReportPoses[];

class XRSession::XRSessionResizeObserverDelegate final
    : public ResizeObserver::Delegate {};

XRSession::MetricsReporter::MetricsReporter(
    mojo::Remote<device::mojom::blink::XRSessionMetricsRecorder> recorder)
    :{}

void XRSession::MetricsReporter::ReportFeatureUsed(
    device::mojom::blink::XRSessionFeature feature) {}

XRSession::XRSession(
    XRSystem* xr,
    mojo::PendingReceiver<device::mojom::blink::XRSessionClient>
        client_receiver,
    device::mojom::blink::XRSessionMode mode,
    device::mojom::blink::XREnvironmentBlendMode environment_blend_mode,
    device::mojom::blink::XRInteractionMode interaction_mode,
    device::mojom::blink::XRSessionDeviceConfigPtr device_config,
    bool sensorless_session,
    XRSessionFeatureSet enabled_feature_set,
    uint64_t trace_id)
    :{}

void XRSession::SetDOMOverlayElement(Element* element) {}

const String XRSession::visibilityState() const {}

const FrozenArray<IDLString>& XRSession::enabledFeatures() const {}

XRAnchorSet* XRSession::TrackedAnchors() const {}

bool XRSession::immersive() const {}

ExecutionContext* XRSession::GetExecutionContext() const {}

const AtomicString& XRSession::InterfaceName() const {}

void XRSession::updateRenderState(XRRenderStateInit* init,
                                  ExceptionState& exception_state) {}

const String& XRSession::depthUsage(ExceptionState& exception_state) {}

const String& XRSession::depthDataFormat(ExceptionState& exception_state) {}

void XRSession::UpdateViews(Vector<device::mojom::blink::XRViewPtr> views) {}

void XRSession::UpdateStageParameters(
    uint32_t stage_parameters_id,
    const device::mojom::blink::VRStageParametersPtr& stage_parameters) {}

ScriptPromise<IDLUndefined> XRSession::updateTargetFrameRate(
    float rate,
    ExceptionState& exception_state) {}

ScriptPromise<XRReferenceSpace> XRSession::requestReferenceSpace(
    ScriptState* script_state,
    const String& type,
    ExceptionState& exception_state) {}

ScriptPromise<XRAnchor> XRSession::CreateAnchorHelper(
    ScriptState* script_state,
    const gfx::Transform& native_origin_from_anchor,
    const device::mojom::blink::XRNativeOriginInformationPtr&
        native_origin_information,
    std::optional<uint64_t> maybe_plane_id,
    ExceptionState& exception_state) {}

std::optional<XRSession::ReferenceSpaceInformation>
XRSession::GetStationaryReferenceSpace() const {}

void XRSession::ScheduleVideoFrameCallbacksExecution(
    ExecuteVfcCallback execute_vfc_callback) {}

base::TimeDelta XRSession::TakeAnimationFrameTimerAverage() {}

void XRSession::ExecuteVideoFrameCallbacks(double timestamp) {}

int XRSession::requestAnimationFrame(V8XRFrameRequestCallback* callback) {}

void XRSession::cancelAnimationFrame(int id) {}

XRInputSourceArray* XRSession::inputSources(ScriptState* script_state) const {}

ScriptPromise<XRHitTestSource> XRSession::requestHitTestSource(
    ScriptState* script_state,
    XRHitTestOptionsInit* options_init,
    ExceptionState& exception_state) {}

ScriptPromise<XRTransientInputHitTestSource>
XRSession::requestHitTestSourceForTransientInput(
    ScriptState* script_state,
    XRTransientInputHitTestOptionsInit* options_init,
    ExceptionState& exception_state) {}

void XRSession::OnSubscribeToHitTestResult(
    ScriptPromiseResolver<XRHitTestSource>* resolver,
    device::mojom::SubscribeToHitTestResult result,
    uint64_t subscription_id) {}

void XRSession::OnSubscribeToHitTestForTransientInputResult(
    ScriptPromiseResolver<XRTransientInputHitTestSource>* resolver,
    device::mojom::SubscribeToHitTestResult result,
    uint64_t subscription_id) {}

void XRSession::OnCreateAnchorResult(ScriptPromiseResolver<XRAnchor>* resolver,
                                     device::mojom::CreateAnchorResult result,
                                     uint64_t id) {}

void XRSession::OnEnvironmentProviderCreated() {}

void XRSession::EnsureEnvironmentErrorHandler() {}

void XRSession::OnEnvironmentProviderError() {}

void XRSession::ProcessAnchorsData(
    const device::mojom::blink::XRAnchorsData* tracked_anchors_data,
    double timestamp) {}

XRPlaneSet* XRSession::GetDetectedPlanes() const {}

void XRSession::CleanUpUnusedHitTestSources() {}

void XRSession::ProcessHitTestData(
    const device::mojom::blink::XRHitTestSubscriptionResultsData*
        hit_test_subscriptions_data) {}

ScriptPromise<XRLightProbe> XRSession::requestLightProbe(
    ScriptState* script_state,
    XRLightProbeInit* light_probe_init,
    ExceptionState& exception_state) {}

ScriptPromise<IDLUndefined> XRSession::end(ScriptState* script_state,
                                           ExceptionState& exception_state) {}

void XRSession::ForceEnd(ShutdownPolicy shutdown_policy) {}

void XRSession::HandleShutdown() {}

double XRSession::NativeFramebufferScale() const {}

double XRSession::RecommendedFramebufferScale() const {}

gfx::SizeF XRSession::RecommendedFramebufferSize() const {}

gfx::SizeF XRSession::RecommendedArrayTextureSize() const {}

gfx::Size XRSession::OutputCanvasSize() const {}

void XRSession::OnFocusChanged() {}

void XRSession::OnVisibilityStateChanged(XRVisibilityState visibility_state) {}

// The ultimate visibility state of the session is a combination of the devices
// reported visibility state and, for inline sessions, the frame focus, which
// will override the device visibility to "hidden" if the frame is not currently
// focused.
void XRSession::UpdateVisibilityState() {}

void XRSession::MaybeRequestFrame() {}

void XRSession::DetachOutputCanvas(HTMLCanvasElement* canvas) {}

void XRSession::ApplyPendingRenderState() {}

void XRSession::UpdatePresentationFrameState(
    double timestamp,
    device::mojom::blink::XRFrameDataPtr frame_data,
    int16_t frame_id,
    bool emulated_position) {}

ScriptPromise<IDLArray<V8XRImageTrackingScore>>
XRSession::getTrackedImageScores(ScriptState* script_state,
                                 ExceptionState& exception_state) {}

void XRSession::ProcessTrackedImagesData(
    const device::mojom::blink::XRTrackedImagesData* images_data) {}

const FrozenArray<XRImageTrackingResult>& XRSession::ImageTrackingResults(
    ExceptionState& exception_state) {}

void XRSession::UpdateWorldUnderstandingStateForFrame(
    double timestamp,
    const device::mojom::blink::XRFrameDataPtr& frame_data) {}

bool XRSession::IsFeatureEnabled(
    device::mojom::XRSessionFeature feature) const {}

void XRSession::SetMetricsReporter(std::unique_ptr<MetricsReporter> reporter) {}

void XRSession::OnFrame(
    double timestamp,
    const std::optional<gpu::MailboxHolder>& output_mailbox_holder,
    const std::optional<gpu::MailboxHolder>& camera_image_mailbox_holder) {}

void XRSession::LogGetPose() const {}

bool XRSession::CanReportPoses() const {}

bool XRSession::CanEnableAntiAliasing() const {}

std::optional<gfx::Transform> XRSession::GetMojoFrom(
    device::mojom::blink::XRReferenceSpaceType space_type) const {}

XRFrame* XRSession::CreatePresentationFrame(bool is_animation_frame) {}

void XRSession::UpdateInlineView() {}

// Called when the canvas element for this session's output context is resized.
void XRSession::UpdateCanvasDimensions(Element* element) {}

void XRSession::OnInputStateChangeInternal(
    int16_t frame_id,
    base::span<const device::mojom::blink::XRInputSourceStatePtr>
        input_states) {}

void XRSession::ProcessInputSourceEvents(
    base::span<const device::mojom::blink::XRInputSourceStatePtr>
        input_states) {}

void XRSession::AddTransientInputSource(XRInputSource* input_source) {}

void XRSession::RemoveTransientInputSource(XRInputSource* input_source) {}

void XRSession::OnMojoSpaceReset() {}

void XRSession::OnExitPresent() {}

bool XRSession::ValidateHitTestSourceExists(
    XRHitTestSource* hit_test_source) const {}

bool XRSession::ValidateHitTestSourceExists(
    XRTransientInputHitTestSource* hit_test_source) const {}

bool XRSession::RemoveHitTestSource(XRHitTestSource* hit_test_source) {}

bool XRSession::RemoveHitTestSource(
    XRTransientInputHitTestSource* hit_test_source) {}

const HeapVector<Member<XRViewData>>& XRSession::views() {}

bool XRSession::HasPendingActivity() const {}

void XRSession::Trace(Visitor* visitor) const {}

}  // namespace blink