Commit 79e051b7 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

ARCore device - create plane manager, refactor plane logic

Mostly mechanical change:
- move maps that track plane state to a separate ArCorePlaneManager
class
- make some of the helpers shared between arcore_impl.cc and
arcore_plane_manager.cc (scoped arcore objects, conversions from ARCore
entities to mojo for cases where ArSession* is needed)
- instead of passing mojo's `const TypePtr&` around, pass `const Type&`

Step 1/N - preparing from creating anchors from hit test results since
plane state will need to be tracked independently from plane detection
feature - hit test feature will also need to be aware of the planes.

Change-Id: Ic4cc008ce4466e85fe65b3901a4848ebb03d6dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055587Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741268}
parent 7cb6c1d8
......@@ -92,10 +92,13 @@ static_library("vr_android") {
"arcore_device/arcore_install_helper.h",
"arcore_device/arcore_java_utils.cc",
"arcore_device/arcore_java_utils.h",
"arcore_device/arcore_plane_manager.cc",
"arcore_device/arcore_plane_manager.h",
"arcore_device/arcore_sdk.h",
"arcore_device/arcore_session_utils.h",
"arcore_device/arcore_shim.cc",
"arcore_device/arcore_shim.h",
"arcore_device/scoped_arcore_objects.h",
"arcore_device/type_converters.cc",
"arcore_device/type_converters.h",
]
......
......@@ -91,8 +91,8 @@ class ArCore {
virtual void UnsubscribeFromHitTest(uint64_t subscription_id) = 0;
virtual base::Optional<uint64_t> CreateAnchor(const mojom::PosePtr& pose) = 0;
virtual base::Optional<uint64_t> CreateAnchor(const mojom::PosePtr& pose,
virtual base::Optional<uint64_t> CreateAnchor(const mojom::Pose& pose) = 0;
virtual base::Optional<uint64_t> CreateAnchor(const mojom::Pose& pose,
uint64_t plane_id) = 0;
virtual void DetachAnchor(uint64_t anchor_id) = 0;
......
......@@ -697,7 +697,10 @@ void ArCoreGl::CreateAnchor(mojom::PosePtr anchor_pose,
CreateAnchorCallback callback) {
DVLOG(2) << __func__;
base::Optional<uint64_t> maybe_anchor_id = arcore_->CreateAnchor(anchor_pose);
DCHECK(anchor_pose);
base::Optional<uint64_t> maybe_anchor_id =
arcore_->CreateAnchor(*anchor_pose);
if (maybe_anchor_id) {
std::move(callback).Run(device::mojom::CreateAnchorResult::SUCCESS,
......@@ -712,8 +715,10 @@ void ArCoreGl::CreatePlaneAnchor(mojom::PosePtr anchor_pose,
CreatePlaneAnchorCallback callback) {
DVLOG(2) << __func__;
DCHECK(anchor_pose);
base::Optional<uint64_t> maybe_anchor_id =
arcore_->CreateAnchor(anchor_pose, plane_id);
arcore_->CreateAnchor(*anchor_pose, plane_id);
if (maybe_anchor_id) {
std::move(callback).Run(device::mojom::CreateAnchorResult::SUCCESS,
......
......@@ -7,89 +7,17 @@
#include "base/macros.h"
#include "base/optional.h"
#include "base/scoped_generic.h"
#include "base/util/type_safety/id_type.h"
#include "chrome/browser/android/vr/arcore_device/arcore.h"
#include "chrome/browser/android/vr/arcore_device/arcore_plane_manager.h"
#include "chrome/browser/android/vr/arcore_device/arcore_sdk.h"
#include "chrome/browser/android/vr/arcore_device/scoped_arcore_objects.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
namespace device {
namespace internal {
class ArCorePlaneManager;
template <class T>
struct ScopedGenericArObject {
static T InvalidValue() { return nullptr; }
static void Free(T object) {}
};
template <>
void inline ScopedGenericArObject<ArSession*>::Free(ArSession* ar_session) {
ArSession_destroy(ar_session);
}
template <>
void inline ScopedGenericArObject<ArFrame*>::Free(ArFrame* ar_frame) {
ArFrame_destroy(ar_frame);
}
template <>
void inline ScopedGenericArObject<ArConfig*>::Free(ArConfig* ar_config) {
ArConfig_destroy(ar_config);
}
template <>
void inline ScopedGenericArObject<ArPose*>::Free(ArPose* ar_pose) {
ArPose_destroy(ar_pose);
}
template <>
void inline ScopedGenericArObject<ArTrackable*>::Free(
ArTrackable* ar_trackable) {
ArTrackable_release(ar_trackable);
}
template <>
void inline ScopedGenericArObject<ArPlane*>::Free(ArPlane* ar_plane) {
// ArPlane itself doesn't have a method to decrease refcount, but it is an
// instance of ArTrackable & we have to use ArTrackable_release.
ArTrackable_release(ArAsTrackable(ar_plane));
}
template <>
void inline ScopedGenericArObject<ArAnchor*>::Free(ArAnchor* ar_anchor) {
ArAnchor_release(ar_anchor);
}
template <>
void inline ScopedGenericArObject<ArTrackableList*>::Free(
ArTrackableList* ar_trackable_list) {
ArTrackableList_destroy(ar_trackable_list);
}
template <>
void inline ScopedGenericArObject<ArCamera*>::Free(ArCamera* ar_camera) {
// Do nothing - ArCamera has no destroy method and is managed by ArCore.
}
template <>
void inline ScopedGenericArObject<ArHitResultList*>::Free(
ArHitResultList* ar_hit_result_list) {
ArHitResultList_destroy(ar_hit_result_list);
}
template <>
void inline ScopedGenericArObject<ArHitResult*>::Free(
ArHitResult* ar_hit_result) {
ArHitResult_destroy(ar_hit_result);
}
template <class T>
using ScopedArCoreObject = base::ScopedGeneric<T, ScopedGenericArObject<T>>;
} // namespace internal
using PlaneId = util::IdTypeU64<class PlaneTag>;
using AnchorId = util::IdTypeU64<class AnchorTag>;
using HitTestSubscriptionId = util::IdTypeU64<class HitTestSubscriptionTag>;
......@@ -174,8 +102,8 @@ class ArCoreImpl : public ArCore {
void UnsubscribeFromHitTest(uint64_t subscription_id) override;
base::Optional<uint64_t> CreateAnchor(
const device::mojom::PosePtr& pose) override;
base::Optional<uint64_t> CreateAnchor(const device::mojom::PosePtr& pose,
const device::mojom::Pose& pose) override;
base::Optional<uint64_t> CreateAnchor(const device::mojom::Pose& pose,
uint64_t plane_id) override;
void DetachAnchor(uint64_t anchor_id) override;
......@@ -194,13 +122,6 @@ class ArCoreImpl : public ArCore {
internal::ScopedArCoreObject<ArSession*> arcore_session_;
internal::ScopedArCoreObject<ArFrame*> arcore_frame_;
// List of trackables - used for retrieving planes detected by ARCore. The
// list will initially be null - call EnsureArCorePlanesList() before using
// it.
// Allows reuse of the list across updates; ARCore clears the list on each
// call to the ARCore SDK.
internal::ScopedArCoreObject<ArTrackableList*> arcore_planes_;
// List of anchors - used for retrieving anchors tracked by ARCore. The list
// will initially be null - call EnsureArCoreAnchorsList() before using it.
// Allows reuse of the list across updates; ARCore clears the list on each
......@@ -210,22 +131,9 @@ class ArCoreImpl : public ArCore {
// ArCore light estimation data
internal::ScopedArCoreObject<ArLightEstimate*> arcore_light_estimate_;
// Initializes |arcore_planes_| list.
void EnsureArCorePlanesList();
// Initializes |arcore_anchors_| list.
void EnsureArCoreAnchorsList();
// Returns vector containing information about all planes updated in current
// frame, assigning IDs for newly detected planes as needed.
std::vector<mojom::XRPlaneDataPtr> GetUpdatedPlanesData();
// This must be called after GetUpdatedPlanesData as it assumes that all
// planes already have an ID assigned. The result includes freshly assigned
// IDs for newly detected planes along with previously known IDs for updated
// and unchanged planes. It excludes planes that are no longer being tracked.
std::vector<uint64_t> GetAllPlaneIds();
// Returns vector containing information about all anchors updated in the
// current frame.
std::vector<mojom::XRAnchorDataPtr> GetUpdatedAnchorsData();
......@@ -234,10 +142,9 @@ class ArCoreImpl : public ArCore {
// frame.
std::vector<uint64_t> GetAllAnchorIds();
std::unique_ptr<ArCorePlaneManager> plane_manager_;
uint64_t next_id_ = 1;
std::map<void*, PlaneId> ar_plane_address_to_id_;
std::map<PlaneId, device::internal::ScopedArCoreObject<ArTrackable*>>
plane_id_to_plane_object_;
std::map<void*, AnchorId> ar_anchor_address_to_id_;
std::map<AnchorId, device::internal::ScopedArCoreObject<ArAnchor*>>
anchor_id_to_anchor_object_;
......@@ -247,9 +154,8 @@ class ArCoreImpl : public ArCore {
std::map<HitTestSubscriptionId, TransientInputHitTestSubscriptionData>
hit_test_subscription_id_to_transient_hit_test_data_;
// Returns tuple containing plane id and a boolean signifying that the plane
// Returns tuple containing anchor id and a boolean signifying that the anchor
// was created.
std::pair<PlaneId, bool> CreateOrGetPlaneId(void* plane_address);
std::pair<AnchorId, bool> CreateOrGetAnchorId(void* anchor_address);
HitTestSubscriptionId CreateHitTestSubscriptionId();
......@@ -306,11 +212,6 @@ class ArCoreImpl : public ArCore {
const base::Optional<std::vector<mojom::XRInputSourceStatePtr>>&
maybe_input_state);
// Executes |fn| for each still tracked, non-subsumed plane present in
// |arcore_planes_|.
template <typename FunctionType>
void ForEachArCorePlane(FunctionType fn);
// Executes |fn| for each still tracked anchor present in |arcore_anchors_|.
template <typename FunctionType>
void ForEachArCoreAnchor(FunctionType fn);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/vr/arcore_device/arcore_plane_manager.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
#include "chrome/browser/android/vr/arcore_device/type_converters.h"
namespace device {
std::pair<gfx::Quaternion, gfx::Point3F> GetPositionAndOrientationFromArPose(
const ArSession* session,
const ArPose* pose) {
std::array<float, 7> pose_raw; // 7 = orientation(4) + position(3).
ArPose_getPoseRaw(session, pose, pose_raw.data());
return {gfx::Quaternion(pose_raw[0], pose_raw[1], pose_raw[2], pose_raw[3]),
gfx::Point3F(pose_raw[4], pose_raw[5], pose_raw[6])};
}
device::mojom::Pose GetMojomPoseFromArPose(const ArSession* session,
const ArPose* pose) {
device::mojom::Pose result;
std::tie(result.orientation, result.position) =
GetPositionAndOrientationFromArPose(session, pose);
return result;
}
device::internal::ScopedArCoreObject<ArPose*> GetArPoseFromMojomPose(
const ArSession* session,
const device::mojom::Pose& pose) {
float pose_raw[7] = {}; // 7 = orientation(4) + position(3).
pose_raw[0] = pose.orientation.x();
pose_raw[1] = pose.orientation.y();
pose_raw[2] = pose.orientation.z();
pose_raw[3] = pose.orientation.w();
pose_raw[4] = pose.position.x();
pose_raw[5] = pose.position.y();
pose_raw[6] = pose.position.z();
device::internal::ScopedArCoreObject<ArPose*> result;
ArPose_create(
session, pose_raw,
device::internal::ScopedArCoreObject<ArPose*>::Receiver(result).get());
return result;
}
ArCorePlaneManager::ArCorePlaneManager(util::PassKey<ArCoreImpl> pass_key,
ArSession* arcore_session)
: arcore_session_(arcore_session) {
DCHECK(arcore_session_);
ArTrackableList_create(
arcore_session_,
internal::ScopedArCoreObject<ArTrackableList*>::Receiver(arcore_planes_)
.get());
DCHECK(arcore_planes_.is_valid());
ArPose_create(
arcore_session_, nullptr,
internal::ScopedArCoreObject<ArPose*>::Receiver(ar_pose_).get());
DCHECK(ar_pose_.is_valid());
}
ArCorePlaneManager::~ArCorePlaneManager() = default;
template <typename FunctionType>
void ArCorePlaneManager::ForEachArCorePlane(FunctionType fn) {
DCHECK(arcore_planes_.is_valid());
int32_t trackable_list_size;
ArTrackableList_getSize(arcore_session_, arcore_planes_.get(),
&trackable_list_size);
for (int i = 0; i < trackable_list_size; i++) {
internal::ScopedArCoreObject<ArTrackable*> trackable;
ArTrackableList_acquireItem(
arcore_session_, arcore_planes_.get(), i,
internal::ScopedArCoreObject<ArTrackable*>::Receiver(trackable).get());
ArTrackingState tracking_state;
ArTrackable_getTrackingState(arcore_session_, trackable.get(),
&tracking_state);
if (tracking_state != ArTrackingState::AR_TRACKING_STATE_TRACKING) {
// Skip all planes that are not currently tracked.
continue;
}
#if DCHECK_IS_ON()
{
ArTrackableType type;
ArTrackable_getType(arcore_session_, trackable.get(), &type);
DCHECK(type == ArTrackableType::AR_TRACKABLE_PLANE)
<< "arcore_planes_ contains a trackable that is not an ArPlane!";
}
#endif
ArPlane* ar_plane =
ArAsPlane(trackable.get()); // Naked pointer is fine here, ArAsPlane
// does not increase ref count.
internal::ScopedArCoreObject<ArPlane*> subsuming_plane;
ArPlane_acquireSubsumedBy(
arcore_session_, ar_plane,
internal::ScopedArCoreObject<ArPlane*>::Receiver(subsuming_plane)
.get());
if (subsuming_plane.is_valid()) {
// Current plane was subsumed by other plane, skip this loop iteration.
// Subsuming plane will be handled when its turn comes.
continue;
}
fn(std::move(trackable), ar_plane);
}
}
std::vector<mojom::XRPlaneDataPtr> ArCorePlaneManager::GetUpdatedPlanesData(
ArFrame* arcore_frame) {
std::vector<mojom::XRPlaneDataPtr> result;
ArTrackableType plane_tracked_type = AR_TRACKABLE_PLANE;
ArFrame_getUpdatedTrackables(arcore_session_, arcore_frame,
plane_tracked_type, arcore_planes_.get());
ForEachArCorePlane(
[this, &result](internal::ScopedArCoreObject<ArTrackable*> trackable,
ArPlane* ar_plane) {
// orientation
ArPlaneType plane_type;
ArPlane_getType(arcore_session_, ar_plane, &plane_type);
// pose
internal::ScopedArCoreObject<ArPose*> plane_pose;
ArPose_create(
arcore_session_, nullptr,
internal::ScopedArCoreObject<ArPose*>::Receiver(plane_pose).get());
ArPlane_getCenterPose(arcore_session_, ar_plane, plane_pose.get());
mojom::Pose pose =
GetMojomPoseFromArPose(arcore_session_, plane_pose.get());
// polygon
int32_t polygon_size;
ArPlane_getPolygonSize(arcore_session_, ar_plane, &polygon_size);
// We are supposed to get 2*N floats describing (x, z) cooridinates of N
// points.
DCHECK(polygon_size % 2 == 0);
std::unique_ptr<float[]> vertices_raw =
std::make_unique<float[]>(polygon_size);
ArPlane_getPolygon(arcore_session_, ar_plane, vertices_raw.get());
std::vector<mojom::XRPlanePointDataPtr> vertices;
for (int i = 0; i < polygon_size; i += 2) {
vertices.push_back(mojom::XRPlanePointData::New(vertices_raw[i],
vertices_raw[i + 1]));
}
// ID
PlaneId plane_id;
bool created;
std::tie(plane_id, created) = CreateOrGetPlaneId(ar_plane);
result.push_back(mojom::XRPlaneData::New(
plane_id.GetUnsafeValue(),
mojo::ConvertTo<device::mojom::XRPlaneOrientation>(plane_type),
device::mojom::Pose::New(pose), std::move(vertices)));
});
return result;
}
std::vector<uint64_t> ArCorePlaneManager::GetAllPlaneIds() {
std::vector<uint64_t> result;
ArTrackableType plane_tracked_type = AR_TRACKABLE_PLANE;
ArSession_getAllTrackables(arcore_session_, plane_tracked_type,
arcore_planes_.get());
std::map<PlaneId, device::internal::ScopedArCoreObject<ArTrackable*>>
plane_id_to_plane_object;
ForEachArCorePlane([this, &plane_id_to_plane_object, &result](
internal::ScopedArCoreObject<ArTrackable*> trackable,
ArPlane* ar_plane) {
// ID
PlaneId plane_id;
bool created;
std::tie(plane_id, created) = CreateOrGetPlaneId(ar_plane);
DCHECK(!created)
<< "Newly detected planes should be handled by GetUpdatedPlanesData().";
result.emplace_back(plane_id);
plane_id_to_plane_object[plane_id] = std::move(trackable);
});
plane_id_to_plane_object_.swap(plane_id_to_plane_object);
return result;
}
mojom::XRPlaneDetectionDataPtr ArCorePlaneManager::GetDetectedPlanesData(
ArFrame* ar_frame) {
TRACE_EVENT0("gpu", __FUNCTION__);
DCHECK(ar_frame);
auto updated_planes = GetUpdatedPlanesData(ar_frame);
auto all_plane_ids = GetAllPlaneIds();
return mojom::XRPlaneDetectionData::New(all_plane_ids,
std::move(updated_planes));
}
std::pair<PlaneId, bool> ArCorePlaneManager::CreateOrGetPlaneId(
void* plane_address) {
auto it = ar_plane_address_to_id_.find(plane_address);
if (it != ar_plane_address_to_id_.end()) {
return std::make_pair(it->second, false);
}
CHECK(next_id_ != std::numeric_limits<uint64_t>::max())
<< "preventing ID overflow";
uint64_t current_id = next_id_++;
ar_plane_address_to_id_.emplace(plane_address, current_id);
return std::make_pair(PlaneId(current_id), true);
}
bool ArCorePlaneManager::PlaneExists(PlaneId id) {
return base::Contains(plane_id_to_plane_object_, id);
}
base::Optional<gfx::Transform> ArCorePlaneManager::GetMojoFromPlane(
PlaneId id) {
auto it = plane_id_to_plane_object_.find(id);
if (it == plane_id_to_plane_object_.end()) {
return base::nullopt;
}
ArPlane* plane =
ArAsPlane(it->second.get()); // Naked pointer is fine here, ArAsPlane
// does not increase the internal refcount.
ArPlane_getCenterPose(arcore_session_, plane, ar_pose_.get());
mojom::Pose mojo_pose =
GetMojomPoseFromArPose(arcore_session_, ar_pose_.get());
return mojo::ConvertTo<gfx::Transform>(mojo_pose);
}
device::internal::ScopedArCoreObject<ArAnchor*>
ArCorePlaneManager::CreateAnchor(PlaneId id, const device::mojom::Pose& pose) {
auto it = plane_id_to_plane_object_.find(id);
if (it == plane_id_to_plane_object_.end()) {
return {};
}
auto ar_pose = GetArPoseFromMojomPose(arcore_session_, pose);
device::internal::ScopedArCoreObject<ArAnchor*> ar_anchor;
ArStatus status = ArTrackable_acquireNewAnchor(
arcore_session_, it->second.get(), ar_pose.get(),
device::internal::ScopedArCoreObject<ArAnchor*>::Receiver(ar_anchor)
.get());
if (status != AR_SUCCESS) {
return {};
}
return ar_anchor;
}
} // namespace device
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_PLANE_MANAGER_H_
#define CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_PLANE_MANAGER_H_
#include <map>
#include "base/util/type_safety/id_type.h"
#include "base/util/type_safety/pass_key.h"
#include "chrome/browser/android/vr/arcore_device/arcore_sdk.h"
#include "chrome/browser/android/vr/arcore_device/scoped_arcore_objects.h"
#include "device/vr/public/mojom/vr_service.mojom.h"
namespace device {
class ArCoreImpl;
using PlaneId = util::IdTypeU64<class PlaneTag>;
std::pair<gfx::Quaternion, gfx::Point3F> GetPositionAndOrientationFromArPose(
const ArSession* session,
const ArPose* pose);
device::mojom::Pose GetMojomPoseFromArPose(const ArSession* session,
const ArPose* pose);
device::internal::ScopedArCoreObject<ArPose*> GetArPoseFromMojomPose(
const ArSession* session,
const device::mojom::Pose& pose);
class ArCorePlaneManager {
public:
ArCorePlaneManager(util::PassKey<ArCoreImpl> pass_key,
ArSession* arcore_session);
~ArCorePlaneManager();
mojom::XRPlaneDetectionDataPtr GetDetectedPlanesData(ArFrame* ar_frame);
bool PlaneExists(PlaneId id);
// Returns base::nullopt if plane with the given id does not exist.
base::Optional<gfx::Transform> GetMojoFromPlane(PlaneId id);
device::internal::ScopedArCoreObject<ArAnchor*> CreateAnchor(
PlaneId id,
const device::mojom::Pose& pose);
private:
// Returns vector containing information about all planes updated in current
// frame, assigning IDs for newly detected planes as needed.
std::vector<mojom::XRPlaneDataPtr> GetUpdatedPlanesData(ArFrame* ar_frame);
// This must be called after GetUpdatedPlanesData as it assumes that all
// planes already have an ID assigned. The result includes freshly assigned
// IDs for newly detected planes along with previously known IDs for updated
// and unchanged planes. It excludes planes that are no longer being tracked.
std::vector<uint64_t> GetAllPlaneIds();
// Executes |fn| for each still tracked, non-subsumed plane present in
// |arcore_planes_|.
template <typename FunctionType>
void ForEachArCorePlane(FunctionType fn);
// Owned by ArCoreImpl - non-owning pointer is fine since ArCorePlaneManager
// is also owned by ArCoreImpl.
ArSession* arcore_session_;
// List of trackables - used for retrieving planes detected by ARCore.
// Allows reuse of the list across updates; ARCore clears the list on each
// call to the ARCore SDK.
internal::ScopedArCoreObject<ArTrackableList*> arcore_planes_;
// Allows reuse of the pose across different objects.
internal::ScopedArCoreObject<ArPose*> ar_pose_;
uint64_t next_id_ = 1;
// Returns tuple containing plane id and a boolean signifying that the
// plane was created.;
std::pair<PlaneId, bool> CreateOrGetPlaneId(void* plane_address);
std::map<void*, PlaneId> ar_plane_address_to_id_;
std::map<PlaneId, device::internal::ScopedArCoreObject<ArTrackable*>>
plane_id_to_plane_object_;
};
} // namespace device
#endif // CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_PLANE_MANAGER_H_
......@@ -304,16 +304,14 @@ mojom::XRLightEstimationDataPtr FakeArCore::GetLightEstimationData() {
return result;
}
base::Optional<uint64_t> FakeArCore::CreateAnchor(const mojom::PosePtr& pose,
base::Optional<uint64_t> FakeArCore::CreateAnchor(const mojom::Pose& pose,
uint64_t plane_id) {
// TODO(992035): Fix this when implementing tests.
return CreateAnchor(pose);
}
base::Optional<uint64_t> FakeArCore::CreateAnchor(const mojom::PosePtr& pose) {
DCHECK(pose);
anchors_[next_id_] = {pose->position, pose->orientation};
base::Optional<uint64_t> FakeArCore::CreateAnchor(const mojom::Pose& pose) {
anchors_[next_id_] = {pose.position, pose.orientation};
int32_t anchor_id = next_id_;
next_id_++;
......
......@@ -61,8 +61,8 @@ class FakeArCore : public ArCore {
mojom::XRLightEstimationDataPtr GetLightEstimationData() override;
base::Optional<uint64_t> CreateAnchor(
const device::mojom::PosePtr& pose) override;
base::Optional<uint64_t> CreateAnchor(const device::mojom::PosePtr& pose,
const device::mojom::Pose& pose) override;
base::Optional<uint64_t> CreateAnchor(const device::mojom::Pose& pose,
uint64_t plane_id) override;
void DetachAnchor(uint64_t anchor_id) override;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_SCOPED_ARCORE_OBJECTS_H_
#define CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_SCOPED_ARCORE_OBJECTS_H_
#include "base/scoped_generic.h"
#include "chrome/browser/android/vr/arcore_device/arcore_sdk.h"
namespace device {
namespace internal {
template <class T>
struct ScopedGenericArObject {
static T InvalidValue() { return nullptr; }
static void Free(T object) {}
};
template <>
void inline ScopedGenericArObject<ArSession*>::Free(ArSession* ar_session) {
ArSession_destroy(ar_session);
}
template <>
void inline ScopedGenericArObject<ArFrame*>::Free(ArFrame* ar_frame) {
ArFrame_destroy(ar_frame);
}
template <>
void inline ScopedGenericArObject<ArConfig*>::Free(ArConfig* ar_config) {
ArConfig_destroy(ar_config);
}
template <>
void inline ScopedGenericArObject<ArPose*>::Free(ArPose* ar_pose) {
ArPose_destroy(ar_pose);
}
template <>
void inline ScopedGenericArObject<ArTrackable*>::Free(
ArTrackable* ar_trackable) {
ArTrackable_release(ar_trackable);
}
template <>
void inline ScopedGenericArObject<ArPlane*>::Free(ArPlane* ar_plane) {
// ArPlane itself doesn't have a method to decrease refcount, but it is an
// instance of ArTrackable & we have to use ArTrackable_release.
ArTrackable_release(ArAsTrackable(ar_plane));
}
template <>
void inline ScopedGenericArObject<ArAnchor*>::Free(ArAnchor* ar_anchor) {
ArAnchor_release(ar_anchor);
}
template <>
void inline ScopedGenericArObject<ArTrackableList*>::Free(
ArTrackableList* ar_trackable_list) {
ArTrackableList_destroy(ar_trackable_list);
}
template <>
void inline ScopedGenericArObject<ArCamera*>::Free(ArCamera* ar_camera) {
// Do nothing - ArCamera has no destroy method and is managed by ArCore.
}
template <>
void inline ScopedGenericArObject<ArHitResultList*>::Free(
ArHitResultList* ar_hit_result_list) {
ArHitResultList_destroy(ar_hit_result_list);
}
template <>
void inline ScopedGenericArObject<ArHitResult*>::Free(
ArHitResult* ar_hit_result) {
ArHitResult_destroy(ar_hit_result);
}
template <class T>
using ScopedArCoreObject = base::ScopedGeneric<T, ScopedGenericArObject<T>>;
} // namespace internal
} // namespace device
#endif // CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_SCOPED_ARCORE_OBJECTS_H_
......@@ -36,14 +36,14 @@ gfx::Transform TypeConverter<gfx::Transform, device::mojom::VRPosePtr>::Convert(
return gfx::ComposeTransform(decomposed);
}
gfx::Transform TypeConverter<gfx::Transform, device::mojom::PosePtr>::Convert(
const device::mojom::PosePtr& pose) {
gfx::Transform TypeConverter<gfx::Transform, device::mojom::Pose>::Convert(
const device::mojom::Pose& pose) {
gfx::DecomposedTransform decomposed;
decomposed.quaternion = pose->orientation;
decomposed.quaternion = pose.orientation;
decomposed.translate[0] = pose->position.x();
decomposed.translate[1] = pose->position.y();
decomposed.translate[2] = pose->position.z();
decomposed.translate[0] = pose.position.x();
decomposed.translate[1] = pose.position.y();
decomposed.translate[2] = pose.position.z();
return gfx::ComposeTransform(decomposed);
}
......
......@@ -22,8 +22,8 @@ struct TypeConverter<gfx::Transform, device::mojom::VRPosePtr> {
};
template <>
struct TypeConverter<gfx::Transform, device::mojom::PosePtr> {
static gfx::Transform Convert(const device::mojom::PosePtr& pose);
struct TypeConverter<gfx::Transform, device::mojom::Pose> {
static gfx::Transform Convert(const device::mojom::Pose& pose);
};
} // namespace mojo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment