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_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" | 15 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" |
| 16 #include "chrome/browser/android/vr_shell/ui_elements.h" | 16 #include "chrome/browser/android/vr_shell/ui_elements.h" |
| 17 #include "chrome/browser/android/vr_shell/ui_interface.h" | 17 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 18 #include "chrome/browser/android/vr_shell/ui_scene.h" | 18 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 19 #include "chrome/browser/android/vr_shell/vr_controller.h" | 19 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 20 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 20 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 21 #include "chrome/browser/android/vr_shell/vr_math.h" | 21 #include "chrome/browser/android/vr_shell/vr_math.h" |
| 22 #include "chrome/browser/android/vr_shell/vr_shell.h" | 22 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 23 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" | 23 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" |
| 24 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 24 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 25 #include "device/vr/android/gvr/gvr_device.h" | 25 #include "device/vr/android/gvr/gvr_device.h" |
| 26 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" | |
| 26 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 27 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 27 #include "third_party/WebKit/public/platform/WebMouseEvent.h" | 28 #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| 28 #include "ui/gl/android/scoped_java_surface.h" | 29 #include "ui/gl/android/scoped_java_surface.h" |
| 29 #include "ui/gl/android/surface_texture.h" | 30 #include "ui/gl/android/surface_texture.h" |
| 30 #include "ui/gl/gl_bindings.h" | 31 #include "ui/gl/gl_bindings.h" |
| 31 #include "ui/gl/gl_context.h" | 32 #include "ui/gl/gl_context.h" |
| 32 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
| 33 #include "ui/gl/init/gl_factory.h" | 34 #include "ui/gl/init/gl_factory.h" |
| 34 | 35 |
| 35 namespace vr_shell { | 36 namespace vr_shell { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 webvr_right_viewport_.reset( | 466 webvr_right_viewport_.reset( |
| 466 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); | 467 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); |
| 467 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, | 468 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, |
| 468 webvr_right_viewport_.get()); | 469 webvr_right_viewport_.get()); |
| 469 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); | 470 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); |
| 470 | 471 |
| 471 main_thread_task_runner_->PostTask( | 472 main_thread_task_runner_->PostTask( |
| 472 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); | 473 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); |
| 473 } | 474 } |
| 474 | 475 |
| 475 void VrShellGl::UpdateController(const gvr::Vec3f& forward_vector) { | 476 void VrShellGl::UpdateController() { |
| 476 controller_->UpdateState(); | 477 controller_->UpdateState(); |
| 477 | 478 |
| 479 device::GvrGamepadData pad = controller_->GetGamepadData(); | |
| 480 main_thread_task_runner_->PostTask( | |
| 481 FROM_HERE, base::Bind(&VrShell::GamepadDataUpdate, weak_vr_shell_, pad)); | |
| 482 } | |
| 483 | |
| 484 void VrShellGl::HandleControllerInput(const gvr::Vec3f& forward_vector) { | |
| 478 if (web_vr_mode_) { | 485 if (web_vr_mode_) { |
| 479 // Process screen touch events for Cardboard button compatibility. | 486 // Process screen touch events for Cardboard button compatibility. |
| 480 // Also send tap events for controller "touchpad click" events. | 487 // Also send tap events for controller "touchpad click" events. |
| 481 if (touch_pending_ || | 488 if (touch_pending_ || |
| 482 controller_->ButtonUpHappened( | 489 controller_->ButtonUpHappened( |
| 483 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { | 490 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { |
| 484 touch_pending_ = false; | 491 touch_pending_ = false; |
| 485 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent( | 492 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent( |
| 486 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, | 493 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, |
| 487 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF())); | 494 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF())); |
| 488 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; | 495 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; |
| 489 gesture->x = 0; | 496 gesture->x = 0; |
| 490 gesture->y = 0; | 497 gesture->y = 0; |
| 491 SendGesture(InputTarget::CONTENT, std::move(gesture)); | 498 SendGesture(InputTarget::CONTENT, std::move(gesture)); |
| 499 DVLOG(1) << __FUNCTION__ << ": sent CLICK gesture"; | |
| 492 } | 500 } |
| 493 | 501 |
| 494 return; | 502 return; |
| 495 } | 503 } |
| 496 | 504 |
| 497 gvr::Vec3f ergo_neutral_pose; | 505 gvr::Vec3f ergo_neutral_pose; |
| 498 if (!controller_->IsConnected()) { | 506 if (!controller_->IsConnected()) { |
| 499 // No controller detected, set up a gaze cursor that tracks the | 507 // No controller detected, set up a gaze cursor that tracks the |
| 500 // forward direction. | 508 // forward direction. |
| 501 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; | 509 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 // TODO: Not sure what object_from_reference_matrix is. The new api removed | 816 // TODO: Not sure what object_from_reference_matrix is. The new api removed |
| 809 // it. For now, removing it seems working fine. | 817 // it. For now, removing it seems working fine. |
| 810 gvr_api_->ApplyNeckModel(head_pose, 1.0f); | 818 gvr_api_->ApplyNeckModel(head_pose, 1.0f); |
| 811 } | 819 } |
| 812 | 820 |
| 813 // Update the render position of all UI elements (including desktop). | 821 // Update the render position of all UI elements (including desktop). |
| 814 scene_->UpdateTransforms(TimeInMicroseconds()); | 822 scene_->UpdateTransforms(TimeInMicroseconds()); |
| 815 | 823 |
| 816 { | 824 { |
| 817 TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); | 825 TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); |
| 818 UpdateController(GetForwardVector(head_pose)); | 826 HandleControllerInput(GetForwardVector(head_pose)); |
| 819 } | 827 } |
| 820 | 828 |
| 821 // Finish drawing in the primary buffer, and draw the headlocked buffer | 829 // Finish drawing in the primary buffer, and draw the headlocked buffer |
| 822 // if needed. This must be the last drawing call, this method will | 830 // if needed. This must be the last drawing call, this method will |
| 823 // return with no frame being bound. | 831 // return with no frame being bound. |
| 824 DrawVrShellAndUnbind(head_pose, frame); | 832 DrawVrShellAndUnbind(head_pose, frame); |
| 825 | 833 |
| 826 { | 834 { |
| 827 TRACE_EVENT0("gpu", "VrShellGl::Submit"); | 835 TRACE_EVENT0("gpu", "VrShellGl::Submit"); |
| 828 frame.Submit(*buffer_viewport_list_, head_pose); | 836 frame.Submit(*buffer_viewport_list_, head_pose); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1194 | 1202 |
| 1195 // Don't send VSyncs until we have a timebase/interval. | 1203 // Don't send VSyncs until we have a timebase/interval. |
| 1196 if (vsync_interval_.is_zero()) | 1204 if (vsync_interval_.is_zero()) |
| 1197 return; | 1205 return; |
| 1198 target = now + vsync_interval_; | 1206 target = now + vsync_interval_; |
| 1199 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; | 1207 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; |
| 1200 target = vsync_timebase_ + intervals * vsync_interval_; | 1208 target = vsync_timebase_ + intervals * vsync_interval_; |
| 1201 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), | 1209 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), |
| 1202 target - now); | 1210 target - now); |
| 1203 | 1211 |
| 1212 // Get controller data now so that it's ready both for WebVR's | |
|
cjgrant
2017/03/21 15:55:38
s/ready/ready for/
klausw
2017/03/21 16:55:56
Done.
| |
| 1213 // gamepad API input and VrShell's own processing. | |
| 1214 UpdateController(); | |
| 1215 | |
| 1204 base::TimeDelta time = intervals * vsync_interval_; | 1216 base::TimeDelta time = intervals * vsync_interval_; |
| 1205 if (!callback_.is_null()) { | 1217 if (!callback_.is_null()) { |
| 1206 SendVSync(time, base::ResetAndReturn(&callback_)); | 1218 SendVSync(time, base::ResetAndReturn(&callback_)); |
| 1207 } else { | 1219 } else { |
| 1208 pending_vsync_ = true; | 1220 pending_vsync_ = true; |
| 1209 pending_time_ = time; | 1221 pending_time_ = time; |
| 1210 } | 1222 } |
| 1211 if (!web_vr_mode_) { | 1223 if (!web_vr_mode_) { |
| 1212 DrawFrame(-1); | 1224 DrawFrame(-1); |
| 1213 } | 1225 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 // appropriate recommended render resolution as the default size during | 1296 // appropriate recommended render resolution as the default size during |
| 1285 // InitializeGl. Revisit if the initialization order changes. | 1297 // InitializeGl. Revisit if the initialization order changes. |
| 1286 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1298 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
| 1287 gvr_api_.get(), webvr_surface_size_, device_id); | 1299 gvr_api_.get(), webvr_surface_size_, device_id); |
| 1288 main_thread_task_runner_->PostTask( | 1300 main_thread_task_runner_->PostTask( |
| 1289 FROM_HERE, | 1301 FROM_HERE, |
| 1290 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1302 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
| 1291 } | 1303 } |
| 1292 | 1304 |
| 1293 } // namespace vr_shell | 1305 } // namespace vr_shell |
| OLD | NEW |