Commit 466a3396 authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

VR: Compose scene background color from UI elements.

Use a box of six panels in lieu of a GL background color. The floor and
ceiling are now additional elements, drawn later, because they are
selecxtively enabled and disabled based on mode.

Other assorted cleanup along the way.

BUG=

Change-Id: Idbd5ad8188659bb5720ffa75c7e919ae5a2de469
Reviewed-on: https://chromium-review.googlesource.com/581850
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488799}
parent 4428e271
......@@ -323,7 +323,7 @@ class UiElement : public cc::AnimationTarget {
int gridline_count_ = 1;
int draw_phase_ = 1;
int draw_phase_ = -1;
// This is the time as of the last call to |Animate|. It is needed when
// reversing transitions.
......
......@@ -32,6 +32,12 @@ enum UiElementDebugId {
kExclusiveScreenToast,
kSplashScreenIcon,
kBluetoothConnectedIndicator,
kBackgroundFront,
kBackgroundLeft,
kBackgroundBack,
kBackgroundRight,
kBackgroundTop,
kBackgroundBottom,
};
} // namespace vr
......
......@@ -29,14 +29,14 @@ void UiSceneManagerTest::MakeAutoPresentedManager() {
browser_.get(), scene_.get(), kNotInCct, kNotInWebVr, kAutopresented);
}
bool UiSceneManagerTest::IsVisible(UiElementDebugId debug_id) {
bool UiSceneManagerTest::IsVisible(UiElementDebugId debug_id) const {
UiElement* element = scene_->GetUiElementByDebugId(debug_id);
return element ? element->visible() : false;
}
void UiSceneManagerTest::VerifyElementsVisible(
const std::string& debug_name,
const std::set<UiElementDebugId>& debug_ids) {
const std::set<UiElementDebugId>& debug_ids) const {
SCOPED_TRACE(debug_name);
for (const auto& element : scene_->GetUiElements()) {
SCOPED_TRACE(element->debug_id());
......@@ -48,7 +48,7 @@ void UiSceneManagerTest::VerifyElementsVisible(
bool UiSceneManagerTest::VerifyVisibility(
const std::set<UiElementDebugId>& debug_ids,
bool visible) {
bool visible) const {
for (const auto& element : scene_->GetUiElements()) {
if (debug_ids.find(element->debug_id()) != debug_ids.end() &&
element->visible() != visible) {
......@@ -69,7 +69,7 @@ void UiSceneManagerTest::AnimateBy(base::TimeDelta delta) {
}
bool UiSceneManagerTest::IsAnimating(UiElement* element,
const std::vector<int>& properties) {
const std::vector<int>& properties) const {
for (auto property : properties) {
if (!element->animation_player().IsAnimatingProperty(property))
return false;
......@@ -77,4 +77,27 @@ bool UiSceneManagerTest::IsAnimating(UiElement* element,
return true;
}
SkColor UiSceneManagerTest::GetBackgroundColor() const {
UiElement* front = scene_->GetUiElementByDebugId(kBackgroundFront);
EXPECT_NE(nullptr, front);
if (!front)
return SK_ColorBLACK;
SkColor color = front->edge_color();
// While returning background color, ensure that all background panel elements
// share the same color.
for (auto debug_id : {kBackgroundFront, kBackgroundLeft, kBackgroundBack,
kBackgroundRight, kBackgroundTop, kBackgroundBottom}) {
const UiElement* panel = scene_->GetUiElementByDebugId(debug_id);
EXPECT_NE(nullptr, panel);
if (!panel)
return SK_ColorBLACK;
EXPECT_EQ(panel->center_color(), color);
EXPECT_EQ(panel->edge_color(), color);
}
return color;
}
} // namespace vr
......@@ -12,6 +12,7 @@
#include "chrome/browser/vr/elements/ui_element_debug_id.h"
#include "chrome/browser/vr/test/mock_browser_interface.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
namespace vr {
......@@ -44,23 +45,27 @@ class UiSceneManagerTest : public testing::Test {
void MakeManager(InCct in_cct, InWebVr in_web_vr);
void MakeAutoPresentedManager();
bool IsVisible(UiElementDebugId debug_id);
bool IsVisible(UiElementDebugId debug_id) const;
// Verify that only the elements in the set are visible.
void VerifyElementsVisible(const std::string& debug_name,
const std::set<UiElementDebugId>& debug_ids);
const std::set<UiElementDebugId>& debug_ids) const;
// Return false if not all elements in the set match the specified visibility
// state. Other elements are ignored.
bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids,
bool visible);
bool visible) const;
// Advances current_time_ by delta. This is done in frame increments and
// UiScene::OnBeginFrame is called at each increment.
void AnimateBy(base::TimeDelta delta);
// Returns true if the given properties are being animated by the element.
bool IsAnimating(UiElement* element, const std::vector<int>& properties);
bool IsAnimating(UiElement* element,
const std::vector<int>& properties) const;
SkColor GetBackgroundColor() const;
base::MessageLoop message_loop_;
std::unique_ptr<MockBrowserInterface> browser_;
......
......@@ -96,6 +96,7 @@ TEST_F(UiInputManagerTest, NoMouseMovesDuringClick) {
&out_target_point, &out_reticle_render_target);
// We should have hit the content quad if our math was correct.
ASSERT_NE(nullptr, out_reticle_render_target);
EXPECT_EQ(UiElementDebugId::kContentQuad,
out_reticle_render_target->debug_id());
......
......@@ -79,17 +79,14 @@ void UiRenderer::DrawWorldElements(const RenderInfo& render_info,
// mode, this will need further testing if those get added
// later.
} else {
// Non-WebVR mode, enable depth testing and clear the primary buffers.
// Non-WebVR mode, enable depth testing and clear the primary buffers. Note
// also that we do not clear the color buffer. The scene's background
// elements are responsible for drawing a complete background.
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
const SkColor backgroundColor = scene_->background_color();
glClearColor(SkColorGetR(backgroundColor) / 255.0,
SkColorGetG(backgroundColor) / 255.0,
SkColorGetB(backgroundColor) / 255.0,
SkColorGetA(backgroundColor) / 255.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
}
std::vector<const UiElement*> elements = scene_->GetWorldElements();
DrawUiView(render_info, controller_info, elements,
......@@ -141,13 +138,13 @@ void UiRenderer::DrawElements(const gfx::Transform& view_proj_matrix,
if (elements.empty()) {
return;
}
int initial_draw_phase = elements.front()->draw_phase();
bool drawn_reticle = false;
for (const auto* element : elements) {
// If we have no element to draw the reticle on, draw it after the
// background (the initial draw phase).
if (!controller_info.reticle_render_target && draw_reticle &&
!drawn_reticle && element->draw_phase() > initial_draw_phase) {
!drawn_reticle &&
element->draw_phase() >= scene_->first_foreground_draw_phase()) {
DrawReticle(view_proj_matrix, render_info, controller_info);
drawn_reticle = true;
}
......@@ -164,6 +161,7 @@ void UiRenderer::DrawElements(const gfx::Transform& view_proj_matrix,
void UiRenderer::DrawElement(const gfx::Transform& view_proj_matrix,
const UiElement& element,
const gfx::Size& content_texture_size) {
DCHECK_GE(element.draw_phase(), 0);
gfx::Transform transform =
view_proj_matrix * element.screen_space_transform();
......
......@@ -87,6 +87,12 @@ class UiScene {
void set_reticle_rendering_enabled(bool enabled) {
reticle_rendering_enabled_ = enabled;
}
int first_foreground_draw_phase() const {
return first_foreground_draw_phase_;
}
void set_first_foreground_draw_phase(int phase) {
first_foreground_draw_phase_ = phase;
}
void OnGLInitialized();
......@@ -103,6 +109,7 @@ class UiScene {
bool webvr_rendering_enabled_ = false;
bool reticle_rendering_enabled_ = true;
bool gl_initialized_ = false;
int first_foreground_draw_phase_ = 0;
DISALLOW_COPY_AND_ASSIGN(UiScene);
};
......
This diff is collapsed.
......@@ -144,8 +144,8 @@ class UiSceneManager {
int next_available_id_ = 1;
std::vector<UiElement*> background_panels_;
std::vector<UiElement*> content_elements_;
std::vector<UiElement*> background_elements_;
std::vector<UiElement*> control_elements_;
base::WeakPtrFactory<UiSceneManager> weak_ptr_factory_;
......
......@@ -25,10 +25,20 @@ using TargetProperty::VISIBILITY;
using TargetProperty::OPACITY;
namespace {
std::set<UiElementDebugId> kBackgroundElements = {
kBackgroundFront, kBackgroundLeft, kBackgroundBack,
kBackgroundRight, kBackgroundTop, kBackgroundBottom};
std::set<UiElementDebugId> kFloorCeilingBackgroundElements = {
kBackgroundFront, kBackgroundLeft, kBackgroundBack, kBackgroundRight,
kBackgroundTop, kBackgroundBottom, kCeiling, kFloor};
std::set<UiElementDebugId> kElementsVisibleInBrowsing = {
kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar};
kBackgroundFront, kBackgroundLeft, kBackgroundBack, kBackgroundRight,
kBackgroundTop, kBackgroundBottom, kCeiling, kFloor,
kContentQuad, kBackplane, kUrlBar};
std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = {
kExitPrompt, kExitPromptBackplane, kCeiling, kFloor};
kBackgroundFront, kBackgroundLeft, kBackgroundBack, kBackgroundRight,
kBackgroundTop, kBackgroundBottom, kCeiling, kFloor,
kExitPrompt, kExitPromptBackplane};
} // namespace
TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) {
......@@ -168,55 +178,33 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) {
MakeManager(kNotInCct, kNotInWebVr);
// Hold onto the background color to make sure it changes.
SkColor initial_background = scene_->background_color();
SkColor initial_background = GetBackgroundColor();
manager_->SetFullscreen(true);
{
SCOPED_TRACE("Entered Fullsceen");
// Make sure background has changed for fullscreen.
EXPECT_NE(initial_background, scene_->background_color());
}
// Make sure background has changed for fullscreen.
EXPECT_NE(initial_background, GetBackgroundColor());
SkColor fullscreen_background = scene_->background_color();
SkColor fullscreen_background = GetBackgroundColor();
manager_->SetIncognito(true);
{
SCOPED_TRACE("Entered Incognito");
// Make sure background has changed for incognito.
EXPECT_NE(fullscreen_background, scene_->background_color());
EXPECT_NE(initial_background, scene_->background_color());
}
// Make sure background has changed for incognito.
EXPECT_NE(fullscreen_background, GetBackgroundColor());
EXPECT_NE(initial_background, GetBackgroundColor());
SkColor incognito_background = scene_->background_color();
SkColor incognito_background = GetBackgroundColor();
manager_->SetIncognito(false);
{
SCOPED_TRACE("Exited Incognito");
EXPECT_EQ(fullscreen_background, scene_->background_color());
}
EXPECT_EQ(fullscreen_background, GetBackgroundColor());
manager_->SetFullscreen(false);
{
SCOPED_TRACE("Exited Fullsceen");
EXPECT_EQ(initial_background, scene_->background_color());
}
EXPECT_EQ(initial_background, GetBackgroundColor());
manager_->SetIncognito(true);
{
SCOPED_TRACE("Entered Incognito");
EXPECT_EQ(incognito_background, scene_->background_color());
}
EXPECT_EQ(incognito_background, GetBackgroundColor());
manager_->SetIncognito(false);
{
SCOPED_TRACE("Exited Incognito");
EXPECT_EQ(initial_background, scene_->background_color());
}
EXPECT_EQ(initial_background, GetBackgroundColor());
}
TEST_F(UiSceneManagerTest, WebVrAutopresentedInsecureOrigin) {
......@@ -227,8 +215,10 @@ TEST_F(UiSceneManagerTest, WebVrAutopresentedInsecureOrigin) {
manager_->SetWebVrMode(true, false);
// Initially, the security warnings should not be visible since the first
// WebVR frame is not received.
VerifyElementsVisible("Initial",
std::set<UiElementDebugId>{kSplashScreenIcon});
auto initial_elements = kBackgroundElements;
initial_elements.insert(kSplashScreenIcon);
VerifyElementsVisible("Initial", initial_elements);
manager_->OnWebVrFrameAvailable();
VerifyElementsVisible("Autopresented", std::set<UiElementDebugId>{
kWebVrPermanentHttpSecurityWarning,
......@@ -254,8 +244,9 @@ TEST_F(UiSceneManagerTest, WebVrAutopresented) {
manager_->SetWebVrSecureOrigin(true);
// Initially, we should only show the splash screen.
VerifyElementsVisible("Initial",
std::set<UiElementDebugId>{kSplashScreenIcon});
auto initial_elements = kBackgroundElements;
initial_elements.insert(kSplashScreenIcon);
VerifyElementsVisible("Initial", initial_elements);
// Enter WebVR with autopresentation.
manager_->SetWebVrMode(true, false);
......@@ -275,15 +266,16 @@ TEST_F(UiSceneManagerTest, WebVrAutopresented) {
}
TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
std::set<UiElementDebugId> visible_in_fullscreen = {
kContentQuad, kCloseButton, kBackplane,
kCeiling, kFloor, kExclusiveScreenToast,
};
auto visible_in_fullscreen = kFloorCeilingBackgroundElements;
visible_in_fullscreen.insert(kContentQuad);
visible_in_fullscreen.insert(kBackplane);
visible_in_fullscreen.insert(kCloseButton);
visible_in_fullscreen.insert(kExclusiveScreenToast);
MakeManager(kNotInCct, kNotInWebVr);
// Hold onto the background color to make sure it changes.
SkColor initial_background = scene_->background_color();
SkColor initial_background = GetBackgroundColor();
VerifyElementsVisible("Initial", kElementsVisibleInBrowsing);
UiElement* content_quad = scene_->GetUiElementByDebugId(kContentQuad);
gfx::SizeF initial_content_size = content_quad->size();
......@@ -295,7 +287,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
manager_->SetFullscreen(true);
VerifyElementsVisible("In fullscreen", visible_in_fullscreen);
// Make sure background has changed for fullscreen.
EXPECT_NE(initial_background, scene_->background_color());
EXPECT_NE(initial_background, GetBackgroundColor());
// Should have started transition.
EXPECT_TRUE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
// Finish the transition.
......@@ -307,7 +299,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
// Everything should return to original state after leaving fullscreen.
manager_->SetFullscreen(false);
VerifyElementsVisible("Restore initial", kElementsVisibleInBrowsing);
EXPECT_EQ(initial_background, scene_->background_color());
EXPECT_EQ(initial_background, GetBackgroundColor());
// Should have started transition.
EXPECT_TRUE(IsAnimating(content_quad, {TRANSFORM, BOUNDS}));
// Finish the transition.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment