Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5416)

Unified Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2471433002: Implement WebVR presentation pausing for VR Shell Menu Mode (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/vr_shell_delegate.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell_delegate.cc b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
index d4ce924bb39e442872567825273be37bf2807438..b341bdfde6cae55b859218e8d0bb9dea3811b5e5 100644
--- a/chrome/browser/android/vr_shell/vr_shell_delegate.cc
+++ b/chrome/browser/android/vr_shell/vr_shell_delegate.cc
@@ -6,6 +6,7 @@
#include "base/android/jni_android.h"
#include "chrome/browser/android/vr_shell/vr_shell.h"
+#include "device/vr/android/gvr/gvr_device_provider.h"
#include "jni/VrShellDelegate_jni.h"
using base::android::JavaParamRef;
@@ -16,7 +17,7 @@ namespace vr_shell {
// A non presenting delegate for magic window mode.
class GvrNonPresentingDelegate : public device::GvrDelegate {
public:
- explicit GvrNonPresentingDelegate(jlong context) {
+ explicit GvrNonPresentingDelegate(jlong context) : weak_ptr_factory_(this) {
gvr_api_ =
gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context));
}
@@ -34,9 +35,12 @@ class GvrNonPresentingDelegate : public device::GvrDelegate {
void SetGvrPoseForWebVr(const gvr::Mat4f& pose,
uint32_t pose_index) override {}
gvr::GvrApi* gvr_api() override { return gvr_api_.get(); }
-
+ base::WeakPtr<GvrNonPresentingDelegate> GetWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+ }
private:
std::unique_ptr<gvr::GvrApi> gvr_api_;
+ base::WeakPtrFactory<GvrNonPresentingDelegate> weak_ptr_factory_;
};
VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
@@ -49,12 +53,16 @@ VrShellDelegate::~VrShellDelegate() {
GvrDelegateProvider::SetInstance(nullptr);
}
-VrShellDelegate* VrShellDelegate::getNativeDelegate(
+VrShellDelegate* VrShellDelegate::GetNativeDelegate(
JNIEnv* env, jobject jdelegate) {
long native_delegate = Java_VrShellDelegate_getNativePointer(env, jdelegate);
return reinterpret_cast<VrShellDelegate*>(native_delegate);
}
+base::WeakPtr<device::GvrDeviceProvider> VrShellDelegate::GetDeviceProvider() {
+ return device_provider_;
+}
+
void VrShellDelegate::ExitWebVRIfNecessary(JNIEnv* env, jobject obj) {
if (!device_provider_)
return;
@@ -63,7 +71,7 @@ void VrShellDelegate::ExitWebVRIfNecessary(JNIEnv* env, jobject obj) {
}
bool VrShellDelegate::RequestWebVRPresent(
- device::GvrDeviceProvider* device_provider) {
+ base::WeakPtr<device::GvrDeviceProvider> device_provider) {
// Only set one device provider at a time
DCHECK(!device_provider_);
device_provider_ = device_provider;
@@ -76,10 +84,7 @@ bool VrShellDelegate::RequestWebVRPresent(
}
void VrShellDelegate::ExitWebVRPresent() {
- if (!device_provider_)
- return;
-
- device_provider_ = nullptr;
+ device_provider_.reset();
// VRShell is no longer needed by WebVR, allow it to shut down if it's not
// being used elsewhere.
@@ -87,7 +92,7 @@ void VrShellDelegate::ExitWebVRPresent() {
Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj());
}
-device::GvrDelegate* VrShellDelegate::GetNonPresentingDelegate() {
+base::WeakPtr<device::GvrDelegate> VrShellDelegate::GetNonPresentingDelegate() {
if (!non_presenting_delegate_) {
JNIEnv* env = AttachCurrentThread();
jlong context = Java_VrShellDelegate_createNonPresentingNativeContext(
@@ -97,7 +102,8 @@ device::GvrDelegate* VrShellDelegate::GetNonPresentingDelegate() {
non_presenting_delegate_.reset(new GvrNonPresentingDelegate(context));
}
- return non_presenting_delegate_.get();
+ return static_cast<GvrNonPresentingDelegate*>(non_presenting_delegate_.get())
+ ->GetWeakPtr();
}
void VrShellDelegate::DestroyNonPresentingDelegate() {
@@ -107,11 +113,6 @@ void VrShellDelegate::DestroyNonPresentingDelegate() {
env, j_vr_shell_delegate_.obj());
}
-void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) {
- if (device_provider_)
- device_provider_->OnGvrDelegateReady(vr_shell);
-}
-
// ----------------------------------------------------------------------------
// Native JNI methods
// ----------------------------------------------------------------------------
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | device/vr/android/gvr/gvr_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698