File: xr_view.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 (154 lines) | stat: -rw-r--r-- 5,502 bytes parent folder | download | duplicates (5)
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
153
154
// 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_VIEW_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_VIEW_H_

#include "device/vr/public/mojom/vr_service.mojom-blink.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/xr/xr_graphics_binding.h"
#include "third_party/blink/renderer/modules/xr/xr_rigid_transform.h"
#include "third_party/blink/renderer/modules/xr/xr_view_geometry.h"
#include "third_party/blink/renderer/modules/xr/xr_viewport.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 "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/transform.h"

namespace blink {

class V8XREye;
class XRCamera;
class XRCPUDepthInformation;
class XRDepthManager;
class XRFrame;
class XRSession;
class XRViewData;
class XRWebGLDepthInformation;

class MODULES_EXPORT XRView final : public ScriptWrappable {
  DEFINE_WRAPPERTYPEINFO();

 public:
  XRView(XRFrame* frame,
         XRViewData* view_data,
         const gfx::Transform& ref_space_from_mojo);

  V8XREye eye() const;
  device::mojom::blink::XREye EyeValue() const { return eye_; }
  gfx::Transform refSpaceFromMojo() const { return ref_space_from_mojo_; }
  XRViewData* ViewData() const { return view_data_.Get(); }
  XRViewport* Viewport(double scale);

  XRFrame* frame() const;
  XRSession* session() const;
  NotShared<DOMFloat32Array> projectionMatrix() const;
  XRRigidTransform* viewGeometryTransform() const;
  XRCamera* camera() const;

  // isFirstPersonObserver is only true for views that composed with a video
  // feed that is not directly displayed on the viewer device. Primarily this is
  // used for video streams from optically transparent AR headsets.
  bool isFirstPersonObserver() const;

  std::optional<double> recommendedViewportScale() const;
  void requestViewportScale(std::optional<double> scale);

  void Trace(Visitor*) const override;

  XRCPUDepthInformation* GetCpuDepthInformation(
      ExceptionState& exception_state) const;

  XRWebGLDepthInformation* GetWebGLDepthInformation(
      ExceptionState& exception_state) const;

 private:
  device::mojom::blink::XREye eye_;
  gfx::Transform ref_space_from_mojo_;
  Member<XRFrame> frame_;
  Member<XRViewData> view_data_;
  // The transform from the view to the reference space requested by
  // XRFrame::getViewerPose.
  Member<XRRigidTransform> ref_space_from_view_;
  NotShared<DOMFloat32Array> projection_matrix_;
  Member<XRViewport> viewport_;
};

class MODULES_EXPORT XRViewData final : public GarbageCollected<XRViewData>,
                                        public XRViewGeometry {
 public:
  XRViewData(wtf_size_t index,
             device::mojom::blink::XREye eye,
             gfx::Rect viewport,
             XRGraphicsBinding::Api graphics_api)
      : XRViewGeometry(graphics_api),
        index_(index),
        eye_(eye),
        viewport_(viewport) {}
  XRViewData(
      wtf_size_t index,
      device::mojom::blink::XRViewPtr view,
      double depth_near,
      double depth_far,
      const device::mojom::blink::XRSessionDeviceConfig& device_config,
      const HashSet<device::mojom::XRSessionFeature>& enabled_feature_set,
      XRGraphicsBinding::Api graphics_api);

  void UpdateView(device::mojom::blink::XRViewPtr view,
                  double depth_near,
                  double depth_far);

  wtf_size_t index() const { return index_; }
  device::mojom::blink::XREye Eye() const { return eye_; }
  const gfx::Rect& Viewport() const { return viewport_; }
  bool IsFirstPersonObserver() const { return is_first_person_observer_; }

  XRCPUDepthInformation* GetCpuDepthInformation(
      const XRView* xr_view,
      ExceptionState& exception_state) const;

  XRWebGLDepthInformation* GetWebGLDepthInformation(
      const XRView* xr_view,
      ExceptionState& exception_state) const;

  std::optional<double> recommendedViewportScale() const;
  void SetRecommendedViewportScale(std::optional<double> scale) {
    recommended_viewport_scale_ = scale;
  }

  void requestViewportScale(std::optional<double> scale);

  bool ViewportModifiable() const { return viewport_modifiable_; }
  void SetViewportModifiable(bool modifiable) {
    viewport_modifiable_ = modifiable;
  }
  double CurrentViewportScale() const { return current_viewport_scale_; }
  void SetCurrentViewportScale(double scale) {
    current_viewport_scale_ = scale;
  }
  double RequestedViewportScale() const { return requested_viewport_scale_; }

  // Returns true if the viewport scale actually changed.
  bool ApplyViewportScaleForFrame();

  void Trace(Visitor*) const;

 private:
  const wtf_size_t index_;
  const device::mojom::blink::XREye eye_;
  gfx::Rect viewport_;
  bool is_first_person_observer_ = false;
  std::optional<double> recommended_viewport_scale_ = std::nullopt;
  double requested_viewport_scale_ = 1.0;
  double current_viewport_scale_ = 1.0;
  bool viewport_modifiable_ = false;
  Member<XRDepthManager> depth_manager_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_XR_XR_VIEW_H_