OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wallpaper/wallpaper_controller.h" | 5 #include "ash/wallpaper/wallpaper_controller.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/sequenced_task_runner.h" | 24 #include "base/sequenced_task_runner.h" |
25 #include "base/task_scheduler/post_task.h" | 25 #include "base/task_scheduler/post_task.h" |
26 #include "components/wallpaper/wallpaper_color_calculator.h" | 26 #include "components/wallpaper/wallpaper_color_calculator.h" |
27 #include "components/wallpaper/wallpaper_resizer.h" | 27 #include "components/wallpaper/wallpaper_resizer.h" |
28 #include "ui/display/manager/managed_display_info.h" | 28 #include "ui/display/manager/managed_display_info.h" |
29 #include "ui/display/screen.h" | 29 #include "ui/display/screen.h" |
30 #include "ui/gfx/color_analysis.h" | 30 #include "ui/gfx/color_analysis.h" |
31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
32 | 32 |
| 33 using color_utils::ColorProfile; |
| 34 using color_utils::ColorProfiles; |
| 35 using color_utils::LumaRange; |
| 36 using color_utils::SaturationRange; |
| 37 |
33 namespace ash { | 38 namespace ash { |
34 | 39 |
35 namespace { | 40 namespace { |
36 | 41 |
37 // How long to wait reloading the wallpaper after the display size has changed. | 42 // How long to wait reloading the wallpaper after the display size has changed. |
38 constexpr int kWallpaperReloadDelayMs = 100; | 43 constexpr int kWallpaperReloadDelayMs = 100; |
39 | 44 |
40 // How long to wait for resizing of the the wallpaper. | 45 // How long to wait for resizing of the the wallpaper. |
41 constexpr int kCompositorLockTimeoutMs = 750; | 46 constexpr int kCompositorLockTimeoutMs = 750; |
42 | 47 |
(...skipping 14 matching lines...) Expand all Loading... |
57 switch_value != switches::kAshShelfColorDisabled) { | 62 switch_value != switches::kAshShelfColorDisabled) { |
58 LOG(WARNING) << "Invalid '--" << switches::kAshShelfColor << "' value of '" | 63 LOG(WARNING) << "Invalid '--" << switches::kAshShelfColor << "' value of '" |
59 << switch_value << "'. Defaulting to " | 64 << switch_value << "'. Defaulting to " |
60 << (kDefaultValue ? "enabled." : "disabled."); | 65 << (kDefaultValue ? "enabled." : "disabled."); |
61 return kDefaultValue; | 66 return kDefaultValue; |
62 } | 67 } |
63 | 68 |
64 return switch_value == switches::kAshShelfColorEnabled; | 69 return switch_value == switches::kAshShelfColorEnabled; |
65 } | 70 } |
66 | 71 |
67 // Returns the |luma| and |saturation| output parameters based on the | 72 // Gets the color profiles for extracting wallpaper prominent colors. |
68 // kAshShelfColorScheme command line arg. | 73 ColorProfiles GetProminentColorProfiles() { |
69 void GetProminentColorProfile(color_utils::LumaRange* luma, | 74 return {ColorProfile(LumaRange::DARK, SaturationRange::VIBRANT), |
70 color_utils::SaturationRange* saturation) { | 75 ColorProfile(LumaRange::NORMAL, SaturationRange::VIBRANT), |
| 76 ColorProfile(LumaRange::LIGHT, SaturationRange::VIBRANT), |
| 77 ColorProfile(LumaRange::DARK, SaturationRange::MUTED), |
| 78 ColorProfile(LumaRange::NORMAL, SaturationRange::MUTED), |
| 79 ColorProfile(LumaRange::LIGHT, SaturationRange::MUTED)}; |
| 80 } |
| 81 |
| 82 // Returns color profile used for shelf based on the kAshShelfColorScheme |
| 83 // command line arg. |
| 84 ColorProfile GetShelfProminentColorProfile() { |
71 const std::string switch_value = | 85 const std::string switch_value = |
72 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 86 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
73 switches::kAshShelfColorScheme); | 87 switches::kAshShelfColorScheme); |
74 | 88 |
75 *luma = color_utils::LumaRange::DARK; | 89 ColorProfile color_profile(LumaRange::DARK, SaturationRange::MUTED); |
76 *saturation = color_utils::SaturationRange::MUTED; | |
77 | 90 |
78 if (switch_value.find("light") != std::string::npos) | 91 if (switch_value.find("light") != std::string::npos) |
79 *luma = color_utils::LumaRange::LIGHT; | 92 color_profile.luma = LumaRange::LIGHT; |
80 else if (switch_value.find("normal") != std::string::npos) | 93 else if (switch_value.find("normal") != std::string::npos) |
81 *luma = color_utils::LumaRange::NORMAL; | 94 color_profile.luma = LumaRange::NORMAL; |
82 else if (switch_value.find("dark") != std::string::npos) | 95 else if (switch_value.find("dark") != std::string::npos) |
83 *luma = color_utils::LumaRange::DARK; | 96 color_profile.luma = LumaRange::DARK; |
84 | 97 |
85 if (switch_value.find("vibrant") != std::string::npos) | 98 if (switch_value.find("vibrant") != std::string::npos) |
86 *saturation = color_utils::SaturationRange::VIBRANT; | 99 color_profile.saturation = SaturationRange::VIBRANT; |
87 else if (switch_value.find("muted") != std::string::npos) | 100 else if (switch_value.find("muted") != std::string::npos) |
88 *saturation = color_utils::SaturationRange::MUTED; | 101 color_profile.saturation = SaturationRange::MUTED; |
| 102 |
| 103 return color_profile; |
89 } | 104 } |
90 | 105 |
91 } // namespace | 106 } // namespace |
92 | 107 |
| 108 const SkColor WallpaperController::kInvalidColor = SK_ColorTRANSPARENT; |
| 109 |
93 WallpaperController::WallpaperController() | 110 WallpaperController::WallpaperController() |
94 : locked_(false), | 111 : locked_(false), |
95 wallpaper_mode_(WALLPAPER_NONE), | 112 wallpaper_mode_(WALLPAPER_NONE), |
96 prominent_color_(kInvalidColor), | 113 color_profiles_(GetProminentColorProfiles()), |
97 wallpaper_reload_delay_(kWallpaperReloadDelayMs), | 114 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
98 sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( | 115 sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( |
99 {base::TaskPriority::USER_VISIBLE, | 116 {base::TaskPriority::USER_VISIBLE, |
100 // Don't need to finish resize or color extraction during shutdown. | 117 // Don't need to finish resize or color extraction during shutdown. |
101 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), | 118 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), |
102 scoped_session_observer_(this) { | 119 scoped_session_observer_(this) { |
| 120 prominent_colors_ = |
| 121 std::vector<SkColor>(color_profiles_.size(), kInvalidColor); |
103 ShellPort::Get()->AddDisplayObserver(this); | 122 ShellPort::Get()->AddDisplayObserver(this); |
104 Shell::Get()->AddShellObserver(this); | 123 Shell::Get()->AddShellObserver(this); |
105 } | 124 } |
106 | 125 |
107 WallpaperController::~WallpaperController() { | 126 WallpaperController::~WallpaperController() { |
108 if (current_wallpaper_) | 127 if (current_wallpaper_) |
109 current_wallpaper_->RemoveObserver(this); | 128 current_wallpaper_->RemoveObserver(this); |
110 if (color_calculator_) | 129 if (color_calculator_) |
111 color_calculator_->RemoveObserver(this); | 130 color_calculator_->RemoveObserver(this); |
112 ShellPort::Get()->RemoveDisplayObserver(this); | 131 ShellPort::Get()->RemoveDisplayObserver(this); |
(...skipping 19 matching lines...) Expand all Loading... |
132 | 151 |
133 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { | 152 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { |
134 observers_.AddObserver(observer); | 153 observers_.AddObserver(observer); |
135 } | 154 } |
136 | 155 |
137 void WallpaperController::RemoveObserver( | 156 void WallpaperController::RemoveObserver( |
138 WallpaperControllerObserver* observer) { | 157 WallpaperControllerObserver* observer) { |
139 observers_.RemoveObserver(observer); | 158 observers_.RemoveObserver(observer); |
140 } | 159 } |
141 | 160 |
| 161 WallpaperController::ColorProfileIndex |
| 162 WallpaperController::GetShelfColorProfileIndex() const { |
| 163 return GetColorProfileIndex(GetShelfProminentColorProfile()); |
| 164 } |
| 165 |
142 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { | 166 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { |
143 if (current_wallpaper_) | 167 if (current_wallpaper_) |
144 return current_wallpaper_->layout(); | 168 return current_wallpaper_->layout(); |
145 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; | 169 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; |
146 } | 170 } |
147 | 171 |
148 void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, | 172 void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, |
149 wallpaper::WallpaperLayout layout) { | 173 wallpaper::WallpaperLayout layout) { |
150 VLOG(1) << "SetWallpaper: image_id=" | 174 VLOG(1) << "SetWallpaper: image_id=" |
151 << wallpaper::WallpaperResizer::GetImageId(image) | 175 << wallpaper::WallpaperResizer::GetImageId(image) |
152 << " layout=" << layout; | 176 << " layout=" << layout; |
153 | 177 |
154 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { | 178 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { |
155 VLOG(1) << "Wallpaper is already loaded"; | 179 VLOG(1) << "Wallpaper is already loaded"; |
156 return; | 180 return; |
157 } | 181 } |
158 | 182 |
159 current_wallpaper_.reset(new wallpaper::WallpaperResizer( | 183 current_wallpaper_.reset(new wallpaper::WallpaperResizer( |
160 image, GetMaxDisplaySizeInNative(), layout, sequenced_task_runner_)); | 184 image, GetMaxDisplaySizeInNative(), layout, sequenced_task_runner_)); |
161 current_wallpaper_->AddObserver(this); | 185 current_wallpaper_->AddObserver(this); |
162 current_wallpaper_->StartResize(); | 186 current_wallpaper_->StartResize(); |
163 | 187 |
164 for (auto& observer : observers_) | 188 for (auto& observer : observers_) |
165 observer.OnWallpaperDataChanged(); | 189 observer.OnWallpaperDataChanged(); |
166 wallpaper_mode_ = WALLPAPER_IMAGE; | 190 wallpaper_mode_ = WALLPAPER_IMAGE; |
167 InstallDesktopControllerForAllWindows(); | 191 InstallDesktopControllerForAllWindows(); |
168 } | 192 } |
169 | 193 |
170 void WallpaperController::CreateEmptyWallpaper() { | 194 void WallpaperController::CreateEmptyWallpaper() { |
171 SetProminentColor(kInvalidColor); | 195 SetProminentColors( |
| 196 std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
172 current_wallpaper_.reset(); | 197 current_wallpaper_.reset(); |
173 wallpaper_mode_ = WALLPAPER_IMAGE; | 198 wallpaper_mode_ = WALLPAPER_IMAGE; |
174 InstallDesktopControllerForAllWindows(); | 199 InstallDesktopControllerForAllWindows(); |
175 } | 200 } |
176 | 201 |
177 void WallpaperController::OnDisplayConfigurationChanged() { | 202 void WallpaperController::OnDisplayConfigurationChanged() { |
178 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); | 203 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
179 if (current_max_display_size_ != max_display_size) { | 204 if (current_max_display_size_ != max_display_size) { |
180 current_max_display_size_ = max_display_size; | 205 current_max_display_size_ = max_display_size; |
181 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) { | 206 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 306 |
282 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); | 307 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); |
283 } | 308 } |
284 | 309 |
285 void WallpaperController::OnWallpaperResized() { | 310 void WallpaperController::OnWallpaperResized() { |
286 CalculateWallpaperColors(); | 311 CalculateWallpaperColors(); |
287 compositor_lock_.reset(); | 312 compositor_lock_.reset(); |
288 } | 313 } |
289 | 314 |
290 void WallpaperController::OnColorCalculationComplete() { | 315 void WallpaperController::OnColorCalculationComplete() { |
291 const SkColor color = color_calculator_->prominent_color(); | 316 const std::vector<SkColor> colors = color_calculator_->prominent_colors(); |
292 color_calculator_.reset(); | 317 color_calculator_.reset(); |
293 SetProminentColor(color); | 318 SetProminentColors(colors); |
294 } | 319 } |
295 | 320 |
296 void WallpaperController::InstallDesktopController(aura::Window* root_window) { | 321 void WallpaperController::InstallDesktopController(aura::Window* root_window) { |
297 WallpaperWidgetController* component = nullptr; | 322 WallpaperWidgetController* component = nullptr; |
298 int container_id = GetWallpaperContainerId(locked_); | 323 int container_id = GetWallpaperContainerId(locked_); |
299 | 324 |
300 switch (wallpaper_mode_) { | 325 switch (wallpaper_mode_) { |
301 case WALLPAPER_IMAGE: { | 326 case WALLPAPER_IMAGE: { |
302 component = new WallpaperWidgetController( | 327 component = new WallpaperWidgetController( |
303 CreateWallpaper(root_window, container_id)); | 328 CreateWallpaper(root_window, container_id)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 int WallpaperController::GetWallpaperContainerId(bool locked) { | 378 int WallpaperController::GetWallpaperContainerId(bool locked) { |
354 return locked ? kShellWindowId_LockScreenWallpaperContainer | 379 return locked ? kShellWindowId_LockScreenWallpaperContainer |
355 : kShellWindowId_WallpaperContainer; | 380 : kShellWindowId_WallpaperContainer; |
356 } | 381 } |
357 | 382 |
358 void WallpaperController::UpdateWallpaper(bool clear_cache) { | 383 void WallpaperController::UpdateWallpaper(bool clear_cache) { |
359 current_wallpaper_.reset(); | 384 current_wallpaper_.reset(); |
360 Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); | 385 Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); |
361 } | 386 } |
362 | 387 |
363 void WallpaperController::SetProminentColor(SkColor color) { | 388 void WallpaperController::SetProminentColors( |
364 if (prominent_color_ == color) | 389 const std::vector<SkColor>& colors) { |
| 390 if (prominent_colors_ == colors) |
365 return; | 391 return; |
366 | 392 |
367 prominent_color_ = color; | 393 prominent_colors_ = colors; |
368 for (auto& observer : observers_) | 394 for (auto& observer : observers_) |
369 observer.OnWallpaperColorsChanged(); | 395 observer.OnWallpaperColorsChanged(); |
370 } | 396 } |
371 | 397 |
| 398 WallpaperController::ColorProfileIndex |
| 399 WallpaperController::GetColorProfileIndex(ColorProfile color_profile) const { |
| 400 if (color_profile.saturation == SaturationRange::VIBRANT) { |
| 401 switch (color_profile.luma) { |
| 402 case LumaRange::DARK: |
| 403 return COLOR_PROFILE_INDEX_DARK_VIBRANT; |
| 404 case LumaRange::NORMAL: |
| 405 return COLOR_PROFILE_INDEX_NORMAL_VIBRANT; |
| 406 case LumaRange::LIGHT: |
| 407 return COLOR_PROFILE_INDEX_LIGHT_VIBRANT; |
| 408 } |
| 409 } else { |
| 410 switch (color_profile.luma) { |
| 411 case LumaRange::DARK: |
| 412 return COLOR_PROFILE_INDEX_DARK_MUTED; |
| 413 case LumaRange::NORMAL: |
| 414 return COLOR_PROFILE_INDEX_NORMAL_MUTED; |
| 415 case LumaRange::LIGHT: |
| 416 return COLOR_PROFILE_INDEX_LIGHT_MUTED; |
| 417 } |
| 418 } |
| 419 NOTREACHED(); |
| 420 return COLOR_PROFILE_INDEX_DARK_MUTED; |
| 421 } |
| 422 |
372 void WallpaperController::CalculateWallpaperColors() { | 423 void WallpaperController::CalculateWallpaperColors() { |
373 if (color_calculator_) { | 424 if (color_calculator_) { |
374 color_calculator_->RemoveObserver(this); | 425 color_calculator_->RemoveObserver(this); |
375 color_calculator_.reset(); | 426 color_calculator_.reset(); |
376 } | 427 } |
377 | 428 |
378 if (!ShouldCalculateColors()) { | 429 if (!ShouldCalculateColors()) { |
379 SetProminentColor(kInvalidColor); | 430 SetProminentColors( |
| 431 std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
380 return; | 432 return; |
381 } | 433 } |
382 | 434 |
383 color_utils::LumaRange luma; | |
384 color_utils::SaturationRange saturation; | |
385 GetProminentColorProfile(&luma, &saturation); | |
386 | |
387 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( | 435 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( |
388 GetWallpaper(), luma, saturation, sequenced_task_runner_); | 436 GetWallpaper(), color_profiles_, sequenced_task_runner_); |
389 color_calculator_->AddObserver(this); | 437 color_calculator_->AddObserver(this); |
390 if (!color_calculator_->StartCalculation()) | 438 if (!color_calculator_->StartCalculation()) { |
391 SetProminentColor(kInvalidColor); | 439 SetProminentColors( |
| 440 std::vector<SkColor>(color_profiles_.size(), kInvalidColor)); |
| 441 } |
392 } | 442 } |
393 | 443 |
394 bool WallpaperController::ShouldCalculateColors() const { | 444 bool WallpaperController::ShouldCalculateColors() const { |
395 gfx::ImageSkia image = GetWallpaper(); | 445 gfx::ImageSkia image = GetWallpaper(); |
396 return IsShelfColoringEnabled() && | 446 return IsShelfColoringEnabled() && |
397 Shell::Get()->session_controller()->GetSessionState() == | 447 Shell::Get()->session_controller()->GetSessionState() == |
398 session_manager::SessionState::ACTIVE && | 448 session_manager::SessionState::ACTIVE && |
399 !image.isNull(); | 449 !image.isNull(); |
400 } | 450 } |
401 | 451 |
(...skipping 25 matching lines...) Expand all Loading... |
427 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); | 477 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); |
428 } | 478 } |
429 } | 479 } |
430 } | 480 } |
431 | 481 |
432 void WallpaperController::CompositorLockTimedOut() { | 482 void WallpaperController::CompositorLockTimedOut() { |
433 compositor_lock_.reset(); | 483 compositor_lock_.reset(); |
434 } | 484 } |
435 | 485 |
436 } // namespace ash | 486 } // namespace ash |
OLD | NEW |