Commit e60c60a2 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

dark mode: Overview wallpaper to work in light mode.

ShouldApplyDimming was skipped in clamshell mode; instead overview
itself would set opacity filter. This patch enables ShouldApplyDimming
(now ShouldApplyColorFilter) for overview clamshell mode and mixes the
shield layer color, which has opacity built in for both tablet and
clamshell mode to match new spec.

I also noticed we always blend with kDarken. So on real dark wallpapers,
light mode black text will still be an issue. But I did notify UX and
I think that is an overall wallpaper issue.

With this change, WallpaperProperty opacity is now always 1.f, so we
can remove WallpaperProperty in a follow up as it only contains blur
now.

Test: manual
Bug: 1145342
Change-Id: Iea321602f577aa848722c6bb665a3de49aff129f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521852
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMin Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825117}
parent 59b34035
......@@ -16,17 +16,25 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_utils.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace ash {
namespace {
// The value used for alpha to apply a dark filter to the wallpaper in tablet
// mode. A higher number up to 255 results in a darker wallpaper.
// The value used for alpha to apply a color filter to the wallpaper in tablet
// mode. A higher number up to 255 results the color filter being more
// prominent.
constexpr int kTabletModeWallpaperAlpha = 102;
// Returns the color used to dim the wallpaper.
SkColor GetWallpaperDarkenColor() {
// Gets the color filter based on the state. This is used for the login, lock,
// overview and tablet mode.
SkColor GetWallpaperFilterColor() {
if (Shell::Get()->overview_controller()->InOverviewSession()) {
return AshColorProvider::Get()->GetShieldLayerColor(
AshColorProvider::ShieldLayerType::kShield40);
}
SkColor darken_color =
Shell::Get()->wallpaper_controller()->GetProminentColor(
color_utils::ColorProfile(color_utils::LumaRange::DARK,
......@@ -42,24 +50,14 @@ SkColor GetWallpaperDarkenColor() {
login_constants::kTranslucentColorDarkenAlpha),
SkColorSetA(darken_color, 0xFF));
int alpha = login_constants::kTranslucentAlpha;
if (Shell::Get()->tablet_mode_controller()->InTabletMode()) {
alpha = kTabletModeWallpaperAlpha;
} else if (Shell::Get()->overview_controller()->InOverviewSession()) {
// Overview mode will apply its own brightness filter on a downscaled image,
// so color with full opacity here.
alpha = 255;
}
const int alpha = Shell::Get()->tablet_mode_controller()->InTabletMode()
? kTabletModeWallpaperAlpha
: login_constants::kTranslucentAlpha;
return SkColorSetA(darken_color, alpha);
}
} // namespace
const char* WallpaperBaseView::GetClassName() const {
return "WallpaperBaseView";
}
void WallpaperBaseView::OnPaint(gfx::Canvas* canvas) {
// Scale the image while maintaining the aspect ratio, cropping as necessary
// to fill the wallpaper. Ideally the image should be larger than the largest
......@@ -77,9 +75,9 @@ void WallpaperBaseView::OnPaint(gfx::Canvas* canvas) {
return;
cc::PaintFlags flags;
if (controller->ShouldApplyDimming()) {
if (controller->ShouldApplyColorFilter()) {
flags.setColorFilter(
SkColorFilters::Blend(GetWallpaperDarkenColor(), SkBlendMode::kDarken));
SkColorFilters::Blend(GetWallpaperFilterColor(), SkBlendMode::kDarken));
}
switch (layout) {
......@@ -149,4 +147,7 @@ void WallpaperBaseView::DrawWallpaper(const gfx::ImageSkia& wallpaper,
/*filter=*/true, flags);
}
BEGIN_METADATA(WallpaperBaseView, views::View)
END_METADATA
} // namespace ash
......@@ -5,7 +5,6 @@
#ifndef ASH_WALLPAPER_WALLPAPER_BASE_VIEW_H_
#define ASH_WALLPAPER_WALLPAPER_BASE_VIEW_H_
#include "base/macros.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/views/view.h"
......@@ -18,7 +17,11 @@ namespace ash {
// wallpaper without any extra effects.
class WallpaperBaseView : public views::View {
public:
METADATA_HEADER(WallpaperBaseView);
WallpaperBaseView() = default;
WallpaperBaseView(const WallpaperBaseView&) = delete;
WallpaperBaseView& operator=(const WallpaperBaseView&) = delete;
~WallpaperBaseView() override = default;
void set_centered_layout_image_scale(const gfx::Vector2dF& value) {
......@@ -26,7 +29,6 @@ class WallpaperBaseView : public views::View {
}
// views::View:
const char* GetClassName() const override;
void OnPaint(gfx::Canvas* canvas) override;
protected:
......@@ -44,8 +46,6 @@ class WallpaperBaseView : public views::View {
// down by the same factor by which we scale down the desk in the its
// mini_view.
gfx::Vector2dF centered_layout_image_scale_ = gfx::Vector2dF(1.0f, 1.0f);
DISALLOW_COPY_AND_ASSIGN(WallpaperBaseView);
};
} // namespace ash
......
......@@ -746,11 +746,12 @@ void WallpaperControllerImpl::RestoreWallpaperPropertyForLockState(
observer.OnWallpaperBlurChanged();
}
bool WallpaperControllerImpl::ShouldApplyDimming() const {
// Dim the wallpaper in a blocked user session or in tablet mode unless during
// wallpaper preview.
bool WallpaperControllerImpl::ShouldApplyColorFilter() const {
// Apply a color filter on the wallpaper in a blocked user session or overview
// or in tablet mode unless during wallpaper preview.
const bool should_dim =
Shell::Get()->session_controller()->IsUserSessionBlocked() ||
Shell::Get()->overview_controller()->InOverviewSession() ||
(Shell::Get()->tablet_mode_controller()->InTabletMode() &&
!confirm_preview_wallpaper_callback_);
return should_dim && !IsOneShotWallpaper();
......@@ -1077,8 +1078,8 @@ void WallpaperControllerImpl::ConfirmPreviewWallpaper() {
std::move(confirm_preview_wallpaper_callback_).Run();
reload_preview_wallpaper_callback_.Reset();
// Ensure dimming is applied after confirming the preview wallpaper.
if (ShouldApplyDimming())
// Ensure color filter is applied after confirming the preview wallpaper.
if (ShouldApplyColorFilter())
RepaintWallpaper();
for (auto& observer : observers_)
......
......@@ -172,8 +172,9 @@ class ASH_EXPORT WallpaperControllerImpl
// Restores the wallpaper property from lock state.
void RestoreWallpaperPropertyForLockState(const WallpaperProperty& property);
// Wallpaper should be dimmed for login, lock, OOBE and add user screens.
bool ShouldApplyDimming() const;
// A color filter should be applied on the wallpaper for overview, login,
// lock, OOBE and add user screens.
bool ShouldApplyColorFilter() const;
// Returns whether the current wallpaper is allowed to be blurred on
// lock/login screen. See https://crbug.com/775591.
......
......@@ -2610,7 +2610,7 @@ TEST_F(WallpaperControllerTest, ShowOneShotWallpaper) {
EXPECT_EQ(kOneShotWallpaperColor, GetWallpaperColor());
EXPECT_EQ(WallpaperType::ONE_SHOT, controller_->GetWallpaperType());
EXPECT_FALSE(controller_->IsBlurAllowedForLockState());
EXPECT_FALSE(controller_->ShouldApplyDimming());
EXPECT_FALSE(controller_->ShouldApplyColorFilter());
// Verify that we can reload wallpaer without losing it.
// This is important for screen rotation.
......@@ -2620,7 +2620,7 @@ TEST_F(WallpaperControllerTest, ShowOneShotWallpaper) {
EXPECT_EQ(kOneShotWallpaperColor, GetWallpaperColor());
EXPECT_EQ(WallpaperType::ONE_SHOT, controller_->GetWallpaperType());
EXPECT_FALSE(controller_->IsBlurAllowedForLockState());
EXPECT_FALSE(controller_->ShouldApplyDimming());
EXPECT_FALSE(controller_->ShouldApplyColorFilter());
// Verify the user wallpaper info is unaffected, and the one-shot wallpaper
// can be replaced by the user wallpaper.
......
......@@ -159,8 +159,8 @@ void WallpaperView::DrawWallpaper(const gfx::ImageSkia& wallpaper,
cc::FilterOperations operations;
// In tablet mode, the wallpaper already has a color filter applied in
// |OnPaint| so we don't need to darken here.
// TODO(crbug.com/944152): Merge this with the color filter in
// WallpaperBaseView.
// TODO(crbug.com/944152): Opacity is always 1.f now. Remove this and
// WallpaperProperty which now only contains blur.
if (!Shell::Get()->tablet_mode_controller()->InTabletMode()) {
operations.Append(
cc::FilterOperation::CreateBrightnessFilter(property_.opacity));
......
......@@ -31,7 +31,7 @@ constexpr float kExtremeWindowRatioThreshold = 2.f;
namespace overview_constants {
// The opacity of the wallpaper in overview mode.
constexpr float kOpacity = 0.4f;
constexpr float kOpacity = 1.0f;
// Amount of blur to apply on the wallpaper when we enter or exit overview
// mode.
......
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