OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 let mockVRService = loadMojoModules( | 3 let mockVRService = loadMojoModules( |
4 'mockVRService', | 4 'mockVRService', |
5 ['mojo/public/js/bindings', | 5 ['mojo/public/js/bindings', |
6 'device/vr/vr_service.mojom', | 6 'device/vr/vr_service.mojom', |
7 ]).then(mojo => { | 7 ]).then(mojo => { |
8 let [bindings, vr_service] = mojo.modules; | 8 let [bindings, vr_service] = mojo.modules; |
9 | 9 |
10 class MockVRDisplay { | 10 class MockVRDisplay { |
11 constructor(interfaceProvider, displayInfo, service) { | 11 constructor(interfaceProvider, displayInfo, service) { |
12 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); | 12 this.bindingSet_ = new bindings.BindingSet(vr_service.VRDisplay); |
13 this.displayClient_ = new vr_service.VRDisplayClientPtr(); | 13 this.displayClient_ = new vr_service.VRDisplayClientPtr(); |
14 this.displayInfo_ = displayInfo; | 14 this.displayInfo_ = displayInfo; |
15 this.service_ = service; | 15 this.service_ = service; |
16 this.vsync_provider_ = new MockVRVSyncProvider(); | 16 this.vsync_provider_ = new MockVRVSyncProvider(); |
17 | 17 |
18 interfaceProvider.addInterfaceOverrideForTesting( | 18 interfaceProvider.addInterfaceOverrideForTesting( |
19 vr_service.VRDisplay.name, | 19 vr_service.VRDisplay.name, |
20 handle => this.bindingSet_.addBinding(this, handle)); | 20 handle => this.bindingSet_.addBinding(this, handle)); |
21 | 21 |
22 if (service.client_) { | 22 if (service.client_) { |
23 this.notifyClientOfDisplay(); | 23 this.notifyClientOfDisplay(); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 requestPresent(secureOrigin) { | 27 requestPresent(secureOrigin, submitFrameClient) { |
| 28 this.submitFrameClient_ = submitFrameClient; |
28 return Promise.resolve({success: true}); | 29 return Promise.resolve({success: true}); |
29 } | 30 } |
30 | 31 |
| 32 submitFrame(frameId, mailboxHolder) { |
| 33 // Trigger the submit completion callbacks here. WARNING: The |
| 34 // Javascript-based mojo mocks are *not* re-entrant. In the current |
| 35 // default implementation, Javascript calls display.submitFrame, and the |
| 36 // corresponding C++ code uses a reentrant mojo call that waits for |
| 37 // onSubmitFrameTransferred to indicate completion. This never finishes |
| 38 // when using the mocks since the incoming calls are queued until the |
| 39 // current execution context finishes. As a workaround, use the alternate |
| 40 // "WebVRExperimentalRendering" mode which works without reentrant calls, |
| 41 // the code only checks for completion on the *next* frame, see the |
| 42 // corresponding option setting in RuntimeEnabledFeatures.json5. |
| 43 this.submitFrameClient_.onSubmitFrameTransferred(); |
| 44 this.submitFrameClient_.onSubmitFrameRendered(); |
| 45 } |
| 46 |
31 setPose(pose) { | 47 setPose(pose) { |
32 if (pose == null) { | 48 if (pose == null) { |
33 this.vsync_provider_.pose_ = null; | 49 this.vsync_provider_.pose_ = null; |
34 } else { | 50 } else { |
35 this.vsync_provider_.initPose(); | 51 this.vsync_provider_.initPose(); |
36 this.vsync_provider_.fillPose(pose); | 52 this.vsync_provider_.fillPose(pose); |
37 } | 53 } |
38 } | 54 } |
39 | 55 |
40 getVRVSyncProvider(request) { this.vsync_provider_.bind(request); } | 56 getVRVSyncProvider(request) { |
| 57 this.vsync_provider_.bind(request); |
| 58 } |
41 | 59 |
42 forceActivate(reason) { | 60 forceActivate(reason) { |
43 this.displayClient_.onActivate(reason); | 61 this.displayClient_.onActivate(reason); |
44 } | 62 } |
45 | 63 |
46 notifyClientOfDisplay() { | 64 notifyClientOfDisplay() { |
47 let displayPtr = new vr_service.VRDisplayPtr(); | 65 let displayPtr = new vr_service.VRDisplayPtr(); |
48 let request = bindings.makeRequest(displayPtr); | 66 let request = bindings.makeRequest(displayPtr); |
49 let binding = new bindings.Binding( | 67 let binding = new bindings.Binding( |
50 vr_service.VRDisplay, | 68 vr_service.VRDisplay, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return new MockVRService(mojo.frameInterfaces); | 164 return new MockVRService(mojo.frameInterfaces); |
147 }); | 165 }); |
148 | 166 |
149 function vr_test(func, vrDisplays, name, properties) { | 167 function vr_test(func, vrDisplays, name, properties) { |
150 mockVRService.then( (service) => { | 168 mockVRService.then( (service) => { |
151 service.setVRDisplays(vrDisplays); | 169 service.setVRDisplays(vrDisplays); |
152 let t = async_test(name, properties); | 170 let t = async_test(name, properties); |
153 func(t, service); | 171 func(t, service); |
154 }); | 172 }); |
155 } | 173 } |
OLD | NEW |