Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_gl.cc

Issue 2762003002: Refactor GVR controller gamepad API integration (Closed)
Patch Set: Rebase, no changes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | device/gamepad/gamepad_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_renderer.h" 23 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h"
24 #include "device/vr/android/gvr/gvr_device.h" 24 #include "device/vr/android/gvr/gvr_device.h"
25 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
25 #include "third_party/WebKit/public/platform/WebInputEvent.h" 26 #include "third_party/WebKit/public/platform/WebInputEvent.h"
26 #include "third_party/WebKit/public/platform/WebMouseEvent.h" 27 #include "third_party/WebKit/public/platform/WebMouseEvent.h"
27 #include "ui/gl/android/scoped_java_surface.h" 28 #include "ui/gl/android/scoped_java_surface.h"
28 #include "ui/gl/android/surface_texture.h" 29 #include "ui/gl/android/surface_texture.h"
29 #include "ui/gl/gl_bindings.h" 30 #include "ui/gl/gl_bindings.h"
30 #include "ui/gl/gl_context.h" 31 #include "ui/gl/gl_context.h"
31 #include "ui/gl/gl_surface.h" 32 #include "ui/gl/gl_surface.h"
32 #include "ui/gl/init/gl_factory.h" 33 #include "ui/gl/init/gl_factory.h"
33 34
34 namespace vr_shell { 35 namespace vr_shell {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 webvr_right_viewport_.reset( 461 webvr_right_viewport_.reset(
461 new gvr::BufferViewport(gvr_api_->CreateBufferViewport())); 462 new gvr::BufferViewport(gvr_api_->CreateBufferViewport()));
462 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE, 463 buffer_viewport_list_->GetBufferViewport(GVR_RIGHT_EYE,
463 webvr_right_viewport_.get()); 464 webvr_right_viewport_.get());
464 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer); 465 webvr_right_viewport_->SetSourceBufferIndex(kFramePrimaryBuffer);
465 466
466 main_thread_task_runner_->PostTask( 467 main_thread_task_runner_->PostTask(
467 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_)); 468 FROM_HERE, base::Bind(&VrShell::GvrDelegateReady, weak_vr_shell_));
468 } 469 }
469 470
470 void VrShellGl::UpdateController(const gvr::Vec3f& forward_vector) { 471 void VrShellGl::UpdateController() {
471 controller_->UpdateState(); 472 controller_->UpdateState();
472 473
474 device::GvrGamepadData pad = controller_->GetGamepadData();
475 main_thread_task_runner_->PostTask(
476 FROM_HERE, base::Bind(&VrShell::UpdateGamepadData, weak_vr_shell_, pad));
477 }
478
479 void VrShellGl::HandleControllerInput(const gvr::Vec3f& forward_vector) {
473 if (ShouldDrawWebVr()) { 480 if (ShouldDrawWebVr()) {
474 // Process screen touch events for Cardboard button compatibility. 481 // Process screen touch events for Cardboard button compatibility.
475 // Also send tap events for controller "touchpad click" events. 482 // Also send tap events for controller "touchpad click" events.
476 if (touch_pending_ || 483 if (touch_pending_ ||
477 controller_->ButtonUpHappened( 484 controller_->ButtonUpHappened(
478 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) { 485 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) {
479 touch_pending_ = false; 486 touch_pending_ = false;
480 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent( 487 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent(
481 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers, 488 WebInputEvent::GestureTapDown, WebInputEvent::NoModifiers,
482 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF())); 489 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF()));
483 gesture->sourceDevice = blink::WebGestureDeviceTouchpad; 490 gesture->sourceDevice = blink::WebGestureDeviceTouchpad;
484 gesture->x = 0; 491 gesture->x = 0;
485 gesture->y = 0; 492 gesture->y = 0;
486 SendGesture(InputTarget::CONTENT, std::move(gesture)); 493 SendGesture(InputTarget::CONTENT, std::move(gesture));
494 DVLOG(1) << __FUNCTION__ << ": sent CLICK gesture";
487 } 495 }
488 496
489 return; 497 return;
490 } 498 }
491 499
492 gvr::Vec3f ergo_neutral_pose; 500 gvr::Vec3f ergo_neutral_pose;
493 if (!controller_->IsConnected()) { 501 if (!controller_->IsConnected()) {
494 // No controller detected, set up a gaze cursor that tracks the 502 // No controller detected, set up a gaze cursor that tracks the
495 // forward direction. 503 // forward direction.
496 ergo_neutral_pose = {0.0f, 0.0f, -1.0f}; 504 ergo_neutral_pose = {0.0f, 0.0f, -1.0f};
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // TODO: Not sure what object_from_reference_matrix is. The new api removed 811 // TODO: Not sure what object_from_reference_matrix is. The new api removed
804 // it. For now, removing it seems working fine. 812 // it. For now, removing it seems working fine.
805 gvr_api_->ApplyNeckModel(head_pose, 1.0f); 813 gvr_api_->ApplyNeckModel(head_pose, 1.0f);
806 } 814 }
807 815
808 // Update the render position of all UI elements (including desktop). 816 // Update the render position of all UI elements (including desktop).
809 scene_->UpdateTransforms(TimeInMicroseconds()); 817 scene_->UpdateTransforms(TimeInMicroseconds());
810 818
811 { 819 {
812 TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); 820 TRACE_EVENT0("gpu", "VrShellGl::UpdateController");
813 UpdateController(GetForwardVector(head_pose)); 821 HandleControllerInput(GetForwardVector(head_pose));
814 } 822 }
815 823
816 DrawWorldElements(head_pose); 824 DrawWorldElements(head_pose);
817 825
818 frame.Unbind(); 826 frame.Unbind();
819 827
820 // Draw head-locked elements to a separate, non-reprojected buffer. 828 // Draw head-locked elements to a separate, non-reprojected buffer.
821 if (scene_->HasVisibleHeadLockedElements()) { 829 if (scene_->HasVisibleHeadLockedElements()) {
822 frame.BindBuffer(kFrameHeadlockedBuffer); 830 frame.BindBuffer(kFrameHeadlockedBuffer);
823 DrawHeadLockedElements(); 831 DrawHeadLockedElements();
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1189
1182 // Don't send VSyncs until we have a timebase/interval. 1190 // Don't send VSyncs until we have a timebase/interval.
1183 if (vsync_interval_.is_zero()) 1191 if (vsync_interval_.is_zero())
1184 return; 1192 return;
1185 target = now + vsync_interval_; 1193 target = now + vsync_interval_;
1186 int64_t intervals = (target - vsync_timebase_) / vsync_interval_; 1194 int64_t intervals = (target - vsync_timebase_) / vsync_interval_;
1187 target = vsync_timebase_ + intervals * vsync_interval_; 1195 target = vsync_timebase_ + intervals * vsync_interval_;
1188 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(), 1196 task_runner_->PostDelayedTask(FROM_HERE, vsync_task_.callback(),
1189 target - now); 1197 target - now);
1190 1198
1199 // Get controller data now so that it's ready for both WebVR's
1200 // gamepad API input and VrShell's own processing.
1201 UpdateController();
1202
1191 base::TimeDelta time = intervals * vsync_interval_; 1203 base::TimeDelta time = intervals * vsync_interval_;
1192 if (!callback_.is_null()) { 1204 if (!callback_.is_null()) {
1193 SendVSync(time, base::ResetAndReturn(&callback_)); 1205 SendVSync(time, base::ResetAndReturn(&callback_));
1194 } else { 1206 } else {
1195 pending_vsync_ = true; 1207 pending_vsync_ = true;
1196 pending_time_ = time; 1208 pending_time_ = time;
1197 } 1209 }
1198 if (!ShouldDrawWebVr()) { 1210 if (!ShouldDrawWebVr()) {
1199 DrawFrame(-1); 1211 DrawFrame(-1);
1200 } 1212 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 // appropriate recommended render resolution as the default size during 1283 // appropriate recommended render resolution as the default size during
1272 // InitializeGl. Revisit if the initialization order changes. 1284 // InitializeGl. Revisit if the initialization order changes.
1273 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( 1285 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo(
1274 gvr_api_.get(), webvr_surface_size_, device_id); 1286 gvr_api_.get(), webvr_surface_size_, device_id);
1275 main_thread_task_runner_->PostTask( 1287 main_thread_task_runner_->PostTask(
1276 FROM_HERE, 1288 FROM_HERE,
1277 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); 1289 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info)));
1278 } 1290 }
1279 1291
1280 } // namespace vr_shell 1292 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_gl.h ('k') | device/gamepad/gamepad_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698