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

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

Issue 2624633002: Remove Sync GetPose VRService call, implement VRVSyncProvider (Closed)
Patch Set: Remove visibility restrictions - can address later if desired. Created 3 years, 11 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
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.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/android/vr_shell/ui_interface.h" 15 #include "chrome/browser/android/vr_shell/ui_interface.h"
16 #include "chrome/browser/android/vr_shell/vr_compositor.h" 16 #include "chrome/browser/android/vr_shell/vr_compositor.h"
17 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
17 #include "chrome/browser/android/vr_shell/vr_input_manager.h" 18 #include "chrome/browser/android/vr_shell/vr_input_manager.h"
18 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 19 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
19 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" 20 #include "chrome/browser/android/vr_shell/vr_shell_gl.h"
20 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h" 21 #include "chrome/browser/android/vr_shell/vr_usage_monitor.h"
21 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" 22 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
22 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host.h" 25 #include "content/public/browser/render_widget_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/referrer.h" 28 #include "content/public/common/referrer.h"
28 #include "device/vr/android/gvr/gvr_device_provider.h" 29 #include "device/vr/android/gvr/gvr_device_provider.h"
29 #include "jni/VrShellImpl_jni.h" 30 #include "jni/VrShellImpl_jni.h"
30 #include "ui/android/view_android.h" 31 #include "ui/android/view_android.h"
31 #include "ui/android/window_android.h" 32 #include "ui/android/window_android.h"
32 #include "ui/base/page_transition_types.h" 33 #include "ui/base/page_transition_types.h"
33 #include "ui/display/display.h" 34 #include "ui/display/display.h"
34 #include "ui/display/screen.h" 35 #include "ui/display/screen.h"
36 #include "ui/gfx/transform.h"
37 #include "ui/gfx/transform_util.h"
35 38
36 using base::android::JavaParamRef; 39 using base::android::JavaParamRef;
37 using base::android::JavaRef; 40 using base::android::JavaRef;
38 41
39 namespace vr_shell { 42 namespace vr_shell {
40 43
41 namespace { 44 namespace {
42 vr_shell::VrShell* g_instance; 45 vr_shell::VrShell* g_instance;
43 46
44 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 47 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
45 48
46 class GLThread : public base::Thread {
47 public:
48 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell,
49 const base::WeakPtr<VrInputManager>& content_input_manager,
50 const base::WeakPtr<VrInputManager>& ui_input_manager,
51 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
52 gvr_context* gvr_api,
53 bool initially_web_vr,
54 bool reprojected_rendering)
55 : base::Thread("VrShellGL"),
56 weak_vr_shell_(weak_vr_shell),
57 content_input_manager_(content_input_manager),
58 ui_input_manager_(ui_input_manager),
59 main_thread_task_runner_(std::move(main_thread_task_runner)),
60 gvr_api_(gvr_api),
61 initially_web_vr_(initially_web_vr),
62 reprojected_rendering_(reprojected_rendering) {}
63
64 ~GLThread() override {
65 Stop();
66 }
67 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; }
68 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); }
69
70 protected:
71 void Init() override {
72 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_),
73 std::move(content_input_manager_),
74 std::move(ui_input_manager_),
75 std::move(main_thread_task_runner_),
76 gvr_api_,
77 initially_web_vr_,
78 reprojected_rendering_));
79 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr();
80 vr_shell_gl_->Initialize();
81 }
82 void CleanUp() override {
83 vr_shell_gl_.reset();
84 }
85
86 private:
87 // Created on GL thread.
88 std::unique_ptr<VrShellGl> vr_shell_gl_;
89 base::WeakPtr<VrShellGl> weak_vr_shell_gl_;
90
91 base::WeakPtr<VrShell> weak_vr_shell_;
92 base::WeakPtr<VrInputManager> content_input_manager_;
93 base::WeakPtr<VrInputManager> ui_input_manager_;
94 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
95 gvr_context* gvr_api_;
96 bool initially_web_vr_;
97 bool reprojected_rendering_;
98 };
99
100 } // namespace 49 } // namespace
101 50
102 VrShell::VrShell(JNIEnv* env, 51 VrShell::VrShell(JNIEnv* env,
103 jobject obj, 52 jobject obj,
104 content::WebContents* main_contents, 53 content::WebContents* main_contents,
105 ui::WindowAndroid* content_window, 54 ui::WindowAndroid* content_window,
106 content::WebContents* ui_contents, 55 content::WebContents* ui_contents,
107 ui::WindowAndroid* ui_window, 56 ui::WindowAndroid* ui_window,
108 bool for_web_vr, 57 bool for_web_vr,
109 VrShellDelegate* delegate, 58 VrShellDelegate* delegate,
110 gvr_context* gvr_api, 59 gvr_context* gvr_api,
111 bool reprojected_rendering) 60 bool reprojected_rendering)
112 : WebContentsObserver(ui_contents), 61 : WebContentsObserver(ui_contents),
113 main_contents_(main_contents), 62 main_contents_(main_contents),
114 content_compositor_(new VrCompositor(content_window, false)), 63 content_compositor_(new VrCompositor(content_window, false)),
115 ui_contents_(ui_contents), 64 ui_contents_(ui_contents),
116 ui_compositor_(new VrCompositor(ui_window, true)), 65 ui_compositor_(new VrCompositor(ui_window, true)),
117 delegate_(delegate), 66 delegate_provider_(delegate),
118 metrics_helper_(new VrMetricsHelper(main_contents_)), 67 metrics_helper_(new VrMetricsHelper(main_contents_)),
119 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 68 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
120 reprojected_rendering_(reprojected_rendering), 69 reprojected_rendering_(reprojected_rendering),
121 weak_ptr_factory_(this) { 70 weak_ptr_factory_(this) {
122 DCHECK(g_instance == nullptr); 71 DCHECK(g_instance == nullptr);
123 g_instance = this; 72 g_instance = this;
124 j_vr_shell_.Reset(env, obj); 73 j_vr_shell_.Reset(env, obj);
125 74
126 content_input_manager_.reset(new VrInputManager(main_contents_)); 75 content_input_manager_.reset(new VrInputManager(main_contents_));
127 ui_input_manager_.reset(new VrInputManager(ui_contents_)); 76 ui_input_manager_.reset(new VrInputManager(ui_contents_));
128 77
129 content_compositor_->SetLayer(main_contents_); 78 content_compositor_->SetLayer(main_contents_);
130 ui_compositor_->SetLayer(ui_contents_); 79 ui_compositor_->SetLayer(ui_contents_);
131 80
132 gl_thread_.reset(new GLThread(weak_ptr_factory_.GetWeakPtr(), 81 gl_thread_.reset(new VrGLThread(
133 content_input_manager_->GetWeakPtr(), 82 weak_ptr_factory_.GetWeakPtr(), content_input_manager_->GetWeakPtr(),
134 ui_input_manager_->GetWeakPtr(), 83 ui_input_manager_->GetWeakPtr(), delegate_provider_->GetWeakPtr(),
135 main_thread_task_runner_, 84 main_thread_task_runner_, gvr_api,
136 gvr_api, 85 for_web_vr, reprojected_rendering_));
137 for_web_vr,
138 reprojected_rendering_));
139 86
140 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 87 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
141 options.priority = base::ThreadPriority::DISPLAY; 88 options.priority = base::ThreadPriority::DISPLAY;
142 gl_thread_->StartWithOptions(options); 89 gl_thread_->StartWithOptions(options);
143 90
144 if (for_web_vr) 91 if (for_web_vr)
145 metrics_helper_->SetWebVREnabled(true); 92 metrics_helper_->SetWebVREnabled(true);
146 html_interface_.reset(new UiInterface( 93 html_interface_.reset(new UiInterface(
147 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 94 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD,
148 main_contents_->IsFullscreen())); 95 main_contents_->IsFullscreen()));
(...skipping 27 matching lines...) Expand all
176 // we need to block shutting down the GvrLayout on stopping our GL thread 123 // we need to block shutting down the GvrLayout on stopping our GL thread
177 // from using the GvrApi instance. 124 // from using the GvrApi instance.
178 // base::Thread::Stop, which is called when destroying the thread, asserts 125 // base::Thread::Stop, which is called when destroying the thread, asserts
179 // that IO is allowed to prevent jank, but there shouldn't be any concerns 126 // that IO is allowed to prevent jank, but there shouldn't be any concerns
180 // regarding jank in this case, because we're switching from 3D to 2D, 127 // regarding jank in this case, because we're switching from 3D to 2D,
181 // adding/removing a bunch of Java views, and probably changing device 128 // adding/removing a bunch of Java views, and probably changing device
182 // orientation here. 129 // orientation here.
183 base::ThreadRestrictions::ScopedAllowIO allow_io; 130 base::ThreadRestrictions::ScopedAllowIO allow_io;
184 gl_thread_.reset(); 131 gl_thread_.reset();
185 } 132 }
186 delegate_->RemoveDelegate(); 133 delegate_provider_->RemoveDelegate();
187 g_instance = nullptr; 134 g_instance = nullptr;
188 } 135 }
189 136
190 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 137 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
191 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 138 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
192 // finished starting? 139 // finished starting?
193 gl_thread_->WaitUntilThreadStarted(); 140 gl_thread_->WaitUntilThreadStarted();
194 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 141 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
195 } 142 }
196 143
197 void VrShell::OnTriggerEvent(JNIEnv* env, 144 void VrShell::OnTriggerEvent(JNIEnv* env,
198 const JavaParamRef<jobject>& obj) { 145 const JavaParamRef<jobject>& obj) {
199 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 146 gl_thread_->task_runner()->PostTask(
200 thread->task_runner()->PostTask(FROM_HERE, 147 FROM_HERE,
201 base::Bind(&VrShellGl::OnTriggerEvent, 148 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
202 thread->GetVrShellGl()));
203 } 149 }
204 150
205 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 151 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
206 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 152 gl_thread_->task_runner()->PostTask(
207 thread->task_runner()->PostTask( 153 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
208 FROM_HERE, base::Bind(&VrShellGl::OnPause, thread->GetVrShellGl()));
209 154
210 // exit vr session 155 // exit vr session
211 metrics_helper_->SetVRActive(false); 156 metrics_helper_->SetVRActive(false);
212 SetIsInVR(false); 157 SetIsInVR(false);
213 } 158 }
214 159
215 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 160 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
216 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 161 gl_thread_->task_runner()->PostTask(
217 thread->task_runner()->PostTask( 162 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl()));
218 FROM_HERE, base::Bind(&VrShellGl::OnResume, thread->GetVrShellGl()));
219 163
220 metrics_helper_->SetVRActive(true); 164 metrics_helper_->SetVRActive(true);
221 SetIsInVR(true); 165 SetIsInVR(true);
222 } 166 }
223 167
224 void VrShell::SetSurface(JNIEnv* env, 168 void VrShell::SetSurface(JNIEnv* env,
225 const JavaParamRef<jobject>& obj, 169 const JavaParamRef<jobject>& obj,
226 const JavaParamRef<jobject>& surface) { 170 const JavaParamRef<jobject>& surface) {
227 CHECK(!reprojected_rendering_); 171 CHECK(!reprojected_rendering_);
228 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
229 gfx::AcceleratedWidget window = 172 gfx::AcceleratedWidget window =
230 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); 173 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
231 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, 174 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
232 thread->GetVrShellGl(), 175 gl_thread_->GetVrShellGl(),
233 base::Unretained(window))); 176 base::Unretained(window)));
234 } 177 }
235 178
236 void VrShell::SetIsInVR(bool is_in_vr) { 179 void VrShell::SetIsInVR(bool is_in_vr) {
237 main_contents_->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 180 main_contents_->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
238 } 181 }
239 182
240 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 183 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
241 const content::WebContents* web_contents) { 184 const content::WebContents* web_contents) {
242 // Ensure that the WebContents requesting the VrShell instance is the one 185 // Ensure that the WebContents requesting the VrShell instance is the one
243 // we created. 186 // we created.
244 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 187 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
245 return g_instance->weak_ptr_factory_.GetWeakPtr(); 188 return g_instance->weak_ptr_factory_.GetWeakPtr();
246 return base::WeakPtr<VrShell>(nullptr); 189 return base::WeakPtr<VrShell>(nullptr);
247 } 190 }
248 191
249 void VrShell::OnDomContentsLoaded() { 192 void VrShell::OnDomContentsLoaded() {
250 html_interface_->SetURL(main_contents_->GetVisibleURL()); 193 html_interface_->SetURL(main_contents_->GetVisibleURL());
251 html_interface_->SetLoading(main_contents_->IsLoading()); 194 html_interface_->SetLoading(main_contents_->IsLoading());
252 html_interface_->OnDomContentsLoaded(); 195 html_interface_->OnDomContentsLoaded();
253 } 196 }
254 197
255 void VrShell::SetWebVrMode(JNIEnv* env, 198 void VrShell::SetWebVrMode(JNIEnv* env,
256 const base::android::JavaParamRef<jobject>& obj, 199 const base::android::JavaParamRef<jobject>& obj,
257 bool enabled) { 200 bool enabled) {
258 metrics_helper_->SetWebVREnabled(enabled); 201 metrics_helper_->SetWebVREnabled(enabled);
259 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 202 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
260 PostToGlThreadWhenReady( 203 gl_thread_->GetVrShellGl(), enabled));
261 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled));
262 if (enabled) { 204 if (enabled) {
263 html_interface_->SetMode(UiInterface::Mode::WEB_VR); 205 html_interface_->SetMode(UiInterface::Mode::WEB_VR);
264 } else { 206 } else {
265 html_interface_->SetMode(UiInterface::Mode::STANDARD); 207 html_interface_->SetMode(UiInterface::Mode::STANDARD);
266 } 208 }
267 } 209 }
268 210
269 void VrShell::OnLoadProgressChanged( 211 void VrShell::OnLoadProgressChanged(
270 JNIEnv* env, 212 JNIEnv* env,
271 const base::android::JavaParamRef<jobject>& obj, 213 const base::android::JavaParamRef<jobject>& obj,
272 double progress) { 214 double progress) {
273 html_interface_->SetLoadProgress(progress); 215 html_interface_->SetLoadProgress(progress);
274 } 216 }
275 217
276 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) {
277 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
278 if (thread->IsRunning()) {
279 thread->task_runner()->PostTask(
280 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr,
281 thread->GetVrShellGl(), pose, pose_num));
282 }
283 }
284
285 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { 218 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) {
286 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR 219 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR
287 // render surface size. 220 // render surface size.
288 } 221 }
289 222
290 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { 223 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() {
291 const gfx::Size& size = content_compositor_->GetWindowBounds(); 224 const gfx::Size& size = content_compositor_->GetWindowBounds();
292 return {size.width(), size.height()}; 225 return {size.width(), size.height()};
293 } 226 }
294 227
295 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { 228 void VrShell::SetWebVRSecureOrigin(bool secure_origin) {
296 // TODO(cjgrant): Align this state with the logic that drives the omnibox. 229 // TODO(cjgrant): Align this state with the logic that drives the omnibox.
297 html_interface_->SetWebVRSecureOrigin(secure_origin); 230 html_interface_->SetWebVRSecureOrigin(secure_origin);
298 } 231 }
299 232
300 void VrShell::SubmitWebVRFrame() {} 233 void VrShell::SubmitWebVRFrame() {}
301 234
302 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, 235 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds,
303 const gvr::Rectf& right_bounds) { 236 const gvr::Rectf& right_bounds) {
304 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
305 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, 237 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds,
306 thread->GetVrShellGl(), left_bounds, 238 gl_thread_->GetVrShellGl(), left_bounds,
307 right_bounds)); 239 right_bounds));
308 } 240 }
309 241
310 // TODO(mthiesse): Do not expose GVR API outside of GL thread. 242 // TODO(mthiesse): Do not expose GVR API outside of GL thread.
311 // It's not thread-safe. 243 // It's not thread-safe.
312 gvr::GvrApi* VrShell::gvr_api() { 244 gvr::GvrApi* VrShell::gvr_api() {
313 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); 245 if (gl_thread_->GetVrShellGlUnsafe()) {
314 if (thread->GetVrShellGlUnsafe()) { 246 return gl_thread_->GetVrShellGlUnsafe()->gvr_api();
315 return thread->GetVrShellGlUnsafe()->gvr_api();
316 } 247 }
317 CHECK(false); 248 CHECK(false);
318 return nullptr; 249 return nullptr;
319 } 250 }
320 251
321 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { 252 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) {
322 content_compositor_->SurfaceChanged(content_surface); 253 content_compositor_->SurfaceChanged(content_surface);
323 ui_compositor_->SurfaceChanged(ui_surface); 254 ui_compositor_->SurfaceChanged(ui_surface);
324 } 255 }
325 256
326 void VrShell::GvrDelegateReady() { 257 void VrShell::GvrDelegateReady() {
327 delegate_->SetDelegate(this); 258 delegate_provider_->SetDelegate(this);
328 } 259 }
329 260
330 void VrShell::AppButtonPressed() { 261 void VrShell::AppButtonPressed() {
331 #if defined(ENABLE_VR_SHELL) 262 #if defined(ENABLE_VR_SHELL)
332 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); 263 html_interface_->SetMenuMode(!html_interface_->GetMenuMode());
333 264
334 // TODO(mthiesse): The page is no longer visible when in menu mode. We 265 // TODO(mthiesse): The page is no longer visible when in menu mode. We
335 // should unfocus or otherwise let it know it's hidden. 266 // should unfocus or otherwise let it know it's hidden.
336 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { 267 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) {
337 if (delegate_->device_provider()) { 268 if (delegate_provider_->device_provider()) {
338 if (html_interface_->GetMenuMode()) { 269 if (html_interface_->GetMenuMode()) {
339 delegate_->device_provider()->OnDisplayBlur(); 270 delegate_provider_->device_provider()->OnDisplayBlur();
340 } else { 271 } else {
341 delegate_->device_provider()->OnDisplayFocus(); 272 delegate_provider_->device_provider()->OnDisplayFocus();
342 } 273 }
343 } 274 }
344 } 275 }
345 #endif 276 #endif
346 } 277 }
347 278
348 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 279 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
349 const JavaParamRef<jobject>& object, 280 const JavaParamRef<jobject>& object,
350 jint width, jint height, 281 jint width, jint height,
351 jfloat dpr) { 282 jfloat dpr) {
352 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 283 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
353 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
354 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 284 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
355 thread->GetVrShellGl(), width, height)); 285 gl_thread_->GetVrShellGl(), width,
286 height));
356 content_compositor_->SetWindowBounds(gfx::Size(width, height)); 287 content_compositor_->SetWindowBounds(gfx::Size(width, height));
357 } 288 }
358 289
359 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env, 290 void VrShell::UIPhysicalBoundsChanged(JNIEnv* env,
360 const JavaParamRef<jobject>& object, 291 const JavaParamRef<jobject>& object,
361 jint width, jint height, jfloat dpr) { 292 jint width, jint height, jfloat dpr) {
362 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
363 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged, 293 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged,
364 thread->GetVrShellGl(), width, height)); 294 gl_thread_->GetVrShellGl(), width,
295 height));
365 ui_compositor_->SetWindowBounds(gfx::Size(width, height)); 296 ui_compositor_->SetWindowBounds(gfx::Size(width, height));
366 } 297 }
367 298
368 UiInterface* VrShell::GetUiInterface() { 299 UiInterface* VrShell::GetUiInterface() {
369 return html_interface_.get(); 300 return html_interface_.get();
370 } 301 }
371 302
372 void VrShell::UpdateScene(const base::ListValue* args) { 303 void VrShell::UpdateScene(const base::ListValue* args) {
373 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
374 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, 304 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene,
375 thread->GetVrShellGl(), 305 gl_thread_->GetVrShellGl(),
376 base::Passed(args->CreateDeepCopy()))); 306 base::Passed(args->CreateDeepCopy())));
377 } 307 }
378 308
379 void VrShell::DoUiAction(const UiAction action) { 309 void VrShell::DoUiAction(const UiAction action) {
380 content::NavigationController& controller = main_contents_->GetController(); 310 content::NavigationController& controller = main_contents_->GetController();
381 switch (action) { 311 switch (action) {
382 case HISTORY_BACK: 312 case HISTORY_BACK:
383 if (main_contents_->IsFullscreen()) { 313 if (main_contents_->IsFullscreen()) {
384 main_contents_->ExitFullscreen(false); 314 main_contents_->ExitFullscreen(false);
385 } else if (controller.CanGoBack()) { 315 } else if (controller.CanGoBack()) {
(...skipping 24 matching lines...) Expand all
410 } 340 }
411 341
412 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 342 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
413 content::RenderViewHost* new_host) { 343 content::RenderViewHost* new_host) {
414 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); 344 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
415 } 345 }
416 346
417 void VrShell::MainFrameWasResized(bool width_changed) { 347 void VrShell::MainFrameWasResized(bool width_changed) {
418 display::Display display = display::Screen::GetScreen() 348 display::Display display = display::Screen::GetScreen()
419 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); 349 ->GetDisplayNearestWindow(ui_contents_->GetNativeView());
420 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
421 PostToGlThreadWhenReady( 350 PostToGlThreadWhenReady(
422 base::Bind(&VrShellGl::UIBoundsChanged, thread->GetVrShellGl(), 351 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(),
423 display.size().width(), display.size().height())); 352 display.size().width(), display.size().height()));
424 } 353 }
425 354
426 void VrShell::ContentFrameWasResized(bool width_changed) { 355 void VrShell::ContentFrameWasResized(bool width_changed) {
427 display::Display display = display::Screen::GetScreen() 356 display::Display display = display::Screen::GetScreen()
428 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); 357 ->GetDisplayNearestWindow(main_contents_->GetNativeView());
429 GLThread* thread = static_cast<GLThread*>(gl_thread_.get());
430 PostToGlThreadWhenReady( 358 PostToGlThreadWhenReady(
431 base::Bind(&VrShellGl::ContentBoundsChanged, thread->GetVrShellGl(), 359 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(),
432 display.size().width(), display.size().height())); 360 display.size().width(), display.size().height()));
433 } 361 }
434 362
435 void VrShell::WebContentsDestroyed() { 363 void VrShell::WebContentsDestroyed() {
436 ui_input_manager_.reset(); 364 ui_input_manager_.reset();
437 ui_contents_ = nullptr; 365 ui_contents_ = nullptr;
438 // TODO(mthiesse): Handle web contents being destroyed. 366 // TODO(mthiesse): Handle web contents being destroyed.
439 ForceExitVr(); 367 ForceExitVr();
440 } 368 }
441 369
442 void VrShell::ContentWebContentsDestroyed() { 370 void VrShell::ContentWebContentsDestroyed() {
443 content_input_manager_.reset(); 371 content_input_manager_.reset();
444 main_contents_ = nullptr; 372 main_contents_ = nullptr;
445 // TODO(mthiesse): Handle web contents being destroyed. 373 // TODO(mthiesse): Handle web contents being destroyed.
446 ForceExitVr(); 374 ForceExitVr();
447 } 375 }
448 376
449 void VrShell::ContentWasHidden() { 377 void VrShell::ContentWasHidden() {
450 // Ensure we don't continue sending input to it. 378 // Ensure we don't continue sending input to it.
451 content_input_manager_.reset(); 379 content_input_manager_.reset();
452 // TODO(mthiesse): Handle web contents being hidden. 380 // TODO(mthiesse): Handle web contents being hidden.
453 ForceExitVr(); 381 ForceExitVr();
454 } 382 }
455 383
456 void VrShell::ForceExitVr() { 384 void VrShell::ForceExitVr() {
457 delegate_->ForceExitVr(); 385 delegate_provider_->ForceExitVr();
386 }
387
388 void VrShell::OnVRVsyncProviderRequest(
389 device::mojom::VRVSyncProviderRequest request) {
390 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest,
391 gl_thread_->GetVrShellGl(),
392 base::Passed(&request)));
393 }
394
395 void VrShell::UpdateVSyncInterval(long timebase_nanos,
396 double interval_seconds) {
397 PostToGlThreadWhenReady(
398 base::Bind(&VrShellGl::UpdateVSyncInterval,
399 gl_thread_->GetVrShellGl(), timebase_nanos, interval_seconds));
458 } 400 }
459 401
460 void VrShell::SetContentCssSize(float width, float height, float dpr) { 402 void VrShell::SetContentCssSize(float width, float height, float dpr) {
461 JNIEnv* env = base::android::AttachCurrentThread(); 403 JNIEnv* env = base::android::AttachCurrentThread();
462 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height, 404 Java_VrShellImpl_setContentCssSize(env, j_vr_shell_.obj(), width, height,
463 dpr); 405 dpr);
464 } 406 }
465 407
466 void VrShell::SetUiCssSize(float width, float height, float dpr) { 408 void VrShell::SetUiCssSize(float width, float height, float dpr) {
467 JNIEnv* env = base::android::AttachCurrentThread(); 409 JNIEnv* env = base::android::AttachCurrentThread();
468 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr); 410 Java_VrShellImpl_setUiCssSize(env, j_vr_shell_.obj(), width, height, dpr);
469 } 411 }
470 412
413 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat,
414 uint32_t pose_index) {
415 device::mojom::VRPosePtr pose = device::mojom::VRPose::New();
416
417 pose->timestamp = base::Time::Now().ToJsTime();
418
419 pose->poseIndex = pose_index;
420 pose->orientation.emplace(4);
421
422 gfx::Transform inv_transform(
423 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3],
424 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3],
425 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3],
426 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]);
427
428 gfx::Transform transform;
429 if (inv_transform.GetInverse(&transform)) {
430 gfx::DecomposedTransform decomposed_transform;
431 gfx::DecomposeTransform(&decomposed_transform, transform);
432
433 pose->orientation.value()[0] = decomposed_transform.quaternion[0];
434 pose->orientation.value()[1] = decomposed_transform.quaternion[1];
435 pose->orientation.value()[2] = decomposed_transform.quaternion[2];
436 pose->orientation.value()[3] = decomposed_transform.quaternion[3];
437
438 pose->position.emplace(3);
439 pose->position.value()[0] = decomposed_transform.translate[0];
440 pose->position.value()[1] = decomposed_transform.translate[1];
441 pose->position.value()[2] = decomposed_transform.translate[2];
442 }
443
444 return pose;
445 }
446
471 // ---------------------------------------------------------------------------- 447 // ----------------------------------------------------------------------------
472 // Native JNI methods 448 // Native JNI methods
473 // ---------------------------------------------------------------------------- 449 // ----------------------------------------------------------------------------
474 450
475 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 451 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj,
476 const JavaParamRef<jobject>& content_web_contents, 452 const JavaParamRef<jobject>& content_web_contents,
477 jlong content_window_android, 453 jlong content_window_android,
478 const JavaParamRef<jobject>& ui_web_contents, 454 const JavaParamRef<jobject>& ui_web_contents,
479 jlong ui_window_android, jboolean for_web_vr, 455 jlong ui_window_android, jboolean for_web_vr,
480 const base::android::JavaParamRef<jobject>& delegate, 456 const base::android::JavaParamRef<jobject>& delegate,
481 jlong gvr_api, jboolean reprojected_rendering) { 457 jlong gvr_api, jboolean reprojected_rendering) {
482 return reinterpret_cast<intptr_t>(new VrShell( 458 return reinterpret_cast<intptr_t>(new VrShell(
483 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 459 env, obj, content::WebContents::FromJavaWebContents(content_web_contents),
484 reinterpret_cast<ui::WindowAndroid*>(content_window_android), 460 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
485 content::WebContents::FromJavaWebContents(ui_web_contents), 461 content::WebContents::FromJavaWebContents(ui_web_contents),
486 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 462 reinterpret_cast<ui::WindowAndroid*>(ui_window_android),
487 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), 463 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate),
488 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 464 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
489 } 465 }
490 466
491 } // namespace vr_shell 467 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698