Chromium Code Reviews| 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" |
| 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 | 14 |
| 15 namespace vr_shell { | 15 namespace vr_shell { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 static constexpr int kWarningTimeoutSeconds = 30; | 19 static constexpr int kWarningTimeoutSeconds = 30; |
| 20 static constexpr float kWarningDistance = 0.7; | 20 static constexpr float kWarningDistance = 0.7; |
| 21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; | 21 static constexpr float kWarningAngleRadians = 16.3 * M_PI / 180.0; |
| 22 | 22 |
| 23 static constexpr float kBackplaneSize = 1000.0; | |
|
amp
2017/04/27 17:28:53
As long as you are changing things here want to me
cjgrant
2017/04/27 18:50:20
I would have said yes, but your CL is now in the C
amp
2017/04/27 18:54:27
Indeed, thanks Michael!
It was small enough I did
| |
| 24 static constexpr float kBackgroundDistanceMultiplier = 1.414; | |
| 25 | |
| 26 static constexpr float kSceneSize = 25.0; | |
| 27 static constexpr float kSceneHeight = 4.0; | |
| 28 static constexpr int kFloorGridlineCount = 40; | |
| 29 static constexpr vr::Colorf kBackgroundHorizonColor = {0.57, 0.57, 0.57, 1.0}; | |
| 30 static constexpr vr::Colorf kBackgroundCenterColor = {0.48, 0.48, 0.48, 1.0}; | |
| 31 | |
| 32 // Tiny distance to offset textures that should appear in the same plane. | |
| 33 static constexpr float kTextureOffset = 0.01; | |
| 34 | |
| 23 } // namespace | 35 } // namespace |
| 24 | 36 |
| 25 UiSceneManager::UiSceneManager(UiScene* scene) | 37 UiSceneManager::UiSceneManager(UiScene* scene) |
| 26 : scene_(scene), weak_ptr_factory_(this) { | 38 : scene_(scene), weak_ptr_factory_(this) { |
| 27 std::unique_ptr<UiElement> element; | 39 std::unique_ptr<UiElement> element; |
| 28 | 40 |
| 29 // For now, use an ID range that does not conflict with the HTML UI. | 41 int id = 0; |
| 30 int id = 1000; | |
| 31 | 42 |
| 32 // Permanent WebVR security warning. | |
| 33 // TODO(mthiesse): Programatically compute the proper texture size for these | 43 // TODO(mthiesse): Programatically compute the proper texture size for these |
| 34 // textured UI elements. | 44 // textured UI elements. |
| 35 element = base::MakeUnique<PermanentSecurityWarning>(512); | 45 element = base::MakeUnique<PermanentSecurityWarning>(512); |
| 46 element->name = "Permanent security warning"; | |
|
mthiesse
2017/04/27 15:47:11
Hmm. Is there an easy way to make these element na
cjgrant
2017/04/27 18:50:19
Agreed on no strings. I don't know of any fancine
cjgrant
2017/04/27 21:28:33
Done.
| |
| 36 element->id = id++; | 47 element->id = id++; |
| 37 element->name = "Permanent security warning"; | |
| 38 element->fill = vr_shell::Fill::NONE; | 48 element->fill = vr_shell::Fill::NONE; |
| 39 element->size = {0.226f, 0.078f, 1}; | 49 element->size = {0.226f, 0.078f, 1}; |
| 40 element->scale = {kWarningDistance, kWarningDistance, 1}; | 50 element->scale = {kWarningDistance, kWarningDistance, 1}; |
| 41 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), | 51 element->translation = {0, kWarningDistance * sin(kWarningAngleRadians), |
| 42 -kWarningDistance * cos(kWarningAngleRadians)}; | 52 -kWarningDistance * cos(kWarningAngleRadians)}; |
| 43 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; | 53 element->rotation = {1.0f, 0, 0, kWarningAngleRadians}; |
| 44 element->visible = false; | 54 element->visible = false; |
| 45 element->hit_testable = false; | 55 element->hit_testable = false; |
| 46 element->lock_to_fov = true; | 56 element->lock_to_fov = true; |
| 47 permanent_security_warning_ = element.get(); | 57 permanent_security_warning_ = element.get(); |
| 48 scene_->AddUiElement(std::move(element)); | 58 scene_->AddUiElement(std::move(element)); |
| 49 | 59 |
| 50 // Transient WebVR security warning. | |
| 51 element = base::MakeUnique<TransientSecurityWarning>(1024); | 60 element = base::MakeUnique<TransientSecurityWarning>(1024); |
| 61 element->name = "Transient security warning"; | |
| 52 element->id = id++; | 62 element->id = id++; |
| 53 element->name = "Transient security warning"; | |
| 54 element->fill = vr_shell::Fill::NONE; | 63 element->fill = vr_shell::Fill::NONE; |
| 55 element->size = {0.512f, 0.160f, 1}; | 64 element->size = {0.512f, 0.160f, 1}; |
| 56 element->scale = {kWarningDistance, kWarningDistance, 1}; | 65 element->scale = {kWarningDistance, kWarningDistance, 1}; |
| 57 element->translation = {0, 0, -kWarningDistance}; | 66 element->translation = {0, 0, -kWarningDistance}; |
| 58 element->visible = false; | 67 element->visible = false; |
| 59 element->hit_testable = false; | 68 element->hit_testable = false; |
| 60 element->lock_to_fov = true; | 69 element->lock_to_fov = true; |
| 61 transient_security_warning_ = element.get(); | 70 transient_security_warning_ = element.get(); |
| 62 scene_->AddUiElement(std::move(element)); | 71 scene_->AddUiElement(std::move(element)); |
| 63 | 72 |
| 64 // Main web content quad. | |
| 65 element = base::MakeUnique<UiElement>(); | 73 element = base::MakeUnique<UiElement>(); |
| 74 element->name = "Content"; | |
| 66 element->id = id++; | 75 element->id = id++; |
| 67 element->name = "Content"; | |
| 68 element->fill = vr_shell::Fill::CONTENT; | 76 element->fill = vr_shell::Fill::CONTENT; |
| 69 element->size = {2.4f, 1.6f, 1}; | 77 element->size = {2.4f, 1.6f, 1}; |
| 70 element->translation = {0, -0.1f, -2.5f}; | 78 element->translation = {0, -0.1f, -2.5f}; |
| 71 element->visible = false; | 79 element->visible = false; |
| 72 main_content_ = element.get(); | 80 main_content_ = element.get(); |
| 81 browser_ui_elements_.push_back(element.get()); | |
| 73 scene_->AddUiElement(std::move(element)); | 82 scene_->AddUiElement(std::move(element)); |
| 83 | |
| 84 // Place an invisible but hittable plane behind the content quad, to keep the | |
|
cjgrant
2017/04/27 15:11:14
Thoughts on this wall of initialization. I though
mthiesse
2017/04/27 15:47:11
I think member functions for each element creation
cjgrant
2017/04/27 18:50:19
Done. Let me know what you think...
| |
| 85 // reticle roughly planar with the content if near content. | |
| 86 element = base::MakeUnique<UiElement>(); | |
| 87 element->name = "Backplane"; | |
| 88 element->id = id++; | |
| 89 element->fill = vr_shell::Fill::NONE; | |
| 90 element->size = {kBackplaneSize, kBackplaneSize, 1.0}; | |
| 91 element->translation = {0.0, 0.0, -kTextureOffset}; | |
| 92 element->parent_id = main_content_->id; | |
| 93 browser_ui_elements_.push_back(element.get()); | |
| 94 scene_->AddUiElement(std::move(element)); | |
| 95 | |
| 96 element = base::MakeUnique<UiElement>(); | |
| 97 element->name = "Floor"; | |
| 98 element->id = id++; | |
| 99 element->size = {kSceneSize, kSceneSize, 1.0}; | |
| 100 element->translation = {0.0, -kSceneHeight / 2, 0.0}; | |
| 101 element->rotation = {1.0, 0.0, 0.0, -M_PI / 2.0}; | |
| 102 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 103 element->edge_color = kBackgroundHorizonColor; | |
| 104 element->center_color = kBackgroundCenterColor; | |
| 105 element->draw_phase = 0; | |
| 106 browser_ui_elements_.push_back(element.get()); | |
| 107 scene_->AddUiElement(std::move(element)); | |
| 108 | |
| 109 element = base::MakeUnique<UiElement>(); | |
| 110 element->name = "Ceiling"; | |
| 111 element->id = id++; | |
| 112 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 113 element->size = {kSceneSize, kSceneSize, 1.0}; | |
| 114 element->translation = {0.0, kSceneHeight / 2, 0.0}; | |
| 115 element->rotation = {1.0, 0.0, 0.0, M_PI / 2}; | |
| 116 element->fill = vr_shell::Fill::OPAQUE_GRADIENT; | |
| 117 element->edge_color = kBackgroundHorizonColor; | |
| 118 element->center_color = kBackgroundCenterColor; | |
| 119 element->draw_phase = 0; | |
| 120 browser_ui_elements_.push_back(element.get()); | |
| 121 scene_->AddUiElement(std::move(element)); | |
| 122 | |
| 123 element = base::MakeUnique<UiElement>(); | |
| 124 element->name = "Floor grid"; | |
| 125 element->id = id++; | |
| 126 element->fill = vr_shell::Fill::GRID_GRADIENT; | |
| 127 element->size = {kSceneSize, kSceneSize, 1.0}; | |
| 128 element->translation = {0.0, -kSceneHeight / 2 + kTextureOffset, 0.0}; | |
| 129 element->rotation = {1.0, 0.0, 0.0, -M_PI / 2}; | |
| 130 element->fill = vr_shell::Fill::GRID_GRADIENT; | |
| 131 element->center_color = kBackgroundHorizonColor; | |
| 132 vr::Colorf edge_color = kBackgroundHorizonColor; | |
| 133 edge_color.a = 0.0; | |
| 134 element->edge_color = edge_color; | |
| 135 element->gridline_count = kFloorGridlineCount; | |
| 136 element->draw_phase = 0; | |
| 137 browser_ui_elements_.push_back(element.get()); | |
| 138 scene_->AddUiElement(std::move(element)); | |
| 139 | |
| 140 scene_->SetBackgroundColor(kBackgroundHorizonColor); | |
| 141 | |
| 142 // Limit reticle distance to a sphere based on content distance. | |
| 143 scene_->SetBackgroundDistance(main_content_->translation.z() * | |
| 144 -kBackgroundDistanceMultiplier); | |
| 74 } | 145 } |
| 75 | 146 |
| 76 UiSceneManager::~UiSceneManager() {} | 147 UiSceneManager::~UiSceneManager() {} |
| 77 | 148 |
| 78 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { | 149 base::WeakPtr<UiSceneManager> UiSceneManager::GetWeakPtr() { |
| 79 return weak_ptr_factory_.GetWeakPtr(); | 150 return weak_ptr_factory_.GetWeakPtr(); |
| 80 } | 151 } |
| 81 | 152 |
| 82 void UiSceneManager::SetWebVRMode(bool web_vr) { | 153 void UiSceneManager::SetWebVRMode(bool web_vr) { |
| 83 web_vr_mode_ = web_vr; | 154 web_vr_mode_ = web_vr; |
| 84 main_content_->visible = !web_vr_mode_; | 155 |
| 156 // Make all VR scene UI elements visible if not in WebVR. | |
| 157 for (UiElement* element : browser_ui_elements_) { | |
| 158 element->visible = !web_vr_mode_; | |
| 159 } | |
| 160 | |
| 85 ConfigureSecurityWarnings(); | 161 ConfigureSecurityWarnings(); |
| 86 } | 162 } |
| 87 | 163 |
| 88 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { | 164 void UiSceneManager::SetWebVRSecureOrigin(bool secure) { |
| 89 secure_origin_ = secure; | 165 secure_origin_ = secure; |
| 90 ConfigureSecurityWarnings(); | 166 ConfigureSecurityWarnings(); |
| 91 } | 167 } |
| 92 | 168 |
| 93 void UiSceneManager::ConfigureSecurityWarnings() { | 169 void UiSceneManager::ConfigureSecurityWarnings() { |
| 94 bool enabled = web_vr_mode_ && !secure_origin_; | 170 bool enabled = web_vr_mode_ && !secure_origin_; |
| 95 permanent_security_warning_->visible = enabled; | 171 permanent_security_warning_->visible = enabled; |
| 96 transient_security_warning_->visible = enabled; | 172 transient_security_warning_->visible = enabled; |
| 97 if (enabled) { | 173 if (enabled) { |
| 98 security_warning_timer_.Start( | 174 security_warning_timer_.Start( |
| 99 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, | 175 FROM_HERE, base::TimeDelta::FromSeconds(kWarningTimeoutSeconds), this, |
| 100 &UiSceneManager::OnSecurityWarningTimer); | 176 &UiSceneManager::OnSecurityWarningTimer); |
| 101 } else { | 177 } else { |
| 102 security_warning_timer_.Stop(); | 178 security_warning_timer_.Stop(); |
| 103 } | 179 } |
| 104 } | 180 } |
| 105 | 181 |
| 106 void UiSceneManager::OnSecurityWarningTimer() { | 182 void UiSceneManager::OnSecurityWarningTimer() { |
| 107 transient_security_warning_->visible = false; | 183 transient_security_warning_->visible = false; |
| 108 } | 184 } |
| 109 | 185 |
| 110 } // namespace vr_shell | 186 } // namespace vr_shell |
| OLD | NEW |