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

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

Issue 2877133002: VR: Add a loading indicator to the scene. (Closed)
Patch Set: Clear dirty flags after drawing. This yields a mysterious performance boost. 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/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" 9 #include "chrome/browser/android/vr_shell/textures/ui_texture.h"
10 #include "chrome/browser/android/vr_shell/ui_elements/close_button.h" 10 #include "chrome/browser/android/vr_shell/ui_elements/close_button.h"
11 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h"
11 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h" 12 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h"
12 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h" 13 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h"
13 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 14 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
14 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" 15 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h"
15 #include "chrome/browser/android/vr_shell/ui_scene.h" 16 #include "chrome/browser/android/vr_shell/ui_scene.h"
16 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" 17 #include "chrome/browser/android/vr_shell/vr_browser_interface.h"
17 #include "chrome/browser/android/vr_shell/vr_shell.h" 18 #include "chrome/browser/android/vr_shell/vr_shell.h"
18 19
19 namespace vr_shell { 20 namespace vr_shell {
20 21
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 bool in_web_vr) 63 bool in_web_vr)
63 : browser_(browser), 64 : browser_(browser),
64 scene_(scene), 65 scene_(scene),
65 in_cct_(in_cct), 66 in_cct_(in_cct),
66 web_vr_mode_(in_web_vr), 67 web_vr_mode_(in_web_vr),
67 weak_ptr_factory_(this) { 68 weak_ptr_factory_(this) {
68 CreateBackground(); 69 CreateBackground();
69 CreateContentQuad(); 70 CreateContentQuad();
70 CreateSecurityWarnings(); 71 CreateSecurityWarnings();
71 CreateUrlBar(); 72 CreateUrlBar();
72
73 if (in_cct_) 73 if (in_cct_)
74 CreateCloseButton(); 74 CreateCloseButton();
75
76 ConfigureScene();
75 } 77 }
76 78
77 UiSceneManager::~UiSceneManager() {} 79 UiSceneManager::~UiSceneManager() {}
78 80
79 void UiSceneManager::CreateSecurityWarnings() { 81 void UiSceneManager::CreateSecurityWarnings() {
80 std::unique_ptr<UiElement> element; 82 std::unique_ptr<UiElement> element;
81 83
82 // TODO(mthiesse): Programatically compute the proper texture size for these 84 // TODO(mthiesse): Programatically compute the proper texture size for these
83 // textured UI elements. 85 // textured UI elements.
84 element = base::MakeUnique<PermanentSecurityWarning>(512); 86 element = base::MakeUnique<PermanentSecurityWarning>(512);
(...skipping 27 matching lines...) Expand all
112 void UiSceneManager::CreateContentQuad() { 114 void UiSceneManager::CreateContentQuad() {
113 std::unique_ptr<UiElement> element; 115 std::unique_ptr<UiElement> element;
114 116
115 element = base::MakeUnique<UiElement>(); 117 element = base::MakeUnique<UiElement>();
116 element->set_id(AllocateId()); 118 element->set_id(AllocateId());
117 element->set_fill(vr_shell::Fill::CONTENT); 119 element->set_fill(vr_shell::Fill::CONTENT);
118 element->set_size({kContentWidth, kContentHeight, 1}); 120 element->set_size({kContentWidth, kContentHeight, 1});
119 element->set_translation({0, kContentVerticalOffset, -kContentDistance}); 121 element->set_translation({0, kContentVerticalOffset, -kContentDistance});
120 element->set_visible(false); 122 element->set_visible(false);
121 main_content_ = element.get(); 123 main_content_ = element.get();
122 browser_ui_elements_.push_back(element.get()); 124 content_elements_.push_back(element.get());
123 scene_->AddUiElement(std::move(element)); 125 scene_->AddUiElement(std::move(element));
124 126
125 // Place an invisible but hittable plane behind the content quad, to keep the 127 // Place an invisible but hittable plane behind the content quad, to keep the
126 // reticle roughly planar with the content if near content. 128 // reticle roughly planar with the content if near content.
127 element = base::MakeUnique<UiElement>(); 129 element = base::MakeUnique<UiElement>();
128 element->set_id(AllocateId()); 130 element->set_id(AllocateId());
129 element->set_fill(vr_shell::Fill::NONE); 131 element->set_fill(vr_shell::Fill::NONE);
130 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); 132 element->set_size({kBackplaneSize, kBackplaneSize, 1.0});
131 element->set_translation({0.0, 0.0, -kTextureOffset}); 133 element->set_translation({0.0, 0.0, -kTextureOffset});
132 element->set_parent_id(main_content_->id()); 134 element->set_parent_id(main_content_->id());
133 browser_ui_elements_.push_back(element.get()); 135 content_elements_.push_back(element.get());
134 scene_->AddUiElement(std::move(element)); 136 scene_->AddUiElement(std::move(element));
135 137
136 // Limit reticle distance to a sphere based on content distance. 138 // Limit reticle distance to a sphere based on content distance.
137 scene_->SetBackgroundDistance(main_content_->translation().z() * 139 scene_->SetBackgroundDistance(main_content_->translation().z() *
138 -kBackgroundDistanceMultiplier); 140 -kBackgroundDistanceMultiplier);
139 } 141 }
140 142
141 void UiSceneManager::CreateBackground() { 143 void UiSceneManager::CreateBackground() {
142 std::unique_ptr<UiElement> element; 144 std::unique_ptr<UiElement> element;
143 vr::Colorf horizon = 145 vr::Colorf horizon =
144 in_cct_ ? kCctBackgroundHorizonColor : kBackgroundHorizonColor; 146 in_cct_ ? kCctBackgroundHorizonColor : kBackgroundHorizonColor;
145 vr::Colorf center = 147 vr::Colorf center =
146 in_cct_ ? kCctBackgroundCenterColor : kBackgroundCenterColor; 148 in_cct_ ? kCctBackgroundCenterColor : kBackgroundCenterColor;
147 149
148 // Floor. 150 // Floor.
149 element = base::MakeUnique<UiElement>(); 151 element = base::MakeUnique<UiElement>();
150 element->set_id(AllocateId()); 152 element->set_id(AllocateId());
151 element->set_size({kSceneSize, kSceneSize, 1.0}); 153 element->set_size({kSceneSize, kSceneSize, 1.0});
152 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); 154 element->set_translation({0.0, -kSceneHeight / 2, 0.0});
153 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); 155 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0});
154 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); 156 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT);
155 element->set_edge_color(horizon); 157 element->set_edge_color(horizon);
156 element->set_center_color(center); 158 element->set_center_color(center);
157 element->set_draw_phase(0); 159 element->set_draw_phase(0);
158 browser_ui_elements_.push_back(element.get()); 160 control_elements_.push_back(element.get());
159 scene_->AddUiElement(std::move(element)); 161 scene_->AddUiElement(std::move(element));
160 162
161 // Ceiling. 163 // Ceiling.
162 element = base::MakeUnique<UiElement>(); 164 element = base::MakeUnique<UiElement>();
163 element->set_id(AllocateId()); 165 element->set_id(AllocateId());
164 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); 166 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT);
165 element->set_size({kSceneSize, kSceneSize, 1.0}); 167 element->set_size({kSceneSize, kSceneSize, 1.0});
166 element->set_translation({0.0, kSceneHeight / 2, 0.0}); 168 element->set_translation({0.0, kSceneHeight / 2, 0.0});
167 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); 169 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2});
168 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); 170 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT);
169 element->set_edge_color(horizon); 171 element->set_edge_color(horizon);
170 element->set_center_color(center); 172 element->set_center_color(center);
171 element->set_draw_phase(0); 173 element->set_draw_phase(0);
172 browser_ui_elements_.push_back(element.get()); 174 control_elements_.push_back(element.get());
173 scene_->AddUiElement(std::move(element)); 175 scene_->AddUiElement(std::move(element));
174 176
175 // Floor grid. 177 // Floor grid.
176 element = base::MakeUnique<UiElement>(); 178 element = base::MakeUnique<UiElement>();
177 element->set_id(AllocateId()); 179 element->set_id(AllocateId());
178 element->set_fill(vr_shell::Fill::GRID_GRADIENT); 180 element->set_fill(vr_shell::Fill::GRID_GRADIENT);
179 element->set_size({kSceneSize, kSceneSize, 1.0}); 181 element->set_size({kSceneSize, kSceneSize, 1.0});
180 element->set_translation({0.0, -kSceneHeight / 2 + kTextureOffset, 0.0}); 182 element->set_translation({0.0, -kSceneHeight / 2 + kTextureOffset, 0.0});
181 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2}); 183 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2});
182 element->set_fill(vr_shell::Fill::GRID_GRADIENT); 184 element->set_fill(vr_shell::Fill::GRID_GRADIENT);
183 element->set_center_color(horizon); 185 element->set_center_color(horizon);
184 vr::Colorf edge_color = horizon; 186 vr::Colorf edge_color = horizon;
185 edge_color.a = 0.0; 187 edge_color.a = 0.0;
186 element->set_edge_color(edge_color); 188 element->set_edge_color(edge_color);
187 element->set_gridline_count(kFloorGridlineCount); 189 element->set_gridline_count(kFloorGridlineCount);
188 element->set_draw_phase(0); 190 element->set_draw_phase(0);
189 browser_ui_elements_.push_back(element.get()); 191 control_elements_.push_back(element.get());
190 scene_->AddUiElement(std::move(element)); 192 scene_->AddUiElement(std::move(element));
191 193
192 scene_->SetBackgroundColor(horizon); 194 scene_->SetBackgroundColor(horizon);
193 } 195 }
194 196
195 void UiSceneManager::CreateUrlBar() { 197 void UiSceneManager::CreateUrlBar() {
196 // TODO(cjgrant): Incorporate final size and position. 198 // TODO(cjgrant): Incorporate final size and position.
197 // TODO(cjgrant): Add the loading progress indicator element. 199 auto url_bar = base::MakeUnique<UrlBar>(512);
198 std::unique_ptr<UrlBar> element = base::MakeUnique<UrlBar>(512); 200 url_bar->set_id(AllocateId());
199 element->set_id(AllocateId()); 201 url_bar->set_translation({0, -0.9, -1.8});
200 element->set_translation({0, -0.9, -1.8}); 202 url_bar->set_size({0.9, 0, 1});
201 element->set_size({0.9, 0, 1}); 203 url_bar->SetBackButtonCallback(
202 element->SetBackButtonCallback(
203 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this))); 204 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)));
204 url_bar_ = element.get(); 205 url_bar_ = url_bar.get();
205 browser_ui_elements_.push_back(element.get()); 206 control_elements_.push_back(url_bar.get());
206 scene_->AddUiElement(std::move(element)); 207 scene_->AddUiElement(std::move(url_bar));
208
209 auto indicator = base::MakeUnique<LoadingIndicator>(256);
210 indicator->set_id(AllocateId());
211 indicator->set_translation({0, -0.8, -1.8});
212 indicator->set_size({0.4, 0, 1});
213 loading_indicator_ = indicator.get();
214 control_elements_.push_back(indicator.get());
215 scene_->AddUiElement(std::move(indicator));
207 } 216 }
208 217
209 void UiSceneManager::CreateCloseButton() { 218 void UiSceneManager::CreateCloseButton() {
210 std::unique_ptr<CloseButton> element = 219 std::unique_ptr<CloseButton> element =
211 base::MakeUnique<CloseButton>(base::Bind( 220 base::MakeUnique<CloseButton>(base::Bind(
212 &UiSceneManager::OnCloseButtonClicked, base::Unretained(this))); 221 &UiSceneManager::OnCloseButtonClicked, base::Unretained(this)));
213 element->set_id(AllocateId()); 222 element->set_id(AllocateId());
214 element->set_fill(vr_shell::Fill::NONE); 223 element->set_fill(vr_shell::Fill::NONE);
215 element->set_translation( 224 element->set_translation(
216 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3, 225 gfx::Vector3dF(0, kContentVerticalOffset - (kContentHeight / 2) - 0.3,
217 -kContentDistance + 0.4)); 226 -kContentDistance + 0.4));
218 element->set_size(gfx::Vector3dF(0.2, 0.2, 1)); 227 element->set_size(gfx::Vector3dF(0.2, 0.2, 1));
219 browser_ui_elements_.push_back(element.get()); 228 control_elements_.push_back(element.get());
220 scene_->AddUiElement(std::move(element)); 229 scene_->AddUiElement(std::move(element));
221 } 230 }
222 231
223 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { 232 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
224 return weak_ptr_factory_.GetWeakPtr(); 233 return weak_ptr_factory_.GetWeakPtr();
225 } 234 }
226 235
227 void UiSceneManager::SetWebVrMode(bool web_vr) { 236 void UiSceneManager::SetWebVrMode(bool web_vr) {
237 if (web_vr_mode_ == web_vr)
238 return;
228 web_vr_mode_ = web_vr; 239 web_vr_mode_ = web_vr;
240 ConfigureScene();
241 }
229 242
230 // Make all VR scene UI elements visible if not in WebVR. 243 void UiSceneManager::ConfigureScene() {
231 for (UiElement* element : browser_ui_elements_) { 244 // Controls (URL bar, loading progress, etc).
232 element->set_visible(!web_vr_mode_); 245 bool controls_visible = !web_vr_mode_ && !fullscreen_;
246 for (UiElement* element : control_elements_) {
247 element->SetEnabled(controls_visible);
233 } 248 }
234 url_bar_->SetEnabled(!web_vr);
235 249
236 ConfigureSecurityWarnings(); 250 // Content quad.
amp 2017/05/12 21:13:46 s/quad/elements/ Now that there are more than one
cjgrant 2017/05/12 21:45:52 Done.
251 for (UiElement* element : content_elements_) {
252 element->SetEnabled(!web_vr_mode_);
253 }
254
255 // Update content quad parameters.
amp 2017/05/12 21:13:46 Change to 'Update content parameters depending on
cjgrant 2017/05/12 21:45:52 Done.
256 // TODO(http://crbug.com/642937): Animate fullscreen transitions.
257 if (fullscreen_) {
258 scene_->SetBackgroundColor(kFullscreenBackgroundColor);
259 main_content_->set_translation(
amp 2017/05/12 21:13:46 do we need to change the backplane as well (now th
cjgrant 2017/05/12 21:45:52 Nope, we're fine - the backplane is a child of the
260 {0, kFullscreenVerticalOffset, -kFullscreenDistance});
261 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1});
262 } else {
263 scene_->SetBackgroundColor(kBackgroundHorizonColor);
264 // Note that main_content_ is already visible in this case.
265 main_content_->set_translation(
266 {0, kContentVerticalOffset, -kContentDistance});
267 main_content_->set_size({kContentWidth, kContentHeight, 1});
268 }
269
270 scene_->SetBackgroundDistance(main_content_->translation().z() *
271 -kBackgroundDistanceMultiplier);
237 } 272 }
238 273
239 void UiSceneManager::SetWebVrSecureOrigin(bool secure) { 274 void UiSceneManager::SetWebVrSecureOrigin(bool secure) {
240 secure_origin_ = secure; 275 secure_origin_ = secure;
241 ConfigureSecurityWarnings(); 276 ConfigureSecurityWarnings();
242 } 277 }
243 278
244 void UiSceneManager::OnAppButtonClicked() { 279 void UiSceneManager::OnAppButtonClicked() {
245 // App button click exits the WebVR presentation and fullscreen. 280 // App button click exits the WebVR presentation and fullscreen.
246 browser_->ExitPresent(); 281 browser_->ExitPresent();
247 browser_->ExitFullscreen(); 282 browser_->ExitFullscreen();
248 } 283 }
249 284
250 void UiSceneManager::OnAppButtonGesturePerformed( 285 void UiSceneManager::OnAppButtonGesturePerformed(
251 UiInterface::Direction direction) {} 286 UiInterface::Direction direction) {}
252 287
253 void UiSceneManager::SetFullscreen(bool fullscreen) { 288 void UiSceneManager::SetFullscreen(bool fullscreen) {
254 // Make all VR scene UI elements visible if not in fullscreen. 289 if (fullscreen_ == fullscreen)
255 for (UiElement* element : browser_ui_elements_) { 290 return;
256 element->set_visible(!fullscreen); 291 fullscreen_ = fullscreen;
257 } 292 ConfigureScene();
258
259 // Show the content quad in full screen.
260 if (fullscreen) {
261 scene_->SetBackgroundColor(kFullscreenBackgroundColor);
262 main_content_->set_visible(true);
263 main_content_->set_translation(
264 {0, kFullscreenVerticalOffset, -kFullscreenDistance});
265 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1});
266
267 // TODO(http://crbug.com/642937): Animate fullscreen transitions.
268 } else {
269 scene_->SetBackgroundColor(kBackgroundHorizonColor);
270 // Note that main_content_ is already visible in this case.
271 main_content_->set_translation(
272 {0, kContentVerticalOffset, -kContentDistance});
273 main_content_->set_size({kContentWidth, kContentHeight, 1});
274 }
275
276 scene_->SetBackgroundDistance(main_content_->translation().z() *
277 -kBackgroundDistanceMultiplier);
278 } 293 }
279 294
280 void UiSceneManager::ConfigureSecurityWarnings() { 295 void UiSceneManager::ConfigureSecurityWarnings() {
281 bool enabled = web_vr_mode_ && !secure_origin_; 296 bool enabled = web_vr_mode_ && !secure_origin_;
282 permanent_security_warning_->set_visible(enabled); 297 permanent_security_warning_->set_visible(enabled);
283 transient_security_warning_->set_visible(enabled); 298 transient_security_warning_->set_visible(enabled);
284 if (enabled) { 299 if (enabled) {
285 security_warning_timer_.Start( 300 security_warning_timer_.Start(
286 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, 301 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this,
287 &UiSceneManager::OnSecurityWarningTimer); 302 &UiSceneManager::OnSecurityWarningTimer);
(...skipping 11 matching lines...) Expand all
299 } 314 }
300 315
301 void UiSceneManager::SetURL(const GURL& gurl) { 316 void UiSceneManager::SetURL(const GURL& gurl) {
302 url_bar_->SetURL(gurl); 317 url_bar_->SetURL(gurl);
303 } 318 }
304 319
305 void UiSceneManager::SetSecurityLevel(int level) { 320 void UiSceneManager::SetSecurityLevel(int level) {
306 url_bar_->SetSecurityLevel(level); 321 url_bar_->SetSecurityLevel(level);
307 } 322 }
308 323
309 void UiSceneManager::SetLoading(bool loading) {} 324 void UiSceneManager::SetLoading(bool loading) {
325 loading_indicator_->SetLoading(loading);
326 }
310 327
311 void UiSceneManager::SetLoadProgress(double progress) {} 328 void UiSceneManager::SetLoadProgress(float progress) {
329 loading_indicator_->SetLoadProgress(progress);
330 }
312 331
313 void UiSceneManager::SetHistoryButtonsEnabled(bool can_go_back, 332 void UiSceneManager::SetHistoryButtonsEnabled(bool can_go_back,
314 bool can_go_forward) {} 333 bool can_go_forward) {}
315 334
316 void UiSceneManager::OnCloseButtonClicked() {} 335 void UiSceneManager::OnCloseButtonClicked() {}
317 336
318 int UiSceneManager::AllocateId() { 337 int UiSceneManager::AllocateId() {
319 return next_available_id_++; 338 return next_available_id_++;
320 } 339 }
321 340
322 } // namespace vr_shell 341 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.h ('k') | chrome/browser/android/vr_shell/vr_gl_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698