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

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

Issue 2878083003: VR Shell: Allow UI elements to determine hit testing. (Closed)
Patch Set: rebase Created 3 years, 7 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
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 <chrono> 7 #include <chrono>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 static constexpr int kViewportListHeadlockedOffset = 2; 79 static constexpr int kViewportListHeadlockedOffset = 2;
80 80
81 // Buffer size large enough to handle the current backlog of poses which is 81 // Buffer size large enough to handle the current backlog of poses which is
82 // 2-3 frames. 82 // 2-3 frames.
83 static constexpr unsigned kPoseRingBufferSize = 8; 83 static constexpr unsigned kPoseRingBufferSize = 8;
84 84
85 // Criteria for considering holding the app button in combination with 85 // Criteria for considering holding the app button in combination with
86 // controller movement as a gesture. 86 // controller movement as a gesture.
87 static constexpr float kMinAppButtonGestureAngleRad = 0.25; 87 static constexpr float kMinAppButtonGestureAngleRad = 0.25;
88 88
89 static constexpr gfx::PointF kInvalidTargetPoint = {-1000.0f, -1000.0f};
90
89 // Generate a quaternion representing the rotation from the negative Z axis 91 // Generate a quaternion representing the rotation from the negative Z axis
90 // (0, 0, -1) to a specified vector. This is an optimized version of a more 92 // (0, 0, -1) to a specified vector. This is an optimized version of a more
91 // general vector-to-vector calculation. 93 // general vector-to-vector calculation.
92 vr::Quatf GetRotationFromZAxis(gfx::Vector3dF vec) { 94 vr::Quatf GetRotationFromZAxis(gfx::Vector3dF vec) {
93 vr::NormalizeVector(&vec); 95 vr::NormalizeVector(&vec);
94 vr::Quatf quat; 96 vr::Quatf quat;
95 quat.qw = 1.0f - vec.z(); 97 quat.qw = 1.0f - vec.z();
96 if (quat.qw < 1e-6f) { 98 if (quat.qw < 1e-6f) {
97 // Degenerate case: vectors are exactly opposite. Replace by an 99 // Degenerate case: vectors are exactly opposite. Replace by an
98 // arbitrary 180 degree rotation to avoid invalid normalization. 100 // arbitrary 180 degree rotation to avoid invalid normalization.
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 534
533 vr::Mat4f mat; 535 vr::Mat4f mat;
534 QuatToMatrix(controller_quat_, &mat); 536 QuatToMatrix(controller_quat_, &mat);
535 gfx::Vector3dF controller_direction = 537 gfx::Vector3dF controller_direction =
536 vr::MatrixVectorMul(mat, ergo_neutral_pose); 538 vr::MatrixVectorMul(mat, ergo_neutral_pose);
537 539
538 HandleControllerAppButtonActivity(controller_direction); 540 HandleControllerAppButtonActivity(controller_direction);
539 541
540 if (ShouldDrawWebVr()) 542 if (ShouldDrawWebVr())
541 return; 543 return;
542 gfx::PointF target_local_point; 544 gfx::PointF target_local_point(kInvalidTargetPoint);
543 gfx::Vector3dF eye_to_target; 545 gfx::Vector3dF eye_to_target;
544 reticle_render_target_ = nullptr; 546 reticle_render_target_ = nullptr;
545 GetVisualTargetElement(controller_direction, eye_to_target, target_point_, 547 GetVisualTargetElement(controller_direction, eye_to_target, target_point_,
546 &reticle_render_target_, target_local_point); 548 &reticle_render_target_, target_local_point);
547 549
548 UiElement* target_element = nullptr; 550 UiElement* target_element = nullptr;
549 if (input_locked_element_) { 551 if (input_locked_element_) {
550 gfx::Point3F plane_intersection_point; 552 gfx::Point3F plane_intersection_point;
551 float distance_to_plane; 553 float distance_to_plane;
552 GetTargetLocalPoint(eye_to_target, *input_locked_element_, 554 if (!GetTargetLocalPoint(eye_to_target, *input_locked_element_,
553 2 * scene_->GetBackgroundDistance(), target_local_point, 555 2 * scene_->GetBackgroundDistance(),
554 plane_intersection_point, distance_to_plane); 556 target_local_point, plane_intersection_point,
557 distance_to_plane)) {
558 target_local_point = kInvalidTargetPoint;
559 }
555 target_element = input_locked_element_; 560 target_element = input_locked_element_;
556 } else if (!in_scroll_ && !in_click_) { 561 } else if (!in_scroll_ && !in_click_) {
557 target_element = reticle_render_target_; 562 target_element = reticle_render_target_;
558 } 563 }
559 564
560 // Handle input targeting on the content quad, ignoring any other elements. 565 // Handle input targeting on the content quad, ignoring any other elements.
561 // Content is treated specially to accomodate scrolling, flings, etc. 566 // Content is treated specially to accomodate scrolling, flings, etc.
562 gfx::Point local_point_pixels; 567 gfx::Point local_point_pixels;
563 if (target_element && (target_element->fill() == Fill::CONTENT)) { 568 if (target_element && (target_element->fill() == Fill::CONTENT)) {
564 gfx::RectF pixel_rect(0, 0, content_tex_css_width_, 569 local_point_pixels.set_x(content_tex_css_width_ * target_local_point.x());
565 content_tex_css_height_); 570 local_point_pixels.set_y(content_tex_css_height_ * target_local_point.y());
566 local_point_pixels.set_x(pixel_rect.x() +
567 pixel_rect.width() * target_local_point.x());
568 local_point_pixels.set_y(pixel_rect.y() +
569 pixel_rect.height() * target_local_point.y());
570 } 571 }
571 std::unique_ptr<GestureList> gesture_list_ptr = controller_->DetectGestures(); 572 std::unique_ptr<GestureList> gesture_list_ptr = controller_->DetectGestures();
572 GestureList& gesture_list = *gesture_list_ptr; 573 GestureList& gesture_list = *gesture_list_ptr;
573 for (const std::unique_ptr<blink::WebGestureEvent>& gesture : gesture_list) { 574 for (const std::unique_ptr<blink::WebGestureEvent>& gesture : gesture_list) {
574 gesture->x = local_point_pixels.x(); 575 gesture->x = local_point_pixels.x();
575 gesture->y = local_point_pixels.y(); 576 gesture->y = local_point_pixels.y();
576 } 577 }
577 SendFlingCancel(gesture_list); 578 SendFlingCancel(gesture_list);
578 // For simplicity, don't allow scrolling while clicking until we need to. 579 // For simplicity, don't allow scrolling while clicking until we need to.
579 if (!in_click_) { 580 if (!in_click_) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 return; 738 return;
738 target->OnButtonDown(target_point); 739 target->OnButtonDown(target_point);
739 } 740 }
740 741
741 bool VrShellGl::SendButtonUp(UiElement* target, 742 bool VrShellGl::SendButtonUp(UiElement* target,
742 const gfx::PointF& target_point) { 743 const gfx::PointF& target_point) {
743 if (!in_click_) 744 if (!in_click_)
744 return false; 745 return false;
745 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick)) 746 if (!controller_->ButtonUpHappened(gvr::kControllerButtonClick))
746 return false; 747 return false;
748 in_click_ = false;
749 if (!input_locked_element_)
750 return true;
747 DCHECK(input_locked_element_ == target); 751 DCHECK(input_locked_element_ == target);
748 input_locked_element_ = nullptr; 752 input_locked_element_ = nullptr;
749 in_click_ = false;
750 // We don't support down/up for content yet. 753 // We don't support down/up for content yet.
751 if (target->fill() == Fill::CONTENT) 754 if (target->fill() == Fill::CONTENT)
752 return false; 755 return false;
753 target->OnButtonUp(target_point); 756 target->OnButtonUp(target_point);
754 return true; 757 return true;
755 } 758 }
756 759
757 void VrShellGl::SendTap(UiElement* target, 760 void VrShellGl::SendTap(UiElement* target,
758 const gfx::PointF& target_point, 761 const gfx::PointF& target_point,
759 const gfx::Point& local_point_pixels) { 762 const gfx::Point& local_point_pixels) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 for (auto& element : scene_->GetUiElements()) { 815 for (auto& element : scene_->GetUiElements()) {
813 if (!element->IsHitTestable()) 816 if (!element->IsHitTestable())
814 continue; 817 continue;
815 gfx::PointF local_point; 818 gfx::PointF local_point;
816 gfx::Point3F plane_intersection_point; 819 gfx::Point3F plane_intersection_point;
817 float distance_to_plane; 820 float distance_to_plane;
818 if (!GetTargetLocalPoint(eye_to_target, *element.get(), 821 if (!GetTargetLocalPoint(eye_to_target, *element.get(),
819 closest_element_distance, local_point, 822 closest_element_distance, local_point,
820 plane_intersection_point, distance_to_plane)) 823 plane_intersection_point, distance_to_plane))
821 continue; 824 continue;
822 825 if (!element->HitTest(local_point))
823 if (local_point.x() < 0.0f || local_point.x() >= 1.0f ||
824 local_point.y() < 0.0f || local_point.y() >= 1.0f)
825 continue; 826 continue;
826 827
827 closest_element_distance = distance_to_plane; 828 closest_element_distance = distance_to_plane;
828 target_point = plane_intersection_point; 829 target_point = plane_intersection_point;
829 *target_element = element.get(); 830 *target_element = element.get();
830 target_local_point = local_point; 831 target_local_point = local_point;
831 } 832 }
832 } 833 }
833 834
834 bool VrShellGl::GetTargetLocalPoint(const gfx::Vector3dF& eye_to_target, 835 bool VrShellGl::GetTargetLocalPoint(const gfx::Vector3dF& eye_to_target,
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 // This assumes that the initial webvr_surface_size_ was set to the 1477 // This assumes that the initial webvr_surface_size_ was set to the
1477 // appropriate recommended render resolution as the default size during 1478 // appropriate recommended render resolution as the default size during
1478 // InitializeGl. Revisit if the initialization order changes. 1479 // InitializeGl. Revisit if the initialization order changes.
1479 device::mojom::VRDisplayInfoPtr info = 1480 device::mojom::VRDisplayInfoPtr info =
1480 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(), 1481 device::GvrDelegate::CreateVRDisplayInfo(gvr_api_.get(),
1481 webvr_surface_size_, device_id); 1482 webvr_surface_size_, device_id);
1482 browser_->RunVRDisplayInfoCallback(callback, &info); 1483 browser_->RunVRDisplayInfoCallback(callback, &info);
1483 } 1484 }
1484 1485
1485 } // namespace vr_shell 1486 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698