| 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> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| 11 #include "ash/common/wallpaper/wallpaper_controller_observer.h" | 11 #include "ash/common/wallpaper/wallpaper_controller_observer.h" |
| 12 #include "ash/common/wallpaper/wallpaper_delegate.h" | 12 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 13 #include "ash/common/wallpaper/wallpaper_view.h" | 13 #include "ash/common/wallpaper/wallpaper_view.h" |
| 14 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 14 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
| 15 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 16 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
| 17 #include "ash/public/cpp/shell_window_ids.h" | 17 #include "ash/public/cpp/shell_window_ids.h" |
| 18 #include "ash/root_window_controller.h" | 18 #include "ash/root_window_controller.h" |
| 19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 20 #include "base/bind.h" | 20 #include "base/bind.h" |
| 21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/task_runner.h" | 23 #include "base/task_runner.h" |
| 24 #include "components/wallpaper/wallpaper_color_cache.h" |
| 24 #include "components/wallpaper/wallpaper_color_calculator.h" | 25 #include "components/wallpaper/wallpaper_color_calculator.h" |
| 25 #include "components/wallpaper/wallpaper_resizer.h" | 26 #include "components/wallpaper/wallpaper_resizer.h" |
| 26 #include "ui/display/manager/managed_display_info.h" | 27 #include "ui/display/manager/managed_display_info.h" |
| 27 #include "ui/display/screen.h" | 28 #include "ui/display/screen.h" |
| 28 #include "ui/gfx/color_analysis.h" | 29 #include "ui/gfx/color_analysis.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 64 else if (switch_value.find("muted") != std::string::npos) | 65 else if (switch_value.find("muted") != std::string::npos) |
| 65 *saturation = color_utils::SaturationRange::MUTED; | 66 *saturation = color_utils::SaturationRange::MUTED; |
| 66 | 67 |
| 67 return true; | 68 return true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 WallpaperController::WallpaperController( | 71 WallpaperController::WallpaperController( |
| 71 const scoped_refptr<base::TaskRunner>& task_runner) | 72 const scoped_refptr<base::TaskRunner>& task_runner) |
| 72 : locked_(false), | 73 : locked_(false), |
| 73 wallpaper_mode_(WALLPAPER_NONE), | 74 wallpaper_mode_(WALLPAPER_NONE), |
| 75 color_cache_(nullptr), |
| 74 prominent_color_(SK_ColorTRANSPARENT), | 76 prominent_color_(SK_ColorTRANSPARENT), |
| 75 wallpaper_reload_delay_(kWallpaperReloadDelayMs), | 77 wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
| 76 task_runner_(task_runner) { | 78 task_runner_(task_runner) { |
| 77 WmShell::Get()->AddDisplayObserver(this); | 79 WmShell::Get()->AddDisplayObserver(this); |
| 78 Shell::GetInstance()->AddShellObserver(this); | 80 Shell::GetInstance()->AddShellObserver(this); |
| 79 } | 81 } |
| 80 | 82 |
| 81 WallpaperController::~WallpaperController() { | 83 WallpaperController::~WallpaperController() { |
| 82 if (current_wallpaper_) | 84 if (current_wallpaper_) |
| 83 current_wallpaper_->RemoveObserver(this); | 85 current_wallpaper_->RemoveObserver(this); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 current_wallpaper_->original_image_id(); | 240 current_wallpaper_->original_image_id(); |
| 239 } | 241 } |
| 240 | 242 |
| 241 void WallpaperController::OpenSetWallpaperPage() { | 243 void WallpaperController::OpenSetWallpaperPage() { |
| 242 if (wallpaper_picker_ && | 244 if (wallpaper_picker_ && |
| 243 Shell::Get()->wallpaper_delegate()->CanOpenSetWallpaperPage()) { | 245 Shell::Get()->wallpaper_delegate()->CanOpenSetWallpaperPage()) { |
| 244 wallpaper_picker_->Open(); | 246 wallpaper_picker_->Open(); |
| 245 } | 247 } |
| 246 } | 248 } |
| 247 | 249 |
| 250 void WallpaperController::SetWallpaperColorCache( |
| 251 wallpaper::WallpaperColorCache* color_cache) { |
| 252 CHECK(!color_cache_); |
| 253 color_cache_ = color_cache; |
| 254 } |
| 255 |
| 248 void WallpaperController::SetWallpaperPicker(mojom::WallpaperPickerPtr picker) { | 256 void WallpaperController::SetWallpaperPicker(mojom::WallpaperPickerPtr picker) { |
| 249 wallpaper_picker_ = std::move(picker); | 257 wallpaper_picker_ = std::move(picker); |
| 250 } | 258 } |
| 251 | 259 |
| 252 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, | 260 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, |
| 253 wallpaper::WallpaperLayout layout) { | 261 wallpaper::WallpaperLayout layout) { |
| 254 if (wallpaper.isNull()) | 262 if (wallpaper.isNull()) |
| 255 return; | 263 return; |
| 256 | 264 |
| 257 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); | 265 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); |
| 258 } | 266 } |
| 259 | 267 |
| 260 void WallpaperController::OnWallpaperResized() { | 268 void WallpaperController::OnWallpaperResized() { |
| 261 CalculateWallpaperColors(); | 269 CalculateWallpaperColors(); |
| 262 } | 270 } |
| 263 | 271 |
| 264 void WallpaperController::OnColorCalculationComplete() { | 272 void WallpaperController::OnColorCalculationComplete() { |
| 265 const SkColor color = color_calculator_->prominent_color(); | 273 const SkColor color = color_calculator_->prominent_color(); |
| 274 |
| 275 if (color_cache_) { |
| 276 // TODO(bruthig): GetWallpaperOriginalImageId() is insufficient!! |
| 277 color_cache_->SetColor(GetWallpaperOriginalImageId(), color); |
| 278 } |
| 279 |
| 266 color_calculator_.reset(); | 280 color_calculator_.reset(); |
| 267 SetProminentColor(color); | 281 SetProminentColor(color); |
| 268 } | 282 } |
| 269 | 283 |
| 270 void WallpaperController::InstallDesktopController(WmWindow* root_window) { | 284 void WallpaperController::InstallDesktopController(WmWindow* root_window) { |
| 271 WallpaperWidgetController* component = nullptr; | 285 WallpaperWidgetController* component = nullptr; |
| 272 int container_id = GetWallpaperContainerId(locked_); | 286 int container_id = GetWallpaperContainerId(locked_); |
| 273 | 287 |
| 274 switch (wallpaper_mode_) { | 288 switch (wallpaper_mode_) { |
| 275 case WALLPAPER_IMAGE: { | 289 case WALLPAPER_IMAGE: { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 360 |
| 347 void WallpaperController::CalculateWallpaperColors() { | 361 void WallpaperController::CalculateWallpaperColors() { |
| 348 color_utils::LumaRange luma; | 362 color_utils::LumaRange luma; |
| 349 color_utils::SaturationRange saturation; | 363 color_utils::SaturationRange saturation; |
| 350 if (!GetProminentColorProfile(&luma, &saturation)) | 364 if (!GetProminentColorProfile(&luma, &saturation)) |
| 351 return; | 365 return; |
| 352 | 366 |
| 353 if (color_calculator_) | 367 if (color_calculator_) |
| 354 color_calculator_->RemoveObserver(this); | 368 color_calculator_->RemoveObserver(this); |
| 355 | 369 |
| 370 color_calculator_.reset(); |
| 371 |
| 372 if (color_cache_) { |
| 373 SkColor color; |
| 374 // TODO(bruthig): GetWallpaperOriginalImageId() is insufficient!! |
| 375 if (color_cache_->GetColor(GetWallpaperOriginalImageId(), &color)) { |
| 376 SetProminentColor(color); |
| 377 return; |
| 378 } |
| 379 } |
| 380 |
| 356 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( | 381 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( |
| 357 GetWallpaper(), luma, saturation, task_runner_); | 382 GetWallpaper(), luma, saturation, task_runner_); |
| 358 color_calculator_->AddObserver(this); | 383 color_calculator_->AddObserver(this); |
| 359 if (!color_calculator_->StartCalculation()) | 384 if (!color_calculator_->StartCalculation()) |
| 360 SetProminentColor(SK_ColorTRANSPARENT); | 385 SetProminentColor(SK_ColorTRANSPARENT); |
| 361 } | 386 } |
| 362 | 387 |
| 363 } // namespace ash | 388 } // namespace ash |
| OLD | NEW |