| 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 | 8 |
| 8 namespace device { | 9 namespace device { |
| 9 | 10 |
| 10 unsigned int VRDevice::next_id_ = 1; | 11 unsigned int VRDevice::next_id_ = 1; |
| 11 | 12 |
| 12 VRDevice::VRDevice(VRDeviceProvider* provider) | 13 VRDevice::VRDevice(VRDeviceProvider* provider) |
| 13 : provider_(provider), id_(next_id_) { | 14 : presenting_service_(nullptr), provider_(provider), id_(next_id_) { |
| 14 // Prevent wraparound. Devices with this ID will be treated as invalid. | 15 // Prevent wraparound. Devices with this ID will be treated as invalid. |
| 15 if (next_id_ != VR_DEVICE_LAST_ID) | 16 if (next_id_ != VR_DEVICE_LAST_ID) |
| 16 next_id_++; | 17 next_id_++; |
| 17 } | 18 } |
| 18 | 19 |
| 19 VRDevice::~VRDevice() {} | 20 VRDevice::~VRDevice() {} |
| 20 | 21 |
| 21 bool VRDevice::RequestPresent(bool secure_origin) { | 22 bool VRDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { |
| 22 return true; | 23 return true; |
| 23 }; | 24 }; |
| 24 | 25 |
| 26 void VRDevice::AddService(VRServiceImpl* service) { |
| 27 // Create a VRDisplayImpl for this service/device pair |
| 28 VRDisplayImpl* display_impl = service->GetVRDisplayImpl(this); |
| 29 displays_.insert(std::make_pair(service, display_impl)); |
| 30 } |
| 31 |
| 32 void VRDevice::RemoveService(VRServiceImpl* service) { |
| 33 ExitPresent(service); |
| 34 displays_.erase(service); |
| 35 } |
| 36 |
| 37 bool VRDevice::IsAccessAllowed(VRServiceImpl* service) { |
| 38 return (!presenting_service_ || presenting_service_ == service); |
| 39 } |
| 40 |
| 41 bool VRDevice::IsPresentingService(VRServiceImpl* service) { |
| 42 return (presenting_service_ && presenting_service_ == service); |
| 43 } |
| 44 |
| 45 void VRDevice::OnDisplayChanged() { |
| 46 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice(); |
| 47 if (vr_device_info.is_null()) |
| 48 return; |
| 49 |
| 50 for (const auto& display : displays_) { |
| 51 mojom::VRDisplayClient* client = display.second->client(); |
| 52 if (client) |
| 53 client->OnDisplayChanged(vr_device_info.Clone()); |
| 54 } |
| 55 } |
| 56 |
| 57 void VRDevice::OnExitPresent(VRServiceImpl* service) { |
| 58 DisplayClientMap::iterator it = displays_.find(service); |
| 59 if (it != displays_.end()) { |
| 60 mojom::VRDisplayClient* client = it->second->client(); |
| 61 if (client) |
| 62 client->OnExitPresent(); |
| 63 } |
| 64 } |
| 65 |
| 25 } // namespace device | 66 } // namespace device |
| OLD | NEW |