| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "device/vr/vr_device.h" | 8 #include "device/vr/vr_device.h" |
| 9 #include "device/vr/vr_service_impl.h" | 9 #include "device/vr/vr_service_impl.h" |
| 10 | 10 |
| 11 namespace device { | 11 namespace device { |
| 12 | 12 |
| 13 VRDisplayImpl::VRDisplayImpl(device::VRDevice* device, VRServiceImpl* service) | 13 VRDisplayImpl::VRDisplayImpl(device::VRDevice* device, VRServiceImpl* service) |
| 14 : binding_(this), device_(device), service_(service) { | 14 : binding_(this), device_(device), service_(service) { |
| 15 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); | 15 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); |
| 16 // Client might be null in unittest. | 16 // Client might be null in unittest. |
| 17 // TODO: setup a mock client in unittest too? | 17 // TODO: setup a mock client in unittest too? |
| 18 if (service->client()) { | 18 if (service->client()) { |
| 19 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), | 19 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), |
| 20 mojo::GetProxy(&client_), | 20 mojo::GetProxy(&client_), |
| 21 std::move(display_info)); | 21 std::move(display_info)); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 VRDisplayImpl::~VRDisplayImpl() {} | 25 VRDisplayImpl::~VRDisplayImpl() {} |
| 26 | 26 |
| 27 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { | 27 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { |
| 28 if (!device_->IsAccessAllowed(service_.get())) { | 28 if (!device_->IsAccessAllowed(service_)) { |
| 29 callback.Run(nullptr); | 29 callback.Run(nullptr); |
| 30 return; | 30 return; |
| 31 } | 31 } |
| 32 | 32 |
| 33 callback.Run(device_->GetPose()); | 33 callback.Run(device_->GetPose()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void VRDisplayImpl::ResetPose() { | 36 void VRDisplayImpl::ResetPose() { |
| 37 if (!device_->IsAccessAllowed(service_.get())) | 37 if (!device_->IsAccessAllowed(service_)) |
| 38 return; | 38 return; |
| 39 | 39 |
| 40 device_->ResetPose(); | 40 device_->ResetPose(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void VRDisplayImpl::RequestPresent(bool secureOrigin, | 43 void VRDisplayImpl::RequestPresent(bool secureOrigin, |
| 44 const RequestPresentCallback& callback) { | 44 const RequestPresentCallback& callback) { |
| 45 if (!device_->IsAccessAllowed(service_.get())) { | 45 if (!device_->IsAccessAllowed(service_)) { |
| 46 callback.Run(false); | 46 callback.Run(false); |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool success = device_->RequestPresent(secureOrigin); | 50 bool success = device_->RequestPresent(secureOrigin); |
| 51 if (success) { | 51 if (success) { |
| 52 device_->SetPresentingService(service_.get()); | 52 device_->SetPresentingService(service_); |
| 53 } | 53 } |
| 54 callback.Run(success); | 54 callback.Run(success); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void VRDisplayImpl::ExitPresent() { | 57 void VRDisplayImpl::ExitPresent() { |
| 58 if (device_->IsPresentingService(service_.get())) | 58 if (device_->IsPresentingService(service_)) |
| 59 device_->ExitPresent(); | 59 device_->ExitPresent(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { | 62 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { |
| 63 if (!device_->IsPresentingService(service_.get())) | 63 if (!device_->IsPresentingService(service_)) |
| 64 return; | 64 return; |
| 65 device_->SubmitFrame(std::move(pose)); | 65 device_->SubmitFrame(std::move(pose)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds, | 68 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds, |
| 69 mojom::VRLayerBoundsPtr right_bounds) { | 69 mojom::VRLayerBoundsPtr right_bounds) { |
| 70 if (!device_->IsAccessAllowed(service_.get())) | 70 if (!device_->IsAccessAllowed(service_)) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds)); | 73 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds)); |
| 74 } | 74 } |
| 75 } | 75 } |
| OLD | NEW |