| 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_gl_thread.h" | 5 #include "chrome/browser/android/vr_shell/vr_gl_thread.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 10 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" | 11 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
| 11 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | 12 #include "chrome/browser/android/vr_shell/vr_input_manager.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_shell.h" | 13 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" | 14 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 14 | 15 |
| 15 namespace vr_shell { | 16 namespace vr_shell { |
| 16 | 17 |
| 17 VrGLThread::VrGLThread( | 18 VrGLThread::VrGLThread( |
| 18 const base::WeakPtr<VrShell>& weak_vr_shell, | 19 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 19 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 20 gvr_context* gvr_api, | 21 gvr_context* gvr_api, |
| 21 bool initially_web_vr, | 22 bool initially_web_vr, |
| 22 bool reprojected_rendering) | 23 bool reprojected_rendering) |
| 23 : base::Thread("VrShellGL"), | 24 : base::Thread("VrShellGL"), |
| 24 weak_vr_shell_(weak_vr_shell), | 25 weak_vr_shell_(weak_vr_shell), |
| 25 main_thread_task_runner_(std::move(main_thread_task_runner)), | 26 main_thread_task_runner_(std::move(main_thread_task_runner)), |
| 26 gvr_api_(gvr_api), | 27 gvr_api_(gvr_api), |
| 27 initially_web_vr_(initially_web_vr), | 28 initially_web_vr_(initially_web_vr), |
| 28 reprojected_rendering_(reprojected_rendering) {} | 29 reprojected_rendering_(reprojected_rendering), |
| 30 weak_ptr_factory_(this) {} |
| 29 | 31 |
| 30 VrGLThread::~VrGLThread() { | 32 VrGLThread::~VrGLThread() { |
| 31 Stop(); | 33 Stop(); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void VrGLThread::Init() { | 36 void VrGLThread::Init() { |
| 35 scene_ = base::MakeUnique<UiScene>(); | 37 scene_ = base::MakeUnique<UiScene>(); |
| 36 vr_shell_gl_ = base::MakeUnique<VrShellGl>( | 38 vr_shell_gl_ = base::MakeUnique<VrShellGl>( |
| 37 std::move(weak_vr_shell_), std::move(main_thread_task_runner_), gvr_api_, | 39 weak_ptr_factory_.GetWeakPtr(), gvr_api_, initially_web_vr_, |
| 38 initially_web_vr_, reprojected_rendering_, scene_.get()); | 40 reprojected_rendering_, scene_.get()); |
| 39 scene_manager_ = base::MakeUnique<UiSceneManager>(scene_.get()); | 41 scene_manager_ = base::MakeUnique<UiSceneManager>( |
| 42 weak_ptr_factory_.GetWeakPtr(), scene_.get()); |
| 40 | 43 |
| 41 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); | 44 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); |
| 42 weak_scene_manager_ = scene_manager_->GetWeakPtr(); | 45 weak_scene_manager_ = scene_manager_->GetWeakPtr(); |
| 43 vr_shell_gl_->Initialize(); | 46 vr_shell_gl_->Initialize(); |
| 44 } | 47 } |
| 45 | 48 |
| 49 void VrGLThread::ContentSurfaceChanged(jobject surface) { |
| 50 main_thread_task_runner_->PostTask( |
| 51 FROM_HERE, |
| 52 base::Bind(&VrShell::ContentSurfaceChanged, weak_vr_shell_, surface)); |
| 53 } |
| 54 |
| 55 void VrGLThread::GvrDelegateReady() { |
| 56 main_thread_task_runner_->PostTask( |
| 57 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); |
| 58 } |
| 59 |
| 60 void VrGLThread::UpdateGamepadData(device::GvrGamepadData pad) { |
| 61 main_thread_task_runner_->PostTask( |
| 62 FROM_HERE, base::Bind(&VrShell::UpdateGamepadData, weak_vr_shell_, pad)); |
| 63 } |
| 64 |
| 65 void VrGLThread::AppButtonGesturePerformed(UiInterface::Direction direction) { |
| 66 main_thread_task_runner_->PostTask( |
| 67 FROM_HERE, base::Bind(&VrShell::AppButtonGesturePerformed, weak_vr_shell_, |
| 68 direction)); |
| 69 } |
| 70 |
| 71 void VrGLThread::OnAppButtonClicked() { |
| 72 weak_vr_shell_gl_->GetTaskRunner()->PostTask( |
| 73 FROM_HERE, |
| 74 base::Bind(&UiSceneManager::OnAppButtonClicked, weak_scene_manager_)); |
| 75 } |
| 76 |
| 77 void VrGLThread::ProcessContentGesture( |
| 78 std::unique_ptr<blink::WebInputEvent> event) { |
| 79 main_thread_task_runner_->PostTask( |
| 80 FROM_HERE, base::Bind(&VrShell::ProcessContentGesture, weak_vr_shell_, |
| 81 base::Passed(std::move(event)))); |
| 82 } |
| 83 |
| 84 void VrGLThread::ForceExitVr() { |
| 85 main_thread_task_runner_->PostTask( |
| 86 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); |
| 87 } |
| 88 |
| 89 void VrGLThread::RunVRDisplayInfoCallback( |
| 90 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 91 device::mojom::VRDisplayInfoPtr* info) { |
| 92 main_thread_task_runner_->PostTask(FROM_HERE, |
| 93 base::Bind(callback, base::Passed(info))); |
| 94 } |
| 95 |
| 96 void VrGLThread::OnContentPaused(bool enabled) { |
| 97 main_thread_task_runner_->PostTask( |
| 98 FROM_HERE, |
| 99 base::Bind(&VrShell::OnContentPaused, weak_vr_shell_, enabled)); |
| 100 } |
| 101 |
| 46 void VrGLThread::CleanUp() { | 102 void VrGLThread::CleanUp() { |
| 47 scene_manager_.reset(); | 103 scene_manager_.reset(); |
| 48 vr_shell_gl_.reset(); | 104 vr_shell_gl_.reset(); |
| 49 scene_.reset(); | 105 scene_.reset(); |
| 50 } | 106 } |
| 51 | 107 |
| 52 } // namespace vr_shell | 108 } // namespace vr_shell |
| OLD | NEW |