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

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

Powered by Google App Engine
This is Rietveld 408576698