| 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_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "chrome/browser/android/vr_shell/ui_elements.h" | 11 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 12 #include "chrome/browser/android/vr_shell/ui_scene.h" | 12 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_controller.h" | 13 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 14 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 15 #include "chrome/browser/android/vr_shell/vr_input_manager.h" | |
| 16 #include "chrome/browser/android/vr_shell/vr_math.h" | 15 #include "chrome/browser/android/vr_shell/vr_math.h" |
| 17 #include "chrome/browser/android/vr_shell/vr_shell.h" | 16 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 18 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 17 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 19 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 18 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 19 #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| 20 #include "ui/gfx/vsync_provider.h" | 20 #include "ui/gfx/vsync_provider.h" |
| 21 #include "ui/gl/android/scoped_java_surface.h" | 21 #include "ui/gl/android/scoped_java_surface.h" |
| 22 #include "ui/gl/android/surface_texture.h" | 22 #include "ui/gl/android/surface_texture.h" |
| 23 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
| 24 #include "ui/gl/gl_context.h" | 24 #include "ui/gl/gl_context.h" |
| 25 #include "ui/gl/gl_surface.h" | 25 #include "ui/gl/gl_surface.h" |
| 26 #include "ui/gl/init/gl_factory.h" | 26 #include "ui/gl/init/gl_factory.h" |
| 27 | 27 |
| 28 namespace vr_shell { | 28 namespace vr_shell { |
| 29 | 29 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 173 } |
| 174 | 174 |
| 175 void WaitForSwapAck(const base::Closure& callback, gfx::SwapResult result) { | 175 void WaitForSwapAck(const base::Closure& callback, gfx::SwapResult result) { |
| 176 callback.Run(); | 176 callback.Run(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 VrShellGl::VrShellGl( | 181 VrShellGl::VrShellGl( |
| 182 const base::WeakPtr<VrShell>& weak_vr_shell, | 182 const base::WeakPtr<VrShell>& weak_vr_shell, |
| 183 const base::WeakPtr<VrInputManager>& content_input_manager, | |
| 184 const base::WeakPtr<VrInputManager>& ui_input_manager, | |
| 185 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 183 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
| 186 gvr_context* gvr_api, | 184 gvr_context* gvr_api, |
| 187 bool initially_web_vr, | 185 bool initially_web_vr, |
| 188 bool reprojected_rendering) | 186 bool reprojected_rendering) |
| 189 : web_vr_mode_(initially_web_vr), | 187 : web_vr_mode_(initially_web_vr), |
| 190 surfaceless_rendering_(reprojected_rendering), | 188 surfaceless_rendering_(reprojected_rendering), |
| 191 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 189 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 192 weak_vr_shell_(weak_vr_shell), | 190 weak_vr_shell_(weak_vr_shell), |
| 193 content_input_manager_(content_input_manager), | |
| 194 ui_input_manager_(ui_input_manager), | |
| 195 main_thread_task_runner_(std::move(main_thread_task_runner)), | 191 main_thread_task_runner_(std::move(main_thread_task_runner)), |
| 196 weak_ptr_factory_(this) { | 192 weak_ptr_factory_(this) { |
| 197 GvrInit(gvr_api); | 193 GvrInit(gvr_api); |
| 198 } | 194 } |
| 199 | 195 |
| 200 VrShellGl::~VrShellGl() { | 196 VrShellGl::~VrShellGl() { |
| 201 draw_task_.Cancel(); | 197 draw_task_.Cancel(); |
| 202 } | 198 } |
| 203 | 199 |
| 204 void VrShellGl::Initialize() { | 200 void VrShellGl::Initialize() { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 WebInputEvent::Type type = | 569 WebInputEvent::Type type = |
| 574 new_target ? WebInputEvent::MouseEnter : WebInputEvent::MouseMove; | 570 new_target ? WebInputEvent::MouseEnter : WebInputEvent::MouseMove; |
| 575 SendGesture(input_target, | 571 SendGesture(input_target, |
| 576 MakeMouseEvent(type, timestamp, pixel_x, pixel_y)); | 572 MakeMouseEvent(type, timestamp, pixel_x, pixel_y)); |
| 577 } | 573 } |
| 578 } | 574 } |
| 579 | 575 |
| 580 void VrShellGl::SendGesture(InputTarget input_target, | 576 void VrShellGl::SendGesture(InputTarget input_target, |
| 581 std::unique_ptr<blink::WebInputEvent> event) { | 577 std::unique_ptr<blink::WebInputEvent> event) { |
| 582 DCHECK(input_target != InputTarget::NONE); | 578 DCHECK(input_target != InputTarget::NONE); |
| 583 const base::WeakPtr<VrInputManager>& weak_ptr = | 579 auto&& target = input_target == InputTarget::CONTENT |
| 584 input_target == InputTarget::CONTENT ? content_input_manager_ | 580 ? &VrShell::ProcessContentGesture |
| 585 : ui_input_manager_; | 581 : &VrShell::ProcessUIGesture; |
| 586 main_thread_task_runner_->PostTask( | 582 main_thread_task_runner_->PostTask( |
| 587 FROM_HERE, | 583 FROM_HERE, |
| 588 base::Bind(&VrInputManager::ProcessUpdatedGesture, weak_ptr, | 584 base::Bind(target, weak_vr_shell_, base::Passed(std::move(event)))); |
| 589 base::Passed(std::move(event)))); | |
| 590 } | 585 } |
| 591 | 586 |
| 592 void VrShellGl::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | 587 void VrShellGl::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
| 593 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; | 588 webvr_head_pose_[pose_num % kPoseRingBufferSize] = pose; |
| 594 webvr_head_pose_valid_[pose_num % kPoseRingBufferSize] = true; | 589 webvr_head_pose_valid_[pose_num % kPoseRingBufferSize] = true; |
| 595 } | 590 } |
| 596 | 591 |
| 597 bool VrShellGl::WebVrPoseByteIsValid(int pose_index_byte) { | 592 bool VrShellGl::WebVrPoseByteIsValid(int pose_index_byte) { |
| 598 if (pose_index_byte < 0) { | 593 if (pose_index_byte < 0) { |
| 599 return false; | 594 return false; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 void VrShellGl::ForceExitVr() { | 987 void VrShellGl::ForceExitVr() { |
| 993 main_thread_task_runner_->PostTask( | 988 main_thread_task_runner_->PostTask( |
| 994 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); | 989 FROM_HERE, base::Bind(&VrShell::ForceExitVr, weak_vr_shell_)); |
| 995 } | 990 } |
| 996 | 991 |
| 997 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { | 992 void VrShellGl::UpdateScene(std::unique_ptr<base::ListValue> commands) { |
| 998 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); | 993 scene_->HandleCommands(std::move(commands), TimeInMicroseconds()); |
| 999 } | 994 } |
| 1000 | 995 |
| 1001 } // namespace vr_shell | 996 } // namespace vr_shell |
| OLD | NEW |