OLD | NEW |
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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 static constexpr vr::Colorf kBackgroundHorizonColor = {0.57, 0.57, 0.57, 1.0}; | 39 static constexpr vr::Colorf kBackgroundHorizonColor = {0.57, 0.57, 0.57, 1.0}; |
40 static constexpr vr::Colorf kBackgroundCenterColor = {0.48, 0.48, 0.48, 1.0}; | 40 static constexpr vr::Colorf kBackgroundCenterColor = {0.48, 0.48, 0.48, 1.0}; |
41 | 41 |
42 // Tiny distance to offset textures that should appear in the same plane. | 42 // Tiny distance to offset textures that should appear in the same plane. |
43 static constexpr float kTextureOffset = 0.01; | 43 static constexpr float kTextureOffset = 0.01; |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 UiSceneManager::UiSceneManager(VrBrowserInterface* browser, UiScene* scene) | 47 UiSceneManager::UiSceneManager(VrBrowserInterface* browser, UiScene* scene) |
48 : browser_(browser), scene_(scene), weak_ptr_factory_(this) { | 48 : browser_(browser), scene_(scene), weak_ptr_factory_(this) { |
49 std::unique_ptr<UiElement> element; | |
50 | |
51 CreateBackground(); | 49 CreateBackground(); |
52 CreateContentQuad(); | 50 CreateContentQuad(); |
53 CreateSecurityWarnings(); | 51 CreateSecurityWarnings(); |
54 } | 52 } |
55 | 53 |
56 UiSceneManager::~UiSceneManager() {} | 54 UiSceneManager::~UiSceneManager() {} |
57 | 55 |
58 void UiSceneManager::CreateSecurityWarnings() { | 56 void UiSceneManager::CreateSecurityWarnings() { |
59 std::unique_ptr<UiElement> element; | 57 std::unique_ptr<UiElement> element; |
60 | 58 |
61 // TODO(mthiesse): Programatically compute the proper texture size for these | 59 // TODO(mthiesse): Programatically compute the proper texture size for these |
62 // textured UI elements. | 60 // textured UI elements. |
63 element = base::MakeUnique<PermanentSecurityWarning>(512); | 61 element = base::MakeUnique<PermanentSecurityWarning>(512); |
64 element->id = AllocateId(); | 62 element->set_id(AllocateId()); |
65 element->fill = vr_shell::Fill::NONE; | 63 element->set_fill(vr_shell::Fill::NONE); |
66 element->size = {kPermanentWarningWidth, kPermanentWarningHeight, 1}; | 64 element->set_size({kPermanentWarningWidth, kPermanentWarningHeight, 1}); |
67 element->scale = {kWarningDistance, kWarningDistance, 1}; | 65 element->set_scale({kWarningDistance, kWarningDistance, 1}); |
68 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), | 66 element->set_translation({0, kWarningDistance * sin(kWarningAngleRadians), |
69 -kWarningDistance * cos(kWarningAngleRadians)}; | 67 -kWarningDistance * cos(kWarningAngleRadians)}); |
70 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; | 68 element->set_rotation({1.0f, 0, 0, kWarningAngleRadians}); |
71 element->visible = false; | 69 element->set_visible(false); |
72 element->hit_testable = false; | 70 element->set_hit_testable(false); |
73 element->lock_to_fov = true; | 71 element->set_lock_to_fov(true); |
74 permanent_security_warning_ = element.get(); | 72 permanent_security_warning_ = element.get(); |
75 scene_->AddUiElement(std::move(element)); | 73 scene_->AddUiElement(std::move(element)); |
76 | 74 |
77 element = base::MakeUnique<TransientSecurityWarning>(1024); | 75 element = base::MakeUnique<TransientSecurityWarning>(1024); |
78 element->id = AllocateId(); | 76 element->set_id(AllocateId()); |
79 element->fill = vr_shell::Fill::NONE; | 77 element->set_fill(vr_shell::Fill::NONE); |
80 element->size = {kTransientWarningWidth, kTransientWarningHeight, 1}; | 78 element->set_size({kTransientWarningWidth, kTransientWarningHeight, 1}); |
81 element->scale = {kWarningDistance, kWarningDistance, 1}; | 79 element->set_scale({kWarningDistance, kWarningDistance, 1}); |
82 element->translation = {0, 0, -kWarningDistance}; | 80 element->set_translation({0, 0, -kWarningDistance}); |
83 element->visible = false; | 81 element->set_visible(false); |
84 element->hit_testable = false; | 82 element->set_hit_testable(false); |
85 element->lock_to_fov = true; | 83 element->set_lock_to_fov(true); |
86 transient_security_warning_ = element.get(); | 84 transient_security_warning_ = element.get(); |
87 scene_->AddUiElement(std::move(element)); | 85 scene_->AddUiElement(std::move(element)); |
88 } | 86 } |
89 | 87 |
90 void UiSceneManager::CreateContentQuad() { | 88 void UiSceneManager::CreateContentQuad() { |
91 std::unique_ptr<UiElement> element; | 89 std::unique_ptr<UiElement> element; |
92 | 90 |
93 element = base::MakeUnique<UiElement>(); | 91 element = base::MakeUnique<UiElement>(); |
94 element->id = AllocateId(); | 92 element->set_id(AllocateId()); |
95 element->fill = vr_shell::Fill::CONTENT; | 93 element->set_fill(vr_shell::Fill::CONTENT); |
96 element->size = {kContentWidth, kContentHeight, 1}; | 94 element->set_size({kContentWidth, kContentHeight, 1}); |
97 element->translation = {0, kContentVerticalOffset, -kContentDistance}; | 95 element->set_translation({0, kContentVerticalOffset, -kContentDistance}); |
98 element->visible = false; | 96 element->set_visible(false); |
99 main_content_ = element.get(); | 97 main_content_ = element.get(); |
100 browser_ui_elements_.push_back(element.get()); | 98 browser_ui_elements_.push_back(element.get()); |
101 scene_->AddUiElement(std::move(element)); | 99 scene_->AddUiElement(std::move(element)); |
102 | 100 |
103 // Place an invisible but hittable plane behind the content quad, to keep the | 101 // Place an invisible but hittable plane behind the content quad, to keep the |
104 // reticle roughly planar with the content if near content. | 102 // reticle roughly planar with the content if near content. |
105 element = base::MakeUnique<UiElement>(); | 103 element = base::MakeUnique<UiElement>(); |
106 element->id = AllocateId(); | 104 element->set_id(AllocateId()); |
107 element->fill = vr_shell::Fill::NONE; | 105 element->set_fill(vr_shell::Fill::NONE); |
108 element->size = {kBackplaneSize, kBackplaneSize, 1.0}; | 106 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); |
109 element->translation = {0.0, 0.0, -kTextureOffset}; | 107 element->set_translation({0.0, 0.0, -kTextureOffset}); |
110 element->parent_id = main_content_->id; | 108 element->set_parent_id(main_content_->id()); |
111 browser_ui_elements_.push_back(element.get()); | 109 browser_ui_elements_.push_back(element.get()); |
112 scene_->AddUiElement(std::move(element)); | 110 scene_->AddUiElement(std::move(element)); |
113 | 111 |
114 // Limit reticle distance to a sphere based on content distance. | 112 // Limit reticle distance to a sphere based on content distance. |
115 scene_->SetBackgroundDistance(main_content_->translation.z() * | 113 scene_->SetBackgroundDistance(main_content_->translation().z() * |
116 -kBackgroundDistanceMultiplier); | 114 -kBackgroundDistanceMultiplier); |
117 } | 115 } |
118 | 116 |
119 void UiSceneManager::CreateBackground() { | 117 void UiSceneManager::CreateBackground() { |
120 std::unique_ptr<UiElement> element; | 118 std::unique_ptr<UiElement> element; |
121 | 119 |
122 // Floor. | 120 // Floor. |
123 element = base::MakeUnique<UiElement>(); | 121 element = base::MakeUnique<UiElement>(); |
124 element->id = AllocateId(); | 122 element->set_id(AllocateId()); |
125 element->size = {kSceneSize, kSceneSize, 1.0}; | 123 element->set_size({kSceneSize, kSceneSize, 1.0}); |
126 element->translation = {0.0, -kSceneHeight / 2, 0.0}; | 124 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); |
127 element->rotation = {1.0, 0.0, 0.0, -M_PI / 2.0}; | 125 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); |
128 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | 126 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); |
129 element->edge_color = kBackgroundHorizonColor; | 127 element->set_edge_color(kBackgroundHorizonColor); |
130 element->center_color = kBackgroundCenterColor; | 128 element->set_center_color(kBackgroundCenterColor); |
131 element->draw_phase = 0; | 129 element->set_draw_phase(0); |
132 browser_ui_elements_.push_back(element.get()); | 130 browser_ui_elements_.push_back(element.get()); |
133 scene_->AddUiElement(std::move(element)); | 131 scene_->AddUiElement(std::move(element)); |
134 | 132 |
135 // Ceiling. | 133 // Ceiling. |
136 element = base::MakeUnique<UiElement>(); | 134 element = base::MakeUnique<UiElement>(); |
137 element->id = AllocateId(); | 135 element->set_id(AllocateId()); |
138 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | 136 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); |
139 element->size = {kSceneSize, kSceneSize, 1.0}; | 137 element->set_size({kSceneSize, kSceneSize, 1.0}); |
140 element->translation = {0.0, kSceneHeight / 2, 0.0}; | 138 element->set_translation({0.0, kSceneHeight / 2, 0.0}); |
141 element->rotation = {1.0, 0.0, 0.0, M_PI / 2}; | 139 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); |
142 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | 140 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); |
143 element->edge_color = kBackgroundHorizonColor; | 141 element->set_edge_color(kBackgroundHorizonColor); |
144 element->center_color = kBackgroundCenterColor; | 142 element->set_center_color(kBackgroundCenterColor); |
145 element->draw_phase = 0; | 143 element->set_draw_phase(0); |
146 browser_ui_elements_.push_back(element.get()); | 144 browser_ui_elements_.push_back(element.get()); |
147 scene_->AddUiElement(std::move(element)); | 145 scene_->AddUiElement(std::move(element)); |
148 | 146 |
149 // Floor grid. | 147 // Floor grid. |
150 element = base::MakeUnique<UiElement>(); | 148 element = base::MakeUnique<UiElement>(); |
151 element->id = AllocateId(); | 149 element->set_id(AllocateId()); |
152 element->fill = vr_shell::Fill::GRID_GRADIENT; | 150 element->set_fill(vr_shell::Fill::GRID_GRADIENT); |
153 element->size = {kSceneSize, kSceneSize, 1.0}; | 151 element->set_size({kSceneSize, kSceneSize, 1.0}); |
154 element->translation = {0.0, -kSceneHeight / 2 + kTextureOffset, 0.0}; | 152 element->set_translation({0.0, -kSceneHeight / 2 + kTextureOffset, 0.0}); |
155 element->rotation = {1.0, 0.0, 0.0, -M_PI / 2}; | 153 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2}); |
156 element->fill = vr_shell::Fill::GRID_GRADIENT; | 154 element->set_fill(vr_shell::Fill::GRID_GRADIENT); |
157 element->center_color = kBackgroundHorizonColor; | 155 element->set_center_color(kBackgroundHorizonColor); |
158 vr::Colorf edge_color = kBackgroundHorizonColor; | 156 vr::Colorf edge_color = kBackgroundHorizonColor; |
159 edge_color.a = 0.0; | 157 edge_color.a = 0.0; |
160 element->edge_color = edge_color; | 158 element->set_edge_color(edge_color); |
161 element->gridline_count = kFloorGridlineCount; | 159 element->set_gridline_count(kFloorGridlineCount); |
162 element->draw_phase = 0; | 160 element->set_draw_phase(0); |
163 browser_ui_elements_.push_back(element.get()); | 161 browser_ui_elements_.push_back(element.get()); |
164 scene_->AddUiElement(std::move(element)); | 162 scene_->AddUiElement(std::move(element)); |
165 | 163 |
166 scene_->SetBackgroundColor(kBackgroundHorizonColor); | 164 scene_->SetBackgroundColor(kBackgroundHorizonColor); |
167 } | 165 } |
168 | 166 |
169 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 167 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
170 return weak_ptr_factory_.GetWeakPtr(); | 168 return weak_ptr_factory_.GetWeakPtr(); |
171 } | 169 } |
172 | 170 |
173 void UiSceneManager::SetWebVRMode(bool web_vr) { | 171 void UiSceneManager::SetWebVRMode(bool web_vr) { |
174 web_vr_mode_ = web_vr; | 172 web_vr_mode_ = web_vr; |
175 | 173 |
176 // Make all VR scene UI elements visible if not in WebVR. | 174 // Make all VR scene UI elements visible if not in WebVR. |
177 for (UiElement* element : browser_ui_elements_) { | 175 for (UiElement* element : browser_ui_elements_) { |
178 element->visible = !web_vr_mode_; | 176 element->set_visible(!web_vr_mode_); |
179 } | 177 } |
180 | 178 |
181 ConfigureSecurityWarnings(); | 179 ConfigureSecurityWarnings(); |
182 } | 180 } |
183 | 181 |
184 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { | 182 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { |
185 secure_origin_ = secure; | 183 secure_origin_ = secure; |
186 ConfigureSecurityWarnings(); | 184 ConfigureSecurityWarnings(); |
187 } | 185 } |
188 | 186 |
189 void UiSceneManager::OnAppButtonClicked() { | 187 void UiSceneManager::OnAppButtonClicked() { |
190 // Pressing the app button currenly pauses content rendering. Note: its still | 188 // Pressing the app button currenly pauses content rendering. Note: its still |
191 // unclear what we want to do here and this will most likely change. | 189 // unclear what we want to do here and this will most likely change. |
192 content_rendering_enabled_ = !content_rendering_enabled_; | 190 content_rendering_enabled_ = !content_rendering_enabled_; |
193 scene_->SetWebVrRenderingEnabled(content_rendering_enabled_); | 191 scene_->SetWebVrRenderingEnabled(content_rendering_enabled_); |
194 browser_->OnContentPaused(!content_rendering_enabled_); | 192 browser_->OnContentPaused(!content_rendering_enabled_); |
195 } | 193 } |
196 | 194 |
197 void UiSceneManager::ConfigureSecurityWarnings() { | 195 void UiSceneManager::ConfigureSecurityWarnings() { |
198 bool enabled = web_vr_mode_ && !secure_origin_; | 196 bool enabled = web_vr_mode_ && !secure_origin_; |
199 permanent_security_warning_->visible = enabled; | 197 permanent_security_warning_->set_visible(enabled); |
200 transient_security_warning_->visible = enabled; | 198 transient_security_warning_->set_visible(enabled); |
201 if (enabled) { | 199 if (enabled) { |
202 security_warning_timer_.Start( | 200 security_warning_timer_.Start( |
203 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, | 201 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, |
204 &UiSceneManager::OnSecurityWarningTimer); | 202 &UiSceneManager::OnSecurityWarningTimer); |
205 } else { | 203 } else { |
206 security_warning_timer_.Stop(); | 204 security_warning_timer_.Stop(); |
207 } | 205 } |
208 } | 206 } |
209 | 207 |
210 void UiSceneManager::OnSecurityWarningTimer() { | 208 void UiSceneManager::OnSecurityWarningTimer() { |
211 transient_security_warning_->visible = false; | 209 transient_security_warning_->set_visible(false); |
212 } | 210 } |
213 | 211 |
214 int UiSceneManager::AllocateId() { | 212 int UiSceneManager::AllocateId() { |
215 return next_available_id_++; | 213 return next_available_id_++; |
216 } | 214 } |
217 | 215 |
218 } // namespace vr_shell | 216 } // namespace vr_shell |
OLD | NEW |