Skip to content

Commit

Permalink
Implement transient hit test on the device
Browse files Browse the repository at this point in the history
Change mojo to account for latest version of hit test API

Bug: 997369
Change-Id: Ib63118a3e1bf0ef29ae7e3e2cced903993cff5cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1915179
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Klaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717471}
  • Loading branch information
bialpio authored and Commit Bot committed Nov 21, 2019
1 parent 1003838 commit 6c56114
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 37 deletions.
18 changes: 18 additions & 0 deletions chrome/browser/android/vr/arcore_device/arcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,26 @@ class ArCore {
const mojom::XRRayPtr& ray,
std::vector<mojom::XRHitResultPtr>* hit_results) = 0;

// Subscribes to hit test. Returns base::nullopt if subscription failed.
// This variant will subscribe for a hit test to a specific native origin
// specified in |native_origin_information|. The native origin will be used
// along with passed in ray to compute the hit test results as of latest
// frame. The passed in |entity_types| will be used to filter out the results
// that do not match anything in the vector.
virtual base::Optional<uint64_t> SubscribeToHitTest(
mojom::XRNativeOriginInformationPtr native_origin_information,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray) = 0;
// Subscribes to hit test for transient input sources. Returns base::nullopt
// if subscription failed. This variant will subscribe for a hit test to
// transient input sources that match the |profile_name|. The passed in ray
// will be used to compute the hit test results as of latest frame (relative
// to the location of transient input source). The passed in |entity_types|
// will be used to filter out the results that do not match anything in the
// vector.
virtual base::Optional<uint64_t> SubscribeToHitTestForTransientInput(
const std::string& profile_name,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray) = 0;

virtual mojom::XRHitTestSubscriptionResultsDataPtr
Expand Down
31 changes: 30 additions & 1 deletion chrome/browser/android/vr/arcore_device/arcore_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ constexpr std::array<float, 6> kDisplayCoordinatesForTransform = {

constexpr uint32_t kInputSourceId = 1;

const char* kInputSourceProfileName = "generic-touchscreen";

gfx::Transform ConvertUvsToTransformMatrix(const std::vector<float>& uvs) {
// We're creating a matrix that transforms viewport UV coordinates (for a
// screen-filling quad, origin at bottom left, u=1 at right, v=1 at top) to
Expand Down Expand Up @@ -660,6 +662,7 @@ void ArCoreGl::RequestHitTest(

void ArCoreGl::SubscribeToHitTest(
mojom::XRNativeOriginInformationPtr native_origin_information,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray,
mojom::XREnvironmentIntegrationProvider::SubscribeToHitTestCallback
callback) {
Expand All @@ -679,7 +682,31 @@ void ArCoreGl::SubscribeToHitTest(
}

base::Optional<uint64_t> maybe_subscription_id = arcore_->SubscribeToHitTest(
std::move(native_origin_information), std::move(ray));
std::move(native_origin_information), entity_types, std::move(ray));

if (maybe_subscription_id) {
DVLOG(2) << __func__ << ": subscription_id=" << *maybe_subscription_id;
std::move(callback).Run(device::mojom::SubscribeToHitTestResult::SUCCESS,
*maybe_subscription_id);
} else {
DVLOG(1) << __func__ << ": subscription failed";
std::move(callback).Run(
device::mojom::SubscribeToHitTestResult::FAILURE_GENERIC, 0);
}
}

void ArCoreGl::SubscribeToHitTestForTransientInput(
const std::string& profile_name,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray,
mojom::XREnvironmentIntegrationProvider::
SubscribeToHitTestForTransientInputCallback callback) {
DVLOG(2) << __func__ << ": ray origin=" << ray->origin.ToString()
<< ", ray direction=" << ray->direction.ToString();

base::Optional<uint64_t> maybe_subscription_id =
arcore_->SubscribeToHitTestForTransientInput(profile_name, entity_types,
std::move(ray));

if (maybe_subscription_id) {
DVLOG(2) << __func__ << ": subscription_id=" << *maybe_subscription_id;
Expand Down Expand Up @@ -837,6 +864,8 @@ mojom::XRInputSourceStatePtr ArCoreGl::GetInputSourceState() {

state->description->target_ray_mode = device::mojom::XRTargetRayMode::TAPPING;

state->description->profiles.push_back(kInputSourceProfileName);

// Controller doesn't have a measured position.
state->emulated_position = true;

Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/android/vr/arcore_device/arcore_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ class ArCoreGl : public mojom::XRFrameDataProvider,

void SubscribeToHitTest(
mojom::XRNativeOriginInformationPtr native_origin_information,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray,
mojom::XREnvironmentIntegrationProvider::SubscribeToHitTestCallback
callback) override;
void SubscribeToHitTestForTransientInput(
const std::string& profile_name,
const std::vector<mojom::EntityTypeForHitTest>& entity_types,
mojom::XRRayPtr ray,
mojom::XREnvironmentIntegrationProvider::
SubscribeToHitTestForTransientInputCallback callback) override;

void UnsubscribeFromHitTest(uint64_t subscription_id) override;

Expand Down
Loading

0 comments on commit 6c56114

Please sign in to comment.