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

Side by Side Diff: ash/wallpaper/wallpaper_controller.cc

Issue 2943333003: Extracting more than one wallpaper prominent color (Closed)
Patch Set: feedback from ps4 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 unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "base/bind.h" 21 #include "base/bind.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
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/gfx/image/image_skia.h"
31 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
32 33
34 using color_utils::ColorProfile;
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
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 std::vector<ColorProfile> 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),
71 const std::string switch_value = 76 ColorProfile(LumaRange::LIGHT, SaturationRange::VIBRANT),
72 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 77 ColorProfile(LumaRange::DARK, SaturationRange::MUTED),
73 switches::kAshShelfColorScheme); 78 ColorProfile(LumaRange::NORMAL, SaturationRange::MUTED),
74 79 ColorProfile(LumaRange::LIGHT, SaturationRange::MUTED)};
75 *luma = color_utils::LumaRange::DARK;
76 *saturation = color_utils::SaturationRange::MUTED;
77
78 if (switch_value.find("light") != std::string::npos)
79 *luma = color_utils::LumaRange::LIGHT;
80 else if (switch_value.find("normal") != std::string::npos)
81 *luma = color_utils::LumaRange::NORMAL;
82 else if (switch_value.find("dark") != std::string::npos)
83 *luma = color_utils::LumaRange::DARK;
84
85 if (switch_value.find("vibrant") != std::string::npos)
86 *saturation = color_utils::SaturationRange::VIBRANT;
87 else if (switch_value.find("muted") != std::string::npos)
88 *saturation = color_utils::SaturationRange::MUTED;
89 } 80 }
90 81
91 } // namespace 82 } // namespace
92 83
84 const SkColor WallpaperController::kInvalidColor = SK_ColorTRANSPARENT;
85
93 WallpaperController::WallpaperController() 86 WallpaperController::WallpaperController()
94 : locked_(false), 87 : locked_(false),
95 wallpaper_mode_(WALLPAPER_NONE), 88 wallpaper_mode_(WALLPAPER_NONE),
96 prominent_color_(kInvalidColor), 89 color_profiles_(GetProminentColorProfiles()),
97 wallpaper_reload_delay_(kWallpaperReloadDelayMs), 90 wallpaper_reload_delay_(kWallpaperReloadDelayMs),
98 sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits( 91 sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
99 {base::TaskPriority::USER_VISIBLE, 92 {base::TaskPriority::USER_VISIBLE,
100 // Don't need to finish resize or color extraction during shutdown. 93 // Don't need to finish resize or color extraction during shutdown.
101 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), 94 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})),
102 scoped_session_observer_(this) { 95 scoped_session_observer_(this) {
96 prominent_colors_ =
97 std::vector<SkColor>(color_profiles_.size(), kInvalidColor);
103 Shell::Get()->window_tree_host_manager()->AddObserver(this); 98 Shell::Get()->window_tree_host_manager()->AddObserver(this);
104 Shell::Get()->AddShellObserver(this); 99 Shell::Get()->AddShellObserver(this);
105 } 100 }
106 101
107 WallpaperController::~WallpaperController() { 102 WallpaperController::~WallpaperController() {
108 if (current_wallpaper_) 103 if (current_wallpaper_)
109 current_wallpaper_->RemoveObserver(this); 104 current_wallpaper_->RemoveObserver(this);
110 if (color_calculator_) 105 if (color_calculator_)
111 color_calculator_->RemoveObserver(this); 106 color_calculator_->RemoveObserver(this);
112 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); 107 Shell::Get()->window_tree_host_manager()->RemoveObserver(this);
(...skipping 19 matching lines...) Expand all
132 127
133 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) { 128 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) {
134 observers_.AddObserver(observer); 129 observers_.AddObserver(observer);
135 } 130 }
136 131
137 void WallpaperController::RemoveObserver( 132 void WallpaperController::RemoveObserver(
138 WallpaperControllerObserver* observer) { 133 WallpaperControllerObserver* observer) {
139 observers_.RemoveObserver(observer); 134 observers_.RemoveObserver(observer);
140 } 135 }
141 136
137 WallpaperController::ColorProfileIndex
138 WallpaperController::GetColorProfileIndex(ColorProfile color_profile) const {
139 if (color_profile.saturation == SaturationRange::VIBRANT) {
140 switch (color_profile.luma) {
141 case LumaRange::DARK:
142 return COLOR_PROFILE_INDEX_DARK_VIBRANT;
143 case LumaRange::NORMAL:
144 return COLOR_PROFILE_INDEX_NORMAL_VIBRANT;
145 case LumaRange::LIGHT:
146 return COLOR_PROFILE_INDEX_LIGHT_VIBRANT;
147 }
148 } else {
149 switch (color_profile.luma) {
150 case LumaRange::DARK:
151 return COLOR_PROFILE_INDEX_DARK_MUTED;
152 case LumaRange::NORMAL:
153 return COLOR_PROFILE_INDEX_NORMAL_MUTED;
154 case LumaRange::LIGHT:
155 return COLOR_PROFILE_INDEX_LIGHT_MUTED;
156 }
157 }
158 NOTREACHED();
159 return COLOR_PROFILE_INDEX_DARK_MUTED;
160 }
161
142 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { 162 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const {
143 if (current_wallpaper_) 163 if (current_wallpaper_)
144 return current_wallpaper_->layout(); 164 return current_wallpaper_->layout();
145 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 165 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
146 } 166 }
147 167
148 void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, 168 void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
149 wallpaper::WallpaperLayout layout) { 169 wallpaper::WallpaperLayout layout) {
150 VLOG(1) << "SetWallpaper: image_id=" 170 VLOG(1) << "SetWallpaper: image_id="
151 << wallpaper::WallpaperResizer::GetImageId(image) 171 << wallpaper::WallpaperResizer::GetImageId(image)
152 << " layout=" << layout; 172 << " layout=" << layout;
153 173
154 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { 174 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
155 VLOG(1) << "Wallpaper is already loaded"; 175 VLOG(1) << "Wallpaper is already loaded";
156 return; 176 return;
157 } 177 }
158 178
159 current_wallpaper_.reset(new wallpaper::WallpaperResizer( 179 current_wallpaper_.reset(new wallpaper::WallpaperResizer(
160 image, GetMaxDisplaySizeInNative(), layout, sequenced_task_runner_)); 180 image, GetMaxDisplaySizeInNative(), layout, sequenced_task_runner_));
161 current_wallpaper_->AddObserver(this); 181 current_wallpaper_->AddObserver(this);
162 current_wallpaper_->StartResize(); 182 current_wallpaper_->StartResize();
163 183
164 for (auto& observer : observers_) 184 for (auto& observer : observers_)
165 observer.OnWallpaperDataChanged(); 185 observer.OnWallpaperDataChanged();
166 wallpaper_mode_ = WALLPAPER_IMAGE; 186 wallpaper_mode_ = WALLPAPER_IMAGE;
167 InstallDesktopControllerForAllWindows(); 187 InstallDesktopControllerForAllWindows();
168 } 188 }
169 189
170 void WallpaperController::CreateEmptyWallpaper() { 190 void WallpaperController::CreateEmptyWallpaper() {
171 SetProminentColor(kInvalidColor); 191 SetProminentColors(
192 std::vector<SkColor>(color_profiles_.size(), kInvalidColor));
172 current_wallpaper_.reset(); 193 current_wallpaper_.reset();
173 wallpaper_mode_ = WALLPAPER_IMAGE; 194 wallpaper_mode_ = WALLPAPER_IMAGE;
174 InstallDesktopControllerForAllWindows(); 195 InstallDesktopControllerForAllWindows();
175 } 196 }
176 197
177 void WallpaperController::OnDisplayConfigurationChanged() { 198 void WallpaperController::OnDisplayConfigurationChanged() {
178 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); 199 gfx::Size max_display_size = GetMaxDisplaySizeInNative();
179 if (current_max_display_size_ != max_display_size) { 200 if (current_max_display_size_ != max_display_size) {
180 current_max_display_size_ = max_display_size; 201 current_max_display_size_ = max_display_size;
181 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) { 202 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 302
282 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); 303 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout);
283 } 304 }
284 305
285 void WallpaperController::OnWallpaperResized() { 306 void WallpaperController::OnWallpaperResized() {
286 CalculateWallpaperColors(); 307 CalculateWallpaperColors();
287 compositor_lock_.reset(); 308 compositor_lock_.reset();
288 } 309 }
289 310
290 void WallpaperController::OnColorCalculationComplete() { 311 void WallpaperController::OnColorCalculationComplete() {
291 const SkColor color = color_calculator_->prominent_color(); 312 const std::vector<SkColor> colors = color_calculator_->prominent_colors();
292 color_calculator_.reset(); 313 color_calculator_.reset();
293 SetProminentColor(color); 314 SetProminentColors(colors);
294 } 315 }
295 316
296 void WallpaperController::InstallDesktopController(aura::Window* root_window) { 317 void WallpaperController::InstallDesktopController(aura::Window* root_window) {
297 WallpaperWidgetController* component = nullptr; 318 WallpaperWidgetController* component = nullptr;
298 int container_id = GetWallpaperContainerId(locked_); 319 int container_id = GetWallpaperContainerId(locked_);
299 320
300 switch (wallpaper_mode_) { 321 switch (wallpaper_mode_) {
301 case WALLPAPER_IMAGE: { 322 case WALLPAPER_IMAGE: {
302 component = new WallpaperWidgetController( 323 component = new WallpaperWidgetController(
303 CreateWallpaper(root_window, container_id)); 324 CreateWallpaper(root_window, container_id));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 int WallpaperController::GetWallpaperContainerId(bool locked) { 374 int WallpaperController::GetWallpaperContainerId(bool locked) {
354 return locked ? kShellWindowId_LockScreenWallpaperContainer 375 return locked ? kShellWindowId_LockScreenWallpaperContainer
355 : kShellWindowId_WallpaperContainer; 376 : kShellWindowId_WallpaperContainer;
356 } 377 }
357 378
358 void WallpaperController::UpdateWallpaper(bool clear_cache) { 379 void WallpaperController::UpdateWallpaper(bool clear_cache) {
359 current_wallpaper_.reset(); 380 current_wallpaper_.reset();
360 Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 381 Shell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
361 } 382 }
362 383
363 void WallpaperController::SetProminentColor(SkColor color) { 384 void WallpaperController::SetProminentColors(
364 if (prominent_color_ == color) 385 const std::vector<SkColor>& colors) {
386 if (prominent_colors_ == colors)
365 return; 387 return;
366 388
367 prominent_color_ = color; 389 prominent_colors_ = colors;
368 for (auto& observer : observers_) 390 for (auto& observer : observers_)
369 observer.OnWallpaperColorsChanged(); 391 observer.OnWallpaperColorsChanged();
370 } 392 }
371 393
372 void WallpaperController::CalculateWallpaperColors() { 394 void WallpaperController::CalculateWallpaperColors() {
373 if (color_calculator_) { 395 if (color_calculator_) {
374 color_calculator_->RemoveObserver(this); 396 color_calculator_->RemoveObserver(this);
375 color_calculator_.reset(); 397 color_calculator_.reset();
376 } 398 }
377 399
378 if (!ShouldCalculateColors()) { 400 if (!ShouldCalculateColors()) {
379 SetProminentColor(kInvalidColor); 401 SetProminentColors(
402 std::vector<SkColor>(color_profiles_.size(), kInvalidColor));
380 return; 403 return;
381 } 404 }
382 405
383 color_utils::LumaRange luma;
384 color_utils::SaturationRange saturation;
385 GetProminentColorProfile(&luma, &saturation);
386
387 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>( 406 color_calculator_ = base::MakeUnique<wallpaper::WallpaperColorCalculator>(
388 GetWallpaper(), luma, saturation, sequenced_task_runner_); 407 GetWallpaper(), color_profiles_, sequenced_task_runner_);
389 color_calculator_->AddObserver(this); 408 color_calculator_->AddObserver(this);
390 if (!color_calculator_->StartCalculation()) 409 if (!color_calculator_->StartCalculation()) {
391 SetProminentColor(kInvalidColor); 410 SetProminentColors(
411 std::vector<SkColor>(color_profiles_.size(), kInvalidColor));
412 }
392 } 413 }
393 414
394 bool WallpaperController::ShouldCalculateColors() const { 415 bool WallpaperController::ShouldCalculateColors() const {
395 gfx::ImageSkia image = GetWallpaper(); 416 gfx::ImageSkia image = GetWallpaper();
396 return IsShelfColoringEnabled() && 417 return IsShelfColoringEnabled() &&
397 Shell::Get()->session_controller()->GetSessionState() == 418 Shell::Get()->session_controller()->GetSessionState() ==
398 session_manager::SessionState::ACTIVE && 419 session_manager::SessionState::ACTIVE &&
399 !image.isNull(); 420 !image.isNull();
bruthig 2017/06/21 15:54:17 nitty-nit-nit: This could return false if color_pr
Qiang(Joe) Xu 2017/06/21 22:35:26 Done.
400 } 421 }
401 422
402 bool WallpaperController::MoveToLockedContainer() { 423 bool WallpaperController::MoveToLockedContainer() {
403 if (locked_) 424 if (locked_)
404 return false; 425 return false;
405 426
406 locked_ = true; 427 locked_ = true;
407 return ReparentWallpaper(GetWallpaperContainerId(true)); 428 return ReparentWallpaper(GetWallpaperContainerId(true));
408 } 429 }
409 430
(...skipping 17 matching lines...) Expand all
427 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); 448 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs));
428 } 449 }
429 } 450 }
430 } 451 }
431 452
432 void WallpaperController::CompositorLockTimedOut() { 453 void WallpaperController::CompositorLockTimedOut() {
433 compositor_lock_.reset(); 454 compositor_lock_.reset();
434 } 455 }
435 456
436 } // namespace ash 457 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698