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

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

Issue 2833773005: Pause drawing webvr when the App button is pressed (Closed)
Patch Set: nit Created 3 years, 8 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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 g_instance = nullptr; 201 g_instance = nullptr;
202 } 202 }
203 203
204 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) { 204 void VrShell::PostToGlThreadWhenReady(const base::Closure& task) {
205 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't 205 // TODO(mthiesse): Remove this blocking wait. Queue up events if thread isn't
206 // finished starting? 206 // finished starting?
207 gl_thread_->WaitUntilThreadStarted(); 207 gl_thread_->WaitUntilThreadStarted();
208 gl_thread_->task_runner()->PostTask(FROM_HERE, task); 208 gl_thread_->task_runner()->PostTask(FROM_HERE, task);
209 } 209 }
210 210
211 void VrShell::SetContentPaused(bool paused) { 211 void VrShell::OnContentPaused(bool paused) {
212 if (content_paused_ == paused)
213 return;
214 content_paused_ = paused;
215
216 if (!delegate_provider_->device_provider()) 212 if (!delegate_provider_->device_provider())
217 return; 213 return;
218 214
219 // TODO(mthiesse): The page is no longer visible when in menu mode. We 215 // TODO(mthiesse): The page is no longer visible when in menu mode. We
220 // should unfocus or otherwise let it know it's hidden. 216 // should unfocus or otherwise let it know it's hidden.
221 if (paused) { 217 if (paused)
222 delegate_provider_->device_provider()->Device()->OnBlur(); 218 delegate_provider_->device_provider()->Device()->OnBlur();
223 } else { 219 else
224 delegate_provider_->device_provider()->Device()->OnFocus(); 220 delegate_provider_->device_provider()->Device()->OnFocus();
225 }
226 } 221 }
227 222
228 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) { 223 void VrShell::OnTriggerEvent(JNIEnv* env, const JavaParamRef<jobject>& obj) {
229 gl_thread_->task_runner()->PostTask( 224 gl_thread_->task_runner()->PostTask(
230 FROM_HERE, 225 FROM_HERE,
231 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); 226 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
232 } 227 }
233 228
234 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 229 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
235 gl_thread_->task_runner()->PostTask( 230 gl_thread_->task_runner()->PostTask(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 390
396 void VrShell::GvrDelegateReady() { 391 void VrShell::GvrDelegateReady() {
397 delegate_provider_->SetPresentingDelegate(this, gvr_api_); 392 delegate_provider_->SetPresentingDelegate(this, gvr_api_);
398 } 393 }
399 394
400 void VrShell::AppButtonGesturePerformed(UiInterface::Direction direction) { 395 void VrShell::AppButtonGesturePerformed(UiInterface::Direction direction) {
401 if (vr_shell_enabled_) 396 if (vr_shell_enabled_)
402 ui_->HandleAppButtonGesturePerformed(direction); 397 ui_->HandleAppButtonGesturePerformed(direction);
403 } 398 }
404 399
405 void VrShell::AppButtonPressed() { 400 void VrShell::AppButtonPressed(bool content_paused) {
406 if (vr_shell_enabled_) 401 if (vr_shell_enabled_) {
402 OnContentPaused(content_paused);
407 ui_->HandleAppButtonClicked(); 403 ui_->HandleAppButtonClicked();
404 }
408 } 405 }
409 406
410 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env, 407 void VrShell::ContentPhysicalBoundsChanged(JNIEnv* env,
411 const JavaParamRef<jobject>& object, 408 const JavaParamRef<jobject>& object,
412 jint width, 409 jint width,
413 jint height, 410 jint height,
414 jfloat dpr) { 411 jfloat dpr) {
415 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged"); 412 TRACE_EVENT0("gpu", "VrShell::ContentPhysicalBoundsChanged");
416 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged, 413 PostToGlThreadWhenReady(base::Bind(&VrShellGl::ContentPhysicalBoundsChanged,
417 gl_thread_->GetVrShellGl(), width, 414 gl_thread_->GetVrShellGl(), width,
418 height)); 415 height));
419 compositor_->SetWindowBounds(gfx::Size(width, height)); 416 compositor_->SetWindowBounds(gfx::Size(width, height));
420 } 417 }
421 418
422 void VrShell::DoUiAction(const UiAction action, 419 void VrShell::DoUiAction(const UiAction action,
423 const base::DictionaryValue* arguments) { 420 const base::DictionaryValue* arguments) {
424 // Actions that can be handled natively. 421 // Actions that can be handled natively.
425 switch (action) { 422 switch (action) {
426 case SET_CONTENT_PAUSED: { 423 case SET_CONTENT_PAUSED: {
bshe 2017/04/21 21:08:42 wondering if this UiAction is still needed? If not
ymalik 2017/04/28 00:12:04 I think we have it here as reference for things th
427 bool paused;
428 CHECK(arguments->GetBoolean("paused", &paused));
429 SetContentPaused(paused);
430 return; 424 return;
431 } 425 }
432 case HISTORY_BACK: 426 case HISTORY_BACK:
433 if (web_contents_ && web_contents_->IsFullscreen()) { 427 if (web_contents_ && web_contents_->IsFullscreen()) {
434 web_contents_->ExitFullscreen(false); 428 web_contents_->ExitFullscreen(false);
435 return; 429 return;
436 } 430 }
437 // Otherwise handle in java. 431 // Otherwise handle in java.
438 break; 432 break;
439 case EXIT_PRESENT: 433 case EXIT_PRESENT:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 jboolean for_web_vr, 557 jboolean for_web_vr,
564 jlong gvr_api, 558 jlong gvr_api,
565 jboolean reprojected_rendering) { 559 jboolean reprojected_rendering) {
566 return reinterpret_cast<intptr_t>(new VrShell( 560 return reinterpret_cast<intptr_t>(new VrShell(
567 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android), 561 env, obj, reinterpret_cast<ui::WindowAndroid*>(window_android),
568 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 562 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
569 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 563 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
570 } 564 }
571 565
572 } // namespace vr_shell 566 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698