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

Side by Side Diff: third_party/WebKit/Source/modules/vr/VRController.cpp

Issue 2668003003: Provide WebVR pose data only to the focused frame. (Closed)
Patch Set: Address comments Created 3 years, 10 months 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 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
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(m_focused);
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(bool focused) {
77 m_focused = focused;
78 for (const auto& display : m_displays)
79 display->focusChanged(focused);
80 }
81
75 // Called when the VRService has called OnDisplayConnected for all active 82 // Called when the VRService has called OnDisplayConnected for all active
76 // VRDisplays. 83 // VRDisplays.
77 void VRController::onDisplaysSynced(unsigned numberOfDisplays) { 84 void VRController::onDisplaysSynced(unsigned numberOfDisplays) {
78 m_numberOfSyncedDisplays = numberOfDisplays; 85 m_numberOfSyncedDisplays = numberOfDisplays;
79 if (m_numberOfSyncedDisplays == m_displays.size()) { 86 if (m_numberOfSyncedDisplays == m_displays.size()) {
80 m_displaySynced = true; 87 m_displaySynced = true;
81 onGetDisplays(); 88 onGetDisplays();
82 } 89 }
83 } 90 }
84 91
85 void VRController::onGetDisplays() { 92 void VRController::onGetDisplays() {
86 while (!m_pendingGetDevicesCallbacks.isEmpty()) { 93 while (!m_pendingGetDevicesCallbacks.isEmpty()) {
87 std::unique_ptr<VRGetDevicesCallback> callback = 94 std::unique_ptr<VRGetDevicesCallback> callback =
88 m_pendingGetDevicesCallbacks.takeFirst(); 95 m_pendingGetDevicesCallbacks.takeFirst();
89 callback->onSuccess(m_displays); 96 callback->onSuccess(m_displays);
90 } 97 }
91 } 98 }
92 99
93 void VRController::contextDestroyed(ExecutionContext*) { 100 void VRController::contextDestroyed(ExecutionContext*) {
94 dispose(); 101 dispose();
95 } 102 }
96 103
97 void VRController::dispose() { 104 void VRController::dispose() {
98 // If the document context was destroyed, shut down the client connection 105 // If the document context was destroyed, shut down the client connection
99 // and never call the mojo service again. 106 // and never call the mojo service again.
100 m_service.reset(); 107 m_service.reset();
101 m_binding.Close(); 108 m_binding.Close();
102 109
103 // Shutdown all displays' message pipe 110 // Shutdown all displays' message pipe
104 for (size_t i = 0; i < m_displays.size(); ++i) 111 for (const auto& display : m_displays)
105 m_displays[i]->dispose(); 112 display->dispose();
106 113
107 m_displays.clear(); 114 m_displays.clear();
108 115
109 // Ensure that any outstanding getDisplays promises are resolved. 116 // Ensure that any outstanding getDisplays promises are resolved.
110 onGetDisplays(); 117 onGetDisplays();
111 } 118 }
112 119
113 DEFINE_TRACE(VRController) { 120 DEFINE_TRACE(VRController) {
114 visitor->trace(m_navigatorVR); 121 visitor->trace(m_navigatorVR);
115 visitor->trace(m_displays); 122 visitor->trace(m_displays);
116 123
117 ContextLifecycleObserver::trace(visitor); 124 ContextLifecycleObserver::trace(visitor);
118 } 125 }
119 126
120 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698