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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2624633002: Remove Sync GetPose VRService call, implement VRVSyncProvider (Closed)
Patch Set: nits Created 3 years, 11 months 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
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 "chrome/browser/android/vr_shell/vr_shell.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/android/vr_shell/ui_interface.h" 15 #include "chrome/browser/android/vr_shell/ui_interface.h"
16 #include "chrome/browser/android/vr_shell/vr_compositor.h" 16 #include "chrome/browser/android/vr_shell/vr_compositor.h"
17 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
17 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 18 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
18 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 19 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
19 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" 20 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
20 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" 21 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h"
21 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" 22 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
22 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host.h" 25 #include "content/public/browser/render_widget_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/referrer.h" 28 #include "content/public/common/referrer.h"
28 #include "device/vr/android/gvr/gvr_device_provider.h" 29 #include "device/vr/android/gvr/gvr_device_provider.h"
29 #include "jni/VrShellImpl_jni.h" 30 #include "jni/VrShellImpl_jni.h"
30 #include "ui/android/view_android.h" 31 #include "ui/android/view_android.h"
31 #include "ui/android/window_android.h" 32 #include "ui/android/window_android.h"
32 #include "ui/base/page_transition_types.h" 33 #include "ui/base/page_transition_types.h"
33 #include "ui/display/display.h" 34 #include "ui/display/display.h"
34 #include "ui/display/screen.h" 35 #include "ui/display/screen.h"
36 #include "ui/gfx/transform.h"
37 #include "ui/gfx/transform_util.h"
35 38
36 using base::android::JavaParamRef; 39 using base::android::JavaParamRef;
37 using base::android::JavaRef; 40 using base::android::JavaRef;
38 41
39 namespace vr_shell { 42 namespace vr_shell {
40 43
41 namespace { 44 namespace {
42 vr_shell::VrShell* g_instance; 45 vr_shell::VrShell* g_instance;
43 46
44 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 47 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
45 48
46 class GLThread : public base::Thread {
47 public:
48 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell,
49 const base::WeakPtr<VrInputManager>& content_input_manager,
50 const base::WeakPtr<VrInputManager>& ui_input_manager,
51 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
52 gvr_context* gvr_api,
53 bool initially_web_vr,
54 bool reprojected_rendering)
55 : base::Thread("VrShellGL"),
56 weak_vr_shell_(weak_vr_shell),
57 content_input_manager_(content_input_manager),
58 ui_input_manager_(ui_input_manager),
59 main_thread_task_runner_(std::move(main_thread_task_runner)),
60 gvr_api_(gvr_api),
61 initially_web_vr_(initially_web_vr),
62 reprojected_rendering_(reprojected_rendering) {}
63
64 ~GLThread() override {
65 Stop();
66 }
67 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; }
68 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); }
69
70 protected:
71 void Init() override {
72 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_),
73 std::move(content_input_manager_),
74 std::move(ui_input_manager_),
75 std::move(main_thread_task_runner_),
76 gvr_api_,
77 initially_web_vr_,
78 reprojected_rendering_));
79 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr();
80 vr_shell_gl_->Initialize();
81 }
82 void CleanUp() override {
83 vr_shell_gl_.reset();
84 }
85
86 private:
87 // Created on GL thread.
88 std::unique_ptr<VrShellGl> vr_shell_gl_;
89 base::WeakPtr<VrShellGl> weak_vr_shell_gl_;
90
91 base::WeakPtr<VrShell> weak_vr_shell_;
92 base::WeakPtr<VrInputManager> content_input_manager_;
93 base::WeakPtr<VrInputManager> ui_input_manager_;
94 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
95 gvr_context* gvr_api_;
96 bool initially_web_vr_;
97 bool reprojected_rendering_;
98 };
99
100 } // namespace 49 } // namespace
101 50
102 VrShell::VrShell(JNIEnv* env, 51 VrShell::VrShell(JNIEnv* env,
103 jobject obj, 52 jobject obj,
104 content::WebContents* main_contents, 53 content::WebContents* main_contents,
105 ui::WindowAndroid* content_window, 54 ui::WindowAndroid* content_window,
106 content::WebContents* ui_contents, 55 content::WebContents* ui_contents,
107 ui::WindowAndroid* ui_window, 56 ui::WindowAndroid* ui_window,
108 bool for_web_vr, 57 bool for_web_vr,
109 VrShellDelegate* delegate, 58 VrShellDelegate* delegate,
110 gvr_context* gvr_api, 59 gvr_context* gvr_api,
111 bool reprojected_rendering) 60 bool reprojected_rendering)
112 : WebContentsObserver(ui_contents), 61 : WebContentsObserver(ui_contents),
113 main_contents_(main_contents), 62 main_contents_(main_contents),
114 content_compositor_(new VrCompositor(content_window, false)), 63 content_compositor_(new VrCompositor(content_window, false)),
115 ui_contents_(ui_contents), 64 ui_contents_(ui_contents),
116 ui_compositor_(new VrCompositor(ui_window, true)), 65 ui_compositor_(new VrCompositor(ui_window, true)),
117 delegate_(delegate), 66 delegate_provider_(delegate),
118 metrics_helper_(new VrMetricsHelper(main_contents_)), 67 metrics_helper_(new VrMetricsHelper(main_contents_)),
119 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 68 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
120 reprojected_rendering_(reprojected_rendering), 69 reprojected_rendering_(reprojected_rendering),
121 weak_ptr_factory_(this) { 70 weak_ptr_factory_(this) {
122 DCHECK(g_instance == nullptr); 71 DCHECK(g_instance == nullptr);
123 g_instance = this; 72 g_instance = this;
124 j_vr_shell_.Reset(env, obj); 73 j_vr_shell_.Reset(env, obj);
125 74
126 content_input_manager_.reset(new VrInputManager(main_contents_)); 75 content_input_manager_.reset(new VrInputManager(main_contents_));
127 ui_input_manager_.reset(new VrInputManager(ui_contents_)); 76 ui_input_manager_.reset(new VrInputManager(ui_contents_));
128 77
129 content_compositor_->SetLayer(main_contents_); 78 content_compositor_->SetLayer(main_contents_);
130 ui_compositor_->SetLayer(ui_contents_); 79 ui_compositor_->SetLayer(ui_contents_);
131 80
132 gl_thread_.reset(new GLThread(weak_ptr_factory_.GetWeakPtr(), 81 gl_thread_.reset(new VrGLThread(
133 content_input_manager_->GetWeakPtr(), 82 weak_ptr_factory_.GetWeakPtr(), content_input_manager_->GetWeakPtr(),
134 ui_input_manager_->GetWeakPtr(), 83 ui_input_manager_->GetWeakPtr(), delegate_provider_->GetWeakPtr(),
135 main_thread_task_runner_, 84 main_thread_task_runner_, gvr_api,
136 gvr_api, 85 for_web_vr, reprojected_rendering_));
137 for_web_vr,
138 reprojected_rendering_));
139 86
140 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 87 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
141 options.priority = base::ThreadPriority::DISPLAY; 88 options.priority = base::ThreadPriority::DISPLAY;
142 gl_thread_->StartWithOptions(options); 89 gl_thread_->StartWithOptions(options);
143 90
144 if (for_web_vr) 91 if (for_web_vr)
145 metrics_helper_->SetWebVREnabled(true); 92 metrics_helper_->SetWebVREnabled(true);
146 html_interface_.reset(new UiInterface( 93 html_interface_.reset(new UiInterface(
147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 94 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD,
148 main_contents_->IsFullscreen())); 95 main_contents_->IsFullscreen()));
(...skipping 27 matching lines...) Expand all
176 // we need to block shutting down the GvrLayout on stopping our GL thread 123 // we need to block shutting down the GvrLayout on stopping our GL thread
177 // from using the GvrApi instance. 124 // from using the GvrApi instance.
178 // base::Thread::Stop, which is called when destroying the thread, asserts 125 // base::Thread::Stop, which is called when destroying the thread, asserts
179 // that IO is allowed to prevent jank, but there shouldn't be any concerns 126 // that IO is allowed to prevent jank, but there shouldn't be any concerns
180 // regarding jank in this case, because we're switching from 3D to 2D, 127 // regarding jank in this case, because we're switching from 3D to 2D,
181 // adding/removing a bunch of Java views, and probably changing device 128 // adding/removing a bunch of Java views, and probably changing device
182 // orientation here. 129 // orientation here.
183 base::ThreadRestrictions::ScopedAllowIO allow_io; 130 base::ThreadRestrictions::ScopedAllowIO allow_io;
184 gl_thread_.reset(); 131 gl_thread_.reset();
185 } 132 }
186 delegate_->RemoveDelegate(); 133 delegate_provider_->RemoveDelegate();
187 g_instance = nullptr; 134 g_instance = nullptr;
188 } 135 }
189 136
190 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 137 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
191 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 138 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
192 // finished starting? 139 // finished starting?
193 gl_thread_->WaitUntilThreadStarted(); 140 gl_thread_->WaitUntilThreadStarted();
194 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 141 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
195 } 142 }
196 143
197 void VrShell::OnTriggerEvent(JNIEnv* env, 144 void VrShell::OnTriggerEvent(JNIEnv* env,
198 const JavaParamRef<jobject>& obj) { 145 const JavaParamRef<jobject>& obj) {
199 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 146 gl_thread_->task_runner()->PostTask(
200 thread->task_runner()->PostTask(FROM_HERE, 147 FROM_HERE,
201 base::Bind(&VrShellGl::OnTriggerEvent, 148 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
202 thread->GetVrShellGl()));
203 } 149 }
204 150
205 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 151 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
206 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 152 gl_thread_->task_runner()->PostTask(
207 thread->task_runner()->PostTask( 153 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
208 FROM_HERE, base::Bind(&VrShellGl::OnPause, thread->GetVrShellGl()));
209 154
210 // exit vr session 155 // exit vr session
211 metrics_helper_->SetVRActive(false); 156 metrics_helper_->SetVRActive(false);
212 SetShowingOverscrollGlow(true); 157 SetShowingOverscrollGlow(true);
213 } 158 }
214 159
215 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 160 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
216 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 161 gl_thread_->task_runner()->PostTask(
217 thread->task_runner()->PostTask( 162 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl()));
218 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl()));
219 163
220 // exit vr session 164 // exit vr session
221 metrics_helper_->SetVRActive(true); 165 metrics_helper_->SetVRActive(true);
222 SetShowingOverscrollGlow(false); 166 SetShowingOverscrollGlow(false);
223 } 167 }
224 168
225 void VrShell::SetSurface(JNIEnv* env, 169 void VrShell::SetSurface(JNIEnv* env,
226 const JavaParamRef<jobject>& obj, 170 const JavaParamRef<jobject>& obj,
227 const JavaParamRef<jobject>& surface) { 171 const JavaParamRef<jobject>& surface) {
228 CHECK(!reprojected_rendering_); 172 CHECK(!reprojected_rendering_);
229 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
230 gfx::AcceleratedWidget window = 173 gfx::AcceleratedWidget window =
231 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); 174 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
232 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, 175 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
233 thread->GetVrShellGl(), 176 gl_thread_->GetVrShellGl(),
234 base::Unretained(window))); 177 base::Unretained(window)));
235 } 178 }
236 179
237 void VrShell::SetShowingOverscrollGlow(bool showing_glow) { 180 void VrShell::SetShowingOverscrollGlow(bool showing_glow) {
238 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow( 181 main_contents_->GetRenderWidgetHostView()->SetShowingOverscrollGlow(
239 showing_glow); 182 showing_glow);
240 } 183 }
241 184
242 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 185 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
243 const content::WebContents* web_contents) { 186 const content::WebContents* web_contents) {
244 // Ensure that the WebContents requesting the VrShell instance is the one 187 // Ensure that the WebContents requesting the VrShell instance is the one
245 // we created. 188 // we created.
246 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 189 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
247 return g_instance->weak_ptr_factory_.GetWeakPtr(); 190 return g_instance->weak_ptr_factory_.GetWeakPtr();
248 return base::WeakPtr<VrShell>(nullptr); 191 return base::WeakPtr<VrShell>(nullptr);
249 } 192 }
250 193
251 void VrShell::OnDomContentsLoaded() { 194 void VrShell::OnDomContentsLoaded() {
252 html_interface_->SetURL(main_contents_->GetVisibleURL()); 195 html_interface_->SetURL(main_contents_->GetVisibleURL());
253 html_interface_->SetLoading(main_contents_->IsLoading()); 196 html_interface_->SetLoading(main_contents_->IsLoading());
254 html_interface_->OnDomContentsLoaded(); 197 html_interface_->OnDomContentsLoaded();
255 } 198 }
256 199
257 void VrShell::SetWebVrMode(JNIEnv* env, 200 void VrShell::SetWebVrMode(JNIEnv* env,
258 const base::android::JavaParamRef<jobject>& obj, 201 const base::android::JavaParamRef<jobject>& obj,
259 bool enabled) { 202 bool enabled) {
260 metrics_helper_->SetWebVREnabled(enabled); 203 metrics_helper_->SetWebVREnabled(enabled);
261 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 204 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
262 PostToGlThreadWhenReady( 205 gl_thread_->GetVrShellGl(), enabled));
263 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled));
264 if (enabled) { 206 if (enabled) {
265 html_interface_->SetMode(UiInterface::Mode::WEB_VR); 207 html_interface_->SetMode(UiInterface::Mode::WEB_VR);
266 } else { 208 } else {
267 html_interface_->SetMode(UiInterface::Mode::STANDARD); 209 html_interface_->SetMode(UiInterface::Mode::STANDARD);
268 } 210 }
269 } 211 }
270 212
271 void VrShell::OnLoadProgressChanged( 213 void VrShell::OnLoadProgressChanged(
272 JNIEnv* env, 214 JNIEnv* env,
273 const base::android::JavaParamRef<jobject>& obj, 215 const base::android::JavaParamRef<jobject>& obj,
274 double progress) { 216 double progress) {
275 html_interface_->SetLoadProgress(progress); 217 html_interface_->SetLoadProgress(progress);
276 } 218 }
277 219
278 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
279 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
280 if (thread->IsRunning()) {
281 thread->task_runner()->PostTask(
282 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr,
283 thread->GetVrShellGl(), pose, pose_num));
284 }
285 }
286
287 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { 220 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) {
288 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR 221 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR
289 // render surface size. 222 // render surface size.
290 } 223 }
291 224
292 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { 225 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() {
293 const gfx::Size& size = content_compositor_->GetWindowBounds(); 226 const gfx::Size& size = content_compositor_->GetWindowBounds();
294 return {size.width(), size.height()}; 227 return {size.width(), size.height()};
295 } 228 }
296 229
297 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 230 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
298 // TODO(cjgrant): Align this state with the logic that drives the omnibox. 231 // TODO(cjgrant): Align this state with the logic that drives the omnibox.
299 html_interface_->SetWebVRSecureOrigin(secure_origin); 232 html_interface_->SetWebVRSecureOrigin(secure_origin);
300 } 233 }
301 234
302 void VrShell::SubmitWebVRFrame() {} 235 void VrShell::SubmitWebVRFrame() {}
303 236
304 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, 237 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
305 const gvr::Rectf& right_bounds) { 238 const gvr::Rectf& right_bounds) {
306 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
307 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 239 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
308 thread->GetVrShellGl(), left_bounds, 240 gl_thread_->GetVrShellGl(), left_bounds,
309 right_bounds)); 241 right_bounds));
310 } 242 }
311 243
312 // TODO(mthiesse): Do not expose GVR API outside of GL thread. 244 // TODO(mthiesse): Do not expose GVR API outside of GL thread.
313 // It's not thread-safe. 245 // It's not thread-safe.
314 gvr::GvrApi* VrShell::gvr_api() { 246 gvr::GvrApi* VrShell::gvr_api() {
315 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 247 if (gl_thread_->GetVrShellGlUnsafe()) {
316 if (thread->GetVrShellGlUnsafe()) { 248 return gl_thread_->GetVrShellGlUnsafe()->gvr_api();
317 return thread->GetVrShellGlUnsafe()->gvr_api();
318 } 249 }
319 CHECK(false); 250 CHECK(false);
320 return nullptr; 251 return nullptr;
321 } 252 }
322 253
323 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { 254 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) {
324 content_compositor_->SurfaceChanged(content_surface); 255 content_compositor_->SurfaceChanged(content_surface);
325 ui_compositor_->SurfaceChanged(ui_surface); 256 ui_compositor_->SurfaceChanged(ui_surface);
326 } 257 }
327 258
328 void VrShell::GvrDelegateReady() { 259 void VrShell::GvrDelegateReady() {
329 delegate_->SetDelegate(this); 260 delegate_provider_->SetDelegate(this);
330 } 261 }
331 262
332 void VrShell::AppButtonPressed() { 263 void VrShell::AppButtonPressed() {
333 #if defined(ENABLE_VR_SHELL) 264 #if defined(ENABLE_VR_SHELL)
334 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); 265 html_interface_->SetMenuMode(!html_interface_->GetMenuMode());
335 266
336 // TODO(mthiesse): The page is no longer visible when in menu mode. We 267 // TODO(mthiesse): The page is no longer visible when in menu mode. We
337 // should unfocus or otherwise let it know it's hidden. 268 // should unfocus or otherwise let it know it's hidden.
338 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { 269 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
339 if (delegate_->device_provider()) { 270 if (delegate_provider_->device_provider()) {
340 if (html_interface_->GetMenuMode()) { 271 if (html_interface_->GetMenuMode()) {
341 delegate_->device_provider()->OnDisplayBlur(); 272 delegate_provider_->device_provider()->OnDisplayBlur();
342 } else { 273 } else {
343 delegate_->device_provider()->OnDisplayFocus(); 274 delegate_provider_->device_provider()->OnDisplayFocus();
344 } 275 }
345 } 276 }
346 } 277 }
347 #endif 278 #endif
348 } 279 }
349 280
350 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 281 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
351 const JavaParamRef<jobject>& object, 282 const JavaParamRef<jobject>& object,
352 jint width, jint height, 283 jint width, jint height,
353 jfloat dpr) { 284 jfloat dpr) {
354 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 285 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
355 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
356 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 286 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
357 thread->GetVrShellGl(), width, height)); 287 gl_thread_->GetVrShellGl(), width,
288 height));
358 content_compositor_->SetWindowBounds(gfx::Size(width, height)); 289 content_compositor_->SetWindowBounds(gfx::Size(width, height));
359 } 290 }
360 291
361 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env, 292 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env,
362 const JavaParamRef<jobject>& object, 293 const JavaParamRef<jobject>& object,
363 jint width, jint height, jfloat dpr) { 294 jint width, jint height, jfloat dpr) {
364 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
365 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged, 295 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged,
366 thread->GetVrShellGl(), width, height)); 296 gl_thread_->GetVrShellGl(), width,
297 height));
367 ui_compositor_->SetWindowBounds(gfx::Size(width, height)); 298 ui_compositor_->SetWindowBounds(gfx::Size(width, height));
368 } 299 }
369 300
370 UiInterface* VrShell::GetUiInterface() { 301 UiInterface* VrShell::GetUiInterface() {
371 return html_interface_.get(); 302 return html_interface_.get();
372 } 303 }
373 304
374 void VrShell::UpdateScene(const base::ListValue* args) { 305 void VrShell::UpdateScene(const base::ListValue* args) {
375 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
376 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, 306 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene,
377 thread->GetVrShellGl(), 307 gl_thread_->GetVrShellGl(),
378 base::Passed(args->CreateDeepCopy()))); 308 base::Passed(args->CreateDeepCopy())));
379 } 309 }
380 310
381 void VrShell::DoUiAction(const UiAction action) { 311 void VrShell::DoUiAction(const UiAction action) {
382 content::NavigationController& controller = main_contents_->GetController(); 312 content::NavigationController& controller = main_contents_->GetController();
383 switch (action) { 313 switch (action) {
384 case HISTORY_BACK: 314 case HISTORY_BACK:
385 if (main_contents_->IsFullscreen()) { 315 if (main_contents_->IsFullscreen()) {
386 main_contents_->ExitFullscreen(false); 316 main_contents_->ExitFullscreen(false);
387 } else if (controller.CanGoBack()) { 317 } else if (controller.CanGoBack()) {
(...skipping 24 matching lines...) Expand all
412 } 342 }
413 343
414 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 344 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
415 content::RenderViewHost* new_host) { 345 content::RenderViewHost* new_host) {
416 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); 346 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
417 } 347 }
418 348
419 void VrShell::MainFrameWasResized(bool width_changed) { 349 void VrShell::MainFrameWasResized(bool width_changed) {
420 display::Display display = display::Screen::GetScreen() 350 display::Display display = display::Screen::GetScreen()
421 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); 351 ->GetDisplayNearestWindow(ui_contents_->GetNativeView());
422 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
423 PostToGlThreadWhenReady( 352 PostToGlThreadWhenReady(
424 base::Bind(&VrShellGl::UIBoundsChanged, thread->GetVrShellGl(), 353 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(),
425 display.size().width(), display.size().height())); 354 display.size().width(), display.size().height()));
426 } 355 }
427 356
428 void VrShell::ContentFrameWasResized(bool width_changed) { 357 void VrShell::ContentFrameWasResized(bool width_changed) {
429 display::Display display = display::Screen::GetScreen() 358 display::Display display = display::Screen::GetScreen()
430 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); 359 ->GetDisplayNearestWindow(main_contents_->GetNativeView());
431 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
432 PostToGlThreadWhenReady( 360 PostToGlThreadWhenReady(
433 base::Bind(&VrShellGl::ContentBoundsChanged, thread->GetVrShellGl(), 361 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(),
434 display.size().width(), display.size().height())); 362 display.size().width(), display.size().height()));
435 } 363 }
436 364
437 void VrShell::WebContentsDestroyed() { 365 void VrShell::WebContentsDestroyed() {
438 ui_input_manager_.reset(); 366 ui_input_manager_.reset();
439 ui_contents_ = nullptr; 367 ui_contents_ = nullptr;
440 // TODO(mthiesse): Handle web contents being destroyed. 368 // TODO(mthiesse): Handle web contents being destroyed.
441 ForceExitVr(); 369 ForceExitVr();
442 } 370 }
443 371
444 void VrShell::ContentWebContentsDestroyed() { 372 void VrShell::ContentWebContentsDestroyed() {
445 content_input_manager_.reset(); 373 content_input_manager_.reset();
446 main_contents_ = nullptr; 374 main_contents_ = nullptr;
447 // TODO(mthiesse): Handle web contents being destroyed. 375 // TODO(mthiesse): Handle web contents being destroyed.
448 ForceExitVr(); 376 ForceExitVr();
449 } 377 }
450 378
451 void VrShell::ContentWasHidden() { 379 void VrShell::ContentWasHidden() {
452 // Ensure we don't continue sending input to it. 380 // Ensure we don't continue sending input to it.
453 content_input_manager_.reset(); 381 content_input_manager_.reset();
454 // TODO(mthiesse): Handle web contents being hidden. 382 // TODO(mthiesse): Handle web contents being hidden.
455 ForceExitVr(); 383 ForceExitVr();
456 } 384 }
457 385
458 void VrShell::ForceExitVr() { 386 void VrShell::ForceExitVr() {
459 delegate_->ForceExitVr(); 387 delegate_provider_->ForceExitVr();
388 }
389
390 void VrShell::OnVRVsyncProviderRequest(
391 device::mojom::VRVSyncProviderRequest request) {
392 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest,
393 gl_thread_->GetVrShellGl(),
394 base::Passed(&request)));
395 }
396
397 void VrShell::UpdateVSyncInterval(long timebase_nanos,
398 double interval_seconds) {
399 PostToGlThreadWhenReady(
400 base::Bind(&VrShellGl::UpdateVSyncInterval,
401 gl_thread_->GetVrShellGl(), timebase_nanos, interval_seconds));
460 } 402 }
461 403
462 void VrShell::SetContentCssSize(float width, float height, float dpr) { 404 void VrShell::SetContentCssSize(float width, float height, float dpr) {
463 JNIEnv* env = base::android::AttachCurrentThread(); 405 JNIEnv* env = base::android::AttachCurrentThread();
464 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, 406 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height,
465 dpr); 407 dpr);
466 } 408 }
467 409
468 void VrShell::SetUiCssSize(float width, float height, float dpr) { 410 void VrShell::SetUiCssSize(float width, float height, float dpr) {
469 JNIEnv* env = base::android::AttachCurrentThread(); 411 JNIEnv* env = base::android::AttachCurrentThread();
470 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); 412 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr);
471 } 413 }
472 414
415 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat,
416 uint32_t pose_index) {
417 device::mojom::VRPosePtr pose = device::mojom::VRPose::New();
418
419 pose->timestamp = base::Time::Now().ToJsTime();
420
421 pose->poseIndex = pose_index;
422 pose->orientation.emplace(4);
423
424 gfx::Transform inv_transform(
425 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3],
426 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3],
427 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3],
428 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]);
429
430 gfx::Transform transform;
431 if (inv_transform.GetInverse(&transform)) {
432 gfx::DecomposedTransform decomposed_transform;
433 gfx::DecomposeTransform(&decomposed_transform, transform);
434
435 pose->orientation.value()[0] = decomposed_transform.quaternion[0];
436 pose->orientation.value()[1] = decomposed_transform.quaternion[1];
437 pose->orientation.value()[2] = decomposed_transform.quaternion[2];
438 pose->orientation.value()[3] = decomposed_transform.quaternion[3];
439
440 pose->position.emplace(3);
441 pose->position.value()[0] = decomposed_transform.translate[0];
442 pose->position.value()[1] = decomposed_transform.translate[1];
443 pose->position.value()[2] = decomposed_transform.translate[2];
444 }
445
446 return pose;
447 }
448
473 // ---------------------------------------------------------------------------- 449 // ----------------------------------------------------------------------------
474 // Native JNI methods 450 // Native JNI methods
475 // ---------------------------------------------------------------------------- 451 // ----------------------------------------------------------------------------
476 452
477 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 453 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj,
478 const JavaParamRef<jobject>& content_web_contents, 454 const JavaParamRef<jobject>& content_web_contents,
479 jlong content_window_android, 455 jlong content_window_android,
480 const JavaParamRef<jobject>& ui_web_contents, 456 const JavaParamRef<jobject>& ui_web_contents,
481 jlong ui_window_android, jboolean for_web_vr, 457 jlong ui_window_android, jboolean for_web_vr,
482 const base::android::JavaParamRef<jobject>& delegate, 458 const base::android::JavaParamRef<jobject>& delegate,
483 jlong gvr_api, jboolean reprojected_rendering) { 459 jlong gvr_api, jboolean reprojected_rendering) {
484 return reinterpret_cast<intptr_t>(new VrShell( 460 return reinterpret_cast<intptr_t>(new VrShell(
485 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 461 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
486 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 462 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
487 content::WebContents::FromJavaWebContents(ui_web_contents), 463 content::WebContents::FromJavaWebContents(ui_web_contents),
488 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 464 reinterpret_cast<ui::WindowAndroid*>(ui_window_android),
489 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), 465 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate),
490 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 466 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
491 } 467 }
492 468
493 } // namespace vr_shell 469 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698