| 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_display_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_display_(nullptr), id_(next_id_) { | 13 VRDevice::VRDevice() |
| 14 : presenting_display_(nullptr), id_(next_id_), weak_ptr_factory_(this) { |
| 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 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) { | 22 void VRDevice::RequestPresent(const base::Callback<void(bool)>& callback) { |
| 22 callback.Run(true); | 23 callback.Run(true); |
| 23 } | 24 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 bool VRDevice::IsAccessAllowed(VRDisplayImpl* display) { | 38 bool VRDevice::IsAccessAllowed(VRDisplayImpl* display) { |
| 38 return (!presenting_display_ || presenting_display_ == display); | 39 return (!presenting_display_ || presenting_display_ == display); |
| 39 } | 40 } |
| 40 | 41 |
| 41 bool VRDevice::CheckPresentingDisplay(VRDisplayImpl* display) { | 42 bool VRDevice::CheckPresentingDisplay(VRDisplayImpl* display) { |
| 42 return (presenting_display_ && presenting_display_ == display); | 43 return (presenting_display_ && presenting_display_ == display); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void VRDevice::OnChanged() { | 46 void VRDevice::OnChanged() { |
| 46 mojom::VRDisplayInfoPtr vr_device_info = GetVRDevice(); | 47 base::Callback<void(mojom::VRDisplayInfoPtr)> callback = base::Bind( |
| 48 &VRDevice::OnVRDisplayInfoCreated, weak_ptr_factory_.GetWeakPtr()); |
| 49 GetVRDevice(callback); |
| 50 } |
| 51 |
| 52 void VRDevice::OnVRDisplayInfoCreated(mojom::VRDisplayInfoPtr vr_device_info) { |
| 47 if (vr_device_info.is_null()) | 53 if (vr_device_info.is_null()) |
| 48 return; | 54 return; |
| 49 | |
| 50 for (const auto& display : displays_) | 55 for (const auto& display : displays_) |
| 51 display->client()->OnChanged(vr_device_info.Clone()); | 56 display->client()->OnChanged(vr_device_info.Clone()); |
| 52 } | 57 } |
| 53 | 58 |
| 54 void VRDevice::OnExitPresent() { | 59 void VRDevice::OnExitPresent() { |
| 60 if (!presenting_display_) |
| 61 return; |
| 55 auto it = displays_.find(presenting_display_); | 62 auto it = displays_.find(presenting_display_); |
| 56 if (it != displays_.end()) | 63 CHECK(it != displays_.end()); |
| 57 (*it)->client()->OnExitPresent(); | 64 (*it)->client()->OnExitPresent(); |
| 58 | |
| 59 SetPresentingDisplay(nullptr); | 65 SetPresentingDisplay(nullptr); |
| 60 } | 66 } |
| 61 | 67 |
| 62 void VRDevice::OnBlur() { | 68 void VRDevice::OnBlur() { |
| 63 for (const auto& display : displays_) | 69 for (const auto& display : displays_) |
| 64 display->client()->OnBlur(); | 70 display->client()->OnBlur(); |
| 65 } | 71 } |
| 66 | 72 |
| 67 void VRDevice::OnFocus() { | 73 void VRDevice::OnFocus() { |
| 68 for (const auto& display : displays_) | 74 for (const auto& display : displays_) |
| 69 display->client()->OnFocus(); | 75 display->client()->OnFocus(); |
| 70 } | 76 } |
| 71 | 77 |
| 72 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) { | 78 void VRDevice::OnActivate(mojom::VRDisplayEventReason reason) { |
| 73 for (const auto& display : displays_) | 79 for (const auto& display : displays_) |
| 74 display->client()->OnActivate(reason); | 80 display->client()->OnActivate(reason); |
| 75 } | 81 } |
| 76 | 82 |
| 77 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) { | 83 void VRDevice::OnDeactivate(mojom::VRDisplayEventReason reason) { |
| 78 for (const auto& display : displays_) | 84 for (const auto& display : displays_) |
| 79 display->client()->OnDeactivate(reason); | 85 display->client()->OnDeactivate(reason); |
| 80 } | 86 } |
| 81 | 87 |
| 82 void VRDevice::SetPresentingDisplay(VRDisplayImpl* display) { | 88 void VRDevice::SetPresentingDisplay(VRDisplayImpl* display) { |
| 83 presenting_display_ = display; | 89 presenting_display_ = display; |
| 84 } | 90 } |
| 85 | 91 |
| 86 } // namespace device | 92 } // namespace device |
| OLD | NEW |