Chromium Code Reviews| 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/common/wallpaper/wallpaper_controller.h" | 5 #include "ash/common/wallpaper/wallpaper_controller.h" |
| 6 | 6 |
| 7 #include <string> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "ash/common/ash_switches.h" | |
| 7 #include "ash/common/wallpaper/wallpaper_controller_observer.h" | 11 #include "ash/common/wallpaper/wallpaper_controller_observer.h" |
| 8 #include "ash/common/wallpaper/wallpaper_delegate.h" | 12 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 9 #include "ash/common/wallpaper/wallpaper_view.h" | 13 #include "ash/common/wallpaper/wallpaper_view.h" |
| 10 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 14 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
| 11 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 17 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/root_window_controller.h" | 18 #include "ash/root_window_controller.h" |
| 15 #include "base/bind.h" | 19 #include "base/bind.h" |
| 20 #include "base/command_line.h" | |
| 16 #include "base/logging.h" | 21 #include "base/logging.h" |
| 17 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
| 23 #include "components/wallpaper/wallpaper_color_calculator.h" | |
| 18 #include "components/wallpaper/wallpaper_resizer.h" | 24 #include "components/wallpaper/wallpaper_resizer.h" |
| 19 #include "ui/display/manager/managed_display_info.h" | 25 #include "ui/display/manager/managed_display_info.h" |
| 20 #include "ui/display/screen.h" | 26 #include "ui/display/screen.h" |
| 27 #include "ui/gfx/color_analysis.h" | |
| 21 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 22 | 29 |
| 23 namespace ash { | 30 namespace ash { |
| 31 | |
| 24 namespace { | 32 namespace { |
| 25 | 33 |
| 26 // How long to wait reloading the wallpaper after the display size has changed. | 34 // How long to wait reloading the wallpaper after the display size has changed. |
| 27 const int kWallpaperReloadDelayMs = 100; | 35 const int kWallpaperReloadDelayMs = 100; |
| 28 | 36 |
| 29 } // namespace | 37 } // namespace |
| 30 | 38 |
| 39 // static | |
| 40 bool WallpaperController::GetProminentColorProfile( | |
| 41 color_utils::LumaRange* luma, | |
| 42 color_utils::SaturationRange* saturation) { | |
| 43 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 44 ash::switches::kAshShelfColor)) { | |
|
bshe
2017/02/24 18:30:36
nit: ash:: namespace is not necessary for this.
bruthig
2017/02/25 17:51:18
Done.
| |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 *luma = color_utils::LumaRange::NORMAL; | |
| 49 *saturation = color_utils::SaturationRange::VIBRANT; | |
| 50 | |
| 51 const std::string switch_value = | |
| 52 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 53 ash::switches::kAshShelfColor); | |
|
bshe
2017/02/24 18:30:36
ditto
bruthig
2017/02/25 17:51:18
Done.
| |
| 54 if (switch_value.find("light") != std::string::npos) | |
| 55 *luma = color_utils::LumaRange::LIGHT; | |
| 56 else if (switch_value.find("normal") != std::string::npos) | |
| 57 *luma = color_utils::LumaRange::NORMAL; | |
| 58 else if (switch_value.find("dark") != std::string::npos) | |
| 59 *luma = color_utils::LumaRange::DARK; | |
| 60 | |
| 61 if (switch_value.find("vibrant") != std::string::npos) | |
| 62 *saturation = color_utils::SaturationRange::VIBRANT; | |
| 63 else if (switch_value.find("muted") != std::string::npos) | |
| 64 *saturation = color_utils::SaturationRange::MUTED; | |
| 65 | |
| 66 return true; | |
| 67 } | |
| 68 | |
| 31 WallpaperController::WallpaperController( | 69 WallpaperController::WallpaperController( |
| 32 const scoped_refptr<base::TaskRunner>& task_runner) | 70 const scoped_refptr<base::TaskRunner>& task_runner) |
| 33 : locked_(false), | 71 : locked_(false), |
| 34 wallpaper_mode_(WALLPAPER_NONE), | 72 wallpaper_mode_(WALLPAPER_NONE), |
| 73 prominent_color_(SK_ColorTRANSPARENT), | |
| 35 wallpaper_reload_delay_(kWallpaperReloadDelayMs), | 74 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
| 36 task_runner_(task_runner) { | 75 task_runner_(task_runner) { |
| 37 WmShell::Get()->AddDisplayObserver(this); | 76 WmShell::Get()->AddDisplayObserver(this); |
| 38 WmShell::Get()->AddShellObserver(this); | 77 WmShell::Get()->AddShellObserver(this); |
| 39 } | 78 } |
| 40 | 79 |
| 41 WallpaperController::~WallpaperController() { | 80 WallpaperController::~WallpaperController() { |
| 81 if (current_wallpaper_) | |
| 82 current_wallpaper_->RemoveObserver(this); | |
| 83 if (color_calculator_) | |
| 84 color_calculator_->RemoveObserver(this); | |
| 42 WmShell::Get()->RemoveDisplayObserver(this); | 85 WmShell::Get()->RemoveDisplayObserver(this); |
| 43 WmShell::Get()->RemoveShellObserver(this); | 86 WmShell::Get()->RemoveShellObserver(this); |
| 44 } | 87 } |
| 45 | 88 |
| 46 void WallpaperController::BindRequest( | 89 void WallpaperController::BindRequest( |
| 47 mojom::WallpaperControllerRequest request) { | 90 mojom::WallpaperControllerRequest request) { |
| 48 bindings_.AddBinding(this, std::move(request)); | 91 bindings_.AddBinding(this, std::move(request)); |
| 49 } | 92 } |
| 50 | 93 |
| 51 gfx::ImageSkia WallpaperController::GetWallpaper() const { | 94 gfx::ImageSkia WallpaperController::GetWallpaper() const { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 75 << wallpaper::WallpaperResizer::GetImageId(image) | 118 << wallpaper::WallpaperResizer::GetImageId(image) |
| 76 << " layout=" << layout; | 119 << " layout=" << layout; |
| 77 | 120 |
| 78 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { | 121 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { |
| 79 VLOG(1) << "Wallpaper is already loaded"; | 122 VLOG(1) << "Wallpaper is already loaded"; |
| 80 return; | 123 return; |
| 81 } | 124 } |
| 82 | 125 |
| 83 current_wallpaper_.reset(new wallpaper::WallpaperResizer( | 126 current_wallpaper_.reset(new wallpaper::WallpaperResizer( |
| 84 image, GetMaxDisplaySizeInNative(), layout, task_runner_)); | 127 image, GetMaxDisplaySizeInNative(), layout, task_runner_)); |
| 128 current_wallpaper_->AddObserver(this); | |
| 85 current_wallpaper_->StartResize(); | 129 current_wallpaper_->StartResize(); |
| 86 | 130 |
| 87 for (auto& observer : observers_) | 131 for (auto& observer : observers_) |
| 88 observer.OnWallpaperDataChanged(); | 132 observer.OnWallpaperDataChanged(); |
| 89 wallpaper_mode_ = WALLPAPER_IMAGE; | 133 wallpaper_mode_ = WALLPAPER_IMAGE; |
| 90 InstallDesktopControllerForAllWindows(); | 134 InstallDesktopControllerForAllWindows(); |
| 91 } | 135 } |
| 92 | 136 |
| 93 void WallpaperController::CreateEmptyWallpaper() { | 137 void WallpaperController::CreateEmptyWallpaper() { |
| 138 SetProminentColor(SK_ColorTRANSPARENT); | |
| 94 current_wallpaper_.reset(); | 139 current_wallpaper_.reset(); |
| 95 wallpaper_mode_ = WALLPAPER_IMAGE; | 140 wallpaper_mode_ = WALLPAPER_IMAGE; |
| 96 InstallDesktopControllerForAllWindows(); | 141 InstallDesktopControllerForAllWindows(); |
| 97 } | 142 } |
| 98 | 143 |
| 99 bool WallpaperController::MoveToLockedContainer() { | 144 bool WallpaperController::MoveToLockedContainer() { |
| 100 if (locked_) | 145 if (locked_) |
| 101 return false; | 146 return false; |
| 102 locked_ = true; | 147 locked_ = true; |
| 103 return ReparentWallpaper(GetWallpaperContainerId(true)); | 148 return ReparentWallpaper(GetWallpaperContainerId(true)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 243 } |
| 199 | 244 |
| 200 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, | 245 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, |
| 201 wallpaper::WallpaperLayout layout) { | 246 wallpaper::WallpaperLayout layout) { |
| 202 if (wallpaper.isNull()) | 247 if (wallpaper.isNull()) |
| 203 return; | 248 return; |
| 204 | 249 |
| 205 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); | 250 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); |
| 206 } | 251 } |
| 207 | 252 |
| 253 void WallpaperController::OnWallpaperResized() { | |
| 254 CalculateWallpaperColors(); | |
| 255 } | |
| 256 | |
| 257 void WallpaperController::OnColorCalculationComplete() { | |
| 258 const SkColor color = color_calculator_->prominent_color(); | |
| 259 color_calculator_.reset(); | |
| 260 SetProminentColor(color); | |
| 261 } | |
| 262 | |
| 208 void WallpaperController::InstallDesktopController(WmWindow* root_window) { | 263 void WallpaperController::InstallDesktopController(WmWindow* root_window) { |
| 209 WallpaperWidgetController* component = nullptr; | 264 WallpaperWidgetController* component = nullptr; |
| 210 int container_id = GetWallpaperContainerId(locked_); | 265 int container_id = GetWallpaperContainerId(locked_); |
| 211 | 266 |
| 212 switch (wallpaper_mode_) { | 267 switch (wallpaper_mode_) { |
| 213 case WALLPAPER_IMAGE: { | 268 case WALLPAPER_IMAGE: { |
| 214 component = new WallpaperWidgetController( | 269 component = new WallpaperWidgetController( |
| 215 CreateWallpaper(root_window, container_id)); | 270 CreateWallpaper(root_window, container_id)); |
| 216 break; | 271 break; |
| 217 } | 272 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 int WallpaperController::GetWallpaperContainerId(bool locked) { | 321 int WallpaperController::GetWallpaperContainerId(bool locked) { |
| 267 return locked ? kShellWindowId_LockScreenWallpaperContainer | 322 return locked ? kShellWindowId_LockScreenWallpaperContainer |
| 268 : kShellWindowId_WallpaperContainer; | 323 : kShellWindowId_WallpaperContainer; |
| 269 } | 324 } |
| 270 | 325 |
| 271 void WallpaperController::UpdateWallpaper(bool clear_cache) { | 326 void WallpaperController::UpdateWallpaper(bool clear_cache) { |
| 272 current_wallpaper_.reset(); | 327 current_wallpaper_.reset(); |
| 273 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); | 328 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); |
| 274 } | 329 } |
| 275 | 330 |
| 331 void WallpaperController::SetProminentColor(SkColor color) { | |
| 332 if (prominent_color_ == color) | |
| 333 return; | |
| 334 | |
| 335 prominent_color_ = color; | |
| 336 for (auto& observer : observers_) | |
| 337 observer.OnWallpaperColorsChanged(); | |
| 338 } | |
| 339 | |
| 340 void WallpaperController::CalculateWallpaperColors() { | |
| 341 color_utils::LumaRange luma; | |
| 342 color_utils::SaturationRange saturation; | |
| 343 if (!GetProminentColorProfile(&luma, &saturation)) | |
| 344 return; | |
| 345 | |
| 346 if (color_calculator_) | |
| 347 color_calculator_->RemoveObserver(this); | |
| 348 | |
| 349 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( | |
| 350 GetWallpaper(), luma, saturation, task_runner_); | |
| 351 color_calculator_->AddObserver(this); | |
| 352 if (!color_calculator_->StartCalculation()) | |
| 353 SetProminentColor(SK_ColorTRANSPARENT); | |
| 354 } | |
| 355 | |
| 276 } // namespace ash | 356 } // namespace ash |
| OLD | NEW |