| 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) {} |
| 29 | 30 |
| 30 VrGLThread::~VrGLThread() { | 31 VrGLThread::~VrGLThread() { |
| 31 Stop(); | 32 Stop(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void VrGLThread::Init() { | 35 void VrGLThread::Init() { |
| 35 scene_ = base::MakeUnique<UiScene>(); | 36 scene_ = base::MakeUnique<UiScene>(); |
| 36 vr_shell_gl_ = base::MakeUnique<VrShellGl>( | 37 vr_shell_gl_ = base::MakeUnique<VrShellGl>( |
| 37 std::move(weak_vr_shell_), std::move(main_thread_task_runner_), gvr_api_, | 38 this, gvr_api_, initially_web_vr_, reprojected_rendering_, scene_.get()); |
| 38 initially_web_vr_, reprojected_rendering_, scene_.get()); | 39 scene_manager_ = base::MakeUnique<UiSceneManager>(this, scene_.get()); |
| 39 scene_manager_ = base::MakeUnique<UiSceneManager>(scene_.get()); | |
| 40 | 40 |
| 41 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); | 41 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); |
| 42 weak_scene_manager_ = scene_manager_->GetWeakPtr(); | 42 weak_scene_manager_ = scene_manager_->GetWeakPtr(); |
| 43 vr_shell_gl_->Initialize(); | 43 vr_shell_gl_->Initialize(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void VrGLThread::ContentSurfaceChanged(jobject surface) { |
| 47 main_thread_task_runner_->PostTask( |
| 48 FROM_HERE, |
| 49 base::Bind(&VrShell::ContentSurfaceChanged, weak_vr_shell_, surface)); |
| 50 } |
| 51 |
| 52 void VrGLThread::GvrDelegateReady() { |
| 53 main_thread_task_runner_->PostTask( |
| 54 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); |
| 55 } |
| 56 |
| 57 void VrGLThread::UpdateGamepadData(device::GvrGamepadData pad) { |
| 58 main_thread_task_runner_->PostTask( |
| 59 FROM_HERE, base::Bind(&VrShell::UpdateGamepadData, weak_vr_shell_, pad)); |
| 60 } |
| 61 |
| 62 void VrGLThread::AppButtonGesturePerformed(UiInterface::Direction direction) { |
| 63 main_thread_task_runner_->PostTask( |
| 64 FROM_HERE, base::Bind(&VrShell::AppButtonGesturePerformed, weak_vr_shell_, |
| 65 direction)); |
| 66 } |
| 67 |
| 68 void VrGLThread::OnAppButtonClicked() { |
| 69 weak_vr_shell_gl_->GetTaskRunner()->PostTask( |
| 70 FROM_HERE, |
| 71 base::Bind(&UiSceneManager::OnAppButtonClicked, weak_scene_manager_)); |
| 72 } |
| 73 |
| 74 void VrGLThread::ProcessContentGesture( |
| 75 std::unique_ptr<blink::WebInputEvent> event) { |
| 76 main_thread_task_runner_->PostTask( |
| 77 FROM_HERE, base::Bind(&VrShell::ProcessContentGesture, weak_vr_shell_, |
| 78 base::Passed(std::move(event)))); |
| 79 } |
| 80 |
| 81 void VrGLThread::ForceExitVr() { |
| 82 main_thread_task_runner_->PostTask( |
| 83 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); |
| 84 } |
| 85 |
| 86 void VrGLThread::RunVRDisplayInfoCallback( |
| 87 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, |
| 88 device::mojom::VRDisplayInfoPtr* info) { |
| 89 main_thread_task_runner_->PostTask(FROM_HERE, |
| 90 base::Bind(callback, base::Passed(info))); |
| 91 } |
| 92 |
| 93 void VrGLThread::OnContentPaused(bool enabled) { |
| 94 main_thread_task_runner_->PostTask( |
| 95 FROM_HERE, |
| 96 base::Bind(&VrShell::OnContentPaused, weak_vr_shell_, enabled)); |
| 97 } |
| 98 |
| 46 void VrGLThread::CleanUp() { | 99 void VrGLThread::CleanUp() { |
| 47 scene_manager_.reset(); | 100 scene_manager_.reset(); |
| 48 vr_shell_gl_.reset(); | 101 vr_shell_gl_.reset(); |
| 49 scene_.reset(); | 102 scene_.reset(); |
| 50 } | 103 } |
| 51 | 104 |
| 52 } // namespace vr_shell | 105 } // namespace vr_shell |
| OLD | NEW |