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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "device/vr/android/gvr/gvr_delegate.h" | 12 #include "device/vr/android/gvr/gvr_delegate.h" |
13 #include "device/vr/vr_service.mojom.h" | 13 #include "device/vr/vr_service.mojom.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 | 15 |
16 namespace vr_shell { | 16 namespace vr_shell { |
17 | 17 |
18 // A non presenting delegate for magic window mode. | 18 // A non presenting delegate for magic window mode. |
19 class NonPresentingGvrDelegate : public device::GvrDelegate, | 19 class NonPresentingGvrDelegate : public device::GvrDelegate, |
20 public device::mojom::VRVSyncProvider { | 20 public device::mojom::VRVSyncProvider { |
21 public: | 21 public: |
22 explicit NonPresentingGvrDelegate(long context); | 22 explicit NonPresentingGvrDelegate(long context); |
23 | 23 |
24 ~NonPresentingGvrDelegate() override; | 24 ~NonPresentingGvrDelegate() override; |
25 | 25 |
26 // GvrDelegate implementation | 26 // GvrDelegate implementation |
27 void SetWebVRSecureOrigin(bool secure_origin) override {} | 27 void SetWebVRSecureOrigin(bool secure_origin) override {} |
28 void SubmitWebVRFrame() override {} | 28 void SubmitWebVRFrame() override {} |
29 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 29 void UpdateWebVRTextureBounds(int16_t frame_index, |
| 30 const gvr::Rectf& left_bounds, |
30 const gvr::Rectf& right_bounds) override {} | 31 const gvr::Rectf& right_bounds) override {} |
31 void SetWebVRRenderSurfaceSize(int width, int height) override {} | 32 void SetWebVRRenderSurfaceSize(int width, int height) override {} |
32 gvr::Sizei GetWebVRCompositorSurfaceSize() override; | 33 gvr::Sizei GetWebVRCompositorSurfaceSize() override; |
33 gvr::GvrApi* gvr_api() override; | 34 gvr::GvrApi* gvr_api() override; |
34 void OnVRVsyncProviderRequest( | 35 void OnVRVsyncProviderRequest( |
35 device::mojom::VRVSyncProviderRequest request) override; | 36 device::mojom::VRVSyncProviderRequest request) override; |
36 void UpdateVSyncInterval(long timebase_nanos, | 37 void UpdateVSyncInterval(long timebase_nanos, |
37 double interval_seconds) override; | 38 double interval_seconds) override; |
38 | 39 |
39 void Pause(); | 40 void Pause(); |
40 void Resume(); | 41 void Resume(); |
41 device::mojom::VRVSyncProviderRequest OnSwitchToPresentingDelegate(); | 42 device::mojom::VRVSyncProviderRequest OnSwitchToPresentingDelegate(); |
42 | 43 |
43 private: | 44 private: |
44 void StopVSyncLoop(); | 45 void StopVSyncLoop(); |
45 void StartVSyncLoop(); | 46 void StartVSyncLoop(); |
46 void OnVSync(); | 47 void OnVSync(); |
47 device::mojom::VRPosePtr GetPose(); | 48 void SendVSync(base::TimeDelta time, const GetVSyncCallback& callback); |
48 | 49 |
49 // VRVSyncProvider | 50 // VRVSyncProvider implementation |
50 void GetVSync(const GetVSyncCallback& callback) override; | 51 void GetVSync(const GetVSyncCallback& callback) override; |
51 | 52 |
52 std::unique_ptr<gvr::GvrApi> gvr_api_; | 53 std::unique_ptr<gvr::GvrApi> gvr_api_; |
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
54 base::CancelableClosure vsync_task_; | 55 base::CancelableClosure vsync_task_; |
55 base::TimeTicks vsync_timebase_; | 56 base::TimeTicks vsync_timebase_; |
56 base::TimeDelta vsync_interval_; | 57 base::TimeDelta vsync_interval_; |
57 | 58 |
58 // Whether the vsync loop is paused, but not stopped. | 59 // Whether the vsync loop is paused, but not stopped. |
59 bool vsync_paused_ = false; | 60 bool vsync_paused_ = false; |
60 base::TimeDelta pending_time_; | 61 base::TimeDelta pending_time_; |
61 bool pending_vsync_ = false; | 62 bool pending_vsync_ = false; |
62 GetVSyncCallback callback_; | 63 GetVSyncCallback callback_; |
63 uint32_t pose_index_ = 1; | |
64 mojo::Binding<device::mojom::VRVSyncProvider> binding_; | 64 mojo::Binding<device::mojom::VRVSyncProvider> binding_; |
65 base::WeakPtrFactory<NonPresentingGvrDelegate> weak_ptr_factory_; | 65 base::WeakPtrFactory<NonPresentingGvrDelegate> weak_ptr_factory_; |
66 | 66 |
67 DISALLOW_COPY_AND_ASSIGN(NonPresentingGvrDelegate); | 67 DISALLOW_COPY_AND_ASSIGN(NonPresentingGvrDelegate); |
68 }; | 68 }; |
69 | 69 |
70 } // namespace vr_shell | 70 } // namespace vr_shell |
71 | 71 |
72 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ | 72 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_NON_PRESENTING_GVR_DELEGATE_H_ |
OLD | NEW |