| 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 <chrono> | 7 #include <chrono> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/android/vr_shell/vr_controller.h" | 23 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 24 #include "chrome/browser/android/vr_shell/vr_gl_util.h" | 24 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
| 25 #include "chrome/browser/android/vr_shell/vr_metrics_util.h" | 25 #include "chrome/browser/android/vr_shell/vr_metrics_util.h" |
| 26 #include "chrome/browser/android/vr_shell/vr_shell.h" | 26 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 27 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 27 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 28 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" | 28 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" |
| 29 #include "device/vr/android/gvr/gvr_delegate.h" | 29 #include "device/vr/android/gvr/gvr_delegate.h" |
| 30 #include "device/vr/android/gvr/gvr_device.h" | 30 #include "device/vr/android/gvr/gvr_device.h" |
| 31 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" | 31 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" |
| 32 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 32 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 33 #include "third_party/WebKit/public/platform/WebInputEvent.h" | |
| 34 #include "third_party/WebKit/public/platform/WebMouseEvent.h" | 33 #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| 35 #include "ui/gl/android/scoped_java_surface.h" | 34 #include "ui/gl/android/scoped_java_surface.h" |
| 36 #include "ui/gl/android/surface_texture.h" | 35 #include "ui/gl/android/surface_texture.h" |
| 37 #include "ui/gl/gl_bindings.h" | 36 #include "ui/gl/gl_bindings.h" |
| 38 #include "ui/gl/gl_context.h" | 37 #include "ui/gl/gl_context.h" |
| 39 #include "ui/gl/gl_fence_egl.h" | 38 #include "ui/gl/gl_fence_egl.h" |
| 40 #include "ui/gl/gl_surface.h" | 39 #include "ui/gl/gl_surface.h" |
| 41 #include "ui/gl/init/gl_factory.h" | 40 #include "ui/gl/init/gl_factory.h" |
| 42 | 41 |
| 43 namespace vr_shell { | 42 namespace vr_shell { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 result.matrix().set(1, 1, Y); | 164 result.matrix().set(1, 1, Y); |
| 166 result.matrix().set(1, 2, B); | 165 result.matrix().set(1, 2, B); |
| 167 result.matrix().set(2, 2, C); | 166 result.matrix().set(2, 2, C); |
| 168 result.matrix().set(2, 3, D); | 167 result.matrix().set(2, 3, D); |
| 169 result.matrix().set(3, 2, -1); | 168 result.matrix().set(3, 2, -1); |
| 170 result.matrix().set(3, 3, 0); | 169 result.matrix().set(3, 3, 0); |
| 171 | 170 |
| 172 return result; | 171 return result; |
| 173 } | 172 } |
| 174 | 173 |
| 175 std::unique_ptr<blink::WebMouseEvent> MakeMouseEvent( | |
| 176 blink::WebInputEvent::Type type, | |
| 177 double timestamp, | |
| 178 const gfx::Point& location, | |
| 179 bool down) { | |
| 180 blink::WebInputEvent::Modifiers modifiers = | |
| 181 down ? blink::WebInputEvent::kLeftButtonDown | |
| 182 : blink::WebInputEvent::kNoModifiers; | |
| 183 std::unique_ptr<blink::WebMouseEvent> mouse_event( | |
| 184 new blink::WebMouseEvent(type, modifiers, timestamp)); | |
| 185 mouse_event->pointer_type = blink::WebPointerProperties::PointerType::kMouse; | |
| 186 mouse_event->button = blink::WebPointerProperties::Button::kLeft; | |
| 187 mouse_event->SetPositionInWidget(location.x(), location.y()); | |
| 188 mouse_event->click_count = 1; | |
| 189 | |
| 190 return mouse_event; | |
| 191 } | |
| 192 | |
| 193 void TransformToGvrMat(const gfx::Transform& in, gvr::Mat4f* out) { | 174 void TransformToGvrMat(const gfx::Transform& in, gvr::Mat4f* out) { |
| 194 for (int i = 0; i < 4; ++i) { | 175 for (int i = 0; i < 4; ++i) { |
| 195 for (int j = 0; j < 4; ++j) { | 176 for (int j = 0; j < 4; ++j) { |
| 196 out->m[i][j] = in.matrix().get(i, j); | 177 out->m[i][j] = in.matrix().get(i, j); |
| 197 } | 178 } |
| 198 } | 179 } |
| 199 } | 180 } |
| 200 | 181 |
| 201 void GvrMatToTransform(const gvr::Mat4f& in, gfx::Transform* out) { | 182 void GvrMatToTransform(const gvr::Mat4f& in, gfx::Transform* out) { |
| 202 for (int i = 0; i < 4; ++i) { | 183 for (int i = 0; i < 4; ++i) { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 617 |
| 637 void VrShellGl::HandleWebVrCompatibilityClick() { | 618 void VrShellGl::HandleWebVrCompatibilityClick() { |
| 638 if (!ShouldDrawWebVr()) | 619 if (!ShouldDrawWebVr()) |
| 639 return; | 620 return; |
| 640 | 621 |
| 641 // Process screen touch events for Cardboard button compatibility. | 622 // Process screen touch events for Cardboard button compatibility. |
| 642 // Also send tap events for controller "touchpad click" events. | 623 // Also send tap events for controller "touchpad click" events. |
| 643 if (touch_pending_ || | 624 if (touch_pending_ || |
| 644 controller_->ButtonUpHappened(gvr::kControllerButtonClick)) { | 625 controller_->ButtonUpHappened(gvr::kControllerButtonClick)) { |
| 645 touch_pending_ = false; | 626 touch_pending_ = false; |
| 646 std::unique_ptr<blink::WebGestureEvent> gesture(new blink::WebGestureEvent( | 627 auto gesture = base::MakeUnique<blink::WebGestureEvent>( |
| 647 blink::WebInputEvent::kGestureTapDown, | 628 blink::WebInputEvent::kGestureTapDown, |
| 648 blink::WebInputEvent::kNoModifiers, NowSeconds())); | 629 blink::WebInputEvent::kNoModifiers, NowSeconds()); |
| 649 gesture->source_device = blink::kWebGestureDeviceTouchpad; | 630 gesture->source_device = blink::kWebGestureDeviceTouchpad; |
| 650 gesture->x = 0; | 631 gesture->x = 0; |
| 651 gesture->y = 0; | 632 gesture->y = 0; |
| 652 SendGestureToContent(std::move(gesture)); | 633 SendGestureToContent(std::move(gesture)); |
| 653 DVLOG(1) << __FUNCTION__ << ": sent CLICK gesture"; | 634 DVLOG(1) << __FUNCTION__ << ": sent CLICK gesture"; |
| 654 } | 635 } |
| 655 } | 636 } |
| 656 | 637 |
| 657 void VrShellGl::SendFlingCancel(GestureList& gesture_list) { | 638 void VrShellGl::SendFlingCancel(GestureList& gesture_list) { |
| 658 if (!fling_target_) | 639 if (!fling_target_) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // Scrolling currently only supported on content window. | 702 // Scrolling currently only supported on content window. |
| 722 DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT); | 703 DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT); |
| 723 SendGestureToContent(std::move(gesture_list.front())); | 704 SendGestureToContent(std::move(gesture_list.front())); |
| 724 gesture_list.erase(gesture_list.begin()); | 705 gesture_list.erase(gesture_list.begin()); |
| 725 } | 706 } |
| 726 | 707 |
| 727 void VrShellGl::SendHoverLeave(UiElement* target) { | 708 void VrShellGl::SendHoverLeave(UiElement* target) { |
| 728 if (!hover_target_ || (target == hover_target_)) | 709 if (!hover_target_ || (target == hover_target_)) |
| 729 return; | 710 return; |
| 730 if (hover_target_->fill() == Fill::CONTENT) { | 711 if (hover_target_->fill() == Fill::CONTENT) { |
| 731 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseLeave, | 712 SendGestureToContent( |
| 732 NowSeconds(), gfx::Point(), in_click_)); | 713 MakeMouseEvent(blink::WebInputEvent::kMouseLeave, gfx::Point())); |
| 733 } else { | 714 } else { |
| 734 hover_target_->OnHoverLeave(); | 715 hover_target_->OnHoverLeave(); |
| 735 } | 716 } |
| 736 hover_target_ = nullptr; | 717 hover_target_ = nullptr; |
| 737 } | 718 } |
| 738 | 719 |
| 739 bool VrShellGl::SendHoverEnter(UiElement* target, | 720 bool VrShellGl::SendHoverEnter(UiElement* target, |
| 740 const gfx::PointF& target_point, | 721 const gfx::PointF& target_point, |
| 741 const gfx::Point& local_point_pixels) { | 722 const gfx::Point& local_point_pixels) { |
| 742 if (!target || target == hover_target_) | 723 if (!target || target == hover_target_) |
| 743 return false; | 724 return false; |
| 744 if (target->fill() == Fill::CONTENT) { | 725 if (target->fill() == Fill::CONTENT) { |
| 745 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseEnter, | 726 SendGestureToContent( |
| 746 NowSeconds(), local_point_pixels, | 727 MakeMouseEvent(blink::WebInputEvent::kMouseEnter, local_point_pixels)); |
| 747 in_click_)); | |
| 748 } else { | 728 } else { |
| 749 target->OnHoverEnter(target_point); | 729 target->OnHoverEnter(target_point); |
| 750 } | 730 } |
| 751 hover_target_ = target; | 731 hover_target_ = target; |
| 752 return true; | 732 return true; |
| 753 } | 733 } |
| 754 | 734 |
| 755 void VrShellGl::SendHoverMove(const gfx::PointF& target_point, | 735 void VrShellGl::SendHoverMove(const gfx::PointF& target_point, |
| 756 const gfx::Point& local_point_pixels) { | 736 const gfx::Point& local_point_pixels) { |
| 757 if (!hover_target_) | 737 if (!hover_target_) |
| 758 return; | 738 return; |
| 759 if (hover_target_->fill() == Fill::CONTENT) { | 739 if (hover_target_->fill() == Fill::CONTENT) { |
| 760 // TODO(mthiesse, vollick): Content is currently way too sensitive to mouse | 740 // TODO(mthiesse, vollick): Content is currently way too sensitive to mouse |
| 761 // moves for how noisy the controller is. It's almost impossible to click a | 741 // moves for how noisy the controller is. It's almost impossible to click a |
| 762 // link without unintentionally starting a drag event. For this reason we | 742 // link without unintentionally starting a drag event. For this reason we |
| 763 // disable mouse moves, only delivering a down and up event. | 743 // disable mouse moves, only delivering a down and up event. |
| 764 if (in_click_) | 744 if (in_click_) |
| 765 return; | 745 return; |
| 766 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseMove, | 746 SendGestureToContent( |
| 767 NowSeconds(), local_point_pixels, | 747 MakeMouseEvent(blink::WebInputEvent::kMouseMove, local_point_pixels)); |
| 768 in_click_)); | |
| 769 } else { | 748 } else { |
| 770 hover_target_->OnMove(target_point); | 749 hover_target_->OnMove(target_point); |
| 771 } | 750 } |
| 772 } | 751 } |
| 773 | 752 |
| 774 void VrShellGl::SendButtonDown(UiElement* target, | 753 void VrShellGl::SendButtonDown(UiElement* target, |
| 775 const gfx::PointF& target_point, | 754 const gfx::PointF& target_point, |
| 776 const gfx::Point& local_point_pixels) { | 755 const gfx::Point& local_point_pixels) { |
| 777 if (in_click_) | 756 if (in_click_) |
| 778 return; | 757 return; |
| 779 if (!controller_->ButtonDownHappened(gvr::kControllerButtonClick)) | 758 if (!controller_->ButtonDownHappened(gvr::kControllerButtonClick)) |
| 780 return; | 759 return; |
| 781 input_locked_element_ = target; | 760 input_locked_element_ = target; |
| 782 in_click_ = true; | 761 in_click_ = true; |
| 783 if (!target) | 762 if (!target) |
| 784 return; | 763 return; |
| 785 if (target->fill() == Fill::CONTENT) { | 764 if (target->fill() == Fill::CONTENT) { |
| 786 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseDown, | 765 SendGestureToContent( |
| 787 NowSeconds(), local_point_pixels, | 766 MakeMouseEvent(blink::WebInputEvent::kMouseDown, local_point_pixels)); |
| 788 in_click_)); | |
| 789 } else { | 767 } else { |
| 790 target->OnButtonDown(target_point); | 768 target->OnButtonDown(target_point); |
| 791 } | 769 } |
| 792 } | 770 } |
| 793 | 771 |
| 794 bool VrShellGl::SendButtonUp(UiElement* target, | 772 bool VrShellGl::SendButtonUp(UiElement* target, |
| 795 const gfx::PointF& target_point, | 773 const gfx::PointF& target_point, |
| 796 const gfx::Point& local_point_pixels) { | 774 const gfx::Point& local_point_pixels) { |
| 797 if (!in_click_) | 775 if (!in_click_) |
| 798 return false; | 776 return false; |
| 799 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick) && | 777 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick) && |
| 800 controller_->ButtonState(gvr::kControllerButtonClick)) | 778 controller_->ButtonState(gvr::kControllerButtonClick)) |
| 801 return false; | 779 return false; |
| 802 in_click_ = false; | 780 in_click_ = false; |
| 803 if (!input_locked_element_) | 781 if (!input_locked_element_) |
| 804 return true; | 782 return true; |
| 805 DCHECK(input_locked_element_ == target); | 783 DCHECK(input_locked_element_ == target); |
| 806 input_locked_element_ = nullptr; | 784 input_locked_element_ = nullptr; |
| 807 if (target->fill() == Fill::CONTENT) { | 785 if (target->fill() == Fill::CONTENT) { |
| 808 SendGestureToContent(MakeMouseEvent(blink::WebInputEvent::kMouseUp, | 786 SendGestureToContent( |
| 809 NowSeconds(), local_point_pixels, | 787 MakeMouseEvent(blink::WebInputEvent::kMouseUp, local_point_pixels)); |
| 810 in_click_)); | |
| 811 } else { | 788 } else { |
| 812 target->OnButtonUp(target_point); | 789 target->OnButtonUp(target_point); |
| 813 } | 790 } |
| 814 return true; | 791 return true; |
| 815 } | 792 } |
| 816 | 793 |
| 817 void VrShellGl::SendTap(UiElement* target, | 794 void VrShellGl::SendTap(UiElement* target, |
| 818 const gfx::PointF& target_point, | 795 const gfx::PointF& target_point, |
| 819 const gfx::Point& local_point_pixels) { | 796 const gfx::Point& local_point_pixels) { |
| 820 if (!target) | 797 if (!target) |
| 821 return; | 798 return; |
| 822 if (!touch_pending_) | 799 if (!touch_pending_) |
| 823 return; | 800 return; |
| 824 touch_pending_ = false; | 801 touch_pending_ = false; |
| 825 if (target->fill() == Fill::CONTENT) { | 802 if (target->fill() == Fill::CONTENT) { |
| 826 auto gesture = base::MakeUnique<blink::WebGestureEvent>( | 803 auto gesture = base::MakeUnique<blink::WebGestureEvent>( |
| 827 blink::WebInputEvent::kGestureTapDown, | 804 blink::WebInputEvent::kGestureTapDown, |
| 828 blink::WebInputEvent::kNoModifiers, NowSeconds()); | 805 blink::WebInputEvent::kNoModifiers, NowSeconds()); |
| 829 gesture->source_device = blink::kWebGestureDeviceTouchpad; | 806 gesture->source_device = blink::kWebGestureDeviceTouchpad; |
| 830 gesture->x = local_point_pixels.x(); | 807 gesture->x = local_point_pixels.x(); |
| 831 gesture->y = local_point_pixels.y(); | 808 gesture->y = local_point_pixels.y(); |
| 832 SendGestureToContent(std::move(gesture)); | 809 SendGestureToContent(std::move(gesture)); |
| 833 } else { | 810 } else { |
| 834 target->OnButtonDown(target_point); | 811 target->OnButtonDown(target_point); |
| 835 target->OnButtonUp(target_point); | 812 target->OnButtonUp(target_point); |
| 836 } | 813 } |
| 837 } | 814 } |
| 838 | 815 |
| 816 std::unique_ptr<blink::WebMouseEvent> VrShellGl::MakeMouseEvent( |
| 817 blink::WebInputEvent::Type type, |
| 818 const gfx::Point& location) { |
| 819 blink::WebInputEvent::Modifiers modifiers = |
| 820 in_click_ ? blink::WebInputEvent::kLeftButtonDown |
| 821 : blink::WebInputEvent::kNoModifiers; |
| 822 base::TimeTicks timestamp; |
| 823 switch (type) { |
| 824 case blink::WebInputEvent::kMouseUp: |
| 825 case blink::WebInputEvent::kMouseDown: |
| 826 timestamp = controller_->GetLastButtonTimestamp(); |
| 827 break; |
| 828 case blink::WebInputEvent::kMouseMove: |
| 829 case blink::WebInputEvent::kMouseEnter: |
| 830 case blink::WebInputEvent::kMouseLeave: |
| 831 timestamp = controller_->GetLastOrientationTimestamp(); |
| 832 break; |
| 833 default: |
| 834 NOTREACHED(); |
| 835 } |
| 836 |
| 837 auto mouse_event = base::MakeUnique<blink::WebMouseEvent>( |
| 838 type, modifiers, (timestamp - base::TimeTicks()).InSecondsF()); |
| 839 mouse_event->pointer_type = blink::WebPointerProperties::PointerType::kMouse; |
| 840 mouse_event->button = blink::WebPointerProperties::Button::kLeft; |
| 841 mouse_event->SetPositionInWidget(location.x(), location.y()); |
| 842 // TODO(mthiesse): Should we support double-clicks for input? What should the |
| 843 // timeout be? |
| 844 mouse_event->click_count = 1; |
| 845 |
| 846 return mouse_event; |
| 847 } |
| 848 |
| 839 void VrShellGl::SendImmediateExitRequestIfNecessary() { | 849 void VrShellGl::SendImmediateExitRequestIfNecessary() { |
| 840 gvr::ControllerButton buttons[] = { | 850 gvr::ControllerButton buttons[] = { |
| 841 gvr::kControllerButtonClick, gvr::kControllerButtonApp, | 851 gvr::kControllerButtonClick, gvr::kControllerButtonApp, |
| 842 gvr::kControllerButtonHome, | 852 gvr::kControllerButtonHome, |
| 843 }; | 853 }; |
| 844 for (size_t i = 0; i < arraysize(buttons); ++i) { | 854 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| 845 if (controller_->ButtonUpHappened(buttons[i]) || | 855 if (controller_->ButtonUpHappened(buttons[i]) || |
| 846 controller_->ButtonDownHappened(buttons[i])) { | 856 controller_->ButtonDownHappened(buttons[i])) { |
| 847 browser_->ForceExitVr(); | 857 browser_->ForceExitVr(); |
| 848 } | 858 } |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1616 // This assumes that the initial webvr_surface_size_ was set to the | 1626 // This assumes that the initial webvr_surface_size_ was set to the |
| 1617 // appropriate recommended render resolution as the default size during | 1627 // appropriate recommended render resolution as the default size during |
| 1618 // InitializeGl. Revisit if the initialization order changes. | 1628 // InitializeGl. Revisit if the initialization order changes. |
| 1619 device::mojom::VRDisplayInfoPtr info = | 1629 device::mojom::VRDisplayInfoPtr info = |
| 1620 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), | 1630 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), |
| 1621 webvr_surface_size_, device_id); | 1631 webvr_surface_size_, device_id); |
| 1622 browser_->RunVRDisplayInfoCallback(callback, &info); | 1632 browser_->RunVRDisplayInfoCallback(callback, &info); |
| 1623 } | 1633 } |
| 1624 | 1634 |
| 1625 } // namespace vr_shell | 1635 } // namespace vr_shell |
| OLD | NEW |