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 #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 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/android/vr_shell/ui_interface.h" | 23 #include "chrome/browser/android/vr_shell/ui_interface.h" |
24 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" | 24 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
25 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 25 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
26 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | 26 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
27 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" | 27 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
28 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 28 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
29 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 29 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
30 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 30 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
31 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 31 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
32 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" | 32 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 33 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 34 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/navigation_controller.h" | 36 #include "content/public/browser/navigation_controller.h" |
35 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/render_widget_host.h" | 38 #include "content/public/browser/render_widget_host.h" |
37 #include "content/public/browser/render_widget_host_view.h" | 39 #include "content/public/browser/render_widget_host_view.h" |
38 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
39 #include "content/public/common/content_features.h" | 41 #include "content/public/common/content_features.h" |
40 #include "content/public/common/referrer.h" | 42 #include "content/public/common/referrer.h" |
41 #include "device/vr/android/gvr/gvr_device.h" | 43 #include "device/vr/android/gvr/gvr_device.h" |
42 #include "device/vr/android/gvr/gvr_device_provider.h" | 44 #include "device/vr/android/gvr/gvr_device_provider.h" |
(...skipping 11 matching lines...) Expand all Loading... |
54 #include "ui/gfx/native_widget_types.h" | 56 #include "ui/gfx/native_widget_types.h" |
55 | 57 |
56 using base::android::JavaParamRef; | 58 using base::android::JavaParamRef; |
57 using base::android::JavaRef; | 59 using base::android::JavaRef; |
58 | 60 |
59 namespace vr_shell { | 61 namespace vr_shell { |
60 | 62 |
61 namespace { | 63 namespace { |
62 vr_shell::VrShell* g_instance; | 64 vr_shell::VrShell* g_instance; |
63 | 65 |
| 66 constexpr base::TimeDelta poll_media_access_interval_ = |
| 67 base::TimeDelta::FromSecondsD(0.01); |
| 68 |
64 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { | 69 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { |
65 if (contents && contents->GetRenderWidgetHostView()) | 70 if (contents && contents->GetRenderWidgetHostView()) |
66 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); | 71 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); |
67 } | 72 } |
68 | 73 |
69 void LoadControllerModelTask( | 74 void LoadControllerModelTask( |
70 base::WeakPtr<VrShell> weak_vr_shell, | 75 base::WeakPtr<VrShell> weak_vr_shell, |
71 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { | 76 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
72 auto controller_model = VrControllerModel::LoadFromComponent(); | 77 auto controller_model = VrControllerModel::LoadFromComponent(); |
73 if (controller_model) { | 78 if (controller_model) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 ui_->SetFullscreen(web_contents_->IsFullscreen()); | 175 ui_->SetFullscreen(web_contents_->IsFullscreen()); |
171 } | 176 } |
172 } | 177 } |
173 | 178 |
174 bool RegisterVrShell(JNIEnv* env) { | 179 bool RegisterVrShell(JNIEnv* env) { |
175 return RegisterNativesImpl(env); | 180 return RegisterNativesImpl(env); |
176 } | 181 } |
177 | 182 |
178 VrShell::~VrShell() { | 183 VrShell::~VrShell() { |
179 DVLOG(1) << __FUNCTION__ << "=" << this; | 184 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 185 poll_capturing_media_task_.Cancel(); |
180 if (gamepad_source_active_) { | 186 if (gamepad_source_active_) { |
181 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( | 187 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
182 device::GAMEPAD_SOURCE_GVR); | 188 device::GAMEPAD_SOURCE_GVR); |
183 } | 189 } |
184 | 190 |
185 delegate_provider_->RemoveDelegate(); | 191 delegate_provider_->RemoveDelegate(); |
186 { | 192 { |
187 // The GvrLayout is, and must always be, used only on the UI thread, and the | 193 // The GvrLayout is, and must always be, used only on the UI thread, and the |
188 // GvrApi used for rendering should only be used from the GL thread as it's | 194 // GvrApi used for rendering should only be used from the GL thread as it's |
189 // not thread safe. However, the GvrLayout owns the GvrApi instance, and | 195 // not thread safe. However, the GvrLayout owns the GvrApi instance, and |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 511 |
506 void VrShell::OnVRVsyncProviderRequest( | 512 void VrShell::OnVRVsyncProviderRequest( |
507 device::mojom::VRVSyncProviderRequest request) { | 513 device::mojom::VRVSyncProviderRequest request) { |
508 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, | 514 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, |
509 gl_thread_->GetVrShellGl(), | 515 gl_thread_->GetVrShellGl(), |
510 base::Passed(&request))); | 516 base::Passed(&request))); |
511 } | 517 } |
512 | 518 |
513 void VrShell::UpdateVSyncInterval(int64_t timebase_nanos, | 519 void VrShell::UpdateVSyncInterval(int64_t timebase_nanos, |
514 double interval_seconds) { | 520 double interval_seconds) { |
| 521 PollMediaAccessFlag(); |
515 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateVSyncInterval, | 522 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateVSyncInterval, |
516 gl_thread_->GetVrShellGl(), timebase_nanos, | 523 gl_thread_->GetVrShellGl(), timebase_nanos, |
517 interval_seconds)); | 524 interval_seconds)); |
518 } | 525 } |
519 | 526 |
| 527 void VrShell::PollMediaAccessFlag() { |
| 528 poll_capturing_media_task_.Cancel(); |
| 529 |
| 530 poll_capturing_media_task_.Reset( |
| 531 base::Bind(&VrShell::PollMediaAccessFlag, base::Unretained(this))); |
| 532 main_thread_task_runner_->PostDelayedTask( |
| 533 FROM_HERE, poll_capturing_media_task_.callback(), |
| 534 poll_media_access_interval_); |
| 535 |
| 536 scoped_refptr<MediaStreamCaptureIndicator> indicator = |
| 537 MediaCaptureDevicesDispatcher::GetInstance() |
| 538 ->GetMediaStreamCaptureIndicator(); |
| 539 bool is_capturing_audio = indicator->IsCapturingAudio(web_contents_); |
| 540 if (is_capturing_audio != is_capturing_audio_) |
| 541 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetAudioCapturingWarning, |
| 542 gl_thread_->GetVrShellGl(), |
| 543 is_capturing_audio)); |
| 544 is_capturing_audio_ = is_capturing_audio; |
| 545 |
| 546 bool is_capturing_video = indicator->IsCapturingVideo(web_contents_); |
| 547 if (is_capturing_video != is_capturing_video_) |
| 548 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetVideoCapturingWarning, |
| 549 gl_thread_->GetVrShellGl(), |
| 550 is_capturing_video)); |
| 551 is_capturing_video_ = is_capturing_video; |
| 552 |
| 553 bool is_capturing_screen = indicator->IsBeingMirrored(web_contents_); |
| 554 if (is_capturing_screen != is_capturing_screen_) |
| 555 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetScreenCapturingWarning, |
| 556 gl_thread_->GetVrShellGl(), |
| 557 is_capturing_screen)); |
| 558 is_capturing_screen_ = is_capturing_screen; |
| 559 } |
| 560 |
520 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 561 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
521 JNIEnv* env = base::android::AttachCurrentThread(); | 562 JNIEnv* env = base::android::AttachCurrentThread(); |
522 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 563 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
523 dpr); | 564 dpr); |
524 } | 565 } |
525 | 566 |
526 void VrShell::ProcessContentGesture( | 567 void VrShell::ProcessContentGesture( |
527 std::unique_ptr<blink::WebInputEvent> event) { | 568 std::unique_ptr<blink::WebInputEvent> event) { |
528 if (input_manager_) { | 569 if (input_manager_) { |
529 input_manager_->ProcessUpdatedGesture(std::move(event)); | 570 input_manager_->ProcessUpdatedGesture(std::move(event)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 jboolean for_web_vr, | 606 jboolean for_web_vr, |
566 jlong gvr_api, | 607 jlong gvr_api, |
567 jboolean reprojected_rendering) { | 608 jboolean reprojected_rendering) { |
568 return reinterpret_cast<intptr_t>(new VrShell( | 609 return reinterpret_cast<intptr_t>(new VrShell( |
569 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 610 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
570 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 611 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
571 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 612 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
572 } | 613 } |
573 | 614 |
574 } // namespace vr_shell | 615 } // namespace vr_shell |
OLD | NEW |