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), | 14 : binding_(this), |
15 device_(device), | 15 device_(device), |
16 service_(service), | 16 service_(service), |
17 weak_ptr_factory_(this) { | 17 weak_ptr_factory_(this) { |
18 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); | 18 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); |
19 // Client might be null in unittest. | |
20 // TODO: setup a mock client in unittest too? | |
21 if (service->client()) { | 19 if (service->client()) { |
22 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), | 20 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), |
23 mojo::GetProxy(&client_), | 21 mojo::GetProxy(&client_), |
24 std::move(display_info)); | 22 std::move(display_info)); |
25 } | 23 } |
26 } | 24 } |
27 | 25 |
28 VRDisplayImpl::~VRDisplayImpl() {} | 26 VRDisplayImpl::~VRDisplayImpl() {} |
29 | 27 |
30 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { | 28 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { |
31 if (!device_->IsAccessAllowed(service_)) { | 29 if (!device_->IsAccessAllowed(this)) { |
32 callback.Run(nullptr); | 30 callback.Run(nullptr); |
33 return; | 31 return; |
34 } | 32 } |
35 | 33 |
36 callback.Run(device_->GetPose()); | 34 callback.Run(device_->GetPose()); |
37 } | 35 } |
38 | 36 |
39 void VRDisplayImpl::ResetPose() { | 37 void VRDisplayImpl::ResetPose() { |
40 if (!device_->IsAccessAllowed(service_)) | 38 if (!device_->IsAccessAllowed(this)) |
41 return; | 39 return; |
42 | 40 |
43 device_->ResetPose(); | 41 device_->ResetPose(); |
44 } | 42 } |
45 | 43 |
46 void VRDisplayImpl::RequestPresent(bool secure_origin, | 44 void VRDisplayImpl::RequestPresent(bool secure_origin, |
47 const RequestPresentCallback& callback) { | 45 const RequestPresentCallback& callback) { |
48 if (!device_->IsAccessAllowed(service_)) { | 46 if (!device_->IsAccessAllowed(this)) { |
49 callback.Run(false); | 47 callback.Run(false); |
50 return; | 48 return; |
51 } | 49 } |
52 | 50 |
53 device_->RequestPresent(base::Bind(&VRDisplayImpl::RequestPresentResult, | 51 device_->RequestPresent(base::Bind(&VRDisplayImpl::RequestPresentResult, |
54 weak_ptr_factory_.GetWeakPtr(), callback, | 52 weak_ptr_factory_.GetWeakPtr(), callback, |
55 secure_origin)); | 53 secure_origin)); |
56 } | 54 } |
57 | 55 |
58 void VRDisplayImpl::RequestPresentResult(const RequestPresentCallback& callback, | 56 void VRDisplayImpl::RequestPresentResult(const RequestPresentCallback& callback, |
59 bool secure_origin, | 57 bool secure_origin, |
60 bool success) { | 58 bool success) { |
61 if (success) { | 59 if (success) { |
62 device_->SetPresentingService(service_); | 60 device_->SetPresentingDisplay(this); |
63 device_->SetSecureOrigin(secure_origin); | 61 device_->SetSecureOrigin(secure_origin); |
64 } | 62 } |
65 callback.Run(success); | 63 callback.Run(success); |
66 } | 64 } |
67 | 65 |
68 void VRDisplayImpl::ExitPresent() { | 66 void VRDisplayImpl::ExitPresent() { |
69 if (device_->IsPresentingService(service_)) | 67 if (device_->CheckPresentingDisplay(this)) |
70 device_->ExitPresent(); | 68 device_->ExitPresent(); |
71 } | 69 } |
72 | 70 |
73 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { | 71 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { |
74 if (!device_->IsPresentingService(service_)) | 72 if (!device_->CheckPresentingDisplay(this)) |
75 return; | 73 return; |
76 device_->SubmitFrame(std::move(pose)); | 74 device_->SubmitFrame(std::move(pose)); |
77 } | 75 } |
78 | 76 |
79 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds, | 77 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds, |
80 mojom::VRLayerBoundsPtr right_bounds) { | 78 mojom::VRLayerBoundsPtr right_bounds) { |
81 if (!device_->IsAccessAllowed(service_)) | 79 if (!device_->IsAccessAllowed(this)) |
82 return; | 80 return; |
83 | 81 |
84 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds)); | 82 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds)); |
85 } | 83 } |
86 } | 84 } |
OLD | NEW |