Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: device/vr/vr_service_impl.cc

Issue 2494733002: Reland of mojo VR interface simpified. (Closed)
Patch Set: Fix Werror Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | device/vr/vr_service_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "device/vr/vr_device_manager.h" 11 #include "device/vr/vr_device_manager.h"
12 12
13 namespace device { 13 namespace device {
14 14
15 VRServiceImpl::VRServiceImpl() {} 15 VRServiceImpl::VRServiceImpl() {}
16 16
17 VRServiceImpl::~VRServiceImpl() { 17 VRServiceImpl::~VRServiceImpl() {
18 RemoveFromDeviceManager(); 18 RemoveFromDeviceManager();
19 } 19 }
20 20
21 void VRServiceImpl::BindRequest(mojo::InterfaceRequest<VRService> request) { 21 void VRServiceImpl::BindRequest(
22 mojo::InterfaceRequest<mojom::VRService> request) {
22 VRServiceImpl* service = new VRServiceImpl(); 23 VRServiceImpl* service = new VRServiceImpl();
23 service->Bind(std::move(request)); 24 service->Bind(std::move(request));
24 } 25 }
25 26
26 void VRServiceImpl::Bind(mojo::InterfaceRequest<VRService> request) { 27 // Gets a VRDisplayPtr unique to this service so that the associated page can
27 binding_.reset(new mojo::Binding<VRService>(this, std::move(request))); 28 // communicate with the VRDevice.
29 VRDisplayImpl* VRServiceImpl::GetVRDisplayImpl(VRDevice* device) {
30 DisplayImplMap::iterator it = displays_.find(device);
31 if (it != displays_.end())
32 return it->second.get();
33
34 VRDisplayImpl* display_impl = new VRDisplayImpl(device, this);
35 displays_[device] = base::WrapUnique(display_impl);
36 return display_impl;
37 }
38
39 void VRServiceImpl::Bind(mojo::InterfaceRequest<mojom::VRService> request) {
40 // TODO(shaobo.yan@intel.com) : Keep one binding_ and use close and rebind.
41 binding_.reset(new mojo::Binding<mojom::VRService>(this, std::move(request)));
28 binding_->set_connection_error_handler(base::Bind( 42 binding_->set_connection_error_handler(base::Bind(
29 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this))); 43 &VRServiceImpl::RemoveFromDeviceManager, base::Unretained(this)));
30 } 44 }
31 45
32 void VRServiceImpl::RemoveFromDeviceManager() { 46 void VRServiceImpl::RemoveFromDeviceManager() {
47 displays_.clear();
33 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); 48 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
34 device_manager->RemoveService(this); 49 device_manager->RemoveService(this);
35 } 50 }
36 51
37 void VRServiceImpl::SetClient(VRServiceClientPtr client) { 52 void VRServiceImpl::RemoveDevice(VRDevice* device) {
53 displays_.erase(device);
54 }
55
56 void VRServiceImpl::SetClient(mojom::VRServiceClientPtr service_client,
57 const SetClientCallback& callback) {
38 DCHECK(!client_.get()); 58 DCHECK(!client_.get());
39 59
40 client_ = std::move(client); 60 client_ = std::move(service_client);
41 VRDeviceManager* device_manager = VRDeviceManager::GetInstance(); 61 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
62 // Once a client has been connected AddService will force any VRDisplays to
63 // send OnConnected to it so that it's populated with the currently active
64 // displays. Thereafer it will stay up to date by virtue of listening for new
65 // connected events.
42 device_manager->AddService(this); 66 device_manager->AddService(this);
43 } 67 callback.Run(device_manager->GetNumberOfConnectedDevices());
44
45 void VRServiceImpl::GetDisplays(const GetDisplaysCallback& callback) {
46 VRDeviceManager* device_manager = VRDeviceManager::GetInstance();
47 callback.Run(device_manager->GetVRDevices());
48 }
49
50 void VRServiceImpl::GetPose(uint32_t index, const GetPoseCallback& callback) {
51 VRDevice* device = VRDeviceManager::GetAllowedDevice(this, index);
52
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 } 68 }
90 69
91 } // namespace device 70 } // namespace device
OLDNEW
« no previous file with comments | « device/vr/vr_service_impl.h ('k') | device/vr/vr_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698