Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: ash/wallpaper/wallpaper_controller.cc

Issue 2943333003: Extracting more than one wallpaper prominent color (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wallpaper/wallpaper_controller.cc
diff --git a/ash/wallpaper/wallpaper_controller.cc b/ash/wallpaper/wallpaper_controller.cc
index 58c7d32696597fe4a7e9b639e6ac4514afa5faaa..d805a71b64644735dc9cfdb8b328cfbc7404632d 100644
--- a/ash/wallpaper/wallpaper_controller.cc
+++ b/ash/wallpaper/wallpaper_controller.cc
@@ -30,6 +30,11 @@
#include "ui/gfx/color_analysis.h"
#include "ui/views/widget/widget.h"
+using color_utils::ColorProfile;
+using color_utils::ColorProfiles;
+using color_utils::LumaRange;
+using color_utils::SaturationRange;
+
namespace ash {
namespace {
@@ -64,42 +69,56 @@ 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) {
+// Gets the color profiles for extracting wallpaper prominent colors.
+ColorProfiles 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)};
+}
+
+// Returns color profile used for shelf based on the kAshShelfColorScheme
+// command line arg.
+ColorProfile GetShelfProminentColorProfile() {
const std::string switch_value =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kAshShelfColorScheme);
- *luma = color_utils::LumaRange::DARK;
- *saturation = color_utils::SaturationRange::MUTED;
+ ColorProfile color_profile(LumaRange::DARK, SaturationRange::MUTED);
if (switch_value.find("light") != std::string::npos)
- *luma = color_utils::LumaRange::LIGHT;
+ color_profile.luma = LumaRange::LIGHT;
else if (switch_value.find("normal") != std::string::npos)
- *luma = color_utils::LumaRange::NORMAL;
+ color_profile.luma = LumaRange::NORMAL;
else if (switch_value.find("dark") != std::string::npos)
- *luma = color_utils::LumaRange::DARK;
+ color_profile.luma = LumaRange::DARK;
if (switch_value.find("vibrant") != std::string::npos)
- *saturation = color_utils::SaturationRange::VIBRANT;
+ color_profile.saturation = SaturationRange::VIBRANT;
else if (switch_value.find("muted") != std::string::npos)
- *saturation = color_utils::SaturationRange::MUTED;
+ color_profile.saturation = SaturationRange::MUTED;
+
+ return color_profile;
}
} // 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);
ShellPort::Get()->AddDisplayObserver(this);
Shell::Get()->AddShellObserver(this);
}
@@ -139,6 +158,11 @@ void WallpaperController::RemoveObserver(
observers_.RemoveObserver(observer);
}
+WallpaperController::ColorProfileIndex
+WallpaperController::GetShelfColorProfileIndex() const {
+ return GetColorProfileIndex(GetShelfProminentColorProfile());
+}
+
wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const {
if (current_wallpaper_)
return current_wallpaper_->layout();
@@ -168,7 +192,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 +313,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,15 +385,41 @@ 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();
}
+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;
+}
+
void WallpaperController::CalculateWallpaperColors() {
if (color_calculator_) {
color_calculator_->RemoveObserver(this);
@@ -376,19 +427,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 {

Powered by Google App Engine
This is Rietveld 408576698