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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2398103002: Enable magic window mode with new Gvr (Closed)
Patch Set: reviews Created 4 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | content/public/android/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "chrome/browser/android/vr_shell/vr_shell.h" 8 #include "chrome/browser/android/vr_shell/vr_shell.h"
9 #include "jni/VrShellDelegate_jni.h" 9 #include "jni/VrShellDelegate_jni.h"
10 10
11 using base::android::JavaParamRef; 11 using base::android::JavaParamRef;
12 using base::android::AttachCurrentThread; 12 using base::android::AttachCurrentThread;
13 13
14 namespace vr_shell { 14 namespace vr_shell {
15 15
16 // A non presenting delegate for magic window mode.
17 class GvrNonPresentingDelegate : public device::GvrDelegate {
18 public:
19 explicit GvrNonPresentingDelegate(jlong context) {
20 gvr_api_ =
21 gvr::GvrApi::WrapNonOwned(reinterpret_cast<gvr_context*>(context));
22 }
23
24 virtual ~GvrNonPresentingDelegate() = default;
25
26 // GvrDelegate implementation
27 void SetWebVRSecureOrigin(bool secure_origin) override {}
28 void SubmitWebVRFrame() override {}
29 void UpdateWebVRTextureBounds(int eye,
30 float left,
31 float top,
32 float width,
33 float height) override {}
34 void SetGvrPoseForWebVr(const gvr::Mat4f& pose,
35 uint32_t pose_index) override {}
36 gvr::GvrApi* gvr_api() override { return gvr_api_.get(); }
37
38 private:
39 std::unique_ptr<gvr::GvrApi> gvr_api_;
40 };
41
16 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) 42 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
17 : device_provider_(nullptr) { 43 : device_provider_(nullptr) {
18 j_vr_shell_delegate_.Reset(env, obj); 44 j_vr_shell_delegate_.Reset(env, obj);
19 GvrDelegateProvider::SetInstance(this); 45 GvrDelegateProvider::SetInstance(this);
20 } 46 }
21 47
22 VrShellDelegate::~VrShellDelegate() { 48 VrShellDelegate::~VrShellDelegate() {
23 GvrDelegateProvider::SetInstance(nullptr); 49 GvrDelegateProvider::SetInstance(nullptr);
24 } 50 }
25 51
(...skipping 29 matching lines...) Expand all
55 return; 81 return;
56 82
57 device_provider_ = nullptr; 83 device_provider_ = nullptr;
58 84
59 // VRShell is no longer needed by WebVR, allow it to shut down if it's not 85 // VRShell is no longer needed by WebVR, allow it to shut down if it's not
60 // being used elsewhere. 86 // being used elsewhere.
61 JNIEnv* env = AttachCurrentThread(); 87 JNIEnv* env = AttachCurrentThread();
62 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj()); 88 Java_VrShellDelegate_exitWebVR(env, j_vr_shell_delegate_.obj());
63 } 89 }
64 90
91 device::GvrDelegate* VrShellDelegate::GetNonPresentingDelegate() {
92 if (!non_presenting_delegate_) {
93 JNIEnv* env = AttachCurrentThread();
94 jlong context = Java_VrShellDelegate_createNonPresentingNativeContext(
95 env, j_vr_shell_delegate_.obj());
96 if (!context)
97 return nullptr;
98
99 non_presenting_delegate_.reset(new GvrNonPresentingDelegate(context));
100 }
101 return non_presenting_delegate_.get();
102 }
103
104 void VrShellDelegate::DestroyNonPresentingDelegate() {
105 non_presenting_delegate_.reset(nullptr);
106 JNIEnv* env = AttachCurrentThread();
107 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
108 env, j_vr_shell_delegate_.obj());
109 }
110
65 void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) { 111 void VrShellDelegate::OnVrShellReady(VrShell* vr_shell) {
66 if (device_provider_) 112 if (device_provider_)
67 device_provider_->OnGvrDelegateReady(vr_shell); 113 device_provider_->OnGvrDelegateReady(vr_shell);
68 } 114 }
69 115
70 // ---------------------------------------------------------------------------- 116 // ----------------------------------------------------------------------------
71 // Native JNI methods 117 // Native JNI methods
72 // ---------------------------------------------------------------------------- 118 // ----------------------------------------------------------------------------
73 119
74 bool RegisterVrShellDelegate(JNIEnv* env) { 120 bool RegisterVrShellDelegate(JNIEnv* env) {
75 return RegisterNativesImpl(env); 121 return RegisterNativesImpl(env);
76 } 122 }
77 123
78 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 124 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
79 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 125 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
80 } 126 }
81 127
82 } // namespace vr_shell 128 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell_delegate.h ('k') | content/public/android/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698