Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRDisplay.h

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: address leon@ comments about name Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef VRDisplay_h 5 #ifndef VRDisplay_h
6 #define VRDisplay_h 6 #define VRDisplay_h
7 7
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/FrameRequestCallback.h" 10 #include "core/dom/FrameRequestCallback.h"
11 #include "device/vr/vr_service.mojom-blink.h" 11 #include "device/vr/vr_service.mojom-blink.h"
12 #include "modules/vr/VRDisplayCapabilities.h" 12 #include "modules/vr/VRDisplayCapabilities.h"
13 #include "modules/vr/VRLayer.h" 13 #include "modules/vr/VRLayer.h"
14 #include "mojo/public/cpp/bindings/binding.h"
14 #include "platform/Timer.h" 15 #include "platform/Timer.h"
15 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
16 #include "public/platform/WebGraphicsContext3DProvider.h" 17 #include "public/platform/WebGraphicsContext3DProvider.h"
17 #include "wtf/Forward.h" 18 #include "wtf/Forward.h"
18 #include "wtf/text/WTFString.h" 19 #include "wtf/text/WTFString.h"
19 20
20 namespace gpu { 21 namespace gpu {
21 namespace gles2 { 22 namespace gles2 {
22 class GLES2Interface; 23 class GLES2Interface;
23 } 24 }
24 } 25 }
25 26
26 namespace blink { 27 namespace blink {
27 28
28 class NavigatorVR; 29 class NavigatorVR;
29 class VRController; 30 class VRController;
30 class VREyeParameters; 31 class VREyeParameters;
31 class VRFrameData; 32 class VRFrameData;
32 class VRStageParameters; 33 class VRStageParameters;
33 class VRPose; 34 class VRPose;
34 35
35 class WebGLRenderingContextBase; 36 class WebGLRenderingContextBase;
36 37
37 enum VREye { VREyeNone, VREyeLeft, VREyeRight }; 38 enum VREye { VREyeNone, VREyeLeft, VREyeRight };
38 39
40 const unsigned MAX = 0xFFFFFFFF;
41
39 class VRDisplay final : public GarbageCollectedFinalized<VRDisplay>, 42 class VRDisplay final : public GarbageCollectedFinalized<VRDisplay>,
43 public device::mojom::blink::VRDisplayClient,
40 public ScriptWrappable { 44 public ScriptWrappable {
41 DEFINE_WRAPPERTYPEINFO(); 45 DEFINE_WRAPPERTYPEINFO();
46 USING_PRE_FINALIZER(VRDisplay, shutdownMessagePipe);
42 47
43 public: 48 public:
44 ~VRDisplay(); 49 ~VRDisplay();
45 50
46 unsigned displayId() const { return m_displayId; } 51 unsigned displayId() const { return m_displayId; }
47 const String& displayName() const { return m_displayName; } 52 const String& displayName() const { return m_displayName; }
48 53
49 VRDisplayCapabilities* capabilities() const { return m_capabilities; } 54 VRDisplayCapabilities* capabilities() const { return m_capabilities; }
50 VRStageParameters* stageParameters() const { return m_stageParameters; } 55 VRStageParameters* stageParameters() const { return m_stageParameters; }
51 56
52 bool isConnected() const { return m_isConnected; } 57 bool isConnected() const { return m_isConnected; }
53 bool isPresenting() const { return m_isPresenting; } 58 bool isPresenting() const { return m_isPresenting; }
54 59
55 bool getFrameData(VRFrameData*); 60 bool getFrameData(VRFrameData*);
56 VRPose* getPose(); 61 VRPose* getPose();
57 void resetPose(); 62 void resetPose();
58 63
59 double depthNear() const { return m_depthNear; } 64 double depthNear() const { return m_depthNear; }
60 double depthFar() const { return m_depthFar; } 65 double depthFar() const { return m_depthFar; }
61 66
62 void setDepthNear(double value) { m_depthNear = value; } 67 void setDepthNear(double value) { m_depthNear = value; }
63 void setDepthFar(double value) { m_depthFar = value; } 68 void setDepthFar(double value) { m_depthFar = value; }
64 69
70 void setDevice(device::mojom::blink::VRDevicePtr client) {
71 m_device = std::move(client);
72 }
73
65 VREyeParameters* getEyeParameters(const String&); 74 VREyeParameters* getEyeParameters(const String&);
66 75
67 int requestAnimationFrame(FrameRequestCallback*); 76 int requestAnimationFrame(FrameRequestCallback*);
68 void cancelAnimationFrame(int id); 77 void cancelAnimationFrame(int id);
69 78
70 ScriptPromise requestPresent(ScriptState*, const HeapVector<VRLayer>& layers); 79 ScriptPromise requestPresent(ScriptState*, const HeapVector<VRLayer>& layers);
71 ScriptPromise exitPresent(ScriptState*); 80 ScriptPromise exitPresent(ScriptState*);
72 81
73 HeapVector<VRLayer> getLayers(); 82 HeapVector<VRLayer> getLayers();
74 83
75 void submitFrame(); 84 void submitFrame();
76 85
77 DECLARE_VIRTUAL_TRACE(); 86 DECLARE_VIRTUAL_TRACE();
78 87
79 protected: 88 protected:
80 friend class VRController; 89 friend class VRController;
81 90
82 VRDisplay(NavigatorVR*); 91 VRDisplay(NavigatorVR*);
83 92
84 void update(const device::blink::VRDisplayPtr&); 93 void update(const device::mojom::blink::VRDisplayPtr&);
85 94
86 void updatePose(); 95 void updatePose();
87 96
88 void beginPresent(ScriptPromiseResolver*); 97 void beginPresent(ScriptPromiseResolver*);
89 void forceExitPresent(); 98 void forceExitPresent();
90 99
91 void updateLayerBounds(); 100 void updateLayerBounds();
92 void disconnected(); 101 void disconnected();
93 102
94 VRController* controller(); 103 VRController* controller();
95 104
96 private: 105 private:
97 void onFullscreenCheck(TimerBase*); 106 void onFullscreenCheck(TimerBase*);
107 device::mojom::blink::VRDisplayClientPtr BindClient();
108 void onPresentComplete(ScriptPromiseResolver*, bool);
109
110 // VRDisplayClient
111 void RegisterDevice(device::mojom::blink::VRDevicePtr) override;
112 void UpdateDisplayInfo(device::mojom::blink::VRDisplayPtr) override;
113 void OnDisplayChanged(device::mojom::blink::VRDisplayPtr) override;
114 void OnExitPresent() override;
115 void OnDisplayConnected(device::mojom::blink::VRDisplayPtr) override;
116 void OnDisplayDisconnected() override;
98 117
99 Member<NavigatorVR> m_navigatorVR; 118 Member<NavigatorVR> m_navigatorVR;
100 unsigned m_displayId; 119 unsigned m_displayId;
101 String m_displayName; 120 String m_displayName;
102 bool m_isConnected; 121 bool m_isConnected;
103 bool m_isPresenting; 122 bool m_isPresenting;
104 bool m_canUpdateFramePose; 123 bool m_canUpdateFramePose;
105 unsigned m_compositorHandle; 124 unsigned m_compositorHandle;
106 Member<VRDisplayCapabilities> m_capabilities; 125 Member<VRDisplayCapabilities> m_capabilities;
107 Member<VRStageParameters> m_stageParameters; 126 Member<VRStageParameters> m_stageParameters;
108 Member<VREyeParameters> m_eyeParametersLeft; 127 Member<VREyeParameters> m_eyeParametersLeft;
109 Member<VREyeParameters> m_eyeParametersRight; 128 Member<VREyeParameters> m_eyeParametersRight;
110 device::blink::VRPosePtr m_framePose; 129 device::mojom::blink::VRPosePtr m_framePose;
111 VRLayer m_layer; 130 VRLayer m_layer;
112 double m_depthNear; 131 double m_depthNear;
113 double m_depthFar; 132 double m_depthFar;
114 133
134 // Help VRController shutdown message pipe.
135 void shutdownMessagePipe();
136
115 Timer<VRDisplay> m_fullscreenCheckTimer; 137 Timer<VRDisplay> m_fullscreenCheckTimer;
116 gpu::gles2::GLES2Interface* m_contextGL; 138 gpu::gles2::GLES2Interface* m_contextGL;
117 Member<WebGLRenderingContextBase> m_renderingContext; 139 Member<WebGLRenderingContextBase> m_renderingContext;
140
141 device::mojom::blink::VRDevicePtr m_device;
142
143 static unsigned nextId;
144
145 mojo::Binding<device::mojom::blink::VRDisplayClient> m_binding;
118 }; 146 };
119 147
120 using VRDisplayVector = HeapVector<Member<VRDisplay>>; 148 using VRDisplayVector = HeapVector<Member<VRDisplay>>;
121 149
122 enum class PresentationResult { 150 enum class PresentationResult {
123 Requested = 0, 151 Requested = 0,
124 Success = 1, 152 Success = 1,
125 SuccessAlreadyPresenting = 2, 153 SuccessAlreadyPresenting = 2,
126 VRDisplayCannotPresent = 3, 154 VRDisplayCannotPresent = 3,
127 PresentationNotSupportedByDisplay = 4, 155 PresentationNotSupportedByDisplay = 4,
128 VRDisplayNotFound = 5, 156 VRDisplayNotFound = 5,
129 NotInitiatedByUserGesture = 6, 157 NotInitiatedByUserGesture = 6,
130 InvalidNumberOfLayers = 7, 158 InvalidNumberOfLayers = 7,
131 InvalidLayerSource = 8, 159 InvalidLayerSource = 8,
132 LayerSourceMissingWebGLContext = 9, 160 LayerSourceMissingWebGLContext = 9,
133 InvalidLayerBounds = 10, 161 InvalidLayerBounds = 10,
134 ServiceInactive = 11, 162 ServiceInactive = 11,
135 RequestDenied = 12, 163 RequestDenied = 12,
136 PresentationResultMax, // Must be last member of enum. 164 PresentationResultMax, // Must be last member of enum.
137 }; 165 };
138 166
139 void ReportPresentationResult(PresentationResult); 167 void ReportPresentationResult(PresentationResult);
140 168
141 } // namespace blink 169 } // namespace blink
142 170
143 #endif // VRDisplay_h 171 #endif // VRDisplay_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698