Commit d6456ac6 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

Move OS version check for AR Core from java to native

Additionally, add a call to check AR Core support from ArCoreDeviceProvider.

This will also fix an issue where not all options for supportsSession
call were being passed.

R=billorr@chromium.org, btebbs@chromium.org, mthiesse@chromium.org

Bug: 852607
Change-Id: I3e407fd001368cbdead0dbf271ee3bdca8188019
Reviewed-on: https://chromium-review.googlesource.com/c/1341025
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609465}
parent 7b3de759
...@@ -80,17 +80,6 @@ public class ArCoreJavaUtils { ...@@ -80,17 +80,6 @@ public class ArCoreJavaUtils {
return ContextUtils.getApplicationContext(); return ContextUtils.getApplicationContext();
} }
/**
* Determines whether ARCore's SDK should be loaded. Currently, this only
* depends on the OS version, but could be more sophisticated.
*
* @return true if the SDK should be loaded.
*/
@CalledByNative
private static boolean shouldLoadArCoreSdk() {
return Build.VERSION.SDK_INT >= MIN_SDK_VERSION;
}
@CalledByNative @CalledByNative
private static ArCoreJavaUtils create(long nativeArCoreJavaUtils) { private static ArCoreJavaUtils create(long nativeArCoreJavaUtils) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/android/vr/arcore_device/arcore_device_provider.h" #include "chrome/browser/android/vr/arcore_device/arcore_device_provider.h"
#include "chrome/browser/android/vr/arcore_device/arcore_device.h" #include "chrome/browser/android/vr/arcore_device/arcore_device.h"
#include "chrome/browser/android/vr/arcore_device/arcore_shim.h"
namespace device { namespace device {
...@@ -18,10 +19,13 @@ void ArCoreDeviceProvider::Initialize( ...@@ -18,10 +19,13 @@ void ArCoreDeviceProvider::Initialize(
mojom::XRRuntimePtr)> add_device_callback, mojom::XRRuntimePtr)> add_device_callback,
base::RepeatingCallback<void(mojom::XRDeviceId)> remove_device_callback, base::RepeatingCallback<void(mojom::XRDeviceId)> remove_device_callback,
base::OnceClosure initialization_complete) { base::OnceClosure initialization_complete) {
arcore_device_ = base::WrapUnique(new ArCoreDevice()); if (vr::SupportsArCore())
add_device_callback.Run(arcore_device_->GetId(), arcore_device_ = std::make_unique<ArCoreDevice>();
arcore_device_->GetVRDisplayInfo(), if (arcore_device_) {
arcore_device_->BindXRRuntimePtr()); add_device_callback.Run(arcore_device_->GetId(),
arcore_device_->GetVRDisplayInfo(),
arcore_device_->BindXRRuntimePtr());
}
initialized_ = true; initialized_ = true;
std::move(initialization_complete).Run(); std::move(initialization_complete).Run();
} }
......
...@@ -114,10 +114,11 @@ void ArCoreJavaUtils::OnRequestInstallArModuleResult( ...@@ -114,10 +114,11 @@ void ArCoreJavaUtils::OnRequestInstallArModuleResult(
} }
bool ArCoreJavaUtils::EnsureLoaded() { bool ArCoreJavaUtils::EnsureLoaded() {
JNIEnv* env = AttachCurrentThread(); if (!vr::SupportsArCore())
if (!Java_ArCoreJavaUtils_shouldLoadArCoreSdk(env))
return false; return false;
JNIEnv* env = AttachCurrentThread();
// TODO(crbug.com/884780): Allow loading the ARCore shim by name instead of by // TODO(crbug.com/884780): Allow loading the ARCore shim by name instead of by
// absolute path. // absolute path.
ScopedJavaLocalRef<jstring> java_path = ScopedJavaLocalRef<jstring> java_path =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include "base/android/build_info.h"
#include "base/logging.h" #include "base/logging.h"
namespace { namespace {
...@@ -94,6 +95,11 @@ bool LoadArCoreSdk(const std::string& libraryPath) { ...@@ -94,6 +95,11 @@ bool LoadArCoreSdk(const std::string& libraryPath) {
return true; return true;
} }
bool SupportsArCore() {
return base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_OREO;
}
} // namespace vr } // namespace vr
#undef FOR_EACH_API_FN #undef FOR_EACH_API_FN
......
...@@ -10,6 +10,15 @@ namespace vr { ...@@ -10,6 +10,15 @@ namespace vr {
// TODO(vollick): add support for unloading the SDK. // TODO(vollick): add support for unloading the SDK.
bool LoadArCoreSdk(const std::string& libraryPath); bool LoadArCoreSdk(const std::string& libraryPath);
/**
* Determines whether AR Core features are supported. Currently, this only
* depends on the OS version, but could be more sophisticated.
* Calling this method won't load AR Core SDK and does not depend
* on AR Core SDK to be loaded.
* Returns true if the AR Core usage is supported, false otherwise.
*/
bool SupportsArCore();
} // namespace vr } // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_SHIM_H_ #endif // CHROME_BROWSER_ANDROID_VR_ARCORE_DEVICE_ARCORE_SHIM_H_
...@@ -32,6 +32,23 @@ const char kRequestRequiresUserActivation[] = ...@@ -32,6 +32,23 @@ const char kRequestRequiresUserActivation[] =
const char kSessionNotSupported[] = const char kSessionNotSupported[] =
"The specified session configuration is not supported."; "The specified session configuration is not supported.";
/**
* Helper method to convert IDL options into Mojo options.
*/
device::mojom::blink::XRSessionOptionsPtr convertIdlOptionsToMojo(
const XRSessionCreationOptions* options) {
auto session_options = device::mojom::blink::XRSessionOptions::New();
if (options->hasImmersive()) {
session_options->immersive = options->immersive();
}
if (options->hasEnvironmentIntegration()) {
session_options->environment_integration =
options->environmentIntegration();
}
return session_options;
}
} // namespace } // namespace
XRDevice::XRDevice(XR* xr, device::mojom::blink::XRDevicePtr device) XRDevice::XRDevice(XR* xr, device::mojom::blink::XRDevicePtr device)
...@@ -71,8 +88,7 @@ ScriptPromise XRDevice::supportsSession( ...@@ -71,8 +88,7 @@ ScriptPromise XRDevice::supportsSession(
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
device::mojom::blink::XRSessionOptionsPtr session_options = device::mojom::blink::XRSessionOptionsPtr session_options =
device::mojom::blink::XRSessionOptions::New(); convertIdlOptionsToMojo(options);
session_options->immersive = options->immersive();
device_ptr_->SupportsSession( device_ptr_->SupportsSession(
std::move(session_options), std::move(session_options),
...@@ -154,9 +170,7 @@ ScriptPromise XRDevice::requestSession( ...@@ -154,9 +170,7 @@ ScriptPromise XRDevice::requestSession(
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
device::mojom::blink::XRSessionOptionsPtr session_options = device::mojom::blink::XRSessionOptionsPtr session_options =
device::mojom::blink::XRSessionOptions::New(); convertIdlOptionsToMojo(options);
session_options->immersive = options->immersive();
session_options->environment_integration = options->environmentIntegration();
session_options->has_user_activation = has_user_activation; session_options->has_user_activation = has_user_activation;
XRPresentationContext* output_context = XRPresentationContext* output_context =
......
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