OLD | NEW |
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 "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 namespace vr_shell { | 37 namespace vr_shell { |
38 | 38 |
39 namespace { | 39 namespace { |
40 vr_shell::VrShell* g_instance; | 40 vr_shell::VrShell* g_instance; |
41 | 41 |
42 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; | 42 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; |
43 | 43 |
44 class GLThread : public base::Thread { | 44 class GLThread : public base::Thread { |
45 public: | 45 public: |
46 GLThread(VrShell* vr_shell, const base::WeakPtr<VrShell>& weak_vr_shell, | 46 GLThread(const base::WeakPtr<VrShell>& weak_vr_shell, |
47 const base::WeakPtr<VrInputManager>& content_input_manager, | 47 const base::WeakPtr<VrInputManager>& content_input_manager, |
48 const base::WeakPtr<VrInputManager>& ui_input_manager, | 48 const base::WeakPtr<VrInputManager>& ui_input_manager, |
49 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | 49 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, |
50 gvr_context* gvr_api) | 50 gvr_context* gvr_api, |
| 51 bool initially_web_vr) |
51 : base::Thread("VrShellGL"), | 52 : base::Thread("VrShellGL"), |
52 vr_shell_(vr_shell), | |
53 weak_vr_shell_(weak_vr_shell), | 53 weak_vr_shell_(weak_vr_shell), |
54 content_input_manager_(content_input_manager), | 54 content_input_manager_(content_input_manager), |
55 ui_input_manager_(ui_input_manager), | 55 ui_input_manager_(ui_input_manager), |
56 main_thread_task_runner_(std::move(main_thread_task_runner)), | 56 main_thread_task_runner_(std::move(main_thread_task_runner)), |
57 gvr_api_(gvr_api) {} | 57 gvr_api_(gvr_api), |
| 58 initially_web_vr_(initially_web_vr) {} |
58 | 59 |
59 ~GLThread() override { | 60 ~GLThread() override { |
60 Stop(); | 61 Stop(); |
61 } | 62 } |
62 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; } | 63 base::WeakPtr<VrShellGl> GetVrShellGl() { return weak_vr_shell_gl_; } |
63 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); } | 64 VrShellGl* GetVrShellGlUnsafe() { return vr_shell_gl_.get(); } |
64 | 65 |
65 protected: | 66 protected: |
66 void Init() override { | 67 void Init() override { |
67 vr_shell_gl_.reset(new VrShellGl(vr_shell_, | 68 vr_shell_gl_.reset(new VrShellGl(std::move(weak_vr_shell_), |
68 std::move(weak_vr_shell_), | |
69 std::move(content_input_manager_), | 69 std::move(content_input_manager_), |
70 std::move(ui_input_manager_), | 70 std::move(ui_input_manager_), |
71 std::move(main_thread_task_runner_), | 71 std::move(main_thread_task_runner_), |
72 gvr_api_)); | 72 gvr_api_, |
| 73 initially_web_vr_)); |
73 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); | 74 weak_vr_shell_gl_ = vr_shell_gl_->GetWeakPtr(); |
74 if (!vr_shell_gl_->Initialize()) { | 75 if (!vr_shell_gl_->Initialize()) { |
75 vr_shell_gl_.reset(); | 76 vr_shell_gl_.reset(); |
76 } | 77 } |
77 } | 78 } |
78 void CleanUp() override { | 79 void CleanUp() override { |
79 vr_shell_gl_.reset(); | 80 vr_shell_gl_.reset(); |
80 } | 81 } |
81 | 82 |
82 private: | 83 private: |
83 // Created on GL thread. | 84 // Created on GL thread. |
84 std::unique_ptr<VrShellGl> vr_shell_gl_; | 85 std::unique_ptr<VrShellGl> vr_shell_gl_; |
85 base::WeakPtr<VrShellGl> weak_vr_shell_gl_; | 86 base::WeakPtr<VrShellGl> weak_vr_shell_gl_; |
86 | 87 |
87 // Created on main thread. | |
88 // TODO(mthiesse): Remove vr_shell_. | |
89 VrShell* vr_shell_; | |
90 base::WeakPtr<VrShell> weak_vr_shell_; | 88 base::WeakPtr<VrShell> weak_vr_shell_; |
91 base::WeakPtr<VrInputManager> content_input_manager_; | 89 base::WeakPtr<VrInputManager> content_input_manager_; |
92 base::WeakPtr<VrInputManager> ui_input_manager_; | 90 base::WeakPtr<VrInputManager> ui_input_manager_; |
93 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 91 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
94 gvr_context* gvr_api_; | 92 gvr_context* gvr_api_; |
| 93 bool initially_web_vr_; |
95 }; | 94 }; |
96 | 95 |
97 } // namespace | 96 } // namespace |
98 | 97 |
99 VrShell::VrShell(JNIEnv* env, | 98 VrShell::VrShell(JNIEnv* env, |
100 jobject obj, | 99 jobject obj, |
101 content::WebContents* main_contents, | 100 content::WebContents* main_contents, |
102 ui::WindowAndroid* content_window, | 101 ui::WindowAndroid* content_window, |
103 content::WebContents* ui_contents, | 102 content::WebContents* ui_contents, |
104 ui::WindowAndroid* ui_window, | 103 ui::WindowAndroid* ui_window, |
(...skipping 12 matching lines...) Expand all Loading... |
117 DCHECK(g_instance == nullptr); | 116 DCHECK(g_instance == nullptr); |
118 g_instance = this; | 117 g_instance = this; |
119 j_vr_shell_.Reset(env, obj); | 118 j_vr_shell_.Reset(env, obj); |
120 | 119 |
121 content_input_manager_.reset(new VrInputManager(main_contents_)); | 120 content_input_manager_.reset(new VrInputManager(main_contents_)); |
122 ui_input_manager_.reset(new VrInputManager(ui_contents_)); | 121 ui_input_manager_.reset(new VrInputManager(ui_contents_)); |
123 | 122 |
124 content_compositor_->SetLayer(main_contents_); | 123 content_compositor_->SetLayer(main_contents_); |
125 ui_compositor_->SetLayer(ui_contents_); | 124 ui_compositor_->SetLayer(ui_contents_); |
126 | 125 |
127 gl_thread_.reset(new GLThread(this, weak_ptr_factory_.GetWeakPtr(), | 126 gl_thread_.reset(new GLThread(weak_ptr_factory_.GetWeakPtr(), |
128 content_input_manager_->GetWeakPtr(), | 127 content_input_manager_->GetWeakPtr(), |
129 ui_input_manager_->GetWeakPtr(), | 128 ui_input_manager_->GetWeakPtr(), |
130 main_thread_task_runner_, | 129 main_thread_task_runner_, |
131 gvr_api)); | 130 gvr_api, |
| 131 for_web_vr)); |
132 | 132 |
133 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); | 133 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); |
134 options.priority = base::ThreadPriority::DISPLAY; | 134 options.priority = base::ThreadPriority::DISPLAY; |
135 gl_thread_->StartWithOptions(options); | 135 gl_thread_->StartWithOptions(options); |
136 | 136 |
137 if (for_web_vr) | 137 if (for_web_vr) |
138 metrics_helper_->SetWebVREnabled(true); | 138 metrics_helper_->SetWebVREnabled(true); |
139 html_interface_.reset(new UiInterface( | 139 html_interface_.reset(new UiInterface( |
140 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, | 140 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, |
141 main_contents_->IsFullscreen())); | 141 main_contents_->IsFullscreen())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // regarding jank in this case, because we're switching from 3D to 2D, | 173 // regarding jank in this case, because we're switching from 3D to 2D, |
174 // adding/removing a bunch of Java views, and probably changing device | 174 // adding/removing a bunch of Java views, and probably changing device |
175 // orientation here. | 175 // orientation here. |
176 base::ThreadRestrictions::ScopedAllowIO allow_io; | 176 base::ThreadRestrictions::ScopedAllowIO allow_io; |
177 gl_thread_.reset(); | 177 gl_thread_.reset(); |
178 } | 178 } |
179 delegate_->RemoveDelegate(); | 179 delegate_->RemoveDelegate(); |
180 g_instance = nullptr; | 180 g_instance = nullptr; |
181 } | 181 } |
182 | 182 |
| 183 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { |
| 184 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't |
| 185 // finished starting? |
| 186 gl_thread_->WaitUntilThreadStarted(); |
| 187 gl_thread_->task_runner()->PostTask(FROM_HERE, task); |
| 188 } |
| 189 |
183 void VrShell::OnTriggerEvent(JNIEnv* env, | 190 void VrShell::OnTriggerEvent(JNIEnv* env, |
184 const JavaParamRef<jobject>& obj) { | 191 const JavaParamRef<jobject>& obj) { |
185 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 192 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
186 thread->task_runner()->PostTask(FROM_HERE, | 193 thread->task_runner()->PostTask(FROM_HERE, |
187 base::Bind(&VrShellGl::OnTriggerEvent, | 194 base::Bind(&VrShellGl::OnTriggerEvent, |
188 thread->GetVrShellGl())); | 195 thread->GetVrShellGl())); |
189 } | 196 } |
190 | 197 |
191 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 198 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
192 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 199 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void VrShell::OnDomContentsLoaded() { | 232 void VrShell::OnDomContentsLoaded() { |
226 html_interface_->SetURL(main_contents_->GetVisibleURL()); | 233 html_interface_->SetURL(main_contents_->GetVisibleURL()); |
227 html_interface_->SetLoading(main_contents_->IsLoading()); | 234 html_interface_->SetLoading(main_contents_->IsLoading()); |
228 html_interface_->OnDomContentsLoaded(); | 235 html_interface_->OnDomContentsLoaded(); |
229 } | 236 } |
230 | 237 |
231 void VrShell::SetWebVrMode(JNIEnv* env, | 238 void VrShell::SetWebVrMode(JNIEnv* env, |
232 const base::android::JavaParamRef<jobject>& obj, | 239 const base::android::JavaParamRef<jobject>& obj, |
233 bool enabled) { | 240 bool enabled) { |
234 metrics_helper_->SetWebVREnabled(enabled); | 241 metrics_helper_->SetWebVREnabled(enabled); |
| 242 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
| 243 PostToGlThreadWhenReady( |
| 244 base::Bind(&VrShellGl::SetWebVrMode, thread->GetVrShellGl(), enabled)); |
235 if (enabled) { | 245 if (enabled) { |
236 html_interface_->SetMode(UiInterface::Mode::WEB_VR); | 246 html_interface_->SetMode(UiInterface::Mode::WEB_VR); |
237 } else { | 247 } else { |
238 html_interface_->SetMode(UiInterface::Mode::STANDARD); | 248 html_interface_->SetMode(UiInterface::Mode::STANDARD); |
239 } | 249 } |
240 } | 250 } |
241 | 251 |
242 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { | 252 void VrShell::SetGvrPoseForWebVr(const gvr::Mat4f& pose, uint32_t pose_num) { |
243 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 253 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
244 thread->task_runner()->PostTask( | 254 if (thread->IsRunning()) { |
245 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr, | 255 thread->task_runner()->PostTask( |
246 thread->GetVrShellGl(), pose, pose_num)); | 256 FROM_HERE, base::Bind(&VrShellGl::SetGvrPoseForWebVr, |
| 257 thread->GetVrShellGl(), pose, pose_num)); |
| 258 } |
247 } | 259 } |
248 | 260 |
249 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { | 261 void VrShell::SetWebVRRenderSurfaceSize(int width, int height) { |
250 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR | 262 // TODO(klausw,crbug.com/655722): Change the GVR render size and set the WebVR |
251 // render surface size. | 263 // render surface size. |
252 } | 264 } |
253 | 265 |
254 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { | 266 gvr::Sizei VrShell::GetWebVRCompositorSurfaceSize() { |
255 const gfx::Size& size = content_compositor_->GetWindowBounds(); | 267 const gfx::Size& size = content_compositor_->GetWindowBounds(); |
256 return {size.width(), size.height()}; | 268 return {size.width(), size.height()}; |
257 } | 269 } |
258 | 270 |
259 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { | 271 void VrShell::SetWebVRSecureOrigin(bool secure_origin) { |
260 // TODO(cjgrant): Align this state with the logic that drives the omnibox. | 272 // TODO(cjgrant): Align this state with the logic that drives the omnibox. |
261 html_interface_->SetWebVRSecureOrigin(secure_origin); | 273 html_interface_->SetWebVRSecureOrigin(secure_origin); |
262 } | 274 } |
263 | 275 |
264 void VrShell::SubmitWebVRFrame() {} | 276 void VrShell::SubmitWebVRFrame() {} |
265 | 277 |
266 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, | 278 void VrShell::UpdateWebVRTextureBounds(const gvr::Rectf& left_bounds, |
267 const gvr::Rectf& right_bounds) { | 279 const gvr::Rectf& right_bounds) { |
268 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 280 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
269 thread->task_runner()->PostTask( | 281 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateWebVRTextureBounds, |
270 FROM_HERE, base::Bind(&VrShellGl::UpdateWebVRTextureBounds, | 282 thread->GetVrShellGl(), left_bounds, |
271 thread->GetVrShellGl(), left_bounds, right_bounds)); | 283 right_bounds)); |
272 } | 284 } |
273 | 285 |
274 // TODO(mthiesse): Do not expose GVR API outside of GL thread. | 286 // TODO(mthiesse): Do not expose GVR API outside of GL thread. |
275 // It's not thread-safe. | 287 // It's not thread-safe. |
276 gvr::GvrApi* VrShell::gvr_api() { | 288 gvr::GvrApi* VrShell::gvr_api() { |
277 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 289 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
278 if (thread->GetVrShellGlUnsafe()) { | 290 if (thread->GetVrShellGlUnsafe()) { |
279 return thread->GetVrShellGlUnsafe()->gvr_api(); | 291 return thread->GetVrShellGlUnsafe()->gvr_api(); |
280 } | 292 } |
281 CHECK(false); | 293 CHECK(false); |
282 return nullptr; | 294 return nullptr; |
283 } | 295 } |
284 | 296 |
285 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { | 297 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { |
286 content_compositor_->SurfaceChanged(content_surface); | 298 content_compositor_->SurfaceChanged(content_surface); |
287 ui_compositor_->SurfaceChanged(ui_surface); | 299 ui_compositor_->SurfaceChanged(ui_surface); |
288 } | 300 } |
289 | 301 |
290 void VrShell::GvrDelegateReady() { | 302 void VrShell::GvrDelegateReady() { |
291 delegate_->SetDelegate(weak_ptr_factory_.GetWeakPtr()); | 303 delegate_->SetDelegate(this); |
| 304 } |
| 305 |
| 306 void VrShell::AppButtonPressed() { |
| 307 #if defined(ENABLE_VR_SHELL) |
| 308 html_interface_->SetMenuMode(!html_interface_->GetMenuMode()); |
| 309 |
| 310 // TODO(mthiesse): The page is no longer visible when in menu mode. We |
| 311 // should unfocus or otherwise let it know it's hidden. |
| 312 if (html_interface_->GetMode() == UiInterface::Mode::WEB_VR) { |
| 313 if (delegate_->device_provider()) { |
| 314 if (html_interface_->GetMenuMode()) { |
| 315 delegate_->device_provider()->OnDisplayBlur(); |
| 316 } else { |
| 317 delegate_->device_provider()->OnDisplayFocus(); |
| 318 } |
| 319 } |
| 320 } |
| 321 #endif |
292 } | 322 } |
293 | 323 |
294 void VrShell::ContentBoundsChanged(JNIEnv* env, | 324 void VrShell::ContentBoundsChanged(JNIEnv* env, |
295 const JavaParamRef<jobject>& object, | 325 const JavaParamRef<jobject>& object, |
296 jint width, jint height, jfloat dpr) { | 326 jint width, jint height, jfloat dpr) { |
297 TRACE_EVENT0("gpu", "VrShell::ContentBoundsChanged"); | 327 TRACE_EVENT0("gpu", "VrShell::ContentBoundsChanged"); |
298 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 328 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
299 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't | 329 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, |
300 // finished starting? | 330 thread->GetVrShellGl(), width, height)); |
301 thread->WaitUntilThreadStarted(); | |
302 CHECK(thread->task_runner()->PostTask( | |
303 FROM_HERE, base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, | |
304 thread->GetVrShellGl(), | |
305 width, height))); | |
306 content_compositor_->SetWindowBounds(gfx::Size(width, height)); | 331 content_compositor_->SetWindowBounds(gfx::Size(width, height)); |
307 } | 332 } |
308 | 333 |
309 void VrShell::UIBoundsChanged(JNIEnv* env, | 334 void VrShell::UIBoundsChanged(JNIEnv* env, |
310 const JavaParamRef<jobject>& object, | 335 const JavaParamRef<jobject>& object, |
311 jint width, jint height, jfloat dpr) { | 336 jint width, jint height, jfloat dpr) { |
312 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 337 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
313 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't | 338 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UIPhysicalBoundsChanged, |
314 // finished starting? | 339 thread->GetVrShellGl(), width, height)); |
315 thread->WaitUntilThreadStarted(); | |
316 thread->task_runner()->PostTask( | |
317 FROM_HERE, base::Bind(&VrShellGl::UIPhysicalBoundsChanged, | |
318 thread->GetVrShellGl(), | |
319 width, height)); | |
320 ui_compositor_->SetWindowBounds(gfx::Size(width, height)); | 340 ui_compositor_->SetWindowBounds(gfx::Size(width, height)); |
321 } | 341 } |
322 | 342 |
323 UiInterface* VrShell::GetUiInterface() { | 343 UiInterface* VrShell::GetUiInterface() { |
324 return html_interface_.get(); | 344 return html_interface_.get(); |
325 } | 345 } |
326 | 346 |
327 void VrShell::UpdateScene(const base::ListValue* args) { | 347 void VrShell::UpdateScene(const base::ListValue* args) { |
328 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 348 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
329 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't | 349 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, |
330 // finished starting? | 350 thread->GetVrShellGl(), |
331 thread->WaitUntilThreadStarted(); | 351 base::Passed(args->CreateDeepCopy()))); |
332 thread->task_runner()->PostTask( | |
333 FROM_HERE, base::Bind(&VrShellGl::UpdateScene, | |
334 thread->GetVrShellGl(), | |
335 base::Passed(args->CreateDeepCopy()))); | |
336 } | 352 } |
337 | 353 |
338 void VrShell::DoUiAction(const UiAction action) { | 354 void VrShell::DoUiAction(const UiAction action) { |
339 content::NavigationController& controller = main_contents_->GetController(); | 355 content::NavigationController& controller = main_contents_->GetController(); |
340 switch (action) { | 356 switch (action) { |
341 case HISTORY_BACK: | 357 case HISTORY_BACK: |
342 if (main_contents_->IsFullscreen()) { | 358 if (main_contents_->IsFullscreen()) { |
343 main_contents_->ExitFullscreen(true /* will_cause_resize */); | 359 main_contents_->ExitFullscreen(true /* will_cause_resize */); |
344 } else if (controller.CanGoBack()) { | 360 } else if (controller.CanGoBack()) { |
345 controller.GoBack(); | 361 controller.GoBack(); |
(...skipping 24 matching lines...) Expand all Loading... |
370 | 386 |
371 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 387 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |
372 content::RenderViewHost* new_host) { | 388 content::RenderViewHost* new_host) { |
373 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); | 389 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); |
374 } | 390 } |
375 | 391 |
376 void VrShell::MainFrameWasResized(bool width_changed) { | 392 void VrShell::MainFrameWasResized(bool width_changed) { |
377 display::Display display = display::Screen::GetScreen() | 393 display::Display display = display::Screen::GetScreen() |
378 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); | 394 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); |
379 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 395 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
380 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't | 396 PostToGlThreadWhenReady( |
381 // finished starting? | 397 base::Bind(&VrShellGl::UIBoundsChanged, thread->GetVrShellGl(), |
382 thread->WaitUntilThreadStarted(); | 398 display.size().width(), display.size().height())); |
383 thread->task_runner()->PostTask( | |
384 FROM_HERE, base::Bind(&VrShellGl::UIBoundsChanged, | |
385 thread->GetVrShellGl(), | |
386 display.size().width(), display.size().height())); | |
387 } | 399 } |
388 | 400 |
389 void VrShell::ContentFrameWasResized(bool width_changed) { | 401 void VrShell::ContentFrameWasResized(bool width_changed) { |
390 display::Display display = display::Screen::GetScreen() | 402 display::Display display = display::Screen::GetScreen() |
391 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); | 403 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); |
392 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); | 404 GLThread* thread = static_cast<GLThread*>(gl_thread_.get()); |
393 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't | 405 PostToGlThreadWhenReady( |
394 // finished starting? | 406 base::Bind(&VrShellGl::ContentBoundsChanged, thread->GetVrShellGl(), |
395 thread->WaitUntilThreadStarted(); | 407 display.size().width(), display.size().height())); |
396 thread->task_runner()->PostTask( | |
397 FROM_HERE, base::Bind(&VrShellGl::ContentBoundsChanged, | |
398 thread->GetVrShellGl(), | |
399 display.size().width(), display.size().height())); | |
400 } | 408 } |
401 | 409 |
402 void VrShell::WebContentsDestroyed() { | 410 void VrShell::WebContentsDestroyed() { |
403 ui_input_manager_.reset(); | 411 ui_input_manager_.reset(); |
404 ui_contents_ = nullptr; | 412 ui_contents_ = nullptr; |
405 // TODO(mthiesse): Handle web contents being destroyed. | 413 // TODO(mthiesse): Handle web contents being destroyed. |
406 ForceExitVr(); | 414 ForceExitVr(); |
407 } | 415 } |
408 | 416 |
409 void VrShell::ContentWebContentsDestroyed() { | 417 void VrShell::ContentWebContentsDestroyed() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 return reinterpret_cast<intptr_t>(new VrShell( | 457 return reinterpret_cast<intptr_t>(new VrShell( |
450 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), | 458 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), |
451 reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 459 reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
452 content::WebContents::FromJavaWebContents(ui_web_contents), | 460 content::WebContents::FromJavaWebContents(ui_web_contents), |
453 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), | 461 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), |
454 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), | 462 for_web_vr, VrShellDelegate::GetNativeDelegate(env, delegate), |
455 reinterpret_cast<gvr_context*>(gvr_api))); | 463 reinterpret_cast<gvr_context*>(gvr_api))); |
456 } | 464 } |
457 | 465 |
458 } // namespace vr_shell | 466 } // namespace vr_shell |
OLD | NEW |