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 "device/vr/vr_device.h" | 5 #include "device/vr/vr_device.h" |
6 #include "device/vr/vr_device_provider.h" | 6 #include "device/vr/vr_device_provider.h" |
7 #include "device/vr/vr_service_impl.h" | 7 #include "device/vr/vr_display_impl.h" |
8 | 8 |
9 namespace device { | 9 namespace device { |
10 | 10 |
11 unsigned int VRDevice::next_id_ = 1; | 11 unsigned int VRDevice::next_id_ = 1; |
12 | 12 |
13 VRDevice::VRDevice() : presenting_service_(nullptr), id_(next_id_) { | 13 VRDevice::VRDevice() : presenting_display_(nullptr), id_(next_id_) { |
14 // Prevent wraparound. Devices with this ID will be treated as invalid. | 14 // Prevent wraparound. Devices with this ID will be treated as invalid. |
15 if (next_id_ != VR_DEVICE_LAST_ID) | 15 if (next_id_ != VR_DEVICE_LAST_ID) |
16 next_id_++; | 16 next_id_++; |
17 } | 17 } |
18 | 18 |
19 VRDevice::~VRDevice() {} | 19 VRDevice::~VRDevice() {} |
20 | 20 |
21 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) { | 21 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) { |
22 callback.Run(true); | 22 callback.Run(true); |
23 } | 23 } |
24 | 24 |
25 void VRDevice::SetSecureOrigin(bool secure_origin) {} | 25 void VRDevice::SetSecureOrigin(bool secure_origin) {} |
26 | 26 |
27 void VRDevice::AddService(VRServiceImpl* service) { | 27 void VRDevice::AddDisplay(VRDisplayImpl* display) { |
28 // Create a VRDisplayImpl for this service/device pair | 28 displays_.push_back(display); |
29 VRDisplayImpl* display_impl = service->GetVRDisplayImpl(this); | |
30 displays_.insert(std::make_pair(service, display_impl)); | |
31 } | 29 } |
32 | 30 |
33 void VRDevice::RemoveService(VRServiceImpl* service) { | 31 void VRDevice::RemoveDisplay(VRDisplayImpl* display) { |
34 if (IsPresentingService(service)) | 32 if (CheckPresentingDisplay(display)) |
35 ExitPresent(); | 33 ExitPresent(); |
36 displays_.erase(service); | 34 displays_.erase(std::remove(displays_.begin(), displays_.end(), display), |
mthiesse
2016/11/29 16:35:13
Why is this necessary? Do we expect the same displ
shaobo.yan
2016/11/30 02:54:42
Done.
| |
35 displays_.end()); | |
37 } | 36 } |
38 | 37 |
39 bool VRDevice::IsAccessAllowed(VRServiceImpl* service) { | 38 bool VRDevice::IsAccessAllowed(VRDisplayImpl* display) { |
40 return (!presenting_service_ || presenting_service_ == service); | 39 return (!presenting_display_ || presenting_display_ == display); |
41 } | 40 } |
42 | 41 |
43 bool VRDevice::IsPresentingService(VRServiceImpl* service) { | 42 bool VRDevice::CheckPresentingDisplay(VRDisplayImpl* display) { |
44 return (presenting_service_ && presenting_service_ == service); | 43 return (presenting_display_ && presenting_display_ == display); |
45 } | 44 } |
46 | 45 |
47 void VRDevice::OnChanged() { | 46 void VRDevice::OnChanged() { |
48 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice(); | 47 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice(); |
49 if (vr_device_info.is_null()) | 48 if (vr_device_info.is_null()) |
50 return; | 49 return; |
51 | 50 |
52 for (const auto& display : displays_) | 51 for (const auto& display : displays_) |
53 display.second->client()->OnChanged(vr_device_info.Clone()); | 52 display->client()->OnChanged(vr_device_info.Clone()); |
54 } | 53 } |
55 | 54 |
56 void VRDevice::OnExitPresent() { | 55 void VRDevice::OnExitPresent() { |
57 DisplayClientMap::iterator it = displays_.find(presenting_service_); | 56 DisplayList::iterator it = |
57 std::find(displays_.begin(), displays_.end(), presenting_display_); | |
58 if (it != displays_.end()) | 58 if (it != displays_.end()) |
59 it->second->client()->OnExitPresent(); | 59 (*it)->client()->OnExitPresent(); |
60 | 60 |
61 SetPresentingService(nullptr); | 61 SetPresentingDisplay(nullptr); |
62 } | 62 } |
63 | 63 |
64 void VRDevice::OnBlur() { | 64 void VRDevice::OnBlur() { |
65 for (const auto& display : displays_) | 65 for (const auto& display : displays_) |
66 display.second->client()->OnBlur(); | 66 display->client()->OnBlur(); |
67 } | 67 } |
68 | 68 |
69 void VRDevice::OnFocus() { | 69 void VRDevice::OnFocus() { |
70 for (const auto& display : displays_) | 70 for (const auto& display : displays_) |
71 display.second->client()->OnFocus(); | 71 display->client()->OnFocus(); |
72 } | 72 } |
73 | 73 |
74 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) { | 74 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) { |
75 for (const auto& display : displays_) | 75 for (const auto& display : displays_) |
76 display.second->client()->OnActivate(reason); | 76 display->client()->OnActivate(reason); |
77 } | 77 } |
78 | 78 |
79 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) { | 79 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) { |
80 for (const auto& display : displays_) | 80 for (const auto& display : displays_) |
81 display.second->client()->OnDeactivate(reason); | 81 display->client()->OnDeactivate(reason); |
82 } | 82 } |
83 | 83 |
84 void VRDevice::SetPresentingService(VRServiceImpl* service) { | 84 void VRDevice::SetPresentingDisplay(VRDisplayImpl* display) { |
85 presenting_service_ = service; | 85 presenting_display_ = display; |
86 } | 86 } |
87 | 87 |
88 } // namespace device | 88 } // namespace device |
OLD | NEW |