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

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

Issue 2510873003: Clean up WebVR RequestPresent and make callback asynchronous. (Closed)
Patch Set: Fix FakeVRDevice 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_display_impl.h ('k') | third_party/WebKit/Source/modules/vr/VRDisplay.cpp » ('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 <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),
15 device_(device),
16 service_(service),
17 weak_ptr_factory_(this) {
15 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice(); 18 mojom::VRDisplayInfoPtr display_info = device->GetVRDevice();
16 // Client might be null in unittest. 19 // Client might be null in unittest.
17 // TODO: setup a mock client in unittest too? 20 // TODO: setup a mock client in unittest too?
18 if (service->client()) { 21 if (service->client()) {
19 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(), 22 service->client()->OnDisplayConnected(binding_.CreateInterfacePtrAndBind(),
20 mojo::GetProxy(&client_), 23 mojo::GetProxy(&client_),
21 std::move(display_info)); 24 std::move(display_info));
22 } 25 }
23 } 26 }
24 27
25 VRDisplayImpl::~VRDisplayImpl() {} 28 VRDisplayImpl::~VRDisplayImpl() {}
26 29
27 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) { 30 void VRDisplayImpl::GetPose(const GetPoseCallback& callback) {
28 if (!device_->IsAccessAllowed(service_)) { 31 if (!device_->IsAccessAllowed(service_)) {
29 callback.Run(nullptr); 32 callback.Run(nullptr);
30 return; 33 return;
31 } 34 }
32 35
33 callback.Run(device_->GetPose()); 36 callback.Run(device_->GetPose());
34 } 37 }
35 38
36 void VRDisplayImpl::ResetPose() { 39 void VRDisplayImpl::ResetPose() {
37 if (!device_->IsAccessAllowed(service_)) 40 if (!device_->IsAccessAllowed(service_))
38 return; 41 return;
39 42
40 device_->ResetPose(); 43 device_->ResetPose();
41 } 44 }
42 45
43 void VRDisplayImpl::RequestPresent(bool secureOrigin, 46 void VRDisplayImpl::RequestPresent(bool secure_origin,
44 const RequestPresentCallback& callback) { 47 const RequestPresentCallback& callback) {
45 if (!device_->IsAccessAllowed(service_)) { 48 if (!device_->IsAccessAllowed(service_)) {
46 callback.Run(false); 49 callback.Run(false);
47 return; 50 return;
48 } 51 }
49 52
50 bool success = device_->RequestPresent(secureOrigin); 53 device_->RequestPresent(base::Bind(&VRDisplayImpl::RequestPresentResult,
54 weak_ptr_factory_.GetWeakPtr(), callback,
55 secure_origin));
56 }
57
58 void VRDisplayImpl::RequestPresentResult(const RequestPresentCallback& callback,
59 bool secure_origin,
60 bool success) {
51 if (success) { 61 if (success) {
52 device_->SetPresentingService(service_); 62 device_->SetPresentingService(service_);
63 device_->SetSecureOrigin(secure_origin);
53 } 64 }
54 callback.Run(success); 65 callback.Run(success);
55 } 66 }
56 67
57 void VRDisplayImpl::ExitPresent() { 68 void VRDisplayImpl::ExitPresent() {
58 if (device_->IsPresentingService(service_)) 69 if (device_->IsPresentingService(service_))
59 device_->ExitPresent(); 70 device_->ExitPresent();
60 } 71 }
61 72
62 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) { 73 void VRDisplayImpl::SubmitFrame(mojom::VRPosePtr pose) {
63 if (!device_->IsPresentingService(service_)) 74 if (!device_->IsPresentingService(service_))
64 return; 75 return;
65 device_->SubmitFrame(std::move(pose)); 76 device_->SubmitFrame(std::move(pose));
66 } 77 }
67 78
68 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds, 79 void VRDisplayImpl::UpdateLayerBounds(mojom::VRLayerBoundsPtr left_bounds,
69 mojom::VRLayerBoundsPtr right_bounds) { 80 mojom::VRLayerBoundsPtr right_bounds) {
70 if (!device_->IsAccessAllowed(service_)) 81 if (!device_->IsAccessAllowed(service_))
71 return; 82 return;
72 83
73 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds)); 84 device_->UpdateLayerBounds(std::move(left_bounds), std::move(right_bounds));
74 } 85 }
75 } 86 }
OLDNEW
« no previous file with comments | « device/vr/vr_display_impl.h ('k') | third_party/WebKit/Source/modules/vr/VRDisplay.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698