| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_service_impl.h" | 5 #include "device/vr/vr_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "device/vr/vr_device.h" | 10 #include "device/vr/vr_device.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 service->Bind(std::move(request)); | 23 service->Bind(std::move(request)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) { | 26 void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) { |
| 27 binding_.reset(new mojo::Binding<VRService>(this, std::move(request))); | 27 binding_.reset(new mojo::Binding<VRService>(this, std::move(request))); |
| 28 binding_->set_connection_error_handler(base::Bind( | 28 binding_->set_connection_error_handler(base::Bind( |
| 29 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); | 29 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void VRServiceImpl::RemoveFromDeviceManager() { | 32 void VRServiceImpl::RemoveFromDeviceManager() { |
| 33 device_client_impl_.clear(); |
| 33 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 34 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| 34 device_manager->RemoveService(this); | 35 device_manager->RemoveService(this); |
| 35 } | 36 } |
| 36 | 37 |
| 38 void VRServiceImpl::RemoveDeviceClientImpl(VRDevice* device) { |
| 39 device_client_impl_.erase(device); |
| 40 } |
| 41 |
| 42 VRDeviceClientPtr VRServiceImpl::GetDeviceServicePtr(VRDevice* device) { |
| 43 if (device_client_impl_.find(device) == device_client_impl_.end()) { |
| 44 VRDeviceClientPtr deviceClient; |
| 45 |
| 46 device_client_impl_[device] = std::unique_ptr<VRDeviceClientImpl>( |
| 47 new VRDeviceClientImpl(GetProxy(&deviceClient), device, this)); |
| 48 |
| 49 return std::move(deviceClient); |
| 50 } |
| 51 |
| 52 return nullptr; |
| 53 } |
| 54 |
| 55 void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) { |
| 56 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| 57 callback.Run(device_manager->GetVRDevices(this)); |
| 58 } |
| 59 |
| 37 void VRServiceImpl::SetClient(VRServiceClientPtr client) { | 60 void VRServiceImpl::SetClient(VRServiceClientPtr client) { |
| 38 DCHECK(!client_.get()); | 61 DCHECK(!client_.get()); |
| 39 | 62 |
| 40 client_ = std::move(client); | 63 client_ = std::move(client); |
| 41 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 64 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); |
| 42 device_manager->AddService(this); | 65 device_manager->AddService(this); |
| 43 } | 66 } |
| 44 | 67 |
| 45 void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) { | 68 VRDisplayClientPtr VRServiceImpl::GetDisplayClient() { |
| 46 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | 69 DCHECK(client_); |
| 47 callback.Run(device_manager->GetVRDevices()); | |
| 48 } | |
| 49 | 70 |
| 50 void VRServiceImpl::GetPose(uint32_t index, const GetPoseCallback& callback) { | 71 VRDisplayClientPtr display_client; |
| 51 VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); | 72 client_->GetDisplayClient(&display_client); |
| 52 | 73 return std::move(display_client); |
| 53 if (device) { | |
| 54 callback.Run(device->GetPose()); | |
| 55 } else { | |
| 56 callback.Run(nullptr); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void VRServiceImpl::ResetPose(uint32_t index) { | |
| 61 VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); | |
| 62 if (device) | |
| 63 device->ResetPose(); | |
| 64 } | |
| 65 | |
| 66 void VRServiceImpl::RequestPresent(uint32_t index, | |
| 67 bool secureOrigin, | |
| 68 const RequestPresentCallback& callback) { | |
| 69 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | |
| 70 callback.Run(device_manager->RequestPresent(this, index, secureOrigin)); | |
| 71 } | |
| 72 | |
| 73 void VRServiceImpl::ExitPresent(uint32_t index) { | |
| 74 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | |
| 75 device_manager->ExitPresent(this, index); | |
| 76 } | |
| 77 | |
| 78 void VRServiceImpl::SubmitFrame(uint32_t index, VRPosePtr pose) { | |
| 79 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); | |
| 80 device_manager->SubmitFrame(this, index, std::move(pose)); | |
| 81 } | |
| 82 | |
| 83 void VRServiceImpl::UpdateLayerBounds(uint32_t index, | |
| 84 VRLayerBoundsPtr leftBounds, | |
| 85 VRLayerBoundsPtr rightBounds) { | |
| 86 VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index); | |
| 87 if (device) | |
| 88 device->UpdateLayerBounds(std::move(leftBounds), std::move(rightBounds)); | |
| 89 } | 74 } |
| 90 | 75 |
| 91 } // namespace device | 76 } // namespace device |
| OLD | NEW |