Chromium Code Reviews| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 510 |
| 506 void VrShell::OnVRVsyncProviderRequest( | 511 void VrShell::OnVRVsyncProviderRequest( |
| 507 device::mojom::VRVSyncProviderRequest request) { | 512 device::mojom::VRVSyncProviderRequest request) { |
| 508 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, | 513 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, |
| 509 gl_thread_->GetVrShellGl(), | 514 gl_thread_->GetVrShellGl(), |
| 510 base::Passed(&request))); | 515 base::Passed(&request))); |
| 511 } | 516 } |
| 512 | 517 |
| 513 void VrShell::UpdateVSyncInterval(int64_t timebase_nanos, | 518 void VrShell::UpdateVSyncInterval(int64_t timebase_nanos, |
| 514 double interval_seconds) { | 519 double interval_seconds) { |
| 520 PollMediaAccessFlag(); | |
| 515 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateVSyncInterval, | 521 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateVSyncInterval, |
| 516 gl_thread_->GetVrShellGl(), timebase_nanos, | 522 gl_thread_->GetVrShellGl(), timebase_nanos, |
| 517 interval_seconds)); | 523 interval_seconds)); |
| 518 } | 524 } |
| 519 | 525 |
| 526 void VrShell::PollMediaAccessFlag() { | |
| 527 poll_capturing_media_task_.Cancel(); | |
| 528 | |
| 529 poll_capturing_media_task_.Reset(base::Bind(&VrShell::PollMediaAccessFlag, | |
| 530 weak_ptr_factory_.GetWeakPtr())); | |
|
mthiesse
2017/05/12 22:43:59
No need for weakptr, just cancel the callback in t
asimjour1
2017/05/12 22:57:04
Done.
| |
| 531 main_thread_task_runner_->PostDelayedTask( | |
| 532 FROM_HERE, poll_capturing_media_task_.callback(), | |
| 533 poll_media_access_interval_); | |
| 534 | |
| 535 scoped_refptr<MediaStreamCaptureIndicator> indicator = | |
| 536 MediaCaptureDevicesDispatcher::GetInstance() | |
| 537 ->GetMediaStreamCaptureIndicator(); | |
| 538 bool is_capturing_audio = indicator->IsCapturingAudio(web_contents_); | |
| 539 if (is_capturing_audio != is_capturing_audio_) | |
| 540 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetAudioCapturingWarning, | |
| 541 gl_thread_->GetVrShellGl(), | |
| 542 is_capturing_audio)); | |
| 543 is_capturing_audio_ = is_capturing_audio; | |
| 544 | |
| 545 bool is_capturing_video = indicator->IsCapturingVideo(web_contents_); | |
| 546 if (is_capturing_video != is_capturing_video_) | |
| 547 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetVideoCapturingWarning, | |
| 548 gl_thread_->GetVrShellGl(), | |
| 549 is_capturing_video)); | |
| 550 is_capturing_video_ = is_capturing_video; | |
| 551 | |
| 552 bool is_capturing_screen = indicator->IsBeingMirrored(web_contents_); | |
| 553 if (is_capturing_screen != is_capturing_screen_) | |
| 554 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetScreenCapturingWarning, | |
| 555 gl_thread_->GetVrShellGl(), | |
| 556 is_capturing_screen)); | |
| 557 is_capturing_screen_ = is_capturing_screen; | |
| 558 } | |
| 559 | |
| 520 void VrShell::SetContentCssSize(float width, float height, float dpr) { | 560 void VrShell::SetContentCssSize(float width, float height, float dpr) { |
| 521 JNIEnv* env = base::android::AttachCurrentThread(); | 561 JNIEnv* env = base::android::AttachCurrentThread(); |
| 522 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, | 562 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, |
| 523 dpr); | 563 dpr); |
| 524 } | 564 } |
| 525 | 565 |
| 526 void VrShell::ProcessContentGesture( | 566 void VrShell::ProcessContentGesture( |
| 527 std::unique_ptr<blink::WebInputEvent> event) { | 567 std::unique_ptr<blink::WebInputEvent> event) { |
| 528 if (input_manager_) { | 568 if (input_manager_) { |
| 529 input_manager_->ProcessUpdatedGesture(std::move(event)); | 569 input_manager_->ProcessUpdatedGesture(std::move(event)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 jboolean for_web_vr, | 605 jboolean for_web_vr, |
| 566 jlong gvr_api, | 606 jlong gvr_api, |
| 567 jboolean reprojected_rendering) { | 607 jboolean reprojected_rendering) { |
| 568 return reinterpret_cast<intptr_t>(new VrShell( | 608 return reinterpret_cast<intptr_t>(new VrShell( |
| 569 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), | 609 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 570 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 610 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 571 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 611 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 572 } | 612 } |
| 573 | 613 |
| 574 } // namespace vr_shell | 614 } // namespace vr_shell |
| OLD | NEW |