Index: ash/wallpaper/wallpaper_controller.cc |
diff --git a/ash/wallpaper/wallpaper_controller.cc b/ash/wallpaper/wallpaper_controller.cc |
index aac1a52c36ce6a24c9b6494dd6d0103b84b6ca73..b09efee24ae236b4168ee1786b0f46ab8e182a94 100644 |
--- a/ash/wallpaper/wallpaper_controller.cc |
+++ b/ash/wallpaper/wallpaper_controller.cc |
@@ -28,8 +28,13 @@ |
#include "ui/display/manager/managed_display_info.h" |
#include "ui/display/screen.h" |
#include "ui/gfx/color_analysis.h" |
+#include "ui/gfx/image/image_skia.h" |
#include "ui/views/widget/widget.h" |
+using color_utils::ColorProfile; |
+using color_utils::LumaRange; |
+using color_utils::SaturationRange; |
+ |
namespace ash { |
namespace { |
@@ -64,42 +69,32 @@ bool IsShelfColoringEnabled() { |
return switch_value == switches::kAshShelfColorEnabled; |
} |
-// Returns the |luma| and |saturation| output parameters based on the |
-// kAshShelfColorScheme command line arg. |
-void GetProminentColorProfile(color_utils::LumaRange* luma, |
- color_utils::SaturationRange* saturation) { |
- const std::string switch_value = |
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
- switches::kAshShelfColorScheme); |
- |
- *luma = color_utils::LumaRange::DARK; |
- *saturation = color_utils::SaturationRange::MUTED; |
- |
- if (switch_value.find("light") != std::string::npos) |
- *luma = color_utils::LumaRange::LIGHT; |
- else if (switch_value.find("normal") != std::string::npos) |
- *luma = color_utils::LumaRange::NORMAL; |
- else if (switch_value.find("dark") != std::string::npos) |
- *luma = color_utils::LumaRange::DARK; |
- |
- if (switch_value.find("vibrant") != std::string::npos) |
- *saturation = color_utils::SaturationRange::VIBRANT; |
- else if (switch_value.find("muted") != std::string::npos) |
- *saturation = color_utils::SaturationRange::MUTED; |
+// Gets the color profiles for extracting wallpaper prominent colors. |
+std::vector<ColorProfile> GetProminentColorProfiles() { |
+ return {ColorProfile(LumaRange::DARK, SaturationRange::VIBRANT), |
+ ColorProfile(LumaRange::NORMAL, SaturationRange::VIBRANT), |
+ ColorProfile(LumaRange::LIGHT, SaturationRange::VIBRANT), |
+ ColorProfile(LumaRange::DARK, SaturationRange::MUTED), |
+ ColorProfile(LumaRange::NORMAL, SaturationRange::MUTED), |
+ ColorProfile(LumaRange::LIGHT, SaturationRange::MUTED)}; |
} |
} // namespace |
+const SkColor WallpaperController::kInvalidColor = SK_ColorTRANSPARENT; |
+ |
WallpaperController::WallpaperController() |
: locked_(false), |
wallpaper_mode_(WALLPAPER_NONE), |
- prominent_color_(kInvalidColor), |
+ color_profiles_(GetProminentColorProfiles()), |
wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
{base::TaskPriority::USER_VISIBLE, |
// Don't need to finish resize or color extraction during shutdown. |
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), |
scoped_session_observer_(this) { |
+ prominent_colors_ = |
+ std::vector<SkColor>(color_profiles_.size(), kInvalidColor); |
Shell::Get()->window_tree_host_manager()->AddObserver(this); |
Shell::Get()->AddShellObserver(this); |
} |
@@ -139,6 +134,31 @@ void WallpaperController::RemoveObserver( |
observers_.RemoveObserver(observer); |
} |
+WallpaperController::ColorProfileIndex |
+WallpaperController::GetColorProfileIndex(ColorProfile color_profile) const { |
+ if (color_profile.saturation == SaturationRange::VIBRANT) { |
+ switch (color_profile.luma) { |
+ case LumaRange::DARK: |
+ return COLOR_PROFILE_INDEX_DARK_VIBRANT; |
+ case LumaRange::NORMAL: |
+ return COLOR_PROFILE_INDEX_NORMAL_VIBRANT; |
+ case LumaRange::LIGHT: |
+ return COLOR_PROFILE_INDEX_LIGHT_VIBRANT; |
+ } |
+ } else { |
+ switch (color_profile.luma) { |
+ case LumaRange::DARK: |
+ return COLOR_PROFILE_INDEX_DARK_MUTED; |
+ case LumaRange::NORMAL: |
+ return COLOR_PROFILE_INDEX_NORMAL_MUTED; |
+ case LumaRange::LIGHT: |
+ return COLOR_PROFILE_INDEX_LIGHT_MUTED; |
+ } |
+ } |
+ NOTREACHED(); |
+ return COLOR_PROFILE_INDEX_DARK_MUTED; |
+} |
+ |
wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { |
if (current_wallpaper_) |
return current_wallpaper_->layout(); |
@@ -168,7 +188,8 @@ void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, |
} |
void WallpaperController::CreateEmptyWallpaper() { |
- SetProminentColor(kInvalidColor); |
+ SetProminentColors( |
+ std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
current_wallpaper_.reset(); |
wallpaper_mode_ = WALLPAPER_IMAGE; |
InstallDesktopControllerForAllWindows(); |
@@ -288,9 +309,9 @@ void WallpaperController::OnWallpaperResized() { |
} |
void WallpaperController::OnColorCalculationComplete() { |
- const SkColor color = color_calculator_->prominent_color(); |
+ const std::vector<SkColor> colors = color_calculator_->prominent_colors(); |
color_calculator_.reset(); |
- SetProminentColor(color); |
+ SetProminentColors(colors); |
} |
void WallpaperController::InstallDesktopController(aura::Window* root_window) { |
@@ -360,11 +381,12 @@ void WallpaperController::UpdateWallpaper(bool clear_cache) { |
Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); |
} |
-void WallpaperController::SetProminentColor(SkColor color) { |
- if (prominent_color_ == color) |
+void WallpaperController::SetProminentColors( |
+ const std::vector<SkColor>& colors) { |
+ if (prominent_colors_ == colors) |
return; |
- prominent_color_ = color; |
+ prominent_colors_ = colors; |
for (auto& observer : observers_) |
observer.OnWallpaperColorsChanged(); |
} |
@@ -376,19 +398,18 @@ void WallpaperController::CalculateWallpaperColors() { |
} |
if (!ShouldCalculateColors()) { |
- SetProminentColor(kInvalidColor); |
+ SetProminentColors( |
+ std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
return; |
} |
- color_utils::LumaRange luma; |
- color_utils::SaturationRange saturation; |
- GetProminentColorProfile(&luma, &saturation); |
- |
color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( |
- GetWallpaper(), luma, saturation, sequenced_task_runner_); |
+ GetWallpaper(), color_profiles_, sequenced_task_runner_); |
color_calculator_->AddObserver(this); |
- if (!color_calculator_->StartCalculation()) |
- SetProminentColor(kInvalidColor); |
+ if (!color_calculator_->StartCalculation()) { |
+ SetProminentColors( |
+ std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
+ } |
} |
bool WallpaperController::ShouldCalculateColors() const { |