| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "modules/vr/VRController.h" | 5 #include "modules/vr/VRController.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // here. Upon calling SetClient in the constructor we should receive one call | 57 // here. Upon calling SetClient in the constructor we should receive one call |
| 58 // for each VRDisplay that was already connected at the time. | 58 // for each VRDisplay that was already connected at the time. |
| 59 void VRController::OnDisplayConnected( | 59 void VRController::OnDisplayConnected( |
| 60 device::mojom::blink::VRDisplayPtr display, | 60 device::mojom::blink::VRDisplayPtr display, |
| 61 device::mojom::blink::VRDisplayClientRequest request, | 61 device::mojom::blink::VRDisplayClientRequest request, |
| 62 device::mojom::blink::VRDisplayInfoPtr displayInfo) { | 62 device::mojom::blink::VRDisplayInfoPtr displayInfo) { |
| 63 VRDisplay* vrDisplay = | 63 VRDisplay* vrDisplay = |
| 64 new VRDisplay(m_navigatorVR, std::move(display), std::move(request)); | 64 new VRDisplay(m_navigatorVR, std::move(display), std::move(request)); |
| 65 vrDisplay->update(displayInfo); | 65 vrDisplay->update(displayInfo); |
| 66 vrDisplay->onConnected(); | 66 vrDisplay->onConnected(); |
| 67 vrDisplay->focusChanged(); |
| 67 m_displays.push_back(vrDisplay); | 68 m_displays.push_back(vrDisplay); |
| 68 | 69 |
| 69 if (m_displays.size() == m_numberOfSyncedDisplays) { | 70 if (m_displays.size() == m_numberOfSyncedDisplays) { |
| 70 m_displaySynced = true; | 71 m_displaySynced = true; |
| 71 onGetDisplays(); | 72 onGetDisplays(); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 | 75 |
| 76 void VRController::focusChanged() { |
| 77 for (const auto& display : m_displays) |
| 78 display->focusChanged(); |
| 79 } |
| 80 |
| 75 // Called when the VRService has called OnDisplayConnected for all active | 81 // Called when the VRService has called OnDisplayConnected for all active |
| 76 // VRDisplays. | 82 // VRDisplays. |
| 77 void VRController::onDisplaysSynced(unsigned numberOfDisplays) { | 83 void VRController::onDisplaysSynced(unsigned numberOfDisplays) { |
| 78 m_numberOfSyncedDisplays = numberOfDisplays; | 84 m_numberOfSyncedDisplays = numberOfDisplays; |
| 79 if (m_numberOfSyncedDisplays == m_displays.size()) { | 85 if (m_numberOfSyncedDisplays == m_displays.size()) { |
| 80 m_displaySynced = true; | 86 m_displaySynced = true; |
| 81 onGetDisplays(); | 87 onGetDisplays(); |
| 82 } | 88 } |
| 83 } | 89 } |
| 84 | 90 |
| 85 void VRController::onGetDisplays() { | 91 void VRController::onGetDisplays() { |
| 86 while (!m_pendingGetDevicesCallbacks.isEmpty()) { | 92 while (!m_pendingGetDevicesCallbacks.isEmpty()) { |
| 87 std::unique_ptr<VRGetDevicesCallback> callback = | 93 std::unique_ptr<VRGetDevicesCallback> callback = |
| 88 m_pendingGetDevicesCallbacks.takeFirst(); | 94 m_pendingGetDevicesCallbacks.takeFirst(); |
| 89 callback->onSuccess(m_displays); | 95 callback->onSuccess(m_displays); |
| 90 } | 96 } |
| 91 } | 97 } |
| 92 | 98 |
| 93 void VRController::contextDestroyed(ExecutionContext*) { | 99 void VRController::contextDestroyed(ExecutionContext*) { |
| 94 dispose(); | 100 dispose(); |
| 95 } | 101 } |
| 96 | 102 |
| 97 void VRController::dispose() { | 103 void VRController::dispose() { |
| 98 // If the document context was destroyed, shut down the client connection | 104 // If the document context was destroyed, shut down the client connection |
| 99 // and never call the mojo service again. | 105 // and never call the mojo service again. |
| 100 m_service.reset(); | 106 m_service.reset(); |
| 101 m_binding.Close(); | 107 m_binding.Close(); |
| 102 | 108 |
| 103 // Shutdown all displays' message pipe | 109 // Shutdown all displays' message pipe |
| 104 for (size_t i = 0; i < m_displays.size(); ++i) | 110 for (const auto& display : m_displays) |
| 105 m_displays[i]->dispose(); | 111 display->dispose(); |
| 106 | 112 |
| 107 m_displays.clear(); | 113 m_displays.clear(); |
| 108 | 114 |
| 109 // Ensure that any outstanding getDisplays promises are resolved. | 115 // Ensure that any outstanding getDisplays promises are resolved. |
| 110 onGetDisplays(); | 116 onGetDisplays(); |
| 111 } | 117 } |
| 112 | 118 |
| 113 DEFINE_TRACE(VRController) { | 119 DEFINE_TRACE(VRController) { |
| 114 visitor->trace(m_navigatorVR); | 120 visitor->trace(m_navigatorVR); |
| 115 visitor->trace(m_displays); | 121 visitor->trace(m_displays); |
| 116 | 122 |
| 117 ContextLifecycleObserver::trace(visitor); | 123 ContextLifecycleObserver::trace(visitor); |
| 118 } | 124 } |
| 119 | 125 |
| 120 } // namespace blink | 126 } // namespace blink |
| OLD | NEW |