Commit 51415e41 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

Fix runtime flag handling for plane detection, fix xrray polyfill

Bug: 966607
Change-Id: I3c2719ba8a3128b4c261a916a604626b82c1c1ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1632916Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664027}
parent ea89848c
......@@ -52,6 +52,13 @@ XRRuntimeManager* g_xr_runtime_manager = nullptr;
base::LazyInstance<base::ObserverList<XRRuntimeManagerObserver>>::Leaky
g_xr_runtime_manager_observers;
// Returns true if any of the AR-related features are enabled.
bool AreArFeaturesEnabled() {
return base::FeatureList::IsEnabled(features::kWebXrHitTest) ||
base::FeatureList::IsEnabled(features::kWebXrPlaneDetection);
}
} // namespace
XRRuntimeManager::~XRRuntimeManager() {
......@@ -64,15 +71,17 @@ XRRuntimeManager* XRRuntimeManager::GetInstance() {
// Register VRDeviceProviders for the current platform
ProviderList providers;
if (AreArFeaturesEnabled()) {
#if defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_ARCORE)
if (base::FeatureList::IsEnabled(features::kWebXrHitTest)) {
providers.emplace_back(device::ArCoreDeviceProviderFactory::Create());
#endif // BUILDFLAG(ENABLE_ARCORE)
#endif // defined(OS_ANDROID)
}
#endif
#if defined(OS_ANDROID)
providers.emplace_back(std::make_unique<device::GvrDeviceProvider>());
#endif
#endif // defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_ISOLATED_XR_SERVICE)
providers.emplace_back(std::make_unique<vr::IsolatedVRDeviceProvider>());
......
......@@ -77,6 +77,9 @@ XRSession::SessionMode stringToSessionMode(const String& mode_string) {
return XRSession::kModeInline;
}
// When updating this list, also update XRRuntimeManager's
// AreArFeaturesEnabled() until https://crbug.com/966647 is fixed.
// TODO(https://crbug.com/966647) remove the above comment when fixed.
bool AreArRuntimeFeaturesEnabled(const FeatureContext* context) {
return RuntimeEnabledFeatures::WebXRHitTestEnabled(context) ||
RuntimeEnabledFeatures::WebXRPlaneDetectionEnabled(context);
......
......@@ -42,7 +42,7 @@ const multiply = function(lhs, rhs) {
for(let col = 0; col < 4; ++col) {
for(let row = 0; row < 4; ++row) {
for(let k = 0; k < 4; ++k) {
result[col * 4 + row] += rhs[col][k] * lhs[k][row];
result[col * 4 + row] += rhs[col * 4 + k] * lhs[k * 4 + row];
}
}
}
......@@ -89,7 +89,7 @@ const rotate = function(matrix, axis, angle) {
// second column
axis.x * axis.y * one_minus_cos_angle - axis.z * sin_angle,
cos_angle + axis.y * axis.y * one_minus_cos_angle,
axis.z * axis.y * one_minus_cos_angle + x * sin_angle,
axis.z * axis.y * one_minus_cos_angle + axis.x * sin_angle,
0,
// third column
axis.x * axis.z * one_minus_cos_angle + axis.y * sin_angle,
......@@ -108,7 +108,6 @@ const rotate = function(matrix, axis, angle) {
export class XRRay {
constructor() {
if (arguments.length > 0 && arguments[0] instanceof XRRigidTransform) {
if(arguments.length != 1)
throw new Error("Invalid number of arguments!");
......@@ -139,7 +138,7 @@ export class XRRay {
]);
const initial_ray_direction = [0, 0, -1];
const desired_ray_direction = [direction.x, direction.y, direction.z];
const desired_ray_direction = [this.direction_.x, this.direction_.y, this.direction_.z];
const cos_angle = dot(initial_ray_direction, desired_ray_direction);
......@@ -153,14 +152,14 @@ export class XRRay {
const axis = new DOMPointReadOnly(1, 0, 0, 0);
cos_angle = -1;
this.matrix_ = rotate(this.matrix_, axis, Math.acos(angle));
this.matrix_ = rotate(this.matrix_, axis, Math.acos(cos_angle));
} else {
// Rotation needed - create it from axis-angle.
const cross_initial_desired = cross(initialRayDirection, desiredRayDirection);
const cross_initial_desired = cross(initial_ray_direction, desired_ray_direction);
const axis = normalizeLength(new DOMPointReadOnly(
cross_initial_desired[0], cross_initial_desired[1], cross_initial_desired[2], 0));
this.matrix_ = rotate(this.matrix_, axis, Math.acos(angle));
this.matrix_ = rotate(this.matrix_, axis, Math.acos(cos_angle));
}
}
......
......@@ -294,7 +294,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}
function DOMPointFromVec4(vector) {
return { x : vector[0], y : vector[1], z : vector[2], w : vector[3]}
return new DOMPointReadOnly(vector[0], vector[1], vector[2], vector[3]);
}
let rayOrigin = vec4.create();
......
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