File: xr_frame.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (152 lines) | stat: -rw-r--r-- 5,717 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_FRAME_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_FRAME_H_

#include <memory>

#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_matrix.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/xr/xr_joint_pose.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "ui/gfx/geometry/transform.h"

namespace blink {

class ExceptionState;
class ScriptState;
class XRAnchor;
class XRAnchorSet;
class XRCPUDepthInformation;
class XRHitTestResult;
class XRHitTestSource;
class XRImageTrackingResult;
class XRInputSource;
class XRJointPose;
class XRLightEstimate;
class XRLightProbe;
class XRJointSpace;
class XRPlaneSet;
class XRPose;
class XRReferenceSpace;
class XRRigidTransform;
class XRSession;
class XRSpace;
class XRTransientInputHitTestResult;
class XRTransientInputHitTestSource;
class XRView;
class XRViewerPose;

template <typename IDLType>
class FrozenArray;

class XRFrame final : public ScriptWrappable {
  DEFINE_WRAPPERTYPEINFO();

 public:
  static constexpr char kInactiveFrame[] =
      "XRFrame access outside the callback that produced it is invalid.";
  static constexpr char kNonAnimationFrame[] =
      "This method can only be called on XRFrame objects passed to "
      "XRSession.requestAnimationFrame callbacks.";

  explicit XRFrame(XRSession* session, bool is_animation_frame = false);

  XRSession* session() const { return session_.Get(); }

  // Returns basespace_from_viewer.
  XRViewerPose* getViewerPose(XRReferenceSpace* basespace,
                              ExceptionState& exception_state);

  // Return an XRPose that has a transform of basespace_from_space, while
  // accounting for the base pose matrix of this frame. If computing a transform
  // isn't possible, return nullptr.
  XRPose* getPose(XRSpace* space,
                  XRSpace* basespace,
                  ExceptionState& exception_state);

  XRAnchorSet* trackedAnchors() const;
  XRLightEstimate* getLightEstimate(XRLightProbe* light_probe,
                                    ExceptionState& exception_state) const;
  XRCPUDepthInformation* getDepthInformation(
      XRView* view,
      ExceptionState& exception_state) const;
  XRPlaneSet* detectedPlanes(ExceptionState& exception_state) const;

  void Trace(Visitor*) const override;

  void Deactivate();

  bool IsActive() const;

  bool IsAnimationFrame() const { return is_animation_frame_; }

  const FrozenArray<XRHitTestResult>& getHitTestResults(
      XRHitTestSource* hit_test_source,
      ExceptionState& exception_state);

  const FrozenArray<XRTransientInputHitTestResult>&
  getHitTestResultsForTransientInput(
      XRTransientInputHitTestSource* hit_test_source,
      ExceptionState& exception_state);

  ScriptPromise<XRAnchor> createAnchor(ScriptState* script_state,
                                       XRRigidTransform* initial_pose,
                                       XRSpace* space,
                                       ExceptionState& exception_state);

  const FrozenArray<XRImageTrackingResult>& getImageTrackingResults(
      ExceptionState&);

  XRJointPose* getJointPose(XRJointSpace* joint,
                            XRSpace* baseSpace,
                            ExceptionState& exception_state) const;
  bool fillJointRadii(const HeapVector<Member<XRJointSpace>>& jointSpaces,
                      NotShared<DOMFloat32Array> radii,
                      ExceptionState& exception_state) const;
  bool fillPoses(const HeapVector<Member<XRSpace>>& spaces,
                 XRSpace* baseSpace,
                 NotShared<DOMFloat32Array> transforms,
                 ExceptionState& exception_state) const;

 private:
  std::unique_ptr<gfx::Transform> GetAdjustedPoseMatrix(XRSpace*) const;
  XRPose* GetTargetRayPose(XRInputSource*, XRSpace*) const;
  XRPose* GetGripPose(XRInputSource*, XRSpace*) const;
  // Helper that creates an anchor with the assumption that the conversion from
  // passed in space to a stationary space is required.
  // |native_origin_from_anchor| is a transform from |space|'s native origin to
  // the desired anchor position (i.e. the origin-offset of the |space| is
  // already taken into account).
  ScriptPromise<XRAnchor> CreateAnchorFromNonStationarySpace(
      ScriptState* script_state,
      const gfx::Transform& native_origin_from_anchor,
      XRSpace* space,
      std::optional<uint64_t> maybe_plane_id,
      ExceptionState& exception_state);
  // Helper for checking if space and frame have the same session.
  // Sets kInvalidStateError exception state if sessions are different.
  bool IsSameSession(XRSession* space_session,
                     ExceptionState& exception_state) const;

  const Member<XRSession> session_;

  // Frames are only active during callbacks. getPose and getViewerPose should
  // only be called from JS on active frames.
  bool is_active_ = true;

  // Only frames created by XRSession.requestAnimationFrame callbacks are
  // animation frames. getViewerPose should only be called from JS on active
  // animation frames.
  bool is_animation_frame_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_FRAME_H_