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

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

Issue 2833773005: Pause drawing webvr when the App button is pressed (Closed)
Patch Set: Add unittest + cleanup Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ui_scene_manager.h" 5 #include "chrome/browser/android/vr_shell/ui_scene_manager.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" 8 #include "chrome/browser/android/vr_shell/textures/ui_texture.h"
9 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h" 9 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h"
10 #include "chrome/browser/android/vr_shell/ui_elements/textured_element.h" 10 #include "chrome/browser/android/vr_shell/ui_elements/textured_element.h"
11 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h" 11 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h"
12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
13 #include "chrome/browser/android/vr_shell/ui_scene.h" 13 #include "chrome/browser/android/vr_shell/ui_scene.h"
14 #include "chrome/browser/android/vr_shell/vr_gl_thread.h"
15 #include "chrome/browser/android/vr_shell/vr_shell.h"
16 #include "chrome/browser/android/vr_shell/vr_thread_envoy.h"
14 17
15 namespace vr_shell { 18 namespace vr_shell {
16 19
17 namespace { 20 namespace {
18 21
19 static constexpr int kWarningTimeoutSeconds = 30; 22 static constexpr int kWarningTimeoutSeconds = 30;
20 static constexpr float kWarningDistance = 0.7; 23 static constexpr float kWarningDistance = 0.7;
21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; 24 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0;
22 25
23 static constexpr float kPermanentWarningHeight = 0.226; 26 static constexpr float kPermanentWarningHeight = 0.226;
24 static constexpr float kPermanentWarningWidth = 0.078; 27 static constexpr float kPermanentWarningWidth = 0.078;
25 static constexpr float kTransientWarningHeight = 0.512; 28 static constexpr float kTransientWarningHeight = 0.512;
26 static constexpr float kTransientWarningWidth = 0.160; 29 static constexpr float kTransientWarningWidth = 0.160;
27 30
28 static constexpr float kContentHeight = 2.4; 31 static constexpr float kContentHeight = 2.4;
29 static constexpr float kContentWidth = 1.6; 32 static constexpr float kContentWidth = 1.6;
30 static constexpr float kContentDistance = 2.5; 33 static constexpr float kContentDistance = 2.5;
31 static constexpr float kContentVerticalOffset = -0.26; 34 static constexpr float kContentVerticalOffset = -0.26;
32 35
33 } // namespace 36 } // namespace
34 37
35 UiSceneManager::UiSceneManager(UiScene* scene) 38 UiSceneManager::UiSceneManager(
36 : scene_(scene), weak_ptr_factory_(this) { 39 const base::WeakPtr<VrThreadEnvoy>& weak_vr_thread_envoy,
40 UiScene* scene)
41 : weak_vr_thread_envoy_(weak_vr_thread_envoy),
42 scene_(scene),
43 weak_ptr_factory_(this) {
37 std::unique_ptr<UiElement> element; 44 std::unique_ptr<UiElement> element;
38 45
39 // For now, use an ID range that does not conflict with the HTML UI. 46 // For now, use an ID range that does not conflict with the HTML UI.
40 int id = 1000; 47 int id = 1000;
41 48
42 // Permanent WebVR security warning. 49 // Permanent WebVR security warning.
43 // TODO(mthiesse): Programatically compute the proper texture size for these 50 // TODO(mthiesse): Programatically compute the proper texture size for these
44 // textured UI elements. 51 // textured UI elements.
45 element = base::MakeUnique<PermanentSecurityWarning>(512); 52 element = base::MakeUnique<PermanentSecurityWarning>(512);
46 element->id = id++; 53 element->id = id++;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 web_vr_mode_ = web_vr; 100 web_vr_mode_ = web_vr;
94 main_content_->visible = !web_vr_mode_; 101 main_content_->visible = !web_vr_mode_;
95 ConfigureSecurityWarnings(); 102 ConfigureSecurityWarnings();
96 } 103 }
97 104
98 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { 105 void UiSceneManager::SetWebVRSecureOrigin(bool secure) {
99 secure_origin_ = secure; 106 secure_origin_ = secure;
100 ConfigureSecurityWarnings(); 107 ConfigureSecurityWarnings();
101 } 108 }
102 109
110 void UiSceneManager::AppButtonPressed() {
111 // Pressing the app button currenly pauses content rendering. Note: its still
112 // unclear what we want to do here and this will most likely change.
ymalik 2017/04/28 00:12:04 I'm just pausing the webvr rending for now. If y'a
113 content_rendering_enabled_ = !content_rendering_enabled_;
114 scene_->SetWebVrRenderingEnabled(!content_rendering_enabled_);
115 weak_vr_thread_envoy_->PostTaskToMainThreadShell(&VrShell::OnContentPaused,
116 content_rendering_enabled_);
117 }
118
103 void UiSceneManager::ConfigureSecurityWarnings() { 119 void UiSceneManager::ConfigureSecurityWarnings() {
104 bool enabled = web_vr_mode_ && !secure_origin_; 120 bool enabled = web_vr_mode_ && !secure_origin_;
105 permanent_security_warning_->visible = enabled; 121 permanent_security_warning_->visible = enabled;
106 transient_security_warning_->visible = enabled; 122 transient_security_warning_->visible = enabled;
107 if (enabled) { 123 if (enabled) {
108 security_warning_timer_.Start( 124 security_warning_timer_.Start(
109 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, 125 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this,
110 &UiSceneManager::OnSecurityWarningTimer); 126 &UiSceneManager::OnSecurityWarningTimer);
111 } else { 127 } else {
112 security_warning_timer_.Stop(); 128 security_warning_timer_.Stop();
113 } 129 }
114 } 130 }
115 131
116 void UiSceneManager::OnSecurityWarningTimer() { 132 void UiSceneManager::OnSecurityWarningTimer() {
117 transient_security_warning_->visible = false; 133 transient_security_warning_->visible = false;
118 } 134 }
119 135
120 } // namespace vr_shell 136 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698