Skip to content

Commit

Permalink
Standup Skeleton Code for Cardboard Runtime
Browse files Browse the repository at this point in the history
Creates features and infrastructure and initial include to begin
building the Cardboard runtime for WebXR. Currently the runtime will
simply reject all session requests, but it links in and initializes the
sdk as a proof of concept that all build files should be mostly
structured right. Stands up the following skeletons/infrastructure:
* Feature Flag and About Flags entry
* Creates CardboardDevice/Provider and adds it (and does not add the
GVR Device) based on the Cardboard Feature Flag
* Adds build files for //third_party/cardboard
* Adds VR Buildflag for Cardboard
* Creates basic directory and build file structure for cardboard
* Incorporates cardboard build into Chrome build.

Bug: 989117
Change-Id: I3e0e4349cb1a031404c38b0a6175681575c23e4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4160186
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Reviewed-by: Piotr Bialecki <bialpio@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096488}
  • Loading branch information
alcooper91 authored and Chromium LUCI CQ committed Jan 24, 2023
1 parent 7e7dc6d commit bdd9a76
Show file tree
Hide file tree
Showing 33 changed files with 769 additions and 2 deletions.
4 changes: 4 additions & 0 deletions base/android/jni_android.cc
Expand Up @@ -127,6 +127,10 @@ bool IsVMInitialized() {
return g_jvm != nullptr;
}

JavaVM* GetVM() {
return g_jvm;
}

void InitGlobalClassLoader(JNIEnv* env) {
DCHECK(g_class_loader == nullptr);

Expand Down
3 changes: 3 additions & 0 deletions base/android/jni_android.h
Expand Up @@ -79,6 +79,9 @@ BASE_EXPORT void InitVM(JavaVM* vm);
// Returns true if the global JVM has been initialized.
BASE_EXPORT bool IsVMInitialized();

// Returns the global JVM, or nullptr if it has not been initialized.
BASE_EXPORT JavaVM* GetVM();

// Initializes the global ClassLoader used by the GetClass and LazyGetClass
// methods. This is needed because JNI will use the base ClassLoader when there
// is no Java code on the stack. The base ClassLoader doesn't know about any of
Expand Down
4 changes: 4 additions & 0 deletions chrome/android/BUILD.gn
Expand Up @@ -757,6 +757,10 @@ if (current_toolchain == default_toolchain) {
]
}

if (enable_cardboard) {
deps += [ "//third_party/cardboard:cardboard_java" ]
}

if (enable_vr) {
deps += [ ":chrome_vr_java_resources" ]
}
Expand Down
1 change: 1 addition & 0 deletions chrome/android/chrome_public_apk_tmpl.gni
Expand Up @@ -22,6 +22,7 @@ default_chrome_public_jinja_variables = [
"channel=$android_channel",
"enable_vr=$enable_vr",
"include_arcore_manifest_flag=false",
"enable_cardboard=$enable_cardboard",
"zygote_preload_class=org.chromium.content_public.app.ZygotePreload",
]

Expand Down
10 changes: 10 additions & 0 deletions chrome/android/java/AndroidManifest.xml
Expand Up @@ -577,6 +577,16 @@ by a child template that "extends" this file.
{{ self.supports_vr() }}
</activity>
{% endif %}
{% set enable_cardboard = enable_cardboard|default(0) %}
{% if enable_cardboard == "true" %}
<!-- Based on //third_party/cardboard/src/sdk/qrcode/android/AndroidManifest.xml -->
<activity
android:name="com.google.cardboard.sdk.QrCodeCaptureActivity"
android:exported="false"
android:label="@string/title_activity_qr_code_capture"
android:theme="@style/Theme.AppCompat.NoActionBar">
</activity>
{% endif %}
<activity android:name="org.chromium.chrome.browser.signin.SyncConsentActivity"
android:theme="@style/Theme.Chromium.DialogWhenLarge"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|mcc|mnc|screenLayout|smallestScreenSize"
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/BUILD.gn
Expand Up @@ -7489,6 +7489,10 @@ static_library("browser") {
"//device/vr/android/arcore",
]
}

if (enable_cardboard) {
deps += [ "//device/vr/android/cardboard:vr_cardboard" ]
}
} else {
deps += [ "//device/vr/public/mojom:isolated_xr_service" ]
}
Expand Down
9 changes: 9 additions & 0 deletions chrome/browser/about_flags.cc
Expand Up @@ -276,6 +276,10 @@
#include "chrome/browser/ui/cocoa/screentime/screentime_features.h"
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(ENABLE_CARDBOARD)
#include "device/vr/public/cpp/features.h"
#endif // ENABLE_CARDBOARD

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/extension_features.h"
#include "extensions/common/switches.h"
Expand Down Expand Up @@ -3327,6 +3331,11 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kVerboseLoggingInNaclDescription, kOsAll,
MULTI_VALUE_TYPE(kVerboseLoggingInNaclChoices)},
#endif // ENABLE_NACL
#if BUILDFLAG(ENABLE_CARDBOARD)
{"enable-cardboard", flag_descriptions::kEnableCardboardName,
flag_descriptions::kEnableCardboardDescription, kOsAndroid,
FEATURE_VALUE_TYPE(device::features::kEnableCardboard)},
#endif // ENABLE_CARDBOARD
#if BUILDFLAG(ENABLE_EXTENSIONS)
{"extensions-on-chrome-urls",
flag_descriptions::kExtensionsOnChromeUrlsName,
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/flag-metadata.json
Expand Up @@ -1841,6 +1841,11 @@
"owners": ["ydago"],
"expiry_milestone": 106
},
{
"name": "enable-cardboard",
"owners": [ "alcooper", "chrome-xr-eng@google.com"],
"expiry_milestone": 120
},
{
"name": "enable-cast-remoting-query-blocklist",
"owners": [ "rwkeane@google.com", "openscreen-eng@google.com" ],
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/flag_descriptions.cc
Expand Up @@ -6371,6 +6371,14 @@ const char kDcheckIsFatalDescription[] =
"rather than crashing. If enabled, DCHECKs will crash the calling process.";
#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)

#if BUILDFLAG(ENABLE_CARDBOARD)
extern const char kEnableCardboardName[] = "Enable Cardboard VR WebXR Runtime";
extern const char kEnableCardboardDescription[] =
"Enables the use of the Cardboard SDK runtime for WebXR instead of the"
"Google VR Services (or GVR) runtime to start a WebXR-based immersive-vr"
"session.";
#endif // ENABLE_CARDBOARD

#if BUILDFLAG(ENABLE_NACL)
const char kNaclName[] = "Native Client";
const char kNaclDescription[] =
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/flag_descriptions.h
Expand Up @@ -14,6 +14,7 @@
#include "chrome/common/buildflags.h"
#include "components/nacl/common/buildflags.h"
#include "components/paint_preview/buildflags/buildflags.h"
#include "device/vr/buildflags/buildflags.h"
#include "extensions/buildflags/buildflags.h"
#include "media/media_buildflags.h"
#include "pdf/buildflags.h"
Expand Down Expand Up @@ -3685,6 +3686,11 @@ extern const char kDcheckIsFatalName[];
extern const char kDcheckIsFatalDescription[];
#endif // BUILDFLAG(DCHECK_IS_CONFIGURABLE)

#if BUILDFLAG(ENABLE_CARDBOARD)
extern const char kEnableCardboardName[];
extern const char kEnableCardboardDescription[];
#endif // ENABLE_CARDBOARD

#if BUILDFLAG(ENABLE_NACL)
extern const char kNaclName[];
extern const char kNaclDescription[];
Expand Down
17 changes: 16 additions & 1 deletion chrome/browser/vr/chrome_xr_integration_client.cc
Expand Up @@ -17,6 +17,7 @@
#include "content/public/browser/media_stream_request.h"
#include "content/public/browser/xr_install_helper.h"
#include "device/vr/buildflags/buildflags.h"
#include "device/vr/public/cpp/features.h"
#include "device/vr/public/cpp/vr_device_provider.h"
#include "device/vr/public/mojom/vr_service.mojom-shared.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"
Expand All @@ -33,6 +34,9 @@
#include "components/webxr/android/arcore_device_provider.h"
#include "components/webxr/android/arcore_install_helper.h"
#endif // BUILDFLAG(ENABLE_ARCORE)
#if BUILDFLAG(ENABLE_CARDBOARD)
#include "device/vr/android/cardboard/cardboard_device_provider.h"
#endif
#endif // BUILDFLAG(IS_WIN)

namespace {
Expand Down Expand Up @@ -111,7 +115,18 @@ content::XRProviderList ChromeXrIntegrationClient::GetAdditionalProviders() {
content::XRProviderList providers;

#if BUILDFLAG(IS_ANDROID)
providers.push_back(std::make_unique<device::GvrDeviceProvider>());
bool add_gvr_device_provider = true;
#if BUILDFLAG(ENABLE_CARDBOARD)
// If the cardboard runtime is enabled we want to use it rather than the GVR
// runtime.
if (base::FeatureList::IsEnabled(device::features::kEnableCardboard)) {
providers.emplace_back(std::make_unique<device::CardboardDeviceProvider>());
add_gvr_device_provider = false;
}
#endif // ENABLE_CARDBOARD
if (add_gvr_device_provider) {
providers.push_back(std::make_unique<device::GvrDeviceProvider>());
}
#if BUILDFLAG(ENABLE_ARCORE)
base::android::ScopedJavaLocalRef<jobject> j_ar_compositor_delegate_provider =
vr::Java_ArCompositorDelegateProviderImpl_Constructor(
Expand Down
1 change: 1 addition & 0 deletions content/browser/xr/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+device/base",
"+device/vr/orientation",
"+device/vr/android/cardboard",
"+device/vr/test",
]
6 changes: 6 additions & 0 deletions content/browser/xr/service/browser_xr_runtime_impl.cc
Expand Up @@ -192,6 +192,9 @@ bool BrowserXRRuntimeImpl::SupportsCustomIPD() const {
case device::mojom::XRDeviceId::FAKE_DEVICE_ID:
case device::mojom::XRDeviceId::ORIENTATION_DEVICE_ID:
case device::mojom::XRDeviceId::GVR_DEVICE_ID:
#if BUILDFLAG(ENABLE_CARDBOARD)
case device::mojom::XRDeviceId::CARDBOARD_DEVICE_ID:
#endif // ENABLE_CARDBOARD
return false;
#if BUILDFLAG(ENABLE_OPENXR)
case device::mojom::XRDeviceId::OPENXR_DEVICE_ID:
Expand All @@ -210,6 +213,9 @@ bool BrowserXRRuntimeImpl::SupportsNonEmulatedHeight() const {
case device::mojom::XRDeviceId::ORIENTATION_DEVICE_ID:
return false;
case device::mojom::XRDeviceId::GVR_DEVICE_ID:
#if BUILDFLAG(ENABLE_CARDBOARD)
case device::mojom::XRDeviceId::CARDBOARD_DEVICE_ID:
#endif // ENABLE_CARDBOARD
#if BUILDFLAG(ENABLE_OPENXR)
case device::mojom::XRDeviceId::OPENXR_DEVICE_ID:
#endif
Expand Down
35 changes: 35 additions & 0 deletions device/vr/android/cardboard/BUILD.gn
@@ -0,0 +1,35 @@
# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/rules.gni")
import("//device/vr/buildflags/buildflags.gni")

assert(enable_cardboard)

component("vr_cardboard") {
defines = [ "IS_VR_CARDBOARD_IMPL" ]
sources = [
"cardboard_device.cc",
"cardboard_device.h",
"cardboard_device_provider.cc",
"cardboard_device_provider.h",
"cardboard_sdk.h",
"cardboard_sdk_impl.cc",
"cardboard_sdk_impl.h",
]

public_deps = [
"//device/vr:vr_base",
"//device/vr/public/cpp",
]

deps = [
"//base",
"//device/vr/android:vr_android",
"//gpu/command_buffer/service:gles2",
"//third_party/cardboard",
"//ui/android",
"//ui/gfx",
]
}
3 changes: 3 additions & 0 deletions device/vr/android/cardboard/DEPS
@@ -0,0 +1,3 @@
include_rules = [
"+third_party/cardboard/src/sdk/include"
]
50 changes: 50 additions & 0 deletions device/vr/android/cardboard/cardboard_device.cc
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/vr/android/cardboard/cardboard_device.h"

#include <utility>
#include <vector>

#include "base/no_destructor.h"
#include "base/notreached.h"

namespace device {

namespace {

const std::vector<mojom::XRSessionFeature>& GetSupportedFeatures() {
static base::NoDestructor<std::vector<mojom::XRSessionFeature>>
kSupportedFeatures{{
mojom::XRSessionFeature::REF_SPACE_VIEWER,
mojom::XRSessionFeature::REF_SPACE_LOCAL,
mojom::XRSessionFeature::REF_SPACE_LOCAL_FLOOR,
}};

return *kSupportedFeatures;
}

} // namespace

CardboardDevice::CardboardDevice(std::unique_ptr<CardboardSdk> cardboard_sdk)
: VRDeviceBase(mojom::XRDeviceId::CARDBOARD_DEVICE_ID),
cardboard_sdk_(std::move(cardboard_sdk)) {
SetSupportedFeatures(GetSupportedFeatures());
}

CardboardDevice::~CardboardDevice() = default;

void CardboardDevice::RequestSession(
mojom::XRRuntimeSessionOptionsPtr options,
mojom::XRRuntime::RequestSessionCallback callback) {
// TODO(https://crbug.com/989117): Implement
std::move(callback).Run(nullptr);
}

void CardboardDevice::ShutdownSession(
mojom::XRRuntime::ShutdownSessionCallback on_completed) {
NOTREACHED();
}

} // namespace device
40 changes: 40 additions & 0 deletions device/vr/android/cardboard/cardboard_device.h
@@ -0,0 +1,40 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEVICE_VR_ANDROID_CARDBOARD_CARDBOARD_DEVICE_H_
#define DEVICE_VR_ANDROID_CARDBOARD_CARDBOARD_DEVICE_H_

#include <memory>

#include "base/component_export.h"
#include "base/memory/weak_ptr.h"
#include "device/vr/android/cardboard/cardboard_sdk.h"
#include "device/vr/vr_device_base.h"

namespace device {

class COMPONENT_EXPORT(VR_CARDBOARD) CardboardDevice : public VRDeviceBase {
public:
explicit CardboardDevice(std::unique_ptr<CardboardSdk> cardboard_sdk);

CardboardDevice(const CardboardDevice&) = delete;
CardboardDevice& operator=(const CardboardDevice&) = delete;

~CardboardDevice() override;

// VRDeviceBase
void RequestSession(
mojom::XRRuntimeSessionOptionsPtr options,
mojom::XRRuntime::RequestSessionCallback callback) override;
void ShutdownSession(mojom::XRRuntime::ShutdownSessionCallback) override;

private:
std::unique_ptr<CardboardSdk> cardboard_sdk_;

base::WeakPtrFactory<CardboardDevice> weak_ptr_factory_{this};
};

} // namespace device

#endif // DEVICE_VR_ANDROID_CARDBOARD_CARDBOARD_DEVICE_H_
33 changes: 33 additions & 0 deletions device/vr/android/cardboard/cardboard_device_provider.cc
@@ -0,0 +1,33 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/vr/android/cardboard/cardboard_device_provider.h"

#include "device/vr/android/cardboard/cardboard_device.h"
#include "device/vr/android/cardboard/cardboard_sdk_impl.h"

namespace device {

CardboardDeviceProvider::CardboardDeviceProvider() = default;

CardboardDeviceProvider::~CardboardDeviceProvider() = default;

void CardboardDeviceProvider::Initialize(VRDeviceProviderClient* client) {
DVLOG(2) << __func__ << ": Cardboard is supported, creating device";

cardboard_device_ =
std::make_unique<CardboardDevice>(std::make_unique<CardboardSdkImpl>());

client->AddRuntime(cardboard_device_->GetId(),
cardboard_device_->GetDeviceData(),
cardboard_device_->BindXRRuntime());
initialized_ = true;
client->OnProviderInitialized();
}

bool CardboardDeviceProvider::Initialized() {
return initialized_;
}

} // namespace device

0 comments on commit bdd9a76

Please sign in to comment.