| 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" | |
| 8 | 7 |
| 9 namespace device { | 8 namespace device { |
| 10 | 9 |
| 11 unsigned int VRDevice::next_id_ = 1; | 10 unsigned int VRDevice::next_id_ = 1; |
| 12 | 11 |
| 13 VRDevice::VRDevice(VRDeviceProvider* provider) | 12 VRDevice::VRDevice(VRDeviceProvider* provider) |
| 14 : presenting_service_(nullptr), provider_(provider), id_(next_id_) { | 13 : provider_(provider), id_(next_id_) { |
| 15 // Prevent wraparound. Devices with this ID will be treated as invalid. | 14 // Prevent wraparound. Devices with this ID will be treated as invalid. |
| 16 if (next_id_ != VR_DEVICE_LAST_ID) | 15 if (next_id_ != VR_DEVICE_LAST_ID) |
| 17 next_id_++; | 16 next_id_++; |
| 18 } | 17 } |
| 19 | 18 |
| 20 VRDevice::~VRDevice() {} | 19 VRDevice::~VRDevice() {} |
| 21 | 20 |
| 22 bool VRDevice::RequestPresent(VRServiceImpl* service, bool secure_origin) { | 21 bool VRDevice::RequestPresent(bool secure_origin) { |
| 23 return true; | 22 return true; |
| 24 }; | 23 }; |
| 25 | 24 |
| 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 | |
| 66 } // namespace device | 25 } // namespace device |
| OLD | NEW |