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

Unified Diff: chrome/browser/android/vr_shell/ui_scene_manager.cc

Issue 2844313002: Add VR gradient and grid background to non-WebVR scene. (Closed)
Patch Set: Rebase onto amp@'s magic number CL. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/ui_scene_manager.cc
diff --git a/chrome/browser/android/vr_shell/ui_scene_manager.cc b/chrome/browser/android/vr_shell/ui_scene_manager.cc
index 29434a3931c9b8d6cd332c116915be46fc4428a8..4cbeae41985937e6e5b8f066a9e8f03afad5c1d7 100644
--- a/chrome/browser/android/vr_shell/ui_scene_manager.cc
+++ b/chrome/browser/android/vr_shell/ui_scene_manager.cc
@@ -19,16 +19,26 @@ namespace {
static constexpr int kWarningTimeoutSeconds = 30;
static constexpr float kWarningDistance = 0.7;
static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0;
-
static constexpr float kPermanentWarningHeight = 0.226;
static constexpr float kPermanentWarningWidth = 0.078;
static constexpr float kTransientWarningHeight = 0.512;
static constexpr float kTransientWarningWidth = 0.160;
-static constexpr float kContentHeight = 2.4;
-static constexpr float kContentWidth = 1.6;
+static constexpr float kContentWidth = 2.4;
+static constexpr float kContentHeight = 1.6;
static constexpr float kContentDistance = 2.5;
static constexpr float kContentVerticalOffset = -0.26;
+static constexpr float kBackplaneSize = 1000.0;
+static constexpr float kBackgroundDistanceMultiplier = 1.414;
+
+static constexpr float kSceneSize = 25.0;
+static constexpr float kSceneHeight = 4.0;
+static constexpr int kFloorGridlineCount = 40;
+static constexpr vr::Colorf kBackgroundHorizonColor = {0.57, 0.57, 0.57, 1.0};
+static constexpr vr::Colorf kBackgroundCenterColor = {0.48, 0.48, 0.48, 1.0};
+
+// Tiny distance to offset textures that should appear in the same plane.
+static constexpr float kTextureOffset = 0.01;
} // namespace
@@ -36,15 +46,20 @@ UiSceneManager::UiSceneManager(UiScene* scene)
: scene_(scene), weak_ptr_factory_(this) {
std::unique_ptr<UiElement> element;
- // For now, use an ID range that does not conflict with the HTML UI.
- int id = 1000;
+ CreateBackground();
+ CreateContentQuad();
+ CreateSecurityWarnings();
+}
+
+UiSceneManager::~UiSceneManager() {}
+
+void UiSceneManager::CreateSecurityWarnings() {
+ std::unique_ptr<UiElement> element;
- // Permanent WebVR security warning.
// TODO(mthiesse): Programatically compute the proper texture size for these
// textured UI elements.
element = base::MakeUnique<PermanentSecurityWarning>(512);
- element->id = id++;
- element->name = "Permanent security warning";
+ element->id = AllocateId();
element->fill = vr_shell::Fill::NONE;
element->size = {kPermanentWarningWidth, kPermanentWarningHeight, 1};
element->scale = {kWarningDistance, kWarningDistance, 1};
@@ -57,10 +72,8 @@ UiSceneManager::UiSceneManager(UiScene* scene)
permanent_security_warning_ = element.get();
scene_->AddUiElement(std::move(element));
- // Transient WebVR security warning.
element = base::MakeUnique<TransientSecurityWarning>(1024);
- element->id = id++;
- element->name = "Transient security warning";
+ element->id = AllocateId();
element->fill = vr_shell::Fill::NONE;
element->size = {kTransientWarningWidth, kTransientWarningHeight, 1};
element->scale = {kWarningDistance, kWarningDistance, 1};
@@ -70,20 +83,86 @@ UiSceneManager::UiSceneManager(UiScene* scene)
element->lock_to_fov = true;
transient_security_warning_ = element.get();
scene_->AddUiElement(std::move(element));
+}
+
+void UiSceneManager::CreateContentQuad() {
+ std::unique_ptr<UiElement> element;
- // Main web content quad.
element = base::MakeUnique<UiElement>();
- element->id = id++;
- element->name = "Content";
+ element->id = AllocateId();
element->fill = vr_shell::Fill::CONTENT;
element->size = {kContentWidth, kContentHeight, 1};
element->translation = {0, kContentVerticalOffset, -kContentDistance};
element->visible = false;
main_content_ = element.get();
+ browser_ui_elements_.push_back(element.get());
+ scene_->AddUiElement(std::move(element));
+
+ // Place an invisible but hittable plane behind the content quad, to keep the
+ // reticle roughly planar with the content if near content.
+ element = base::MakeUnique<UiElement>();
+ element->id = AllocateId();
+ element->fill = vr_shell::Fill::NONE;
+ element->size = {kBackplaneSize, kBackplaneSize, 1.0};
+ element->translation = {0.0, 0.0, -kTextureOffset};
+ element->parent_id = main_content_->id;
+ browser_ui_elements_.push_back(element.get());
scene_->AddUiElement(std::move(element));
+
+ // Limit reticle distance to a sphere based on content distance.
+ scene_->SetBackgroundDistance(main_content_->translation.z() *
+ -kBackgroundDistanceMultiplier);
}
-UiSceneManager::~UiSceneManager() {}
+void UiSceneManager::CreateBackground() {
+ std::unique_ptr<UiElement> element;
+
+ // Floor.
+ element = base::MakeUnique<UiElement>();
+ element->id = AllocateId();
+ element->size = {kSceneSize, kSceneSize, 1.0};
+ element->translation = {0.0, -kSceneHeight / 2, 0.0};
+ element->rotation = {1.0, 0.0, 0.0, -M_PI / 2.0};
+ element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
+ element->edge_color = kBackgroundHorizonColor;
+ element->center_color = kBackgroundCenterColor;
+ element->draw_phase = 0;
+ browser_ui_elements_.push_back(element.get());
+ scene_->AddUiElement(std::move(element));
+
+ // Ceiling.
+ element = base::MakeUnique<UiElement>();
+ element->id = AllocateId();
+ element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
+ element->size = {kSceneSize, kSceneSize, 1.0};
+ element->translation = {0.0, kSceneHeight / 2, 0.0};
+ element->rotation = {1.0, 0.0, 0.0, M_PI / 2};
+ element->fill = vr_shell::Fill::OPAQUE_GRADIENT;
+ element->edge_color = kBackgroundHorizonColor;
+ element->center_color = kBackgroundCenterColor;
+ element->draw_phase = 0;
+ browser_ui_elements_.push_back(element.get());
+ scene_->AddUiElement(std::move(element));
+
+ // Floor grid.
+ element = base::MakeUnique<UiElement>();
+ element->id = AllocateId();
+ element->fill = vr_shell::Fill::GRID_GRADIENT;
+ element->size = {kSceneSize, kSceneSize, 1.0};
+ element->translation = {0.0, -kSceneHeight / 2 + kTextureOffset, 0.0};
+ element->rotation = {1.0, 0.0, 0.0, -M_PI / 2};
+ element->fill = vr_shell::Fill::GRID_GRADIENT;
+ element->center_color = kBackgroundHorizonColor;
+ vr::Colorf edge_color = kBackgroundHorizonColor;
+ edge_color.a = 0.0;
+ element->edge_color = edge_color;
+ element->gridline_count = kFloorGridlineCount;
+ element->draw_phase = 0;
+ browser_ui_elements_.push_back(element.get());
+ scene_->AddUiElement(std::move(element));
+
+ scene_->SetBackgroundColor(kBackgroundHorizonColor);
+}
base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
@@ -91,7 +170,12 @@ base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() {
void UiSceneManager::SetWebVRMode(bool web_vr) {
web_vr_mode_ = web_vr;
- main_content_->visible = !web_vr_mode_;
+
+ // Make all VR scene UI elements visible if not in WebVR.
+ for (UiElement* element : browser_ui_elements_) {
+ element->visible = !web_vr_mode_;
+ }
+
ConfigureSecurityWarnings();
}
@@ -117,4 +201,8 @@ void UiSceneManager::OnSecurityWarningTimer() {
transient_security_warning_->visible = false;
}
+int UiSceneManager::AllocateId() {
+ return next_available_id_++;
+}
+
} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698