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

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

Issue 2683953007: Support rendering Android Native Pages in VR Shell. (Closed)
Patch Set: Created 3 years, 10 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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 using base::android::JavaRef; 48 using base::android::JavaRef;
49 49
50 namespace vr_shell { 50 namespace vr_shell {
51 51
52 namespace { 52 namespace {
53 vr_shell::VrShell* g_instance; 53 vr_shell::VrShell* g_instance;
54 54
55 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 55 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
56 56
57 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { 57 void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
58 if (contents->GetRenderWidgetHostView()) 58 if (contents && contents->GetRenderWidgetHostView())
59 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 59 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 VrShell::VrShell(JNIEnv* env, 64 VrShell::VrShell(JNIEnv* env,
65 jobject obj, 65 jobject obj,
66 content::WebContents* main_contents,
67 ui::WindowAndroid* content_window, 66 ui::WindowAndroid* content_window,
68 content::WebContents* ui_contents, 67 content::WebContents* ui_contents,
69 ui::WindowAndroid* ui_window, 68 ui::WindowAndroid* ui_window,
70 bool for_web_vr, 69 bool for_web_vr,
71 VrShellDelegate* delegate, 70 VrShellDelegate* delegate,
72 gvr_context* gvr_api, 71 gvr_context* gvr_api,
73 bool reprojected_rendering) 72 bool reprojected_rendering)
74 : WebContentsObserver(ui_contents), 73 : WebContentsObserver(ui_contents),
75 main_contents_(main_contents), 74 content_window_(content_window),
76 content_compositor_( 75 content_compositor_(
77 base::MakeUnique<VrCompositor>(content_window, false)), 76 base::MakeUnique<VrCompositor>(content_window_, false)),
78 ui_contents_(ui_contents), 77 ui_contents_(ui_contents),
79 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), 78 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)),
80 delegate_provider_(delegate), 79 delegate_provider_(delegate),
81 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)),
82 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 80 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
83 reprojected_rendering_(reprojected_rendering), 81 reprojected_rendering_(reprojected_rendering),
84 gvr_api_(gvr_api), 82 gvr_api_(gvr_api),
85 weak_ptr_factory_(this) { 83 weak_ptr_factory_(this) {
86 DCHECK(g_instance == nullptr); 84 DCHECK(g_instance == nullptr);
87 g_instance = this; 85 g_instance = this;
88 j_vr_shell_.Reset(env, obj); 86 j_vr_shell_.Reset(env, obj);
89 87
90 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
91 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); 88 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_);
92
93 content_compositor_->SetLayer(main_contents_);
94 ui_compositor_->SetLayer(ui_contents_); 89 ui_compositor_->SetLayer(ui_contents_);
95 90
96 gl_thread_ = base::MakeUnique<VrGLThread>( 91 gl_thread_ = base::MakeUnique<VrGLThread>(
97 weak_ptr_factory_.GetWeakPtr(), delegate_provider_->GetWeakPtr(), 92 weak_ptr_factory_.GetWeakPtr(), delegate_provider_->GetWeakPtr(),
98 main_thread_task_runner_, gvr_api, for_web_vr, reprojected_rendering_); 93 main_thread_task_runner_, gvr_api, for_web_vr, reprojected_rendering_);
99 94
100 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 95 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
101 options.priority = base::ThreadPriority::DISPLAY; 96 options.priority = base::ThreadPriority::DISPLAY;
102 gl_thread_->StartWithOptions(options); 97 gl_thread_->StartWithOptions(options);
103 98
104 if (for_web_vr)
105 metrics_helper_->SetWebVREnabled(true);
106 html_interface_ = base::MakeUnique<UiInterface>( 99 html_interface_ = base::MakeUnique<UiInterface>(
107 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 100 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
108 main_contents_->IsFullscreen());
109 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>(
110 main_contents_, html_interface_.get(), this);
111
112 SetIsInVR(main_contents_, true);
113 } 101 }
114 102
115 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 103 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
116 delete this; 104 delete this;
117 } 105 }
118 106
119 void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj, 107 void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj,
120 const JavaParamRef<jobject>& web_contents) { 108 const JavaParamRef<jobject>& web_contents) {
121 SetIsInVR(main_contents_, false);
122 content::WebContents* contents = 109 content::WebContents* contents =
123 content::WebContents::FromJavaWebContents(web_contents); 110 content::WebContents::FromJavaWebContents(web_contents);
111 if (contents == main_contents_)
112 return;
113
114 SetIsInVR(main_contents_, false);
115
124 main_contents_ = contents; 116 main_contents_ = contents;
117 content_compositor_->SetLayer(main_contents_);
118 SetIsInVR(main_contents_, true);
119 ContentFrameWasResized(false /* unused */);
cjgrant 2017/02/10 15:21:47 Is "unused" necessary?
mthiesse 2017/02/10 16:13:39 Technically no, but I'm pointing out that this val
120
121 if (!main_contents_) {
122 content_input_manager_ = nullptr;
123 vr_web_contents_observer_ = nullptr;
124 html_interface_->SetFullscreen(false);
125 metrics_helper_ = nullptr;
126 // TODO(mthiesse): Properly handle native page URLs.
127 html_interface_->SetURL(GURL());
128 html_interface_->SetLoading(false);
129 return;
130 }
125 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 131 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
126 content_compositor_->SetLayer(main_contents_);
127 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( 132 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>(
128 main_contents_, html_interface_.get(), this); 133 main_contents_, html_interface_.get(), this);
129 SetIsInVR(main_contents_, true); 134 html_interface_->SetFullscreen(main_contents_->IsFullscreen());
cjgrant 2017/02/10 15:21:47 Should probably create a SetUiState() method that
mthiesse 2017/02/10 16:13:39 Done.
135 html_interface_->SetURL(main_contents_->GetVisibleURL());
136 html_interface_->SetLoading(main_contents_->IsLoading());
130 137
131 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple 138 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple
132 // tabs. crbug.com/684661 139 // tabs. crbug.com/684661
133 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_); 140 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_);
134 metrics_helper_->SetVRActive(true); 141 metrics_helper_->SetVRActive(true);
135 metrics_helper_->SetWebVREnabled(webvr_mode_); 142 metrics_helper_->SetWebVREnabled(webvr_mode_);
136 } 143 }
137 144
138 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { 145 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) {
139 GURL url(kVrShellUIURL); 146 GURL url(kVrShellUIURL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 gl_thread_->task_runner()->PostTask( 202 gl_thread_->task_runner()->PostTask(
196 FROM_HERE, 203 FROM_HERE,
197 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); 204 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
198 } 205 }
199 206
200 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 207 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
201 gl_thread_->task_runner()->PostTask( 208 gl_thread_->task_runner()->PostTask(
202 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); 209 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
203 210
204 // exit vr session 211 // exit vr session
205 metrics_helper_->SetVRActive(false); 212 if (metrics_helper_)
213 metrics_helper_->SetVRActive(false);
206 SetIsInVR(main_contents_, false); 214 SetIsInVR(main_contents_, false);
207 } 215 }
208 216
209 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 217 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
210 gl_thread_->task_runner()->PostTask( 218 gl_thread_->task_runner()->PostTask(
211 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl())); 219 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl()));
212 220
213 metrics_helper_->SetVRActive(true); 221 if (metrics_helper_)
222 metrics_helper_->SetVRActive(true);
214 SetIsInVR(main_contents_, true); 223 SetIsInVR(main_contents_, true);
215 } 224 }
216 225
217 void VrShell::SetSurface(JNIEnv* env, 226 void VrShell::SetSurface(JNIEnv* env,
218 const JavaParamRef<jobject>& obj, 227 const JavaParamRef<jobject>& obj,
219 const JavaParamRef<jobject>& surface) { 228 const JavaParamRef<jobject>& surface) {
220 CHECK(!reprojected_rendering_); 229 CHECK(!reprojected_rendering_);
221 gfx::AcceleratedWidget window = 230 gfx::AcceleratedWidget window =
222 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); 231 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
223 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, 232 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
224 gl_thread_->GetVrShellGl(), 233 gl_thread_->GetVrShellGl(),
225 base::Unretained(window))); 234 base::Unretained(window)));
226 } 235 }
227 236
228 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 237 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
229 const content::WebContents* web_contents) { 238 const content::WebContents* web_contents) {
230 // Ensure that the WebContents requesting the VrShell instance is the one 239 // Ensure that the WebContents requesting the VrShell instance is the one
231 // we created. 240 // we created.
232 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 241 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
233 return g_instance->weak_ptr_factory_.GetWeakPtr(); 242 return g_instance->weak_ptr_factory_.GetWeakPtr();
234 return base::WeakPtr<VrShell>(nullptr); 243 return base::WeakPtr<VrShell>(nullptr);
235 } 244 }
236 245
237 void VrShell::OnDomContentsLoaded() { 246 void VrShell::OnDomContentsLoaded() {
238 html_interface_->SetURL(main_contents_->GetVisibleURL()); 247 if (main_contents_) {
239 html_interface_->SetLoading(main_contents_->IsLoading()); 248 html_interface_->SetURL(main_contents_->GetVisibleURL());
249 html_interface_->SetLoading(main_contents_->IsLoading());
250 }
240 html_interface_->OnDomContentsLoaded(); 251 html_interface_->OnDomContentsLoaded();
241 } 252 }
242 253
243 void VrShell::SetWebVrMode(JNIEnv* env, 254 void VrShell::SetWebVrMode(JNIEnv* env,
244 const base::android::JavaParamRef<jobject>& obj, 255 const base::android::JavaParamRef<jobject>& obj,
245 bool enabled) { 256 bool enabled) {
246 webvr_mode_ = enabled; 257 webvr_mode_ = enabled;
247 metrics_helper_->SetWebVREnabled(enabled); 258 if (metrics_helper_)
259 metrics_helper_->SetWebVREnabled(enabled);
248 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, 260 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
249 gl_thread_->GetVrShellGl(), enabled)); 261 gl_thread_->GetVrShellGl(), enabled));
250 html_interface_->SetMode( 262 html_interface_->SetMode(
251 enabled ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); 263 enabled ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
252 } 264 }
253 265
254 void VrShell::OnLoadProgressChanged(JNIEnv* env, 266 void VrShell::OnLoadProgressChanged(JNIEnv* env,
255 const JavaParamRef<jobject>& obj, 267 const JavaParamRef<jobject>& obj,
256 double progress) { 268 double progress) {
257 html_interface_->SetLoadProgress(progress); 269 html_interface_->SetLoadProgress(progress);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 329 }
318 330
319 void VrShell::CreateVRDisplayInfo( 331 void VrShell::CreateVRDisplayInfo(
320 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 332 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
321 uint32_t device_id) { 333 uint32_t device_id) {
322 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo, 334 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo,
323 gl_thread_->GetVrShellGl(), 335 gl_thread_->GetVrShellGl(),
324 callback, device_id)); 336 callback, device_id));
325 } 337 }
326 338
327 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { 339 base::android::ScopedJavaGlobalRef<jobject> VrShell::TakeContentSurface(
328 content_compositor_->SurfaceChanged(content_surface); 340 JNIEnv* env,
329 ui_compositor_->SurfaceChanged(ui_surface); 341 const JavaParamRef<jobject>& obj) {
342 content_compositor_->SurfaceChanged(nullptr);
343 base::android::ScopedJavaGlobalRef<jobject> surface(env, content_surface_);
344 content_surface_ = nullptr;
345 return surface;
346 }
347
348 void VrShell::RestoreContentSurface(JNIEnv* env,
349 const JavaParamRef<jobject>& obj) {
350 PostToGlThreadWhenReady(
351 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl()));
352 }
353
354 void VrShell::UiSurfaceChanged(jobject surface) {
355 ui_compositor_->SurfaceChanged(surface);
356 }
357
358 void VrShell::ContentSurfaceChanged(jobject surface) {
359 content_surface_ = surface;
360 content_compositor_->SurfaceChanged(surface);
361 JNIEnv* env = base::android::AttachCurrentThread();
362 Java_VrShellImpl_contentSurfaceCreated(env, j_vr_shell_.obj());
330 } 363 }
331 364
332 void VrShell::GvrDelegateReady() { 365 void VrShell::GvrDelegateReady() {
333 delegate_provider_->SetDelegate(this, gvr_api_); 366 delegate_provider_->SetDelegate(this, gvr_api_);
334 } 367 }
335 368
336 void VrShell::AppButtonPressed() { 369 void VrShell::AppButtonPressed() {
337 #if defined(ENABLE_VR_SHELL) 370 #if defined(ENABLE_VR_SHELL)
338 html_interface_->HandleAppButtonClicked(); 371 html_interface_->HandleAppButtonClicked();
339 #endif 372 #endif
(...skipping 24 matching lines...) Expand all
364 } 397 }
365 398
366 void VrShell::UpdateScene(const base::ListValue* args) { 399 void VrShell::UpdateScene(const base::ListValue* args) {
367 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, 400 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene,
368 gl_thread_->GetVrShellGl(), 401 gl_thread_->GetVrShellGl(),
369 base::Passed(args->CreateDeepCopy()))); 402 base::Passed(args->CreateDeepCopy())));
370 } 403 }
371 404
372 void VrShell::DoUiAction(const UiAction action, 405 void VrShell::DoUiAction(const UiAction action,
373 const base::DictionaryValue* arguments) { 406 const base::DictionaryValue* arguments) {
374 content::NavigationController& controller = main_contents_->GetController(); 407 content::NavigationController* controller =
cjgrant 2017/02/10 15:21:47 For readability, it's odd to have several differen
mthiesse 2017/02/10 16:13:39 Done.
408 main_contents_ ? &main_contents_->GetController() : nullptr;
375 switch (action) { 409 switch (action) {
376 case HISTORY_BACK: 410 case HISTORY_BACK:
377 if (main_contents_->IsFullscreen()) { 411 if (main_contents_ && main_contents_->IsFullscreen()) {
378 main_contents_->ExitFullscreen(false); 412 main_contents_->ExitFullscreen(false);
379 } else if (controller.CanGoBack()) { 413 } else if (controller && controller->CanGoBack()) {
380 controller.GoBack(); 414 controller->GoBack();
381 } 415 }
382 break; 416 break;
383 case HISTORY_FORWARD: 417 case HISTORY_FORWARD:
384 if (controller.CanGoForward()) 418 if (controller && controller->CanGoForward())
385 controller.GoForward(); 419 controller->GoForward();
386 break; 420 break;
387 case RELOAD: 421 case RELOAD:
388 controller.Reload(content::ReloadType::NORMAL, false); 422 if (controller)
423 controller->Reload(content::ReloadType::NORMAL, false);
389 break; 424 break;
390 case LOAD_URL: { 425 case LOAD_URL: {
426 // TODO(mthiesse): Pass the URL up to the Tab in java and navigate there
427 // to support navigating from native pages.
428 if (!controller)
429 break;
391 std::string url_string; 430 std::string url_string;
392 CHECK(arguments->GetString("url", &url_string)); 431 CHECK(arguments->GetString("url", &url_string));
393 GURL url(url_string); 432 GURL url(url_string);
394 // TODO(crbug.com/683344): Sanitize the URL and prefix, and pass the 433 // TODO(crbug.com/683344): Sanitize the URL and prefix, and pass the
395 // proper transition type down from the UI. 434 // proper transition type down from the UI.
396 controller.LoadURL(url, content::Referrer(), 435 controller->LoadURL(url, content::Referrer(),
397 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, 436 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL,
398 std::string("")); 437 std::string(""));
399 break; 438 break;
400 } 439 }
401 case OMNIBOX_CONTENT: 440 case OMNIBOX_CONTENT:
402 html_interface_->HandleOmniboxInput(*arguments); 441 html_interface_->HandleOmniboxInput(*arguments);
403 break; 442 break;
404 case SET_CONTENT_PAUSED: { 443 case SET_CONTENT_PAUSED: {
405 bool paused; 444 bool paused;
406 CHECK(arguments->GetBoolean("paused", &paused)); 445 CHECK(arguments->GetBoolean("paused", &paused));
407 SetContentPaused(paused); 446 SetContentPaused(paused);
408 break; 447 break;
409 } 448 }
410 #if defined(ENABLE_VR_SHELL_UI_DEV) 449 #if defined(ENABLE_VR_SHELL_UI_DEV)
411 case RELOAD_UI: 450 case RELOAD_UI:
451 if (!main_contents_)
452 return;
412 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false); 453 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false);
413 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD, 454 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD,
414 main_contents_->IsFullscreen())); 455 main_contents_->IsFullscreen()));
415 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); 456 vr_web_contents_observer_->SetUiInterface(html_interface_.get());
416 break; 457 break;
417 #endif 458 #endif
418 case ZOOM_OUT: // Not handled yet. 459 case ZOOM_OUT: // Not handled yet.
419 case ZOOM_IN: // Not handled yet. 460 case ZOOM_IN: // Not handled yet.
420 break; 461 break;
421 default: 462 default:
422 NOTREACHED(); 463 NOTREACHED();
423 } 464 }
424 } 465 }
425 466
426 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 467 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
427 content::RenderViewHost* new_host) { 468 content::RenderViewHost* new_host) {
428 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); 469 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
429 } 470 }
430 471
431 void VrShell::MainFrameWasResized(bool width_changed) { 472 void VrShell::MainFrameWasResized(bool width_changed) {
432 display::Display display = display::Screen::GetScreen() 473 display::Display display = display::Screen::GetScreen()
433 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); 474 ->GetDisplayNearestWindow(ui_contents_->GetNativeView());
434 PostToGlThreadWhenReady( 475 PostToGlThreadWhenReady(
435 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(), 476 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(),
436 display.size().width(), display.size().height())); 477 display.size().width(), display.size().height()));
437 } 478 }
438 479
439 void VrShell::ContentFrameWasResized(bool width_changed) { 480 void VrShell::ContentFrameWasResized(bool width_changed) {
440 display::Display display = display::Screen::GetScreen() 481 display::Display display =
441 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); 482 display::Screen::GetScreen()->GetDisplayNearestWindow(content_window_);
442 PostToGlThreadWhenReady( 483 PostToGlThreadWhenReady(
443 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(), 484 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(),
444 display.size().width(), display.size().height())); 485 display.size().width(), display.size().height()));
445 } 486 }
446 487
447 void VrShell::WebContentsDestroyed() { 488 void VrShell::WebContentsDestroyed() {
448 ui_input_manager_.reset(); 489 ui_input_manager_.reset();
449 ui_contents_ = nullptr; 490 ui_contents_ = nullptr;
450 // TODO(mthiesse): Handle web contents being destroyed. 491 // TODO(mthiesse): Handle web contents being destroyed.
451 ForceExitVr(); 492 ForceExitVr();
452 } 493 }
453 494
454 void VrShell::ContentWebContentsDestroyed() { 495 void VrShell::ContentWebContentsDestroyed() {
455 content_input_manager_.reset(); 496 content_input_manager_.reset();
456 main_contents_ = nullptr; 497 main_contents_ = nullptr;
457 // TODO(mthiesse): Handle web contents being destroyed. 498 // TODO(mthiesse): Handle web contents being destroyed.
458 ForceExitVr(); 499 ForceExitVr();
459 } 500 }
460 501
461 void VrShell::ContentWasHidden() { 502 void VrShell::ContentWasHidden() {
462 // Ensure we don't continue sending input to it. 503 // Ensure we don't continue sending input to it.
463 content_input_manager_ = nullptr; 504 content_input_manager_ = nullptr;
464 } 505 }
465 506
466 void VrShell::ContentWasShown() { 507 void VrShell::ContentWasShown() {
467 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 508 if (main_contents_)
509 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
468 } 510 }
469 511
470 void VrShell::ForceExitVr() { 512 void VrShell::ForceExitVr() {
471 JNIEnv* env = base::android::AttachCurrentThread(); 513 JNIEnv* env = base::android::AttachCurrentThread();
472 Java_VrShellImpl_forceExitVr(env, j_vr_shell_.obj()); 514 Java_VrShellImpl_forceExitVr(env, j_vr_shell_.obj());
473 } 515 }
474 516
475 void VrShell::OnVRVsyncProviderRequest( 517 void VrShell::OnVRVsyncProviderRequest(
476 device::mojom::VRVSyncProviderRequest request) { 518 device::mojom::VRVSyncProviderRequest request) {
477 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, 519 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 eye_params->offset[2] = -eye_mat.m[2][3]; 630 eye_params->offset[2] = -eye_mat.m[2][3];
589 } 631 }
590 632
591 return device; 633 return device;
592 } 634 }
593 635
594 // ---------------------------------------------------------------------------- 636 // ----------------------------------------------------------------------------
595 // Native JNI methods 637 // Native JNI methods
596 // ---------------------------------------------------------------------------- 638 // ----------------------------------------------------------------------------
597 639
598 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 640 jlong Init(JNIEnv* env,
599 const JavaParamRef<jobject>& content_web_contents, 641 const JavaParamRef<jobject>& obj,
642 const JavaParamRef<jobject>& ui_web_contents,
600 jlong content_window_android, 643 jlong content_window_android,
601 const JavaParamRef<jobject>& ui_web_contents, 644 jlong ui_window_android,
602 jlong ui_window_android, jboolean for_web_vr, 645 jboolean for_web_vr,
603 const base::android::JavaParamRef<jobject>& delegate, 646 const base::android::JavaParamRef<jobject>& delegate,
604 jlong gvr_api, jboolean reprojected_rendering) { 647 jlong gvr_api,
648 jboolean reprojected_rendering) {
605 return reinterpret_cast<intptr_t>(new VrShell( 649 return reinterpret_cast<intptr_t>(new VrShell(
606 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 650 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
607 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
608 content::WebContents::FromJavaWebContents(ui_web_contents), 651 content::WebContents::FromJavaWebContents(ui_web_contents),
609 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 652 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
610 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 653 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
611 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 654 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
612 } 655 }
613 656
614 } // namespace vr_shell 657 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698