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_VR_SHELL_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/android/jni_weak_ref.h" | 12 #include "base/android/jni_weak_ref.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "device/vr/android/gvr/gvr_delegate.h" | 18 #include "device/vr/android/gvr/gvr_delegate.h" |
| 19 #include "device/vr/vr_service.mojom.h" |
19 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 20 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
20 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" | 21 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class ListValue; | 24 class ListValue; |
24 class Thread; | |
25 } | 25 } |
26 | 26 |
27 namespace blink { | 27 namespace blink { |
28 class WebInputEvent; | 28 class WebInputEvent; |
29 } | 29 } |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 class WebContents; | 32 class WebContents; |
33 } | 33 } |
34 | 34 |
35 namespace ui { | 35 namespace ui { |
36 class WindowAndroid; | 36 class WindowAndroid; |
37 } | 37 } |
38 | 38 |
39 namespace vr_shell { | 39 namespace vr_shell { |
40 | 40 |
41 class UiInterface; | 41 class UiInterface; |
42 class VrCompositor; | 42 class VrCompositor; |
| 43 class VrGLThread; |
43 class VrInputManager; | 44 class VrInputManager; |
44 class VrMetricsHelper; | 45 class VrMetricsHelper; |
45 class VrShellDelegate; | 46 class VrShellDelegate; |
46 class VrWebContentsObserver; | 47 class VrWebContentsObserver; |
47 | 48 |
48 enum UiAction { | 49 enum UiAction { |
49 HISTORY_BACK = 0, | 50 HISTORY_BACK = 0, |
50 HISTORY_FORWARD, | 51 HISTORY_FORWARD, |
51 RELOAD, | 52 RELOAD, |
52 ZOOM_OUT, | 53 ZOOM_OUT, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void ContentWebContentsDestroyed(); | 95 void ContentWebContentsDestroyed(); |
95 // Called when our WebContents have been hidden. Usually a sign that something | 96 // Called when our WebContents have been hidden. Usually a sign that something |
96 // like another tab placed in front of it. | 97 // like another tab placed in front of it. |
97 void ContentWasHidden(); | 98 void ContentWasHidden(); |
98 void ContentWasShown(); | 99 void ContentWasShown(); |
99 | 100 |
100 // html/js UI hooks. | 101 // html/js UI hooks. |
101 static base::WeakPtr<VrShell> GetWeakPtr( | 102 static base::WeakPtr<VrShell> GetWeakPtr( |
102 const content::WebContents* web_contents); | 103 const content::WebContents* web_contents); |
103 | 104 |
104 // TODO(mthiesse): Clean up threading around UiInterface. | |
105 UiInterface* GetUiInterface(); | 105 UiInterface* GetUiInterface(); |
106 void OnDomContentsLoaded(); | 106 void OnDomContentsLoaded(); |
107 | 107 |
108 // device::GvrDelegate implementation | |
109 // TODO(mthiesse): Clean up threading around GVR API. These functions are | |
110 // called on the UI thread, but use GL thread objects in a non-threadsafe way. | |
111 void SetWebVRSecureOrigin(bool secure_origin) override; | |
112 void SubmitWebVRFrame() override; | |
113 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | |
114 const gvr::Rectf& right_bounds) override; | |
115 gvr::GvrApi* gvr_api() override; | |
116 void SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) override; | |
117 void SetWebVRRenderSurfaceSize(int width, int height) override; | |
118 gvr::Sizei GetWebVRCompositorSurfaceSize() override; | |
119 | |
120 void SurfacesChanged(jobject content_surface, jobject ui_surface); | 108 void SurfacesChanged(jobject content_surface, jobject ui_surface); |
121 void GvrDelegateReady(); | 109 void GvrDelegateReady(); |
122 void AppButtonPressed(); | 110 void AppButtonPressed(); |
123 | 111 |
124 void ContentPhysicalBoundsChanged( | 112 void ContentPhysicalBoundsChanged( |
125 JNIEnv* env, | 113 JNIEnv* env, |
126 const base::android::JavaParamRef<jobject>& object, | 114 const base::android::JavaParamRef<jobject>& object, |
127 jint width, jint height, jfloat dpr); | 115 jint width, jint height, jfloat dpr); |
128 | 116 |
129 void UIPhysicalBoundsChanged( | 117 void UIPhysicalBoundsChanged( |
130 JNIEnv* env, | 118 JNIEnv* env, |
131 const base::android::JavaParamRef<jobject>& object, | 119 const base::android::JavaParamRef<jobject>& object, |
132 jint width, jint height, jfloat dpr); | 120 jint width, jint height, jfloat dpr); |
133 | 121 |
134 void UpdateScene(const base::ListValue* args); | 122 void UpdateScene(const base::ListValue* args); |
135 | 123 |
136 // Perform a UI action triggered by the javascript API. | 124 // Perform a UI action triggered by the javascript API. |
137 void DoUiAction(const UiAction action); | 125 void DoUiAction(const UiAction action); |
138 | 126 |
139 void SetContentCssSize(float width, float height, float dpr); | 127 void SetContentCssSize(float width, float height, float dpr); |
140 void SetUiCssSize(float width, float height, float dpr); | 128 void SetUiCssSize(float width, float height, float dpr); |
141 | 129 |
142 void ContentFrameWasResized(bool width_changed); | 130 void ContentFrameWasResized(bool width_changed); |
143 | 131 |
144 void ForceExitVr(); | 132 void ForceExitVr(); |
145 | 133 |
146 void ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event); | 134 void ProcessUIGesture(std::unique_ptr<blink::WebInputEvent> event); |
147 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event); | 135 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event); |
148 | 136 |
| 137 static device::mojom::VRPosePtr VRPosePtrFromGvrPose(gvr::Mat4f head_mat, |
| 138 uint32_t pose_index); |
| 139 |
149 private: | 140 private: |
150 ~VrShell() override; | 141 ~VrShell() override; |
151 void PostToGlThreadWhenReady(const base::Closure& task); | 142 void PostToGlThreadWhenReady(const base::Closure& task); |
152 | 143 |
153 // content::WebContentsObserver implementation. All called on UI thread. | 144 // content::WebContentsObserver implementation. |
154 void RenderViewHostChanged(content::RenderViewHost* old_host, | 145 void RenderViewHostChanged(content::RenderViewHost* old_host, |
155 content::RenderViewHost* new_host) override; | 146 content::RenderViewHost* new_host) override; |
156 void MainFrameWasResized(bool width_changed) override; | 147 void MainFrameWasResized(bool width_changed) override; |
157 void WebContentsDestroyed() override; | 148 void WebContentsDestroyed() override; |
158 | 149 |
| 150 // device::GvrDelegate implementation |
| 151 void SetWebVRSecureOrigin(bool secure_origin) override; |
| 152 void SubmitWebVRFrame() override; |
| 153 void UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |
| 154 const gvr::Rectf& right_bounds) override; |
| 155 gvr::GvrApi* gvr_api() override; |
| 156 void SetWebVRRenderSurfaceSize(int width, int height) override; |
| 157 gvr::Sizei GetWebVRCompositorSurfaceSize() override; |
| 158 void OnVRVsyncProviderRequest( |
| 159 device::mojom::VRVSyncProviderRequest request) override; |
| 160 void UpdateVSyncInterval(long timebase_nanos, |
| 161 double interval_seconds) override; |
| 162 |
159 std::unique_ptr<UiInterface> html_interface_; | 163 std::unique_ptr<UiInterface> html_interface_; |
160 | 164 |
161 content::WebContents* main_contents_; | 165 content::WebContents* main_contents_; |
162 std::unique_ptr<VrCompositor> content_compositor_; | 166 std::unique_ptr<VrCompositor> content_compositor_; |
163 content::WebContents* ui_contents_; | 167 content::WebContents* ui_contents_; |
164 std::unique_ptr<VrCompositor> ui_compositor_; | 168 std::unique_ptr<VrCompositor> ui_compositor_; |
165 | 169 |
166 std::unique_ptr<VrWebContentsObserver> vr_web_contents_observer_; | 170 std::unique_ptr<VrWebContentsObserver> vr_web_contents_observer_; |
167 | 171 |
168 VrShellDelegate* delegate_ = nullptr; | 172 VrShellDelegate* delegate_provider_ = nullptr; |
169 base::android::ScopedJavaGlobalRef<jobject> j_vr_shell_; | 173 base::android::ScopedJavaGlobalRef<jobject> j_vr_shell_; |
170 | 174 |
171 std::unique_ptr<VrInputManager> content_input_manager_; | 175 std::unique_ptr<VrInputManager> content_input_manager_; |
172 std::unique_ptr<VrInputManager> ui_input_manager_; | 176 std::unique_ptr<VrInputManager> ui_input_manager_; |
173 std::unique_ptr<VrMetricsHelper> metrics_helper_; | 177 std::unique_ptr<VrMetricsHelper> metrics_helper_; |
174 | 178 |
175 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 179 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
176 std::unique_ptr<base::Thread> gl_thread_; | 180 std::unique_ptr<VrGLThread> gl_thread_; |
177 bool reprojected_rendering_; | 181 bool reprojected_rendering_; |
178 | 182 |
179 base::WeakPtrFactory<VrShell> weak_ptr_factory_; | 183 base::WeakPtrFactory<VrShell> weak_ptr_factory_; |
180 | 184 |
181 DISALLOW_COPY_AND_ASSIGN(VrShell); | 185 DISALLOW_COPY_AND_ASSIGN(VrShell); |
182 }; | 186 }; |
183 | 187 |
184 bool RegisterVrShell(JNIEnv* env); | 188 bool RegisterVrShell(JNIEnv* env); |
185 | 189 |
186 } // namespace vr_shell | 190 } // namespace vr_shell |
187 | 191 |
188 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ | 192 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ |
OLD | NEW |