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