| OLD | NEW |
| 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 "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/FrameRequestCallback.h" | 9 #include "core/dom/FrameRequestCallback.h" |
| 10 #include "core/events/EventTarget.h" | 10 #include "core/events/EventTarget.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 "mojo/public/cpp/bindings/binding.h" |
| 15 #include "platform/Timer.h" | |
| 16 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 17 #include "public/platform/WebGraphicsContext3DProvider.h" | 16 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 18 #include "wtf/Forward.h" | 17 #include "wtf/Forward.h" |
| 19 #include "wtf/text/WTFString.h" | 18 #include "wtf/text/WTFString.h" |
| 20 | 19 |
| 21 namespace gpu { | 20 namespace gpu { |
| 22 namespace gles2 { | 21 namespace gles2 { |
| 23 class GLES2Interface; | 22 class GLES2Interface; |
| 24 } | 23 } |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace blink { | 26 namespace blink { |
| 28 | 27 |
| 29 class NavigatorVR; | 28 class NavigatorVR; |
| 30 class ScriptedAnimationController; | 29 class ScriptedAnimationController; |
| 31 class VRController; | 30 class VRController; |
| 32 class VREyeParameters; | 31 class VREyeParameters; |
| 33 class VRFrameData; | 32 class VRFrameData; |
| 34 class VRStageParameters; | 33 class VRStageParameters; |
| 35 class VRPose; | 34 class VRPose; |
| 36 | 35 |
| 37 class WebGLRenderingContextBase; | 36 class WebGLRenderingContextBase; |
| 38 | 37 |
| 39 enum VREye { VREyeNone, VREyeLeft, VREyeRight }; | 38 enum VREye { VREyeNone, VREyeLeft, VREyeRight }; |
| 40 | 39 |
| 40 class StatTracker final { |
| 41 public: |
| 42 StatTracker(unsigned int capacity); |
| 43 ~StatTracker(); |
| 44 bool hasPrediction(); |
| 45 double getPrediction(); |
| 46 void add(double value); |
| 47 void clear(); |
| 48 private: |
| 49 unsigned int m_capacity; |
| 50 std::list<double> m_items; |
| 51 }; |
| 52 |
| 41 class VRDisplay final : public EventTargetWithInlineData, | 53 class VRDisplay final : public EventTargetWithInlineData, |
| 42 public ActiveScriptWrappable<VRDisplay>, | 54 public ActiveScriptWrappable<VRDisplay>, |
| 43 public ContextLifecycleObserver, | 55 public ContextLifecycleObserver, |
| 44 public device::mojom::blink::VRDisplayClient { | 56 public device::mojom::blink::VRDisplayClient, |
| 57 public NON_EXPORTED_BASE(device::mojom::blink::VRPoseCli
ent) { |
| 45 DEFINE_WRAPPERTYPEINFO(); | 58 DEFINE_WRAPPERTYPEINFO(); |
| 46 USING_GARBAGE_COLLECTED_MIXIN(VRDisplay); | 59 USING_GARBAGE_COLLECTED_MIXIN(VRDisplay); |
| 47 USING_PRE_FINALIZER(VRDisplay, dispose); | 60 USING_PRE_FINALIZER(VRDisplay, dispose); |
| 48 | 61 |
| 49 public: | 62 public: |
| 50 ~VRDisplay(); | 63 ~VRDisplay(); |
| 51 | 64 |
| 52 unsigned displayId() const { return m_displayId; } | 65 unsigned displayId() const { return m_displayId; } |
| 53 const String& displayName() const { return m_displayName; } | 66 const String& displayName() const { return m_displayName; } |
| 54 | 67 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 double depthNear() const { return m_depthNear; } | 78 double depthNear() const { return m_depthNear; } |
| 66 double depthFar() const { return m_depthFar; } | 79 double depthFar() const { return m_depthFar; } |
| 67 | 80 |
| 68 void setDepthNear(double value) { m_depthNear = value; } | 81 void setDepthNear(double value) { m_depthNear = value; } |
| 69 void setDepthFar(double value) { m_depthFar = value; } | 82 void setDepthFar(double value) { m_depthFar = value; } |
| 70 | 83 |
| 71 VREyeParameters* getEyeParameters(const String&); | 84 VREyeParameters* getEyeParameters(const String&); |
| 72 | 85 |
| 73 int requestAnimationFrame(FrameRequestCallback*); | 86 int requestAnimationFrame(FrameRequestCallback*); |
| 74 void cancelAnimationFrame(int id); | 87 void cancelAnimationFrame(int id); |
| 75 void serviceScriptedAnimations(double monotonicAnimationStartTime); | 88 void frameTick(double highResTimeMs); |
| 89 void serviceScriptedAnimations(); |
| 90 void rescheduleAtNextTick(); |
| 76 | 91 |
| 77 ScriptPromise requestPresent(ScriptState*, const HeapVector<VRLayer>& layers); | 92 ScriptPromise requestPresent(ScriptState*, const HeapVector<VRLayer>& layers); |
| 78 ScriptPromise exitPresent(ScriptState*); | 93 ScriptPromise exitPresent(ScriptState*); |
| 79 | 94 |
| 80 HeapVector<VRLayer> getLayers(); | 95 HeapVector<VRLayer> getLayers(); |
| 81 | 96 |
| 82 void submitFrame(); | 97 void submitFrame(); |
| 83 | 98 |
| 84 Document* document(); | 99 Document* document(); |
| 85 | 100 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 void update(const device::mojom::blink::VRDisplayInfoPtr&); | 120 void update(const device::mojom::blink::VRDisplayInfoPtr&); |
| 106 | 121 |
| 107 void updatePose(); | 122 void updatePose(); |
| 108 | 123 |
| 109 void beginPresent(); | 124 void beginPresent(); |
| 110 void forceExitPresent(); | 125 void forceExitPresent(); |
| 111 | 126 |
| 112 void updateLayerBounds(); | 127 void updateLayerBounds(); |
| 113 void disconnected(); | 128 void disconnected(); |
| 114 | 129 |
| 130 gpu::gles2::GLES2Interface* getCompositingContext(); |
| 131 |
| 115 VRController* controller(); | 132 VRController* controller(); |
| 116 | 133 |
| 117 private: | 134 private: |
| 118 void onFullscreenCheck(TimerBase*); | 135 void submitFrameAnyContext(); |
| 136 |
| 119 void onPresentComplete(bool); | 137 void onPresentComplete(bool); |
| 138 void onSubmitFrameComplete(int32_t surfaceHandle, uint32_t poseIndex, double r
enderMs); |
| 139 void onGetSurfaceHandleComplete(int32_t surfaceHandle); |
| 140 |
| 141 void requestPose(); |
| 142 void onPoseReceived(device::mojom::blink::VRPosePtr); |
| 120 | 143 |
| 121 void onConnected(); | 144 void onConnected(); |
| 122 void onDisconnected(); | 145 void onDisconnected(); |
| 123 | 146 |
| 124 void OnPresentChange(); | 147 void OnPresentChange(); |
| 125 | 148 |
| 149 // VRPoseClient |
| 150 void OnPoseReceived(device::mojom::blink::VRPosePtr pose) override; |
| 151 |
| 126 // VRDisplayClient | 152 // VRDisplayClient |
| 127 void OnChanged(device::mojom::blink::VRDisplayInfoPtr) override; | 153 void OnChanged(device::mojom::blink::VRDisplayInfoPtr) override; |
| 128 void OnExitPresent() override; | 154 void OnExitPresent() override; |
| 129 void OnBlur() override; | 155 void OnBlur() override; |
| 130 void OnFocus() override; | 156 void OnFocus() override; |
| 131 void OnActivate(device::mojom::blink::VRDisplayEventReason) override; | 157 void OnActivate(device::mojom::blink::VRDisplayEventReason) override; |
| 132 void OnDeactivate(device::mojom::blink::VRDisplayEventReason) override; | 158 void OnDeactivate(device::mojom::blink::VRDisplayEventReason) override; |
| 133 | 159 |
| 134 ScriptedAnimationController& ensureScriptedAnimationController(Document*); | 160 ScriptedAnimationController& ensureScriptedAnimationController(Document*); |
| 135 | 161 |
| 136 Member<NavigatorVR> m_navigatorVR; | 162 Member<NavigatorVR> m_navigatorVR; |
| 137 unsigned m_displayId; | 163 unsigned m_displayId; |
| 138 String m_displayName; | 164 String m_displayName; |
| 139 bool m_isConnected; | 165 bool m_isConnected; |
| 140 bool m_isPresenting; | 166 bool m_isPresenting; |
| 141 bool m_isValidDeviceForPresenting; | 167 bool m_isValidDeviceForPresenting; |
| 168 |
| 169 double m_highResTimeMsAtLastFrameTick; |
| 170 double m_frameTickStartMs; |
| 171 double m_serviceStartMs; |
| 172 double m_submitExecuteMs; |
| 173 bool m_tickIsScheduled = false; |
| 174 |
| 175 // Track "pending submitted frames" counter for the current output |
| 176 // surface. Always zero while not submitting frames. Must only be |
| 177 // changed when submitting frames to a valid surface and on its |
| 178 // return callback if it still matches the current surface. We allow |
| 179 // rAF processing to start if one frame is pending in post-submit, |
| 180 // but if it's still nonzero when trying to submit a frame we defer |
| 181 // that until the previous in-flight frame is done. |
| 182 int m_framesPending; |
| 183 bool m_frameWaitingToSubmit = false; |
| 184 StatTracker m_historyPreSubmitTimeMs{7}; |
| 185 StatTracker m_historyPostSubmitTimeMs{7}; |
| 186 |
| 187 bool m_poseCallbackPending = false; |
| 142 bool m_canUpdateFramePose; | 188 bool m_canUpdateFramePose; |
| 189 bool m_canSubmitFramePose; |
| 143 Member<VRDisplayCapabilities> m_capabilities; | 190 Member<VRDisplayCapabilities> m_capabilities; |
| 144 Member<VRStageParameters> m_stageParameters; | 191 Member<VRStageParameters> m_stageParameters; |
| 145 Member<VREyeParameters> m_eyeParametersLeft; | 192 Member<VREyeParameters> m_eyeParametersLeft; |
| 146 Member<VREyeParameters> m_eyeParametersRight; | 193 Member<VREyeParameters> m_eyeParametersRight; |
| 147 device::mojom::blink::VRPosePtr m_framePose; | 194 device::mojom::blink::VRPosePtr m_framePose; |
| 148 VRLayer m_layer; | 195 VRLayer m_layer; |
| 196 int m_sourceWidth; |
| 197 int m_sourceHeight; |
| 149 double m_depthNear; | 198 double m_depthNear; |
| 150 double m_depthFar; | 199 double m_depthFar; |
| 151 | 200 |
| 152 void dispose(); | 201 void dispose(); |
| 153 | 202 |
| 154 Timer<VRDisplay> m_fullscreenCheckTimer; | |
| 155 String m_fullscreenOrigWidth; | |
| 156 String m_fullscreenOrigHeight; | |
| 157 gpu::gles2::GLES2Interface* m_contextGL; | 203 gpu::gles2::GLES2Interface* m_contextGL; |
| 158 Member<WebGLRenderingContextBase> m_renderingContext; | 204 Member<WebGLRenderingContextBase> m_renderingContext; |
| 159 | 205 |
| 160 Member<ScriptedAnimationController> m_scriptedAnimationController; | 206 Member<ScriptedAnimationController> m_scriptedAnimationController; |
| 161 bool m_animationCallbackRequested; | 207 bool m_animationCallbackRequested; |
| 162 bool m_inAnimationFrame; | 208 bool m_inAnimationFrame; |
| 163 bool m_displayBlurred; | 209 bool m_displayBlurred; |
| 164 bool m_reenteredFullscreen; | 210 bool m_reenteredFullscreen; |
| 165 | 211 |
| 212 int32_t m_surfaceHandle; |
| 213 bool m_surfaceHandleRequested = false; |
| 214 |
| 166 device::mojom::blink::VRDisplayPtr m_display; | 215 device::mojom::blink::VRDisplayPtr m_display; |
| 167 | 216 |
| 168 mojo::Binding<device::mojom::blink::VRDisplayClient> m_binding; | 217 mojo::Binding<device::mojom::blink::VRDisplayClient> m_binding; |
| 218 mojo::Binding<device::mojom::blink::VRPoseClient> m_pose_client_binding; |
| 169 | 219 |
| 170 HeapDeque<Member<ScriptPromiseResolver>> m_pendingPresentResolvers; | 220 HeapDeque<Member<ScriptPromiseResolver>> m_pendingPresentResolvers; |
| 221 |
| 222 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; |
| 171 }; | 223 }; |
| 172 | 224 |
| 173 using VRDisplayVector = HeapVector<Member<VRDisplay>>; | 225 using VRDisplayVector = HeapVector<Member<VRDisplay>>; |
| 174 | 226 |
| 175 enum class PresentationResult { | 227 enum class PresentationResult { |
| 176 Requested = 0, | 228 Requested = 0, |
| 177 Success = 1, | 229 Success = 1, |
| 178 SuccessAlreadyPresenting = 2, | 230 SuccessAlreadyPresenting = 2, |
| 179 VRDisplayCannotPresent = 3, | 231 VRDisplayCannotPresent = 3, |
| 180 PresentationNotSupportedByDisplay = 4, | 232 PresentationNotSupportedByDisplay = 4, |
| 181 VRDisplayNotFound = 5, | 233 VRDisplayNotFound = 5, |
| 182 NotInitiatedByUserGesture = 6, | 234 NotInitiatedByUserGesture = 6, |
| 183 InvalidNumberOfLayers = 7, | 235 InvalidNumberOfLayers = 7, |
| 184 InvalidLayerSource = 8, | 236 InvalidLayerSource = 8, |
| 185 LayerSourceMissingWebGLContext = 9, | 237 LayerSourceMissingWebGLContext = 9, |
| 186 InvalidLayerBounds = 10, | 238 InvalidLayerBounds = 10, |
| 187 ServiceInactive = 11, | 239 ServiceInactive = 11, |
| 188 RequestDenied = 12, | 240 RequestDenied = 12, |
| 189 PresentationResultMax, // Must be last member of enum. | 241 PresentationResultMax, // Must be last member of enum. |
| 190 }; | 242 }; |
| 191 | 243 |
| 192 void ReportPresentationResult(PresentationResult); | 244 void ReportPresentationResult(PresentationResult); |
| 193 | 245 |
| 194 } // namespace blink | 246 } // namespace blink |
| 195 | 247 |
| 196 #endif // VRDisplay_h | 248 #endif // VRDisplay_h |
| OLD | NEW |