Commit ae1733b5 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Add black layer on the back of wallpaper

Apply layer blur on the layer that has wallpaper, but not the widget
because the solid color is a part of widget's layer.

Bug: 1015886
Test: covered by unittest. Also tested manually with blur change reverted.
Change-Id: Iaf0f2faaa1e92285a3f8b45083027a7fccf0bc59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1885219Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710141}
parent 21f7b494
......@@ -40,7 +40,7 @@
namespace ash {
namespace {
const char kWallpaperView[] = "WallpaperView";
const char kWallpaperView[] = "WallpaperViewWidget";
class TestEventHandler : public ui::EventHandler {
public:
......
......@@ -50,7 +50,7 @@
namespace ash {
namespace {
const char kWallpaperView[] = "WallpaperView";
const char kWallpaperView[] = "WallpaperViewWidget";
template <typename T>
class Resetter {
......
......@@ -1913,11 +1913,23 @@ TEST_F(WallpaperControllerTest, WallpaperBlur) {
}
TEST_F(WallpaperControllerTest, WallpaperBlurDuringLockScreenTransition) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
gfx::ImageSkia image = CreateImage(600, 400, kWallpaperColor);
controller_->ShowWallpaperImage(
image, CreateWallpaperInfo(WALLPAPER_LAYOUT_CENTER),
/*preview_mode=*/false, /*always_on_top=*/false);
TestWallpaperControllerObserver observer(controller_);
ASSERT_TRUE(controller_->IsBlurAllowed());
ASSERT_FALSE(controller_->IsWallpaperBlurred());
ASSERT_EQ(1u, wallpaper_view()->layer()->parent()->children().size());
EXPECT_EQ(ui::LAYER_TEXTURED,
wallpaper_view()->layer()->parent()->children()[0]->type());
// Simulate lock and unlock sequence.
controller_->UpdateWallpaperBlur(true);
EXPECT_TRUE(controller_->IsWallpaperBlurred());
......@@ -1925,12 +1937,20 @@ TEST_F(WallpaperControllerTest, WallpaperBlurDuringLockScreenTransition) {
SetSessionState(SessionState::LOCKED);
EXPECT_TRUE(controller_->IsWallpaperBlurred());
ASSERT_EQ(2u, wallpaper_view()->layer()->parent()->children().size());
EXPECT_EQ(ui::LAYER_SOLID_COLOR,
wallpaper_view()->layer()->parent()->children()[0]->type());
EXPECT_EQ(ui::LAYER_TEXTURED,
wallpaper_view()->layer()->parent()->children()[1]->type());
// Change of state to ACTIVE triggers post lock animation and
// UpdateWallpaperBlur(false)
SetSessionState(SessionState::ACTIVE);
EXPECT_FALSE(controller_->IsWallpaperBlurred());
EXPECT_EQ(2, observer.blur_changed_count());
ASSERT_EQ(1u, wallpaper_view()->layer()->parent()->children().size());
EXPECT_EQ(ui::LAYER_TEXTURED,
wallpaper_view()->layer()->parent()->children()[0]->type());
}
TEST_F(WallpaperControllerTest, OnlyShowDevicePolicyWallpaperOnLoginScreen) {
......
......@@ -34,7 +34,14 @@ namespace {
// in the compositor.
class LayerControlView : public views::View {
public:
explicit LayerControlView(views::View* view) {
LayerControlView(views::View* view, bool needs_shield) {
if (needs_shield) {
auto* shield = new views::View();
AddChildView(shield);
shield->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
shield->layer()->SetColor(SK_ColorBLACK);
shield->layer()->set_name("WallpaperViewShield");
}
AddChildView(view);
view->SetPaintToLayer();
}
......@@ -51,14 +58,15 @@ class LayerControlView : public views::View {
display::ManagedDisplayInfo info =
Shell::Get()->display_manager()->GetDisplayInfo(display.id());
DCHECK_EQ(1u, children().size());
views::View* child = children().front();
child->SetBounds(0, 0, display.size().width(), display.size().height());
gfx::Transform transform;
// Apply RTL transform explicitly becacuse Views layer code
// doesn't handle RTL. crbug.com/458753.
transform.Translate(-child->GetMirroredX(), 0);
child->SetTransform(transform);
for (auto* child : children()) {
// views::View* child = children().front();
child->SetBounds(0, 0, display.size().width(), display.size().height());
gfx::Transform transform;
// Apply RTL transform explicitly becacuse Views layer code
// doesn't handle RTL. crbug.com/458753.
transform.Translate(-child->GetMirroredX(), 0);
child->SetTransform(transform);
}
}
private:
......@@ -179,14 +187,17 @@ views::Widget* CreateWallpaperWidget(aura::Window* root_window,
views::Widget* wallpaper_widget = new views::Widget;
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.name = "WallpaperView";
params.name = "WallpaperViewWidget";
params.layer_type = ui::LAYER_NOT_DRAWN;
if (controller->GetWallpaper().isNull())
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.parent = root_window->GetChildById(container_id);
wallpaper_widget->Init(std::move(params));
// Owned by views.
WallpaperView* wallpaper_view = new WallpaperView(blur, opacity);
wallpaper_widget->SetContentsView(new LayerControlView(wallpaper_view));
wallpaper_widget->SetContentsView(new LayerControlView(
wallpaper_view,
Shell::Get()->session_controller()->IsUserSessionBlocked()));
*out_wallpaper_view = wallpaper_view;
int animation_type =
controller->ShouldShowInitialAnimation()
......
......@@ -108,7 +108,8 @@ class WallpaperWidgetController::WidgetHandler
float blur_sigma() const { return widget_->GetLayer()->layer_blur(); }
void SetBlur(float blur_sigma) {
widget_->GetLayer()->SetLayerBlur(blur_sigma);
wallpaper_view_->layer()->SetLayerBlur(blur_sigma);
const bool old_has_blur_cache = has_blur_cache_;
has_blur_cache_ = blur_sigma > 0.0f;
if (!old_has_blur_cache && has_blur_cache_) {
......
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